diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-01-14 16:14:57 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-01-15 09:54:02 -0800 |
commit | 282857a907624ce29566b50b60687273dcd56f42 (patch) | |
tree | 97908afab8333f3dac20db2cb36079534eb6d3f2 | |
parent | c623f10e9acc9033b2df436126799424eb5830b8 (diff) |
More variable scope reductions as recommended by cppcheck
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | Dvi.c | 3 | ||||
-rw-r--r-- | parse.c | 71 | ||||
-rw-r--r-- | xditview.c | 16 |
3 files changed, 54 insertions, 36 deletions
@@ -399,9 +399,8 @@ static Boolean SetValuesHook(Widget widget, ArgList args, Cardinal *num_argsp) { DviWidget dw = (DviWidget) widget; - Cardinal i; - for (i = 0; i < *num_argsp; i++) { + for (Cardinal i = 0; i < *num_argsp; i++) { if (!strcmp(args[i].name, XtNfile)) { CloseFile(dw); OpenFile(dw); @@ -68,13 +68,7 @@ charWidth(DviWidget dw, XftFont *font, char c) int ParseInput(DviWidget dw) { - int n, k; - int c; char Buffer[BUFSIZ]; - int NextPage; - int prevFont; - int otherc; - unsigned char tc; /* * make sure some state exists @@ -83,6 +77,8 @@ ParseInput(DviWidget dw) if (!dw->dvi.state) push_env(dw); for (;;) { + int c; + switch (DviGetC(dw, &c)) { case '\n': break; @@ -108,38 +104,42 @@ ParseInput(DviWidget dw) case '7': case '8': case '9': + { + int otherc; HorizontalMove(dw, (c - '0') * 10 + DviGetC(dw, &otherc) - '0'); + } /* fall through */ case 'c': /* single ascii character */ (void) DviGetC(dw, &c); if (c == ' ') break; - tc = c; - PutCharacters(dw, &tc, 1); + else { + unsigned char tc = c; + PutCharacters(dw, &tc, 1); + } break; case 'C': GetWord(dw, Buffer, BUFSIZ); { DviCharNameMap *map; - int i; - unsigned char *ligature; + int prevFont; c = -1; map = QueryFontMap(dw, dw->dvi.state->font_number); if (map) { c = DviCharIndex(map, Buffer); if (c == -1) { - ligature = DviCharIsLigature(map, Buffer); + unsigned char *ligature = DviCharIsLigature(map, Buffer); if (ligature) { - i = strlen((char *) ligature); - PutCharacters(dw, ligature, i); + int l = strlen((char *) ligature); + PutCharacters(dw, ligature, l); break; } } } prevFont = -1; if (c == -1) { - for (i = 1; (map = QueryFontMap(dw, i)); i++) { + for (int i = 1; (map = QueryFontMap(dw, i)); i++) { if (map->special) { if ((c = DviCharIndex(map, Buffer)) != -1) { prevFont = dw->dvi.state->font_number; @@ -150,7 +150,7 @@ ParseInput(DviWidget dw) } } if (c != -1) { - tc = c; + unsigned char tc = c; PutCharacters(dw, &tc, 1); } if (prevFont != -1) @@ -162,7 +162,8 @@ ParseInput(DviWidget dw) ParseDrawFunction(dw, Buffer); break; case 's': /* ignore fractional sizes */ - n = GetNumber(dw); + { + int n = GetNumber(dw); if (!dw->dvi.size_scale) { static const int guesses[] = { 1, 4, 100, 1000, 1 }; int i; @@ -177,37 +178,52 @@ ParseInput(DviWidget dw) dw->dvi.state->font_size = n; dw->dvi.state->line_width = n * (dw->dvi.device_resolution / (720 * dw->dvi.size_scale)); + } break; case 'f': - n = GetNumber(dw); + { + int n = GetNumber(dw); dw->dvi.state->font_number = n; + } break; case 'H': /* absolute horizontal motion */ - k = GetNumber(dw); + { + int k = GetNumber(dw); HorizontalGoto(dw, k); + } break; case 'h': /* relative horizontal motion */ - k = GetNumber(dw); + { + int k = GetNumber(dw); HorizontalMove(dw, k); + } break; case 'w': /* word space */ break; case 'V': - n = GetNumber(dw); + { + int n = GetNumber(dw); VerticalGoto(dw, n); + } break; case 'v': - n = GetNumber(dw); + { + int n = GetNumber(dw); VerticalMove(dw, n); + } break; case 'P': /* new spread */ break; case 'p': /* new page */ + { + int NextPage; + (void) GetNumber(dw); NextPage = dw->dvi.current_page + 1; RememberPagePosition(dw, NextPage); FlushCharCache(dw); return (NextPage); + } case 'n': /* end of line */ GetNumber(dw); GetNumber(dw); @@ -293,7 +309,6 @@ PutCharacters(DviWidget dw, unsigned char *src, int len) int xx, yx; int fx, fy; char *dst; - int c; xx = ToX(dw, dw->dvi.state->x); yx = ToX(dw, dw->dvi.state->y); @@ -371,7 +386,7 @@ PutCharacters(DviWidget dw, unsigned char *src, int len) dw->dvi.cache.char_index += len; text->nchars += len; while (len--) { - c = *src++; + int c = *src++; *dst++ = c; if (font) dw->dvi.cache.x += charWidth(dw, font, c); @@ -424,8 +439,8 @@ extern int LastPage, CurrentPage; static void ParseDeviceControl(DviWidget dw) { /* Parse the x commands */ - char str[20], str1[50]; - int c, n; + char str[20]; + int c; GetWord(dw, str, 20); switch (str[0]) { /* crude for now */ @@ -445,10 +460,14 @@ ParseDeviceControl(DviWidget dw) SetDeviceResolution(dw, GetNumber(dw)); break; case 'f': /* font used */ - n = GetNumber(dw); + { + int n = GetNumber(dw); + char str1[50]; + GetWord(dw, str, 20); GetLine(dw, str1, 50); SetFontPosition(dw, n, str, str1); + } break; case 'H': /* char height */ break; @@ -160,7 +160,6 @@ main(int argc, char **argv) char * file_name = NULL; XtAppContext xtcontext; Arg topLevelArgs[2]; - Widget entry; XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); @@ -195,9 +194,9 @@ main(int argc, char **argv) popupMenu = XtCreatePopupShell("popupMenu", simpleMenuWidgetClass, toplevel, NULL, 0); for (Cardinal i = 0; i < XtNumber(popupMenuEntries); i++) { - entry = XtCreateManagedWidget(popupMenuEntries[i].name, - smeBSBObjectClass, popupMenu, - NULL, (Cardinal) 0); + Widget entry = XtCreateManagedWidget(popupMenuEntries[i].name, + smeBSBObjectClass, popupMenu, + NULL, (Cardinal) 0); XtAddCallback(entry, XtNcallback, popupMenuEntries[i].function, NULL); } @@ -212,9 +211,9 @@ main(int argc, char **argv) XtCreatePopupShell("fileMenu", simpleMenuWidgetClass, fileMenuButton, NULL, (Cardinal) 0); for (Cardinal i = 0; i < XtNumber(fileMenuEntries); i++) { - entry = XtCreateManagedWidget(fileMenuEntries[i].name, - smeBSBObjectClass, fileMenu, - NULL, (Cardinal) 0); + Widget entry = XtCreateManagedWidget(fileMenuEntries[i].name, + smeBSBObjectClass, fileMenu, + NULL, (Cardinal) 0); XtAddCallback(entry, XtNcallback, fileMenuEntries[i].function, NULL); } @@ -536,7 +535,6 @@ MakePrompt(Widget centerw, const char *prompt, void (*func)(char *), char *def) {XtNlabel,(XtArgVal) 0}, {XtNvalue,(XtArgVal) 0}, }; - Arg valueArgs[1]; Arg centerArgs[2]; Position source_x, source_y; Position dest_x, dest_y; @@ -556,6 +554,8 @@ MakePrompt(Widget centerw, const char *prompt, void (*func)(char *), char *def) XawDialogAddButton(promptDialog, "cancel", NULL, NULL); valueWidget = XtNameToWidget(promptDialog, "value"); if (valueWidget) { + Arg valueArgs[1]; + XtSetArg(valueArgs[0], XtNresizable, TRUE); XtSetValues(valueWidget, valueArgs, 1); /* |