awk: Make -F '' and -v FS="" behave the same

IEEE Std 1003.1-2008 mandates that -F str be treated the same as -v
FS=str. For a null string, this was not the case. Since awk(1) documents
that a null string for FS has a specific behavior, make -F '' behave
consistently with -v FS="".

PR:
upstream issue:		https://github.com/onetrueawk/awk/issues/127
Sponsored by:		Netflix
This commit is contained in:
Warner Losh 2021-07-19 22:47:30 -06:00
parent c0f4e97e45
commit 45dab2a7e0
1 changed files with 1 additions and 5 deletions

6
main.c
View File

@ -91,9 +91,7 @@ setfs(char *p)
/* wart: t=>\t */ /* wart: t=>\t */
if (p[0] == 't' && p[1] == '\0') if (p[0] == 't' && p[1] == '\0')
return "\t"; return "\t";
else if (p[0] != '\0') return p;
return p;
return NULL;
} }
static char * static char *
@ -169,8 +167,6 @@ int main(int argc, char *argv[])
break; break;
case 'F': /* set field separator */ case 'F': /* set field separator */
fs = setfs(getarg(&argc, &argv, "no field separator")); fs = setfs(getarg(&argc, &argv, "no field separator"));
if (fs == NULL)
WARNING("field separator FS is empty");
break; break;
case 'v': /* -v a=1 to be done NOW. one -v for each */ case 'v': /* -v a=1 to be done NOW. one -v for each */
vn = getarg(&argc, &argv, "no variable name"); vn = getarg(&argc, &argv, "no variable name");