diff options
Diffstat (limited to 'src/if_mzsch.c')
-rw-r--r-- | src/if_mzsch.c | 451 |
1 files changed, 261 insertions, 190 deletions
diff --git a/src/if_mzsch.c b/src/if_mzsch.c index 04a444e23..bf0157a59 100644 --- a/src/if_mzsch.c +++ b/src/if_mzsch.c @@ -25,8 +25,8 @@ #include "if_mzsch.h" -/* Only do the following when the feature is enabled. Needed for "make - * depend". */ +// Only do the following when the feature is enabled. Needed for "make +// depend". #if defined(FEAT_MZSCHEME) || defined(PROTO) #ifdef PROTO @@ -63,7 +63,7 @@ typedef int HINSTANCE; # define TRAMPOLINED_MZVIM_STARTUP #endif -/* Base data structures */ +// Base data structures #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type) #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type) @@ -90,7 +90,7 @@ typedef struct { Scheme_Closed_Prim *prim; char *name; - int mina; /* arity information */ + int mina; // arity information int maxa; } Vim_Prim; @@ -115,12 +115,12 @@ static Scheme_Object *sandbox_file_guard(int, Scheme_Object **); static Scheme_Object *sandbox_network_guard(int, Scheme_Object **); static void sandbox_check(void); #endif -/* Buffer-related commands */ +// Buffer-related commands static Scheme_Object *buffer_new(buf_T *buf); static Scheme_Object *get_buffer_by_num(void *, int, Scheme_Object **); static vim_mz_buffer *get_vim_curr_buffer(void); -/* Window-related commands */ +// Window-related commands static Scheme_Object *window_new(win_T *win); static vim_mz_window *get_vim_curr_window(void); @@ -182,13 +182,11 @@ static int buffer_mark_proc(void *obj) } static int buffer_fixup_proc(void *obj) { - /* apparently not needed as the object will be uncollectable while - * the buffer is alive - */ - /* - vim_mz_buffer* buf = (vim_mz_buffer*) obj; - buf->buf->b_mzscheme_ref = GC_fixup_self(obj); - */ + // apparently not needed as the object will be uncollectable while + // the buffer is alive + // vim_mz_buffer* buf = (vim_mz_buffer*) obj; + // buf->buf->b_mzscheme_ref = GC_fixup_self(obj); + return buffer_size_proc(obj); } static int window_size_proc(void *obj UNUSED) @@ -201,18 +199,16 @@ static int window_mark_proc(void *obj) } static int window_fixup_proc(void *obj) { - /* apparently not needed as the object will be uncollectable while - * the window is alive - */ - /* - vim_mz_window* win = (vim_mz_window*) obj; - win->win->w_mzscheme_ref = GC_fixup_self(obj); - */ + // apparently not needed as the object will be uncollectable while + // the window is alive + // vim_mz_window* win = (vim_mz_window*) obj; + // win->win->w_mzscheme_ref = GC_fixup_self(obj); + // return window_size_proc(obj); } -/* with precise GC, w_mzscheme_ref and b_mzscheme_ref are immobile boxes - * containing pointers to a window/buffer - * with conservative GC these are simply pointers*/ +// with precise GC, w_mzscheme_ref and b_mzscheme_ref are immobile boxes +// containing pointers to a window/buffer +// with conservative GC these are simply pointers # define WINDOW_REF(win) *(vim_mz_window **)((win)->w_mzscheme_ref) # define BUFFER_REF(buf) *(vim_mz_buffer **)((buf)->b_mzscheme_ref) #else @@ -378,16 +374,16 @@ static void (*dll_scheme_register_embedded_load)(intptr_t len, const char *s); static void (*dll_scheme_set_config_path)(Scheme_Object *p); # endif -#if defined(DYNAMIC_MZSCHEME) /* not when defined(PROTO) */ +#if defined(DYNAMIC_MZSCHEME) // not when defined(PROTO) -/* arrays are imported directly */ +// arrays are imported directly # define scheme_eof dll_scheme_eof # define scheme_false dll_scheme_false # define scheme_void dll_scheme_void # define scheme_null dll_scheme_null # define scheme_true dll_scheme_true -/* pointers are GetProceAddress'ed as pointers to pointer */ +// pointers are GetProceAddress'ed as pointers to pointer #if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE) # define scheme_current_thread (*dll_scheme_current_thread_ptr) # endif @@ -395,7 +391,7 @@ static void (*dll_scheme_set_config_path)(Scheme_Object *p); # define scheme_console_output (*dll_scheme_console_output_ptr) # define scheme_notify_multithread (*dll_scheme_notify_multithread_ptr) -/* and functions in a usual way */ +// and functions in a usual way # define GC_malloc dll_GC_malloc # define GC_malloc_atomic dll_GC_malloc_atomic @@ -504,7 +500,7 @@ static void (*dll_scheme_set_config_path)(Scheme_Object *p); # if MZSCHEME_VERSION_MAJOR >= 500 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || defined(IMPLEMENT_THREAD_LOCAL_EXTERNALLY_VIA_PROC) -/* define as function for macro in schthread.h */ +// define as function for macro in schthread.h Thread_Local_Variables * scheme_external_get_thread_local_variables(void) { @@ -735,7 +731,7 @@ dynamic_mzscheme_end(void) hMzGC = 0; } } -#endif /* DYNAMIC_MZSCHEME */ +#endif // DYNAMIC_MZSCHEME #if MZSCHEME_VERSION_MAJOR < 299 # define GUARANTEED_STRING_ARG(proc, num) GUARANTEE_STRING(proc, num) @@ -760,13 +756,13 @@ guaranteed_byte_string_arg(char *proc, int num, int argc, Scheme_Object **argv) } else scheme_wrong_type(proc, "string", num, argc, argv); - /* unreachable */ + // unreachable return scheme_void; } # define GUARANTEED_STRING_ARG(proc, num) guaranteed_byte_string_arg(proc, num, argc, argv) #endif -/* need to put it here for dynamic stuff to work */ +// need to put it here for dynamic stuff to work #if defined(INCLUDE_MZSCHEME_BASE) # include "mzscheme_base.c" #endif @@ -786,16 +782,16 @@ static int disabled = FALSE; #endif static int load_base_module_failed = FALSE; -/* global environment */ +// global environment static Scheme_Env *environment = NULL; -/* output/error handlers */ +// output/error handlers static Scheme_Object *curout = NULL; static Scheme_Object *curerr = NULL; -/* exn:vim exception */ +// exn:vim exception static Scheme_Object *exn_catching_apply = NULL; static Scheme_Object *exn_p = NULL; static Scheme_Object *exn_message = NULL; -static Scheme_Object *vim_exn = NULL; /* Vim Error exception */ +static Scheme_Object *vim_exn = NULL; // Vim Error exception #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400 static void *stack_base = NULL; @@ -804,7 +800,7 @@ static void *stack_base = NULL; static long range_start; static long range_end; -/* MzScheme threads scheduling stuff */ +// MzScheme threads scheduling stuff static int mz_threads_allow = 0; #if defined(FEAT_GUI_MSWIN) @@ -822,11 +818,11 @@ static EventLoopTimerRef timer_id = NULL; static EventLoopTimerUPP timerUPP; #endif -#if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) /* Win32 console and Unix */ +#if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) // Win32 console and Unix void mzvim_check_threads(void) { - /* Last time MzScheme threads were scheduled */ + // Last time MzScheme threads were scheduled static time_t mz_last_time = 0; if (mz_threads_allow && p_mzq > 0) @@ -846,7 +842,7 @@ mzvim_check_threads(void) static void setup_timer(void); static void remove_timer(void); -/* timers are presented in GUI only */ +// timers are presented in GUI only # if defined(FEAT_GUI_MSWIN) static void CALLBACK timer_proc(HWND hwnd UNUSED, UINT uMsg UNUSED, UINT_PTR idEvent UNUSED, DWORD dwTime UNUSED) @@ -863,9 +859,9 @@ timer_proc(EventLoopTimerRef theTimer UNUSED, void *userData UNUSED) { scheme_check_threads(); # if defined(FEAT_GUI_GTK) - return TRUE; /* continue receiving notifications */ + return TRUE; // continue receiving notifications # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) - /* renew timeout */ + // renew timeout if (mz_threads_allow && p_mzq > 0) timer_id = XtAppAddTimeOut(app_context, p_mzq, timer_proc, NULL); @@ -913,7 +909,7 @@ mzvim_reset_timer(void) setup_timer(); } -#endif /* MZSCHEME_GUI_THREADS */ +#endif // MZSCHEME_GUI_THREADS static void notify_multithread(int on) @@ -930,7 +926,7 @@ notify_multithread(int on) void mzscheme_end(void) { - /* We can not unload the DLL. Racket's thread might be still alive. */ + // We can not unload the DLL. Racket's thread might be still alive. #if 0 #ifdef DYNAMIC_MZSCHEME dynamic_mzscheme_end(); @@ -987,7 +983,7 @@ mzscheme_main(void) mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED) { #ifdef TRAMPOLINED_MZVIM_STARTUP - /* Scheme has created the environment for us */ + // Scheme has created the environment for us environment = env; #else # ifdef MZ_PRECISE_GC @@ -1003,7 +999,7 @@ mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED) #endif vim_main2(); - /* not reached, vim_main2() will loop until exit() */ + // not reached, vim_main2() will loop until exit() return 0; } @@ -1030,7 +1026,7 @@ startup_mzscheme(void) #endif #ifndef TRAMPOLINED_MZVIM_STARTUP - /* in newer versions of precise GC the initial env has been created */ + // in newer versions of precise GC the initial env has been created environment = scheme_basic_env(); #endif @@ -1045,11 +1041,11 @@ startup_mzscheme(void) MZ_GC_CHECK(); #ifdef INCLUDE_MZSCHEME_BASE - /* invoke function from generated and included mzscheme_base.c */ + // invoke function from generated and included mzscheme_base.c declare_modules(environment); #endif - /* setup 'current-library-collection-paths' parameter */ + // setup 'current-library-collection-paths' parameter # if MZSCHEME_VERSION_MAJOR >= 299 { Scheme_Object *coll_path = NULL; @@ -1059,7 +1055,7 @@ startup_mzscheme(void) MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, coll_path); MZ_GC_REG(); - /* workaround for dynamic loading on windows */ + // workaround for dynamic loading on windows s = vim_getenv((char_u *)"PLTCOLLECTS", &mustfree); if (s != NULL) { @@ -1116,7 +1112,7 @@ startup_mzscheme(void) MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, config_path); MZ_GC_REG(); - /* workaround for dynamic loading on windows */ + // workaround for dynamic loading on windows s = vim_getenv((char_u *)"PLTCONFIGDIR", &mustfree); if (s != NULL) { @@ -1150,7 +1146,7 @@ startup_mzscheme(void) * we need to add them explicitly */ { - /* use error handler to avoid abort */ + // use error handler to avoid abort scheme_dynamic_wind(NULL, load_base_module, NULL, load_base_module_on_error, "racket/base"); if (load_base_module_failed) @@ -1164,10 +1160,10 @@ startup_mzscheme(void) } register_vim_exn(); - /* use new environment to initialise exception handling */ + // use new environment to initialise exception handling init_exn_catching_apply(); - /* redirect output */ + // redirect output scheme_console_output = do_output; scheme_console_printf = do_printf; @@ -1195,7 +1191,7 @@ startup_mzscheme(void) MZ_GC_CHECK(); #endif - /* setup sandbox guards */ + // setup sandbox guards if (make_security_guard != NULL) { Scheme_Object *args[3] = {NULL, NULL, NULL}; @@ -1223,7 +1219,7 @@ startup_mzscheme(void) MZ_GC_UNREG(); } #endif - /* Create buffer and window types for use in Scheme code */ + // Create buffer and window types for use in Scheme code mz_buffer_type = scheme_make_type("<vim-buffer>"); MZ_GC_CHECK(); mz_window_type = scheme_make_type("<vim-window>"); @@ -1278,7 +1274,7 @@ mzscheme_init(void) MZ_GC_REG(); config = scheme_current_config(); MZ_GC_CHECK(); - /* recreate ports each call effectively clearing these ones */ + // recreate ports each call effectively clearing these ones curout = scheme_make_byte_string_output_port(); MZ_GC_CHECK(); curerr = scheme_make_byte_string_output_port(); @@ -1323,24 +1319,24 @@ eval_with_exn_handling(void *data, Scheme_Closed_Prim *what, Scheme_Object **ret if (!value) { value = extract_exn_message(exn); - /* Got an exn? */ + // Got an exn? if (value) { - scheme_display(value, curerr); /* Send to stderr-vim */ + scheme_display(value, curerr); // Send to stderr-vim MZ_GC_CHECK(); do_flush(); } MZ_GC_UNREG(); - /* `raise' was called on some arbitrary value */ + // `raise' was called on some arbitrary value return FAIL; } - if (ret != NULL) /* if pointer to retval supported give it up */ + if (ret != NULL) // if pointer to retval supported give it up *ret = value; - /* Print any result, as long as it's not a void */ + // Print any result, as long as it's not a void else if (!SCHEME_VOIDP(value)) { - scheme_display(value, curout); /* Send to stdout-vim */ + scheme_display(value, curout); // Send to stdout-vim MZ_GC_CHECK(); } @@ -1349,7 +1345,9 @@ eval_with_exn_handling(void *data, Scheme_Closed_Prim *what, Scheme_Object **ret return OK; } -/* :mzscheme */ +/* + * :mzscheme + */ static int do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what) { @@ -1451,21 +1449,21 @@ do_load(void *data, int noargc UNUSED, Scheme_Object **noargv UNUSED) file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1); MZ_GC_CHECK(); - /* make Vim expansion */ + // make Vim expansion expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL); pinfo->port = scheme_open_input_file(file, "mzfile"); MZ_GC_CHECK(); - scheme_count_lines(pinfo->port); /* to get accurate read error location*/ + scheme_count_lines(pinfo->port); // to get accurate read error location MZ_GC_CHECK(); - /* Like REPL but print only last result */ + // Like REPL but print only last result while (!SCHEME_EOFP(expr = scheme_read(pinfo->port))) { result = scheme_eval(expr, environment); MZ_GC_CHECK(); } - /* errors will be caught in do_mzscheme_command and ex_mzfile */ + // errors will be caught in do_mzscheme_command and ex_mzfile scheme_close_input_port(pinfo->port); MZ_GC_CHECK(); pinfo->port = NULL; @@ -1473,7 +1471,9 @@ do_load(void *data, int noargc UNUSED, Scheme_Object **noargv UNUSED) return result; } -/* :mzfile */ +/* + * :mzfile + */ void ex_mzfile(exarg_T *eap) { @@ -1485,7 +1485,7 @@ ex_mzfile(exarg_T *eap) pinfo.name = (char *)eap->arg; if (do_mzscheme_command(eap, &pinfo, do_load) != OK - && pinfo.port != NULL) /* looks like port was not closed */ + && pinfo.port != NULL) // looks like port was not closed { scheme_close_input_port(pinfo.port); MZ_GC_CHECK(); @@ -1530,7 +1530,7 @@ _apply_thunk_catch_exceptions(Scheme_Object *f, Scheme_Object **exn) Scheme_Object *v; v = _scheme_apply(exn_catching_apply, 1, &f); - /* v is a pair: (cons #t value) or (cons #f exn) */ + // v is a pair: (cons #t value) or (cons #f exn) if (SCHEME_TRUEP(SCHEME_CAR(v))) return SCHEME_CDR(v); @@ -1547,7 +1547,7 @@ extract_exn_message(Scheme_Object *v) if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v))) return _scheme_apply(exn_message, 1, &v); else - return NULL; /* Not an exn structure */ + return NULL; // Not an exn structure } static Scheme_Object * @@ -1588,7 +1588,7 @@ do_intrnl_output(char *mesg, int error) static void do_output(char *mesg, OUTPUT_LEN_TYPE len UNUSED) { - /* TODO: use len, the string may not be NUL terminated */ + // TODO: use len, the string may not be NUL terminated do_intrnl_output(mesg, 0); } @@ -1630,7 +1630,9 @@ do_flush(void) *======================================================================== */ -/* (command {command-string}) */ +/* + * (command {command-string}) + */ static Scheme_Object * vim_command(void *data, int argc, Scheme_Object **argv) { @@ -1641,7 +1643,7 @@ vim_command(void *data, int argc, Scheme_Object **argv) MZ_GC_REG(); cmd = GUARANTEED_STRING_ARG(prim->name, 0); - /* may be use do_cmdline_cmd? */ + // may be use do_cmdline_cmd? do_cmdline(BYTE_STRING_VALUE(cmd), NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE); update_screen(VALID); @@ -1650,7 +1652,9 @@ vim_command(void *data, int argc, Scheme_Object **argv) return scheme_void; } -/* (eval {expr-string}) */ +/* + * (eval {expr-string}) + */ static Scheme_Object * vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { @@ -1678,26 +1682,32 @@ vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) return result; #else raise_vim_exn(_("expressions disabled at compile time")); - /* unreachable */ + // unreachable return scheme_false; #endif } -/* (range-start) */ +/* + * (range-start) + */ static Scheme_Object * get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return scheme_make_integer(range_start); } -/* (range-end) */ +/* + * (range-end) + */ static Scheme_Object * get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return scheme_make_integer(range_end); } -/* (beep) */ +/* + * (beep) + */ static Scheme_Object * mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { @@ -1707,7 +1717,9 @@ mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) static Scheme_Object *M_global = NULL; -/* (get-option {option-name}) [buffer/window] */ +/* + * (get-option {option-name}) [buffer/window] + */ static Scheme_Object * get_option(void *data, int argc, Scheme_Object **argv) { @@ -1775,17 +1787,19 @@ get_option(void *data, int argc, Scheme_Object **argv) case -2: MZ_GC_UNREG(); raise_vim_exn(_("hidden option")); - /*NOTREACHED*/ + //NOTREACHED case -3: MZ_GC_UNREG(); raise_vim_exn(_("unknown option")); - /*NOTREACHED*/ + //NOTREACHED } - /* unreachable */ + // unreachable return scheme_void; } -/* (set-option {option-changing-string} [buffer/window]) */ +/* + * (set-option {option-changing-string} [buffer/window]) + */ static Scheme_Object * set_option(void *data, int argc, Scheme_Object **argv) { @@ -1828,7 +1842,7 @@ set_option(void *data, int argc, Scheme_Object **argv) scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); } - /* do_set can modify cmd, make copy */ + // do_set can modify cmd, make copy command = vim_strsave(BYTE_STRING_VALUE(cmd)); MZ_GC_UNREG(); do_set(command, opt_flags); @@ -1846,14 +1860,18 @@ set_option(void *data, int argc, Scheme_Object **argv) *=========================================================================== */ -/* (curr-win) */ +/* + * (curr-win) + */ static Scheme_Object * get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return (Scheme_Object *)get_vim_curr_window(); } -/* (win-count) */ +/* + * (win-count) + */ static Scheme_Object * get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { @@ -1865,7 +1883,9 @@ get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED return scheme_make_integer(n); } -/* (get-win-list [buffer]) */ +/* + * (get-win-list [buffer]) + */ static Scheme_Object * get_window_list(void *data, int argc, Scheme_Object **argv) { @@ -1895,14 +1915,13 @@ window_new(win_T *win) MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, self); - /* We need to handle deletion of windows underneath us. - * If we add a "w_mzscheme_ref" field to the win_T structure, - * then we can get at it in win_free() in vim. - * - * On a win_free() we set the Scheme object's win_T *field - * to an invalid value. We trap all uses of a window - * object, and reject them if the win_T *field is invalid. - */ + // We need to handle deletion of windows underneath us. + // If we add a "w_mzscheme_ref" field to the win_T structure, + // then we can get at it in win_free() in vim. + // + // On a win_free() we set the Scheme object's win_T *field + // to an invalid value. We trap all uses of a window + // object, and reject them if the win_T *field is invalid. if (win->w_mzscheme_ref != NULL) return (Scheme_Object *)WINDOW_REF(win); @@ -1910,7 +1929,7 @@ window_new(win_T *win) self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window)); vim_memset(self, 0, sizeof(vim_mz_window)); #ifndef MZ_PRECISE_GC - scheme_dont_gc_ptr(self); /* because win isn't visible to GC */ + scheme_dont_gc_ptr(self); // because win isn't visible to GC #else win->w_mzscheme_ref = scheme_malloc_immobile_box(NULL); #endif @@ -1924,7 +1943,9 @@ window_new(win_T *win) return (Scheme_Object *)self; } -/* (get-win-num [window]) */ +/* + * (get-win-num [window]) + */ static Scheme_Object * get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { @@ -1939,7 +1960,9 @@ get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) return scheme_make_integer(nr); } -/* (get-win-by-num {windownum}) */ +/* + * (get-win-by-num {windownum}) + */ static Scheme_Object * get_window_by_num(void *data, int argc, Scheme_Object **argv) { @@ -1952,13 +1975,15 @@ get_window_by_num(void *data, int argc, Scheme_Object **argv) scheme_signal_error(_("window index is out of range")); for ( ; win != NULL; win = win->w_next, --fnum) - if (fnum == 1) /* to be 1-based */ + if (fnum == 1) // to be 1-based return window_new(win); return scheme_false; } -/* (get-win-buffer [window]) */ +/* + * (get-win-buffer [window]) + */ static Scheme_Object * get_window_buffer(void *data, int argc, Scheme_Object **argv) { @@ -1968,7 +1993,9 @@ get_window_buffer(void *data, int argc, Scheme_Object **argv) return buffer_new(win->win->w_buffer); } -/* (get-win-height [window]) */ +/* + * (get-win-height [window]) + */ static Scheme_Object * get_window_height(void *data, int argc, Scheme_Object **argv) { @@ -1978,7 +2005,9 @@ get_window_height(void *data, int argc, Scheme_Object **argv) return scheme_make_integer(win->win->w_height); } -/* (set-win-height {height} [window]) */ +/* + * (set-win-height {height} [window]) + */ static Scheme_Object * set_window_height(void *data, int argc, Scheme_Object **argv) { @@ -2003,7 +2032,9 @@ set_window_height(void *data, int argc, Scheme_Object **argv) return scheme_void; } -/* (get-win-width [window]) */ +/* + * (get-win-width [window]) + */ static Scheme_Object * get_window_width(void *data, int argc, Scheme_Object **argv) { @@ -2013,7 +2044,9 @@ get_window_width(void *data, int argc, Scheme_Object **argv) return scheme_make_integer(win->win->w_width); } -/* (set-win-width {width} [window]) */ +/* + * (set-win-width {width} [window]) + */ static Scheme_Object * set_window_width(void *data, int argc, Scheme_Object **argv) { @@ -2038,7 +2071,9 @@ set_window_width(void *data, int argc, Scheme_Object **argv) return scheme_void; } -/* (get-cursor [window]) -> (line . col) */ +/* + * (get-cursor [window]) -> (line . col) + */ static Scheme_Object * get_cursor(void *data, int argc, Scheme_Object **argv) { @@ -2052,7 +2087,9 @@ get_cursor(void *data, int argc, Scheme_Object **argv) scheme_make_integer_value((long)pos.col + 1)); } -/* (set-cursor (line . col) [window]) */ +/* + * (set-cursor (line . col) [window]) + */ static Scheme_Object * set_cursor(void *data, int argc, Scheme_Object **argv) { @@ -2075,7 +2112,7 @@ set_cursor(void *data, int argc, Scheme_Object **argv) col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1; check_line_range(lnum, win->win->w_buffer); - /* don't know how to catch invalid column value */ + // don't know how to catch invalid column value win->win->w_cursor.lnum = lnum; win->win->w_cursor.col = col; @@ -2091,7 +2128,9 @@ set_cursor(void *data, int argc, Scheme_Object **argv) *=========================================================================== */ -/* (open-buff {filename}) */ +/* + * (open-buff {filename}) + */ static Scheme_Object * mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) { @@ -2111,7 +2150,7 @@ mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) #ifdef HAVE_SANDBOX sandbox_check(); #endif - /* TODO make open existing file */ + // TODO make open existing file num = buflist_add(BYTE_STRING_VALUE(fname), BLN_LISTED | BLN_CURBUF); if (num == 0) @@ -2123,7 +2162,9 @@ mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) return buf; } -/* (get-buff-by-num {buffernum}) */ +/* + * (get-buff-by-num {buffernum}) + */ static Scheme_Object * get_buffer_by_num(void *data, int argc, Scheme_Object **argv) { @@ -2140,7 +2181,9 @@ get_buffer_by_num(void *data, int argc, Scheme_Object **argv) return scheme_false; } -/* (get-buff-by-name {buffername}) */ +/* + * (get-buff-by-name {buffername}) + */ static Scheme_Object * get_buffer_by_name(void *data, int argc, Scheme_Object **argv) { @@ -2159,7 +2202,7 @@ get_buffer_by_name(void *data, int argc, Scheme_Object **argv) FOR_ALL_BUFFERS(buf) { if (buf->b_ffname == NULL || buf->b_sfname == NULL) - /* empty string */ + // empty string { if (BYTE_STRING_VALUE(fname)[0] == NUL) buffer = buffer_new(buf); @@ -2167,7 +2210,7 @@ get_buffer_by_name(void *data, int argc, Scheme_Object **argv) else if (!fnamecmp(buf->b_ffname, BYTE_STRING_VALUE(fname)) || !fnamecmp(buf->b_sfname, BYTE_STRING_VALUE(fname))) { - /* either short or long filename matches */ + // either short or long filename matches buffer = buffer_new(buf); } } @@ -2176,7 +2219,9 @@ get_buffer_by_name(void *data, int argc, Scheme_Object **argv) return buffer; } -/* (get-next-buff [buffer]) */ +/* + * (get-next-buff [buffer]) + */ static Scheme_Object * get_next_buffer(void *data, int argc, Scheme_Object **argv) { @@ -2189,7 +2234,9 @@ get_next_buffer(void *data, int argc, Scheme_Object **argv) return buffer_new(buf->b_next); } -/* (get-prev-buff [buffer]) */ +/* + * (get-prev-buff [buffer]) + */ static Scheme_Object * get_prev_buffer(void *data, int argc, Scheme_Object **argv) { @@ -2202,7 +2249,9 @@ get_prev_buffer(void *data, int argc, Scheme_Object **argv) return buffer_new(buf->b_prev); } -/* (get-buff-num [buffer]) */ +/* + * (get-buff-num [buffer]) + */ static Scheme_Object * get_buffer_num(void *data, int argc, Scheme_Object **argv) { @@ -2212,7 +2261,9 @@ get_buffer_num(void *data, int argc, Scheme_Object **argv) return scheme_make_integer(buf->buf->b_fnum); } -/* (buff-count) */ +/* + * (buff-count) + */ static Scheme_Object * get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { @@ -2223,7 +2274,9 @@ get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED return scheme_make_integer(n); } -/* (get-buff-name [buffer]) */ +/* + * (get-buff-name [buffer]) + */ static Scheme_Object * get_buffer_name(void *data, int argc, Scheme_Object **argv) { @@ -2233,7 +2286,9 @@ get_buffer_name(void *data, int argc, Scheme_Object **argv) return scheme_make_byte_string((char *)buf->buf->b_ffname); } -/* (curr-buff) */ +/* + * (curr-buff) + */ static Scheme_Object * get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { @@ -2248,10 +2303,9 @@ buffer_new(buf_T *buf) MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, self); - /* We need to handle deletion of buffers underneath us. - * If we add a "b_mzscheme_ref" field to the buf_T structure, - * then we can get at it in buf_freeall() in vim. - */ + // We need to handle deletion of buffers underneath us. + // If we add a "b_mzscheme_ref" field to the buf_T structure, + // then we can get at it in buf_freeall() in vim. if (buf->b_mzscheme_ref) return (Scheme_Object *)BUFFER_REF(buf); @@ -2259,7 +2313,7 @@ buffer_new(buf_T *buf) self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer)); vim_memset(self, 0, sizeof(vim_mz_buffer)); #ifndef MZ_PRECISE_GC - scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */ + scheme_dont_gc_ptr(self); // because buf isn't visible to GC #else buf->b_mzscheme_ref = scheme_malloc_immobile_box(NULL); #endif @@ -2354,7 +2408,7 @@ get_buffer_line_list(void *data, int argc, Scheme_Object **argv) (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE)); raise_if_error(); - /* Set the list item */ + // Set the list item list = scheme_make_pair(str, list); MZ_GC_CHECK(); } @@ -2377,12 +2431,11 @@ get_buffer_line_list(void *data, int argc, Scheme_Object **argv) static Scheme_Object * set_buffer_line(void *data, int argc, Scheme_Object **argv) { - /* First of all, we check the value of the supplied MzScheme object. - * There are three cases: - * 1. #f - this is a deletion. - * 2. A string - this is a replacement. - * 3. Anything else - this is an error. - */ + // First of all, we check the value of the supplied MzScheme object. + // There are three cases: + // 1. #f - this is a deletion. + // 2. A string - this is a replacement. + // 3. Anything else - this is an error. Vim_Prim *prim = (Vim_Prim *)data; vim_mz_buffer *buf; Scheme_Object *line = NULL; @@ -2432,7 +2485,7 @@ set_buffer_line(void *data, int argc, Scheme_Object **argv) } else { - /* Otherwise it's a line */ + // Otherwise it's a line buf_T *savebuf = curbuf; save = string_to_line(line); @@ -2459,7 +2512,7 @@ set_buffer_line(void *data, int argc, Scheme_Object **argv) curbuf = savebuf; - /* Check that the cursor is not beyond the end of the line now. */ + // Check that the cursor is not beyond the end of the line now. if (buf->buf == curwin->w_buffer) check_cursor_col(); @@ -2493,12 +2546,11 @@ free_array(char **array) static Scheme_Object * set_buffer_line_list(void *data, int argc, Scheme_Object **argv) { - /* First of all, we check the type of the supplied MzScheme object. - * There are three cases: - * 1. #f - this is a deletion. - * 2. A list - this is a replacement. - * 3. Anything else - this is an error. - */ + // First of all, we check the type of the supplied MzScheme object. + // There are three cases: + // 1. #f - this is a deletion. + // 2. A list - this is a replacement. + // 3. Anything else - this is an error. Vim_Prim *prim = (Vim_Prim *)data; vim_mz_buffer *buf = NULL; Scheme_Object *line_list = NULL; @@ -2520,7 +2572,7 @@ set_buffer_line_list(void *data, int argc, Scheme_Object **argv) line_list = argv[2]; buf = get_buffer_arg(prim->name, 3, argc, argv); old_len = hi - lo; - if (old_len < 0) /* process inverse values wisely */ + if (old_len < 0) // process inverse values wisely { i = lo; lo = hi; @@ -2529,8 +2581,8 @@ set_buffer_line_list(void *data, int argc, Scheme_Object **argv) } extra = 0; - check_line_range(lo, buf->buf); /* inclusive */ - check_line_range(hi - 1, buf->buf); /* exclusive */ + check_line_range(lo, buf->buf); // inclusive + check_line_range(hi - 1, buf->buf); // exclusive if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list)) { @@ -2565,10 +2617,10 @@ set_buffer_line_list(void *data, int argc, Scheme_Object **argv) { buf_T *savebuf = curbuf; - /* List */ + // List new_len = scheme_proper_list_length(line_list); MZ_GC_CHECK(); - if (new_len < 0) /* improper or cyclic list */ + if (new_len < 0) // improper or cyclic list scheme_wrong_type(prim->name, "proper list", 2, argc, argv); else @@ -2713,7 +2765,7 @@ insert_buffer_line_list(void *data, int argc, Scheme_Object **argv) scheme_wrong_type(prim->name, "string or list", 1, argc, argv); buf = get_buffer_arg(prim->name, 2, argc, argv); - if (n != 0) /* 0 can be used in insert */ + if (n != 0) // 0 can be used in insert check_line_range(n, buf->buf); if (SCHEME_STRINGP(list)) { @@ -2748,10 +2800,10 @@ insert_buffer_line_list(void *data, int argc, Scheme_Object **argv) return scheme_void; } - /* List */ + // List size = scheme_proper_list_length(list); MZ_GC_CHECK(); - if (size < 0) /* improper or cyclic list */ + if (size < 0) // improper or cyclic list scheme_wrong_type(prim->name, "proper list", 2, argc, argv); else @@ -2813,7 +2865,9 @@ insert_buffer_line_list(void *data, int argc, Scheme_Object **argv) /* * Predicates */ -/* (buff? obj) */ +/* + * (buff? obj) + */ static Scheme_Object * vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { @@ -2823,7 +2877,9 @@ vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) return scheme_false; } -/* (win? obj) */ +/* + * (win? obj) + */ static Scheme_Object * vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { @@ -2833,7 +2889,9 @@ vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) return scheme_false; } -/* (buff-valid? obj) */ +/* + * (buff-valid? obj) + */ static Scheme_Object * vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { @@ -2844,7 +2902,9 @@ vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) return scheme_false; } -/* (win-valid? obj) */ +/* + * (win-valid? obj) + */ static Scheme_Object * vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { @@ -2879,18 +2939,16 @@ string_to_line(Scheme_Object *obj) scheme_str = scheme_display_to_string(obj, &len); - /* Error checking: String must not contain newlines, as we - * are replacing a single line, and we must replace it with - * a single line. - */ + // Error checking: String must not contain newlines, as we + // are replacing a single line, and we must replace it with + // a single line. if (memchr(scheme_str, '\n', len)) scheme_signal_error(_("string cannot contain newlines")); vim_str = alloc(len + 1); - /* Create a copy of the string, with internal nulls replaced by - * newline characters, as is the vim convention. - */ + // Create a copy of the string, with internal nulls replaced by + // newline characters, as is the vim convention. for (i = 0; i < len; ++i) { if (scheme_str[i] == '\0') @@ -2913,7 +2971,7 @@ string_to_line(Scheme_Object *obj) vim_to_mzscheme(typval_T *vim_value) { Scheme_Object *result = NULL; - /* hash table to store visited values to avoid infinite loops */ + // hash table to store visited values to avoid infinite loops Scheme_Hash_Table *visited = NULL; MZ_GC_DECL_REG(2); @@ -2941,19 +2999,18 @@ vim_to_mzscheme_impl(typval_T *vim_value, int depth, Scheme_Hash_Table *visited) MZ_GC_VAR_IN_REG(1, visited); MZ_GC_REG(); - /* Avoid infinite recursion */ + // Avoid infinite recursion if (depth > 100) { MZ_GC_UNREG(); return scheme_void; } - /* Check if we run into a recursive loop. The item must be in visited - * then and we can use it again. - */ + // Check if we run into a recursive loop. The item must be in visited + // then and we can use it again. result = scheme_hash_get(visited, (Scheme_Object *)vim_value); MZ_GC_CHECK(); - if (result != NULL) /* found, do nothing */ + if (result != NULL) // found, do nothing new_value = FALSE; else if (vim_value->v_type == VAR_STRING) { @@ -3046,7 +3103,7 @@ vim_to_mzscheme_impl(typval_T *vim_value, int depth, Scheme_Hash_Table *visited) MZ_GC_VAR_IN_REG(0, funcname); MZ_GC_REG(); - /* FIXME: func_ref() and func_unref() are needed. */ + // FIXME: func_ref() and func_unref() are needed. funcname = scheme_make_byte_string((char *)vim_value->vval.v_string); MZ_GC_CHECK(); result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, @@ -3067,8 +3124,8 @@ vim_to_mzscheme_impl(typval_T *vim_value, int depth, Scheme_Hash_Table *visited) MZ_GC_VAR_IN_REG(0, funcname); MZ_GC_REG(); - /* FIXME: func_ref() and func_unref() are needed. */ - /* TODO: Support pt_dict and pt_argv. */ + // FIXME: func_ref() and func_unref() are needed. + // TODO: Support pt_dict and pt_argv. funcname = scheme_make_byte_string( (char *)partial_name(vim_value->vval.v_partial)); MZ_GC_CHECK(); @@ -3118,7 +3175,7 @@ mzscheme_to_vim(Scheme_Object *obj, typval_T *tv) status = mzscheme_to_vim_impl(obj, tv, 1, visited); for (i = 0; i < visited->size; ++i) { - /* free up remembered objects */ + // free up remembered objects if (visited->vals[i] != NULL) free_tv((typval_T *)visited->vals[i]); } @@ -3139,7 +3196,7 @@ mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, MZ_GC_REG(); MZ_GC_CHECK(); - if (depth > 100) /* limit the deepest recursion level */ + if (depth > 100) // limit the deepest recursion level { tv->v_type = VAR_NUMBER; tv->vval.v_number = 0; @@ -3201,7 +3258,7 @@ mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, int i; Scheme_Object *curr = NULL; Scheme_Object *cval = NULL; - /* temporary var to hold current element of vectors and pairs */ + // temporary var to hold current element of vectors and pairs typval_T *v; MZ_GC_DECL_REG(2); @@ -3218,8 +3275,8 @@ mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, status = FAIL; else { - /* add the value in advance to allow handling of self-referential - * data structures */ + // add the value in advance to allow handling of self-referential + // data structures typval_T *visited_tv = ALLOC_ONE(typval_T); copy_tv(tv, visited_tv); scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv); @@ -3253,8 +3310,8 @@ mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, if (status == FAIL) break; } - /* improper list not terminated with null - * need to handle the last element */ + // improper list not terminated with null + // need to handle the last element if (status == OK && !SCHEME_NULLP(curr)) { status = mzscheme_to_vim_impl(cval, v, depth + 1, visited); @@ -3265,7 +3322,7 @@ mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, } } } - /* nothing to do for scheme_null */ + // nothing to do for scheme_null vim_free(v); } MZ_GC_UNREG(); @@ -3301,10 +3358,10 @@ mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, { if (((Scheme_Hash_Table *) obj)->vals[i] != NULL) { - /* generate item for `display'ed Scheme key */ + // generate item for `display'ed Scheme key dictitem_T *item = dictitem_alloc((char_u *)string_to_line( ((Scheme_Hash_Table *) obj)->keys[i])); - /* convert Scheme val to Vim and add it to the dict */ + // convert Scheme val to Vim and add it to the dict if (mzscheme_to_vim_impl(((Scheme_Hash_Table *) obj)->vals[i], &item->di_tv, depth + 1, visited) == FAIL || dict_add(dict, item) == FAIL) @@ -3321,7 +3378,7 @@ mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, } else { - /* `display' any other value to string */ + // `display' any other value to string tv->v_type = VAR_STRING; tv->vval.v_string = (char_u *)string_to_line(obj); } @@ -3329,7 +3386,9 @@ mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, return status; } -/* Scheme prim procedure wrapping Vim funcref */ +/* + * Scheme prim procedure wrapping Vim funcref + */ static Scheme_Object * vim_funcref(void *name, int argc, Scheme_Object **argv) { @@ -3546,7 +3605,8 @@ raise_if_error(void) raise_vim_exn(NULL); } -/* get buffer: +/* + * get buffer: * either current * or passed as argv[argnum] with checks */ @@ -3564,7 +3624,8 @@ get_buffer_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) return b; } -/* get window: +/* + * get window: * either current * or passed as argv[argnum] with checks */ @@ -3582,7 +3643,9 @@ get_window_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) return w; } -/* get valid Vim buffer from Scheme_Object* */ +/* + * get valid Vim buffer from Scheme_Object* + */ buf_T *get_valid_buffer(void *obj) { buf_T *buf = ((vim_mz_buffer *)obj)->buf; @@ -3592,7 +3655,9 @@ buf_T *get_valid_buffer(void *obj) return buf; } -/* get valid Vim window from Scheme_Object* */ +/* + * get valid Vim window from Scheme_Object* + */ win_T *get_valid_window(void *obj) { win_T *win = ((vim_mz_window *)obj)->win; @@ -3631,8 +3696,8 @@ mz_fix_cursor(int lo, int hi, int extra) { if (curwin->w_cursor.lnum >= lo) { - /* Adjust the cursor position if it's in/after the changed - * lines. */ + // Adjust the cursor position if it's in/after the changed + // lines. if (curwin->w_cursor.lnum >= hi) { curwin->w_cursor.lnum += extra; @@ -3704,7 +3769,9 @@ static Vim_Prim prims[]= {vim_window_validp, "win-valid?", 1, 1} }; -/* return MzScheme wrapper for curbuf */ +/* + * return MzScheme wrapper for curbuf + */ static vim_mz_buffer * get_vim_curr_buffer(void) { @@ -3714,7 +3781,9 @@ get_vim_curr_buffer(void) return BUFFER_REF(curbuf); } -/* return MzScheme wrapper for curwin */ +/* + * return MzScheme wrapper for curwin + */ static vim_mz_window * get_vim_curr_window(void) { @@ -3742,7 +3811,7 @@ make_modules(void) MZ_GC_CHECK(); mod = scheme_primitive_module(vimext_symbol, environment); MZ_GC_CHECK(); - /* all prims made closed so they can access their own names */ + // all prims made closed so they can access their own names for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++) { Vim_Prim *prim = prims + i; @@ -3769,7 +3838,9 @@ sandbox_check(void) raise_vim_exn(_("not allowed in the Vim sandbox")); } -/* security guards to force Vim's sandbox restrictions on MzScheme level */ +/* + * security guards to force Vim's sandbox restrictions on MzScheme level + */ static Scheme_Object * sandbox_file_guard(int argc UNUSED, Scheme_Object **argv) { |