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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
17 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
18 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
19 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
20 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
21 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
22 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
23 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
24 |
};
|
|
|
25 |
static char last_sep[256];
|
|
|
26 |
|
|
|
27 |
char *
|
|
|
28 |
setfields(char *arg)
|
|
|
29 |
{
|
|
|
30 |
register unsigned char *s;
|
|
|
31 |
register i;
|
|
|
32 |
|
|
|
33 |
for(i = 1, s = (unsigned char *)last_sep; i < 256; i++)
|
|
|
34 |
if(is_sep[i])
|
|
|
35 |
*s++ = i;
|
|
|
36 |
*s = 0;
|
|
|
37 |
memset(is_sep, 0, sizeof is_sep);
|
|
|
38 |
memset(is_field, 1, sizeof is_field);
|
|
|
39 |
for(s = (unsigned char *)arg; *s;){
|
|
|
40 |
is_sep[*s] = 1;
|
|
|
41 |
is_field[*s++] = 0;
|
|
|
42 |
}
|
|
|
43 |
is_field[0] = 0;
|
|
|
44 |
return(last_sep);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
int
|
|
|
48 |
getfields(char *ss, char **sp, int nptrs)
|
|
|
49 |
{
|
|
|
50 |
register unsigned char *s = (unsigned char *)ss;
|
|
|
51 |
register unsigned char **p = (unsigned char **)sp;
|
|
|
52 |
register unsigned c;
|
|
|
53 |
|
|
|
54 |
c = 0;
|
|
|
55 |
for(;;){
|
|
|
56 |
if(--nptrs < 0) break;
|
|
|
57 |
*p++ = s;
|
|
|
58 |
while(is_field[c = *s++])
|
|
|
59 |
;
|
|
|
60 |
if(c == 0) break;
|
|
|
61 |
s[-1] = 0;
|
|
|
62 |
}
|
|
|
63 |
if(nptrs > 0)
|
|
|
64 |
*p = 0;
|
|
|
65 |
else if(--s >= (unsigned char *)ss)
|
|
|
66 |
*s = c;
|
|
|
67 |
return(p - (unsigned char **)sp);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
int
|
|
|
71 |
getmfields(char *ss, char **sp, int nptrs)
|
|
|
72 |
{
|
|
|
73 |
register unsigned char *s = (unsigned char *)ss;
|
|
|
74 |
register unsigned char **p = (unsigned char **)sp;
|
|
|
75 |
register unsigned c;
|
|
|
76 |
|
|
|
77 |
if(nptrs <= 0)
|
|
|
78 |
return(0);
|
|
|
79 |
goto flushdelim;
|
|
|
80 |
for(;;){
|
|
|
81 |
*p++ = s;
|
|
|
82 |
if(--nptrs == 0) break;
|
|
|
83 |
while(is_field[c = *s++])
|
|
|
84 |
;
|
|
|
85 |
/*
|
|
|
86 |
* s is now pointing 1 past the delimiter of the last field
|
|
|
87 |
* c is the delimiter
|
|
|
88 |
*/
|
|
|
89 |
if(c == 0) break;
|
|
|
90 |
s[-1] = 0;
|
|
|
91 |
flushdelim:
|
|
|
92 |
while(is_sep[c = *s++])
|
|
|
93 |
;
|
|
|
94 |
/*
|
|
|
95 |
* s is now pointing 1 past the beginning of the next field
|
|
|
96 |
* c is the first letter of the field
|
|
|
97 |
*/
|
|
|
98 |
if(c == 0) break;
|
|
|
99 |
s--;
|
|
|
100 |
/*
|
|
|
101 |
* s is now pointing to the beginning of the next field
|
|
|
102 |
* c is the first letter of the field
|
|
|
103 |
*/
|
|
|
104 |
}
|
|
|
105 |
if(nptrs > 0)
|
|
|
106 |
*p = 0;
|
|
|
107 |
return(p - (unsigned char **)sp);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
#ifdef MAIN
|
|
|
111 |
#include <fio.h>
|
|
|
112 |
|
|
|
113 |
main()
|
|
|
114 |
{
|
|
|
115 |
char *fields[256];
|
|
|
116 |
char *s;
|
|
|
117 |
int n, i;
|
|
|
118 |
char buf[1024];
|
|
|
119 |
|
|
|
120 |
print("go:\n");
|
|
|
121 |
while(s = Frdline(0)){
|
|
|
122 |
strcpy(buf, s);
|
|
|
123 |
Fprint(1, "getf:");
|
|
|
124 |
n = getfields(s, fields, 4);
|
|
|
125 |
for(i = 0; i < n; i++)
|
|
|
126 |
Fprint(1, " >%s<", fields[i]);
|
|
|
127 |
Fputc(1, '\n');
|
|
|
128 |
Fprint(1, "getmf:");
|
|
|
129 |
n = getmfields(buf, fields, 4);
|
|
|
130 |
for(i = 0; i < n; i++)
|
|
|
131 |
Fprint(1, " >%s<", fields[i]);
|
|
|
132 |
Fputc(1, '\n');
|
|
|
133 |
Fflush(1);
|
|
|
134 |
}
|
|
|
135 |
exit(0);
|
|
|
136 |
}
|
|
|
137 |
#endif
|