From 565239b0342b9e23d024bdf63fb8f0f0c8324ddd Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 30 Apr 2011 13:06:24 +0200 Subject: ul.c: code style and comment fixes Signed-off-by: Sami Kerola --- text-utils/ul.c | 166 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 94 insertions(+), 72 deletions(-) (limited to 'text-utils') diff --git a/text-utils/ul.c b/text-utils/ul.c index d2f88cd81..d7ed6f568 100644 --- a/text-utils/ul.c +++ b/text-utils/ul.c @@ -56,12 +56,13 @@ #include "c.h" #ifdef HAVE_WIDECHAR -static int put1wc(int c) /* Output an ASCII character as a wide character */ +/* Output an ASCII character as a wide character */ +static int put1wc(int c) { - if (putwchar(c) == WEOF) - return EOF; - else - return c; + if (putwchar(c) == WEOF) + return EOF; + else + return c; } #define putwp(s) tputs(s, STDOUT_FILENO, put1wc) #else @@ -69,16 +70,16 @@ static int put1wc(int c) /* Output an ASCII character as a wide character */ #endif static void usage(FILE *out); -void filter(FILE *f); -void flushln(void); -void overstrike(void); -void iattr(void); -void initbuf(void); -void fwd(void); -void reverse(void); -void initinfo(void); -void outc(wint_t c, int width); -void setmode(int newmode); +static void filter(FILE *f); +static void flushln(void); +static void overstrike(void); +static void iattr(void); +static void initbuf(void); +static void fwd(void); +static void reverse(void); +static void initinfo(void); +static void outc(wint_t c, int width); +static void setmode(int newmode); static void setcol(int newcol); static void needcol(int col); static void sig_handler(int signo); @@ -99,18 +100,27 @@ static void print_out(char *line); #define BOLD 020 /* Bold */ int must_use_uc, must_overstrike; -char *CURS_UP, *CURS_RIGHT, *CURS_LEFT, - *ENTER_STANDOUT, *EXIT_STANDOUT, *ENTER_UNDERLINE, *EXIT_UNDERLINE, - *ENTER_DIM, *ENTER_BOLD, *ENTER_REVERSE, *UNDER_CHAR, *EXIT_ATTRIBUTES; +char *CURS_UP, + *CURS_RIGHT, + *CURS_LEFT, + *ENTER_STANDOUT, + *EXIT_STANDOUT, + *ENTER_UNDERLINE, + *EXIT_UNDERLINE, + *ENTER_DIM, + *ENTER_BOLD, + *ENTER_REVERSE, + *UNDER_CHAR, + *EXIT_ATTRIBUTES; struct CHAR { char c_mode; wchar_t c_char; int c_width; -} ; +}; struct CHAR *obuf; -int obuflen; /* Tracks number of elements in obuf. */ +int obuflen; int col, maxcol; int mode; int halfpos; @@ -156,14 +166,23 @@ int main(int argc, char **argv) signal(SIGTERM, sig_handler); termtype = getenv("TERM"); + + /* + * FIXME: why terminal type is lpr when command begins with c and has + * no terminal? If this behavior can be explained please insert + * refrence or remove the code. In case this truly is desired command + * behavior this should be mentioned in manual page. + */ if (termtype == NULL || (argv[0][0] == 'c' && !isatty(STDOUT_FILENO))) termtype = "lpr"; + while ((c = getopt_long(argc, argv, "it:T:Vh", longopts, NULL)) != -1) - switch(c) { + switch (c) { case 't': - case 'T': /* for nroff compatibility */ - termtype = optarg; + case 'T': + /* for nroff compatibility */ + termtype = optarg; break; case 'i': iflag = 1; @@ -179,7 +198,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } setupterm(termtype, STDOUT_FILENO, &ret); - switch(ret) { + switch (ret) { case 1: break; @@ -190,34 +209,37 @@ int main(int argc, char **argv) case 0: /* No such terminal type - assume dumb */ - setupterm("dumb", STDOUT_FILENO, (int *)0); + setupterm("dumb", STDOUT_FILENO, (int *)0); break; } initinfo(); - if ( (tigetflag("os") && ENTER_BOLD==NULL ) || - (tigetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL)) - must_overstrike = 1; + if ((tigetflag("os") && ENTER_BOLD==NULL ) || + (tigetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL)) + must_overstrike = 1; initbuf(); if (optind == argc) filter(stdin); - else for (; optind 1) - i += obuf[i].c_width -1; + i += obuf[i].c_width - 1; } if (lastmode != NORMAL) { setmode(0); @@ -371,7 +394,7 @@ void flushln(void) putwchar('\n'); if (iflag && hadmodes) iattr(); - (void)fflush(stdout); + fflush(stdout); if (upln) upln--; initbuf(); @@ -381,11 +404,11 @@ void flushln(void) * For terminals that can overstrike, overstrike underlines and bolds. * We don't do anything with halfline ups and downs, or Greek. */ -void overstrike(void) +static void overstrike(void) { register int i; #ifdef __GNUC__ - register wchar_t *lbuf = __builtin_alloca((maxcol+1)*sizeof(wchar_t)); + register wchar_t *lbuf = __builtin_alloca((maxcol + 1) * sizeof(wchar_t)); #else wchar_t lbuf[BUFSIZ]; #endif @@ -393,7 +416,7 @@ void overstrike(void) int hadbold=0; /* Set up overstrike buffer */ - for (i=0; i= obuflen, expand obuf until obuflen > col. */ @@ -616,9 +637,10 @@ needcol(int col) { errx(EXIT_FAILURE, _("Input line too long.")); /* Similar paranoia: double only up to INT_MAX. */ - obuflen = ((INT_MAX / 2) < obuflen) - ? INT_MAX - : obuflen * 2; + if (obuflen < (INT_MAX / 2)) + obuflen *= 2; + else + obuflen = INT_MAX; /* Now we can try to expand obuf. */ obuf = xrealloc(obuf, sizeof(struct CHAR) * obuflen); -- cgit v1.2.3-55-g7522