aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorozan yigit <ozan.yigit@gmail.com>2023-11-27 23:13:53 -0500
committerozan yigit <ozan.yigit@gmail.com>2023-11-27 23:13:53 -0500
commita9642137999b3cefaca03d53e6f42b0a458fa13b (patch)
tree814ec57c50b972d5f43cf2dfedb7176d71c61291
parent0096fa60008346f24de36064930c911ced766961 (diff)
downloadone-true-awk-a9642137999b3cefaca03d53e6f42b0a458fa13b.tar.gz
Wilbert van der Poel's fixes to inconsistent handling of -F and --csv.
-rw-r--r--lib.c2
-rw-r--r--main.c4
-rwxr-xr-xtestdir/T.csv4
3 files changed, 7 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index b5b83f8..7fb9ac3 100644
--- a/lib.c
+++ b/lib.c
@@ -399,7 +399,7 @@ void fldbld(void) /* create fields from current record */
i = 0; /* number of fields accumulated here */
if (inputFS == NULL) /* make sure we have a copy of FS */
savefs();
- if (strlen(inputFS) > 1) { /* it's a regular expression */
+ if (!CSV && strlen(inputFS) > 1) { /* it's a regular expression */
i = refldbld(r, inputFS);
} else if (!CSV && (sep = *inputFS) == ' ') { /* default whitespace */
for (i = 0; ; ) {
diff --git a/main.c b/main.c
index c478e32..a5d4f1c 100644
--- a/main.c
+++ b/main.c
@@ -157,6 +157,8 @@ int main(int argc, char *argv[])
}
if (strcmp(argv[1], "--csv") == 0) { /* turn on csv input processing */
CSV = true;
+ if (fs)
+ WARNING("danger: don't set FS when --csv is in effect");
argc--;
argv++;
continue;
@@ -178,6 +180,8 @@ int main(int argc, char *argv[])
break;
case 'F': /* set field separator */
fs = setfs(getarg(&argc, &argv, "no field separator"));
+ if (CSV)
+ WARNING("danger: don't set FS when --csv is in effect");
break;
case 'v': /* -v a=1 to be done NOW. one -v for each */
vn = getarg(&argc, &argv, "no variable name");
diff --git a/testdir/T.csv b/testdir/T.csv
index 79c1510..40ef0c6 100755
--- a/testdir/T.csv
+++ b/testdir/T.csv
@@ -17,8 +17,8 @@ $1 ~ /try/ { # new test
sub(/try /, "")
prog = $0
printf("%3d %s\n", nt, prog)
- prog = sprintf("%s -F\"\\t\" '"'"'%s'"'"'", awk, prog)
- # print "prog is", prog
+ prog = sprintf("%s '"'"'%s'"'"'", awk, prog)
+ print "prog is", prog
nt2 = 0
while (getline > 0) {
if (NF == 0) # blank line terminates a sequence