From: schwarze Date: Fri, 9 May 2014 00:03:41 +0000 (+0000) Subject: Various cleanup: X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4ba9194b644726696091f5a05429dadc98cddff2;p=openbsd Various cleanup: 1. Style: Don't use variables as format strings. NetBSD rev. 1.26 (May 23, 2011) joerg@NetBSD via maintainer pjanzen@. 2. Style: Avoid needless pointer arithmetics. NetBSD rev. 1.27 (Oct 13, 2012) dholland@NetBSD via pjanzen@, who also applied some KNF to the indentation while here. 3. End curses before printing fatal error messages; from pjanzen@. --- diff --git a/games/cribbage/io.c b/games/cribbage/io.c index c46b7d266e6..551c5c99386 100644 --- a/games/cribbage/io.c +++ b/games/cribbage/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.14 2012/03/04 04:05:15 fgsch Exp $ */ +/* $OpenBSD: io.c,v 1.15 2014/05/09 00:03:41 schwarze Exp $ */ /* $NetBSD: io.c,v 1.9 1997/07/09 06:25:47 phil Exp $ */ /*- @@ -90,13 +90,13 @@ msgcrd(CARD c, bool brfrank, char *mid, bool brfsuit) if (brfrank) addmsg("%1.1s", rankchar[c.rank]); else - addmsg(rankname[c.rank]); + addmsg("%s", rankname[c.rank]); if (mid != NULL) - addmsg(mid); + addmsg("%s", mid); if (brfsuit) addmsg("%1.1s", suitchar[c.suit]); else - addmsg(suitname[c.suit]); + addmsg("%s", suitname[c.suit]); return (TRUE); } @@ -160,11 +160,12 @@ infrom(CARD hand[], int n, char *prompt) CARD crd; if (n < 1) { + bye(); printf("\nINFROM: %d = n < 1!!\n", n); exit(74); } for (;;) { - msg(prompt); + msg("%s", prompt); if (incard(&crd)) { /* if card is full card */ if (!isone(crd, hand, n)) msg("That's not in your hand"); @@ -174,6 +175,7 @@ infrom(CARD hand[], int n, char *prompt) hand[i].suit == crd.suit) break; if (i >= n) { + bye(); printf("\nINFROM: isone or something messed up\n"); exit(77); } @@ -314,7 +316,7 @@ number(int lo, int hi, char *prompt) int sum, tmp; for (sum = 0;;) { - msg(prompt); + msg("%s", prompt); if (!(p = get_line()) || *p == '\0') { msg(quiet ? "Not a number" : "That doesn't look like a number"); @@ -512,7 +514,7 @@ over: char * get_line(void) { - char *sp; + size_t pos; int c, oy, ox; WINDOW *oscr; @@ -521,39 +523,36 @@ get_line(void) getyx(stdscr, oy, ox); refresh(); /* loop reading in the string, and put it in a temporary buffer */ - for (sp = linebuf; (c = readchar()) != '\n'; clrtoeol(), refresh()) { + for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) { if (c == -1) continue; else if (c == erasechar()) { /* process erase character */ - if (sp > linebuf) { + if (pos > 0) { int i; - sp--; - for (i = strlen(unctrl(*sp)); i; i--) + pos--; + for (i = strlen(unctrl(linebuf[pos])); i; i--) addch('\b'); } continue; - } else - if (c == killchar()) { /* process kill - * character */ - sp = linebuf; - move(oy, ox); - continue; - } else - if (sp == linebuf && c == ' ') - continue; - if (sp >= &linebuf[LINESIZE - 1] || !(isprint(c) || c == ' ')) + } else if (c == killchar()) { /* process kill character */ + pos = 0; + move(oy, ox); + continue; + } else if (pos == 0 && c == ' ') + continue; + if (pos >= LINESIZE - 1 || !(isprint(c) || c == ' ')) putchar(CTRL('G')); else { if (islower(c)) c = toupper(c); - *sp++ = c; + linebuf[pos++] = c; addstr(unctrl(c)); Mpos++; } } - *sp = '\0'; + linebuf[pos] = '\0'; stdscr = oscr; return (linebuf); }