예제 #1
0
파일: posteval.c 프로젝트: mbethke/hsc
/*
 * postprocess_attributes
 *
 * This function scans a tag's list of attributes for URI-attributes
 * referring to an external URI. If it succeeds, and the hsc-process
 * has it's hp->strip_ext flag enabled, the function exits.
 *
 * Otherwise, it scans the attributes for new IDs and references
 * and updates the document data if neccessary (but only for start tags)
 *
 * params:
 *   hp ........ hsc-process
 *   tag ....... tag whose attribute list should be examined
 *   open_tag .. for end tags, the document-data should not be
 *               updated again
 * result:
 *   TRUE, if tag should NOT be stripped
 */
BOOL postprocess_tagattr(HSCPRC * hp, HSCTAG * tag, BOOL open_tag) {
    BOOL dontstrip = TRUE;

    if (tag->attr) {

        /*
         * find out, if list should be refused
         */
        if (hp->strip_ext
            && tag->uri_stripext
            && get_vartext(tag->uri_stripext)
            && (uri_kind(get_vartext(tag->uri_stripext)) == URI_ext)
            )
        {
            D(fprintf(stderr, DHL "strip external\n"));
            dontstrip = FALSE;
        } else if (open_tag) {
            /*
             * search for new IDs and references
             */
            DLNODE *nd = dll_first(tag->attr);
            while (nd) {
                HSCATTR *attrib = (HSCATTR *) dln_data(nd);
                STRPTR value = get_vartext(attrib);

                if (value) {
                    if (attrib->vartype == VT_URI) {
                        /* new reference */
                        INFILEPOS *fpos = new_infilepos(hp->inpf);
                        CALLER *newcaller = fpos2caller(fpos);
                        HSCREF *newref =
                        app_reference(hp->project->document, value);

                        newref->caller = newcaller;

                        del_infilepos(fpos);
                        D(fprintf(stderr, DHL "new REFERENCE: `%s'\n", value));

                    } else if (attrib->vartype == VT_ID) {
                        /* new id defined */
                        D(fprintf(stderr, DHL "new ID: `%s'\n", value));
                        add_local_iddef(hp, value);
                    }
                }
                nd = dln_next(nd);
            }
        }
    }
    return (dontstrip);
}
예제 #2
0
/*
 * add_local_iddef
 *
 * define a new local ID that can be refered to
 */
BOOL add_local_iddef(HSCPRC * hp, STRPTR id)
{
    INFILEPOS *fpos = new_infilepos(hp->inpf);
    HSCIDD *iddef = find_iddef(hp->project->document, id);

    DIHP(fprintf(stderr, DHL "add ref to id `%s' at `%s' (%lu,%lu)\n",
                 id, ifp_get_fname(fpos),
                 ifp_get_y(fpos), ifp_get_x(fpos)));

    /* check for duplicate definition */

    if (iddef)
    {
        /* duplicate definition */
        DIHP(fprintf(stderr, DHL "    duplicate definition\n"));

        hsc_message(hp, MSG_REDEFINE_ID,
                    "local id %q already declared", id);

        set_infilepos(hp->inpf, iddef->fpos);
        hsc_message(hp, MSG_REDEFINE_ID,
                    "(location of previous declaration)");

        set_infilepos(hp->inpf, fpos);
        del_infilepos(fpos);
    }
    else
    {
        /* remember new local id */
        iddef = app_iddef(hp->project->document, id);
        iddef->caller = fpos2caller(fpos);
        iddef->fpos = fpos;

        DIHP(fprintf(stderr, DHL "    append to local iddefs\n"));
    }

    return (TRUE);
}