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/menu.c | 138 +++++++++++++++++++++++-------------------------------------- 1 file changed, 51 insertions(+), 87 deletions(-) (limited to 'src/menu.c') diff --git a/src/menu.c b/src/menu.c index 12e91b0ae6..bb62296a61 100644 --- a/src/menu.c +++ b/src/menu.c @@ -53,8 +53,10 @@ static char_u e_nomenu[] = N_("E329: No menu \"%s\""); /* * Do the :menu command and relatives. */ -void ex_menu(eap) -exarg_T *eap; /* Ex command arguments */ +void +ex_menu ( + exarg_T *eap /* Ex command arguments */ +) { char_u *menu_path; int modes; @@ -262,12 +264,14 @@ theend: /* * Add the menu with the given name to the menu hierarchy */ -static int add_menu_path(menu_path, menuarg, pri_tab, call_data) -char_u *menu_path; -vimmenu_T *menuarg; /* passes modes, iconfile, iconidx, +static int +add_menu_path ( + char_u *menu_path, + vimmenu_T *menuarg, /* passes modes, iconfile, iconidx, icon_builtin, silent[0], noremap[0] */ -int *pri_tab; -char_u *call_data; + int *pri_tab, + char_u *call_data +) { char_u *path_name; int modes = menuarg->modes; @@ -506,11 +510,7 @@ erret: * Set the (sub)menu with the given name to enabled or disabled. * Called recursively. */ -static int menu_nable_recurse(menu, name, modes, enable) -vimmenu_T *menu; -char_u *name; -int modes; -int enable; +static int menu_nable_recurse(vimmenu_T *menu, char_u *name, int modes, int enable) { char_u *p; @@ -559,11 +559,13 @@ int enable; * Remove the (sub)menu with the given name from the menu hierarchy * Called recursively. */ -static int remove_menu(menup, name, modes, silent) -vimmenu_T **menup; -char_u *name; -int modes; -int silent; /* don't give error messages */ +static int +remove_menu ( + vimmenu_T **menup, + char_u *name, + int modes, + int silent /* don't give error messages */ +) { vimmenu_T *menu; vimmenu_T *child; @@ -666,8 +668,7 @@ int silent; /* don't give error messages */ /* * Free the given menu structure and remove it from the linked list. */ -static void free_menu(menup) -vimmenu_T **menup; +static void free_menu(vimmenu_T **menup) { int i; vimmenu_T *menu; @@ -692,9 +693,7 @@ vimmenu_T **menup; /* * Free the menu->string with the given index. */ -static void free_menu_string(menu, idx) -vimmenu_T *menu; -int idx; +static void free_menu_string(vimmenu_T *menu, int idx) { int count = 0; int i; @@ -710,9 +709,7 @@ int idx; /* * Show the mapping associated with a menu item or hierarchy in a sub-menu. */ -static int show_menus(path_name, modes) -char_u *path_name; -int modes; +static int show_menus(char_u *path_name, int modes) { char_u *p; char_u *name; @@ -765,10 +762,7 @@ int modes; /* * Recursively show the mappings associated with the menus under the given one */ -static void show_menus_recursive(menu, modes, depth) -vimmenu_T *menu; -int modes; -int depth; +static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) { int i; int bit; @@ -844,11 +838,7 @@ static int expand_emenu; /* TRUE for ":emenu" command */ /* * Work out what to complete when doing command line completion of menu names. */ -char_u * set_context_in_menu_cmd(xp, cmd, arg, forceit) -expand_T *xp; -char_u *cmd; -char_u *arg; -int forceit; +char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forceit) { char_u *after_dot; char_u *p; @@ -952,9 +942,7 @@ int forceit; * Function given to ExpandGeneric() to obtain the list of (sub)menus (not * entries). */ -char_u * get_menu_name(xp, idx) -expand_T *xp UNUSED; -int idx; +char_u *get_menu_name(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; char_u *str; @@ -999,9 +987,7 @@ int idx; * Function given to ExpandGeneric() to obtain the list of menus and menu * entries. */ -char_u * get_menu_names(xp, idx) -expand_T *xp UNUSED; -int idx; +char_u *get_menu_names(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; #define TBUFFER_LEN 256 @@ -1065,8 +1051,7 @@ int idx; * element. Any \ and ^Vs are removed from the current element. * "name" may be modified. */ -char_u * menu_name_skip(name) -char_u *name; +char_u *menu_name_skip(char_u *name) { char_u *p; @@ -1086,9 +1071,7 @@ char_u *name; * Return TRUE when "name" matches with menu "menu". The name is compared in * two ways: raw menu name and menu name without '&'. ignore part after a TAB. */ -static int menu_name_equal(name, menu) -char_u *name; -vimmenu_T *menu; +static int menu_name_equal(char_u *name, vimmenu_T *menu) { if (menu->en_name != NULL && (menu_namecmp(name, menu->en_name) @@ -1097,9 +1080,7 @@ vimmenu_T *menu; return menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname); } -static int menu_namecmp(name, mname) -char_u *name; -char_u *mname; +static int menu_namecmp(char_u *name, char_u *mname) { int i; @@ -1118,11 +1099,13 @@ char_u *mname; * If "unmenu" is not NULL, then the flag it points to is set according to * whether the command is an "unmenu" command. */ -static int get_menu_cmd_modes(cmd, forceit, noremap, unmenu) -char_u *cmd; -int forceit; /* Was there a "!" after the command? */ -int *noremap; -int *unmenu; +static int +get_menu_cmd_modes ( + char_u *cmd, + int forceit, /* Was there a "!" after the command? */ + int *noremap, + int *unmenu +) { int modes; @@ -1179,9 +1162,7 @@ int *unmenu; * Modify a menu name starting with "PopUp" to include the mode character. * Returns the name in allocated memory (NULL for failure). */ -static char_u * popup_mode_name(name, idx) -char_u *name; -int idx; +static char_u *popup_mode_name(char_u *name, int idx) { char_u *p; int len = (int)STRLEN(name); @@ -1202,10 +1183,7 @@ int idx; * If mnemonic != NULL, *mnemonic is set to the character after the first '&'. * If actext != NULL, *actext is set to the text after the first TAB. */ -static char_u * menu_text(str, mnemonic, actext) -char_u *str; -int *mnemonic; -char_u **actext; +static char_u *menu_text(char_u *str, int *mnemonic, char_u **actext) { char_u *p; char_u *text; @@ -1251,8 +1229,7 @@ char_u **actext; /* * Return TRUE if "name" can be a menu in the MenuBar. */ -int menu_is_menubar(name) -char_u *name; +int menu_is_menubar(char_u *name) { return !menu_is_popup(name) && !menu_is_toolbar(name) @@ -1262,8 +1239,7 @@ char_u *name; /* * Return TRUE if "name" is a popup menu name. */ -int menu_is_popup(name) -char_u *name; +int menu_is_popup(char_u *name) { return STRNCMP(name, "PopUp", 5) == 0; } @@ -1272,8 +1248,7 @@ char_u *name; /* * Return TRUE if "name" is a toolbar menu name. */ -int menu_is_toolbar(name) -char_u *name; +int menu_is_toolbar(char_u *name) { return STRNCMP(name, "ToolBar", 7) == 0; } @@ -1282,8 +1257,7 @@ char_u *name; * Return TRUE if the name is a menu separator identifier: Starts and ends * with '-' */ -int menu_is_separator(name) -char_u *name; +int menu_is_separator(char_u *name) { return name[0] == '-' && name[STRLEN(name) - 1] == '-'; } @@ -1291,8 +1265,7 @@ char_u *name; /* * Return TRUE if the menu is hidden: Starts with ']' */ -static int menu_is_hidden(name) -char_u *name; +static int menu_is_hidden(char_u *name) { return (name[0] == ']') || (menu_is_popup(name) && name[5] != NUL); } @@ -1302,8 +1275,7 @@ char_u *name; /* * Return TRUE if the menu is the tearoff menu. */ -static int menu_is_tearoff(name) -char_u *name UNUSED; +static int menu_is_tearoff(char_u *name) { return FALSE; } @@ -1315,8 +1287,7 @@ char_u *name UNUSED; * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy and * execute it. */ -void ex_emenu(eap) -exarg_T *eap; +void ex_emenu(exarg_T *eap) { vimmenu_T *menu; char_u *name; @@ -1430,8 +1401,7 @@ exarg_T *eap; /* * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy. */ -vimmenu_T * gui_find_menu(path_name) -char_u *path_name; +vimmenu_T *gui_find_menu(char_u *path_name) { vimmenu_T *menu = NULL; char_u *name; @@ -1499,8 +1469,7 @@ static garray_T menutrans_ga = {0, 0, 0, 0, NULL}; * This function is also defined without the +multi_lang feature, in which * case the commands are ignored. */ -void ex_menutranslate(eap) -exarg_T *eap UNUSED; +void ex_menutranslate(exarg_T *eap) { char_u *arg = eap->arg; menutrans_T *tp; @@ -1562,8 +1531,7 @@ exarg_T *eap UNUSED; /* * Find the character just after one part of a menu name. */ -static char_u * menu_skip_part(p) -char_u *p; +static char_u *menu_skip_part(char_u *p) { while (*p != NUL && *p != '.' && !vim_iswhite(*p)) { if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) @@ -1577,9 +1545,7 @@ char_u *p; * Lookup part of a menu name in the translations. * Return a pointer to the translation or NULL if not found. */ -static char_u * menutrans_lookup(name, len) -char_u *name; -int len; +static char_u *menutrans_lookup(char_u *name, int len) { menutrans_T *tp = (menutrans_T *)menutrans_ga.ga_data; int i; @@ -1609,8 +1575,7 @@ int len; /* * Unescape the name in the translate dictionary table. */ -static void menu_unescape_name(name) -char_u *name; +static void menu_unescape_name(char_u *name) { char_u *p; @@ -1623,8 +1588,7 @@ char_u *name; * Isolate the menu name. * Skip the menu name, and translate into a real TAB. */ -static char_u * menu_translate_tab_and_shift(arg_start) -char_u *arg_start; +static char_u *menu_translate_tab_and_shift(char_u *arg_start) { char_u *arg = arg_start; -- 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/menu.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/menu.c') diff --git a/src/menu.c b/src/menu.c index bb62296a61..95ac7bd5f5 100644 --- a/src/menu.c +++ b/src/menu.c @@ -13,6 +13,15 @@ */ #include "vim.h" +#include "menu.h" +#include "charset.h" +#include "eval.h" +#include "ex_docmd.h" +#include "getchar.h" +#include "message.h" +#include "misc1.h" +#include "misc2.h" +#include "term.h" #define MENUDEPTH 10 /* maximum depth of menus */ -- cgit