17 |
|
#include <sys/stat.h> |
18 |
|
#include <fcntl.h> |
19 |
|
|
20 |
< |
#ifdef _WIN32 |
21 |
< |
#include <io.h> |
22 |
< |
#endif |
23 |
< |
|
20 |
> |
#include "platform.h" |
21 |
|
#include "standard.h" |
22 |
|
|
23 |
|
|
24 |
< |
#define MAXFLEN 8192 /* file must be smaller than this */ |
24 |
> |
#ifndef MAXFLEN |
25 |
> |
#define MAXFLEN 204800 /* file must be smaller than this */ |
26 |
> |
#endif |
27 |
|
|
29 |
– |
extern char *bmalloc(); |
28 |
|
|
31 |
– |
|
29 |
|
int |
30 |
< |
wordfile(words, fname) /* get words from fname, put in words */ |
31 |
< |
char **words; |
32 |
< |
char *fname; |
30 |
> |
wordfile( /* get words from fname, put in words */ |
31 |
> |
char **words, |
32 |
> |
int nargs, |
33 |
> |
char *fname |
34 |
> |
) |
35 |
|
{ |
36 |
|
int fd; |
37 |
|
char buf[MAXFLEN]; |
38 |
< |
register int n; |
38 |
> |
int n; |
39 |
|
/* load file into buffer */ |
40 |
|
if (fname == NULL) |
41 |
|
return(-1); /* no filename */ |
49 |
|
while (!isspace(buf[--n])) |
50 |
|
if (n <= 0) /* one long word! */ |
51 |
|
return(-1); |
52 |
< |
buf[n] = '\0'; /* terminate */ |
53 |
< |
return(wordstring(words, buf)); /* wordstring does the rest */ |
52 |
> |
buf[n] = '\0'; /* terminate */ |
53 |
> |
return(wordstring(words, nargs, buf)); /* wordstring does the rest */ |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
int |
58 |
< |
wordstring(avl, str) /* allocate and load argument list */ |
59 |
< |
char **avl; |
60 |
< |
char *str; |
58 |
> |
wordstring( /* allocate and load argument list */ |
59 |
> |
char **avl, |
60 |
> |
int nargs, |
61 |
> |
char *str |
62 |
> |
) |
63 |
|
{ |
64 |
< |
register char *cp, **ap; |
64 |
> |
char *cp, **ap; |
65 |
|
|
66 |
|
if (str == NULL) |
67 |
|
return(-1); |
69 |
|
if (cp == NULL) /* ENOMEM */ |
70 |
|
return(-1); |
71 |
|
strcpy(cp, str); |
72 |
< |
ap = avl; /* parse into words */ |
73 |
< |
for ( ; ; ) { |
72 |
> |
/* parse into words */ |
73 |
> |
for (ap = avl; ap-avl < nargs-1; ap++) { |
74 |
|
while (isspace(*cp)) /* nullify spaces */ |
75 |
|
*cp++ = '\0'; |
76 |
|
if (!*cp) /* all done? */ |
77 |
|
break; |
78 |
< |
*ap++ = cp; /* add argument to list */ |
78 |
> |
*ap = cp; /* add argument to list */ |
79 |
|
while (*++cp && !isspace(*cp)) |
80 |
|
; |
81 |
|
} |