30 #define EAT_SPACE(ptr) while( ptr && *ptr && isspace((int)*ptr) ) ptr++
31 #define EAT_WORD(ptr) while( ptr && *ptr && !isspace((int)*ptr) && ('>' != *ptr)) ptr++
34 #define show(x) printf x
40 char *appendstring(
char *
string,
45 size_t len = strlen(buffer);
46 size_t needed_len = len + *stringlen;
48 if(needed_len >= *stralloc) {
50 size_t newsize = needed_len*2;
52 newptr = realloc(
string, newsize);
60 strcpy(&
string[*stringlen], buffer);
68 const char *sub,
int *
size)
86 } state = STATE_OUTSIDE;
88 string = (
char *)malloc(stralloc);
94 while(fgets(buffer,
sizeof(buffer), stream)) {
103 show((
"=> %s", buffer));
104 string = appendstring(
string, buffer, &stringlen, &stralloc);
105 show((
"* %s\n", buffer));
122 if((state == STATE_INSUB) &&
129 else if((state == STATE_INMAIN) &&
146 state = STATE_INMAIN;
157 string = appendstring(
string, buffer, &stringlen, &stralloc);
158 show((
"* %s\n", buffer));
161 if((STATE_INSUB == state) &&
164 show((
"* (%d bytes) %s\n", stringlen, buffer));
168 show((
"%d (%s/%s): %s\n", state, cmain, csub, buffer));
178 int main(
int argc,
char **argv)
181 printf(
"./moo main sub\n");
GLenum GLsizei const GLvoid * string
const char * spitout(FILE *stream, const char *main, const char *sub, int *size)