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;
105 switch (ch = t->
s[
j]) {
106 case '"':
case '[':
case ']':
case '(':
case ')':
107 case '\\':
case '\r':
case '\n': ++len;
115 if (!stralloc_ready(
sa,len))
return -1;
123 for (i = 0; i < ta->len; ++i) {
126 if (needspace(lasttype,newtype)) *
s++ =
' ';
133 s[0] = '\n'; s[1] = ' '; \
134 if (linee && (!linelen || (s - lineb <= linelen))) \
135 { while (linee < s) { linee[0] = linee[2]; ++linee; } linee -= 2; } \
136 else { if (linee) lineb = linee + 1; linee = s; s += 2; }
151 switch (ch = t->
s[
j]) {
152 case '"':
case '[':
case ']':
case '(':
case ')':
153 case '\\':
case '\r':
case '\n': *
s++ =
'\\';
178 for (i = 0; i < ta->len; ++i) {
193 if (!stralloc_ready(
sa,len))
return -1;
197 for (i = 0; i < ta->len; ++i) {
235 for (i = 0; i < salen; ++i)
237 case '.':
case ',':
case '@':
238 case '<':
case '>':
case ':':
case ';':
240 case ' ':
case '\t':
case '\r':
case '\n':
break;
241 case ')':
case ']':
return 0;
246 if (++i >= salen)
return 0;
248 case '(': ++level;
break;
249 case ')': --level;
break;
250 case '\\':
if (++i >= salen)
return 0;
259 if (++i >= salen)
return 0;
261 case '"': --level;
break;
262 case '\\':
if (++i >= salen)
return 0;
271 if (++i >= salen)
return 0;
273 case ']': --level;
break;
274 case '\\':
if (++i >= salen)
return 0;
282 if (
sa->s[i] ==
'\\')
if (++i >= salen)
break;
284 if (++i >= salen)
break;
285 }
while (atomok(
sa->s[i]));
291 if (!stralloc_ready(
buf,numchars))
return -1;
297 for (i = 0; i < salen; ++i)
306 case ' ':
case '\t':
case '\r':
case '\n':
break;
313 case '(': ++level;
break;
314 case ')': --level;
break;
327 case '"': --level;
break;
340 case ']': --level;
break;
350 if (
sa->s[i] ==
'\\')
if (++i >= salen)
break;
352 if (++i >= salen)
break;
353 }
while (atomok(
sa->s[i]));
361static int gotaddr(token822_alloc *taout,token822_alloc *taaddr,
int (*callback)())
365 if (callback(taaddr) != 1)
371 for (i = 0; i < taaddr->len; ++i)
372 taout->t[taout->len++] = taaddr->t[i];
378int token822_addrlist(token822_alloc *taout,token822_alloc *taaddr,token822_alloc *ta,
int (*callback)())
394 beginning = ta->t + 2;
395 t = ta->t + ta->len - 1;
399#define FLUSH if (taaddr->len) if (!gotaddr(taout,taaddr,callback)) return -1;
400#define FLUSHCOMMA if (taaddr->len) { \
401if (!gotaddr(taout,taaddr,callback)) return -1; \
402if (!token822_append(taout,&comma)) return -1; }
403#define ADDRLEFT if (!token822_append(taaddr,t--)) return -1;
404#define OUTLEFT if (!token822_append(taout,t--)) return -1;
406 while (t >= beginning) {
410 if (ingroup)
return 0;
416 if (!ingroup)
return 0;
430 if (!gotaddr(taout,taaddr,callback))
return -1;
431 if (t < beginning)
return 0;
GEN_ALLOC_readyplus(prioq, struct prioq_elt, p, len, a, i, n, x, 100, prioq_readyplus)
int token822_unparse(stralloc *sa, token822_alloc *ta, unsigned int linelen)
int token822_addrlist(token822_alloc *taout, token822_alloc *taaddr, token822_alloc *ta, int(*callback)())
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_unquote(stralloc *sa, token822_alloc *ta)
void token822_reverse(token822_alloc *ta)
int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf)
int token822_append(token822_alloc *, struct token822 *)
int token822_ready(token822_alloc *, unsigned int)
int token822_readyplus(token822_alloc *, unsigned int)