Back to index

radiance  4R0+20100331
Defines | Functions | Variables
wordfile.c File Reference
#include "copyright.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "platform.h"
#include "standard.h"

Go to the source code of this file.

Defines

#define MAXFLEN   65536 /* file must be smaller than this */

Functions

int wordfile (char **words, char *fname)
int wordstring (char **avl, char *str)

Variables

static const char RCSid [] = "$Id: wordfile.c,v 2.15 2005/06/10 16:42:11 greg Exp $"

Define Documentation

#define MAXFLEN   65536 /* file must be smaller than this */

Definition at line 25 of file wordfile.c.


Function Documentation

int wordfile ( char **  words,
char *  fname 
)

Definition at line 30 of file wordfile.c.

{
       int    fd;
       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);
       close(fd);
       if (n < 0)                         /* read error */
              return(-1);
       if (n == MAXFLEN)           /* file too big, take what we can */
              while (!isspace(buf[--n]))
                     if (n <= 0)          /* one long word! */
                            return(-1);
       buf[n] = '\0';                     /* terminate */
       return(wordstring(words, buf));    /* wordstring does the rest */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int wordstring ( char **  avl,
char *  str 
)

Definition at line 56 of file wordfile.c.

{
       register char *cp, **ap;
       
       if (str == NULL)
              return(-1);
       cp = bmalloc(strlen(str)+1);
       if (cp == NULL)                    /* ENOMEM */
              return(-1);
       strcpy(cp, str);
       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);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: wordfile.c,v 2.15 2005/06/10 16:42:11 greg Exp $" [static]

Definition at line 2 of file wordfile.c.