code style

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-06-01 14:59:47 +02:00 committed by sin
parent 97ca7c8b6d
commit 953ebf3573
35 changed files with 58 additions and 94 deletions

View File

@ -39,4 +39,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

1
cal.c
View File

@ -189,4 +189,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -46,4 +46,3 @@ main(int argc, char *argv[])
_exit(savederrno == ENOENT ? 127 : 126); _exit(savederrno == ENOENT ? 127 : 126);
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -93,7 +93,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
cksum(FILE *fp, const char *s) cksum(FILE *fp, const char *s)
{ {
unsigned char buf[BUFSIZ]; unsigned char buf[BUFSIZ];
@ -117,4 +117,3 @@ cksum(FILE *fp, const char *s)
printf(" %s", s); printf(" %s", s);
putchar('\n'); putchar('\n');
} }

7
comm.c
View File

@ -66,7 +66,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
printline(int pos, char *line) printline(int pos, char *line)
{ {
int i; int i;
@ -81,7 +81,7 @@ printline(int pos, char *line)
printf("%s", line); printf("%s", line);
} }
char * static char *
nextline(char *buf, int n, FILE *f, char *name) nextline(char *buf, int n, FILE *f, char *name)
{ {
buf = fgets(buf, n, f); buf = fgets(buf, n, f);
@ -93,7 +93,7 @@ nextline(char *buf, int n, FILE *f, char *name)
return buf; return buf;
} }
void static void
finish(int pos, FILE *f, char *name) finish(int pos, FILE *f, char *name)
{ {
char buf[LINE_MAX+1]; char buf[LINE_MAX+1];
@ -103,4 +103,3 @@ finish(int pos, FILE *f, char *name)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

1
date.c
View File

@ -43,4 +43,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -26,4 +26,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

1
echo.c
View File

@ -31,4 +31,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

3
env.c
View File

@ -34,7 +34,7 @@ main(int argc, char *argv[])
if(*argv) { if(*argv) {
execvp(*argv, argv); execvp(*argv, argv);
enprintf(127-(errno!=EEXIST), "env: '%s':", *argv); enprintf(127 - (errno != EEXIST), "env: '%s':", *argv);
} }
while(environ && *environ) while(environ && *environ)
@ -42,4 +42,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

4
fold.c
View File

@ -58,7 +58,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
fold(FILE *fp, long width) fold(FILE *fp, long width)
{ {
char *buf = NULL; char *buf = NULL;
@ -69,7 +69,7 @@ fold(FILE *fp, long width)
free(buf); free(buf);
} }
void static void
foldline(const char *str, long width) foldline(const char *str, long width)
{ {
bool space; bool space;

2
head.c
View File

@ -46,7 +46,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
head(FILE *fp, const char *str, long n) head(FILE *fp, const char *str, long n)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];

1
kill.c
View File

@ -76,4 +76,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

1
ln.c
View File

@ -41,4 +41,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

13
ls.c
View File

@ -96,7 +96,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
int static int
entcmp(const void *va, const void *vb) entcmp(const void *va, const void *vb)
{ {
const Entry *a = va, *b = vb; const Entry *a = va, *b = vb;
@ -107,7 +107,7 @@ entcmp(const void *va, const void *vb)
return strcmp(a->name, b->name); return strcmp(a->name, b->name);
} }
void static void
ls(Entry *ent) ls(Entry *ent)
{ {
if(S_ISDIR(ent->mode) && !dflag) { if(S_ISDIR(ent->mode) && !dflag) {
@ -117,7 +117,7 @@ ls(Entry *ent)
} }
} }
void static void
lsdir(const char *path) lsdir(const char *path)
{ {
char *cwd, *p; char *cwd, *p;
@ -169,7 +169,7 @@ lsdir(const char *path)
free(cwd); free(cwd);
} }
void static void
mkent(Entry *ent, char *path, bool dostat) mkent(Entry *ent, char *path, bool dostat)
{ {
struct stat st; struct stat st;
@ -188,7 +188,7 @@ mkent(Entry *ent, char *path, bool dostat)
ent->ino = st.st_ino; ent->ino = st.st_ino;
} }
char * static char *
indicator(mode_t mode) indicator(mode_t mode)
{ {
if(!Fflag) if(!Fflag)
@ -210,7 +210,7 @@ indicator(mode_t mode)
return ""; return "";
} }
void static void
output(Entry *ent) output(Entry *ent)
{ {
char buf[BUFSIZ], *fmt; char buf[BUFSIZ], *fmt;
@ -290,4 +290,3 @@ output(Entry *ent)
} }
putchar('\n'); putchar('\n');
} }

View File

@ -53,7 +53,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
mkdirp(char *path) mkdirp(char *path)
{ {
char *p = path; char *p = path;
@ -67,4 +67,3 @@ mkdirp(char *path)
*p = '/'; *p = '/';
} while(p); } while(p);
} }

View File

@ -33,4 +33,3 @@ main(int argc, char *argv[])
eprintf("mkfifo %s:", argv[0]); eprintf("mkfifo %s:", argv[0]);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

5
mv.c
View File

@ -7,7 +7,7 @@
#include "fs.h" #include "fs.h"
#include "util.h" #include "util.h"
int mv(const char *, const char *); static int mv(const char *, const char *);
static void static void
usage(void) usage(void)
@ -37,7 +37,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
int static int
mv(const char *s1, const char *s2) mv(const char *s1, const char *s2)
{ {
if (rename(s1, s2) == 0) if (rename(s1, s2) == 0)
@ -51,4 +51,3 @@ mv(const char *s1, const char *s2)
} }
return -1; return -1;
} }

1
nice.c
View File

@ -46,4 +46,3 @@ main(int argc, char *argv[])
weprintf("execvp %s:", argv[0]); weprintf("execvp %s:", argv[0]);
return (savederrno == ENOENT)? 127 : 126; return (savederrno == ENOENT)? 127 : 126;
} }

1
nl.c
View File

@ -80,4 +80,3 @@ nl(FILE *fp)
} }
free(buf); free(buf);
} }

View File

@ -49,4 +49,3 @@ main(int argc, char *argv[])
return Error; return Error;
} }

41
paste.c
View File

@ -30,9 +30,9 @@ main(int argc, char *argv[])
{ {
const char *adelim = NULL; const char *adelim = NULL;
bool seq = false; bool seq = false;
wchar_t *delim; wchar_t *delim = NULL;
size_t len; size_t len;
Fdescr *dsc; Fdescr *dsc = NULL;
int i; int i;
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
@ -59,8 +59,7 @@ main(int argc, char *argv[])
if(len == (size_t)-1) if(len == (size_t)-1)
eprintf("invalid delimiter\n"); eprintf("invalid delimiter\n");
delim = malloc((len + 1) * sizeof(*delim)); if(!(delim = malloc((len + 1) * sizeof(*delim))))
if(!delim)
eprintf("out of memory\n"); eprintf("out of memory\n");
mbstowcs(delim, adelim, len); mbstowcs(delim, adelim, len);
@ -69,22 +68,19 @@ main(int argc, char *argv[])
eprintf("no delimiters specified\n"); eprintf("no delimiters specified\n");
/* populate file list */ /* populate file list */
dsc = malloc(argc * sizeof(*dsc)); if(!(dsc = malloc(argc * sizeof(*dsc))))
if(!dsc)
eprintf("out of memory\n"); eprintf("out of memory\n");
for(i = 0; i < argc; i++) { for(i = 0; i < argc; i++) {
const char *name = argv[i]; if(strcmp(argv[i], "-") == 0)
if(strcmp(name, "-") == 0)
dsc[i].fp = stdin; dsc[i].fp = stdin;
else else
dsc[i].fp = fopen(name, "r"); dsc[i].fp = fopen(argv[i], "r");
if(!dsc[i].fp) if(!dsc[i].fp)
eprintf("can't open '%s':", name); eprintf("can't open '%s':", argv[i]);
dsc[i].name = name; dsc[i].name = argv[i];
} }
if(seq) if(seq)
@ -160,10 +156,12 @@ static void
sequential(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt) sequential(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt)
{ {
int i; int i;
size_t d;
wint_t c, last;
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
size_t d = 0; d = 0;
wint_t c, last = WEOF; last = WEOF;
while((c = in(&dsc[i])) != WEOF) { while((c = in(&dsc[i])) != WEOF) {
if(last == '\n') { if(last == '\n') {
@ -188,19 +186,17 @@ sequential(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt)
static void static void
parallel(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt) parallel(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt)
{ {
int last; int last, i;
wint_t c, o;
wchar_t d;
do { do {
int i;
last = 0; last = 0;
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
wint_t c; d = delim[i % cnt];
wchar_t d = delim[i % cnt];
do { do {
wint_t o = in(&dsc[i]); o = in(&dsc[i]);
c = o; c = o;
switch(c) { switch(c) {
case WEOF: case WEOF:
@ -212,7 +208,6 @@ parallel(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt)
case '\n': case '\n':
if(i != len - 1) if(i != len - 1)
o = d; o = d;
break; break;
default: default:
break; break;
@ -224,11 +219,9 @@ parallel(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt)
if(d != '\0') if(d != '\0')
out(d); out(d);
} }
out((wchar_t)o); out((wchar_t)o);
} }
} while(c != '\n' && c != WEOF); } while(c != '\n' && c != WEOF);
} }
} while(last > 0); } while(last > 0);
} }

3
pwd.c
View File

@ -34,7 +34,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
const char * static const char *
getpwd(const char *cwd) getpwd(const char *cwd)
{ {
const char *pwd; const char *pwd;
@ -49,4 +49,3 @@ getpwd(const char *cwd)
else else
return cwd; return cwd;
} }

View File

@ -114,4 +114,3 @@ renice(int which, int who, long adj)
return true; return true;
} }

1
rm.c
View File

@ -36,4 +36,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -27,4 +27,3 @@ main(int argc, char *argv[])
; ;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

4
tail.c
View File

@ -52,7 +52,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
dropinit(FILE *fp, const char *str, long n) dropinit(FILE *fp, const char *str, long n)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -64,7 +64,7 @@ dropinit(FILE *fp, const char *str, long n)
concat(fp, str, stdout, "<stdout>"); concat(fp, str, stdout, "<stdout>");
} }
void static void
taketail(FILE *fp, const char *str, long n) taketail(FILE *fp, const char *str, long n)
{ {
char **ring; char **ring;

15
tar.c
View File

@ -61,6 +61,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct stat st;
char *file = NULL, *dir = ".", *ap; char *file = NULL, *dir = ".", *ap;
char mode = '\0'; char mode = '\0';
@ -118,8 +119,6 @@ main(int argc, char *argv[])
usage(); usage();
if(file) { if(file) {
struct stat st;
tarfile = fopen(file, (mode == 'c') ? "wb" : "rb"); tarfile = fopen(file, (mode == 'c') ? "wb" : "rb");
if(!tarfile) if(!tarfile)
eprintf("tar: open '%s':", file); eprintf("tar: open '%s':", file);
@ -142,13 +141,13 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
putoctal(char *dst, unsigned num, int n) putoctal(char *dst, unsigned num, int n)
{ {
snprintf(dst, n, "%.*o", n-1, num); snprintf(dst, n, "%.*o", n-1, num);
} }
int static int
archive(const char* path) archive(const char* path)
{ {
unsigned char b[Blksiz]; unsigned char b[Blksiz];
@ -220,7 +219,7 @@ archive(const char* path)
return 0; return 0;
} }
int static int
unarchive(char *fname, int l, char b[Blksiz]) unarchive(char *fname, int l, char b[Blksiz])
{ {
char lname[101]; char lname[101];
@ -279,7 +278,7 @@ unarchive(char *fname, int l, char b[Blksiz])
return 0; return 0;
} }
int static int
print(char * fname, int l, char b[Blksiz]) print(char * fname, int l, char b[Blksiz])
{ {
puts(fname); puts(fname);
@ -288,14 +287,14 @@ print(char * fname, int l, char b[Blksiz])
return 0; return 0;
} }
void static void
c(const char * path) c(const char * path)
{ {
archive(path); archive(path);
recurse(path, c); recurse(path, c);
} }
void static void
xt(int (*fn)(char*, int, char[Blksiz])) xt(int (*fn)(char*, int, char[Blksiz]))
{ {
char b[Blksiz], fname[101]; char b[Blksiz], fname[101];

3
tee.c
View File

@ -18,7 +18,7 @@ main(int argc, char *argv[])
char buf[BUFSIZ]; char buf[BUFSIZ];
int i, nfps = 1; int i, nfps = 1;
size_t n; size_t n;
FILE **fps; FILE **fps = NULL;
ARGBEGIN { ARGBEGIN {
case 'a': case 'a':
@ -50,4 +50,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

5
test.c
View File

@ -55,7 +55,7 @@ main(int argc, char *argv[])
return ret ? EXIT_SUCCESS : EXIT_FAILURE; return ret ? EXIT_SUCCESS : EXIT_FAILURE;
} }
bool static bool
unary(const char *op, const char *arg) unary(const char *op, const char *arg)
{ {
struct stat st; struct stat st;
@ -112,7 +112,7 @@ unary(const char *op, const char *arg)
return false; /* should not reach */ return false; /* should not reach */
} }
bool static bool
binary(const char *arg1, const char *op, const char *arg2) binary(const char *arg1, const char *op, const char *arg2)
{ {
int i; int i;
@ -156,4 +156,3 @@ binary(const char *arg1, const char *op, const char *arg2)
} }
return false; return false;
} }

View File

@ -45,7 +45,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
touch(const char *str) touch(const char *str)
{ {
int fd; int fd;
@ -69,4 +69,3 @@ touch(const char *str)
close(fd); close(fd);
touch(str); touch(str);
} }

View File

@ -61,4 +61,3 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

12
uniq.c
View File

@ -60,14 +60,14 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void static void
uniqline(char *l) uniqline(char *l)
{ {
bool linesequal = ((l == NULL) || (prevline == NULL)) bool linesequel = ((l == NULL) || (prevline == NULL))
? l == prevline ? l == prevline
: !strcmp(l, prevline); : !strcmp(l, prevline);
if(linesequal) { if(linesequel) {
++prevlinecount; ++prevlinecount;
return; return;
} }
@ -87,7 +87,7 @@ uniqline(char *l)
prevlinecount = 1; prevlinecount = 1;
} }
void static void
uniq(FILE *fp, const char *str) uniq(FILE *fp, const char *str)
{ {
char *buf = NULL; char *buf = NULL;
@ -97,8 +97,8 @@ uniq(FILE *fp, const char *str)
uniqline(buf); uniqline(buf);
} }
void static void
uniqfinish() uniqfinish(void)
{ {
uniqline(NULL); uniqline(NULL);
} }

View File

@ -26,9 +26,8 @@ cp(const char *s1, const char *s2)
DIR *dp; DIR *dp;
if (stat(s1, &st) == 0 && S_ISDIR(st.st_mode)) { if (stat(s1, &st) == 0 && S_ISDIR(st.st_mode)) {
if (!cp_rflag) { if (!cp_rflag)
eprintf("%s: is a directory\n", s1); eprintf("%s: is a directory\n", s1);
}
if(!(dp = opendir(s1))) if(!(dp = opendir(s1)))
eprintf("opendir %s:", s1); eprintf("opendir %s:", s1);

1
yes.c
View File

@ -21,4 +21,3 @@ main(int argc, char *argv[])
puts(argc >= 1 ? argv[0] : "y"); puts(argc >= 1 ? argv[0] : "y");
return EXIT_FAILURE; /* should not reach */ return EXIT_FAILURE; /* should not reach */
} }