From 0ba05dd5a679e7723ea4b9f1426175b1651926cf Mon Sep 17 00:00:00 2001 From: jsm Date: Thu, 21 Sep 2000 17:44:34 +0000 Subject: Various improvements to parsing in battlestar, mostly from OpenBSD. Define a constant WORDLEN. Always use this constant and NWORD where appropriate. Use NWORD - 1 in battlestar.c to avoid off-by-one error. Increment wordnumber after the INVEN verb to allow it to be followed by a comma and other actions. Avoid overflowing elements of the words array if input words are too long. Parse "," as AND except when followed by a verb, to allow such constructions as "take foo, bar, and baz". Trim AND AND which may occur from the ", and" in such a list. Avoid crashes from EVERYTHING in the wrong place by moving it to the start of OBJECT AND EVERYTHING and NOUNS AND EVERYTHING sequences, and trimming EVERYTHING AND EVERYTHING. --- battlestar/battlestar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'battlestar/battlestar.c') diff --git a/battlestar/battlestar.c b/battlestar/battlestar.c index 6d0ab8ec..a6a11efa 100644 --- a/battlestar/battlestar.c +++ b/battlestar/battlestar.c @@ -1,4 +1,4 @@ -/* $NetBSD: battlestar.c,v 1.11 2000/09/08 17:22:01 jsm Exp $ */ +/* $NetBSD: battlestar.c,v 1.12 2000/09/21 17:44:34 jsm Exp $ */ /* * Copyright (c) 1983, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ #if 0 static char sccsid[] = "@(#)battlestar.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: battlestar.c,v 1.11 2000/09/08 17:22:01 jsm Exp $"); +__RCSID("$NetBSD: battlestar.c,v 1.12 2000/09/21 17:44:34 jsm Exp $"); #endif #endif /* not lint */ @@ -96,7 +96,7 @@ start: run: next = getcom(mainbuf, sizeof mainbuf, ">-: ", "Please type in something."); - for (wordcount = 0; next && wordcount < 20; wordcount++) + for (wordcount = 0; next && wordcount < NWORD - 1; wordcount++) next = getword(next, words[wordcount], -1); parse(); switch (cypher()) { -- cgit v1.2.3