- Don't require a space between -[fv] and its argument.
- Initial memory allocation for fields was off-by-one.

Approved by:	re (kensmith)
This commit is contained in:
ru 2006-09-18 15:28:12 +00:00
parent 64e48c48e3
commit 93b0c1d4f4
2 changed files with 45 additions and 2 deletions

View File

@ -29,7 +29,7 @@ CLEANFILES+= nawk.1
nawk.1: awk.1
cat ${.ALLSRC} > ${.TARGET}
.for f in b.c main.c run.c
.for f in b.c lib.c main.c run.c
${f}: ${AWKSRC}/${f} ${.CURDIR}/${f}.diff
patch -s -b .orig -o ${.TARGET} < ${.CURDIR}/${f}.diff ${AWKSRC}/${f}
CLEANFILES+= ${f}

View File

@ -6,7 +6,7 @@ RCS file: /home/ncvs/src/contrib/one-true-awk/main.c,v
retrieving revision 1.1.1.10
diff -u -p -r1.1.1.10 main.c
--- main.c 16 May 2005 19:11:31 -0000 1.1.1.10
+++ main.c 17 May 2005 14:41:20 -0000
+++ main.c 15 Sep 2006 13:21:30 -0000
@@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE
THIS SOFTWARE.
****************************************************************/
@ -24,3 +24,46 @@ diff -u -p -r1.1.1.10 main.c
setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
cmdname = argv[0];
if (argc == 1) {
@@ -79,13 +80,18 @@ int main(int argc, char *argv[])
safe = 1;
break;
case 'f': /* next argument is program filename */
- argc--;
- argv++;
- if (argc <= 1)
- FATAL("no program filename");
- if (npfile >= MAX_PFILE - 1)
- FATAL("too many -f options");
- pfile[npfile++] = argv[1];
+ if (argv[1][2] != 0) { /* arg is -fsomething */
+ if (npfile >= MAX_PFILE - 1)
+ FATAL("too many -f options");
+ pfile[npfile++] = &argv[1][2];
+ } else { /* arg is -f something */
+ argc--; argv++;
+ if (argc <= 1)
+ FATAL("no program filename");
+ if (npfile >= MAX_PFILE - 1)
+ FATAL("too many -f options");
+ pfile[npfile++] = argv[1];
+ }
break;
case 'F': /* set field separator */
if (argv[1][2] != 0) { /* arg is -Fsomething */
@@ -104,8 +110,14 @@ int main(int argc, char *argv[])
WARNING("field separator FS is empty");
break;
case 'v': /* -v a=1 to be done NOW. one -v for each */
- if (argv[1][2] == '\0' && --argc > 1 && isclvar((++argv)[1]))
- setclvar(argv[1]);
+ if (argv[1][2] != 0) { /* arg is -vsomething */
+ if (argv[1][2] != 0)
+ setclvar(&argv[1][2]);
+ } else { /* arg is -v something */
+ argc--; argv++;
+ if (argc > 1 && isclvar(argv[1]))
+ setclvar(argv[1]);
+ }
break;
case 'm': /* more memory: -mr=record, -mf=fields */
/* no longer supported */