diff options
-rw-r--r-- | name.c | 36 | ||||
-rw-r--r-- | re.c | 20 |
2 files changed, 28 insertions, 28 deletions
@@ -24,10 +24,10 @@ main(int argc, char *argv[]) int c, i, j, s, xflag; /* Allocate memory. */ - for (i = 0; i < MAXFILES; i++) - if (!(froms[i]=malloc(MAXFILE)) || !(tos[i]=malloc(MAXFILE))) + for(i = 0; i < MAXFILES; i++) + if(!(froms[i]=malloc(MAXFILE)) || !(tos[i]=malloc(MAXFILE))) err(1, "malloc"); - if (!(tmp = malloc(MAXLINE*4))) + if(!(tmp = malloc(MAXLINE*4))) err(1, "malloc"); sprintf(file, "/var/tmp/re.%d", getppid()); @@ -37,7 +37,7 @@ main(int argc, char *argv[]) * is input to be read on standard in, as re(1) doesn't create * the file until it starts writing on standard out. */ - if (waitstdin(), access(file, F_OK)) { + if(waitstdin(), access(file, F_OK)){ fprintf(stderr, "%s: %s does not exist\n", argv[0], file); return 1; } @@ -45,8 +45,8 @@ main(int argc, char *argv[]) /* Read command-line options. */ name = argv[0]; xflag = 0; - while ((c = getopt(argc, argv, "x")) != -1) - switch (c) { + while((c = getopt(argc, argv, "x")) != -1) + switch(c){ case 'x': xflag = 1; break; @@ -55,27 +55,27 @@ main(int argc, char *argv[]) } argc -= optind; argv += optind; - if (argc > 0) { + if(argc > 0){ usage: fprintf(stderr, "usage: %s [-x]\n", name); return 1; } - if (!(fp = fopen(file, "r"))) + if(!(fp = fopen(file, "r"))) err(1, "fopen"); /* Read original file names. */ - for (i = 0; i < MAXFILES && fgets(tmp, MAXLINE, fp); i++) { + for(i = 0; i < MAXFILES && fgets(tmp, MAXLINE, fp); i++){ tmp[strcspn(tmp, "\n")] = 0; strcpy(froms[i], tmp); } /* Read new file names. */ - for (j = 0; j < MAXFILES && fgets(tmp, MAXLINE, stdin); j++) { + for(j = 0; j < MAXFILES && fgets(tmp, MAXLINE, stdin); j++){ tmp[strcspn(tmp, "\n")] = 0; strcpy(tos[j], tmp); } - if (i != j) { + if(i != j){ fprintf(stderr, "%s: too %s lines\n", name, j > i ? "many" : "few"); return 1; @@ -85,15 +85,15 @@ usage: fprintf(stderr, "usage: %s [-x]\n", name); * The corresponding mv invocations are printed on standard out. * If the -x flag is given, they are executed too. */ - for (i = 0; i < j; i++) { + for(i = 0; i < j; i++){ escape(froms[i], &tmp); printf("mv '%s'", tmp); escape(tos[i], &tmp); printf(" '%s'\n", tmp); - if (xflag) { - if (!fork()) { + if(xflag){ + if(!fork()){ execl("/bin/mv", "mv", froms[i], tos[i], NULL); err(1, "execl"); } - if (wait(&s), s) { + if(wait(&s), s){ fprintf(stderr, "/bin/mv exited with %d\n", WEXITSTATUS(s)); return 1; @@ -111,8 +111,8 @@ escape(char *str, char **res) { int i, j, offset; - for (i = j = 0; str[i]; i++) { - if (str[i] == '\'') { + for(i = j = 0; str[i]; i++){ + if(str[i] == '\''){ strcat(*res, "'\\''"); j += 4; } else @@ -129,6 +129,6 @@ waitstdin() FD_ZERO(&readfds); FD_SET(0, &readfds); - if (select(1, &readfds, NULL, NULL, NULL) == -1) + if(select(1, &readfds, NULL, NULL, NULL) == -1) err(1, "select"); } @@ -9,35 +9,35 @@ main(int argc, char *argv[]) FILE *fp; int i; - if (argc-1 == 0) { + if(argc-1 == 0){ fprintf(stderr, "usage: %s file [...]\n", argv[0]); return 1; } /* Ensure arguments do not contain newlines. */ - for (i = 1; i < argc; i++) - for (a = argv[i]; *a; a++) - if (*a == '\n') { + for(i = 1; i < argc; i++) + for(a = argv[i]; *a; a++) + if(*a == '\n'){ *a = '*'; fprintf(stderr, - "%s contains newline (at *)\n", + "%s contains newline(at *)\n", argv[i]); return 1; } sprintf(file, "/var/tmp/re.%d", getppid()); - if (!access(file, F_OK)) { + if(!access(file, F_OK)){ do fprintf(stderr, "%s already exists; overwrite? ", file); - while (!gets(ans) || !*ans); - if (ans[0] != 'y') return 1; + while(!gets(ans) || !*ans); + if(ans[0] != 'y') return 1; } - if (!(fp = fopen(file, "w"))) + if(!(fp = fopen(file, "w"))) err(1, "fopen"); - for (i = 1; i < argc; i++) { + for(i = 1; i < argc; i++){ fprintf(fp, "%s\n", argv[i]); printf("%s\n", argv[i]); } |