diff options
author | joe <joe@FreeBSD.org> | 2001-12-29 00:18:16 +0000 |
---|---|---|
committer | joe <joe@FreeBSD.org> | 2001-12-29 00:18:16 +0000 |
commit | 4771d6130329d531407b442ce0ce8f1e2d98a34a (patch) | |
tree | 64d6a6acac6bc5a6639647c5c6b6c053fb629816 | |
parent | ab30f96094953549e72239190dc27926a3ebcb8e (diff) | |
download | FreeBSD-src-4771d6130329d531407b442ce0ce8f1e2d98a34a.zip FreeBSD-src-4771d6130329d531407b442ce0ce8f1e2d98a34a.tar.gz |
Restore these files to shiny KNF.
-rw-r--r-- | bin/ls/ls.c | 84 | ||||
-rw-r--r-- | bin/ls/print.c | 86 |
2 files changed, 88 insertions, 82 deletions
diff --git a/bin/ls/ls.c b/bin/ls/ls.c index e4afb61..f500426 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -133,18 +133,17 @@ main(argc, argv) int argc; char *argv[]; { - static char dot[] = ".", *dotav[] = { dot, NULL }; + static char dot[] = ".", *dotav[] = {dot, NULL}; struct winsize win; int ch, fts_options, notused; char *p; - #ifdef COLORLS - char termcapbuf[1024]; /* termcap definition buffer */ - char tcapbuf[512]; /* capability buffer */ + char termcapbuf[1024]; /* termcap definition buffer */ + char tcapbuf[512]; /* capability buffer */ char *bp = tcapbuf; #endif - (void) setlocale(LC_ALL, ""); + (void)setlocale(LC_ALL, ""); /* Terminal defaults to -Cq, non-terminal defaults to -1. */ if (isatty(STDOUT_FILENO)) { @@ -152,8 +151,7 @@ main(argc, argv) !win.ws_col) { if ((p = getenv("COLUMNS")) != NULL) termwidth = atoi(p); - } - else + } else termwidth = win.ws_col; f_column = f_nonprint = 1; } else { @@ -168,7 +166,7 @@ main(argc, argv) f_listdot = 1; fts_options = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "1ABCFGHLPRTWZabcdfghiklnoqrstu")) != -1) { + while ((ch = getopt(argc, argv, "1ABCFGHLPRTWZabcdfghiklnoqrstu")) != -1) { switch (ch) { /* * The -1, -C and -l options all override each other so shell @@ -181,7 +179,7 @@ main(argc, argv) case 'B': f_nonprint = 0; f_octal = 1; - f_octal_escape = 0; + f_octal_escape = 0; break; case 'C': f_column = 1; @@ -204,7 +202,7 @@ main(argc, argv) f_type = 1; break; case 'H': - fts_options |= FTS_COMFOLLOW; + fts_options |= FTS_COMFOLLOW; break; case 'G': setenv("CLICOLOR", "", 1); @@ -214,7 +212,7 @@ main(argc, argv) fts_options |= FTS_LOGICAL; break; case 'P': - fts_options &= ~FTS_COMFOLLOW; + fts_options &= ~FTS_COMFOLLOW; fts_options &= ~FTS_LOGICAL; fts_options |= FTS_PHYSICAL; break; @@ -235,7 +233,7 @@ main(argc, argv) case 'f': f_nosort = 1; break; - case 'g': /* Compatibility with 4.3BSD. */ + case 'g': /* Compatibility with 4.3BSD. */ break; case 'h': f_humanval = 1; @@ -255,7 +253,7 @@ main(argc, argv) case 'q': f_nonprint = 1; f_octal = 0; - f_octal_escape = 0; + f_octal_escape = 0; break; case 'r': f_reversesort = 1; @@ -274,7 +272,7 @@ main(argc, argv) break; case 'b': f_nonprint = 0; - f_octal = 0; + f_octal = 0; f_octal_escape = 1; break; case 'Z': @@ -319,8 +317,8 @@ main(argc, argv) * for "stty oxtabs" mode. */ f_notabs = 1; - (void) signal(SIGINT, colorquit); - (void) signal(SIGQUIT, colorquit); + (void)signal(SIGINT, colorquit); + (void)signal(SIGQUIT, colorquit); parsecolors(getenv("LSCOLORS")); } #endif @@ -334,7 +332,7 @@ main(argc, argv) #ifdef COLORLS && !f_color #endif - ) + ) fts_options |= FTS_NOSTAT; /* @@ -361,7 +359,6 @@ main(argc, argv) blocksize /= 512; } } - /* Select a sort function. */ if (f_reversesort) { if (!f_timesort) @@ -370,7 +367,7 @@ main(argc, argv) sortfcn = revacccmp; else if (f_statustime) sortfcn = revstatcmp; - else /* Use modification time. */ + else /* Use modification time. */ sortfcn = revmodcmp; } else { if (!f_timesort) @@ -379,7 +376,7 @@ main(argc, argv) sortfcn = acccmp; else if (f_statustime) sortfcn = statcmp; - else /* Use modification time. */ + else /* Use modification time. */ sortfcn = modcmp; } @@ -398,7 +395,7 @@ main(argc, argv) exit(rval); } -static int output; /* If anything output. */ +static int output; /* If anything output. */ /* * Traverse() walks the logical directory structure specified by the argv list @@ -455,7 +452,6 @@ traverse(argc, argv, options) (void)printf("%s:\n", p->fts_path); output = 1; } - chp = fts_children(ftsp, ch_options); display(p, chp); @@ -527,7 +523,8 @@ display(p, list) initmax2[1] = '\0'; } } - if (initmax2[-1] == ':') strcpy(initmax2, "0"); + if (initmax2[-1] == ':') + strcpy(initmax2, "0"); ninitmax = sscanf(jinitmax, " %lu : %lu : %lu : %i : %i : %i : %qu : %lu : %lu ", @@ -535,19 +532,28 @@ display(p, list) &maxgroup, &maxflags, &maxsize, &maxlen, &maxlattr); f_notabs = 1; switch (ninitmax) { - case 0: maxinode = 0; - case 1: maxblock = 0; - case 2: maxnlink = 0; - case 3: maxuser = 0; - case 4: maxgroup = 0; - case 5: maxflags = 0; - case 6: maxsize = 0; - case 7: maxlen = 0; - case 8: maxlattr = 0; + case 0: + maxinode = 0; + case 1: + maxblock = 0; + case 2: + maxnlink = 0; + case 3: + maxuser = 0; + case 4: + maxgroup = 0; + case 5: + maxflags = 0; + case 6: + maxsize = 0; + case 7: + maxlen = 0; + case 8: + maxlattr = 0; #ifdef COLORLS - if (!f_color) + if (!f_color) #endif - f_notabs = 0; + f_notabs = 0; } maxinode = makenines(maxinode); maxblock = makenines(maxblock); @@ -568,7 +574,6 @@ display(p, list) rval = 1; continue; } - /* * P is NULL if list is the argv list, to which different rules * apply. @@ -589,8 +594,10 @@ display(p, list) if (cur->fts_namelen > maxlen) maxlen = cur->fts_namelen; if (f_octal || f_octal_escape) { - u_long t = len_octal(cur->fts_name, cur->fts_namelen); - if (t > maxlen) maxlen = t; + u_long t = len_octal(cur->fts_name, cur->fts_namelen); + + if (t > maxlen) + maxlen = t; } if (needstats) { sp = cur->fts_statp; @@ -655,7 +662,7 @@ display(p, list) if (f_flags) { np->flags = &np->data[ulen + glen + 2]; - (void)strcpy(np->flags, flags); + (void)strcpy(np->flags, flags); free(flags); } if (f_lomac) { @@ -692,7 +699,6 @@ display(p, list) d.s_size = strlen(buf); d.s_user = maxuser; } - printfcn(&d); output = 1; diff --git a/bin/ls/print.c b/bin/ls/print.c index fde57ab..0c9ba00 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -92,28 +92,32 @@ static int colortype __P((mode_t)); #define TERA_2_SZ (TERA_SZ(1024ULL)) #define PETA_2_SZ (PETA_SZ(1024ULL)) -unsigned long long vals_base2[] = { 1, KILO_2_SZ, MEGA_2_SZ, GIGA_2_SZ, TERA_2_SZ, PETA_2_SZ }; +unsigned long long vals_base2[] = {1, KILO_2_SZ, MEGA_2_SZ, GIGA_2_SZ, TERA_2_SZ, PETA_2_SZ}; -typedef enum { NONE, KILO, MEGA, GIGA, TERA, PETA, UNIT_MAX } unit_t; +typedef enum { + NONE, KILO, MEGA, GIGA, TERA, PETA, UNIT_MAX +} unit_t; static unit_t unit_adjust __P((off_t *)); -int unitp [] = { NONE, KILO, MEGA, GIGA, TERA, PETA }; +int unitp[] = {NONE, KILO, MEGA, GIGA, TERA, PETA}; #ifdef COLORLS /* Most of these are taken from <sys/stat.h> */ typedef enum Colors { - C_DIR, /* directory */ - C_LNK, /* symbolic link */ - C_SOCK, /* socket */ - C_FIFO, /* pipe */ - C_EXEC, /* executable */ - C_BLK, /* block special */ - C_CHR, /* character special */ - C_SUID, /* setuid executable */ - C_SGID, /* setgid executable */ - C_WSDIR, /* directory writeble to others, with sticky bit */ - C_WDIR, /* directory writeble to others, without sticky bit */ - C_NUMCOLORS /* just a place-holder */ + C_DIR, /* directory */ + C_LNK, /* symbolic link */ + C_SOCK, /* socket */ + C_FIFO, /* pipe */ + C_EXEC, /* executable */ + C_BLK, /* block special */ + C_CHR, /* character special */ + C_SUID, /* setuid executable */ + C_SGID, /* setgid executable */ + C_WSDIR, /* directory writeble to others, with sticky + * bit */ + C_WDIR, /* directory writeble to others, without + * sticky bit */ + C_NUMCOLORS /* just a place-holder */ } Colors; const char *defcolors = "exfxcxdxbxegedabagacad"; @@ -123,7 +127,6 @@ static struct { int num[2]; int bold; } colors[C_NUMCOLORS]; - #endif void @@ -278,7 +281,6 @@ printcol(dp) printscol(dp); return; } - numcols = termwidth / colwidth; numrows = num / numcols; if (num % numcols) @@ -402,7 +404,7 @@ static int putch(c) int c; { - (void) putchar(c); + (void)putchar(c); return 0; } @@ -412,7 +414,7 @@ writech(c) { char tmp = c; - (void) write(STDOUT_FILENO, &tmp, 1); + (void)write(STDOUT_FILENO, &tmp, 1); return 0; } @@ -430,7 +432,6 @@ printcolor(c) if (ansiseq) tputs(ansiseq, 1, putch); } - if (colors[c].num[1] != -1) { ansiseq = tgoto(ansi_bgcol, 0, colors[c].num[1]); if (ansiseq) @@ -450,7 +451,7 @@ static int colortype(mode) mode_t mode; { - switch(mode & S_IFMT) { + switch (mode & S_IFMT) { case S_IFDIR: if (mode & S_IWOTH) if (mode & S_ISTXT) @@ -459,22 +460,22 @@ colortype(mode) printcolor(C_WDIR); else printcolor(C_DIR); - return(1); + return (1); case S_IFLNK: printcolor(C_LNK); - return(1); + return (1); case S_IFSOCK: printcolor(C_SOCK); - return(1); + return (1); case S_IFIFO: printcolor(C_FIFO); - return(1); + return (1); case S_IFBLK: printcolor(C_BLK); - return(1); + return (1); case S_IFCHR: printcolor(C_CHR); - return(1); + return (1); } if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) { if (mode & S_ISUID) @@ -483,9 +484,9 @@ colortype(mode) printcolor(C_SGID); else printcolor(C_EXEC); - return(1); + return (1); } - return(0); + return (0); } void @@ -499,20 +500,19 @@ parsecolors(cs) short legacy_warn = 0; if (cs == NULL) - cs = ""; /* LSCOLORS not set */ + cs = ""; /* LSCOLORS not set */ len = strlen(cs); - for (i = 0 ; i < C_NUMCOLORS ; i++) { + for (i = 0; i < C_NUMCOLORS; i++) { colors[i].bold = 0; if (len <= 2 * i) { c[0] = defcolors[2 * i]; c[1] = defcolors[2 * i + 1]; - } - else { + } else { c[0] = cs[2 * i]; c[1] = cs[2 * i + 1]; } - for (j = 0 ; j < 2 ; j++) { + for (j = 0; j < 2; j++) { /* Legacy colours used 0-7 */ if (c[j] >= '0' && c[j] <= '7') { colors[i].num[j] = c[j] - '0'; @@ -546,11 +546,12 @@ colorquit(sig) { endcolor(sig); - (void) signal(sig, SIG_DFL); - (void) kill(getpid(), sig); + (void)signal(sig, SIG_DFL); + (void)kill(getpid(), sig); } -#endif /*COLORLS*/ - + +#endif /* COLORLS */ + static void printlink(p) FTSENT *p; @@ -579,17 +580,16 @@ printsize(width, bytes) off_t bytes; { unit_t unit; - + if (f_humanval) { unit = unit_adjust(&bytes); if (bytes == 0) (void)printf("%*s ", width, "0B"); else - (void)printf("%*qd%c ", width - 1, bytes, - "BKMGTPE"[unit]); - } - else + (void)printf("%*qd%c ", width - 1, bytes, + "BKMGTPE"[unit]); + } else (void)printf("%*qd ", width, bytes); } |