1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Load whitespace separated words from a file into an array. |
6 |
|
* Assume the passed pointer array is big enough to hold them all. |
7 |
+ |
* |
8 |
+ |
* External symbols declared in standard.h |
9 |
|
*/ |
10 |
|
|
11 |
+ |
#include "copyright.h" |
12 |
+ |
|
13 |
|
#include <ctype.h> |
14 |
+ |
#include <string.h> |
15 |
+ |
#include <stdio.h> |
16 |
+ |
#include <sys/types.h> |
17 |
+ |
#include <sys/stat.h> |
18 |
+ |
#include <fcntl.h> |
19 |
|
|
20 |
< |
#define NULL 0 |
20 |
> |
#include "platform.h" |
21 |
> |
#include "standard.h" |
22 |
|
|
16 |
– |
#define MAXFLEN 8192 /* file must be smaller than this */ |
23 |
|
|
24 |
< |
extern char *bmalloc(); |
24 |
> |
#ifndef MAXFLEN |
25 |
> |
#define MAXFLEN 16384 /* file must be smaller than this */ |
26 |
> |
#endif |
27 |
|
|
28 |
|
|
29 |
|
int |
35 |
|
char buf[MAXFLEN]; |
36 |
|
register int n; |
37 |
|
/* load file into buffer */ |
38 |
+ |
if (fname == NULL) |
39 |
+ |
return(-1); /* no filename */ |
40 |
|
if ((fd = open(fname, 0)) < 0) |
41 |
|
return(-1); /* open error */ |
42 |
|
n = read(fd, buf, MAXFLEN); |
65 |
|
if (cp == NULL) /* ENOMEM */ |
66 |
|
return(-1); |
67 |
|
strcpy(cp, str); |
68 |
< |
for (ap = avl; *cp; *cp++ = '\0') { |
69 |
< |
while (isspace(*cp)) /* skip leading space */ |
70 |
< |
cp++; |
71 |
< |
if (*cp) { /* add argument to list */ |
72 |
< |
*ap++ = cp; |
73 |
< |
while (*cp && !isspace(*cp)) |
74 |
< |
cp++; |
75 |
< |
} |
68 |
> |
ap = avl; /* parse into words */ |
69 |
> |
for ( ; ; ) { |
70 |
> |
while (isspace(*cp)) /* nullify spaces */ |
71 |
> |
*cp++ = '\0'; |
72 |
> |
if (!*cp) /* all done? */ |
73 |
> |
break; |
74 |
> |
*ap++ = cp; /* add argument to list */ |
75 |
> |
while (*++cp && !isspace(*cp)) |
76 |
> |
; |
77 |
|
} |
78 |
|
*ap = NULL; |
79 |
|
return(ap - avl); |