--- ray/src/common/wordfile.c 1992/10/17 08:08:02 2.3 +++ ray/src/common/wordfile.c 1993/06/18 09:00:22 2.7 @@ -27,6 +27,8 @@ char *fname; char buf[MAXFLEN]; register int n; /* load file into buffer */ + if (fname == NULL) + return(-1); /* no filename */ if ((fd = open(fname, 0)) < 0) return(-1); /* open error */ n = read(fd, buf, MAXFLEN); @@ -55,14 +57,15 @@ char *str; if (cp == NULL) /* ENOMEM */ return(-1); strcpy(cp, str); - for (ap = avl; *cp; *cp++ = '\0') { - while (isspace(*cp)) /* skip leading space */ - cp++; - if (*cp) { /* add argument to list */ - *ap++ = cp; - while (*cp && !isspace(*cp)) - cp++; - } + ap = avl; /* parse into words */ + for ( ; ; ) { + while (isspace(*cp)) /* nullify spaces */ + *cp++ = '\0'; + if (!*cp) /* all done? */ + break; + *ap++ = cp; /* add argument to list */ + while (*++cp && !isspace(*cp)) + ; } *ap = NULL; return(ap - avl);