diff options
Diffstat (limited to 'src/misc2.c')
-rw-r--r-- | src/misc2.c | 614 |
1 files changed, 240 insertions, 374 deletions
diff --git a/src/misc2.c b/src/misc2.c index e18de18258..544a45a315 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -11,6 +11,29 @@ * misc2.c: Various functions. */ #include "vim.h" +#include "misc2.h" +#include "blowfish.h" +#include "charset.h" +#include "edit.h" +#include "eval.h" +#include "ex_docmd.h" +#include "ex_getln.h" +#include "fileio.h" +#include "fold.h" +#include "mbyte.h" +#include "memfile.h" +#include "memline.h" +#include "message.h" +#include "misc1.h" +#include "move.h" +#include "option.h" +#include "os_unix.h" +#include "screen.h" +#include "tag.h" +#include "term.h" +#include "ui.h" +#include "window.h" +#include "os/os.h" static char_u *username = NULL; /* cached result of mch_get_user_name() */ @@ -22,7 +45,7 @@ static int coladvance2 __ARGS((pos_T *pos, int addspaces, int finetune, /* * Return TRUE if in the current mode we need to use virtual. */ -int virtual_active() { +int virtual_active(void) { /* While an operator is being executed we return "virtual_op", because * VIsual_active has already been reset, thus we can't check for "block" * being used. */ @@ -36,7 +59,7 @@ int virtual_active() { /* * Get the screen position of the cursor. */ -int getviscol() { +int getviscol(void) { colnr_T x; getvvcol(curwin, &curwin->w_cursor, &x, NULL, NULL); @@ -46,9 +69,7 @@ int getviscol() { /* * Get the screen position of character col with a coladd in the cursor line. */ -int getviscol2(col, coladd) -colnr_T col; -colnr_T coladd; +int getviscol2(colnr_T col, colnr_T coladd) { colnr_T x; pos_T pos; @@ -65,8 +86,7 @@ colnr_T coladd; * cursor in that column. * The caller must have saved the cursor line for undo! */ -int coladvance_force(wcol) -colnr_T wcol; +int coladvance_force(colnr_T wcol) { int rc = coladvance2(&curwin->w_cursor, TRUE, FALSE, wcol); @@ -89,8 +109,7 @@ colnr_T wcol; * * return OK if desired column is reached, FAIL if not */ -int coladvance(wcol) -colnr_T wcol; +int coladvance(colnr_T wcol) { int rc = getvpos(&curwin->w_cursor, wcol); @@ -108,18 +127,18 @@ colnr_T wcol; * Return in "pos" the position of the cursor advanced to screen column "wcol". * return OK if desired column is reached, FAIL if not */ -int getvpos(pos, wcol) -pos_T *pos; -colnr_T wcol; +int getvpos(pos_T *pos, colnr_T wcol) { return coladvance2(pos, FALSE, virtual_active(), wcol); } -static int coladvance2(pos, addspaces, finetune, wcol) -pos_T *pos; -int addspaces; /* change the text to achieve our goal? */ -int finetune; /* change char offset for the exact column */ -colnr_T wcol; /* column to move to */ +static int +coladvance2 ( + pos_T *pos, + int addspaces, /* change the text to achieve our goal? */ + int finetune, /* change char offset for the exact column */ + colnr_T wcol /* column to move to */ +) { int idx; char_u *ptr; @@ -286,7 +305,7 @@ colnr_T wcol; /* column to move to */ /* * Increment the cursor position. See inc() for return values. */ -int inc_cursor() { +int inc_cursor(void) { return inc(&curwin->w_cursor); } @@ -297,8 +316,7 @@ int inc_cursor() { * Return -1 when at the end of file. * Return 0 otherwise. */ -int inc(lp) -pos_T *lp; +int inc(pos_T *lp) { char_u *p = ml_get_pos(lp); @@ -325,8 +343,7 @@ pos_T *lp; /* * incl(lp): same as inc(), but skip the NUL at the end of non-empty lines */ -int incl(lp) -pos_T *lp; +int incl(pos_T *lp) { int r; @@ -341,12 +358,11 @@ pos_T *lp; * Decrement the line pointer 'p' crossing line boundaries as necessary. * Return 1 when crossing a line, -1 when at start of file, 0 otherwise. */ -int dec_cursor() { +int dec_cursor(void) { return dec(&curwin->w_cursor); } -int dec(lp) -pos_T *lp; +int dec(pos_T *lp) { char_u *p; @@ -373,8 +389,7 @@ pos_T *lp; /* * decl(lp): same as dec(), but skip the NUL at the end of non-empty lines */ -int decl(lp) -pos_T *lp; +int decl(pos_T *lp) { int r; @@ -388,9 +403,11 @@ pos_T *lp; * difference between line number and cursor position. Only look for lines that * can be visible, folded lines don't count. */ -linenr_T get_cursor_rel_lnum(wp, lnum) -win_T *wp; -linenr_T lnum; /* line number to get the result for */ +linenr_T +get_cursor_rel_lnum ( + win_T *wp, + linenr_T lnum /* line number to get the result for */ +) { linenr_T cursor = wp->w_cursor.lnum; linenr_T retval = 0; @@ -427,7 +444,7 @@ linenr_T lnum; /* line number to get the result for */ /* * Make sure curwin->w_cursor.lnum is valid. */ -void check_cursor_lnum() { +void check_cursor_lnum(void) { if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { /* If there is a closed fold at the end of the file, put the cursor in * its first line. Otherwise in the last line. */ @@ -442,15 +459,14 @@ void check_cursor_lnum() { /* * Make sure curwin->w_cursor.col is valid. */ -void check_cursor_col() { +void check_cursor_col(void) { check_cursor_col_win(curwin); } /* * Make sure win->w_cursor.col is valid. */ -void check_cursor_col_win(win) -win_T *win; +void check_cursor_col_win(win_T *win) { colnr_T len; colnr_T oldcol = win->w_cursor.col; @@ -495,7 +511,7 @@ win_T *win; /* * make sure curwin->w_cursor in on a valid character */ -void check_cursor() { +void check_cursor(void) { check_cursor_lnum(); check_cursor_col(); } @@ -504,7 +520,7 @@ void check_cursor() { * Make sure curwin->w_cursor is not on the NUL at the end of the line. * Allow it when in Visual mode and 'selection' is not "old". */ -void adjust_cursor_col() { +void adjust_cursor_col(void) { if (curwin->w_cursor.col > 0 && (!VIsual_active || *p_sel == 'o') && gchar_cursor() == NUL) @@ -515,7 +531,7 @@ void adjust_cursor_col() { * When curwin->w_leftcol has changed, adjust the cursor position. * Return TRUE if the cursor was moved. */ -int leftcol_changed() { +int leftcol_changed(void) { long lastcol; colnr_T s, e; int retval = FALSE; @@ -579,21 +595,17 @@ static void mem_pre_alloc_l __ARGS((long_u *sizep)); static void mem_post_alloc __ARGS((void **pp, size_t size)); static void mem_pre_free __ARGS((void **pp)); -static void mem_pre_alloc_s(sizep) -size_t *sizep; +static void mem_pre_alloc_s(size_t *sizep) { *sizep += sizeof(size_t); } -static void mem_pre_alloc_l(sizep) -long_u *sizep; +static void mem_pre_alloc_l(long_u *sizep) { *sizep += sizeof(size_t); } -static void mem_post_alloc(pp, size) -void **pp; -size_t size; +static void mem_post_alloc(void **pp, size_t size) { if (*pp == NULL) return; @@ -610,8 +622,7 @@ size_t size; *pp = (void *)((char *)*pp + sizeof(size_t)); } -static void mem_pre_free(pp) -void **pp; +static void mem_pre_free(void **pp) { long_u size; @@ -628,7 +639,7 @@ void **pp; /* * called on exit via atexit() */ -void vim_mem_profile_dump() { +void vim_mem_profile_dump(void) { int i, j; printf("\r\n"); @@ -673,8 +684,7 @@ void vim_mem_profile_dump() { * Note: if unsigned is 16 bits we can only allocate up to 64K with alloc(). * Use lalloc for larger blocks. */ -char_u * alloc(size) -unsigned size; +char_u *alloc(unsigned size) { return lalloc((long_u)size, TRUE); } @@ -682,8 +692,7 @@ unsigned size; /* * Allocate memory and set all bytes to zero. */ -char_u * alloc_clear(size) -unsigned size; +char_u *alloc_clear(unsigned size) { char_u *p; @@ -696,8 +705,7 @@ unsigned size; /* * alloc() with check for maximum line length */ -char_u * alloc_check(size) -unsigned size; +char_u *alloc_check(unsigned size) { #if !defined(UNIX) && !defined(__EMX__) if (sizeof(int) == 2 && size > 0x7fff) { @@ -713,9 +721,7 @@ unsigned size; /* * Allocate memory like lalloc() and set all bytes to zero. */ -char_u * lalloc_clear(size, message) -long_u size; -int message; +char_u *lalloc_clear(long_u size, int message) { char_u *p; @@ -729,9 +735,7 @@ int message; * Low level memory allocation function. * This is used often, KEEP IT FAST! */ -char_u * lalloc(size, message) -long_u size; -int message; +char_u *lalloc(long_u size, int message) { char_u *p; /* pointer to new storage space */ static int releasing = FALSE; /* don't do mf_release_all() recursive */ @@ -817,9 +821,7 @@ theend: /* * realloc() with memory profiling. */ -void * mem_realloc(ptr, size) -void *ptr; -size_t size; +void *mem_realloc(void *ptr, size_t size) { void *p; @@ -838,8 +840,7 @@ size_t size; * Avoid repeating the error message many times (they take 1 second each). * Did_outofmem_msg is reset when a character is read. */ -void do_outofmem_msg(size) -long_u size; +void do_outofmem_msg(long_u size) { if (!did_outofmem_msg) { /* Don't hide this message */ @@ -864,7 +865,7 @@ static void free_findfile __ARGS((void)); * surprised if Vim crashes... * Some things can't be freed, esp. things local to a library function. */ -void free_all_mem() { +void free_all_mem(void) { buf_T *buf, *nextbuf; static int entered = FALSE; @@ -1008,8 +1009,7 @@ void free_all_mem() { /* * Copy "string" into newly allocated memory. */ -char_u * vim_strsave(string) -char_u *string; +char_u *vim_strsave(char_u *string) { char_u *p; unsigned len; @@ -1027,9 +1027,7 @@ char_u *string; * The allocated memory always has size "len + 1", also when "string" is * shorter. */ -char_u * vim_strnsave(string, len) -char_u *string; -int len; +char_u *vim_strnsave(char_u *string, int len) { char_u *p; @@ -1045,9 +1043,7 @@ int len; * Same as vim_strsave(), but any characters found in esc_chars are preceded * by a backslash. */ -char_u * vim_strsave_escaped(string, esc_chars) -char_u *string; -char_u *esc_chars; +char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars) { return vim_strsave_escaped_ext(string, esc_chars, '\\', FALSE); } @@ -1057,11 +1053,7 @@ char_u *esc_chars; * characters where rem_backslash() would remove the backslash. * Escape the characters with "cc". */ -char_u * vim_strsave_escaped_ext(string, esc_chars, cc, bsl) -char_u *string; -char_u *esc_chars; -int cc; -int bsl; +char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int bsl) { char_u *p; char_u *p2; @@ -1106,7 +1098,7 @@ int bsl; /* * Return TRUE when 'shell' has "csh" in the tail. */ -int csh_like_shell() { +int csh_like_shell(void) { return strstr((char *)gettail(p_sh), "csh") != NULL; } @@ -1119,9 +1111,7 @@ int csh_like_shell() { * with "<" like "<cfile>". * Returns the result in allocated memory, NULL if we have run out. */ -char_u * vim_strsave_shellescape(string, do_special) -char_u *string; -int do_special; +char_u *vim_strsave_shellescape(char_u *string, int do_special) { unsigned length; char_u *p; @@ -1198,8 +1188,7 @@ int do_special; * Like vim_strsave(), but make all characters uppercase. * This uses ASCII lower-to-upper case translation, language independent. */ -char_u * vim_strsave_up(string) -char_u *string; +char_u *vim_strsave_up(char_u *string) { char_u *p1; @@ -1212,9 +1201,7 @@ char_u *string; * Like vim_strnsave(), but make all characters uppercase. * This uses ASCII lower-to-upper case translation, language independent. */ -char_u * vim_strnsave_up(string, len) -char_u *string; -int len; +char_u *vim_strnsave_up(char_u *string, int len) { char_u *p1; @@ -1226,8 +1213,7 @@ int len; /* * ASCII lower-to-upper case translation, language independent. */ -void vim_strup(p) -char_u *p; +void vim_strup(char_u *p) { char_u *p2; int c; @@ -1244,8 +1230,7 @@ char_u *p; * Handles multi-byte characters as well as possible. * Returns NULL when out of memory. */ -char_u * strup_save(orig) -char_u *orig; +char_u *strup_save(char_u *orig) { char_u *p; char_u *res; @@ -1295,9 +1280,7 @@ char_u *orig; /* * copy a space a number of times */ -void copy_spaces(ptr, count) -char_u *ptr; -size_t count; +void copy_spaces(char_u *ptr, size_t count) { size_t i = count; char_u *p = ptr; @@ -1310,10 +1293,7 @@ size_t count; * Copy a character a number of times. * Does not work for multi-byte characters! */ -void copy_chars(ptr, count, c) -char_u *ptr; -size_t count; -int c; +void copy_chars(char_u *ptr, size_t count, int c) { size_t i = count; char_u *p = ptr; @@ -1325,8 +1305,7 @@ int c; /* * delete spaces at the end of a string */ -void del_trailing_spaces(ptr) -char_u *ptr; +void del_trailing_spaces(char_u *ptr) { char_u *q; @@ -1339,10 +1318,7 @@ char_u *ptr; * Like strncpy(), but always terminate the result with one NUL. * "to" must be "len + 1" long! */ -void vim_strncpy(to, from, len) -char_u *to; -char_u *from; -size_t len; +void vim_strncpy(char_u *to, char_u *from, size_t len) { STRNCPY(to, from, len); to[len] = NUL; @@ -1352,10 +1328,7 @@ size_t len; * Like strcat(), but make sure the result fits in "tosize" bytes and is * always NUL terminated. */ -void vim_strcat(to, from, tosize) -char_u *to; -char_u *from; -size_t tosize; +void vim_strcat(char_u *to, char_u *from, size_t tosize) { size_t tolen = STRLEN(to); size_t fromlen = STRLEN(from); @@ -1374,11 +1347,7 @@ size_t tosize; * "*option" is advanced to the next part. * The length is returned. */ -int copy_option_part(option, buf, maxlen, sep_chars) -char_u **option; -char_u *buf; -int maxlen; -char *sep_chars; +int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars) { int len = 0; char_u *p = *option; @@ -1411,8 +1380,7 @@ char *sep_chars; * Also skip free() when exiting for sure, this helps when we caught a deadly * signal that was caused by a crash in free(). */ -void vim_free(x) -void *x; +void vim_free(void *x) { if (x != NULL && !really_exiting) { #ifdef MEM_PROFILE @@ -1490,9 +1458,7 @@ size_t len; * Doesn't work for multi-byte characters. * return 0 for match, < 0 for smaller, > 0 for bigger */ -int vim_stricmp(s1, s2) -char *s1; -char *s2; +int vim_stricmp(char *s1, char *s2) { int i; @@ -1515,10 +1481,7 @@ char *s2; * Doesn't work for multi-byte characters. * return 0 for match, < 0 for smaller, > 0 for bigger */ -int vim_strnicmp(s1, s2, len) -char *s1; -char *s2; -size_t len; +int vim_strnicmp(char *s1, char *s2, size_t len) { int i; @@ -1541,9 +1504,7 @@ size_t len; * with characters from 128 to 255 correctly. It also doesn't return a * pointer to the NUL at the end of the string. */ -char_u * vim_strchr(string, c) -char_u *string; -int c; +char_u *vim_strchr(char_u *string, int c) { char_u *p; int b; @@ -1589,9 +1550,7 @@ int c; * strings with characters above 128 correctly. It also doesn't return a * pointer to the NUL at the end of the string. */ -char_u * vim_strbyte(string, c) -char_u *string; -int c; +char_u *vim_strbyte(char_u *string, int c) { char_u *p = string; @@ -1608,9 +1567,7 @@ int c; * Return NULL if not found. * Does not handle multi-byte char for "c"! */ -char_u * vim_strrchr(string, c) -char_u *string; -int c; +char_u *vim_strrchr(char_u *string, int c) { char_u *retval = NULL; char_u *p = string; @@ -1631,9 +1588,7 @@ int c; # ifdef vim_strpbrk # undef vim_strpbrk # endif -char_u * vim_strpbrk(s, charset) -char_u *s; -char_u *charset; +char_u *vim_strpbrk(char_u *s, char_u *charset) { while (*s) { if (vim_strchr(charset, *s) != NULL) @@ -1648,8 +1603,7 @@ char_u *charset; * Vim has its own isspace() function, because on some machines isspace() * can't handle characters above 128. */ -int vim_isspace(x) -int x; +int vim_isspace(int x) { return (x >= 9 && x <= 13) || x == ' '; } @@ -1661,8 +1615,7 @@ int x; /* * Clear an allocated growing array. */ -void ga_clear(gap) -garray_T *gap; +void ga_clear(garray_T *gap) { vim_free(gap->ga_data); ga_init(gap); @@ -1671,8 +1624,7 @@ garray_T *gap; /* * Clear a growing array that contains a list of strings. */ -void ga_clear_strings(gap) -garray_T *gap; +void ga_clear_strings(garray_T *gap) { int i; @@ -1685,18 +1637,14 @@ garray_T *gap; * Initialize a growing array. Don't forget to set ga_itemsize and * ga_growsize! Or use ga_init2(). */ -void ga_init(gap) -garray_T *gap; +void ga_init(garray_T *gap) { gap->ga_data = NULL; gap->ga_maxlen = 0; gap->ga_len = 0; } -void ga_init2(gap, itemsize, growsize) -garray_T *gap; -int itemsize; -int growsize; +void ga_init2(garray_T *gap, int itemsize, int growsize) { ga_init(gap); gap->ga_itemsize = itemsize; @@ -1707,9 +1655,7 @@ int growsize; * Make room in growing array "gap" for at least "n" items. * Return FAIL for failure, OK otherwise. */ -int ga_grow(gap, n) -garray_T *gap; -int n; +int ga_grow(garray_T *gap, int n) { size_t old_len; size_t new_len; @@ -1736,8 +1682,7 @@ int n; * strings with a separating comma. * Returns NULL when out of memory. */ -char_u * ga_concat_strings(gap) -garray_T *gap; +char_u *ga_concat_strings(garray_T *gap) { int i; int len = 0; @@ -1762,9 +1707,7 @@ garray_T *gap; * Concatenate a string to a growarray which contains characters. * Note: Does NOT copy the NUL at the end! */ -void ga_concat(gap, s) -garray_T *gap; -char_u *s; +void ga_concat(garray_T *gap, char_u *s) { int len = (int)STRLEN(s); @@ -1777,9 +1720,7 @@ char_u *s; /* * Append one byte to a growarray which contains bytes. */ -void ga_append(gap, c) -garray_T *gap; -int c; +void ga_append(garray_T *gap, int c) { if (ga_grow(gap, 1) == OK) { *((char *)gap->ga_data + gap->ga_len) = c; @@ -1791,8 +1732,7 @@ int c; /* * Append the text in "gap" below the cursor line and clear "gap". */ -void append_ga_line(gap) -garray_T *gap; +void append_ga_line(garray_T *gap) { /* Remove trailing CR. */ if (gap->ga_len > 0 @@ -2120,8 +2060,7 @@ static struct mousetable { * Return the modifier mask bit (MOD_MASK_*) which corresponds to the given * modifier name ('S' for Shift, 'C' for Ctrl etc). */ -int name_to_mod_mask(c) -int c; +int name_to_mod_mask(int c) { int i; @@ -2136,9 +2075,7 @@ int c; * Check if if there is a special key code for "key" that includes the * modifiers specified. */ -int simplify_key(key, modifiers) -int key; -int *modifiers; +int simplify_key(int key, int *modifiers) { int i; int key0; @@ -2167,8 +2104,7 @@ int *modifiers; /* * Change <xHome> to <Home>, <xUp> to <Up>, etc. */ -int handle_x_keys(key) -int key; +int handle_x_keys(int key) { switch (key) { case K_XUP: return K_UP; @@ -2195,9 +2131,7 @@ int key; * Return a string which contains the name of the given key when the given * modifiers are down. */ -char_u * get_special_key_name(c, modifiers) -int c; -int modifiers; +char_u *get_special_key_name(int c, int modifiers) { static char_u string[MAX_KEY_NAME_LEN + 1]; @@ -2293,10 +2227,12 @@ int modifiers; * If there is a match, srcp is advanced to after the <> name. * dst[] must be big enough to hold the result (up to six characters)! */ -int trans_special(srcp, dst, keycode) -char_u **srcp; -char_u *dst; -int keycode; /* prefer key code, e.g. K_DEL instead of DEL */ +int +trans_special ( + char_u **srcp, + char_u *dst, + int keycode /* prefer key code, e.g. K_DEL instead of DEL */ +) { int modifiers = 0; int key; @@ -2332,11 +2268,13 @@ int keycode; /* prefer key code, e.g. K_DEL instead of DEL */ * srcp is advanced to after the <> name. * returns 0 if there is no match. */ -int find_special_key(srcp, modp, keycode, keep_x_key) -char_u **srcp; -int *modp; -int keycode; /* prefer key code, e.g. K_DEL instead of DEL */ -int keep_x_key; /* don't translate xHome to Home key */ +int +find_special_key ( + char_u **srcp, + int *modp, + int keycode, /* prefer key code, e.g. K_DEL instead of DEL */ + int keep_x_key /* don't translate xHome to Home key */ +) { char_u *last_dash; char_u *end_of_name; @@ -2453,9 +2391,7 @@ int keep_x_key; /* don't translate xHome to Home key */ * Try to include modifiers in the key. * Changes "Shift-a" to 'A', "Alt-A" to 0xc0, etc. */ -int extract_modifiers(key, modp) -int key; -int *modp; +int extract_modifiers(int key, int *modp) { int modifiers = *modp; @@ -2487,8 +2423,7 @@ int *modp; * Try to find key "c" in the special key table. * Return the index when found, -1 when not found. */ -int find_special_key_in_table(c) -int c; +int find_special_key_in_table(int c) { int i; @@ -2507,8 +2442,7 @@ int c; * termcap name. * Return the key code, or 0 if not found. */ -int get_special_key_code(name) -char_u *name; +int get_special_key_code(char_u *name) { char_u *table_name; char_u string[3]; @@ -2535,8 +2469,7 @@ char_u *name; return 0; } -char_u * get_key_name(i) -int i; +char_u *get_key_name(int i) { if (i >= (int)KEY_NAMES_TABLE_LEN) return NULL; @@ -2547,10 +2480,7 @@ int i; * Look up the given mouse code to return the relevant information in the other * arguments. Return which button is down or was released. */ -int get_mouse_button(code, is_click, is_drag) -int code; -int *is_click; -int *is_drag; +int get_mouse_button(int code, int *is_click, int *is_drag) { int i; @@ -2568,10 +2498,12 @@ int *is_drag; * the given information about which mouse button is down, and whether the * mouse was clicked, dragged or released. */ -int get_pseudo_mouse_code(button, is_click, is_drag) -int button; /* eg MOUSE_LEFT */ -int is_click; -int is_drag; +int +get_pseudo_mouse_code ( + int button, /* eg MOUSE_LEFT */ + int is_click, + int is_drag +) { int i; @@ -2587,8 +2519,7 @@ int is_drag; /* * Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC. */ -int get_fileformat(buf) -buf_T *buf; +int get_fileformat(buf_T *buf) { int c = *buf->b_p_ff; @@ -2603,9 +2534,11 @@ buf_T *buf; * Like get_fileformat(), but override 'fileformat' with "p" for "++opt=val" * argument. */ -int get_fileformat_force(buf, eap) -buf_T *buf; -exarg_T *eap; /* can be NULL! */ +int +get_fileformat_force ( + buf_T *buf, + exarg_T *eap /* can be NULL! */ +) { int c; @@ -2629,9 +2562,11 @@ exarg_T *eap; /* can be NULL! */ * Sets both 'textmode' and 'fileformat'. * Note: Does _not_ set global value of 'textmode'! */ -void set_fileformat(t, opt_flags) -int t; -int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */ +void +set_fileformat ( + int t, + int opt_flags /* OPT_LOCAL and/or OPT_GLOBAL */ +) { char *p = NULL; @@ -2662,7 +2597,7 @@ int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */ /* * Return the default fileformat from 'fileformats'. */ -int default_fileformat() { +int default_fileformat(void) { switch (*p_ffs) { case 'm': return EOL_MAC; case 'd': return EOL_DOS; @@ -2673,9 +2608,7 @@ int default_fileformat() { /* * Call shell. Calls mch_call_shell, with 'shellxquote' added. */ -int call_shell(cmd, opt) -char_u *cmd; -int opt; +int call_shell(char_u *cmd, int opt) { char_u *ncmd; int retval; @@ -2744,7 +2677,7 @@ int opt; * VISUAL, SELECTMODE and OP_PENDING State are never set, they are equal to * NORMAL State with a condition. This function returns the real State. */ -int get_real_state() { +int get_real_state(void) { if (State & NORMAL) { if (VIsual_active) { if (VIsual_select) @@ -2761,9 +2694,7 @@ int get_real_state() { * Takes care of multi-byte characters. * "b" must point to the start of the file name */ -int after_pathsep(b, p) -char_u *b; -char_u *p; +int after_pathsep(char_u *b, char_u *p) { return p > b && vim_ispathsep(p[-1]) && (!has_mbyte || (*mb_head_off)(b, p - 1) == 0); @@ -2773,9 +2704,7 @@ char_u *p; * Return TRUE if file names "f1" and "f2" are in the same directory. * "f1" may be a short name, "f2" must be a full path. */ -int same_directory(f1, f2) -char_u *f1; -char_u *f2; +int same_directory(char_u *f1, char_u *f2) { char_u ffname[MAXPATHL]; char_u *t1; @@ -2802,8 +2731,7 @@ char_u *f2; * Caller must call shorten_fnames()! * Return OK or FAIL. */ -int vim_chdirfile(fname) -char_u *fname; +int vim_chdirfile(char_u *fname) { char_u dir[MAXPATHL]; @@ -2819,8 +2747,7 @@ char_u *fname; * Used for systems where stat() ignores a trailing slash on a file name. * The Vim code assumes a trailing slash is only ignored for a directory. */ -int illegal_slash(name) -char *name; +int illegal_slash(char *name) { if (name[0] == NUL) return FALSE; /* no file name is not illegal */ @@ -2868,8 +2795,7 @@ cursorentry_T shape_table[SHAPE_IDX_COUNT] = * ("what" is SHAPE_MOUSE). * Returns error message for an illegal option, NULL otherwise. */ -char_u * parse_shape_opt(what) -int what; +char_u *parse_shape_opt(int what) { char_u *modep; char_u *colonp; @@ -3045,8 +2971,7 @@ int what; * Return the index into shape_table[] for the current mode. * When "mouse" is TRUE, consider indexes valid for the mouse pointer. */ -int get_shape_idx(mouse) -int mouse; +int get_shape_idx(int mouse) { if (!mouse && State == SHOWMATCH) return SHAPE_IDX_SM; @@ -3106,7 +3031,7 @@ static ulg crc_32_tab[256]; /* * Fill the CRC table. */ -static void make_crc_tab() { +static void make_crc_tab(void) { ulg s,t,v; static int done = FALSE; @@ -3154,8 +3079,7 @@ static int saved_crypt_method; * 0 for "zip", the old method. Also for any non-valid value. * 1 for "blowfish". */ -int crypt_method_from_string(s) -char_u *s; +int crypt_method_from_string(char_u *s) { return *s == 'b' ? 1 : 0; } @@ -3163,8 +3087,7 @@ char_u *s; /* * Get the crypt method for buffer "buf" as a number. */ -int get_crypt_method(buf) -buf_T *buf; +int get_crypt_method(buf_T *buf) { return crypt_method_from_string(*buf->b_p_cm == NUL ? p_cm : buf->b_p_cm); } @@ -3173,9 +3096,7 @@ buf_T *buf; * Set the crypt method for buffer "buf" to "method" using the int value as * returned by crypt_method_from_string(). */ -void set_crypt_method(buf, method) -buf_T *buf; -int method; +void set_crypt_method(buf_T *buf, int method) { free_string_option(buf->b_p_cm); buf->b_p_cm = vim_strsave((char_u *)(method == 0 ? "zip" : "blowfish")); @@ -3186,7 +3107,7 @@ int method; * the state. * Must always be called symmetrically with crypt_pop_state(). */ -void crypt_push_state() { +void crypt_push_state(void) { if (crypt_busy == 1) { /* save the state */ if (use_crypt_method == 0) { @@ -3206,7 +3127,7 @@ void crypt_push_state() { * the saved state. * Must always be called symmetrically with crypt_push_state(). */ -void crypt_pop_state() { +void crypt_pop_state(void) { --crypt_busy; if (crypt_busy == 1) { use_crypt_method = saved_crypt_method; @@ -3223,10 +3144,7 @@ void crypt_pop_state() { * Encrypt "from[len]" into "to[len]". * "from" and "to" can be equal to encrypt in place. */ -void crypt_encode(from, len, to) -char_u *from; -size_t len; -char_u *to; +void crypt_encode(char_u *from, size_t len, char_u *to) { size_t i; int ztemp, t; @@ -3245,9 +3163,7 @@ char_u *to; /* * Decrypt "ptr[len]" in place. */ -void crypt_decode(ptr, len) -char_u *ptr; -long len; +void crypt_decode(char_u *ptr, long len) { char_u *p; @@ -3268,8 +3184,10 @@ long len; * the given password. * If "passwd" is NULL or empty, don't do anything. */ -void crypt_init_keys(passwd) -char_u *passwd; /* password string with which to modify keys */ +void +crypt_init_keys ( + char_u *passwd /* password string with which to modify keys */ +) { if (passwd != NULL && *passwd != NUL) { if (use_crypt_method == 0) { @@ -3291,8 +3209,7 @@ char_u *passwd; /* password string with which to modify keys */ * Free an allocated crypt key. Clear the text to make sure it doesn't stay * in memory anywhere. */ -void free_crypt_key(key) -char_u *key; +void free_crypt_key(char_u *key) { char_u *p; @@ -3310,9 +3227,11 @@ char_u *key; * When "store" is FALSE, the typed key is returned in allocated memory. * Returns NULL on failure. */ -char_u * get_crypt_key(store, twice) -int store; -int twice; /* Ask for the key twice. */ +char_u * +get_crypt_key ( + int store, + int twice /* Ask for the key twice. */ +) { char_u *p1, *p2 = NULL; int round; @@ -3599,19 +3518,18 @@ static char_u e_pathtoolong[] = N_("E854: path too long for completion"); * This function silently ignores a few errors, vim_findfile() will have * limited functionality then. */ -void * vim_findfile_init(path, filename, stopdirs, level, free_visited, - find_what, - search_ctx_arg, tagfile, - rel_fname) -char_u *path; -char_u *filename; -char_u *stopdirs UNUSED; -int level; -int free_visited; -int find_what; -void *search_ctx_arg; -int tagfile; /* expanding names of tags files */ -char_u *rel_fname; /* file name to use for "." */ +void * +vim_findfile_init ( + char_u *path, + char_u *filename, + char_u *stopdirs, + int level, + int free_visited, + int find_what, + void *search_ctx_arg, + int tagfile, /* expanding names of tags files */ + char_u *rel_fname /* file name to use for "." */ +) { char_u *wc_part; ff_stack_T *sptr; @@ -3911,8 +3829,7 @@ error_return: /* * Get the stopdir string. Check that ';' is not escaped. */ -char_u * vim_findfile_stopdir(buf) -char_u *buf; +char_u *vim_findfile_stopdir(char_u *buf) { char_u *r_ptr = buf; @@ -3936,8 +3853,7 @@ char_u *buf; /* * Clean up the given search context. Can handle a NULL pointer. */ -void vim_findfile_cleanup(ctx) -void *ctx; +void vim_findfile_cleanup(void *ctx) { if (ctx == NULL) return; @@ -3959,8 +3875,7 @@ void *ctx; * stack with a list (don't forget to leave partly searched directories on the * top of the list). */ -char_u * vim_findfile(search_ctx_arg) -void *search_ctx_arg; +char_u *vim_findfile(void *search_ctx_arg) { char_u *file_path; char_u *rest_of_wildcards; @@ -4344,8 +4259,7 @@ void *search_ctx_arg; * Free the list of lists of visited files and directories * Can handle it if the passed search_context is NULL; */ -void vim_findfile_free_visited(search_ctx_arg) -void *search_ctx_arg; +void vim_findfile_free_visited(void *search_ctx_arg) { ff_search_ctx_T *search_ctx; @@ -4357,8 +4271,7 @@ void *search_ctx_arg; vim_findfile_free_visited_list(&search_ctx->ffsc_dir_visited_lists_list); } -static void vim_findfile_free_visited_list(list_headp) -ff_visited_list_hdr_T **list_headp; +static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp) { ff_visited_list_hdr_T *vp; @@ -4373,8 +4286,7 @@ ff_visited_list_hdr_T **list_headp; *list_headp = NULL; } -static void ff_free_visited_list(vl) -ff_visited_T *vl; +static void ff_free_visited_list(ff_visited_T *vl) { ff_visited_T *vp; @@ -4391,9 +4303,7 @@ ff_visited_T *vl; * Returns the already visited list for the given filename. If none is found it * allocates a new one. */ -static ff_visited_list_hdr_T* ff_get_visited_list(filename, list_headp) -char_u *filename; -ff_visited_list_hdr_T **list_headp; +static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_list_hdr_T **list_headp) { ff_visited_list_hdr_T *retptr = NULL; @@ -4456,9 +4366,7 @@ ff_visited_list_hdr_T **list_headp; * - the only differences are in the counters behind a '**', so * '**\20' is equal to '**\24' */ -static int ff_wc_equal(s1, s2) -char_u *s1; -char_u *s2; +static int ff_wc_equal(char_u *s1, char_u *s2) { int i; int prev1 = NUL; @@ -4495,11 +4403,7 @@ char_u *s2; * -> return TRUE - Better the file is found several times instead of * never. */ -static int ff_check_visited(visited_list, fname - , wc_path) -ff_visited_T **visited_list; -char_u *fname; -char_u *wc_path; +static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path) { ff_visited_T *vp; #ifdef UNIX @@ -4576,13 +4480,7 @@ char_u *wc_path; /* * create stack element from given path pieces */ -static ff_stack_T * ff_create_stack_element(fix_part, - wc_part, - level, star_star_empty) -char_u *fix_part; -char_u *wc_part; -int level; -int star_star_empty; +static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, int level, int star_star_empty) { ff_stack_T *new; @@ -4620,9 +4518,7 @@ int star_star_empty; /* * Push a dir on the directory stack. */ -static void ff_push(search_ctx, stack_ptr) -ff_search_ctx_T *search_ctx; -ff_stack_T *stack_ptr; +static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr) { /* check for NULL pointer, not to return an error to the user, but * to prevent a crash */ @@ -4636,8 +4532,7 @@ ff_stack_T *stack_ptr; * Pop a dir from the directory stack. * Returns NULL if stack is empty. */ -static ff_stack_T * ff_pop(search_ctx) -ff_search_ctx_T *search_ctx; +static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx) { ff_stack_T *sptr; @@ -4651,8 +4546,7 @@ ff_search_ctx_T *search_ctx; /* * free the given stack element */ -static void ff_free_stack_element(stack_ptr) -ff_stack_T *stack_ptr; +static void ff_free_stack_element(ff_stack_T *stack_ptr) { /* vim_free handles possible NULL pointers */ vim_free(stack_ptr->ffs_fix_path); @@ -4667,8 +4561,7 @@ ff_stack_T *stack_ptr; /* * Clear the search context, but NOT the visited list. */ -static void ff_clear(search_ctx) -ff_search_ctx_T *search_ctx; +static void ff_clear(ff_search_ctx_T *search_ctx) { ff_stack_T *sptr; @@ -4704,10 +4597,7 @@ ff_search_ctx_T *search_ctx; * check if the given path is in the stopdirs * returns TRUE if yes else FALSE */ -static int ff_path_in_stoplist(path, path_len, stopdirs_v) -char_u *path; -int path_len; -char_u **stopdirs_v; +static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) { int i = 0; @@ -4761,12 +4651,14 @@ char_u **stopdirs_v; * Returns an allocated string for the file name. NULL for error. * */ -char_u * find_file_in_path(ptr, len, options, first, rel_fname) -char_u *ptr; /* file name */ -int len; /* length of file name */ -int options; -int first; /* use count'th matching file name */ -char_u *rel_fname; /* file name searching relative to */ +char_u * +find_file_in_path ( + char_u *ptr, /* file name */ + int len, /* length of file name */ + int options, + int first, /* use count'th matching file name */ + char_u *rel_fname /* file name searching relative to */ +) { return find_file_in_path_option(ptr, len, options, first, *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path, @@ -4777,7 +4669,7 @@ static char_u *ff_file_to_find = NULL; static void *fdip_search_ctx = NULL; #if defined(EXITFREE) -static void free_findfile() { +static void free_findfile(void) { vim_free(ff_file_to_find); vim_findfile_cleanup(fdip_search_ctx); } @@ -4794,27 +4686,29 @@ static void free_findfile() { * * Returns an allocated string for the file name. NULL for error. */ -char_u * find_directory_in_path(ptr, len, options, rel_fname) -char_u *ptr; /* file name */ -int len; /* length of file name */ -int options; -char_u *rel_fname; /* file name searching relative to */ +char_u * +find_directory_in_path ( + char_u *ptr, /* file name */ + int len, /* length of file name */ + int options, + char_u *rel_fname /* file name searching relative to */ +) { return find_file_in_path_option(ptr, len, options, TRUE, p_cdpath, FINDFILE_DIR, rel_fname, (char_u *)""); } -char_u * find_file_in_path_option(ptr, len, options, first, path_option, - find_what, rel_fname, - suffixes) -char_u *ptr; /* file name */ -int len; /* length of file name */ -int options; -int first; /* use count'th matching file name */ -char_u *path_option; /* p_path or p_cdpath */ -int find_what; /* FINDFILE_FILE, _DIR or _BOTH */ -char_u *rel_fname; /* file name we are looking relative to. */ -char_u *suffixes; /* list of suffixes, 'suffixesadd' option */ +char_u * +find_file_in_path_option ( + char_u *ptr, /* file name */ + int len, /* length of file name */ + int options, + int first, /* use count'th matching file name */ + char_u *path_option, /* p_path or p_cdpath */ + int find_what, /* FINDFILE_FILE, _DIR or _BOTH */ + char_u *rel_fname, /* file name we are looking relative to. */ + char_u *suffixes /* list of suffixes, 'suffixesadd' option */ +) { static char_u *dir; static int did_findfile_init = FALSE; @@ -4973,8 +4867,7 @@ theend: * Change directory to "new_dir". If FEAT_SEARCHPATH is defined, search * 'cdpath' for relative directory names, otherwise just mch_chdir(). */ -int vim_chdir(new_dir) -char_u *new_dir; +int vim_chdir(char_u *new_dir) { char_u *dir_name; int r; @@ -4995,9 +4888,7 @@ char_u *new_dir; * cache the result. * Returns OK or FAIL. */ -int get_user_name(buf, len) -char_u *buf; -int len; +int get_user_name(char_u *buf, int len) { if (username == NULL) { if (mch_get_user_name(buf, len) == FAIL) @@ -5053,16 +4944,12 @@ int (*cmp)__ARGS((const void *, const void *)); static int sort_compare __ARGS((const void *s1, const void *s2)); -static int sort_compare(s1, s2) -const void *s1; -const void *s2; +static int sort_compare(const void *s1, const void *s2) { return STRCMP(*(char **)s1, *(char **)s2); } -void sort_strings(files, count) -char_u **files; -int count; +void sort_strings(char_u **files, int count) { qsort((void *)files, (size_t)count, sizeof(char_u *), sort_compare); } @@ -5073,9 +4960,7 @@ int count; * If "maxlen" >= 0 compare "p[maxlen]" to "q[maxlen]" * Return value like strcmp(p, q), but consider path separators. */ -int pathcmp(p, q, maxlen) -const char *p, *q; -int maxlen; +int pathcmp(const char *p, const char *q, int maxlen) { int i; int c1, c2; @@ -5174,8 +5059,7 @@ static int findenv __ARGS((char *name)); /* look for a name in the env. */ static int newenv __ARGS((void)); /* copy env. from stack to heap */ static int moreenv __ARGS((void)); /* incr. size of env. */ -int putenv(string) -const char *string; +int putenv(const char *string) { int i; char *p; @@ -5208,8 +5092,7 @@ const char *string; return 0; } -static int findenv(name) -char *name; +static int findenv(char *name) { char *namechar, *envchar; int i, found; @@ -5227,7 +5110,7 @@ char *name; return found ? i - 1 : -1; } -static int newenv() { +static int newenv(void) { char **env, *elem; int i, esize; @@ -5252,7 +5135,7 @@ static int newenv() { return 0; } -static int moreenv() { +static int moreenv(void) { int esize; char **env; @@ -5266,8 +5149,7 @@ static int moreenv() { } # ifdef USE_VIMPTY_GETENV -char_u * vimpty_getenv(string) -const char_u *string; +char_u *vimpty_getenv(const char_u *string) { int i; char_u *p; @@ -5291,8 +5173,7 @@ const char_u *string; * Return 0 for not writable, 1 for writable file, 2 for a dir which we have * rights to write into. */ -int filewritable(fname) -char_u *fname; +int filewritable(char_u *fname) { int retval = 0; #if defined(UNIX) || defined(VMS) @@ -5319,8 +5200,7 @@ char_u *fname; * Print an error message with one or two "%s" and one or two string arguments. * This is not in message.c to avoid a warning for prototypes. */ -int emsg3(s, a1, a2) -char_u *s, *a1, *a2; +int emsg3(char_u *s, char_u *a1, char_u *a2) { if (emsg_not_now()) return TRUE; /* no error messages at the moment */ @@ -5336,9 +5216,7 @@ char_u *s, *a1, *a2; * Print an error message with one "%ld" and one long int argument. * This is not in message.c to avoid a warning for prototypes. */ -int emsgn(s, n) -char_u *s; -long n; +int emsgn(char_u *s, long n) { if (emsg_not_now()) return TRUE; /* no error messages at the moment */ @@ -5349,8 +5227,7 @@ long n; /* * Read 2 bytes from "fd" and turn them into an int, MSB first. */ -int get2c(fd) -FILE *fd; +int get2c(FILE *fd) { int n; @@ -5362,8 +5239,7 @@ FILE *fd; /* * Read 3 bytes from "fd" and turn them into an int, MSB first. */ -int get3c(fd) -FILE *fd; +int get3c(FILE *fd) { int n; @@ -5376,8 +5252,7 @@ FILE *fd; /* * Read 4 bytes from "fd" and turn them into an int, MSB first. */ -int get4c(fd) -FILE *fd; +int get4c(FILE *fd) { /* Use unsigned rather than int otherwise result is undefined * when left-shift sets the MSB. */ @@ -5393,8 +5268,7 @@ FILE *fd; /* * Read 8 bytes from "fd" and turn them into a time_t, MSB first. */ -time_t get8ctime(fd) -FILE *fd; +time_t get8ctime(FILE *fd) { time_t n = 0; int i; @@ -5408,9 +5282,7 @@ FILE *fd; * Read a string of length "cnt" from "fd" into allocated memory. * Returns NULL when out of memory or unable to read that many bytes. */ -char_u * read_string(fd, cnt) -FILE *fd; -int cnt; +char_u *read_string(FILE *fd, int cnt) { char_u *str; int i; @@ -5436,10 +5308,7 @@ int cnt; /* * Write a number to file "fd", MSB first, in "len" bytes. */ -int put_bytes(fd, nr, len) -FILE *fd; -long_u nr; -int len; +int put_bytes(FILE *fd, long_u nr, int len) { int i; @@ -5453,9 +5322,7 @@ int len; /* * Write time_t to file "fd" in 8 bytes. */ -void put_time(fd, the_time) -FILE *fd; -time_t the_time; +void put_time(FILE *fd, time_t the_time) { int c; int i; @@ -5491,8 +5358,7 @@ time_t the_time; * Return TRUE if string "s" contains a non-ASCII character (128 or higher). * When "s" is NULL FALSE is returned. */ -int has_non_ascii(s) -char_u *s; +int has_non_ascii(char_u *s) { char_u *p; |