Module Name:src
Committed By: joerg
Date: Sun Sep 4 20:26:17 UTC 2011
Modified Files:
src/usr.bin/fpr: fpr.c
Log Message:
Use static, change deep if / else if / ... chains to switch(), apply
__dead, ANSIfy.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/fpr/fpr.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/fpr/fpr.c
diff -u src/usr.bin/fpr/fpr.c:1.8 src/usr.bin/fpr/fpr.c:1.9
--- src/usr.bin/fpr/fpr.c:1.8 Mon Jul 21 14:19:22 2008
+++ src/usr.bin/fpr/fpr.c Sun Sep 4 20:26:17 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: fpr.c,v 1.8 2008/07/21 14:19:22 lukem Exp $ */
+/* $NetBSD: fpr.c,v 1.9 2011/09/04 20:26:17 joerg Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = @(#)fpr.c 8.1 (Berkeley) 6/6/93;
#endif
-__RCSID($NetBSD: fpr.c,v 1.8 2008/07/21 14:19:22 lukem Exp $);
+__RCSID($NetBSD: fpr.c,v 1.9 2011/09/04 20:26:17 joerg Exp $);
#endif/* not lint */
#include err.h
@@ -73,114 +73,110 @@
}
COLUMN;
-charcc;
-charsaved;
-int length;
-char *text;
-int highcol;
-COLUMN *line;
-int maxpos;
-int maxcol;
-
-void flush __P((void));
-void get_text __P((void));
-void init __P((void));
-int main __P((int, char **));
-void nospace __P((void));
-void savech __P((int));
+static charcc;
+static charsaved;
+static int length;
+static char *text;
+static int highcol;
+static COLUMN *line;
+static int maxpos;
+static int maxcol;
+
+static void flush(void);
+static void get_text(void);
+static void init(void);
+__dead static void nospace(void);
+static void savech(int);
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
int ch;
char ateof;
int i;
int errorcount;
-
init();
errorcount = 0;
ateof = FALSE;
- ch = getchar();
- if (ch == EOF)
+ switch (ch = getchar()) {
+ case EOF:
exit(0);
-
- if (ch == EOL) {
+ case EOL:
cc = NUL;
ungetc((int) EOL, stdin);
- } else
- if (ch == BLANK)
- cc = NUL;
- else
- if (ch == '1')
-cc = FF;
- else
-if (ch == '0')
- cc = EOL;
-else
- if (ch == '+')
- cc = CR;
- else {
- errorcount = 1;
- cc = NUL;
- ungetc(ch, stdin);
- }
+ break;
+ case BLANK:
+ cc = NUL;
+ break;
+ case '1':
+ cc = FF;
+ break;
+ case '0':
+ cc = EOL;
+ break;
+ case '+':
+ cc = CR;
+ break;
+ default:
+ errorcount = 1;
+ cc = NUL;
+ ungetc(ch, stdin);
+ break;
+ }
while (!ateof) {
get_text();
- ch = getchar();
- if (ch == EOF) {
+ switch (ch = getchar()) {
+ case EOF:
flush();
ateof = TRUE;
- } else
- if (ch == EOL) {
-flush();
-cc = NUL;
-ungetc((int) EOL, stdin);
- } else
-if (ch == BLANK) {
- flush();
- cc = NUL;
-} else
- if (ch == '1') {
- flush();
- cc = FF;
- } else
- if (ch == '0') {
- flush();
- cc = EOL;
- } else
- if (ch == '+') {
-for (i = 0; i length; i++)
- savech(i);
- } else {
-errorcount++;
-flush();
-cc = NUL;
-ungetc(ch, stdin);
- }
+ break;
+ case EOL:
+ flush();
+ cc = NUL;
+ ungetc((int) EOL, stdin);
+ break;
+ case BLANK:
+ flush();
+ cc = NUL;
+ break;
+ case '1':
+ flush();
+ cc = FF;
+ break;
+ case '0':
+ flush();
+ cc = EOL;
+ break;
+ case '+':
+ for (i = 0; i length; i++)
+savech(i);
+ break;
+ default:
+ errorcount++;
+ flush();
+ cc = NUL;
+ ungetc(ch, stdin);
+ break;
+ }
}
- if (errorcount == 1)
- fprintf(stderr, Illegal carriage control - 1 line.\n);
- else
- if (errorcount 1)
- fprintf(stderr, Illegal carriage control - %d lines.\n, errorcount);
+ if (errorcount)
+ fprintf(stderr, Illegal carriage control - %d line%s.\n,
+ errorcount, errorcount == 1 ? : s);
exit(0);
}
-void
-init()
+static void
+init(void)
{
COLUMN *cp;
COLUMN *cend;
char *sp;
-
length = 0;
maxpos = MAXCOL;
sp = malloc((unsigned) maxpos);
@@ -190,14 +186,14 @@
highcol = -1;
maxcol = MAXCOL;
- line = (COLUMN *) calloc(maxcol, (unsigned) sizeof(COLUMN));
+ line = calloc(maxcol, sizeof(COLUMN));
if (line == NULL)
nospace();
cp = line;
cend = line + (maxcol - 1);
while (cp = cend) {
cp-width = INITWIDTH;
- sp = calloc(INITWIDTH, (unsigned) sizeof(char));
+ sp = calloc(INITWIDTH, sizeof(char));
if (sp == NULL)
nospace();
cp-str = sp;
@@ -205,8 +201,8 @@
}
}
-void
-get_text()
+static void
+get_text(void)
{
int i;
char ateol;
@@ -218,58 +214,61 @@
ateol = FALSE;
while (!ateol) {
- ch = getchar();
- if (ch == EOL || ch == EOF)
+ switch (ch = getchar()) {
+ case EOL:
+ case EOF:
ateol = TRUE;
- else
- if (ch == TAB) {
-pos = (1 + i / TABSIZE) * TABSIZE;
-if (pos maxpos) {
- n = realloc(text, (unsigned)(pos + 10));
- if (n