示例#1
0
/* 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);
}
示例#2
0
/*
** handle_macro
**
** handle for macro: add local attributes to global attributes,
** include macro text, remove local attributes
**
** params: open_mac..TRUE, if called by an opening macro
**         inpf......input file
*/
BOOL handle_macro( BOOL open_mac, INFILE *inpf, HSCTAG *macro )
{
    BOOL    ok = FALSE;
    EXPSTR *text;       /* macro text */
    EXPSTR *fname;      /* pseudo-filename */
    DLLIST *args;
    ULONG   mci = get_mci();

    /* determine filename & args */
    args = macro->attr;
    if ( open_mac ) {
        text  = macro->op_text ;
    } else {
        text  = macro->cl_text ;
    }
    fname = init_estr( 0 );

    if ( fname ) {

        /* debugging message */
        DMC( {
            fprintf( stderr, "**-MACRO <" );
            if ( !open_mac )
                fprintf( stderr, "/" );
            fprintf( stderr, "%s> from %p\n", macro->name, text );
        } );

        /* create pseudo-filename */
        ok = set_estr( fname, "[macro " );
        ok &= app_estr( fname, macro->name );
        ok &= app_estr( fname, "]" );

    }
示例#3
0
文件: linit.c 项目: mbethke/hsc
/*
 * 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);
}
示例#4
0
文件: hscprc.c 项目: mbethke/hsc
/*
 * 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);
}
示例#5
0
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);
}
示例#6
0
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);
}
示例#7
0
文件: hscprc.c 项目: mbethke/hsc
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);
}
示例#8
0
/*
 * 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);
}
示例#9
0
/*
 * 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 RISCOS
    /* simply copy path */
    set_estr(dest, path);

#elif defined MSDOS /* dos1 */
#elif (defined NEXTSTEP) || (defined BEOS) || (defined UNIX)
    /* simply copy path */
    set_estr(dest, path);
#else
#error "system not supported: conv_path2uri"
#endif
}
示例#10
0
/*
 * set/define_dest_attribs, define_source_attribs
 *
 * set and define attributes for destiantion uri
 */
static VOID set_dest_attribs(HSCPRC * hp, STRPTR destpath, STRPTR destname)
{
    set_estr(fileattr_str, "<$define HSC.DOCUMENT.NAME:string/c=\"");
    if (destname)
        app_estr(fileattr_str, destname);
    app_estr(fileattr_str, "\">\n<$define HSC.DOCUMENT.PATH:string/c=\"");
    if (destname)
        app_estr(fileattr_str, destpath);
    app_estr(fileattr_str, "\">\n<$define HSC.DOCUMENT.URI:string/c=\"");
    if (destname)
        app_estr(fileattr_str, destpath);
    if (destname)
        app_estr(fileattr_str, destname);
    app_estr(fileattr_str, "\">\n");
}
示例#11
0
/*
 * 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
}
示例#12
0
/*
 * set_estrn
 *
 * set expstr with first n chars of string
 */
BOOL set_estrn(EXPSTR * es, CONSTRPTR s, size_t n)
{
    BOOL ok = FALSE;
    STRPTR s1 = NULL;
    size_t len = strlen(s);

    if (n > len)
        n = len;

    s1 = (STRPTR) umalloc(n + 1);
    if (s1) {

        memcpy(s1, s, n);
        s1[n] = 0;
        ok = set_estr(es, s1);
        ufree(s1);

    }
    return (ok);
}
示例#13
0
/*
 * 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);
}
示例#14
0
/*
 * hsc_parse_text
 */
BOOL hsc_parse_text(HSCPRC * hp)
{
    INFILE *inpf = hp->inpf;
    STRPTR nw = infgetcw(inpf);

    if (nw && hp->suppress_output)
        hp_enable_output(hp, "some text");

    if (nw)
    {                           /* do test below only if not end-of-file */
        /*
         * check unmatched ">"
         */
        if (!strcmp(nw, ">"))
        {
            BOOL rplc = hp->smart_ent;  /* TRUE, if ">" should be replaced */

            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 gt */
                message_rplc(hp, nw, "&gt;");
                nw = "&gt;";
            }
            else
            {
                hsc_message(hp, MSG_UNMA_GT, "unmatched %q", ">");
            }
        }
        /*
         * check for quote
         */
        else if (!strcmp(nw, "\""))
        {
            if (hp->rplc_quote)
            {
                /* replace quote */
                message_rplc(hp, nw, "&quot;");
                nw = "&quot;";
            }
        }
        /*
         * check for entities to replace
         */
        else
        {
            DLNODE *nd = NULL;  /* entity search result */

            if (hp->rplc_ent && (strlen(nw) == 1) && (nw[0] >= 127))
            {
                nd = find_dlnode(hp->defent->first, (APTR) nw, cmp_rplcent);

                if (nd)
                {
                    BOOL ok = TRUE;

                    /* copy replaced entity to buffer */
                    ok &= set_estr(hp->tmpstr, "&");
                    ok &= app_estr(hp->tmpstr, ((HSCENT *) nd->data)->name);
                    ok &= app_estr(hp->tmpstr, ";");

                    if (ok)
                    {
                        /* replace-message */
                        message_rplc(hp, nw, estr2str(hp->tmpstr));
                        nw = estr2str(hp->tmpstr);
                    }
                }
            }
            /*
             * check for "click here" syndrome
             */
            if (hp->inside_anchor && hp->click_here_str)
            {
                ULONG found = strenum(nw, hp->click_here_str, '|', STEN_NOCASE);
                if (found)
                {
                    hsc_message(hp, MSG_CLICK_HERE,
                                "%q-syndrome detected", "click here");
                }
            }

#if (defined MSDOS & (!defined HSC_PLEASE))
            /* replace certain keywords */
            if (!upstrcmp(nw, "Netscape"))
            {
                nw = "Nutscape";
            }
            else if (!upstrcmp(nw, "Microsoft"))
            {
                nw = "Mircosoft";
            }
            else if (!upstrcmp(nw, "Intel"))
            {
                nw = "Wintel";
            }
            /* to be continued.. */
#endif
        }
    }

    if (nw)
        hsc_output_text(hp, "", nw);    /* output word */

    return (BOOL) (!hp->fatal);
}
示例#15
0
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);
}
示例#16
0
/*
 * 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 "&lt;" and white spaces */
            message_rplc(hp, "<", "&lt;");
            hsc_output_text(hp, "", "&lt;");
        }
        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);
}
示例#17
0
/*
 * 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, "&", "&amp;");
            set_estr(amp_str, "&amp;");
        }
        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);
}
示例#18
0
/*
 * args_ok
 *
 * prepare args, check & parse user args, display error and
 * help message if neccessary
 *
 * result: TRUE, if all args ok
 */
BOOL args_ok(HSCPRC * hp, int argc, char *argv[])
{
    BOOL ok;                    /* return value */
    DLLIST *ignore_list = NULL; /* dummy */
    EXPSTR *destdir = init_estr(32);    /* destination dir */
    EXPSTR *rel_destdir = init_estr(32);        /* relative destination dir */
    EXPSTR *kack_name = init_estr(0);   /* temp. str for outfilename */
    struct arglist *hsc_args;   /* argument structure */

    arg_hp = hp;

    arg_mode_CB(DEFAULT_MODE_STR);

    /* create arg-table */
    hsc_args =
        prepare_args("HSC_ARGS",

    /* file args */
                     "FROM/M", &incfile,
                     "include- and input-file(s)",

                     "TO/K", &arg_outfname,
                     "output file (default: stdout)",

                     "PRJFILE/T/K", &prjfilename,
                     "project file (default: none)",

                     "PREFSFILE/T/K", &prefsfilename,
                     "syntax preferences (default: hsc.prefs)",

                     "MSGFILE=MF/T/K", &msgfilename,
                     "message file (default: stderr)",

                     "MSGFORMAT/T/K", &msg_format,
                     "how to display message",
    /* numeric */
                     "MAXERR/N/K", &max_error,
                     "max. number of errors (default: 20)",

                     "EXTENSION/T/K", &arg_extension,
                   "output-file-extension (default: " DEFAULT_EXTENSION ")",

                     "DEFINE=DEF/T/K/M", &define_list,
                     "define global attribute",

                     "IGNORE=IGN/N/K/M/$", arg_ignore_CB, &ignore_list,
                     "ignore message number",

                     "MODE/E/K/$", arg_mode_CB, MODE_ENUMSTR, &arg_mode,
                     "mode for syntax check (" MODE_ENUMSTR ")",

                     "QUOTESTYLE=QS/E/K", QMODE_ENUMSTR, &arg_quotemode,
                     "defines how quotes appear (" QMODE_ENUMSTR ")",
#if 0
                     "ENTITYSTYLE=ES/E/K", EMODE_ENUMSTR, &entmode,
                     "defines how special chars. appear (" EMODE_ENUMSTR ")",
    /* switches */
#endif
                     "COMPACT=CO/S", &arg_compact,
                     "strip useless LFs and white-spaces",

                     "GETSIZE/S", &arg_getsize,
                     "get width and height of images",

                     "MSGANSI/S", &msg_ansi,
                     "use ansi-sequences in messages",

                     "RPLCENT=RE/S", &arg_rplc_ent,
                     "replace special characters",

                     "RPLCQUOTE=RQ/S", &arg_rplc_quote,
                     "replace quotes in text by `&quot;'",

                     "SMARTENT=SA/S", &arg_smart_ent,
                     "replace special entities (`&<>\"')",

                     "JENS/S", &arg_jens,
                     "don't try this at home",
                     "STRIPCOMMENT=SC/S", &arg_strip_cmt,
                     "strip SGML-comments",

                     "STRIPEXTERNAL=SX/S", &arg_strip_ext,
                     "strip tags with external URIs",

                     "STRIPTAGS=ST/K", &arg_striptags,
                     "tags to be stripped",

                     "ICONBASE/T/K", &arg_iconbase,
                     "base-uri for icon-entities",

                     "STATUS/E/K/$", arg_status_CB,
                     STATUS_ENUM_STR, &disp_status,
                     "status message (" STATUS_ENUM_STR ")",

                     "-DEBUG/S", &arg_debug, "enable debugging output",
    /* help */
                     "HELP=?/S", &arg_help, "display this text",
                     "LICENSE/S", &arg_license, "display license",

                     NULL);

    /* remove dummy list TODO: this sucks */
    del_dllist(ignore_list);

    ok = (hsc_args != NULL);

    /* set & test args */
    if (ok)
    {
        BOOL use_stdout = FALSE;        /* flag: use stdout as output-file */

        ok = set_args(argc, argv, hsc_args);

        /* display help, if requested vie HELP switch, or no
         * input to pipe or read is passed */
        ok &= (!arg_help &&
               (arg_pipe_in || (incfile && dll_first(incfile))));

        if (arg_license)
        {
            /* display license text */
            fprintf_prginfo(stderr);
            show_license();
            set_return_code(RC_WARN);
        }
        else if (!ok)
        {
            /* display help, if error in args or HELP-switch set */
            fprintf_prginfo(stderr);
            fprintf_arghelp(stderr, hsc_args);
            set_return_code(RC_WARN);
        }
        else
        {
            BOOL fnsux = FALSE; /* flag: TRUE = can't evaluate out-filename */

            /* set debugging switch */
            hsc_set_debug(hp, arg_debug);

            /* autoset depending options */
            if (hsc_get_debug(hp))
                disp_status = STATUS_VERBOSE;

            /* set default options */
            if (!arg_extension)
                arg_extension = DEFAULT_EXTENSION;

            /* disable ID-warning if no project-file */
            if (!prjfilename)
                hsc_set_msg_ignore(hp, MSG_NO_DOCENTRY, TRUE);

            /* compute name of input file */
            arg_inpfname = NULL;
            if (dll_first(incfile) && !arg_pipe_in)
            {
                /* use last FROM as input file */
                arg_inpfname = dln_data(dll_last(incfile));

                set_estr(inpfilename, arg_inpfname);

                /* get path part of inputfilename as relative
                 * destination directory */
                get_fpath(rel_destdir, arg_inpfname);

                /* TODO: set reldir when including first file */
                /* TODO: find out why the above TODO is there */

                /* remove input filename from incfile */
                del_dlnode(incfile, dll_last(incfile));

                D(fprintf(stderr, DHSC "input : use `%s'\n"
                          DHSC "reldir: use `%s'\n",
                          estr2str(inpfilename), estr2str(rel_destdir)));
            }

            /* display include files */
            D(
                 {
                 DLNODE * nd = dll_first(incfile);

                 while (nd)
                 {
                 fprintf(stderr, DHSC "includ: use `%s'\n", (
                                                      STRPTR) dln_data(nd));
                 nd = dln_next(nd);
                 }
                 }
            );

            /*
             * if no output-filename given,
             * outfilename stays NULL. this let open_output
             * open stdout as output-file
             */
            if (arg_outfname)
            {
                /* check, if last char of outputfilename is a
                 * directory separator; if so, use the filename
                 * as destination directory
                 */
                if (arg_outfname)
                {
                    UBYTE lastch = 0;

                    /* get last char of outfname to determine
                     * if it's a directory
                     */
                    if (strlen(arg_outfname))
                        lastch = arg_outfname[strlen(arg_outfname) - 1];

#ifdef AMIGA
                    /* for Amiga, execpt empty string for current dir */
                    if (!lastch)
                    {
                        lastch = (PATH_SEPARATOR[0]);
                        D(fprintf(stderr, DHSC "AMIGA: use current dir\n"));
                    }
#endif

                    if (strchr(PATH_SEPARATOR, lastch))
                    {
                        /* use outfilename as destdir */
                        set_estr(destdir, arg_outfname);
                        arg_outfname = NULL;
                        D(fprintf(stderr, DHSC "output: use `%s' as destdir\n",
                                  estr2str(destdir)));
                    }
                    else if (arg_inpfname)
                    {
                        /* output-filename already specified */
                        /* separate it to destdir + reldir + name */
                        EXPSTR *kack_destdir = init_estr(0);
                        EXPSTR *kack_reldir = init_estr(0);
                        STRPTR inp_reldir = estr2str(rel_destdir);
                        STRPTR out_reldir = NULL;
                        STRPTR ou2_reldir = NULL;

                        get_fname(kack_name, arg_outfname);
                        get_fpath(kack_destdir, arg_outfname);

                        /* check corresponding dirs for
                         * consistency: check if last strlen(rel_destdir)
                         * chars are equal */
                        out_reldir = estr2str(kack_destdir);
                        ou2_reldir = out_reldir;
                        out_reldir = out_reldir
                            + (strlen(out_reldir) - strlen(inp_reldir));

                        if (out_reldir[0])
                        {
                            /* search for next dir-sparator backwards */
                            /* (this ones only needed for a smart error message) */
                            while ((out_reldir != ou2_reldir)
                                 && (!strchr(PATH_SEPARATOR, out_reldir[0]))
                                )
                            {
                                out_reldir--;
                            }
                            out_reldir++;
                        }
                        D(fprintf(stderr, DHSC "corr_inp: `%s'\n"
                                  DHSC "corr_out: `%s'\n",
                                  inp_reldir, out_reldir)
                            );

                        /* check if correspondig relative in/out-dirs
                         * are equal */
                        if (!fnamecmp(inp_reldir, out_reldir))
                        {
                            /* they match.. */
                            STRPTR tmp_name = NULL;     /* copy of kack_nam */

                            /* cut corresponding chars */
                            get_left_estr(kack_destdir, kack_destdir,
                                          estrlen(kack_destdir)
                                          - strlen(out_reldir));

                            set_estr(kack_reldir, inp_reldir);

                            D(fprintf(stderr, DHSC "kack_dst: `%s'\n"
                                      DHSC "kack_rel: `%s'\n"
                                      DHSC "kack_nam: `%s'\n",
                                      estr2str(kack_destdir),
                                      estr2str(kack_reldir),
                                      estr2str(kack_name))
                                );

                            /* just copy these values where they are
                             * expected to be */
                            estrcpy(destdir, kack_destdir);
                            estrcpy(rel_destdir, kack_reldir);

                            /* create output filename */
                            tmp_name = strclone(estr2str(kack_name));
                            estrcpy(kack_name, kack_destdir);
                            estrcat(kack_name, kack_reldir);
                            app_estr(kack_name, tmp_name);
                            ufreestr(tmp_name);

                            arg_outfname = estr2str(kack_name);
                        }
                        else
                        {
                            /* unmatched corresponding dirs */
                            fprintf(stderr, "unmatched corresponding relative directories:\n"
                                    "  input  `%s'\n  output `%s'\n",
                                    inp_reldir, out_reldir);
                            ok = FALSE;
                        }

                        /* free temp. vars */
                        del_estr(kack_reldir);
                        del_estr(kack_destdir);
                    }
                }
                if (arg_outfname)
                {
                    /* set outputfilename with value passed iwithin args */
                    outfilename = init_estr(32);
                    set_estr(outfilename, arg_outfname);
                    D(fprintf(stderr, DHSC "output: set to `%s'\n",
                              estr2str(outfilename)));
                }
                else
                {
                    if (!arg_pipe_in)
                    {
                        /* no outfilename given */
                        /* ->outfilename = destdir + inpfilename + ".html" */

                        /* link destdir & input filename */
                        outfilename = init_estr(32);
                        link_fname(outfilename, estr2str(destdir),
                                   arg_inpfname);
                        if (strcmp(arg_extension, "."))
                            set_fext(outfilename, arg_extension);
                        D(fprintf(stderr,
                              DHSC "output: concat destdir+inpfile+`.%s'\n"
                                  DHSC "output: set to `%s'\n",
                                  arg_extension, estr2str(outfilename)));
                    }
                    else
                        fnsux = TRUE;
                }

                if (fnsux)
                {
                    /* no way to find out output filename */
                    status_error("unable to evaluate output filename\n");
                    arg_outfname = NULL;
                    ok = FALSE;
                }
            }
            else
            {
                D(fprintf(stderr, DHSC "output: use stdout\n"));
                use_stdout = TRUE;
            }

            if (!ok)
                set_return_code(RC_ERROR);

        }

        if (ok)
        {
            if (arg_iconbase)
                hsc_set_iconbase(hp, arg_iconbase);
            if (!use_stdout)
                hsc_set_filename_document(hp, estr2str(outfilename));
        }
        /* display argument error message */
        if (!ok)
        {
            /* NOTE: no strclone() is used on outfilename, if an
             * error already occured within set_args(). therefore,
             * you must not call ufreestr( outfilename ) */
            pargerr();
            arg_outfname = NULL;
            set_return_code(RC_ERROR);
        }
        else
        {
            EXPSTR *tmp_fname = init_estr(32);  /* filename only part */

            fileattr_str = init_estr(64);

            if (outfilename)
                get_fname(tmp_fname, estr2str(outfilename));
            set_dest_attribs(hp, estr2str(rel_destdir),
                             estr2str(tmp_fname));
            if (!arg_pipe_in)
            {
                if (outfilename)
                    get_fname(tmp_fname, estr2str(outfilename));
                else
                    clr_estr(tmp_fname);
                set_source_attribs(hp, estr2str(rel_destdir),
                                   estr2str(tmp_fname));
            }
            else
                set_source_attribs(hp, NULL, NULL);

            D(
                 {
                 HSCMSG_ID i;

                 fprintf(stderr, "\n"
                         DHSC "input : `%s'\n", estr2str(inpfilename));
                 fprintf(stderr, DHSC "output: `%s'\n", get_outfilename());
                 fprintf(stderr, DHSC "destdr: `%s'\n", estr2str(destdir));
                fprintf(stderr, DHSC "reldst: `%s'\n", estr2str(rel_destdir));
                 if (prjfilename)
                 fprintf(stderr, DHSC "projct: `%s'\n", prjfilename);
                 if (!use_stdout)
                fprintf(stderr, DHSC "procss: `%s'\n", estr2str(outfilename));
                 fprintf(stderr, DHSC "ignore:");
                 for (i = 0; i < MAX_MSGID; i++)
                 if (hsc_get_msg_ignore(hp, i))
                 fprintf(stderr, " %lu", i);
                 fprintf(stderr, "\n");
                 }
            );

            del_estr(tmp_fname);
        }
示例#19
0
/*
 * 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));
}
示例#20
0
/*
 * convert uri to filename in destination-dir
 */
static VOID conv_hscuri2fileNuri(HSCPRC * hp, EXPSTR * dest_uri, EXPSTR * dest_fname, STRPTR uri)
{
    EXPSTR *rel_path = init_estr(32);   /* relative path */
    URIKIND kind = uri_kind(uri);

    clr_estr(dest_uri);
    clr_estr(dest_fname);

    if  (kind == URI_relserv)
    {
        /* skip "/" in URI */
        STRPTR uri2 = uri + 1;

        /* debug */
        D(fprintf(stderr, DHL "exists `%s' [relserv]\n", uri));

        /* convert server relative URI to local filename
         * by preceding server_dir */
        conv_uri2path(rel_path, uri2, hp->weenix);
        estrcpy(dest_fname, hp->server_dir);
        estrcat(dest_fname, rel_path);

        /* debug */
        D(fprintf(stderr, DHL "  server-dir=`%s'\n", estr2str(hp->server_dir)));
        D(fprintf(stderr, DHL "  rel. path =`%s'\n", estr2str(rel_path)));

        /* keep URI untouched */
        set_estr(dest_uri, uri);
    }
    else
    {
        /* convert relative/project uris */

        /* if a <BASE HREF="..."> was found before,
         * treat all relative URIs as absolute
         */
        if (hp->docbase_set)
        {
            kind = URI_ext;
        }

        /* evaluate kind of URI */
        if (kind == URI_abs)
        {
            uri++;                  /* skip ":" */
        }

        if (kind == URI_abs)
        {
            /*
             * parse absolute uri
             */
            D(fprintf(stderr, DHL "exists `%s' [abs]\n", uri));

            /* check if local uri exists */
            {
                EXPSTR *dest_relfname = init_estr(32);
                conv_uri2path(dest_relfname, uri, hp->weenix);

                estrcpy(dest_fname, hp->destdir);
                estrcat(dest_fname, dest_relfname);

                del_estr(dest_relfname);
            }

            D(fprintf(stderr, DHL "  -> file `%s'\n",
                      estr2str(dest_fname)));

            /* create path of destination file */
            estrcpy(dest_uri, hp->reldir);
            app_estr(dest_uri, uri);

            get_relfname(rel_path, uri, estr2str(hp->reldir));
            D(fprintf(stderr, DHL "  -> rel. path `%s' (`%s')\n",
                      estr2str(rel_path),
                      estr2str(hp->reldir)));

            /* debug */
            D(fprintf(stderr, DHL "  -> real path `%s'\n", uri));

            /* convert (filesystem depending) path to uri */
            conv_path2uri(dest_uri, estr2str(rel_path));
        }
        else if (kind == URI_rel)
        {
            /*
             * parse relative uri
             */
            EXPSTR *uri_path = init_estr(32);

            /* debug */
            D(fprintf(stderr, DHL "exists `%s' [rel]\n", uri));

            /* create local filename */
            conv_uri2path(uri_path, uri, hp->weenix);
            estrcat(dest_fname, hp->destdir);
            estrcat(dest_fname, hp->reldir);
            estrcat(dest_fname, uri_path);

            /* create uri (only copy path) */
            set_estr(dest_uri, uri);

            del_estr(uri_path);
        }
        else
        {
            set_estr(dest_uri, uri);
            set_estr(dest_fname, "");
        }
    }

    /* debug */
    D(
         {
         fprintf(stderr, DHL "  -> real file `%s'\n",
                 estr2str(dest_fname));
         fprintf(stderr, DHL "  -> real uri  `%s'\n",
                 estr2str(dest_uri));
         }
    );
示例#21
0
BOOL skip_until_tag(HSCPRC * hp, EXPSTR * tagfound, STRPTR tagstoplist, STRPTR tagnest)
{
    UBYTE state = STATE_TEXT;   /* */
    INFILE *inpf = hp->inpf;    /* input file */
    LONG nesting = 0;           /* tag-nesting */
    LONG nesting_comment = 0;   /* comment-nesting */
    STRPTR nw = NULL;
    BOOL quit = FALSE;          /* flag: exit from skipping */
    EXPSTR *ungetstr = init_estr(32);

    clr_estr(tagfound);

    do
    {
        /* get next word or tag-id */
        if (state != STATE_TAG)
            nw = infgetw(inpf);
        else
        {
            nw = infget_tagid(hp);
            if (nw)
            {
                app_estr(ungetstr, infgetcws(inpf));
                app_estr(ungetstr, infgetcw(inpf));
                if (strcmp(nw, "/"))
                {
                    DS(fprintf(stderr, DHLS "start-tag <%s>\n", nw));
                    state = STATE_TAGNAME;      /* tag detected */
                }
                else
                {
                    nw = infget_tagid(hp);
                    DS(fprintf(stderr, DHLS "end-tag </%s>\n", nw));
                    app_estr(ungetstr, infgetcws(inpf));
                    app_estr(ungetstr, infgetcw(inpf));
                    state = STATE_ENDTAGNAME;   /* end-tag detected */
                }
            }
        }

        if (nw)
        {
            switch (state)
            {

                /* check if tag starts */
            case STATE_TEXT:
                if (!strcmp(nw, "<"))
                {
                    DS(fprintf(stderr, DHLS "tag\n"));
                    set_estr(ungetstr, nw);
                    state = STATE_TAG;
                }
                break;

                /* check which tag it is and how to act */
            case STATE_TAGNAME:
                {
                    /* check, if nesting-tag should be incr. */
                    if (!upstrcmp(nw, tagnest))
                    {
                        DS(fprintf(stderr, DHLS "nest-tag (%ld)\n", nesting));
                        state = STATE_TAGATTR;
                        nesting++;
                    }
                    /* check, if stop-tag reached */
                    else if (!nesting
                             && strenum(nw, tagstoplist, '|', STEN_NOCASE))
                    {
                        DS(fprintf(stderr, DHLS "stop-tag `%s'\n", nw));
                        set_estr(tagfound, nw);
                        quit = TRUE;
                    }
                    /* check, if commant-tag reached */
                    else if (!strcmp(nw, HSC_COMMENT_STR))
                    {
                        DS(fprintf(stderr, DHLS "comment-tag (0)\n"));
                        state = STATE_COMMENT;
                    }
                    /* any tag; just skip attributes */
                    else
                    {
                        DS(fprintf(stderr, DHLS "any tag\n"));
                        state = STATE_TAGATTR;
                    }
                    break;
                }

            case STATE_ENDTAGNAME:
                {
                    if (!upstrcmp(nw, tagnest))
                    {
                        if (nesting)
                        {
                            nesting--;
                            DS(fprintf(stderr, DHLS "nest-tag (%ld)\n", nesting));
                        }
                        else
                        {
                            DS(fprintf(stderr, DHLS "nest-tag ending\n"));
                            quit = TRUE;
                        }
                    }
                    else
                        state = STATE_TEXT;     /* no attr for endtag */

                    break;
                }

                /*
                 * process tag attributes
                 */
            case STATE_TAGATTR:
                {
                    if (!strcmp(nw, "="))
                        state = STATE_TAGATTR_EQ;
                    else if (!strcmp(nw, ">"))
                    {
                        DS(fprintf(stderr, DHLS "back to text\n"));
                        state = STATE_TEXT;
                    }
                    break;
                }

            case STATE_TAGATTR_EQ:
                {
                    if (!strcmp(nw, "\""))
                    {
                        DS(fprintf(stderr, DHLS "tagarg (double quote)\n"));
                        state = STATE_TAGATTR_DQUOTE;
                    }
                    else if (!strcmp(nw, "'"))
                    {
                        DS(fprintf(stderr, DHLS "tagarg (single quote)\n"));
                        state = STATE_TAGATTR_SQUOTE;
                    }
                    else
                        state = STATE_TAGATTR;
                    break;
                }

            case STATE_TAGATTR_DQUOTE:
                {
                    if (!strcmp(nw, "\""))
                    {
                        DS(fprintf(stderr, DHLS "end tagarg (double quote)\n"));
                        state = STATE_TAGATTR;
                    }
                    break;
                }

            case STATE_TAGATTR_SQUOTE:
                {
                    if (!strcmp(nw, "'"))
                    {
                        DS(fprintf(stderr, DHLS "end tagarg (single quote)\n"));
                        state = STATE_TAGATTR;
                    }
                    break;
                }

                /*
                 * comment processing
                 */
            case STATE_COMMENT:
                {
                    /* check for <" */
                    if (!strcmp(nw, "<"))
                        state = STATE_COMMENT_TAG;
                    else if (!strcmp(nw, HSC_COMMENT_STR))
                        state = STATE_COMMENT_STAR;
                    break;
                }

            case STATE_COMMENT_TAG:
                {
                    /* check for comment-nesting */
                    if (!strcmp(nw, HSC_COMMENT_STR))
                    {
                        nesting_comment++;
                        DS(fprintf(stderr, DHLS "comment-tag (%ld)\n", nesting_comment));
                        state = STATE_COMMENT;
                    }
                    else
                        state = STATE_COMMENT;

                    break;
                }

            case STATE_COMMENT_STAR:
                {
                    /* check for end comment */
                    if (!strcmp(nw, ">"))
                        if (nesting_comment)
                        {
                            nesting_comment--;
                            DS(fprintf(stderr, DHLS "end comment-tag (%ld)\n", nesting_comment));
                            state = STATE_COMMENT;
                        }
                        else
                        {
                            DS(fprintf(stderr, DHLS "end comment-tag (%ld)\n", nesting_comment));
                            state = STATE_TEXT;
                        }
                    else
                        state = STATE_COMMENT;
                    break;
                }

                /*
                 * unhandled tag
                 */
            default:
                panic("unhandled state");
                break;
            }
        }
    }
    while (nw && !quit && !(hp->fatal));

    if (nw)
    {
        inungets(estr2str(ungetstr), inpf);
    }
    else
    {
        EXPSTR *tagstr = init_estr(0);

        set_estr(tagstr, "</");
        app_estr(tagstr, tagnest);
        app_estr(tagstr, "> expected");
        hsc_msg_eof(hp, estr2str(tagstr));

        del_estr(tagstr);
    }

    del_estr(ungetstr);

    return ((BOOL) (nw != NULL));
}
示例#22
0
/*
** clr_estr
**
** clear expstr (set es_data to "")
*/
BOOL clr_estr( EXPSTR *es )
{
    return( set_estr( es, "" ) );
}
示例#23
0
/*
**-------------------------------------
** <$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 );
}
示例#24
0
/*
 * convert uri to filename in destination-dir
 */
static VOID conv_hscuri2fileNuri(HSCPRC * hp, EXPSTR * dest_uri, EXPSTR * dest_fname, STRPTR uri)
{
    EXPSTR *rel_path = init_estr(32);   /* relative path */
    URIKIND kind = uri_kind(uri);

    clr_estr(dest_uri);
    clr_estr(dest_fname);

    /* if a <BASE HREF=".."> was found before,
     * therefor treat URI as absolute
     */
    if (hp->docbase_set)
        kind = URI_ext;

    /* evaluate kind of URI */
    if (kind == URI_abs)
        uri++;                  /* skip ":" */

    /* reset destination filename */
    set_estr(dest_fname, "");

    if (kind == URI_abs)
    {
        /*
         * parse absolute uri
         */
        D(fprintf(stderr, DHL "exists `%s' [abs]\n", uri));

        /* check if local uri exists */
        {
            EXPSTR *dest_relfname = init_estr(32);
            conv_uri2path(dest_relfname, uri);

            estrcpy(dest_fname, hp->destdir);
            estrcat(dest_fname, dest_relfname);

            del_estr(dest_relfname);
        }

        D(fprintf(stderr, DHL "  -> file `%s'\n",
                  estr2str(dest_fname)));

        /* create path of destination file */
        estrcpy(dest_uri, hp->reldir);
        app_estr(dest_uri, uri);

        get_relfname(rel_path, uri, estr2str(hp->reldir));
        D(fprintf(stderr, DHL "  -> rel. path `%s' (`%s')\n",
                  estr2str(rel_path),
                  estr2str(hp->reldir)));

        /* debug */
        D(fprintf(stderr, DHL "  -> real path `%s'\n", uri));

        /* convert (filesystem depending) path to uri */
        conv_path2uri(dest_uri, estr2str(rel_path));

        /* debug */
        D(fprintf(stderr, DHL "  -> real uri  `%s'\n",
                  estr2str(dest_uri)));
    }
    else if (kind == URI_rel)
    {
        /*
         * parse relative uri
         */
        EXPSTR *uri_path = init_estr(32);

        /* debug */
        D(fprintf(stderr, DHL "exists `%s' [rel]\n", uri));

        /* create local filename */
        conv_uri2path(uri_path, uri);
        estrcat(dest_fname, hp->destdir);
        estrcat(dest_fname, hp->reldir);
        estrcat(dest_fname, uri_path);

        /* create uri (only copy path) */
        set_estr(dest_uri, uri);

        /* debug */
        D(
             {
             fprintf(stderr, DHL "  -> real path `%s'\n",
                     estr2str(dest_fname));
             fprintf(stderr, DHL "  -> real uri  `%s'\n",
                     estr2str(dest_uri));
             }
        );
示例#25
0
BOOL estrcpy( EXPSTR *dest, EXPSTR *src )
{
    return( set_estr( dest, estr2str( src ) ) );
}
示例#26
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 );
}