diff --git a/libs/console/complete.c b/libs/console/complete.c index 70d44166b..f957f2d3f 100644 --- a/libs/console/complete.c +++ b/libs/console/complete.c @@ -59,38 +59,34 @@ static __attribute__ ((used)) const char rcsid[] = VISIBLE void Con_BasicCompleteCommandLine (inputline_t *il) { - char *s; - const char *cmd = "", **list[3] = {0, 0, 0}; - int cmd_len, c, i, v, o; - cbuf_t *cbuf; + char *s; + const char *cmd = "", **list[3] = {0, 0, 0}; + int cmd_len, c, i, v, o; + cbuf_t *cbuf; s = il->lines[il->edit_line] + 1; if (*s == '\\' || *s == '/') s++; - s = strdup(s); + s = strdup (s); cbuf = con_module->data->console->cbuf; - if (cbuf->interpreter->complete) - { - const char** completions = cbuf->interpreter->complete(cbuf, s); - const char** com; + if (cbuf->interpreter->complete) { + const char **completions = cbuf->interpreter->complete (cbuf, s); + const char **com; for (o = 0, com = completions; *com; com++, o++) - { - } + ; c = v = 0; list[2] = completions; - } - else - { + } else { // Count number of possible matches - c = Cmd_CompleteCountPossible(s); - v = Cvar_CompleteCountPossible(s); + c = Cmd_CompleteCountPossible (s); + v = Cvar_CompleteCountPossible (s); o = 0; } @@ -98,33 +94,28 @@ Con_BasicCompleteCommandLine (inputline_t *il) return; if (c + v + o == 1) { - if (c) - { - list[0] = Cmd_CompleteBuildList(s); + if (c) { + list[0] = Cmd_CompleteBuildList (s); cmd = *list[0]; - } - else if (v) - { - list[0] = Cvar_CompleteBuildList(s); + } else if (v) { + list[0] = Cvar_CompleteBuildList (s); cmd = *list[0]; - } - else - { + } else { cmd = *list[2]; } cmd_len = strlen (cmd); } else { if (c) - cmd = *(list[0] = Cmd_CompleteBuildList(s)); + cmd = *(list[0] = Cmd_CompleteBuildList (s)); if (v) - cmd = *(list[1] = Cvar_CompleteBuildList(s)); + cmd = *(list[1] = Cvar_CompleteBuildList (s)); if (o) cmd = *(list[2]); cmd_len = 0; do { for (i = 0; i < 3; i++) { - char ch = cmd[cmd_len]; + char ch = cmd[cmd_len]; const char **l = list[i]; if (l) { while (*l && (*l)[cmd_len] == ch) @@ -137,38 +128,41 @@ Con_BasicCompleteCommandLine (inputline_t *il) cmd_len++; } while (i == 3); // 'quakebar' - Con_Printf("\n\35"); + Con_Printf ("\n\35"); for (i = 0; i < con_linewidth - 4; i++) - Con_Printf("\36"); - Con_Printf("\37\n"); + Con_Printf ("\36"); + Con_Printf ("\37\n"); // Print Possible Commands if (c) { - Con_Printf("%i possible command%s\n", c, (c > 1) ? "s: " : ":"); - Con_DisplayList(list[0], con_linewidth); + Con_Printf ("%i possible command%s\n", c, (c > 1) ? "s: " : ":"); + Con_DisplayList (list[0], con_linewidth); } if (v) { - Con_Printf("%i possible variable%s\n", v, (v > 1) ? "s: " : ":"); - Con_DisplayList(list[1], con_linewidth); + Con_Printf ("%i possible variable%s\n", v, (v > 1) ? "s: " : ":"); + Con_DisplayList (list[1], con_linewidth); } if (o) { - Con_Printf("%i possible matche%s\n", o, (o > 1) ? "s: " : ":"); - Con_DisplayList(list[2], con_linewidth); + Con_Printf ("%i possible matche%s\n", o, (o > 1) ? "s: " : ":"); + Con_DisplayList (list[2], con_linewidth); } } if (cmd) { - unsigned int bound = max(0, (int) strlen(s) - (int) cmd_len); - const char* overwrite; + unsigned bound = max (0, (int) strlen (s) - (int) cmd_len); + const char *overwrite; - if (cmd_len > 0) while (bound < strlen(s) && strncmp(s+bound, cmd, strlen(s+bound))) bound++; + if (cmd_len > 0) + while (bound < strlen (s) + && strncmp (s + bound, cmd, strlen (s + bound))) + bound++; overwrite = va("%.*s%.*s", bound, s, cmd_len, cmd); il->lines[il->edit_line][1] = '/'; - strncpy(il->lines[il->edit_line] + 2, overwrite, strlen(overwrite)); - il->linepos = strlen(overwrite) + 2; + strncpy (il->lines[il->edit_line] + 2, overwrite, strlen (overwrite)); + il->linepos = strlen (overwrite) + 2; if (c + v == 1 && !o) { il->lines[il->edit_line][il->linepos] = ' '; il->linepos++; @@ -177,7 +171,7 @@ Con_BasicCompleteCommandLine (inputline_t *il) } for (i = 0; i < 3; i++) if (list[i]) - free ((void*)list[i]); + free ((void *) list[i]); - free(s); + free (s); } diff --git a/libs/console/filelist.c b/libs/console/filelist.c index 46f6f70ef..4ce973a63 100644 --- a/libs/console/filelist.c +++ b/libs/console/filelist.c @@ -70,6 +70,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "QF/cmd.h" #include "QF/console.h" #include "QF/cvar.h" +#include "QF/dstring.h" #include "QF/hash.h" #include "QF/pakfile.h" #include "QF/qargs.h" @@ -83,7 +84,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "compat.h" #ifndef HAVE_FNMATCH_PROTO -int fnmatch (const char *__pattern, const char *__string, int __flags); +int fnmatch (const char *__pattern, const char *__string, int __flags); #endif static int @@ -104,14 +105,12 @@ filelist_print (filelist_t *filelist) if (filelist->count) { qsort (filelist->list, filelist->count, sizeof (char *), filelist_cmp); - //if (0) filelist_cmp (0, 0); - - list = (const char **)malloc ((filelist->count + 1)*sizeof(char **)); + list = malloc ((filelist->count + 1) * sizeof (char **)); list[filelist->count] = 0; for (i = 0; i < filelist->count; i++) list[i] = filelist->list[i]; Con_DisplayList (list, con_linewidth); - free ((void*)list); + free ((void *) list); } } @@ -119,9 +118,9 @@ VISIBLE void Con_Maplist_f (void) { filelist_t *maplist = QFS_FilelistNew (); - + QFS_FilelistFill (maplist, "maps/", "bsp", 1); - + filelist_print (maplist); QFS_FilelistFree (maplist); } @@ -130,7 +129,7 @@ VISIBLE void Con_Skinlist_f (void) { filelist_t *skinlist = QFS_FilelistNew (); - + QFS_FilelistFill (skinlist, "skins/", "pcx", 1); filelist_print (skinlist); @@ -150,8 +149,9 @@ const char *sb_endings[] = { VISIBLE void Con_Skyboxlist_f (void) { - int i, j, k, c, b; - char basename[256]; + int i, j, k, c, b; + size_t ending_len = strlen (sb_endings[0]); + dstring_t *basename = dstring_new (); filelist_t *skyboxlist = QFS_FilelistNew (); filelist_t *cutlist = QFS_FilelistNew (); @@ -160,40 +160,44 @@ Con_Skyboxlist_f (void) QFS_FilelistFill (skyboxlist, "env/", "pcx", 1); for (i = 0; i < skyboxlist->count; i++) { - if (strlen(skyboxlist->list[i]) > strlen(sb_endings[0]) && strcmp(skyboxlist->list[i] + strlen(skyboxlist->list[i]) - strlen(sb_endings[0]), sb_endings[0]) == 0) { - strncpy(basename, skyboxlist->list[i], sizeof(basename)); - basename[strlen(skyboxlist->list[i]) - strlen(sb_endings[0])] = 0; + if (strlen(skyboxlist->list[i]) > ending_len + && strcmp((skyboxlist->list[i] + strlen (skyboxlist->list[i]) + - ending_len), + sb_endings[0]) == 0) { + dstring_copysubstr (basename, skyboxlist->list[i], + strlen (skyboxlist->list[i]) - ending_len); c = 0; for (j = 1; sb_endings[j]; j++) { b = 0; for (k = 0; k < skyboxlist->count; k++) { - if (strcmp(va("%s%s", basename, sb_endings[j]), skyboxlist->list[k]) == 0) { + if (strcmp(va("%s%s", basename->str, sb_endings[j]), + skyboxlist->list[k]) == 0) { b = 1; *skyboxlist->list[k] = 0; } } c += b; - } if (c == 5) - QFS_FilelistAdd (cutlist, basename, 0); + QFS_FilelistAdd (cutlist, basename->str, 0); } } filelist_print (cutlist); QFS_FilelistFree (cutlist); QFS_FilelistFree (skyboxlist); + dstring_delete (basename); } VISIBLE void Con_Demolist_QWD_f (void) { filelist_t *demolist = QFS_FilelistNew (); - + QFS_FilelistFill (demolist, "", "qwd", 1); - + filelist_print (demolist); QFS_FilelistFree (demolist); - + return; } @@ -201,7 +205,7 @@ VISIBLE void Con_Demolist_DEM_f (void) { filelist_t *demolist = QFS_FilelistNew (); - + QFS_FilelistFill (demolist, "", "dem", 1); filelist_print (demolist); diff --git a/libs/console/inputline.c b/libs/console/inputline.c index da96955fb..f2cc4f95e 100644 --- a/libs/console/inputline.c +++ b/libs/console/inputline.c @@ -56,13 +56,13 @@ Con_CreateInputLine (int lines, int lsize, char prompt) inputline_t *inputline; int i; - size = sizeof (inputline_t); // space for the header - size += sizeof(char*) * lines; // space for the line pointers - size += lines * lsize; // space for the lines themselves + size = sizeof (inputline_t); // space for the header + size += sizeof (char *) * lines; // space for the line pointers + size += lines * lsize; // space for the lines themselves inputline = calloc (1, size); - p = (char**)(inputline + 1); - l = (char*)&p[lines]; + p = (char **) (inputline + 1); + l = p[lines]; inputline->lines = p; inputline->num_lines = lines; @@ -169,8 +169,8 @@ Con_ProcessInputLine (inputline_t *il, int ch) break; // This also moves the ending \0 memmove (il->lines[il->edit_line] + il->linepos + 1, - il->lines[il->edit_line] + il->linepos, - i - il->linepos + 1); + il->lines[il->edit_line] + il->linepos, + i - il->linepos + 1); il->lines[il->edit_line][il->linepos] = ch; il->linepos++; } diff --git a/libs/console/list.c b/libs/console/list.c index 2b0ecd6e6..12e72167b 100644 --- a/libs/console/list.c +++ b/libs/console/list.c @@ -53,9 +53,9 @@ VISIBLE void (*con_list_print)(const char *fmt, ...) = Con_Printf; void Con_DisplayList (const char **list, int con_linewidth) { - const char **walk = list; - int len = 0, maxlen = 0, pos =0, i = 0; - int width = (con_linewidth - 4); + const char **walk = list; + int len = 0, maxlen = 0, pos =0, i = 0; + int width = (con_linewidth - 4); while (*walk) { len = strlen (*walk); diff --git a/libs/console/menu.c b/libs/console/menu.c index 9eaddfabc..68d97f5f1 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -96,10 +96,10 @@ menu_resolve_globals (progs_t *pr) if (!(f = PR_FindFunction (pr, sym = "menu_init"))) goto error; - menu_init = (func_t)(f - menu_pr_state.pr_functions); + menu_init = (func_t) (f - menu_pr_state.pr_functions); if (!(f = PR_FindFunction (pr, sym = "menu_draw_hud"))) goto error; - menu_draw_hud = (func_t)(f - pr->pr_functions); + menu_draw_hud = (func_t) (f - pr->pr_functions); if (!(def = PR_FindGlobal (pr, sym = "time"))) goto error; menu_pr_state.globals.time = &G_FLOAT (pr, def->ofs); @@ -112,17 +112,17 @@ error: static const char * menu_get_key (void *m, void *unused) { - return ((menu_item_t *)m)->text; + return ((menu_item_t *) m)->text; } static void menu_free (void *_m, void *unused) { int i; - menu_item_t *m = (menu_item_t *)_m; + menu_item_t *m = (menu_item_t *) _m; if (m->text) - free ((char*)m->text); + free ((char *) m->text); if (m->parent) { // remove self from parent list to avoid double frees for (i = 0; i < m->parent->num_items; i++) @@ -143,7 +143,7 @@ menu_free (void *_m, void *unused) menu_pic_t *p = m->pics; m->pics = p->next; if (p->name) - free ((char*)p->name); + free ((char *) p->name); free (p); } free (m); @@ -324,7 +324,7 @@ bi_Menu_TopMenu (progs_t *pr) const char *name = P_GSTRING (pr, 0); if (top_menu) - free ((char*)top_menu); + free ((char *) top_menu); top_menu = strdup (name); } diff --git a/libs/console/pr_keys.c b/libs/console/pr_keys.c index 083189d72..6536b5b58 100644 --- a/libs/console/pr_keys.c +++ b/libs/console/pr_keys.c @@ -104,7 +104,7 @@ bi_Key_CountBinding (progs_t *pr) { int target = P_INT (pr, 0); const char *binding = P_GSTRING (pr, 1); - int i, res = 0; + int i, res = 0; const char *keybind = NULL; for (i = 0; i < QFK_LAST; i++) {