/* SGMLmain.c -- test driver for SGML io routines * $Id$ */ #include "SGMLstream.h" #include "HTMLentities.h" #include #include main() { int read; char buffer[72]; int content = SGML_PCDATA; int lookahead = EOF; char name[SGML_NAMELEN+1]; char name_chars; char value[SGML_LITLEN+1]; while((read = SGML_read((SGML_Object)stdin, (SGML_Method)getc, buffer, sizeof(buffer), (SGML_Object)HTML_entities, HTML_expand_entity, sizeof(char), content, &lookahead)) != EOF){ switch(read){ case SGML_end_tag: case SGML_start_tag: name_chars = SGML_read_name((SGML_Object)stdin, (SGML_Method)getc, name, &lookahead); name[name_chars] = '\0'; if(read == SGML_end_tag){ printf("\n", name); content = SGML_PCDATA; }else{ printf("<%s", name); /* * certain tags change parsing mode * @@ this should be table-driven */ if(!strcmp(name, "XMP") || !strcmp(name, "LISTING")){ content = SGML_RCDATA; } while(isalpha(lookahead)){ /* iterate over attributes */ name_chars = SGML_read_name((SGML_Object)stdin, (SGML_Method)getc, name, &lookahead); name[name_chars] = '\0'; if(lookahead == '='){ lookahead = EOF; read = SGML_read_value((SGML_Object)stdin, (SGML_Method)getc, value, (SGML_Object)HTML_entities, HTML_expand_entity, sizeof(char), &lookahead); value[read] = '\0'; printf(" %s=\"%s\"", name, value); /* @@ */ } } printf(">\n"); } /* look for tag close */ while(lookahead != EOF){ if(lookahead == '>') lookahead = EOF; /* eat tag close */ else /* error: illegal char in markup */ lookahead = getc(stdin); } break; default: printf("__start_data__\n"); fwrite(buffer, sizeof(char), read, stdout); /* @@ */ printf("__end_data__\n"); } } exit(0); }