diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-11 11:54:48 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-11 12:04:13 +0200 |
commit | 7bf7902f4afef0ece6dc911ce744a2a2afc55cbd (patch) | |
tree | f91d24cfc656cffe53a1f16987b23c2ddeff49ca /re.c | |
parent | 4c4fd309cf5c0ea28c17c9b90ebe073a66dcaf72 (diff) | |
download | re-name-7bf7902f4afef0ece6dc911ce744a2a2afc55cbd.tar.gz |
Change coding style
This is the coding style used in Plan 9. Eschewing the whitespace
here has several large benefits:
1. Control constructs are much easier to type.
2. Long conditions are very naturally handled:
if(bla && bla && bla
|| yada && yada && yada)
Because "if(" and "|| " (or "&& ") are the same length, the
two parts of the condition are aligned.
3. It becomes much less bothersome to convert a single-statement
body to a multiple-statement body. It may seem minor, but the
extra space is extra work.
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -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]); } |