/* ** 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); }
/* 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); }
/* * get_mid_estr * * get a part from a expstr; compare BASIC's "MID$()" * * params: dest...destination expstr where to store result part * src....source expstr where to get part from * from...position of char where to begin part (0=first char) * num....number of chars to get * result: TRUE and result in dest if ok; else FALSE is returned an * dest is left untouched * * NOTE: it is possible to use the source-exstr as destination-expstr, * because the result is copied to a temp. expstr before * ( example: get_mid_estr( hugo, hugo, 3, 4 ); ) */ BOOL get_mid_estr(EXPSTR * dest, EXPSTR * src, size_t from, size_t num) { BOOL ok = FALSE; EXPSTR *tmp = init_estr(dest->es_step); if (tmp) { STRPTR old_data = tmp->es_data; /* check size */ if (from >= src->es_len) from = src->es_len - 1; if (from + num >= src->es_len) num = src->es_len - from - 1; /* set new mem for tmp */ ok = set_estr_mem(tmp, modadj(num + 1, tmp->es_step)); if (ok) { /* copy data */ strncpy(estr2str(tmp), estr2str(src) + from, num); tmp->es_data[num] = 0; tmp->es_len = num + 1; ufree(old_data); ok = estrcpy(dest, tmp); } del_estr(tmp); } 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) ); }
/* * read_macro_text */ static BOOL read_macro_text(HSCPRC * hp, HSCTAG * macro, BOOL is_start_macro) { BOOL ok = FALSE; EXPSTR *macstr = NULL; /* skip first LF if any */ skip_next_lf(hp); /* init an EXPSTR for macro text, * remember location of macro-def (for messages) */ if (is_start_macro) { macro->op_text = init_estr(ES_STEP_MACRO); macstr = macro->op_text; macro->start_fpos = new_winfilepos(hp->inpf); } else { macro->cl_text = init_estr(ES_STEP_MACRO); macstr = macro->cl_text; macro->end_fpos = new_winfilepos(hp->inpf); } /* read macro text */ ok = skip_until_tag(hp, macstr, NULL, NULL, HSC_MACRO_STR, SKUT_NO_CONTENT_TAGFOUND); /* if last char of macrotext is LF, CR or CR/LF, remove it */ if (ok) { STRPTR ms = estr2str(macstr); size_t len = strlen(ms); size_t oldlen = len; /* NOTE: this is a bit ugly, it would be nicer to * call leftstr() here and strip last ch, but this * a lot faster */ if (len && (ms[len - 1] == '\n')) { ms[len - 1] = '\0'; len = strlen(ms); } if (len && (ms[len - 1] == '\r')) { ms[len - 1] = '\0'; len = strlen(ms); } if (oldlen != len) { DMC(fprintf(stderr, DHL " stripped cr/lf at end\n")); } DMC(fprintf(stderr, DHL "Macro text: \"%s\"\n", estr2str(macstr))); } return (ok); }
/* * set values */ BOOL hsc_set_destdir(HSCPRC * hp, STRPTR dir) { set_estr(hp->destdir, dir); /* append "/" if neccessary */ link_fname(hp->destdir, estr2str(hp->destdir), ""); D(fprintf(stderr, DHL "destdir=`%s'\n", estr2str(hp->destdir))); return (TRUE); }
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); }
/* set_file_attribs */ static VOID define_file_attribs(HSCPRC * hp) { hsc_include_string(hp, "[define destattr]", estr2str(fileattr_str), IH_PARSE_HSC | IH_NO_STATUS); D(fprintf(stderr, DHSC "destination attributes defines:\n%s", estr2str(fileattr_str)) ); }
/* * find_prefs_fname * * find preferences file: first check, if it is located * somewhere in the paths given via CONFIG_PATH (which * is a system depandent symbol); if not, check if it * is in the path described in the envvar HSCPREFS * * result: full path & filename of prefs or NULL if not found * */ static STRPTR find_prefs_fname(HSCPRC * hp, EXPSTR *cfgfn) { #define ENV_HOME "HOME" STRPTR prefs_fname = NULL; STRPTR paths[] = /* paths to search for config file */ {"", "", "", CONFIG_PATH, NULL, NULL}; STRPTR path = NULL; UBYTE path_ctr = 0; FILE *cfgf = NULL; /* prefs file */ EXPSTR *hscpathstr = init_estr(32); /* buffer to read $HSCPATH */ EXPSTR *homepathstr = init_estr(32); /* buffer to read $HOME */ /* add "$HSCPATH/hsc.prefs" to files-to-be-checked */ if (link_envfname(hscpathstr, ENV_HSCPATH, NULL, NULL)) { /* add envval to paths */ paths[1] = estr2str(hscpathstr); } /* add "$HOME/lib/hsc.prefs" to files-to-be-checked */ if (link_envfname(homepathstr, ENV_HOME, "lib", NULL)) { /* add envval to paths */ paths[2] = estr2str(homepathstr); } /* try to open any prefs-file */ do { /* loop: */ path = paths[path_ctr]; /* get next path */ if (path) { /* is it the last one? */ set_estr(cfgfn, path); /* N->generate filename */ app_estr(cfgfn, CONFIG_FILE); DC(fprintf(stderr, DHL "try \"%s\"\n", estr2str(cfgfn))); cfgf = fopen(estr2str(cfgfn), "r"); /* try to open file */ } path_ctr++; /* process next path */ } while (path && (!cfgf)); /* until no path left or file opened */ if (cfgf) { prefs_fname = estr2str(cfgfn); fclose(cfgf); } del_estr(homepathstr); del_estr(hscpathstr); return (prefs_fname); }
/* * output text function * * output text to host process * * params: hp....hsc process to perform ouput with * wspc..white spaces * text..other text * result: true, if text has been outputted */ BOOL hsc_output_text(HSCPRC * hp, STRPTR wspc, STRPTR text) { BOOL written = FALSE; if ((hp)->CB_text && !((hp)->suppress_output)) { /* add current white spaces to white space * buffer; if hp->compact is enabled, reduce * white spaces */ if (wspc) app_estr(hp->whtspc, wspc); if (hp->compact && (!hp->inside_pre)) /* reduce white spaces */ wspc = compactWs(hp, estr2str(hp->whtspc)); else wspc = estr2str(hp->whtspc); /* strip white spaces if requested */ if (hp->strip_next_whtspc) { D(fprintf(stderr, DHL "bad white spaces stripped\n")); hp->strip_next_whtspc = FALSE; wspc = ""; } else if (hp->strip_next2_whtspc) { hp->strip_next2_whtspc = FALSE; hp->strip_next_whtspc = TRUE; } else if ((hp->tag_next_whtspc) && strlen(wspc)) { hsc_message(hp, MSG_SUCC_WHTSPC, "succeeding white-space for %T", hp->tag_next_whtspc); } hp->tag_next_whtspc = NULL; #if DEBUG_HSCLIB_OUTPUT if (hp->debug) if (text) if (strcmp(text, "\n")) fprintf(stderr, DHL "ouput: `%s', `%s'\n", wspc, text); else fprintf(stderr, DHL "ouput: `%s', `\\n'\n", wspc); #endif if ((wspc && wspc[0]) || (text && text[0])) { /* convert NULL values to empty strings */ if (!wspc) wspc = ""; if (!text) text = ""; /* output text */ (*((hp)->CB_text)) ((hp), wspc, text); written = TRUE; } /* reset white space buffer */ clr_estr(hp->whtspc); } return (written); }
/* is_pop: remove first value of the if-stack */ BOOL is_pop( VOID ) { BOOL value = is_get(); if ( !strlen(estr2str(IF_stack)) ) DIF( panic( "Popping empty IF_stack" ) ); if ( !get_left_estr( IF_stack, IF_stack, strlen(estr2str(IF_stack))-1 ) ) err_mem( NULL ); DIF( fprintf( stderr, "** pop IF-stack: \"%s\"\n", estr2str( IF_stack ) ) ); return( value ); }
/* * 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); }
/* * hsc_read_prefs * * try to open (any) config file and read preferences * from it */ static BOOL hsc_read_prefs(HSCPRC * hp, STRPTR prefs_fname) { BOOL ok = FALSE; EXPSTR *prefs_name_buffer = init_estr(32); /* find prefs file */ if (!prefs_fname) prefs_fname = find_prefs_fname(hp, prefs_name_buffer); /* status message */ if (prefs_fname) { dbg_disable(hp); hsc_status_file_begin(hp, prefs_fname); ok = hsc_include_file(hp, prefs_fname, IH_PARSE_HSC | IH_NO_STATUS); dbg_restore(hp); if (ok) { EXPSTR *msg = init_estr(32); set_estr(msg, prefs_fname); app_estr(msg, ": preferences read"); hsc_status_misc(hp, estr2str(msg)); del_estr(msg); } } else hsc_message(hp, MSG_NO_CONFIG, "can not open preferences file"); del_estr(prefs_name_buffer); return (ok); }
/* ** get_outfilename ** ** return output filename or `<stdout>' */ STRPTR get_outfilename( VOID ) { if ( outfilename ) return( estr2str( outfilename ) ); else return( STDOUT_NAME ); }
/* is_get: get first value from the if-stack */ BOOL is_get( VOID ) { BOOL value = FALSE; if ( IF_stack ) { STRPTR stkstr = estr2str( IF_stack ); DIF( fprintf( stderr, "** get IF-stack: \"%s\"\n", stkstr ) ); if ( stkstr && (stkstr[0]) ) { char lastch = stkstr[strlen(stkstr)-1]; if ( lastch == ISTK_TRUE ) value = TRUE; else if ( lastch != ISTK_FALSE ) DIF( panic( "Illegal value on IF_stack" ) ); } else DIF( panic( "IF_stack EMPTY" ) ); } else DIF( panic( "IF_stack UNDEFINED" ) ); DIF( fprintf( stderr, "** get IF-stack: value=%d\n", value ) ); return( value ); }
static BOOL handle_macro(HSCPRC * hp, HSCTAG * macro, BOOL open_mac) { BOOL ok = TRUE; EXPSTR *text = NULL; /* macro text */ INFILEPOS *fpos = NULL; /* file position of macro text */ /* debugging message */ dbg_print_macro(hp, macro, open_mac, "BEGIN"); /* determine relative file position and macro text */ if (open_mac) { text = macro->op_text; fpos = macro->start_fpos; } else { text = macro->cl_text; fpos = macro->end_fpos; } /* include macro file */ ok = include_macro(hp, macro, estr2str(text), SPECIAL_FILE_ID "macro", fpos); /* debugging message */ dbg_print_macro(hp, macro, open_mac, "END"); return (FALSE); }
/* * define_attr_by_text * * define a new attribute with attribute definition passed as * string. The new attribute is assigned to the global attr-list * (by default, with a local scope) * * params: varname..name of new var * flag.....flags: VF_ONLYONCE to avoid re-definition of a var * result: ptr to new var * * NOTE: * The new attribute will be declared as if a corresponding * <$define> showed up in the source. It will be assigned to * the local scope; you will need to add a "/GLOBAL" to the * description text if you want to avoid this * * It's recommended not to setup a default value, if you are * not sure that it can't contain data that will cause error * messages to show up (like value=xy"zw'bl) * * definition syntax in input file: * <varname>":"<vartype>[/flag]["="<deftext value>] * * EXAMPLE: * define_attr_by_text(hp,"sepp:string/global='sepp'", 0) * * SEE ALSO: * define_var() */ HSCATTR *define_attr_by_text(HSCPRC * hp, STRPTR attr_text, STRPTR default_value, ULONG unmasked_flags) { /* NOTE: this functions works a bit strange */ EXPSTR *define_text = init_estr(0); INFILE *old_inpf = hp->inpf; HSCATTR *attr = NULL; /* create attribute definition */ set_estr(define_text, attr_text); app_estr(define_text, ">"); hp->inpf = infopen_str(PARENT_FILE_ID "define_attr_by_text", estr2str(define_text), 0); /* process attribute definition */ if (hp->inpf) { attr = define_attr_by_hp(hp, default_value, unmasked_flags); infclose(hp->inpf); } /* cleanup */ hp->inpf = old_inpf; del_estr(define_text); return (attr); }
BOOL hsc_set_iconbase(HSCPRC * hp, STRPTR uri) { set_estr(hp->iconbase, uri); D(fprintf(stderr, DHL "iconbase=`%s'\n", estr2str(hp->iconbase))); return (TRUE); }
/* is_empty: check if if-stack is empty */ BOOL is_empty( VOID ) { BOOL result = FALSE; if ( !strlen( estr2str( IF_stack ) ) ) result = TRUE; return( result ); }
/* * getfilesize * * get size of a specific file * * templates for HSC.FORMAT.FILESIZE: * %b size in byte * %k size in Kbyte * %m size in MByte * %g size in Gbyte * %a size, unit computed automatically * %u unit for %A (none, "K", "M" or "G") */ static STRPTR getfilesize(HSCPRC * hp, EXPSTR * dest, STRPTR uri) { STRPTR filesizestr = NULL; FILE *file = NULL; LONG filesize = 0; /* filesize in byte */ LONG filesize_k = 0; /* filesize in Kbyte */ LONG filesize_m = 0; /* filesize in Mbyte */ LONG filesize_g = 0; /* filesize in Gbyte */ LONG filesize_auto = 0; /* filesize in auto-units (%A) */ EXPSTR *efilename = init_estr(32); STRPTR filename = NULL; STRPTR sizeunit = ""; STRPTR s = get_vartext_byname(hp->defattr, FILESIZEFORMAT_ATTR); conv_hscuri2file(hp, efilename, uri); filename = estr2str(efilename); D(fprintf(stderr, DHL " GETFILESIZE(`%s')\n", filename)); errno = 0; file = fopen(filename, "rb"); if (file) { /* retrieve size */ fseek(file, 0L, SEEK_END); filesize = ftell(file); fclose(file); /* compute size in units, */ filesize_k = (filesize + 512) >> 10; filesize_m = (filesize_k + 512) >> 10; filesize_g = (filesize_m + 512) >> 10; /* compute auto-size */ if (filesize_g > 10) { filesize_auto = filesize_g; sizeunit = "G"; } else if (filesize_m > 10) { filesize_auto = filesize_m; sizeunit = "M"; } else if (filesize_k > 10) { filesize_auto = filesize_k; sizeunit = "K"; } else { filesize_auto = filesize; sizeunit = ""; } } else {
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); }
/* * find_includefile * * scan all include-directories for file to be opened; * if the file can't be found, the filename in the current * directory will be returned (which should therefor result * in an error while processing hsc_include()) * * NOTE: this function considers the file to be found if it could have * been opened for input. afterwards, the file is immediatly * closed. This isn't really a multitasking-conform behavior * because the file will have to be reopend again by the * hsc_include() function later and meanwhile could have been * removed by another task. */ static BOOL find_includefile(HSCPRC *hp, EXPSTR * dest, STRPTR filename) { BOOL found = FALSE; /* reset filename */ set_estr(dest, filename); if (!fexists(filename)) { DLNODE *nd = dll_first(hp->include_dirs); /* process all include-directories.. */ while (nd && !found) { /* concat incdir+filename, check if it exists, * process next or abort loop */ link_fname(dest, (STRPTR) dln_data(nd), filename); D(fprintf(stderr, DHL " try `%s'\n", estr2str(dest))); if (fexists(estr2str(dest))) { found = TRUE; } else nd = dln_next(nd); } } else { /* found in current directory */ found = TRUE; } if (found) { D(fprintf(stderr, DHL " found at `%s'\n", estr2str(dest))); } return (found); }
/* append all document-related data */ static VOID append_document(EXPSTR * prjstr, HSCDOC * document) { STRPTR docname = document->docname; append_docname(prjstr, docname); append_sourcename(prjstr, document->sourcename); append_title(prjstr, estr2str(document->title)); append_doc_iddefs(prjstr, document->iddefs); append_doc_includes(prjstr, document->includes); #if 0 append_doc_references(prjstr, document->references); #endif }
/* 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 ) ) ); }
/* hsc_include_file: include file without base-position */ BOOL hsc_include_file(HSCPRC * hp, STRPTR filename, ULONG optn) { BOOL ok = FALSE; EXPSTR *real_filename = init_estr(64); /* scan include directories */ find_includefile(hp, real_filename, filename); /* now include file */ ok = hsc_base_include_file(hp, estr2str(real_filename), optn, NULL); /* cleanup */ del_estr(real_filename); return ok; }
/* ** handle_hsc_exec ** ** exec a sub file */ BOOL handle_hsc_exec( INFILE *inpf, HSCTAG *tag ) { STRPTR cmd = get_vartext( tag->attr, "COMMAND" ); if ( cmd ) { int result; EXPSTR *msg = init_estr( 0 ); if ( msg && app_estr( msg, "execute: " ) && app_estr( msg, cmd ) ) { /* status message */ status_msg( estr2str( msg ) ); if ( verbose ) status_lf(); /* call command */ result = system( cmd ); /* check for non-zero-result */ if ( result ) { message( MSG_SYSTEM_RETURN, inpf ); errstr( "Calling external command returned " ); errstr( long2str( (LONG) result ) ); errlf(); } } else err_mem( inpf ); del_estr( msg ); } return (TRUE); }
/* * get_width_height * * tries to get values for WIDTH and HEIGHT attributes * from file * * result: TRUE, if filetype has been recognised */ BOOL get_attr_size(HSCPRC * hp, HSCTAG * tag) { #define BUFSIZE 2048 #define WIDTH_PNG 16 /* file indeces for PNG */ #define HEIGHT_PNG 20 HSCVAR *asrc = tag->uri_size; STRPTR srcuri = NULL; if (asrc) srcuri = get_vartext(asrc); else { panic("no uri_size"); } if (hp->getsize && srcuri && (uri_kind(srcuri) != URI_ext)) { STRARR buf[BUFSIZE]; EXPSTR *srcpath = init_estr(64); EXPSTR *imgpath = init_estr(64); ULONG width = 0; ULONG height = 0; BOOL transparent = FALSE; BOOL progressive = FALSE; STRPTR filetype = NULL; FILE *fref = NULL; /* file link references to */ STRARR id_PNG[8] = {137, 80, 78, 71, 13, 10, 26, 10}; /* PNG image header */ conv_hscuri2file(hp, srcpath, srcuri); DSZ(fprintf(stderr, DHL " uri : \"%s\"\n** path: \"%s\"\n", srcuri, estr2str(srcpath))); fref = fopen(estr2str(srcpath), "r"); if (fref) { /* fill buffer with zero */ memset(buf, 0, BUFSIZE); /* read buffer from file */ fread(buf, BUFSIZE, 1, fref); if (buf[0] == 0xff) { /* * JFIF/JPEG */ BOOL found = FALSE; size_t i = 0; /*TODO: progressive */ while (!found && (i < BUFSIZE + 8)) { if (buf[i] == 0xff) { BOOL is_msof = FALSE; int j = 0; DSZ(printf("%04x: %02x %02x: (%02x%02x %02x%02x) ", (ULONG) i, buf[i], buf[i + 1], buf[i + 2], buf[i + 3], buf[i + 4], buf[i + 5])); /* check if marker is of required type */ while (!is_msof && msof[j]) if (buf[i + 1] == msof[j]) is_msof = TRUE; else j++; if (is_msof) { DSZ( { for (j = 0; j < 10; j++) { printf("\n %-2d: $%02x %-3d", j, buf[i + j], buf[i + j]); if (buf[i + j] >= 32) printf(" '%c'", buf[i + j]); } } ); filetype = "JFIF/JPEG"; width = buf[i + 8] + (buf[i + 7] << 8); height = buf[i + 6] + (buf[i + 5] << 8); found = TRUE; } else { DDA(printf("ignore\n")); } }
/* * handle_content_macro * * handle for content macros * (with /CLOSE set at declaration) * * - scan macro content until corresponding end macro * tag is found * - increase scope * - define local HSC.CONTENT * - include macro text (not content!) * - remove HSC.CONTENT * */ static BOOL handle_content_macro(HSCPRC * hp, HSCTAG * tag) { EXPSTR *macro_content = init_estr(1024); /* contains macro contents */ HSCATTR *macro_content_attr = find_varname(hp->defattr, CONTENT_ATTR); /* attribute that contains contents, too */ HSCTAG *end_macro = NULL; STRPTR old_content = NULL; /* to store old value of content attr */ /* position where content starts */ INFILEPOS *start_content_fpos = new_infilepos(hp->inpf); DMC(fprintf(stderr, DHL "--BEGIN content macro <%s>\n", tag->name)); if (!macro_content_attr) { panic("no content attribute") } /* skip macro content until corresponding end macro is found; store * content in macro_content, but without the tag call for the end macro */ skip_until_tag(hp, macro_content, NULL, NULL, tag->name, SKUT_NO_CONTENT_TAGFOUND); /* store current value of content attribute */ { STRPTR old = get_vartext(macro_content_attr); if (old) { old_content = strclone(old); } } /* set content attribute with current macro content */ set_vartext(macro_content_attr, estr2str(macro_content)); /* push content to content stack */ add_strnode(hp->content_stack, estr2str(macro_content)); /* some debuggin info */ DMC(fprintf(stderr, DHL " content=`%s'\n", estr2str(macro_content))); DMC(fprintf(stderr, DHL " text =`%s'\n", estr2str(tag->op_text))); /* push current tag on container stack; this is * only necessary for tag modifiers /MCI and * /NAW, which would not work otherwise */ end_macro = append_end_tag(hp, tag); /* assign position of start of content to macro-tag */ end_macro->end_fpos = start_content_fpos; /* now include the macro text */ include_macro(hp, tag, estr2str(tag->op_text), SPECIAL_FILE_ID "content-macro", tag->start_fpos); /* pull macro tag from container stack */ end_macro->end_fpos = NULL; remove_end_tag(hp, tag); /* restore content attribute to previous value */ set_vartext(macro_content_attr, old_content); /* remove content from stack */ del_dlnode(hp->content_stack, dll_first(hp->content_stack)); /* cleanup */ ufreestr(old_content); del_estr(macro_content); del_infilepos(start_content_fpos); DMC(fprintf(stderr, DHL "--END content macro <%s>\n", tag->name)); return (FALSE); }
BOOL estrcat(EXPSTR * dest, EXPSTR * src) { return (app_estr(dest, estr2str(src))); }
BOOL estrcpy( EXPSTR *dest, EXPSTR *src ) { return( set_estr( dest, estr2str( src ) ) ); }