diff options
Diffstat (limited to 'src/nvim/ex_cmds2.c')
-rw-r--r-- | src/nvim/ex_cmds2.c | 390 |
1 files changed, 188 insertions, 202 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 575c5c9cbd..5d40d7a16a 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -6,79 +6,53 @@ /// Some more functions for command line commands #include <assert.h> +#include <fcntl.h> #include <inttypes.h> #include <stdbool.h> #include <string.h> -#include <fcntl.h> -#include "nvim/vim.h" #include "nvim/ascii.h" +#include "nvim/vim.h" #ifdef HAVE_LOCALE_H # include <locale.h> #endif -#include "nvim/ex_cmds2.h" +#include "nvim/api/private/defs.h" +#include "nvim/api/private/helpers.h" #include "nvim/buffer.h" #include "nvim/change.h" #include "nvim/charset.h" #include "nvim/debugger.h" #include "nvim/eval/userfunc.h" #include "nvim/ex_cmds.h" +#include "nvim/ex_cmds2.h" #include "nvim/ex_eval.h" #include "nvim/ex_getln.h" #include "nvim/fileio.h" +#include "nvim/garray.h" +#include "nvim/lua/executor.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" +#include "nvim/memory.h" #include "nvim/message.h" #include "nvim/misc1.h" -#include "nvim/garray.h" -#include "nvim/memory.h" #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/os/fs_defs.h" +#include "nvim/os/shell.h" #include "nvim/os_unix.h" #include "nvim/path.h" +#include "nvim/profile.h" #include "nvim/quickfix.h" #include "nvim/regexp.h" #include "nvim/strings.h" #include "nvim/undo.h" #include "nvim/version.h" #include "nvim/window.h" -#include "nvim/profile.h" -#include "nvim/os/shell.h" -#include "nvim/os/fs_defs.h" -#include "nvim/api/private/helpers.h" -#include "nvim/api/private/defs.h" -#include "nvim/lua/executor.h" - /// Growarray to store info about already sourced scripts. -/// Also store the dev/ino, so that we don't have to stat() each -/// script when going through the list. -typedef struct scriptitem_S { - char_u *sn_name; - bool file_id_valid; - FileID file_id; - bool sn_prof_on; ///< true when script is/was profiled - bool sn_pr_force; ///< forceit: profile functions in this script - proftime_T sn_pr_child; ///< time set when going into first child - int sn_pr_nest; ///< nesting for sn_pr_child - // profiling the script as a whole - int sn_pr_count; ///< nr of times sourced - proftime_T sn_pr_total; ///< time spent in script + children - proftime_T sn_pr_self; ///< time spent in script itself - proftime_T sn_pr_start; ///< time at script start - proftime_T sn_pr_children; ///< time in children after script start - // profiling the script per line - garray_T sn_prl_ga; ///< things stored for every line - proftime_T sn_prl_start; ///< start time for current line - proftime_T sn_prl_children; ///< time spent in children for this line - proftime_T sn_prl_wait; ///< wait start time for current line - linenr_T sn_prl_idx; ///< index of line being timed; -1 if none - int sn_prl_execed; ///< line being timed was executed -} scriptitem_T; - static garray_T script_items = { 0, 0, sizeof(scriptitem_T), 4, NULL }; #define SCRIPT_ITEM(id) (((scriptitem_T *)script_items.ga_data)[(id) - 1]) @@ -109,20 +83,20 @@ struct source_cookie { vimconv_T conv; ///< type of conversion }; -# define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)]) +#define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)]) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ex_cmds2.c.generated.h" #endif -static char_u *profile_fname = NULL; +static char_u *profile_fname = NULL; /// ":profile cmd args" void ex_profile(exarg_T *eap) { static proftime_T pause_time; - char_u *e; + char_u *e; int len; e = skiptowhite(eap->arg); @@ -277,7 +251,7 @@ void set_context_in_profile_cmd(expand_T *xp, const char *arg) /// Dump the profiling info. void profile_dump(void) { - FILE *fd; + FILE *fd; if (profile_fname != NULL) { fd = os_fopen((char *)profile_fname, "w"); @@ -317,7 +291,7 @@ static void profile_reset(void) } // Reset functions. - size_t n = func_hashtab.ht_used; + size_t n = func_hashtab.ht_used; hashitem_T *hi = func_hashtab.ht_array; for (; n > (size_t)0; hi++) { @@ -362,11 +336,11 @@ static void profile_init(scriptitem_T *si) } /// Save time when starting to invoke another script or function. -void script_prof_save( - proftime_T *tm // place to store wait time -) +/// +/// @param tm place to store wait time +void script_prof_save(proftime_T *tm) { - scriptitem_T *si; + scriptitem_T *si; if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) { si = &SCRIPT_ITEM(current_sctx.sc_sid); @@ -380,7 +354,7 @@ void script_prof_save( /// Count time spent in children after invoking another script or function. void script_prof_restore(proftime_T *tm) { - scriptitem_T *si; + scriptitem_T *si; if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) { si = &SCRIPT_ITEM(current_sctx.sc_sid); @@ -412,9 +386,9 @@ void prof_inchar_exit(void) /// Dump the profiling results for all scripts in file "fd". static void script_dump_profile(FILE *fd) { - scriptitem_T *si; - FILE *sfd; - sn_prl_T *pp; + scriptitem_T *si; + FILE *sfd; + sn_prl_T *pp; for (int id = 1; id <= script_items.ga_len; id++) { si = &SCRIPT_ITEM(id); @@ -699,7 +673,7 @@ bool check_changed_any(bool hidden, bool unload) int i; int bufnum = 0; size_t bufcount = 0; - int *bufnrs; + int *bufnrs; // Make a list of all buffers, with the most important ones first. FOR_ALL_BUFFERS(buf) { @@ -829,7 +803,7 @@ int check_fname(void) int buf_write_all(buf_T *buf, int forceit) { int retval; - buf_T *old_curbuf = curbuf; + buf_T *old_curbuf = curbuf; retval = (buf_write(buf, buf->b_ffname, buf->b_fname, (linenr_T)1, buf->b_ml.ml_line_count, NULL, @@ -852,7 +826,7 @@ int buf_write_all(buf_T *buf, int forceit) /// Return a pointer to the start of the next argument. static char_u *do_one_arg(char_u *str) { - char_u *p; + char_u *p; bool inbacktick; inbacktick = false; @@ -936,8 +910,8 @@ static int do_arglist(char_u *str, int what, int after, bool will_edit) { garray_T new_ga; int exp_count; - char_u **exp_files; - char_u *p; + char_u **exp_files; + char_u *p; int match; int arg_escaped = true; @@ -1037,9 +1011,8 @@ static bool editing_arg_idx(win_T *win) || (win->w_buffer->b_fnum != WARGLIST(win)[win->w_arg_idx].ae_fnum && (win->w_buffer->b_ffname == NULL - || !(path_full_compare( - alist_name(&WARGLIST(win)[win->w_arg_idx]), - win->w_buffer->b_ffname, true, true) & kEqualFiles)))); + || !(path_full_compare(alist_name(&WARGLIST(win)[win->w_arg_idx]), + win->w_buffer->b_ffname, true, true) & kEqualFiles)))); } /// Check if window "win" is editing the w_arg_idx file in its argument list. @@ -1102,7 +1075,7 @@ void ex_args(exarg_T *eap) xfree(items); } } else if (eap->cmdidx == CMD_arglocal) { - garray_T *gap = &curwin->w_alist->al_ga; + garray_T *gap = &curwin->w_alist->al_ga; // ":argslocal": make a local copy of the global argument list. ga_grow(gap, GARGCOUNT); @@ -1158,7 +1131,7 @@ void ex_argument(exarg_T *eap) void do_argfile(exarg_T *eap, int argn) { int other; - char_u *p; + char_u *p; int old_arg_idx = curwin->w_arg_idx; if (argn < 0 || argn >= ARGCOUNT) { @@ -1310,9 +1283,9 @@ void ex_argdelete(exarg_T *eap) curwin->w_arg_idx = (int)eap->line1; } if (ARGCOUNT == 0) { - curwin->w_arg_idx = 0; + curwin->w_arg_idx = 0; } else if (curwin->w_arg_idx >= ARGCOUNT) { - curwin->w_arg_idx = ARGCOUNT - 1; + curwin->w_arg_idx = ARGCOUNT - 1; } } } else { @@ -1325,11 +1298,11 @@ void ex_argdelete(exarg_T *eap) void ex_listdo(exarg_T *eap) { int i; - win_T *wp; - tabpage_T *tp; + win_T *wp; + tabpage_T *tp; int next_fnum = 0; - char_u *save_ei = NULL; - char_u *p_shm_save; + char_u *save_ei = NULL; + char_u *p_shm_save; if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) { // Don't do syntax HL autocommands. Skipping the syntax file is a @@ -1610,9 +1583,9 @@ char_u *get_arglist_name(expand_T *xp FUNC_ATTR_UNUSED, int idx) /// ":compiler[!] {name}" void ex_compiler(exarg_T *eap) { - char_u *buf; - char_u *old_cur_comp = NULL; - char_u *p; + char_u *buf; + char_u *old_cur_comp = NULL; + char_u *p; if (*eap->arg == NUL) { // List all compiler scripts. @@ -1641,10 +1614,10 @@ void ex_compiler(exarg_T *eap) do_unlet(S_LEN("b:current_compiler"), true); snprintf((char *)buf, bufsize, "compiler/%s.vim", eap->arg); - if (source_runtime(buf, DIP_ALL) == FAIL) { + if (source_runtime((char *)buf, DIP_ALL) == FAIL) { // Try lua compiler snprintf((char *)buf, bufsize, "compiler/%s.lua", eap->arg); - if (source_runtime(buf, DIP_ALL) == FAIL) { + if (source_runtime((char *)buf, DIP_ALL) == FAIL) { EMSG2(_("E666: compiler not supported: %s"), eap->arg); } } @@ -1703,9 +1676,9 @@ void init_pyxversion(void) // otherwise return 0. static int requires_py_version(char_u *filename) { - FILE *file; - int requires_py_version = 0; - int i, lines; + FILE *file; + int requires_py_version = 0; + int i, lines; lines = (int)p_mls; if (lines < 0) { @@ -1824,7 +1797,7 @@ static void cmd_source(char_u *fname, exarg_T *eap) || eap->cstack->cs_idx >= 0); // ":source" read ex commands - } else if (do_source(fname, false, DOSO_NONE) == FAIL) { + } else if (do_source((char *)fname, false, DOSO_NONE) == FAIL) { EMSG2(_(e_notopen), fname); } } @@ -1940,9 +1913,30 @@ static char_u *get_str_line(int c, void *cookie, int indent, bool do_concat) return ga.ga_data; } -static int source_using_linegetter(void *cookie, - LineGetter fgetline, - const char *traceback_name) +/// Create a new script item and allocate script-local vars. @see new_script_vars +/// +/// @param name File name of the script. NULL for anonymous :source. +/// @param[out] sid_out SID of the new item. +/// @return pointer to the created script item. +scriptitem_T *new_script_item(char_u *const name, scid_T *const sid_out) +{ + static scid_T last_current_SID = 0; + const scid_T sid = ++last_current_SID; + if (sid_out != NULL) { + *sid_out = sid; + } + ga_grow(&script_items, (int)(sid - script_items.ga_len)); + while (script_items.ga_len < sid) { + script_items.ga_len++; + SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; + SCRIPT_ITEM(script_items.ga_len).sn_prof_on = false; + } + SCRIPT_ITEM(sid).sn_name = name; + new_script_vars(sid); // Allocate the local script variables to use for this script. + return &SCRIPT_ITEM(sid); +} + +static int source_using_linegetter(void *cookie, LineGetter fgetline, const char *traceback_name) { char_u *save_sourcing_name = sourcing_name; linenr_T save_sourcing_lnum = sourcing_lnum; @@ -1951,9 +1945,9 @@ static int source_using_linegetter(void *cookie, sourcing_name = (char_u *)traceback_name; } else { snprintf((char *)sourcing_name_buf, sizeof(sourcing_name_buf), - "%s called at %s:%"PRIdLINENR, traceback_name, save_sourcing_name, + "%s called at %s:%" PRIdLINENR, traceback_name, save_sourcing_name, save_sourcing_lnum); - sourcing_name = sourcing_name_buf; + sourcing_name = sourcing_name_buf; // -V507 reassigned below, before return. } sourcing_lnum = 0; @@ -1987,13 +1981,13 @@ static void cmd_source_buffer(const exarg_T *const eap) if (ga.ga_len > 400) { ga_set_growsize(&ga, MAX(ga.ga_len, 8000)); } - ga_concat(&ga, ml_get(curr_lnum)); + ga_concat(&ga, (char *)ml_get(curr_lnum)); ga_append(&ga, NL); } ((char_u *)ga.ga_data)[ga.ga_len - 1] = NUL; const GetStrLineCookie cookie = { - .buf = ga.ga_data, - .offset = 0, + .buf = ga.ga_data, + .offset = 0, }; if (curbuf->b_fname && path_with_extension((const char *)curbuf->b_fname, "lua")) { @@ -2012,8 +2006,8 @@ static void cmd_source_buffer(const exarg_T *const eap) int do_source_str(const char *cmd, const char *traceback_name) { GetStrLineCookie cookie = { - .buf = (char_u *)cmd, - .offset = 0, + .buf = (char_u *)cmd, + .offset = 0, }; return source_using_linegetter((void *)&cookie, get_str_line, traceback_name); } @@ -2030,23 +2024,22 @@ int do_source_str(const char *cmd, const char *traceback_name) /// @param is_vimrc DOSO_ value /// /// @return FAIL if file could not be opened, OK otherwise -int do_source(char_u *fname, int check_other, int is_vimrc) +int do_source(char *fname, int check_other, int is_vimrc) { struct source_cookie cookie; - char_u *save_sourcing_name; + char_u *save_sourcing_name; linenr_T save_sourcing_lnum; - char_u *p; - char_u *fname_exp; - char_u *firstline = NULL; + char_u *p; + char_u *fname_exp; + char_u *firstline = NULL; int retval = FAIL; - static scid_T last_current_SID = 0; static int last_current_SID_seq = 0; int save_debug_break_level = debug_break_level; - scriptitem_T *si = NULL; + scriptitem_T *si = NULL; proftime_T wait_start; bool trigger_source_post = false; - p = expand_env_save(fname); + p = expand_env_save((char_u *)fname); if (p == NULL) { return retval; } @@ -2115,7 +2108,7 @@ int do_source(char_u *fname, int check_other, int is_vimrc) verbose_leave(); } if (is_vimrc == DOSO_VIMRC) { - vimrc_found(fname_exp, (char_u *)"MYVIMRC"); + vimrc_found((char *)fname_exp, "MYVIMRC"); } #ifdef USE_CRNL @@ -2186,15 +2179,7 @@ int do_source(char_u *fname, int check_other, int is_vimrc) } } if (current_sctx.sc_sid == 0) { - current_sctx.sc_sid = ++last_current_SID; - ga_grow(&script_items, (int)(current_sctx.sc_sid - script_items.ga_len)); - while (script_items.ga_len < current_sctx.sc_sid) { - script_items.ga_len++; - SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; - SCRIPT_ITEM(script_items.ga_len).sn_prof_on = false; - } - si = &SCRIPT_ITEM(current_sctx.sc_sid); - si->sn_name = fname_exp; + si = new_script_item(fname_exp, ¤t_sctx.sc_sid); fname_exp = vim_strsave(si->sn_name); // used for autocmd if (file_id_ok) { si->file_id_valid = true; @@ -2202,9 +2187,6 @@ int do_source(char_u *fname, int check_other, int is_vimrc) } else { si->file_id_valid = false; } - - // Allocate the local script variables to use for this script. - new_script_vars(current_sctx.sc_sid); } if (l_do_profiling == PROF_YES) { @@ -2343,7 +2325,7 @@ void ex_scriptnames(exarg_T *eap) } } -# if defined(BACKSLASH_IN_FILENAME) +#if defined(BACKSLASH_IN_FILENAME) /// Fix slashes in the list of script names for 'shellslash'. void scriptnames_slash_adjust(void) { @@ -2354,7 +2336,7 @@ void scriptnames_slash_adjust(void) } } -# endif +#endif /// Get a pointer to a script name. Used for ":verbose set". /// Message appended to "Last set from " @@ -2363,35 +2345,40 @@ char_u *get_scriptname(LastSet last_set, bool *should_free) *should_free = false; switch (last_set.script_ctx.sc_sid) { - case SID_MODELINE: - return (char_u *)_("modeline"); - case SID_CMDARG: - return (char_u *)_("--cmd argument"); - case SID_CARG: - return (char_u *)_("-c argument"); - case SID_ENV: - return (char_u *)_("environment variable"); - case SID_ERROR: - return (char_u *)_("error handler"); - case SID_WINLAYOUT: - return (char_u *)_("changed window size"); - case SID_LUA: - return (char_u *)_("Lua"); - case SID_API_CLIENT: - vim_snprintf((char *)IObuff, IOSIZE, - _("API client (channel id %" PRIu64 ")"), - last_set.channel_id); + case SID_MODELINE: + return (char_u *)_("modeline"); + case SID_CMDARG: + return (char_u *)_("--cmd argument"); + case SID_CARG: + return (char_u *)_("-c argument"); + case SID_ENV: + return (char_u *)_("environment variable"); + case SID_ERROR: + return (char_u *)_("error handler"); + case SID_WINLAYOUT: + return (char_u *)_("changed window size"); + case SID_LUA: + return (char_u *)_("Lua"); + case SID_API_CLIENT: + snprintf((char *)IObuff, IOSIZE, _("API client (channel id %" PRIu64 ")"), last_set.channel_id); + return IObuff; + case SID_STR: + return (char_u *)_("anonymous :source"); + default: { + char_u *const sname = SCRIPT_ITEM(last_set.script_ctx.sc_sid).sn_name; + if (sname == NULL) { + snprintf((char *)IObuff, IOSIZE, _("anonymous :source (script id %d)"), + last_set.script_ctx.sc_sid); return IObuff; - case SID_STR: - return (char_u *)_("anonymous :source"); - default: - *should_free = true; - return home_replace_save(NULL, - SCRIPT_ITEM(last_set.script_ctx.sc_sid).sn_name); + } + + *should_free = true; + return home_replace_save(NULL, sname); + } } } -# if defined(EXITFREE) +#if defined(EXITFREE) void free_scriptnames(void) { profile_reset(); @@ -2399,11 +2386,11 @@ void free_scriptnames(void) # define FREE_SCRIPTNAME(item) xfree((item)->sn_name) GA_DEEP_CLEAR(&script_items, scriptitem_T, FREE_SCRIPTNAME); } -# endif +#endif linenr_T get_sourced_lnum(LineGetter fgetline, void *cookie) { - return fgetline == getsourceline + return fgetline == getsourceline ? ((struct source_cookie *)cookie)->sourcing_lnum : sourcing_lnum; } @@ -2462,7 +2449,7 @@ char_u *getsourceline(int c, void *cookie, int indent, bool do_concat) garray_T ga; ga_init(&ga, (int)sizeof(char_u), 400); - ga_concat(&ga, line); + ga_concat(&ga, (char *)line); while (sp->nextline != NULL && concat_continued_line(&ga, 400, sp->nextline, STRLEN(sp->nextline))) { @@ -2476,7 +2463,7 @@ char_u *getsourceline(int c, void *cookie, int indent, bool do_concat) } if (line != NULL && sp->conv.vc_type != CONV_NONE) { - char_u *s; + char_u *s; // Convert the encoding of the script line. s = string_convert(&sp->conv, line, NULL); @@ -2502,7 +2489,7 @@ static char_u *get_one_sourceline(struct source_cookie *sp) garray_T ga; int len; int c; - char_u *buf; + char_u *buf; #ifdef USE_CRNL int has_cr; // CR-LF found #endif @@ -2605,8 +2592,8 @@ retry: /// until later and we need to store the time now. void script_line_start(void) { - scriptitem_T *si; - sn_prl_T *pp; + scriptitem_T *si; + sn_prl_T *pp; if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; @@ -2637,7 +2624,7 @@ void script_line_start(void) /// Called when actually executing a function line. void script_line_exec(void) { - scriptitem_T *si; + scriptitem_T *si; if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; @@ -2651,8 +2638,8 @@ void script_line_exec(void) /// Called when done with a function line. void script_line_end(void) { - scriptitem_T *si; - sn_prl_T *pp; + scriptitem_T *si; + sn_prl_T *pp; if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; @@ -2677,8 +2664,8 @@ void script_line_end(void) /// Without the multi-byte feature it's simply ignored. void ex_scriptencoding(exarg_T *eap) { - struct source_cookie *sp; - char_u *name; + struct source_cookie *sp; + char_u *name; if (!getline_equal(eap->getline, eap->cookie, getsourceline)) { EMSG(_("E167: :scriptencoding used outside of a sourced file")); @@ -2743,14 +2730,13 @@ void do_finish(exarg_T *eap, int reanimate) bool source_finished(LineGetter fgetline, void *cookie) { return getline_equal(fgetline, cookie, getsourceline) - && ((struct source_cookie *)getline_cookie( - fgetline, cookie))->finished; + && ((struct source_cookie *)getline_cookie(fgetline, cookie))->finished; } /// ":checktime [buffer]" void ex_checktime(exarg_T *eap) { - buf_T *buf; + buf_T *buf; int save_no_check_timestamps = no_check_timestamps; no_check_timestamps = 0; @@ -2790,17 +2776,17 @@ char *get_mess_lang(void) { char *p; -# ifdef HAVE_GET_LOCALE_VAL -# if defined(LC_MESSAGES) +#ifdef HAVE_GET_LOCALE_VAL +# if defined(LC_MESSAGES) p = get_locale_val(LC_MESSAGES); -# else +# else // This is necessary for Win32, where LC_MESSAGES is not defined and $LANG // may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME // and LC_MONETARY may be set differently for a Japanese working in the // US. p = get_locale_val(LC_COLLATE); -# endif -# else +# endif +#else p = os_getenv("LC_ALL"); if (!is_valid_mess_lang(p)) { p = os_getenv("LC_MESSAGES"); @@ -2808,7 +2794,7 @@ char *get_mess_lang(void) p = os_getenv("LANG"); } } -# endif +#endif return is_valid_mess_lang(p) ? p : NULL; } @@ -2817,7 +2803,7 @@ char *get_mess_lang(void) /// Get the language used for messages from the environment. static char_u *get_mess_env(void) { - char_u *p; + char_u *p; p = (char_u *)os_getenv("LC_ALL"); if (p == NULL) { @@ -2846,37 +2832,37 @@ void set_lang_var(void) { const char *loc; -# ifdef HAVE_GET_LOCALE_VAL +#ifdef HAVE_GET_LOCALE_VAL loc = get_locale_val(LC_CTYPE); -# else +#else // setlocale() not supported: use the default value loc = "C"; -# endif +#endif set_vim_var_string(VV_CTYPE, loc, -1); // When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall // back to LC_CTYPE if it's empty. -# ifdef HAVE_WORKING_LIBINTL +#ifdef HAVE_WORKING_LIBINTL loc = (char *)get_mess_env(); -# elif defined(LC_MESSAGES) +#elif defined(LC_MESSAGES) loc = get_locale_val(LC_MESSAGES); -# else +#else // In Windows LC_MESSAGES is not defined fallback to LC_CTYPE loc = get_locale_val(LC_CTYPE); -# endif +#endif set_vim_var_string(VV_LANG, loc, -1); -# ifdef HAVE_GET_LOCALE_VAL +#ifdef HAVE_GET_LOCALE_VAL loc = get_locale_val(LC_TIME); -# endif +#endif set_vim_var_string(VV_LC_TIME, loc, -1); -# ifdef HAVE_GET_LOCALE_VAL +#ifdef HAVE_GET_LOCALE_VAL loc = get_locale_val(LC_COLLATE); -# else +#else // setlocale() not supported: use the default value loc = "C"; -# endif +#endif set_vim_var_string(VV_COLLATE, loc, -1); } @@ -2888,16 +2874,16 @@ void set_lang_var(void) /// void ex_language(exarg_T *eap) { - char *loc; - char_u *p; - char_u *name; + char *loc; + char_u *p; + char_u *name; int what = LC_ALL; - char *whatstr = ""; -#ifdef LC_MESSAGES -# define VIM_LC_MESSAGES LC_MESSAGES -#else -# define VIM_LC_MESSAGES 6789 -#endif + char *whatstr = ""; +# ifdef LC_MESSAGES +# define VIM_LC_MESSAGES LC_MESSAGES +# else +# define VIM_LC_MESSAGES 6789 +# endif name = eap->arg; @@ -2926,43 +2912,43 @@ void ex_language(exarg_T *eap) } if (*name == NUL) { -#ifdef HAVE_WORKING_LIBINTL +# ifdef HAVE_WORKING_LIBINTL if (what == VIM_LC_MESSAGES) { p = get_mess_env(); } else { -#endif - p = (char_u *)setlocale(what, NULL); -#ifdef HAVE_WORKING_LIBINTL - } -#endif +# endif + p = (char_u *)setlocale(what, NULL); +# ifdef HAVE_WORKING_LIBINTL + } +# endif if (p == NULL || *p == NUL) { p = (char_u *)"Unknown"; } smsg(_("Current %slanguage: \"%s\""), whatstr, p); } else { -#ifndef LC_MESSAGES +# ifndef LC_MESSAGES if (what == VIM_LC_MESSAGES) { loc = ""; } else { -#endif - loc = setlocale(what, (char *)name); -#ifdef LC_NUMERIC - // Make sure strtod() uses a decimal point, not a comma. - setlocale(LC_NUMERIC, "C"); -#endif -#ifndef LC_MESSAGES - } -#endif +# endif + loc = setlocale(what, (char *)name); +# ifdef LC_NUMERIC + // Make sure strtod() uses a decimal point, not a comma. + setlocale(LC_NUMERIC, "C"); +# endif +# ifndef LC_MESSAGES + } +# endif if (loc == NULL) { EMSG2(_("E197: Cannot set language to \"%s\""), name); } else { -#ifdef HAVE_NL_MSG_CAT_CNTR +# ifdef HAVE_NL_MSG_CAT_CNTR // Need to do this for GNU gettext, otherwise cached translations // will be used again. extern int _nl_msg_cat_cntr; _nl_msg_cat_cntr++; -#endif +# endif // Reset $LC_ALL, otherwise it would overrule everything. os_setenv("LC_ALL", "", 1); @@ -2991,7 +2977,7 @@ void ex_language(exarg_T *eap) static char_u **locales = NULL; // Array of all available locales -#ifndef WIN32 +# ifndef WIN32 static bool did_init_locales = false; /// Return an array of strings for all available locales + NULL for the @@ -2999,7 +2985,7 @@ static bool did_init_locales = false; static char_u **find_locales(void) { garray_T locales_ga; - char_u *loc; + char_u *loc; char *saveptr = NULL; // Find all available locales by running command "locale -a". If this @@ -3026,20 +3012,20 @@ static char_u **find_locales(void) ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; return (char_u **)locales_ga.ga_data; } -#endif +# endif /// Lazy initialization of all available locales. static void init_locales(void) { -#ifndef WIN32 +# ifndef WIN32 if (!did_init_locales) { did_init_locales = true; locales = find_locales(); } -#endif +# endif } -# if defined(EXITFREE) +# if defined(EXITFREE) void free_locales(void) { int i; @@ -3051,7 +3037,7 @@ void free_locales(void) } } -# endif +# endif /// Function given to ExpandGeneric() to obtain the possible arguments of the /// ":language" command. @@ -3137,7 +3123,7 @@ static void script_host_do_range(char *name, exarg_T *eap) /// ":drop" /// Opens the first argument in a window. When there are two or more arguments /// the argument list is redefined. -void ex_drop(exarg_T *eap) +void ex_drop(exarg_T *eap) { bool split = false; buf_T *buf; |