Back to index

radiance  4R0+20100331
Functions
rtio.h File Reference
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>

Go to the source code of this file.

Functions

int badarg (int ac, char **av, char *fl)
int expandarg (int *acp, char ***avp, int n)
time_t fdate (char *fname)
int setfdate (char *fname, long ftim)
char * fgetline (char *s, int n, FILE *fp)
int fgetval (FILE *fp, int ty, void *vp)
char * fgetword (char *s, int n, FILE *fp)
void fputword (char *s, FILE *fp)
FILE * frlibopen (char *fname)
char * getrlibpath (void)
char * gethomedir (char *uname, char *path, int plen)
char * getpath (char *fname, char *searchpath, int mode)
void swap16 (char *wp, int n)
void swap32 (char *wp, int n)
void swap64 (char *wp, int n)
void putstr (char *s, FILE *fp)
void putint (long i, int siz, FILE *fp)
void putflt (double f, FILE *fp)
char * getstr (char *s, FILE *fp)
long getint (int siz, FILE *fp)
double getflt (FILE *fp)
int ecompile (char *sp, int iflg, int wflag)
char * expsave (void)
void expset (char *ep)
char * eindex (char *sp)
char * savestr (char *str)
void freestr (char *s)
int shash (char *s)
char * savqstr (char *s)
void freeqstr (char *s)
int wordfile (char **words, char *fname)
int wordstring (char **avl, char *str)
char * atos (char *rs, int nb, char *s)
char * nextword (char *cp, int nb, char *s)
char * sskip (char *s)
char * sskip2 (char *s, int n)
char * iskip (char *s)
char * fskip (char *s)
int isint (char *s)
int isintd (char *s, char *ds)
int isflt (char *s)
int isfltd (char *s, char *ds)
float * matchlamp (char *s)
int loadlamps (char *file)
void freelamps (void)

Function Documentation

char* atos ( char *  rs,
int  nb,
char *  s 
)

Definition at line 18 of file words.c.

{
       register char  *cp = rs;

       while (isspace(*s))
              s++;
       while (--nb > 0 && *s && !isspace(*s))
              *cp++ = *s++;
       *cp = '\0';
       return(rs);
}

Here is the caller graph for this function:

int badarg ( int  ac,
char **  av,
char *  fl 
)

Definition at line 15 of file badarg.c.

{
       register int  i;

       if (fl == NULL)
              fl = "";             /* no arguments? */
       for (i = 1; *fl; i++,av++,fl++) {
              if (i > ac || *av == NULL)
                     return(-1);
              switch (*fl) {
              case 's':            /* string */
                     if (**av == '\0' || isspace(**av))
                            return(i);
                     break;
              case 'i':            /* integer */
                     if (!isintd(*av, " \t\r\n"))
                            return(i);
                     break;
              case 'f':            /* float */
                     if (!isfltd(*av, " \t\r\n"))
                            return(i);
                     break;
              default:             /* bad call! */
                     return(-1);
              }
       }
       return(0);           /* all's well */
}
int ecompile ( char *  sp,
int  iflg,
int  wflag 
)

Definition at line 48 of file rexpr.c.

{
        register int c;
        register char *ep;
        char *lastep = NULL;
        int cclcnt;
        
        iflag = iflg;
        ep = expbuf;
       explen = 0;
        if (*sp == '^') {
                circf = 1;
                sp++;
        } else
              circf = 0;
        if (wflag)
                *ep++ = CBRC;
        for (;;) {
                if (ep >= &expbuf[ESIZE])
                        return(-1);
                if ((c = *sp++) != '*')
                        lastep = ep;
                switch (c) {

                case '\0':
                        if (wflag)
                                *ep++ = CLET;
                        *ep++ = CEOF;
                     explen = ep - expbuf;
                        return(0);

                case '.':
                        *ep++ = CDOT;
                        continue;

                case '*':
                        if (lastep==0)
                                goto defchar;
                        *lastep |= STAR;
                        continue;

                case '$':
                        if (*sp != '\0')
                                goto defchar;
                        *ep++ = CDOL;
                        continue;

                case '[':
                        *ep++ = CCL;
                        *ep++ = 0;
                        cclcnt = 1;
                        if ((c = *sp++) == '^') {
                                c = *sp++;
                                ep[-2] = NCCL;
                        }
                        do {
                                *ep++ = c;
                                cclcnt++;
                                if (c=='\0' || ep >= &expbuf[ESIZE])
                                        return(-1);
                        } while ((c = *sp++) != ']');
                        lastep[1] = cclcnt;
                        continue;

                case '\\':
                        if ((c = *sp++) == '\0')
                                return(-1);
                        if (c == '<') {
                            if (ep == expbuf || ep[-1] != CBRC)
                                   *ep++ = CBRC;
                                continue;
                        }
                        if (c == '>') {
                                *ep++ = CLET;
                                continue;
                        }
                defchar:
                default:
                        *ep++ = CCHR;
                        *ep++ = c;
                }
        }
}

Here is the caller graph for this function:

char* eindex ( char *  sp)

Definition at line 160 of file rexpr.c.

{
       /* check for match at beginning of line, watch CBRC */
       if (advance(sp, expbuf[0]==CBRC ? expbuf+1 : expbuf))
              return(sp);
       if (circf)
                return(NULL);
        /* fast check for first character */
        if (expbuf[0]==CCHR) {
              register int c = expbuf[1];
              while (*++sp)
                     if (same(*sp, c) && advance(sp, expbuf))
                            return(sp);
                return(NULL);
        }
        /* regular algorithm */
       while (*++sp)
                if (advance(sp, expbuf))
                        return(sp);
        return(NULL);
}

Here is the call graph for this function:

int expandarg ( int *  acp,
char ***  avp,
int  n 
)

Definition at line 27 of file expandarg.c.

{
       int    ace;
       char   *ave[MAXARGEXP];
       char   **newav;
                                   /* check argument */
       if (n >= *acp)
              return(0);
       errno = 0;    
       if ((*avp)[n][0] == filexpchr) {          /* file name */
              ace = wordfile(ave, (*avp)[n]+1);
              if (ace < 0)
                     return(-1);   /* no such file */
       } else if ((*avp)[n][0] == envexpchr) {          /* env. variable */
              ace = wordstring(ave, getenv((*avp)[n]+1));
              if (ace < 0)
                     return(-1);   /* no such variable */
       } else                                    /* regular argument */
              return(0);
                                   /* allocate new pointer list */
       newav = (char **)bmalloc((*acp+ace)*sizeof(char *));
       if (newav == NULL)
              return(-1);
                                   /* copy preceeding arguments */
       memcpy((void *)newav, (void *)*avp, n*sizeof(char *));
                                   /* copy expanded argument */
       memcpy((void *)(newav+n), (void *)ave, ace*sizeof(char *));
                                   /* copy trailing arguments + NULL */
       memcpy((void *)(newav+n+ace), (void *)(*avp+n+1), (*acp-n)*sizeof(char *));
                                   /* free old list */
       bfree((char *)*avp, (*acp+1)*sizeof(char *));
                                   /* assign new list */
       *acp += ace-1;
       *avp = newav;
       return(1);                  /* return success */
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* expsave ( void  )

Definition at line 135 of file rexpr.c.

{
       register char  *ep;

       if (explen == 0)
              return(NULL);
       if ((ep = (char *)malloc(explen+3)) == NULL)
              return(NULL);
       ep[0] = iflag;
       ep[1] = circf;
       ep[2] = explen;
       (void)memcpy(ep+3, expbuf, explen);
       return(ep);
}
void expset ( char *  ep)

Definition at line 151 of file rexpr.c.

{
       iflag = ep[0];
       circf = ep[1];
       (void)memcpy(expbuf, ep+3, ep[2]&0xff);
}

Here is the caller graph for this function:

time_t fdate ( char *  fname)

Definition at line 22 of file fdate.c.

{
       struct stat  sbuf;

       if (stat(fname, &sbuf) == -1)
              return(0);

       return(sbuf.st_mtime);
}

Here is the caller graph for this function:

char* fgetline ( char *  s,
int  n,
FILE *  fp 
)

Definition at line 21 of file fgetline.c.

{
       register char  *cp = s;
       register int  c = EOF;

       while (--n > 0 && (c = getc(fp)) != EOF) {
              if (c == '\r' && (c = getc(fp)) != '\n') {
                     ungetc(c, fp);              /* must be Apple file */
                     c = '\n';
              }
              if (c == '\n' && (cp == s || cp[-1] != '\\'))
                     break;
              *cp++ = c;
       }
       if (cp == s && c == EOF)
              return(NULL);
       *cp = '\0';
       return(s);
}

Here is the caller graph for this function:

int fgetval ( FILE *  fp,
int  ty,
void *  vp 
)

Definition at line 17 of file fgetval.c.

{
       char   wrd[64];
       register char *cp;
       register int  c;
                                   /* elide comments (# to EOL) */
       do {
              while ((c = getc(fp)) != EOF && isspace(c))
                     ;
              if (c == '#')
                     while ((c = getc(fp)) != EOF && c != '\n')
                            ;
       } while (c == '\n');
       if (c == EOF)
              return(EOF);
                                   /* get word */
       cp = wrd;
       do {
              *cp++ = c;
              if (cp - wrd >= sizeof(wrd))
                     return(0);
       } while ((c = getc(fp)) != EOF && !isspace(c) && c != '#');
       if (c != EOF)
              ungetc(c, fp);
       *cp = '\0';
       switch (ty) {               /* check and convert it */
       case 'h':                   /* short */
              if (!isint(wrd))
                     return(0);
              *(short *)vp = c = atoi(wrd);
              if (*(short *)vp != c)
                     return(0);
              return(1);
       case 'i':                   /* integer */
              if (!isint(wrd))
                     return(0);
              *(int *)vp = atoi(wrd);
              return(1);
       case 'l':                   /* long */
              if (!isint(wrd))
                     return(0);
              *(long *)vp = atol(wrd);
              return(1);
       case 'f':                   /* float */
              if (!isflt(wrd))
                     return(0);
              *(float *)vp = atof(wrd);
              return(1);
       case 'd':                   /* double */
              if (!isflt(wrd))
                     return(0);
              *(double *)vp = atof(wrd);
              return(1);
       case 's':                   /* string */
              strcpy(vp, wrd);
              return(1);
       default:                    /* unsupported type */
              return(0);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* fgetword ( char *  s,
int  n,
FILE *  fp 
)
void fputword ( char *  s,
FILE *  fp 
)

Definition at line 17 of file fputword.c.

{
       int           hasspace = 0;
       int           quote = 0;
       register char *cp;
                                   /* check if quoting needed */
       for (cp = s; *cp; cp++)
              if (isspace(*cp))
                     hasspace++;
              else if (*cp == '"')
                     quote = '\'';
              else if (*cp == '\'')
                     quote = '"';

       if (hasspace || quote) {    /* output with quotes */
              if (!quote) quote = '"';
              fputc(quote, fp);
              fputs(s, fp);
              fputc(quote, fp);
       } else                      /* output sans quotes */
              fputs(s, fp);
}

Here is the caller graph for this function:

void freelamps ( void  )

Definition at line 134 of file lamps.c.

{
       register LAMP *lp1, *lp2;
       
       for (lp1 = lamps; lp1 != NULL; lp1 = lp2) {
              free(lp1->pattern);
              if (lp1->color != NULL) {
                     for (lp2 = lp1->next; lp2 != NULL; lp2 = lp2->next)
                            if (lp2->color == lp1->color)
                                   lp2->color = NULL;
                     free((void *)lp1->color);
              }
              lp2 = lp1->next;
              free((void *)lp1);
       }
       lamps = NULL;
}

Here is the caller graph for this function:

void freeqstr ( char *  s)

Definition at line 41 of file savqstr.c.

{
       if (s != NULL)
              free((void *)s);
}

Here is the caller graph for this function:

void freestr ( char *  s)

Definition at line 77 of file savestr.c.

{
       int  hval;
       register S_HEAD  *spl, *sp;

       if (s == NULL)
              return;
       hval = hash(s);
       for (spl = NULL, sp = stab[hval]; sp != NULL; spl = sp, sp = sp->next)
              if (s == string(sp)) {
                     if (--sp->nl > 0)
                            return;
                     if (spl != NULL)
                            spl->next = sp->next;
                     else
                            stab[hval] = sp->next;
                     sfree(sp);
                     return;
              }
}

Here is the caller graph for this function:

FILE* frlibopen ( char *  fname)

Definition at line 19 of file fropen.c.

{
       FILE  *fp;
       char  pname[PATH_MAX];
       register char  *sp, *cp;

       if (fname == NULL)
              return(NULL);

       if (ISDIRSEP(fname[0]) || fname[0] == '.')       /* absolute path */
              return(fopen(fname, "r"));
                                          /* check search path */
       sp = getrlibpath();
       do {
              cp = pname;
              while (*sp && (*cp = *sp++) != PATHSEP)
                     cp++;
              if (cp > pname && !ISDIRSEP(cp[-1]))
                     *cp++ = DIRSEP;
              strcpy(cp, fname);
              if ((fp = fopen(pname, "r")) != NULL)
                     return(fp);                 /* got it! */
       } while (*sp);
                                          /* not found */
       return(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* fskip ( char *  s)

Definition at line 108 of file words.c.

{
       register char  *cp;

       while (isspace(*s))
              s++;
       if (*s == '-' || *s == '+')
              s++;
       cp = s;
       while (isdigit(*cp))
              cp++;
       if (*cp == '.') {
              cp++; s++;
              while (isdigit(*cp))
                     cp++;
       }
       if (cp == s)
              return(NULL);
       if (*cp == 'e' || *cp == 'E')
              return(iskip(cp+1));
       return(cp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double getflt ( FILE *  fp)

Definition at line 106 of file portio.c.

{
       long   l;
       double d;

       l = getint(4, fp);
       if (l == 0) {
              getc(fp);            /* exactly zero -- ignore exponent */
              return(0.0);
       }
       d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff);
       return(ldexp(d, (int)getint(1, fp)));
}
char* gethomedir ( char *  uname,
char *  path,
int  plen 
)

Definition at line 52 of file gethomedir.c.

{
       struct passwd *pwent;
       uid_t uid;
       char *cp;

       if (uname == NULL || *uname == '\0') {    /* ours */
              if ((cp = getenv("HOME")) != NULL) {
                     strncpy(path, cp, plen);
                     path[plen-1] = '\0';
                     return path;
              }
              uid = getuid();
              if ((pwent = getpwuid(uid)) == NULL)
                     return(NULL); /* we don't exist ?!? */
              strncpy(path, pwent->pw_dir, plen);
              path[plen-1] = '\0';
              return path;
       }
       /* someone else */
       if ((pwent = getpwnam(uname)) == NULL)
              return(NULL); /* no such user */

       strncpy(path, pwent->pw_dir, plen);
       path[plen-1] = '\0';
       return path;
}

Here is the caller graph for this function:

long getint ( int  siz,
FILE *  fp 
)

Definition at line 85 of file portio.c.

{
       register int  c;
       register long  r;

       if ((c = getc(fp)) == EOF)
              return(EOF);
       r = 0x80&c ? -1<<8|c : c;          /* sign extend */
       while (--siz > 0) {
              if ((c = getc(fp)) == EOF)
                     return(EOF);
              r <<= 8;
              r |= c;
       }
       return(r);
}
char* getpath ( char *  fname,
char *  searchpath,
int  mode 
)
char* getrlibpath ( void  )

Definition at line 18 of file getlibpath.c.

{
       static char   *libpath = NULL;

       if (libpath == NULL)
              if ((libpath = getenv(ULIBVAR)) == NULL)
                     libpath = DEFPATH;

       return(libpath);
}

Here is the caller graph for this function:

char* getstr ( char *  s,
FILE *  fp 
)

Definition at line 68 of file portio.c.

{
       register char  *cp;
       register int  c;

       cp = s;
       while ((c = getc(fp)) != EOF)
              if ((*cp++ = c) == '\0')
                     return(s);
              
       return(NULL);
}
int isflt ( char *  s)

Definition at line 156 of file words.c.

{
       register char  *cp;

       cp = fskip(s);
       return(cp != NULL && *cp == '\0');
}

Here is the caller graph for this function:

int isfltd ( char *  s,
char *  ds 
)

Definition at line 167 of file words.c.

{
       register char  *cp;

       cp = fskip(s);
       return(cp != NULL && strchr(ds, *cp) != NULL);
}

Here is the caller graph for this function:

int isint ( char *  s)

Definition at line 134 of file words.c.

{
       register char  *cp;

       cp = iskip(s);
       return(cp != NULL && *cp == '\0');
}
int isintd ( char *  s,
char *  ds 
)

Definition at line 145 of file words.c.

{
       register char  *cp;

       cp = iskip(s);
       return(cp != NULL && strchr(ds, *cp) != NULL);
}

Here is the caller graph for this function:

char* iskip ( char *  s)

Definition at line 91 of file words.c.

{
       while (isspace(*s))
              s++;
       if (*s == '-' || *s == '+')
              s++;
       if (!isdigit(*s))
              return(NULL);
       do
              s++;
       while (isdigit(*s));
       return(s);
}

Here is the caller graph for this function:

int loadlamps ( char *  file)

Definition at line 45 of file lamps.c.

{
       LAMP   *lastp;
       register LAMP *lp;
       FILE   *fp;
       float  xyz[3];
       char   buf[128], str[128];
       register char *cp1, *cp2;

       if ((fp = frlibopen(file)) == NULL)
              return(0);
       lastp = NULL;
       while (fgets(buf, sizeof(buf), fp) != NULL) {
                                   /* work on a copy of buffer */
              strcpy(str, buf);
                                   /* get pattern for this entry */
              for (cp1 = str; isspace(*cp1); cp1++)
                     ;
              if (!*cp1 || *cp1 == '#')
                     continue;
              for (cp2 = cp1+1; *cp2; cp2++)
                     if (*cp2 == *cp1 && cp2[-1] != '\\')
                            break;
              if (!*cp2) {
                     cp1 = "unclosed pattern";
                     goto fmterr;
              }
              cp1++; *cp2++ = '\0';
              if (ecompile(cp1, 1, 0) < 0) {
                     cp1 = "bad regular expression";
                     goto fmterr;
              }
              if ((lp = (LAMP *)malloc(sizeof(LAMP))) == NULL)
                     goto memerr;
              if ((lp->pattern = expsave()) == NULL)
                     goto memerr;
                                          /* get specification */
              for (cp1 = cp2; isspace(*cp1); cp1++)
                     ;
              if (!isdigit(*cp1) && *cp1 != '.' && *cp1 != '(') {
                     cp1 = "missing lamp specification";
                     goto fmterr;
              }
              if (*cp1 == '(') {          /* find alias */
                     for (cp2 = ++cp1; *cp2; cp2++)
                            if (*cp2 == ')' && cp2[-1] != '\\')
                                   break;
                     *cp2 = '\0';
                     if ((lp->color = matchlamp(cp1)) == NULL) {
                            cp1 = "unmatched alias";
                            goto fmterr;
                     }
              } else {                    /* or read specificaion */
                     if ((lp->color=(float *)malloc(6*sizeof(float)))==NULL)
                            goto memerr;
                     if (sscanf(cp1, "%f %f %f", &lp->color[3], &
                                   lp->color[4], &lp->color[5]) != 3) {
                            cp1 = "bad lamp data";
                            goto fmterr;
                     }
                                          /* convert xyY to XYZ */
                     xyz[1] = lp->color[5];
                     xyz[0] = lp->color[3]/lp->color[4] * xyz[1];
                     xyz[2] = xyz[1]*(1./lp->color[4] - 1.) - xyz[0];
                                          /* XYZ to RGB */
                     cie_rgb(lp->color, xyz);
              }
              if (lastp == NULL)
                     lamps = lp;
              else
                     lastp->next = lp;
              lp->next = NULL;
              lastp = lp;
       }
       fclose(fp);
       return(lastp != NULL);
memerr:
       fputs("Out of memory in loadlamps\n", stderr);
       return(-1);
fmterr:
       fputs(buf, stderr);
       fprintf(stderr, "%s: %s\n", file, cp1);
       return(-1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

float* matchlamp ( char *  s)

Definition at line 29 of file lamps.c.

{
       register LAMP *lp;

       for (lp = lamps; lp != NULL; lp = lp->next) {
              expset(lp->pattern);
              if (eindex(s) != NULL)
                     return(lp->color);
       }
       return(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* nextword ( char *  cp,
int  nb,
char *  s 
)

Definition at line 35 of file words.c.

{
       int    quote = 0;

       if (s == NULL) return(NULL);
       while (isspace(*s))
              s++;
       switch (*s) {
       case '\0':
              return(NULL);
       case '"':
       case '\'':
              quote = *s++;
       }
       while (--nb > 0 && *s && (quote ? *s!=quote : !isspace(*s)))
              *cp++ = *s++;
       *cp = '\0';
       if (quote && *s==quote)
              s++;
       return(s);
}

Here is the caller graph for this function:

void putflt ( double  f,
FILE *  fp 
)

Definition at line 47 of file portio.c.

{
       long  m;
       int  e;

       m = frexp(f, &e) * 0x7fffffff;
       if (e > 127) {                     /* overflow */
              m = m > 0 ? (long)0x7fffffff : -(long)0x7fffffff;
              e = 127;
       } else if (e < -128) {             /* underflow */
              m = 0;
              e = 0;
       }
       putint(m, 4, fp);
       putint((long)e, 1, fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void putint ( long  i,
int  siz,
FILE *  fp 
)

Definition at line 36 of file portio.c.

{
       while (siz--)
              putc((int)(i>>(siz<<3) & 0xff), fp);
}

Here is the caller graph for this function:

void putstr ( char *  s,
FILE *  fp 
)

Definition at line 25 of file portio.c.

{
       do
              putc(*s, fp);
       while (*s++);
}

Here is the caller graph for this function:

char* savestr ( char *  str)

Definition at line 51 of file savestr.c.

{
       register int  hval;
       register S_HEAD  *sp;

       if (str == NULL)
              return(NULL);
       hval = hash(str);
       for (sp = stab[hval]; sp != NULL; sp = sp->next)
              if (!strcmp(str, string(sp))) {
                     sp->nl++;
                     return(string(sp));
              }
       if ((sp = salloc(str)) == NULL) {
              eputs("Out of memory in savestr\n");
              quit(1);
       }
       strcpy(string(sp), str);
       sp->nl = 1;
       sp->next = stab[hval];
       stab[hval] = sp;
       return(string(sp));
}

Here is the caller graph for this function:

char* savqstr ( char *  s)

Definition at line 21 of file savqstr.c.

{
       register char  *cp;
       char  *newp;

       for (cp = s; *cp++; )                     /* compute strlen()+1 */
              ;
       newp = (char *)malloc(cp-s);
       if (newp == NULL) {
              eputs("out of memory in savqstr");
              quit(1);
       }
       for (cp = newp; (*cp++ = *s++); )         /* inline strcpy() */
              ;
       return(newp);                      /* return new location */
}

Here is the call graph for this function:

int setfdate ( char *  fname,
long  ftim 
)

Definition at line 35 of file fdate.c.

{
       struct utimbuf utb;

       utb.actime = utb.modtime = ftim;
       return(utime(fname, &utb));

#ifdef NOTHING /* XXX does this work anywhere? */
       time_t  ftm[2];

       ftm[0] = ftm[1] = ftim;
       return(utime(fname, ftm));
#endif
}

Here is the caller graph for this function:

int shash ( char *  s)
char* sskip ( char *  s)

Definition at line 62 of file words.c.

{
       while (isspace(*s))
              s++;
       while (*s && !isspace(*s))
              s++;
       return(s);
}

Here is the caller graph for this function:

char* sskip2 ( char *  s,
int  n 
)

Definition at line 74 of file words.c.

{
       while (isspace(*s))
              s++;
       while (n-- > 0) {
              while (*s && !isspace(*s))
                     s++;
              while (isspace(*s))
                     s++;
       }
       return(s);
}

Here is the caller graph for this function:

void swap16 ( char *  wp,
int  n 
)
void swap32 ( char *  wp,
int  n 
)
void swap64 ( char *  wp,
int  n 
)
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: