aboutsummaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-11 11:54:48 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-11 12:04:13 +0200
commit7bf7902f4afef0ece6dc911ce744a2a2afc55cbd (patch)
treef91d24cfc656cffe53a1f16987b23c2ddeff49ca /re.c
parent4c4fd309cf5c0ea28c17c9b90ebe073a66dcaf72 (diff)
downloadre-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.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/re.c b/re.c
index f86f3c2..9d3f230 100644
--- a/re.c
+++ b/re.c
@@ -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]);
}