#include #include "frame.h" #define CUR f->pinfo->dtdcur->cur #define MACHED f->pinfo->dtdcur->mached #define ALLMACHED f->pinfo->dtdcur->allmached #define CHILDMACHED f->pinfo->dtdcur->childmached #define AFTERPOP f->pinfo->dtdcur->afterpop static void frame_push_dtd_cur(Frame *f, DTDObj *obj) { DTDCur *cur = dtdcur_new(); cur->cur = obj; /* push */ cur->next = f->pinfo->dtdcur; f->pinfo->dtdcur = cur; } static void frame_pop_dtd_cur(Frame *f) { int mached = ALLMACHED; DTDCur *cur = f->pinfo->dtdcur; /* pop */ f->pinfo->dtdcur = cur->next; dtdcur_delete(cur); CHILDMACHED = mached; } int frame_check_dtd(Frame *f, TagInfo *ti, TagInfo **ommit) { TagInfo *dtd_ti; #if 0 fprintf(stderr, "dtd:[%s] tag:[%s]\n", f->pinfo->taginfo->name, ti->name); dtdobjlist_show(f->pinfo->taginfo->dtd); #endif start: if (f->pinfo->dtdcur == NULL) { /* fprintf(stderr, "dtd: [%s] parse end\n", f->pinfo->taginfo->name);*/ return -2; /* ¥Ñ¡¼¥¹´°Î» */ } if (CUR == NULL) { /* ³ç¸ÌÊĤ¸ */ /* fprintf(stderr, "dtd: [%s] close brace\n", f->pinfo->taginfo->name);*/ frame_pop_dtd_cur(f); goto start; } if (MACHED && (CUR->repeat == DTD_REPEAT_1 || CUR->repeat == DTD_REPEAT_0or1)) { /* fprintf(stderr, "dtd: mach 1 and next\n");*/ MACHED = 0; CUR = CUR->end; goto start; } if (CUR->type == DTD_NORMAL) { dtd_ti = (TagInfo*)CUR->data; #if 0 fprintf(stderr, "dtd: normal dtd[%s][%d]\n", dtd_ti->name, CUR->repeat); #endif if (ti->id == dtd_ti->id) { /* match */ /* fprintf(stderr, "dtd: mach\n");*/ ALLMACHED = MACHED = 1; return 0; /* match */ } else { /* no match */ if (MACHED) { /* fprintf(stderr, "dtd: mach and next\n");*/ /* already matched */ MACHED = 0; CUR = CUR->end; goto start; } else if (CUR->next != CUR->end || CUR->repeat == DTD_REPEAT_0or1 || CUR->repeat == DTD_REPEAT_over0 ) { /* fprintf(stderr, "dtd: no mach and next\n");*/ MACHED = 0; CUR = CUR->next; /* for or */ goto start; } else if (dtd_ti->ommit & 01) { /* fprintf(stderr, "dtd: ommited\n");*/ ALLMACHED = MACHED = 1; *ommit = dtd_ti; return 1; /* ommited tag */ } else { /* fprintf(stderr, "dtd: no match\n");*/ MACHED = 0; CUR = CUR->end; *ommit = dtd_ti; /* tag that may match */ return -1; /* no match!! error */ } } } else { /* ³ç¸Ì */ if (!AFTERPOP) { /* fprintf(stderr, "dtd: open brace\n");*/ frame_push_dtd_cur(f, (DTDObj*)CUR->data); goto start; } else { AFTERPOP = 0; if (CHILDMACHED) { MACHED = ALLMACHED = 1; goto start; } else { if (MACHED) { /* already matched */ MACHED = 0; CUR = CUR->end; goto start; } else if (CUR->repeat == DTD_REPEAT_0or1 || CUR->repeat == DTD_REPEAT_over0 ) { MACHED = 0; CUR = CUR->next; /* for or */ goto start; } else { MACHED = 0; return -1; /* no match!! error */ } } } } }