aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--awk.h9
-rw-r--r--builtin.c2
-rw-r--r--eval.c22
-rw-r--r--io.c8
-rw-r--r--main.c4
6 files changed, 37 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b81ade5..8fba6f20 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-12-09 Arnold D. Robbins <arnold@skeeve.com>
+
+ Clean up BINMODE to use symbolic values.
+
+ * awk.h (enum binmode_values): New enum.
+ * eval.c (set_BINMODE): Use them.
+ * io.c (binmode, close_rp, gawk_popen): Ditto.
+ * main.c (main): Ditto.
+ * builtin.c (do_system): Ditto.
+
2012-12-07 Arnold D. Robbins <arnold@skeeve.com>
* awkgram.y (tokentab): `fflush()' is now in POSIX, remove the
diff --git a/awk.h b/awk.h
index 0a0ac136..7dcecd29 100644
--- a/awk.h
+++ b/awk.h
@@ -836,6 +836,15 @@ struct redirect {
const char *mode;
};
+/* values for BINMODE, used as bit flags */
+
+enum binmode_values {
+ TEXT_TRANSLATE = 0, /* usual \r\n ---> \n translation */
+ BINMODE_INPUT = 1, /* no translation for input files */
+ BINMODE_OUTPUT = 2, /* no translation for output files */
+ BINMODE_BOTH = 3 /* no translation for either */
+};
+
/*
* structure for our source, either a command line string or a source file.
*/
diff --git a/builtin.c b/builtin.c
index aed9dfe5..be99cbca 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1844,7 +1844,7 @@ do_system(int nargs)
ret = system(cmd);
if (ret != -1)
ret = WEXITSTATUS(ret);
- if ((BINMODE & 1) != 0)
+ if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(fileno(stdin), O_BINARY);
cmd[tmp->stlen] = save;
diff --git a/eval.c b/eval.c
index 57411afc..49395d3a 100644
--- a/eval.c
+++ b/eval.c
@@ -754,14 +754,14 @@ set_BINMODE()
lintwarn(_("`BINMODE' is a gawk extension"));
}
if (do_traditional)
- BINMODE = 0;
+ BINMODE = TEXT_TRANSLATE;
else if ((BINMODE_node->var_value->flags & NUMBER) != 0) {
BINMODE = (int) force_number(BINMODE_node->var_value);
/* Make sure the value is rational. */
- if (BINMODE < 0)
- BINMODE = 0;
- else if (BINMODE > 3)
- BINMODE = 3;
+ if (BINMODE < TEXT_TRANSLATE)
+ BINMODE = TEXT_TRANSLATE;
+ else if (BINMODE > BINMODE_BOTH)
+ BINMODE = BINMODE_BOTH;
}
else if ((BINMODE_node->var_value->flags & STRING) != 0) {
v = BINMODE_node->var_value;
@@ -783,13 +783,13 @@ set_BINMODE()
BINMODE = p[0] - '0';
break;
case 'r':
- BINMODE = 1;
+ BINMODE = BINMODE_INPUT;
break;
case 'w':
- BINMODE = 2;
+ BINMODE = BINMODE_OUTPUT;
break;
default:
- BINMODE = 3;
+ BINMODE = BINMODE_BOTH;
goto bad_value;
break;
}
@@ -797,21 +797,21 @@ set_BINMODE()
case 2:
switch (p[0]) {
case 'r':
- BINMODE = 3;
+ BINMODE = BINMODE_BOTH;
if (p[1] != 'w')
goto bad_value;
break;
case 'w':
- BINMODE = 3;
+ BINMODE = BINMODE_BOTH;
if (p[1] != 'r')
goto bad_value;
break;
+ }
break;
default:
bad_value:
lintwarn(_("BINMODE value `%s' is invalid, treated as 3"), p);
break;
- }
}
}
else
diff --git a/io.c b/io.c
index c57aef2a..efdec065 100644
--- a/io.c
+++ b/io.c
@@ -233,12 +233,12 @@ binmode(const char *mode)
{
switch (mode[0]) {
case 'r':
- if ((BINMODE & 1) != 0)
+ if ((BINMODE & BINMODE_INPUT) != 0)
mode = "rb";
break;
case 'w':
case 'a':
- if ((BINMODE & 2) != 0)
+ if ((BINMODE & BINMODE_OUTPUT) != 0)
mode = (mode[0] == 'w' ? "wb" : "ab");
break;
}
@@ -1017,7 +1017,7 @@ close_rp(struct redirect *rp, two_way_close_type how)
}
} else if ((rp->flag & (RED_PIPE|RED_WRITE)) == (RED_PIPE|RED_WRITE)) { /* write to pipe */
status = pclose(rp->fp);
- if ((BINMODE & 1) != 0)
+ if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(fileno(stdin), O_BINARY);
rp->fp = NULL;
@@ -2134,7 +2134,7 @@ gawk_popen(const char *cmd, struct redirect *rp)
os_restore_mode(fileno(stdin));
current = popen(cmd, binmode("r"));
- if ((BINMODE & 1) != 0)
+ if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(fileno(stdin), O_BINARY);
if (current == NULL)
return NULL;
diff --git a/main.c b/main.c
index 2bb0b01f..4292874a 100644
--- a/main.c
+++ b/main.c
@@ -611,10 +611,10 @@ out:
if (preassigns != NULL)
efree(preassigns);
- if ((BINMODE & 1) != 0)
+ if ((BINMODE & BINMODE_INPUT) != 0)
if (os_setbinmode(fileno(stdin), O_BINARY) == -1)
fatal(_("can't set binary mode on stdin (%s)"), strerror(errno));
- if ((BINMODE & 2) != 0) {
+ if ((BINMODE & BINMODE_OUTPUT) != 0) {
if (os_setbinmode(fileno(stdout), O_BINARY) == -1)
fatal(_("can't set binary mode on stdout (%s)"), strerror(errno));
if (os_setbinmode(fileno(stderr), O_BINARY) == -1)