16 for (i = 0; i + i < n; ++i) {
18 ta->t[i] = ta->t[n - i];
25GEN_ALLOC_append(token822_alloc,
struct token822,t,len,a,i,n,x,30,
token822_readyplus,
token822_append)
27static int needspace(
int t1,
int t2)
46static int atomok(
char ch)
49 case ' ':
case '\t':
case '\r':
case '\n':
50 case '(':
case '[':
case '"':
51 case '<':
case '>':
case ';':
case ':':
52 case '@':
case ',':
case '.':
58static void atomcheck(
struct token822 *t)
63 for (i = 0; i < t->
slen; ++i) {
65 if ((ch < 32) || (ch > 126) || (ch ==
')') || (ch ==
']') || (ch ==
'\\')) {
88 for (i = 0; i < ta->len; ++i) {
91 if (needspace(lasttype,newtype)) ++len;
103 switch (ch = t->
s[
j]) {
104 case '"':
case '[':
case ']':
case '(':
case ')':
105 case '\\':
case '\r':
case '\n': ++len;
113 if (!stralloc_ready(
sa,len))
return -1;
121 for (i = 0; i < ta->len; ++i) {
124 if (needspace(lasttype,newtype)) *
s++ =
' ';
131 s[0] = '\n'; s[1] = ' '; \
132 if (linee && (!linelen || (s - lineb <= linelen))) \
133 { while (linee < s) { linee[0] = linee[2]; ++linee; } linee -= 2; } \
134 else { if (linee) lineb = linee + 1; linee = s; s += 2; }
149 switch (ch = t->
s[
j]) {
150 case '"':
case '[':
case ']':
case '(':
case ')':
151 case '\\':
case '\r':
case '\n': *
s++ =
'\\';
176 for (i = 0; i < ta->len; ++i) {
189 if (!stralloc_ready(
sa,len))
return -1;
193 for (i = 0; i < ta->len; ++i) {
231 for (i = 0; i < salen; ++i)
233 case '.':
case ',':
case '@':
case '<':
case '>':
case ':':
case ';':
235 case ' ':
case '\t':
case '\r':
case '\n':
break;
236 case ')':
case ']':
return 0;
241 if (++i >= salen)
return 0;
243 case '(': ++level;
break;
244 case ')': --level;
break;
245 case '\\':
if (++i >= salen)
return 0;
254 if (++i >= salen)
return 0;
256 case '"': --level;
break;
257 case '\\':
if (++i >= salen)
return 0;
266 if (++i >= salen)
return 0;
268 case ']': --level;
break;
269 case '\\':
if (++i >= salen)
return 0;
277 if (
sa->s[i] ==
'\\')
if (++i >= salen)
break;
279 if (++i >= salen)
break;
280 }
while (atomok(
sa->s[i]));
286 if (!stralloc_ready(
buf,numchars))
return -1;
292 for (i = 0; i < salen; ++i)
301 case ' ':
case '\t':
case '\r':
case '\n':
break;
308 case '(': ++level;
break;
309 case ')': --level;
break;
322 case '"': --level;
break;
335 case ']': --level;
break;
345 if (
sa->s[i] ==
'\\')
if (++i >= salen)
break;
347 if (++i >= salen)
break;
348 }
while (atomok(
sa->s[i]));
356static int gotaddr(token822_alloc *taout,token822_alloc *taaddr,
int (*callback)())
360 if (callback(taaddr) != 1)
366 for (i = 0; i < taaddr->len; ++i)
367 taout->t[taout->len++] = taaddr->t[i];
373int token822_addrlist(token822_alloc *taout,token822_alloc *taaddr,token822_alloc *ta,
int (*callback)())
389 beginning = ta->t + 2;
390 t = ta->t + ta->len - 1;
394#define FLUSH if (taaddr->len) if (!gotaddr(taout,taaddr,callback)) return -1;
395#define FLUSHCOMMA if (taaddr->len) { \
396if (!gotaddr(taout,taaddr,callback)) return -1; \
397if (!token822_append(taout,&comma)) return -1; }
398#define ADDRLEFT if (!token822_append(taaddr,t--)) return -1;
399#define OUTLEFT if (!token822_append(taout,t--)) return -1;
401 while (t >= beginning) {
405 if (ingroup)
return 0;
411 if (!ingroup)
return 0;
425 if (!
gotaddr(taout,taaddr,callback))
return -1;
426 if (t < beginning)
return 0;
GEN_ALLOC_readyplus(prioq, struct prioq_elt, p, len, a, i, n, x, 100, prioq_readyplus)
GEN_ALLOC_ready(GEN_ALLOC_readyplus(token822_alloc, GEN_ALLOC_readyplus(struct token822, GEN_ALLOC_readyplus(t, GEN_ALLOC_readyplus(len, GEN_ALLOC_readyplus(a, GEN_ALLOC_readyplus(i, GEN_ALLOC_readyplus(n, GEN_ALLOC_readyplus(x, GEN_ALLOC_readyplus(30, token822_ready)
int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf)