コード例 #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
ファイル: size.c プロジェクト: BackupTheBerlios/hsc-svn
/*
 * 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"));
                        }
                    }
コード例 #3
0
ファイル: uri.c プロジェクト: BackupTheBerlios/hsc-svn
/*
 * 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));
             }
        );
コード例 #4
0
ファイル: uri.c プロジェクト: BackupTheBerlios/hsc-svn
/*
** parse_uri
**
** read an uri-string, check it for syntatic correctnes.
** if the uri refers to an local file, convert its absolute
** path to a relative path and check its existence.
**
** uri = "rsrc_type://host.domain:port/pathname#name"
*/
STRPTR parse_uri( STRPTR uri, INFILE *inpf )
{

    STRPTR host = NULL;
    STRPTR port = NULL;
    STRPTR path = NULL;
    STRPTR name = NULL;
    char dest_fname[MAX_PATHLEN]; /* destination file name that's existence */
    /* is checked if chkuri is enabled */
    if (uri) {

        /* check for valid uri */
        URIKIND kind = uri_kind( uri );
        if ( kind == URI_ext ) {

            /*
            ** check global uri
            */
            if (!host) host = "";
            if (!port) port = "";
            if (!host) host = "";

            /*
            ** TODO: parse global uris
            */


        } else {

            /*
            ** check local uri
            */

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

            /* if a <BASE HREF=".."> was found before,
            ** also treat URI as absolute
            */
            if ( docbase_set && (kind == URI_rel) )
                kind = URI_abs;


            /* extract path and #name */
            if ( uri[0] == '#' ) {

                path = NULL;  /* TODO: set path to current filename */
                name = uri+1; /* skip '#' */

            } else {

                path = strtok( uri, "#" );
                name = strtok( NULL, "" );

            }

            /* reset destination filename */
            strcpy( dest_fname, projdir );

            if ( path ) {

                FILE *exist;

                if ( kind == URI_abs ) {

                    /*
                    **
                    ** parse absolute uri
                    **
                    */
                    /* debug */
                    if (debug)
                        fprintf( stderr, "** exists %s [abs]\n", path );

                    /* check if local uri exists */
                    strcat( dest_fname, destdir );
                    strcat( dest_fname, path );

                    /* debug */
                    if (debug)
                        fprintf( stderr, "**   -> file %s\n", dest_fname );

                    /* create path of destination file */
                    strcpy( dest_uri, rel_destdir );
                    strcat( dest_uri, path );


                    path = get_relfname( path, rel_destdir );
                    /* debug */
                    if (debug)
                        fprintf( stderr, "**   -> real path %s\n", path );

                    /* convert (filesystem depending) path to uri */
                    uri = conv_path2uri( path );

                    /* debug */
                    if (debug)
                        fprintf( stderr, "**   -> real uri  %s\n", uri );

                } else { /* if (kind==URI_abs) */

                    /*
                    ** parse relative uri
                    */


                    /* debug */
                    if (debug)
                        fprintf( stderr, "** exists %s [rel]\n", path );

                    /* check if local uri exists */
                    strcat( dest_fname, destdir );
                    strcat( dest_fname, rel_destdir );
                    strcat( dest_fname, conv_uri2path(path) );

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

                    /* debug */
                    if (debug) {
                        fprintf( stderr, "**   -> real path %s\n", dest_fname );
                        fprintf( stderr, "**   -> real uri  %s\n", dest_uri );
                    }
                }

                /*
                **check existence of local uri
                */
                if ( chkuri ) {

                    exist = fopen( dest_fname, "r" );
                    if ( !exist ) {

                        message( MSG_NO_URIPATH, inpf );
                        errstr( "path to URI not found:" );
                        errqstr( dest_fname );
                        errlf();

                    } else
                        fclose( exist );
                }

            } else { /* if (path) */

                path = "";
                strcpy( dest_uri, path );
                uri = dest_uri;

            }

            /* add #name part */
            if ( name ) {
                strcat( uri, "#" );
                strcat( uri, name );
            }

        } /* else (rsrc) */

    } /* if (uri) */

    return ( uri );
}
コード例 #5
0
ファイル: uri.c プロジェクト: BackupTheBerlios/hsc-svn
/*
 * 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));
         }
    );