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/digraph.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/digraph.c') diff --git a/src/digraph.c b/src/digraph.c index 4584973526..4a1e1e4d04 100644 --- a/src/digraph.c +++ b/src/digraph.c @@ -1623,8 +1623,7 @@ static digr_T digraphdefault[] = /* * handle digraphs after typing a character */ -int do_digraph(c) -int c; +int do_digraph(int c) { static int backspaced; /* character before K_BS */ static int lastchar; /* last typed character */ @@ -1647,8 +1646,10 @@ int c; * mode. * Returns composed character, or NUL when ESC was used. */ -int get_digraph(cmdline) -int cmdline; /* TRUE when called from the cmdline */ +int +get_digraph ( + int cmdline /* TRUE when called from the cmdline */ +) { int c, cc; @@ -1683,10 +1684,7 @@ int cmdline; /* TRUE when called from the cmdline */ * If no match, return "char2". * If "meta_char" is TRUE and "char1" is a space, return "char2" | 0x80. */ -static int getexactdigraph(char1, char2, meta_char) -int char1; -int char2; -int meta_char; +static int getexactdigraph(int char1, int char2, int meta_char) { int i; int retval = 0; @@ -1759,10 +1757,7 @@ int meta_char; * Get digraph. * Allow for both char1-char2 and char2-char1 */ -int getdigraph(char1, char2, meta_char) -int char1; -int char2; -int meta_char; +int getdigraph(int char1, int char2, int meta_char) { int retval; @@ -1777,8 +1772,7 @@ int meta_char; * Add the digraphs in the argument to the digraph table. * format: {c1}{c2} char {c1}{c2} char ... */ -void putdigraph(str) -char_u *str; +void putdigraph(char_u *str) { int char1, char2, n; int i; @@ -1828,7 +1822,7 @@ char_u *str; } } -void listdigraphs() { +void listdigraphs(void) { int i; digr_T *dp; @@ -1867,8 +1861,7 @@ void listdigraphs() { wrong, in which case we messed up ScreenLines */ } -static void printdigraph(dp) -digr_T *dp; +static void printdigraph(digr_T *dp) { char_u buf[30]; char_u *p; @@ -1925,7 +1918,7 @@ static void keymap_unload __ARGS((void)); * used when setting the option, not later when the value has already been * checked. */ -char_u * keymap_init() { +char_u *keymap_init(void) { curbuf->b_kmap_state &= ~KEYMAP_INIT; if (*curbuf->b_p_keymap == NUL) { @@ -1967,8 +1960,7 @@ char_u * keymap_init() { /* * ":loadkeymap" command: load the following lines as the keymap. */ -void ex_loadkeymap(eap) -exarg_T *eap; +void ex_loadkeymap(exarg_T *eap) { char_u *line; char_u *p; @@ -2044,7 +2036,7 @@ exarg_T *eap; /* * Stop using 'keymap'. */ -static void keymap_unload() { +static void keymap_unload(void) { char_u buf[KMAP_MAXLEN + 10]; int i; char_u *save_cpo = p_cpo; -- 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/digraph.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/digraph.c') diff --git a/src/digraph.c b/src/digraph.c index 4a1e1e4d04..9a58058fde 100644 --- a/src/digraph.c +++ b/src/digraph.c @@ -12,7 +12,18 @@ */ #include "vim.h" - +#include "digraph.h" +#include "charset.h" +#include "ex_cmds2.h" +#include "ex_docmd.h" +#include "ex_getln.h" +#include "getchar.h" +#include "mbyte.h" +#include "message.h" +#include "misc2.h" +#include "normal.h" +#include "screen.h" +#include "ui.h" typedef int result_T; -- cgit