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;
}

1
cal.c
View File

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

View File

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

View File

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

7
comm.c
View File

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

1
date.c
View File

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

View File

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

1
echo.c
View File

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

1
env.c
View File

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

4
fold.c
View File

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

2
head.c
View File

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

1
kill.c
View File

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

1
ln.c
View File

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

13
ls.c
View File

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

View File

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

View File

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

5
mv.c
View File

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

1
nice.c
View File

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

1
nl.c
View File

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

View File

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

41
paste.c
View File

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

3
pwd.c
View File

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

View File

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

1
rm.c
View File

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

View File

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

4
tail.c
View File

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

15
tar.c
View File

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

3
tee.c
View File

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

5
test.c
View File

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

View File

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

View File

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

12
uniq.c
View File

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

View File

@ -26,9 +26,8 @@ cp(const char *s1, const char *s2)
DIR *dp;
if (stat(s1, &st) == 0 && S_ISDIR(st.st_mode)) {
if (!cp_rflag) {
if (!cp_rflag)
eprintf("%s: is a directory\n", s1);
}
if(!(dp = opendir(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");
return EXIT_FAILURE; /* should not reach */
}