/* * conv_uri2path * * convert a uri to a path for local (system-dependant) * file system */ VOID conv_uri2path(EXPSTR * dest, STRPTR uri, BOOL weenix) { clr_estr(dest); #ifdef AMIGA if (weenix) { /* convert leading "/" to ":" */ /* convert leading "~" to ":" */ if (!strncmp(uri, "/", 1) || !strncmp(uri, "~/", 2) || !strncmp(uri, "~", 1)) { app_estr(dest, ":"); uri++; } } /* convert leading "../" to "/" */ while (!strncmp(uri, PARENT_URI, strlen(PARENT_URI))) { app_estr(dest, PARENT_DIR); uri += strlen(PARENT_URI); } /* convert inside "../" to "//" */ while (uri[0]) { if (!strncmp(uri, PARENT_URI, strlen(PARENT_URI))) { app_estrch(dest, '/'); uri += strlen(PARENT_URI); } else { app_estrch(dest, uri[0]); uri++; } } #elif defined RISCOS set_estr(dest, uri); #elif defined MSDOS /* dos2 */ #elif (defined NEXTSTEP) || (defined BEOS) || (defined UNIX) set_estr(dest, uri); #else #error "system not supported: conv_uri2path" #endif }
/* ** handle_hsc_time ** ** insert current time */ BOOL handle_hsc_time( INFILE *inpf, HSCTAG *tag ) { STRPTR timefmt = get_vartext( tag->attr, "FORMAT" ); EXPSTR *timebuf = init_estr( TIMEBUF_INC ); BOOL strftrc = 0; /* result of strftime() */ size_t i; /* loop var */ /* set default time format */ if ( !timefmt ) timefmt = "%d-%b-%Y, %H:%M"; while ( !fatal_error && !strftrc ) { /* expand timebuffer */ for ( i=0; i<TIMEBUF_INC; i++ ) if ( !app_estrch( timebuf, '.' ) ) err_mem( inpf ); D( fprintf( stderr, "** timebuf: inc+%d\n", TIMEBUF_INC ) ); /* output time */ strftrc = strftime( estr2str( timebuf ), estrlen( timebuf ), timefmt, localtime(&now) ); } if ( strftrc ) include_hsc_string( "[insert TIME]", estr2str( timebuf ), outfile, IH_PARSE_HSC ); del_estr( timebuf ); return (TRUE); }
static VOID msg_idname(EXPSTR * msgstr, CONSTRPTR idname) { app_estr(msgstr, "id "); app_estr(msgstr, "\"#"); app_estr(msgstr, idname); app_estrch(msgstr, '"'); }
/* replace icon-entity by image */ static VOID replace_icon(HSCPRC * hp, STRPTR icon) { INFILEPOS *base = new_infilepos(hp->inpf); EXPSTR *image = init_estr(0); STRPTR s = estr2str(hp->iconbase); /* create string like <IMG SRC=":icons/back.gif" ALT="back"> */ set_estr(image, "<IMG SRC=\""); /* use iconbase with "*" replaced by iconname as uri */ while (s[0]) { if (s[0] == '*') app_estr(image, icon); else app_estrch(image, s[0]); s++; } /* set ALT attribute to iconname */ app_estr(image, "\" ALT=\""); app_estr(image, icon); app_estr(image, "\">"); hsc_message(hp, MSG_RPLC_ICON, "replacing icon-%e", icon); hsc_include_string(hp, SPECIAL_FILE_ID "include icon", estr2str(image), IH_PARSE_HSC | IH_NO_STATUS | IH_POS_PARENT); del_estr(image); del_infilepos(base); }
/* * gettimestr */ static EXPSTR *gettimestr(HSCPRC * hp, const struct tm *time) { #define TIMEBUF_INC 20 STRPTR timefmt = get_vartext_byname(hp->defattr, TIMEFORMAT_ATTR); EXPSTR *timebuf = init_estr(TIMEBUF_INC); BOOL strftrc = 0; /* result of strftime() */ size_t i; /* loop var */ /* set default time format */ if (!timefmt) timefmt = "%d-%b-%Y, %H:%M"; while (!(hp->fatal) && !strftrc) { /* expand timebuffer */ for (i = 0; i < TIMEBUF_INC; i++) app_estrch(timebuf, '.'); D(fprintf(stderr, DHL " timebuf: inc+%d\n", TIMEBUF_INC)); /* output time */ strftrc = strftime(estr2str(timebuf), estrlen(timebuf), timefmt, time); } if (!strftrc) { del_estr(timebuf); timebuf = NULL; } return (timebuf); }
/* ** 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) ); }
/* * conv_path2uri * * convert a path for local (system-dependant) * file system to URI */ VOID conv_path2uri(EXPSTR * dest, STRPTR path) { clr_estr(dest); #ifdef AMIGA /* replace leading parent directories by "../" */ while (!strncmp(path, PARENT_DIR, strlen(PARENT_DIR))) { app_estr(dest, PARENT_URI); path += strlen(PARENT_DIR); } while (path[0]) { /* replace all "//" by "../" */ if ((path[0] == '/') && (path[1] == '/')) { app_estr(dest, PARENT_URI); path += 2; } else { app_estrch(dest, path[0]); path++; } } #elif defined MSDOS /* replace all "\" by "/" */ while (path[0]) { if ((path[0] == '\\')) app_estrch(dest, '/'); else app_estrch(dest, path[0]); path++; } #elif defined UNIX /* simply copy path */ set_estr(dest, path); #else #error "system not supported: conv_path2uri" #endif }
static VOID send_arexx_command(HSCPRC * hp, STRPTR arexx_command) { /* Hex-escaped Arexx command */ EXPSTR *escaped_arexx_command = init_estr(256); STRPTR command_character = NULL; BOOL insert_concatenation; set_estr(escaped_arexx_command, "RX >nil: \"cmd='"); /* Hex-escape nasty characters in command before sending it via RX. * Probably more characters then neccessary are escaped, but extending * this list is faster then finding out if a character is nasty or not. */ command_character = arexx_command; insert_concatenation = TRUE; while (command_character[0] != '\0') { STRARR hex_buffer[10]; if (insert_concatenation) { app_estr(escaped_arexx_command, "'||'"); } switch (command_character[0]) { case '\'': case '\"': case '*': case '`': sprintf(hex_buffer, "'||'%x'x'", command_character[0]); app_estr(escaped_arexx_command, hex_buffer); insert_concatenation = TRUE; break; default: app_estrch(escaped_arexx_command, command_character[0]); insert_concatenation = FALSE; break; } command_character += 1; } app_estr(escaped_arexx_command,"';"); #if DEBUG_MSGBROWSER app_estr(escaped_arexx_command,"call open(f,'console:'); call writeln(f,cmd);"); #endif app_estr(escaped_arexx_command,"address " SC_SCMSG " cmd"); app_estr(escaped_arexx_command, "\""); #if DEBUG_MSGBROWSER fprintf(stderr, "sending arexx: %s\n", estr2str(escaped_arexx_command)); #endif system(estr2str(escaped_arexx_command)); del_estr(escaped_arexx_command); }
/* * conv_uri2path * * convert a uri to a path for local (system-dependant) * file system */ VOID conv_uri2path(EXPSTR * dest, STRPTR uri) { clr_estr(dest); #ifdef AMIGA /* convert leading "../" to "/" */ while (!strncmp(uri, PARENT_URI, strlen(PARENT_URI))) { app_estr(dest, PARENT_DIR); uri += strlen(PARENT_URI); } /* convert inside "../" to "//" */ while (uri[0]) { if (!strncmp(uri, PARENT_URI, strlen(PARENT_URI))) { app_estrch(dest, '/'); uri += strlen(PARENT_URI); } else { app_estrch(dest, uri[0]); uri++; } } #elif defined MSDOS /* convert all "/" to "\" */ while (uri[0]) { if (uri[0] == '/') app_estrch(dest, '\\'); else app_estrch(dest, uri[0]); uri++; } #elif defined UNIX set_estr(dest, uri); #else #error "system not supported: conv_2path" #endif }
BOOL app_estr( EXPSTR *es, CONSTRPTR s ) { size_t i; BOOL ok = TRUE; for ( i=0; ( (s[i]) && ok ); i++ ) ok &= app_estrch( es, s[i] ); return( ok ); }
BOOL hsc_set_server_dir(HSCPRC * hp, STRPTR dir) { set_estr(hp->server_dir, dir); /* if dir does not already end with a directory separator, append it now */ if (!strchr(PATH_SEPARATOR, last_ch(dir))) { app_estrch(hp->server_dir, PATH_SEPARATOR[0]); } D(fprintf(stderr, DHL "serverdir=`%s'\n", estr2str(hp->server_dir))); return (TRUE); }
/* * try_set_attr * * if attribute exists and it's value is empty, set * new value and update tag-attribute-string */ static VOID try_setattr(HSCPRC * hp, HSCVAR * attr, ULONG value) { if (attr) { STRPTR old_value = get_vartext(attr); STRPTR new_value = long2str(value); if (!old_value) { /* set new value */ set_vartext(attr, new_value); /* append attribute name and "=" */ app_estr(hp->tag_attr_str, " "); app_estr(hp->tag_attr_str, attr->name); app_estr(hp->tag_attr_str, "="); /* append quotes and value */ if ((hp->quotemode == QMODE_KEEP) || (hp->quotemode == QMODE_DOUBLE)) app_estrch(hp->tag_attr_str, '\"'); else if (hp->quotemode == QMODE_SINGLE) app_estrch(hp->tag_attr_str, '\''); app_estr(hp->tag_attr_str, long2str(value)); /* append value */ if ((hp->quotemode == QMODE_KEEP) || (hp->quotemode == QMODE_DOUBLE)) app_estrch(hp->tag_attr_str, '\"'); else if (hp->quotemode == QMODE_SINGLE) app_estrch(hp->tag_attr_str, '\''); } else { /* validate old value */ if (strcmp(old_value, new_value)) { hsc_message(hp, MSG_UNEX_ATTR_VALUE, "unexpected value for %A: expected %q, found %q", attr, new_value, old_value); } } } }
/* is_push: add a new value to the if-stack */ VOID is_push( BOOL value ) { BYTE ch; if ( value ) ch = ISTK_TRUE; else ch = ISTK_FALSE; if ( !app_estrch( IF_stack, ch ) ) err_mem( NULL ); DIF( fprintf( stderr, "** push IF-stack: \"%s\"\n", estr2str( IF_stack ) ) ); }
/* * try_set_attr * * if attribute exists and it's value is empty, set * new value and update tag-attribute-string */ static VOID try_setattr(HSCPRC * hp, HSCVAR * attr, ULONG value) { if (attr && !get_vartext(attr)) { set_vartext(attr, long2str(value)); /* append attribute name and "=" */ app_estr(hp->tag_attr_str, " "); app_estr(hp->tag_attr_str, attr->name); app_estr(hp->tag_attr_str, "="); /* append quotes and value */ if ((hp->quotemode == QMODE_KEEP) || (hp->quotemode == QMODE_DOUBLE)) app_estrch(hp->tag_attr_str, '\"'); else if (hp->quotemode == QMODE_SINGLE) app_estrch(hp->tag_attr_str, '\''); app_estr(hp->tag_attr_str, long2str(value)); /* append value */ if ((hp->quotemode == QMODE_KEEP) || (hp->quotemode == QMODE_DOUBLE)) app_estrch(hp->tag_attr_str, '\"'); else if (hp->quotemode == QMODE_SINGLE) app_estrch(hp->tag_attr_str, '\''); } }
/* * append groups of data */ static VOID append_header(EXPSTR * prjstr) { time_t now = time(NULL); /* get current time */ /* create string for current time */ strftime(timebuf, TIMEBUFSIZE, "%d-%b-%Y %H:%M:%S", localtime(&now)); /* append key-sequence, file-format-version and comment */ app_estr(prjstr, FILEID_HSCPRJ "\n" LINE_VERSION_STR " "); append_ulong(prjstr, VERSION_HSCPRJ); app_estr(prjstr, "\n"); app_estr(prjstr, LINE_REM_STR " Contains all data relevant for project.\n" LINE_REM_STR " Maintained by hsc, DO NOT MODIFY!\n"); app_estr(prjstr, LINE_REM_STR " updated: "); app_estr(prjstr, timebuf); app_estrch(prjstr, '\n'); }
/* * user_defines_ok * * process all defines passed via user args * * result: always TRUE */ BOOL user_defines_ok(HSCPRC * hp) { /* define destination attributes (HSC.DOCUMENT.URI etc.) */ define_file_attribs(hp); if (define_list && dll_first(define_list)) { DLNODE *nd = dll_first(define_list); EXPSTR *defbuf = init_estr(64); #if 0 BOOL old_ignore_quotemsg = hsc_get_msg_ignore(hp, MSG_ARG_NO_QUOTE); #endif while (nd) { STRPTR defarg = (STRPTR) dln_data(nd); D(fprintf(stderr, DHSC "define using `%s'\n", defarg)); set_estr(defbuf, "<$define "); /* append attribute name */ do { app_estrch(defbuf, defarg[0]); defarg++; } while (defarg[0] && (defarg[0] != '=') && (defarg[0] != '/') && (defarg[0] != ':')); /* if no type set, use "string" as default */ if (defarg[0] != ':') { app_estr(defbuf, ":string"); } /* append type (if set) and attribute-flags */ while (defarg[0] && (defarg[0] != '=')) { app_estrch(defbuf, defarg[0]); defarg++; } /* append value (if any) and quotes */ if (defarg[0] == '=') { char quote_needed = 0; /* flag: user did not use quotes */ /* append "=" */ app_estrch(defbuf, defarg[0]); defarg++; /* check which kind of quote should be appended */ if ((defarg[0] != '\"') && (defarg[0] != '\'')) { BOOL single_quote = FALSE; BOOL double_quote = FALSE; STRPTR scanarg = defarg; /* scan value for quotes */ while (scanarg[0]) { if (scanarg[0] == '\"') double_quote = TRUE; else if (scanarg[0] == '\'') single_quote = TRUE; scanarg++; } /* choose quote to enclose value */ if (!double_quote) quote_needed = '\"'; else if (!single_quote) quote_needed = '\''; else panic("both quotes in value"); } /* append quote (if not already done by user) */ if (quote_needed) app_estrch(defbuf, quote_needed); /* append value */ while (defarg[0]) { app_estrch(defbuf, defarg[0]); defarg++; } /* append quote (if not already done by user) */ if (quote_needed) app_estrch(defbuf, quote_needed); } /* append end ">" */ app_estrch(defbuf, '>'); D(fprintf(stderr, DHSC "define: `%s'\n", estr2str(defbuf))); hsc_include_string(hp, "DEFINE", estr2str(defbuf), IH_PARSE_HSC | IH_NO_STATUS); nd = dln_next(nd); } del_estr(defbuf); #if 0 hsc_set_msg_ignore(hp, MSG_ARG_NO_QUOTE, old_ignore_quotemsg); #endif } else { D(fprintf(stderr, DHSC "(no defines)\n")); } return ((BOOL) (return_code < RC_ERROR)); }
VOID hsc_message(HSCPRC * hp, HSCMSG_ID msg_id, const char *format,...) { HSCMSG_CLASS msg_class = hsc_get_msg_class(hp, msg_id); HSCMSG_ID msg_id_unmasked = msg_id & MASK_MESSAGE; INFILE *msg_inpf = NULL; STRPTR msg_fname = "unknown"; ULONG msg_x = 0; ULONG msg_y = 0; BOOL disp_msg = really_display_message(hp, msg_id); /* display message? */ if (disp_msg) { va_list ap; /* increase message-counter */ hp->msg_count++; /* set fatal-flag, if this is a fatal message */ if (msg_id > MSG_FATAL) { hp->fatal = TRUE; } /* clear message buffer */ clr_estr(hp->curr_msg); /* create message string */ va_start(ap, format); while (format[0]) { if (format[0] == '%') { STRPTR s = NULL; HSCTAG *tag = NULL; HSCTAG *lazy = NULL; HSCATTR *attr = NULL; HSCENT *ent = NULL; format++; switch (format[0]) { case 'd': /* * append decimal number */ app_estr(hp->curr_msg, long2str(va_arg(ap, LONG))); break; case 'q': /* * append quoted string */ s = va_arg(ap, STRPTR); app_estrch(hp->curr_msg, '`'); while (s[0]) { switch (s[0]) { case '\n': app_estr(hp->curr_msg, "\\n"); break; case '\"': app_estr(hp->curr_msg, "\\\""); break; default: if (s[0] < ' ') { app_estrch(hp->curr_msg, '\\'); app_estr(hp->curr_msg, long2str((LONG) s[0])); app_estrch(hp->curr_msg, ';'); } else app_estrch(hp->curr_msg, s[0]); } s++; /* process next char */ } app_estrch(hp->curr_msg, '\''); break; case 's': /* * append simple string */ app_estr(hp->curr_msg, va_arg(ap, STRPTR)); break; case 'T': /* append tag-pointer */ tag = va_arg(ap, HSCTAG *); msg_tag(hp->curr_msg, tag->name); break; case 't': /* append tag */ msg_tag(hp->curr_msg, va_arg(ap, STRPTR)); break; case 'C': /* append end tag-pointer */ tag = va_arg(ap, HSCTAG *); msg_endtag(hp->curr_msg, tag->name); break; case 'c': /* append end tag */ msg_endtag(hp->curr_msg, va_arg(ap, STRPTR)); break; case 'A': /* append attribute-pointer */ attr = va_arg(ap, HSCATTR *); msg_attr(hp->curr_msg, attr->name); break; case 'a': /* append attribute */ msg_attr(hp->curr_msg, va_arg(ap, STRPTR)); break; case 'E': /* append entity-pointer */ ent = va_arg(ap, HSCENT *); msg_entity(hp->curr_msg, ent->name); break; case 'e': /* append entity */ msg_entity(hp->curr_msg, va_arg(ap, STRPTR)); break; case 'i': /* append ID */ msg_idname(hp->curr_msg, va_arg(ap, STRPTR)); break; case 'j': /* append jerk/prostitute */ if (hp->prostitute) { app_estr(hp->curr_msg, "prostitutes"); } else { app_estr(hp->curr_msg, "jerks"); } break; case 'L': /* append var-list-pointer */ lazy = va_arg(ap, HSCTAG *); msg_lazy(hp->curr_msg, lazy->name); break; case 'l': /* append var-list */ msg_lazy(hp->curr_msg, va_arg(ap, STRPTR)); break; default: /* * append unknown */ app_estrch(hp->curr_msg, '%'); if (format[0] && (format[0] != '%')) { app_estrch(hp->curr_msg, '%'); format--; } break; } } else { app_estrch(hp->curr_msg, format[0]); } if (format[0]) { format++; } }
/* ** set_tag_arg ** ** parse & set one single tag argument ** */ static BOOL set_tag_arg( HSCPRC *hp, DLLIST *varlist, STRPTR varname ) { HSCATTR *var = find_varname( varlist, varname ); INFILE *inpf = hp->inpf; STRPTR arg = NULL; BOOL ok = FALSE; STRPTR nw; HSCATTR skipvar; /* dummy attribute to skip unkown */ EXPSTR *attr_str = init_estr( 40 ); /* string for attribute name */ EXPSTR *val_str = init_estr( 40 ); /* string for "=" and value */ DAV( fprintf( stderr, DHL " set attr %s\n", varname ) ); /* append attribute name to attr_str */ app_estr( attr_str, infgetcws( inpf ) ); app_estr( attr_str, infgetcw( inpf ) ); if ( !var ) { /* attribute not found */ /* assign to pseudo-attribute */ var = &skipvar; var->name = varname; var->deftext = NULL; var->text = NULL; var->enumstr = NULL; var->vartype = VT_STRING; var->varflag = 0; /* message: unknown attribute */ hsc_msg_unkn_attr( hp, varname ); } /* get argument */ nw = infgetw( inpf ); if ( nw ) if ( !strcmp( nw, "=" ) ) { /* append "=" to log */ app_estr( val_str, infgetcws( inpf ) ); app_estr( val_str, infgetcw( inpf ) ); /* parse expression */ arg = eval_expression( hp, var, NULL ); /* append value to log */ if ( var->quote != VQ_NO_QUOTE ) app_estrch( val_str, var->quote ); if ( get_vartext( var ) ) app_estr( val_str, get_vartext( var ) ); if ( var->quote != VQ_NO_QUOTE ) app_estrch( val_str, var->quote ); if ( arg ) { DAV( fprintf( stderr, DHL " `%s'\n", arg ) ); ok = TRUE; } } else { arg = NULL; inungetcwws( inpf ); ok = TRUE; } else hsc_msg_eof( hp, "read attribute value" ); if ( ok ) if ( arg ) { if ( var->vartype == VT_BOOL ) { /* set boolean attribute depending on expression */ set_vartext_bool( var, get_varbool( var ) ); /* if the expression returned FALSE, remove ** the boolean switch from the call */ if ( !get_varbool( var ) ) clr_estr( attr_str ); } else /* append value to attribute string */ app_estr( attr_str, estr2str( val_str ) ); } else { /* no value has been passed to the attribute */ if ( var->vartype == VT_BOOL ) { /* for boolean attributes, this is legal, ** and enables the attribute */ set_vartext_bool( var, TRUE ); } else { /* for non-boolean attributes, display ** error message */ hsc_message( hp, MSG_NOARG_ATTR, "missing value for %A", var ); } } #if 0 if ( arg ) { if ( var->vartype == VT_BOOL ) { message( MSG_ARG_BOOL_ATTR, inpf ); errstr( "value for boolean" ); errsym( var->name ); errlf(); } } else { if ( var->vartype == VT_BOOL ) { /* set boolean attribute */ DAV( fprintf( stderr, " (bool)\n", var->name ) ); set_vartext( var, var->name ); var->quote = VQ_NO_QUOTE; } else { } } #endif /* cleanup pseudo-attr */ if ( var == &skipvar ) clr_vartext( var ); /* append & cleanup attribute and value string */ app_estr( hp->tag_attr_str, estr2str( attr_str ) ); del_estr( attr_str ); del_estr( val_str ); return( ok ); }
int main(void) { #if 0 LONG i; #endif #if DEBUG_UGLY_MEMORY atexit(atexit_uglymemory); #endif #if 0 for (i = 0; i < 20; i++) printf("modadj(%-2d/%-2d) = %d\n", i, EXPSTR_MEMSTEP, modadj(i, EXPSTR_MEMSTEP)); #endif es = init_estr(8); pe("init "); res = init_estr(8); pr("init "); umem_wallcheck("after init"); #if 0 /* test reference to NULL string */ app_estrch(NULL, 'x'); app_estr(es, NULL); #endif #if 0 #if 1 printf("** test set\n"); set_estr(es, "dummy"); pr("set "); umem_wallcheck("after set"); #if 1 set_estr(es, "hugo ist doof."); pe("set "); set_estrn(es, "hugo", 4); pe("setn:4 "); set_estrn(es, "hugo", 1); pe("setn:1 "); set_estrn(es, "hugo", 0); pe("setn:0 "); set_estrn(es, "hugo", 5); pe("setn:5 "); #endif umem_wallcheck("after set"); #endif #if 1 printf("** test append-string\n"); set_estr(es, "hugo ist doof...!!"); pe("set "); app_estrch(es, ' '); pe("appch "); app_estrch(es, 's'); pe("appch "); #if 1 app_estr(es, "epp auch."); pe("appstr"); app_estr(es, "."); pe("appstr"); app_estr(es, "."); pe("appstr"); app_estr(es, "."); pe("appstr"); app_estr(es, " that's it, as you can see"); pe("appstr"); #endif umem_wallcheck("after append"); #endif #if 0 /* test cutting functions */ estrcpy(res, es); pr("copy "); get_mid_estr(es, res, 5, 3); pe("mid "); /* "ist" */ get_right_estr(es, res, 5); pe("right "); /* "auch." */ get_left_estr(es, res, 4); pe("left "); /* "hugo" */ /* test special cases for cutting funtions */ printf("** test get-part\n"); set_estr(res, "hugo"); pr("res=hugo "); get_mid_estr(es, res, 4, 3); pe("mid(4,5) "); get_mid_estr(es, res, 3, 2); pe("mid(3,2) "); get_mid_estr(es, res, 0, 9); pe("mid(0,9) "); get_left_estr(es, res, 5); pe("lef(5) "); get_left_estr(es, res, 4); pe("lef(4) "); get_right_estr(es, res, 5); pe("rig(5) "); get_right_estr(es, res, 4); pe("rig(4) "); #endif #endif /* umem_wallcheck("before delete"); */ printf("** remove strings\n"); del_estr(es); del_estr(res); return (0); }
/* ** parse_vararg: read & check a attribute value */ STRPTR parse_vararg( HSCVAR *var, INFILE *inpf ) { STRPTR str_vararg = NULL; /* return value */ int ch; /* char read from input */ /* TODO: handle "<>" (reset var->text to NULL) */ infskip_ws( inpf ); /* disable log */ inflog_disable( inpf ); /* read var->quote char */ ch = infgetc( inpf ); if ( !strchr( VQ_STR_QUOTE, ch ) ) if ( ch != EOF ) var->quote = VQ_NO_QUOTE; else err_eof( inpf, "reading attribute" ); else var->quote = ch; /* warning if no quote */ if ( ( var->quote == VQ_NO_QUOTE ) && !( var->varflag & VF_NOQUOTE ) ) { message( MSG_ARG_NO_QUOTE, inpf ); errstr( "Argument without quote\n" ); } /* read arg string */ if ( var->quote == '<' ) { /* ** get arg from other var */ STRPTR nw = infgetw( inpf ); if ( nw ) { HSCVAR *refvar = find_varname( vars, nw ); if ( refvar ) { /* TODO: type checking */ var->quote = refvar->quote; str_vararg = refvar->text; /* check empty/circular reference */ if ( !str_vararg ) { message( MSG_EMPTY_SYMB_REF, inpf ); errstr( "Empty reference to" ); errsym( var->name ); errlf(); } /* debugging message */ DDA( fprintf( stderr, "** %s refers to <%s>\n", var->name, refvar->name ) ); } else { /* reference to unknown var */ message( MSG_UNKN_SYMB_REF, inpf ); errstr( "reference to unknown" ); errsym( nw ); errlf(); } if ( (!refvar) || (!str_vararg ) ) { /* return empty var */ var->quote = '"'; str_vararg = ""; } parse_gt( inpf ); } else err_eof( inpf, "reading attribute" ); } else if ( var->quote != EOF ) { /* ** get arg from input file */ BOOL end = FALSE; /* clear vararg or set with first char read */ if ( var->quote == VQ_NO_QUOTE ) end = !set_estr( vararg, ch2str( ch ) ); else end = !clr_estr( vararg ); if ( end ) err_mem( inpf ); /* ** read next char from input file until a ** closing quote if found. ** if the arg had no quote, a white space ** or a '>' is used to detect end of arg. ** if a LF is found, view error message */ while ( !end ) { ch = infgetc( inpf ); end = TRUE; if ( ch == EOF ) err_eof( inpf, "reading attribute" ); else if ( (ch==var->quote) || ( ch==CH_LF ) || ( (var->quote==VQ_NO_QUOTE) && ( inf_isws(ch,inpf) || ( ch=='>' ) ) ) ) { /* end of arg reached */ str_vararg = estr2str( vararg ); if ( var->quote == VQ_NO_QUOTE ) { if ( ch==CH_LF ) err_streol( inpf ); inungetc( ch, inpf ); } } else { /* append next char to vararg */ if ( !app_estrch( vararg, ch ) ) err_mem( inpf ); else end = FALSE; /* continue loop */ } } } if ( str_vararg && var ) /* ** check enum type */ if (var->vartype == VT_ENUM) check_enumstr( var, str_vararg, inpf ); /* ** parse uri (only if no macro-attr) ** (convert abs.uris, check existence) */ else if (var->vartype == VT_URI ) if ( !(var->varflag & VF_MACRO) ) str_vararg = parse_uri( str_vararg, inpf ); else { DDA( fprintf( stderr, "** didn't parse uri \"%s\"\n", str_vararg ) ); } /* update and enable log */ if ( !fatal_error ) { BOOL ok = TRUE; if ( var->quote != VQ_NO_QUOTE ) ok &= inflog_app( inpf, ch2str( var->quote ) );/* append quote */ inflog_app( inpf, str_vararg ); /* append arg */ if ( var->quote != VQ_NO_QUOTE ) ok &= inflog_app( inpf, ch2str( var->quote ) );/* append quote */ inflog_enable( inpf ); /* enable log */ if ( !ok ) err_mem( NULL ); } return ( str_vararg ); }