--- ray/src/common/wordfile.c 1992/10/17 08:08:02 2.3 +++ ray/src/common/wordfile.c 2005/06/10 16:42:11 2.15 @@ -1,21 +1,29 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: wordfile.c,v 2.15 2005/06/10 16:42:11 greg Exp $"; #endif - /* * Load whitespace separated words from a file into an array. * Assume the passed pointer array is big enough to hold them all. + * + * External symbols declared in standard.h */ +#include "copyright.h" + #include +#include +#include +#include +#include +#include -#define NULL 0 +#include "platform.h" +#include "standard.h" -#define MAXFLEN 8192 /* file must be smaller than this */ -extern char *bmalloc(); +#ifndef MAXFLEN +#define MAXFLEN 65536 /* file must be smaller than this */ +#endif int @@ -27,6 +35,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 +65,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);