Closed wajap closed 7 months ago
good catch, thanks.
your fix included in the latest edition.
When FS is set with the -v option there is no warning The change below fixes this.
diff -au org/main.c new/main.c
--- org/main.c 2023-11-27 20:31:28.000000000 +0100
+++ new/main.c 2023-12-09 11:24:04.323724500 +0100
@@ -157,8 +157,6 @@
}
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;
@@ -180,8 +178,6 @@
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");
@@ -203,6 +199,8 @@
argc--;
argv++;
}
+ if (CSV && (fs != NULL || lookup("FS", symtab) != NULL))
+ WARNING("danger: don't set FS when --csv is in effect");
/* argv[1] is now the first argument */
if (npfile == 0) { /* no -f; first argument is program */
if (argc <= 1) {
ok, noted, fix pushed.
Normal behavior:
echo 'aa,"bb"' | ./nawk_org --csv '{print $1 "|" $2}'
givesaa|bb
But:echo 'aa,"bb"' | ./nawk_org -Fbb --csv '{print $1 "|" $2}'
givesaa,"|"
and no warning Also:echo 'aa,"bb"' |/nawk_org --csv 'BEGIN{FS="bb"}{print $1 "|" $2}'
gives:Below a fix with also a warning when -F is used.