version 1.16, 2010/09/29 21:31:24
|
version 1.17, 2010/09/29 21:33:03
|
Line 210 const static unsigned char possible_desc
|
Line 210 const static unsigned char possible_desc
|
#define LOOP_DEPTH 4 |
#define LOOP_DEPTH 4 |
#define REALLOC_CHUNK 32 |
#define REALLOC_CHUNK 32 |
|
|
|
static struct { |
|
int tablen; |
|
int itab; |
|
int fd; |
|
int isdescr; /* 0: main table, >0: descr loop depth */ |
|
int descrtag; |
|
int isyn; |
|
int isyntab; |
|
int numcount; |
|
int loopbegin[LOOP_DEPTH]; |
|
int loopcount[LOOP_DEPTH]; |
|
int ibuf; |
|
char buf[2048]; |
|
} tabnew; |
|
|
struct sitab { |
struct sitab { |
struct sitab *next; |
struct sitab *next; |
char typ; |
char typ; |
Line 220 struct sitab {
|
Line 235 struct sitab {
|
enum enumsi esi; |
enum enumsi esi; |
unsigned long *tab; |
unsigned long *tab; |
struct timeval soon; |
struct timeval soon; |
union { |
|
struct { |
|
int tablen; |
|
int itab; |
|
int fd; |
|
int isdescr; /* 0: main table, >0: descr loop depth */ |
|
int descrtag; |
|
int isyn; |
|
int isyntab; |
|
int numcount; |
|
int loopbegin[LOOP_DEPTH]; |
|
int loopcount[LOOP_DEPTH]; |
|
int ibuf; |
|
char buf[256]; |
|
} a; |
|
} u; |
|
unsigned char descrnum[DESCR_LAST-DESCR_FIRST+1]; |
unsigned char descrnum[DESCR_LAST-DESCR_FIRST+1]; |
}; |
}; |
|
|
Line 1606 static void maketab(char typ, long pid,
|
Line 1605 static void maketab(char typ, long pid,
|
t->esi = e; |
t->esi = e; |
t->tab = NULL; |
t->tab = NULL; |
memset(&t->descrnum[0], 0, sizeof(t->descrnum[0])); |
memset(&t->descrnum[0], 0, sizeof(t->descrnum[0])); |
memset(&t->u, 0, sizeof(t->u)); |
memset(&tabnew, 0, sizeof(tabnew)); |
t->u.a.fd = fd; |
tabnew.fd = fd; |
newtab = t; |
newtab = t; |
} |
} |
} |
} |
Line 1668 static int tabline(char *b, int n)
|
Line 1667 static int tabline(char *b, int n)
|
|
|
static int taballoc(struct sitab *st, int cnt) |
static int taballoc(struct sitab *st, int cnt) |
{ |
{ |
while (st->u.a.tablen < (st->u.a.itab + cnt)) { |
while (tabnew.tablen < (tabnew.itab + cnt)) { |
st->u.a.tablen += REALLOC_CHUNK; |
tabnew.tablen += REALLOC_CHUNK; |
st->tab = realloc(st->tab, st->u.a.tablen * sizeof(unsigned long)); |
st->tab = realloc(st->tab, tabnew.tablen * sizeof(unsigned long)); |
if (st->tab == NULL) { |
if (st->tab == NULL) { |
return -ENOMEM; |
return -ENOMEM; |
} |
} |
Line 1699 static int siline(struct sitab *st, char
|
Line 1698 static int siline(struct sitab *st, char
|
char *e, *a, *z; |
char *e, *a, *z; |
long v; |
long v; |
int s, i; |
int s, i; |
s = syntax[(st->u.a.isdescr > 0) ? 1 : 0] |
s = syntax[(tabnew.isdescr > 0) ? 1 : 0] |
[(st->u.a.isdescr > 0) ? st->u.a.descrtag : st->esi][st->u.a.isyn]; |
[(tabnew.isdescr > 0) ? tabnew.descrtag : st->esi][tabnew.isyn]; |
if ((s == SYNTAX_END) || (s == SYNTAX_LOOPEND)) { |
if ((s == SYNTAX_END) || (s == SYNTAX_LOOPEND)) { |
int lc; |
int lc; |
#ifdef DEBUG |
#ifdef DEBUG |
fprintf(stderr, "end:\n"); |
fprintf(stderr, "end:\n"); |
#endif |
#endif |
if ((lc = --st->u.a.loopcount[0]) <= 0) { |
if ((lc = --tabnew.loopcount[0]) <= 0) { |
if (lc == 0) { |
if (lc == 0) { |
for (i = 0; i < LOOP_DEPTH-1; i++) { |
for (i = 0; i < LOOP_DEPTH-1; i++) { |
st->u.a.loopbegin[i] = st->u.a.loopbegin[i+1]; |
tabnew.loopbegin[i] = tabnew.loopbegin[i+1]; |
st->u.a.loopcount[i] = st->u.a.loopcount[i+1]; |
tabnew.loopcount[i] = tabnew.loopcount[i+1]; |
} |
} |
st->u.a.loopcount[LOOP_DEPTH-1] = 0; |
tabnew.loopcount[LOOP_DEPTH-1] = 0; |
if (s == SYNTAX_LOOPEND) { |
if (s == SYNTAX_LOOPEND) { |
st->u.a.isyn += 1; |
tabnew.isyn += 1; |
} else if (st->u.a.isdescr > 0) { |
} else if (tabnew.isdescr > 0) { |
if (--st->u.a.isdescr == 0) { |
if (--tabnew.isdescr == 0) { |
st->u.a.isyn = st->u.a.isyntab; |
tabnew.isyn = tabnew.isyntab; |
} |
} |
} |
} |
return 0; |
return 0; |
} else { |
} else { |
st->u.a.tablen = st->u.a.itab; |
tabnew.tablen = tabnew.itab; |
st->tab = realloc(st->tab, st->u.a.itab * sizeof(unsigned long)); |
st->tab = realloc(st->tab, tabnew.itab * sizeof(unsigned long)); |
return -ENOBUFS; |
return -ENOBUFS; |
} |
} |
} else { |
} else { |
st->u.a.isyn = st->u.a.loopbegin[0]; |
tabnew.isyn = tabnew.loopbegin[0]; |
return 0; |
return 0; |
} |
} |
} |
} |
Line 1749 static int siline(struct sitab *st, char
|
Line 1748 static int siline(struct sitab *st, char
|
fprintf(stderr, "internal syntax error\n"); |
fprintf(stderr, "internal syntax error\n"); |
exit(1); |
exit(1); |
} |
} |
if (st->u.a.numcount == 0) { |
if (tabnew.numcount == 0) { |
st->u.a.numcount = s; |
tabnew.numcount = s; |
} |
} |
v = strtoul(a, &z, 0); |
v = strtoul(a, &z, 0); |
if (a == z) { |
if (a == z) { |
Line 1759 static int siline(struct sitab *st, char
|
Line 1758 static int siline(struct sitab *st, char
|
#ifdef DEBUG |
#ifdef DEBUG |
fprintf(stderr, "number: %ld, %d..%d\n", v, a-b, z-b); |
fprintf(stderr, "number: %ld, %d..%d\n", v, a-b, z-b); |
#endif |
#endif |
st->tab[st->u.a.itab++] = v; |
st->tab[tabnew.itab++] = v; |
if (++st->u.a.numcount == 0) { |
if (++tabnew.numcount == 0) { |
st->u.a.isyn += 1; |
tabnew.isyn += 1; |
} |
} |
*e = '\n'; |
*e = '\n'; |
return z-b; |
return z-b; |
Line 1773 static int siline(struct sitab *st, char
|
Line 1772 static int siline(struct sitab *st, char
|
#ifdef DEBUG |
#ifdef DEBUG |
fprintf(stderr, "loop: %ld, %d..%d\n", v, a-b, z-b); |
fprintf(stderr, "loop: %ld, %d..%d\n", v, a-b, z-b); |
#endif |
#endif |
st->tab[st->u.a.itab++] = v; |
st->tab[tabnew.itab++] = v; |
if (v != 0) { |
if (v != 0) { |
if (st->u.a.isdescr > 0) { |
if (tabnew.isdescr > 0) { |
st->u.a.isdescr += 1; |
tabnew.isdescr += 1; |
} |
} |
for (i = LOOP_DEPTH-2; i >= 0; i--) { |
for (i = LOOP_DEPTH-2; i >= 0; i--) { |
st->u.a.loopbegin[i+1] = st->u.a.loopbegin[i]; |
tabnew.loopbegin[i+1] = tabnew.loopbegin[i]; |
st->u.a.loopcount[i+1] = st->u.a.loopcount[i]; |
tabnew.loopcount[i+1] = tabnew.loopcount[i]; |
} |
} |
st->u.a.loopbegin[0] = ++st->u.a.isyn; |
tabnew.loopbegin[0] = ++tabnew.isyn; |
st->u.a.loopcount[0] = v; |
tabnew.loopcount[0] = v; |
} else { |
} else { |
do { |
do { |
st->u.a.isyn += 1; |
tabnew.isyn += 1; |
s = syntax[(st->u.a.isdescr > 0) ? 1 : 0] |
s = syntax[(tabnew.isdescr > 0) ? 1 : 0] |
[(st->u.a.isdescr > 0) ? st->u.a.descrtag : st->esi] |
[(tabnew.isdescr > 0) ? tabnew.descrtag : st->esi] |
[st->u.a.isyn]; |
[tabnew.isyn]; |
if (s == SYNTAX_LOOP) { |
if (s == SYNTAX_LOOP) { |
v += 1; |
v += 1; |
} |
} |
} while ((s != SYNTAX_END) && ((s != SYNTAX_LOOPEND) || (--v >= 0))); |
} while ((s != SYNTAX_END) && ((s != SYNTAX_LOOPEND) || (--v >= 0))); |
if (s == SYNTAX_LOOPEND) { |
if (s == SYNTAX_LOOPEND) { |
st->u.a.isyn += 1; |
tabnew.isyn += 1; |
} |
} |
} |
} |
*e = '\n'; |
*e = '\n'; |
Line 1808 static int siline(struct sitab *st, char
|
Line 1807 static int siline(struct sitab *st, char
|
#ifdef DEBUG |
#ifdef DEBUG |
fprintf(stderr, "descr: %ld, %d..%d\n", v, a-b, z-b); |
fprintf(stderr, "descr: %ld, %d..%d\n", v, a-b, z-b); |
#endif |
#endif |
st->tab[st->u.a.itab++] = v; |
st->tab[tabnew.itab++] = v; |
st->u.a.isyn += 1; |
tabnew.isyn += 1; |
if (v != 0) { |
if (v != 0) { |
st->u.a.isdescr = 1; |
tabnew.isdescr = 1; |
st->u.a.descrtag = 0; |
tabnew.descrtag = 0; |
for (i = LOOP_DEPTH-2; i >= 0; i--) { |
for (i = LOOP_DEPTH-2; i >= 0; i--) { |
st->u.a.loopbegin[i+1] = st->u.a.loopbegin[i]; |
tabnew.loopbegin[i+1] = tabnew.loopbegin[i]; |
st->u.a.loopcount[i+1] = st->u.a.loopcount[i]; |
tabnew.loopcount[i+1] = tabnew.loopcount[i]; |
} |
} |
st->u.a.loopbegin[0] = 0; |
tabnew.loopbegin[0] = 0; |
st->u.a.loopcount[0] = v; |
tabnew.loopcount[0] = v; |
st->u.a.isyntab = st->u.a.isyn; |
tabnew.isyntab = tabnew.isyn; |
st->u.a.isyn = 0; |
tabnew.isyn = 0; |
} |
} |
*e = '\n'; |
*e = '\n'; |
return z-b; |
return z-b; |
Line 1832 static int siline(struct sitab *st, char
|
Line 1831 static int siline(struct sitab *st, char
|
#ifdef DEBUG |
#ifdef DEBUG |
fprintf(stderr, "descrtag: %ld, %d..%d\n", v, a-b, z-b); |
fprintf(stderr, "descrtag: %ld, %d..%d\n", v, a-b, z-b); |
#endif |
#endif |
st->tab[st->u.a.itab++] = v; |
st->tab[tabnew.itab++] = v; |
v -= DESCR_FIRST; |
v -= DESCR_FIRST; |
if ((v < 0) || (v > (DESCR_LAST - DESCR_FIRST))) { |
if ((v < 0) || (v > (DESCR_LAST - DESCR_FIRST))) { |
return -EINVAL; |
return -EINVAL; |
Line 1841 static int siline(struct sitab *st, char
|
Line 1840 static int siline(struct sitab *st, char
|
if (!((1 << st->esi) & possible_descr[v])) { |
if (!((1 << st->esi) & possible_descr[v])) { |
return -EINVAL; |
return -EINVAL; |
} |
} |
st->u.a.descrtag = v; |
tabnew.descrtag = v; |
st->u.a.isyn += 1; |
tabnew.isyn += 1; |
*e = '\n'; |
*e = '\n'; |
return z-b; |
return z-b; |
case SYNTAX_DATETIME: |
case SYNTAX_DATETIME: |
Line 1881 static int siline(struct sitab *st, char
|
Line 1880 static int siline(struct sitab *st, char
|
return -EINVAL; |
return -EINVAL; |
} |
} |
v += s - 678912; |
v += s - 678912; |
st->tab[st->u.a.itab++] = v; |
st->tab[tabnew.itab++] = v; |
v = 0; |
v = 0; |
s = ' '; |
s = ' '; |
for (i = 2; i >= 0; i--) { |
for (i = 2; i >= 0; i--) { |
Line 1900 static int siline(struct sitab *st, char
|
Line 1899 static int siline(struct sitab *st, char
|
v = (v<<4) + (s-'0'); |
v = (v<<4) + (s-'0'); |
s = ':'; |
s = ':'; |
} |
} |
st->tab[st->u.a.itab++] = v; |
st->tab[tabnew.itab++] = v; |
#ifdef DEBUG |
#ifdef DEBUG |
fprintf(stderr, "datetime: %04lx %06lx, %d..%d\n", |
fprintf(stderr, "datetime: %04lx %06lx, %d..%d\n", |
st->tab[st->u.a.itab-2], v, a-b, z-b); |
st->tab[tabnew.itab-2], v, a-b, z-b); |
#endif |
#endif |
st->u.a.isyn += 1; |
tabnew.isyn += 1; |
*e = '\n'; |
*e = '\n'; |
return z-b; |
return z-b; |
case SYNTAX_STRING: |
case SYNTAX_STRING: |
Line 1920 static int siline(struct sitab *st, char
|
Line 1919 static int siline(struct sitab *st, char
|
i = v; |
i = v; |
v += z-a; |
v += z-a; |
taballoc(st, 1 + (v + sizeof(long) - 1) / sizeof(long)); |
taballoc(st, 1 + (v + sizeof(long) - 1) / sizeof(long)); |
memcpy(((char *)&st->tab[st->u.a.itab+1]) + i, a, z-a); |
memcpy(((char *)&st->tab[tabnew.itab+1]) + i, a, z-a); |
z += 1; |
z += 1; |
while (*z == '"') { |
while (*z == '"') { |
a = z; |
a = z; |
Line 1931 static int siline(struct sitab *st, char
|
Line 1930 static int siline(struct sitab *st, char
|
i = v; |
i = v; |
v += z-a; |
v += z-a; |
taballoc(st, 1 + (v + sizeof(long) - 1) / sizeof(long)); |
taballoc(st, 1 + (v + sizeof(long) - 1) / sizeof(long)); |
memcpy(((char *)&st->tab[st->u.a.itab+1]) + i, a, z-a); |
memcpy(((char *)&st->tab[tabnew.itab+1]) + i, a, z-a); |
z += 1; |
z += 1; |
} |
} |
st->tab[st->u.a.itab] = v; |
st->tab[tabnew.itab] = v; |
#ifdef DEBUG |
#ifdef DEBUG |
fprintf(stderr, "string: %ld, %d..%d\n", v, a-b, z-b); |
fprintf(stderr, "string: %ld, %d..%d\n", v, a-b, z-b); |
#endif |
#endif |
st->u.a.itab += 1 + (v + sizeof(long) - 1) / sizeof(long); |
tabnew.itab += 1 + (v + sizeof(long) - 1) / sizeof(long); |
st->u.a.isyn += 1; |
tabnew.isyn += 1; |
*e = '\n'; |
*e = '\n'; |
return z-b; |
return z-b; |
} |
} |
Line 2018 static void argloop(int f0)
|
Line 2017 static void argloop(int f0)
|
n0 = -1; |
n0 = -1; |
nst = -1; |
nst = -1; |
if (newtab != NULL) { |
if (newtab != NULL) { |
nst = pollfd_add(newtab->u.a.fd, POLLIN); |
nst = pollfd_add(tabnew.fd, POLLIN); |
} else if ((r = tabline(&buf0[o0], i0))) { |
} else if ((r = tabline(&buf0[o0], i0))) { |
o0 += r; |
o0 += r; |
i0 -= r; |
i0 -= r; |
Line 2171 static void argloop(int f0)
|
Line 2170 static void argloop(int f0)
|
if ((n > 0) && (nst >= 0) && (r = pollfd_rev(nst))) { |
if ((n > 0) && (nst >= 0) && (r = pollfd_rev(nst))) { |
if (r & (POLLNVAL | POLLERR)) { |
if (r & (POLLNVAL | POLLERR)) { |
fprintf(stderr, "poll error: %x\n", r); |
fprintf(stderr, "poll error: %x\n", r); |
close(newtab->u.a.fd); |
close(tabnew.fd); |
free(newtab->tab); |
free(newtab->tab); |
free(newtab); |
free(newtab); |
newtab = NULL; |
newtab = NULL; |
} else { |
} else { |
i = newtab->u.a.ibuf; |
i = tabnew.ibuf; |
r = read(newtab->u.a.fd, &newtab->u.a.buf[i], sizeof(newtab->u.a.buf) - i - 1); |
r = read(tabnew.fd, &tabnew.buf[i], sizeof(tabnew.buf) - i - 1); |
if (r <= 0) { |
if (r <= 0) { |
fprintf(stderr, "read error(%d): %d\n", errno, newtab->u.a.fd); |
fprintf(stderr, "read error(%d): %d\n", errno, tabnew.fd); |
close(newtab->u.a.fd); |
close(tabnew.fd); |
free(newtab->tab); |
free(newtab->tab); |
free(newtab); |
free(newtab); |
newtab = NULL; |
newtab = NULL; |
} else { |
} else { |
int j = 0; |
int j = 0; |
i += r; |
i += r; |
while ((r = siline(newtab, &newtab->u.a.buf[j], i)) >= 0) { |
while ((r = siline(newtab, &tabnew.buf[j], i)) >= 0) { |
j += r; |
j += r; |
i -= r; |
i -= r; |
} |
} |
switch (r) { |
switch (r) { |
case -ENOBUFS: |
case -ENOBUFS: |
close(newtab->u.a.fd); |
close(tabnew.fd); |
#ifdef DEBUG |
#ifdef DEBUG |
fprintf(stderr, "done, itab=%d\n", newtab->u.a.itab); |
fprintf(stderr, "done, itab=%d\n", tabnew.itab); |
for (i = 0; i < newtab->u.a.itab; i++) { |
for (i = 0; i < tabnew.itab; i++) { |
fprintf(stderr, "%lu,", newtab->tab[i]); |
fprintf(stderr, "%lu,", newtab->tab[i]); |
} |
} |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
Line 2218 static void argloop(int f0)
|
Line 2217 static void argloop(int f0)
|
break; |
break; |
case -EAGAIN: |
case -EAGAIN: |
if (i > 0) { |
if (i > 0) { |
memmove(&newtab->u.a.buf[0], &newtab->u.a.buf[j], i); |
memmove(&tabnew.buf[0], &tabnew.buf[j], i); |
} |
} |
newtab->u.a.ibuf = i; |
tabnew.ibuf = i; |
break; |
break; |
default: |
default: |
fprintf(stderr, "eval error: %d\n", r); |
fprintf(stderr, "eval error: %d\n", r); |
close(newtab->u.a.fd); |
close(tabnew.fd); |
free(newtab->tab); |
free(newtab->tab); |
free(newtab); |
free(newtab); |
newtab = NULL; |
newtab = NULL; |