ref: a9642137999b3cefaca03d53e6f42b0a458fa13b
parent: 0096fa60008346f24de36064930c911ced766961
author: ozan yigit <ozan.yigit@gmail.com>
date: Mon Nov 27 18:13:53 EST 2023
Wilbert van der Poel's fixes to inconsistent handling of -F and --csv.
--- a/lib.c
+++ b/lib.c
@@ -399,7 +399,7 @@
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; ; ) {--- a/main.c
+++ b/main.c
@@ -157,6 +157,8 @@
}
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 @@
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");
--- a/testdir/T.csv
+++ b/testdir/T.csv
@@ -17,8 +17,8 @@
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
--
⑨