/* **------------------------------------- ** <$LET> set a new global attribute ** or overwrite a defined one **------------------------------------- */ BOOL handle_hsc_let( INFILE *inpf, HSCTAG *tag ) { STRPTR varname = infgetw( inpf ); BOOL ok = FALSE; /* create copy of varname */ if ( varname ) varname = strclone( varname ); else err_eof( inpf, "missing attribute name" ); if ( varname ) { ok = parse_wd( inpf, ":" ); if ( ok && define_var( varname, vars, inpf, 0 ) ) ok = TRUE; if ( ok ) ok = parse_gt( inpf ); } else err_mem( inpf ); /* release mem */ ufreestr( varname ); /* if error occured, skip rest of tag */ if ( !ok ) skip_until_eot( inpf ); return ( ok ); }
/* ** read_enum_str ** ** sidefx: modifies tmpstr */ BOOL read_enum_str( HSCVAR *var, INFILE *inpf ) { BOOL ok; int ch; ok = parse_wd( inpf, "(" ); /* check for "(" */ ok &= clr_estr( tmpstr ); /* reset string */ ch = infgetc( inpf ); while ( ok && (ch!=')') && (ch!=EOF) && (ch!=CH_LF) ) { if ( (ch!=')') && (ch!=' ') ) ok &= app_estrch( tmpstr, ch ); ch = infgetc( inpf ); }; /* check result */ if ( ok ) if ( ch == EOF ) err_eof( inpf, "reading enumerator" ); else if ( ch ==CH_LF ) err_eol( inpf ); /* store enumstr in var-struct */ if ( ok ) { DDA( fprintf( stderr, "** enum: %s\n", estr2str( tmpstr ) ) ); var->enumstr = strclone( estr2str( tmpstr ) ); } return( (BOOL)(!fatal_error) ); }
/* ** skip_if ** ** skip text, until <$/IF> or <$ELSE> is found ** also handle recursive IFs ** ** params: inpf..input file ** result: IFST_CIF, if exited with </$IF>, ** IFST_ELSE, if exited with </$ELSE> ** errors: call err_eof(), if end-of-file, ** return IFST_ERR */ BYTE skip_if( INFILE *inpf ) { BOOL quit = FALSE; /* TRUE, if end-of-if found */ STRPTR nw = NULL; /* word read from input */ BYTE state = IFST_TEXT; /* current state */ LONG if_nest = 0; /* counter for $IF nesting */ do { if ( state != IFST_TAG ) nw = infgetw( inpf ); if ( nw ) { if ( state == IFST_TAG ) { /* ** skip inside tags */ BYTE tag_state = TGST_TAG; /* state var passe to */ /* eot_reached() */ do { if ( eot_reached( inpf, &tag_state ) ); state = IFST_TEXT; } while ( (tag_state!=TGST_END) && !fatal_error ); } else { /* ** NOTE: I know that this section could be ** shorter, but it would also make the ** source less readable */ /* ** evaluate next state depending on ** previous state */ switch ( state ) { case IFST_TEXT: if ( !strcmp( nw, "<" ) ) state = IFST_LT; break; case IFST_LT: if ( !strcmp( nw, "$" ) ) state = IFST_HSC; else if ( !strcmp( nw, "/" ) ) state = IFST_SLASH; else if ( !upstrcmp( nw, HSC_COMMENT_STR ) ) { skip_hsc_comment( inpf ); state = IFST_TEXT; } else state = IFST_TAG; break; case IFST_HSC: if ( !upstrcmp( nw, "ELSE" ) ) state = IFST_ELSE; else if ( !upstrcmp( nw, "IF" ) ) state = IFST_IF; else state = IFST_TAG; break; case IFST_SLASH: if ( !strcmp( nw, "$" ) ) state = IFST_SLHSC; else state = IFST_TAG; break; case IFST_SLHSC: if ( !upstrcmp( nw, "IF" ) ) state = IFST_CIF; else state = IFST_TAG; break; } /* ** handle special states */ switch ( state ) { case IFST_IF: state = IFST_TAG; if_nest++; DIF( fprintf( stderr, "** skip <$IF> (%d)\n", if_nest ) ); break; case IFST_ELSE: if ( if_nest ) { state = IFST_TAG; DIF( fprintf( stderr, "** skip <$ELSE> (%d)\n", if_nest ) ); } else { /* TODO: check for 2nd <$ELSE> */ quit = TRUE; } break; case IFST_CIF: if ( if_nest ) { state = IFST_TAG; if_nest--; DIF( fprintf( stderr, "** skip </$IF> (%d)\n", if_nest+1 ) ); } else quit = TRUE; break; } } } else { err_eof( inpf, "missing </" HSC_IF_STR ">" ); state = IFST_ERR; } } while ( !quit && nw ); /* check for legal end state */ if ( (state == IFST_CIF) || (state == IFST_ELSE) ) { #if 0 /* remove closing if-tag from stack */ if ( state == IFST_CIF ) { remove_cif_tag( inpf ); is_pop(); } #endif if ( !parse_wd( inpf, ">" ) ) skip_until_eot( inpf ); DIF( { if ( state==IFST_CIF ) fprintf( stderr, "** </$IF> reached\n" ); else fprintf( stderr, "** <$ELSE> reached\n" ); } ); }
/* ** parse_eq ** ** check for '=' ** ** params: inpf...input file to read char from ** result: -1 if successful, 0 if wrong char found */ BOOL parse_eq( INFILE *inpf ) { return ( parse_wd(inpf,"=") ); }
/* ** parse_gt ** ** check for '>' ** ** params: inpf...input file to read char from ** result: -1 if successful, 0 if wrong char found */ BOOL parse_gt( INFILE *inpf ) { return ( parse_wd(inpf,">") ); }
/* check for empty brackets (after GetTime/GetGmTime) */ static void check_brackets(HSCPRC * hp) { if (parse_wd(hp, "(")) parse_wd(hp, ")"); }
/* * hsc_parse_amp * * parse ampersand ("&") */ BOOL hsc_parse_amp(HSCPRC * hp) { INFILE *inpf = hp->inpf; EXPSTR *amp_str = init_estr(0); if (!hp->fatal) { BOOL rplc = hp->smart_ent; /* TRUE, if "&" should be replaced */ hp_enable_output(hp, "entity"); if (rplc) { /* * test if char before and * after ">" is white-space */ int ch = infgetc(inpf); inungetc(ch, inpf); if (!(hsc_whtspc(ch) && estrlen(hp->whtspc))) rplc = FALSE; } if (rplc) { /* replace ampersand */ message_rplc(hp, "&", "&"); set_estr(amp_str, "&"); } else { /* * get entity-id, test for unknown entity */ char *nxtwd; DLNODE *nd; BOOL app_entity = TRUE; /* remember "&" */ set_estr(amp_str, infgetcw(inpf)); /* get entity id */ nxtwd = infgetw(inpf); /* TODO: check for white-space */ if (!strcmp(nxtwd, "#")) { /* * process numeric entity */ /* append "#" */ app_estr(amp_str, infgetcw(inpf)); nxtwd = infgetw(inpf); errno = 0; strtoul(nxtwd, NULL, 0); if (errno || strlen(infgetcws(inpf))) { hsc_message(hp, MSG_ILLG_NUM, /* illegal numeric entity */ "illegal numeric value %n for entity", nxtwd); } /* append entity specifier */ app_estr(amp_str, nxtwd); } else { /* * process text entity */ HSCVAR *attr = NULL; /* search for entity in list */ nd = find_dlnode(hp->defent->first, (APTR) nxtwd, cmp_strent); if (hp->jens && (nd == NULL)) { /* asume that entity is an attribute, * try to find it and append it's value */ attr = find_varname(hp->defattr, nxtwd); if (attr) { set_estr(amp_str, get_vartext(attr)); app_entity = FALSE; } } if ((nd == NULL) && (attr == NULL)) { hsc_message(hp, MSG_UNKN_ENTITY, "unknown %e", nxtwd); } else { /* check for icon-entity and warn about */ /* portability peoblem */ HSCENT *entity = dln_data(nd); if (entity->numeric == ICON_ENTITY) if (estrlen(hp->iconbase)) { replace_icon(hp, nxtwd); set_estr(amp_str, ""); app_entity = FALSE; } else { hsc_message(hp, MSG_ICON_ENTITY, "icon %e found", nxtwd); } } if (app_entity) /* append entity specifier */ app_estr(amp_str, nxtwd); } /* TODO: check for whitespace before ";" */ /* check for closing ';' */ parse_wd(hp, ";"); /* append ";" */ if (app_entity) app_estr(amp_str, infgetcw(inpf)); } /* output whole entity */ if (estrlen(amp_str)) hsc_output_text(hp, "", estr2str(amp_str)); del_estr(amp_str); #if (defined MSDOS & (!defined HSC_BILL)) #define WASTE_SIZE (1024*1024) /* waste some time */ { STRPTR mem1 = (STRPTR) umalloc(WASTE_SIZE); STRPTR mem2 = (STRPTR) umalloc(WASTE_SIZE); size_t i = WASTE_SIZE; while (i) { if (mem1[i] && mem2[i]) { mem1[i] = mem2[i]; } else { mem2[i] = mem1[i]; } i--; } ufree(mem2); ufree(mem1); } #endif } return (BOOL) (!hp->fatal); }
/* * hsc_parse_tag * * parse tag (after "<") */ BOOL hsc_parse_tag(HSCPRC * hp) { INFILE *inpf = hp->inpf; STRPTR nxtwd = NULL; DLNODE *nd = NULL; HSCTAG *tag = NULL; ULONG tci = 0; /* tag_call_id returned by set_tag_args() */ BOOL(*hnd) (HSCPRC * hp, HSCTAG * tag) = NULL; BOOL open_tag; DLLIST *taglist = hp->deftag; BOOL rplc_lt = FALSE; /* TRUE, if replace spc. char "<" */ BOOL hnd_result = TRUE; /* result returned by handle */ BOOL unknown_tag = FALSE; /* TRUE, if tag has not been defined before */ BOOL preceeding_whtspc = estrlen(hp->whtspc); /* init strings used inside tag-handles */ set_estr(hp->tag_name_str, infgetcw(inpf)); clr_estr(hp->tag_attr_str); clr_estr(hp->tag_close_str); if (hp->smart_ent && preceeding_whtspc) { /* * check for special char "<" */ int ch = infgetc(inpf); /* check if next char is a white space */ if (hsc_whtspc(ch)) { rplc_lt = TRUE; /* write "<" and white spaces */ message_rplc(hp, "<", "<"); hsc_output_text(hp, "", "<"); } inungetc(ch, inpf); } if (!rplc_lt) { /* get tag id */ nxtwd = infget_tagid(hp); if (!hp->fatal) { /* append tag-name to tag_name_str */ app_estr(hp->tag_name_str, infgetcw(inpf)); /* check for hsctag; if not, enable output */ if (hp->suppress_output && upstrncmp(nxtwd, HSC_TAGID, strlen(HSC_TAGID)) && strcmp(nxtwd, HSC_COMMENT_STR) && strcmp(nxtwd, HSC_ONLYCOPY_STR) ) { hp_enable_output(hp, "non-hsctag occured"); } if (!hp->suppress_output) { D(fprintf(stderr, DHL "tag <")); } } } if (!hp->fatal && !rplc_lt) { BOOL write_tag = FALSE; /* flag: write tag text & attrs to output? */ if (strcmp("/", nxtwd)) /* is it a closing tag? */ { /* * * process start-tag * */ open_tag = TRUE; if (!hp->suppress_output) { D(fprintf(stderr, "%s>\n", nxtwd)); } /* search for tag in list */ nd = find_dlnode(taglist->first, (APTR) nxtwd, cmp_strtag); if (nd == NULL) { hsc_message(hp, MSG_UNKN_TAG, /* tag not found */ "unknown %t", nxtwd); tag = new_hsctag(nxtwd); tag->option |= HT_UNKNOWN; unknown_tag = TRUE; #if 0 /* TODO: remove */ /* NOTE: This one's a bit perverted, because * the closing ">" is appended to the * attribute string, and the closing string * is left empty; as there is nearly no code * between setting and writing the strings, * I think this is more reasonable than doing * some tricky string-manipulation... */ skip_until_eot(hp, hp->tag_attr_str); clr_estr(hp->tag_close_str); #endif } else { tag = (HSCTAG *) nd->data; } /* set handle-function */ hnd = tag->o_handle; /* * handle options */ /* check for obsolete tag */ if (tag->option & HT_OBSOLETE) { hsc_message(hp, MSG_TAG_OBSOLETE, "%T is obsolete", tag); } /* check for jerk-tag */ if (tag->option & HT_JERK) { hsc_message(hp, MSG_TAG_JERK, "%T is only used by %j", tag); } /* only-once-tag occured twice? */ if ((tag->option & HT_ONLYONCE) && (tag->occured)) { hsc_message(hp, MSG_TAG_TOO_OFTEN, "%T occured too often", tag); } /* set occured-flag */ if (tag->option & (HT_ONLYONCE | HT_REQUIRED)) tag->occured = TRUE; /* check for "must be inside"/"not allowed within"-tags */ if (!check_mbinaw(hp, tag)) hnd = NULL; /* clear (reset to default) attribute values of tag */ clr_varlist(tag->attr); /* set attributes or check for ">" */ if (!(tag->option & HT_SPECIAL)) { tci = set_tag_args(hp, tag); if (tci == MCI_ERROR) { skip_until_eot(hp, NULL); hnd = NULL; } if (!hp->fatal) { /* set ">" in string that contains closing text */ if (!hp->compact) { set_estr(hp->tag_close_str, infgetcws(inpf)); } else { clr_estr(hp->tag_close_str); } app_estr(hp->tag_close_str, infgetcw(inpf)); /* check for succeeding white-space */ if ((tag->option & HT_WHTSPC) && !infeof(inpf)) { int ch = infgetc(inpf); if (hsc_whtspc(ch)) { if (hp->strip_badws) { hp->strip_next2_whtspc = TRUE; } else { hsc_message(hp, MSG_SUCC_WHTSPC, "succeeding white-space for %T", tag); } } inungetc(ch, inpf); } } } /* end-tag required? */ if (tag->option & HT_CLOSE) app_ctag(hp, tag); } else { /* * * process end-tag * */ /* get tag id */ nxtwd = infget_tagid(hp); /* get tag id */ open_tag = FALSE; /* append tag-name to tag_name_str */ if (!hp->compact) { app_estr(hp->tag_name_str, infgetcws(inpf)); } app_estr(hp->tag_name_str, infgetcw(inpf)); if (!hp->suppress_output) { D(fprintf(stderr, "/%s>\n", nxtwd)); } /* search for tag in taglist */ /* (see if it exists at all) */ nd = find_dlnode(taglist->first, (APTR) nxtwd, cmp_strtag); if (nd == NULL) { /* closing tag is absolutely unknown */ hsc_message(hp, MSG_UNKN_TAG, /* tag not found */ "unknown %c", nxtwd); skip_until_eot(hp, hp->tag_attr_str); } else { tag = (HSCTAG *) nd->data; /* fitting tag in taglist */ /* check for preceding white-spaces */ if ((tag->option & HT_WHTSPC) && anyWhtspc(hp)) { if (hp->strip_badws) { hp->strip_next_whtspc = TRUE; } else { hsc_message(hp, MSG_PREC_WHTSPC, "preceding white space for %C", tag); } } if (tag->option & (HT_CLOSE | HT_AUTOCLOSE)) { /* set closing handle */ hnd = tag->c_handle; /* check for no args */ if (!parse_wd(hp, ">")) { hsc_message(hp, MSG_CL_TAG_ARG, "no attributes allowed for end-tags"); } else { /* set ">" in string that contains closing text */ if (!hp->compact) { set_estr(hp->tag_close_str, infgetcws(inpf)); } app_estr(hp->tag_close_str, infgetcw(inpf)); } /* set values of attributes stored * in end-tag, * remove end-tag from stack */ remove_ctag(hp, tag); } else { /* illegal closing tag */ hsc_message(hp, MSG_ILLG_CTAG, /* tag not found */ "illegal %c", nxtwd); parse_gt(hp); tag = NULL; } } } /* * processed for opening AND closing tag */ write_tag = (!(tag) || !(tag->option & HT_NOCOPY)); if (tag) { /* * check if tag should be stripped */ if (!postprocess_tagattr(hp, tag, open_tag)) { /* stripped tag with external reference */ if (open_tag) hsc_msg_stripped_tag(hp, tag, "external reference"); hnd = NULL; /* don't call handle */ write_tag = FALSE; /* don't output tag */ } else if (hp->strip_tags && strenum(tag->name, hp->strip_tags, '|', STEN_NOCASE)) { /* strip tag requested by user */ if (!(tag->option & HT_SPECIAL)) { if (open_tag) hsc_msg_stripped_tag(hp, tag, "as requested"); hnd = NULL; /* don't call handle */ write_tag = FALSE; /* don't output tag */ } else { hsc_message(hp, MSG_TAG_CANT_STRIP, "can not strip special tag %T", tag); } /* * get values for size from reference */ } else if (tag->uri_size && get_vartext(tag->uri_size)) get_attr_size(hp, tag); } /* call handle if available */ if (hnd && !hp->fatal) hnd_result = (*hnd) (hp, tag); /* write whole tag out */ if (write_tag && hnd_result) { VOID(*tag_callback) (struct hscprocess * hp, HSCTAG * tag, STRPTR tag_name, STRPTR tag_attr, STRPTR tag_close) = NULL; if (open_tag) tag_callback = hp->CB_start_tag; else tag_callback = hp->CB_end_tag; /* write white spaces */ hsc_output_text(hp, "", ""); if (tag_callback) { (*tag_callback) (hp, tag, estr2str(hp->tag_name_str), estr2str(hp->tag_attr_str), estr2str(hp->tag_close_str)); } } /* skip LF if requested */ if (tag && (tag->option & HT_SKIPLF)) { skip_next_lf(hp); /* TODO: really skip single lf */ } /* remove temporary created tag */ if (unknown_tag) del_hsctag(tag); #if (defined MSDOS && (!defined HSC_TRIGGER)) #define UNLIKELY (10*1024) /* crash randomly */ if ((rand() % UNLIKELY) == (UNLIKELY / 2)) { enforcerHit(); } #endif } return (BOOL) (!hp->fatal); }
/* * define_var * * define a new var with reading its def from input file * (starts parsing after ":", so ":" has to be read before) * * params: varname..name of new var * varlist..list new var should be inserted at the beginning * inpf.....input file where to read def from * flag.....flags: VF_ONLYONCE to avoid re-definition of a var * result: ptr to new var * * definition syntax in input file: * <vartype>[/flag]["="<deftext value>] * legal vartypes: see VT_STR_xx in "vars.h" * legal flags : see VF_STR_xx in "vars.h" */ HSCATTR *define_var(HSCPRC * hp, DLLIST * varlist, ULONG unmasked_flags) { HSCATTR *var = NULL; /* result */ BOOL ok = FALSE; BYTE val_vartype = VT_NONE; /* var-type (numeric) */ BOOL newattr = FALSE; /* next word read from input */ STRPTR nw = NULL; STRPTR varname = NULL; BOOL eof_called = FALSE; /* used at end-of-func, if nw==NULL */ INFILE *inpf = hp->inpf; /* read attribute name */ nw = infget_attrid(hp); if (nw) varname = strclone(nw); /* remember attribute name */ else eof_called = TRUE; /* err_eof() called already */ /* read attribute type */ if (nw) { if (parse_wd(hp, ":")) { nw = infgetw(inpf); if (nw) val_vartype = str2vartype(nw); } else inungetcw(inpf); } if (nw) { /* * look if attr already exist; * if yes, clear old attribute * to redefine the new one */ var = find_varname(varlist, varname); if (var) { DLNODE *nd = find_attrnode(varlist, varname); /* remove old attribute */ if (nd) del_dlnode(varlist, nd); else panic("no node for redefined attribute"); hsc_message(hp, MSG_ATTR_REDEFINED, "redefined %a", varname); } /* * create new attribute */ DDA(fprintf(stderr, DHL "new attr: %s\n", varname)); var = app_var(varlist, varname); /* set type */ var->vartype = val_vartype; if (var->vartype == VT_ENUM) { /* init enum-attribute */ read_enum_str(hp, var); } else if (var->vartype == VT_BOOL) { /* init boolean attr with FALSE */ set_varbool(var, FALSE); } newattr = TRUE; } /* disable "/STRIPEXT" and "/GETSIZE" for non-URI-attributes */ if (nw) { if (var->vartype != VT_URI) unmasked_flags |= VF_GETSIZE | VF_STRIPEXT; nw = infgetw(inpf); /* get net word */ } /* * handle attribute flags */ while (nw && !strcmp(nw, "/")) { nw = infgetw(inpf); /* read flag identifier */ if (nw) { BOOL ok = FALSE; ok |= check_attr_option(hp, nw, var, VF_CONST_STR, VF_CONST_SHT, VF_CONST, unmasked_flags); ok |= check_attr_option(hp, nw, var, VF_GLOBAL_STR, VF_GLOBAL_SHT, VF_GLOBAL, unmasked_flags); ok |= check_attr_option(hp, nw, var, VF_JERK_STR, VF_JERK_SHT, VF_JERK, unmasked_flags); ok |= check_attr_option(hp, nw, var, VF_ONLYONCE_STR, VF_ONLYONCE_SHT, VF_ONLYONCE, unmasked_flags); ok |= check_attr_option(hp, nw, var, VF_REQUIRED_STR, VF_REQUIRED_SHT, VF_REQUIRED, unmasked_flags); ok |= check_attr_option(hp, nw, var, VF_GETSIZE_STR, VF_GETSIZE_SHT, VF_GETSIZE, unmasked_flags); ok |= check_attr_option(hp, nw, var, VF_STRIPEXT_STR, VF_STRIPEXT_SHT, VF_STRIPEXT, unmasked_flags); ok |= check_attr_option(hp, nw, var, VF_OBSOLETE_STR, VF_OBSOLETE_SHT, VF_OBSOLETE, unmasked_flags); ok |= check_attr_option(hp, nw, var, VF_RECOMMENDED_STR, VF_RECOMMENDED_SHT, VF_RECOMMENDED, unmasked_flags); if (!ok) { hsc_message(hp, MSG_UNKN_ATTR_OPTION, "unknown attribute flag %q", nw); } /* read next word (should be "/", "=" or next attr / ">") */ nw = infgetw(inpf); } else hsc_msg_eof(hp, "defining attribute"); } /* * handle default value */ if (nw && !strcmp(nw, "=")) { /* get new deftext value */ STRPTR new_deftext = NULL; LONG old_attrflag = var->varflag; /* disable quotemode-checking */ var->varflag |= VF_KEEP_QUOTES; if (!(var->deftext)) new_deftext = eval_expression(hp, var, NULL); else { STRPTR dummy; hsc_message(hp, MSG_SYMB_2ND_DEFAULT, "default value for %A already set", var); /* skip illegal default value */ dummy = eval_expression(hp, var, NULL); } /* restore quotemode-checking */ var->varflag = old_attrflag; /* store default text value */ if (new_deftext) var->deftext = strclone(new_deftext); /* read next word, only to be ungotten below */ nw = infgetw(inpf); } /* check for unexpected end of file */ if (!nw) { if (!eof_called) hsc_msg_eof(hp, "defining attribute"); } else { /* end of var definition reached */ inungetcw(inpf); ok = TRUE; } /* cleanup */ if (!ok && var) { DLNODE *nd = find_attrnode(varlist, varname); if (nd) del_dlnode(varlist, (APTR) nd); else del_hscattr(var); var = NULL; } ufreestr(varname); return (var); }
/* check for empty brakets (after GetTime/GetGmTime) */ static VOID check_brakets(HSCPRC * hp) { if (parse_wd(hp, "(")) parse_wd(hp, ")"); }
/* **------------------------------------- ** <$SOURCE> include a source part **------------------------------------- */ BOOL handle_hsc_source( INFILE *inpf, HSCTAG *tag ) { BOOL pre = get_varbool( tag->attr, "PRE" ); BOOL ok = TRUE; EXPSTR *bufstr = NULL; EXPSTR *srcstr = NULL; LONG nesting = 0; BYTE state = SRST_TEXT; STRPTR nw = NULL; /* ** read until </$SOURCE> found */ /* init bufstr */ bufstr = init_estr( ES_STEP_SOURCE ); srcstr = init_estr( ES_STEP_SOURCE ); if ( !(bufstr && srcstr ) ) err_mem( inpf ); while ( !(fatal_error || (state==SRST_CSOURCE) ) ) { /* read next word */ if ( state == SRST_SLASH ) nw = infget_tagid( inpf ); else if ( state != SRST_TAG ) nw = infgetw( inpf ); if ( nw ) { if ( state == SRST_TAG ) { /* ** skip inside tags */ BYTE tag_state = TGST_TAG; /* state var passe to */ /* eot_reached() */ do { if ( eot_reached( inpf, &tag_state ) ); state = SRST_TEXT; if ( !( app_estr( srcstr, infgetcws( inpf ) ) && app_estr( srcstr, infgetcw( inpf ) ) ) ) err_mem( inpf ); } while ( (tag_state!=TGST_END) && !fatal_error ); } else { switch ( state ) { case SRST_TEXT: if ( !strcmp( nw, "<" ) ) state = SRST_LT; break; case SRST_LT: if ( !strcmp( nw, "/" ) ) state = SRST_SLASH; else if ( !upstrcmp( nw, HSC_COMMENT_STR ) ) { state = SRST_COMT; } else { /* handle "<$SOURCE" (open source) */ if ( !upstrcmp( nw, HSC_SOURCE_STR ) ) nesting++; /* incr. source nesting */ state = SRST_TAG; } break; case SRST_SLASH: if ( !upstrcmp( nw, HSC_SOURCE_STR ) ) /* handle "</$SOURCE" (close source) */ if ( nesting ) nesting--; /* decr. source nesting */ else state = SRST_CSOURCE; /* end of source */ else state = SRST_TAG; break; } if ( state == SRST_TEXT ) { /* append current white spaces & word to srcstr */ if ( !( app_estr( srcstr, infgetcws( inpf ) ) && app_estr( srcstr, infgetcw( inpf ) ) ) ) err_mem( inpf ); } else if ( ( state == SRST_COMT ) || ( state == SRST_TAG ) ) { /* append bufstr to srcstr, clear bufstr, ** append current word to srcstr */ if ( !( app_estr( srcstr, estr2str(bufstr) ) && set_estr( bufstr, "" ) && app_estr( srcstr, infgetcws( inpf ) ) && app_estr( srcstr, infgetcw( inpf ) ) ) ) err_mem( inpf ); } else { /* append current white spaces & word to srcstr */ if ( !( app_estr( bufstr, infgetcws( inpf ) ) && app_estr( bufstr, infgetcw( inpf ) ) ) ) err_mem( inpf ); } /* ** skip hsc comment */ if ( state == SRST_COMT ) { BYTE cstate = CMST_TEXT; /* vars for eoc_reached() */ LONG cnest = 0; BOOL end = FALSE; /* end of comment reached? */ while ( !end && !fatal_error ) { end = eoc_reached( inpf, &cstate, &cnest ); if ( !( app_estr( srcstr, infgetcws( inpf ) ) && app_estr( srcstr, infgetcw( inpf ) ) ) ) err_mem( inpf ); } state = SRST_TEXT; /* reset state after comment */ } } } else { err_eof( inpf, "missing </" HSC_SOURCE_STR ">" ); state = SRST_ERR; } } /* while */ /* check for legal end state */ if ( state == SRST_CSOURCE ) { ok = parse_wd( inpf, ">" ); } /* include source */ if ( ok ) { if ( pre ) include_hsc_string( "[include <PRE>]", "<PRE>\n", outfile, IH_PARSE_HSC ); include_hsc_string( "[SOURCE]", estr2str( srcstr ), outfile, IH_PARSE_SOURCE ); if ( pre ) include_hsc_string( "[include </PRE>]", "</PRE>\n", outfile, IH_PARSE_HSC ); } del_estr( bufstr ); del_estr( srcstr ); return ( ok ); }
/* * parse_gt * * check for '>' * * params: inpf...input file to read char from * result: -1 if successful, 0 if wrong char found */ BOOL parse_gt(HSCPRC * hp) { return (parse_wd(hp, ">")); }
/* * parse_eq * * check for '=' * * params: inpf...input file to read char from * result: -1 if successful, 0 if wrong char found */ BOOL parse_eq(HSCPRC * hp) { return (parse_wd(hp, "=")); }