From b76c358f3de9106a4bdbf853b4c4371f6f7a62c2 Mon Sep 17 00:00:00 2001 From: scott-linder Date: Sun, 23 Feb 2014 15:34:45 -0500 Subject: Convert function declarations from K&R to ANSI style. cproto (http://invisible-island.net/cproto/) was used to do the bulk of the work in batch; even the most recent version had some issues with typedef'd parameters; a quick "patch" was to modify `lex.l` to explicitly include all vim typedefs as known types. One example from `vim.h` is typedef unsigned char char_u; which was added in `lex.l` as char_u { save_text_offset(); return T_CHAR; } Even with these changes there were some problems: * Two files (`mbyte.c` and `os_unix.c`) were not cleanly converted. * Any function with the `UNUSED` macro in its parameter list was not converted. Rather than spend more time fixing the automated approach, the two files `mbyte.c` and `os_unix.c` were converted by hand. The `UNUSED` macros were compiler specific, and the alternative, generic version would require a different syntax, so in order to simplify the conversion all uses of `UNUSED` were stripped, and then the sources were run back through cproto. It is planned to reconsider each use of `UNUSED` manually using a new macro definition. --- src/ui.c | 115 +++++++++++++++++++++++++-------------------------------------- 1 file changed, 46 insertions(+), 69 deletions(-) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index 7eebee6572..76eca6fff9 100644 --- a/src/ui.c +++ b/src/ui.c @@ -19,9 +19,7 @@ #include "vim.h" -void ui_write(s, len) -char_u *s; -int len; +void ui_write(char_u *s, int len) { #ifndef NO_CONSOLE /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */ @@ -53,9 +51,7 @@ static char_u *ta_str = NULL; static int ta_off; /* offset for next char to use when ta_str != NULL */ static int ta_len; /* length of ta_str when it's not NULL*/ -void ui_inchar_undo(s, len) -char_u *s; -int len; +void ui_inchar_undo(char_u *s, int len) { char_u *new; int newlen; @@ -91,11 +87,13 @@ int len; * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL * otherwise. */ -int ui_inchar(buf, maxlen, wtime, tb_change_cnt) -char_u *buf; -int maxlen; -long wtime; /* don't use "time", MIPS cannot handle it */ -int tb_change_cnt; +int +ui_inchar ( + char_u *buf, + int maxlen, + long wtime, /* don't use "time", MIPS cannot handle it */ + int tb_change_cnt +) { int retval = 0; @@ -159,7 +157,7 @@ theend: /* * return non-zero if a character is available */ -int ui_char_avail() { +int ui_char_avail(void) { #ifndef NO_CONSOLE # ifdef NO_CONSOLE_INPUT if (no_console_input()) @@ -175,9 +173,7 @@ int ui_char_avail() { * Delay for the given number of milliseconds. If ignoreinput is FALSE then we * cancel the delay if a key is hit. */ -void ui_delay(msec, ignoreinput) -long msec; -int ignoreinput; +void ui_delay(long msec, int ignoreinput) { mch_delay(msec, ignoreinput); } @@ -187,7 +183,7 @@ int ignoreinput; * otherwise fake it by starting a new shell. * When running the GUI iconify the window. */ -void ui_suspend() { +void ui_suspend(void) { mch_suspend(); } @@ -196,7 +192,7 @@ void ui_suspend() { * When the OS can't really suspend, call this function to start a shell. * This is never called in the GUI. */ -void suspend_shell() { +void suspend_shell(void) { if (*p_sh == NUL) EMSG(_(e_shellempty)); else { @@ -212,7 +208,7 @@ void suspend_shell() { * Use the new sizes as defaults for 'columns' and 'lines'. * Return OK when size could be determined, FAIL otherwise. */ -int ui_get_shellsize() { +int ui_get_shellsize(void) { int retval; retval = mch_get_shellsize(); @@ -232,8 +228,10 @@ int ui_get_shellsize() { * The gui_set_shellsize() or mch_set_shellsize() function will try to set the * new size. If this is not possible, it will adjust Rows and Columns. */ -void ui_set_shellsize(mustset) -int mustset UNUSED; /* set by the user */ +void +ui_set_shellsize ( + int mustset /* set by the user */ +) { mch_set_shellsize(); } @@ -242,13 +240,13 @@ int mustset UNUSED; /* set by the user */ * Called when Rows and/or Columns changed. Adjust scroll region and mouse * region. */ -void ui_new_shellsize() { +void ui_new_shellsize(void) { if (full_screen && !exiting) { mch_new_shellsize(); } } -void ui_breakcheck() { +void ui_breakcheck(void) { mch_breakcheck(); } @@ -305,16 +303,16 @@ static int inbufcount = 0; /* number of chars in inbuf[] */ * are used by the gui_* calls when a GUI is used to handle keyboard input. */ -int vim_is_input_buf_full() { +int vim_is_input_buf_full(void) { return inbufcount >= INBUFLEN; } -int vim_is_input_buf_empty() { +int vim_is_input_buf_empty(void) { return inbufcount == 0; } #if defined(FEAT_OLE) || defined(PROTO) -int vim_free_in_input_buf() { +int vim_free_in_input_buf(void) { return INBUFLEN - inbufcount; } @@ -325,7 +323,7 @@ int vim_free_in_input_buf() { * Return the current contents of the input buffer and make it empty. * The returned pointer must be passed to set_input_buf() later. */ -char_u * get_input_buf() { +char_u *get_input_buf(void) { garray_T *gap; /* We use a growarray to store the data pointer and the length. */ @@ -345,8 +343,7 @@ char_u * get_input_buf() { * Restore the input buffer with a pointer returned from get_input_buf(). * The allocated memory is freed, this only works once! */ -void set_input_buf(p) -char_u *p; +void set_input_buf(char_u *p) { garray_T *gap = (garray_T *)p; @@ -370,9 +367,7 @@ char_u *p; * Special keys start with CSI. A real CSI must have been translated to * CSI KS_EXTRA KE_CSI. K_SPECIAL doesn't require translation. */ -void add_to_input_buf(s, len) -char_u *s; -int len; +void add_to_input_buf(char_u *s, int len) { if (inbufcount + len > INBUFLEN + MAX_KEY_CODE_LEN) return; /* Shouldn't ever happen! */ @@ -413,9 +408,7 @@ void add_to_input_buf_csi(char_u *str, int len) { #endif -void push_raw_key(s, len) -char_u *s; -int len; +void push_raw_key(char_u *s, int len) { while (len--) inbuf[inbufcount++] = *s++; @@ -424,7 +417,7 @@ int len; #if defined(FEAT_GUI) || defined(FEAT_EVAL) || defined(FEAT_EX_EXTRA) \ || defined(PROTO) /* Remove everything from the input buffer. Called when ^C is found */ -void trash_input_buf() { +void trash_input_buf(void) { inbufcount = 0; } @@ -435,9 +428,7 @@ void trash_input_buf() { * it in buf. * Note: this function used to be Read() in unix.c */ -int read_from_input_buf(buf, maxlen) -char_u *buf; -long maxlen; +int read_from_input_buf(char_u *buf, long maxlen) { if (inbufcount == 0) /* if the buffer is empty, fill it */ fill_input_buf(TRUE); @@ -450,8 +441,7 @@ long maxlen; return (int)maxlen; } -void fill_input_buf(exit_on_error) -int exit_on_error UNUSED; +void fill_input_buf(int exit_on_error) { #if defined(UNIX) || defined(OS2) || defined(VMS) || defined(MACOS_X_UNIX) int len; @@ -567,7 +557,7 @@ int exit_on_error UNUSED; /* * Exit because of an input read error. */ -void read_error_exit() { +void read_error_exit(void) { if (silent_mode) /* Normal way to exit for "ex -s" */ getout(0); STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); @@ -578,7 +568,7 @@ void read_error_exit() { /* * May update the shape of the cursor. */ -void ui_cursor_shape() { +void ui_cursor_shape(void) { term_cursor_shape(); @@ -592,8 +582,7 @@ void ui_cursor_shape() { /* * Check bounds for column number */ -int check_col(col) -int col; +int check_col(int col) { if (col < 0) return 0; @@ -605,8 +594,7 @@ int col; /* * Check bounds for row number */ -int check_row(row) -int row; +int check_row(int row) { if (row < 0) return 0; @@ -626,9 +614,7 @@ int row; /* * Get the contents of the X CUT_BUFFER0 and put it in "cbd". */ -void yank_cut_buffer0(dpy, cbd) -Display *dpy; -VimClipboard *cbd; +void yank_cut_buffer0(Display *dpy, VimClipboard *cbd) { int nbytes = 0; char_u *buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0); @@ -694,10 +680,12 @@ VimClipboard *cbd; * If flags has MOUSE_SETPOS, nothing is done, only the current position is * remembered. */ -int jump_to_mouse(flags, inclusive, which_button) -int flags; -int *inclusive; /* used for inclusive operator, can be NULL */ -int which_button; /* MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE */ +int +jump_to_mouse ( + int flags, + int *inclusive, /* used for inclusive operator, can be NULL */ + int which_button /* MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE */ +) { static int on_status_line = 0; /* #lines below bottom of window */ static int on_sep_line = 0; /* on separator right of window */ @@ -986,11 +974,7 @@ retnomove: * window "win". * Returns TRUE if the position is below the last line. */ -int mouse_comp_pos(win, rowp, colp, lnump) -win_T *win; -int *rowp; -int *colp; -linenr_T *lnump; +int mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump) { int col = *colp; int row = *rowp; @@ -1056,9 +1040,7 @@ linenr_T *lnump; * Find the window at screen position "*rowp" and "*colp". The positions are * updated to become relative to the top-left of the window. */ -win_T * mouse_find_win(rowp, colp) -int *rowp; -int *colp UNUSED; +win_T *mouse_find_win(int *rowp, int *colp) { frame_T *fp; @@ -1090,8 +1072,7 @@ int *colp UNUSED; /* * Translate window coordinates to buffer position without any side effects */ -int get_fpos_of_mouse(mpos) -pos_T *mpos; +int get_fpos_of_mouse(pos_T *mpos) { win_T *wp; int row = mouse_row; @@ -1129,10 +1110,7 @@ pos_T *mpos; * Convert a virtual (screen) column to a character column. * The first column is one. */ -int vcol2col(wp, lnum, vcol) -win_T *wp; -linenr_T lnum; -int vcol; +int vcol2col(win_T *wp, linenr_T lnum, int vcol) { /* try to advance to the specified column */ int count = 0; @@ -1154,8 +1132,7 @@ int vcol; /* * Save current Input Method status to specified place. */ -void im_save_status(psave) -long *psave; +void im_save_status(long *psave) { /* Don't save when 'imdisable' is set or "xic" is NULL, IM is always * disabled then (but might start later). -- cgit From 0ef90c13b72b74928bfb3c183c7a5bd7240b51ad Mon Sep 17 00:00:00 2001 From: scott-linder Date: Tue, 25 Feb 2014 15:41:16 -0500 Subject: Removes 'proto' dir See #137 for the issue. Every header in the proto directory was: * Given include guards in the form #ifndef NEOVIM_FILENAME_H #define NEOVIM_FILENAME_H ... #endif /* NEOVIM_FILENAM_H */ * Renamed from *.pro -> *.h * Moved from src/proto/ to src/ This would have caused conficts with some existing headers in src/; rather than merge these conflicts now (which is a whole other can of worms involving multiple and conditional inclusion), any header in src/ with a conflicting name was renamed from *.h -> *_defs.h (which may or may not actually describe its purpose, the change is purely a namespacing issue). Once all of these changes were made a script was developed to determine what #includes needed to be added to each source file to describe its dependencies and allow it to compile; because the script is so short and I'll just list it here: #! /bin/bash cd $(dirname $0) # Scrapes `make` output for provided error messages and outputs #includes # needed to resolve them. # $1 : part of the clang error message between filename and identifier list_missing_includes() { for file_missing_pair in $(CC=clang make 2>&1 >/dev/null | sed -n "s/\/\(.*\.[hc]\).*$1.*'\(.*\)'.*/\1:\2/p"); do fields=(${file_missing_pair//:/ }) source_file=${fields[0]} missing_func=${fields[1]} # Try to find the declaration of the missing function. echo $(basename $source_file) \ \#include \"$(grep -r "\b$missing_func __ARGS" | sed -n "s/.*\/\(.*\)\:.*/\1/p")\" # Remove duplicates done | sort | uniq } echo "Finding missing function prototypes..." list_missing_includes "implicit declaration of function" echo "Finding missing identifier declarations..." list_missing_includes "use of undeclared identifier" Each list of required headers was added by hand in the following format: #include "vim.h" #include "*_defs.h" #include "filename.h" /* All other includes in same module here, in alphabetical order. */ /* All includes from other modules (e.g. "os/*.h") here in alphabetical * order. */ --- src/ui.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index 76eca6fff9..3396f2e6ef 100644 --- a/src/ui.c +++ b/src/ui.c @@ -17,7 +17,21 @@ */ #include "vim.h" - +#include "ui.h" +#include "diff.h" +#include "ex_cmds2.h" +#include "fold.h" +#include "main.h" +#include "mbyte.h" +#include "misc1.h" +#include "misc2.h" +#include "move.h" +#include "normal.h" +#include "option.h" +#include "os_unix.h" +#include "screen.h" +#include "term.h" +#include "window.h" void ui_write(char_u *s, int len) { -- cgit