Exemplo n.º 1
0
void test_fpath( STRPTR path )
{
    STRPTR newp = get_fpath( path );

    printf( "get_fpath: \"%s\" -> \"%s\"\n", path, newp );

}
Exemplo n.º 2
0
static char	*get_prog_path(t_env *tenv, char *pname)
{
	char	**paths;
	char	*pval;
	char	*fpath;
	int		cnt;

	fpath = NULL;
	cnt = 0;
	if ((pval = get_env_val(tenv, "PATH")) == NULL)
		return (NULL);
	if ((paths = ft_strsplit(pval, ':')) == NULL)
		return (NULL);
	while (paths[cnt] != NULL)
	{
		if ((fpath = get_fpath(paths[cnt], pname)) != NULL)
			break ;
		cnt++;
	}
	ft_strdel(&pval);
	ft_starfree(paths);
	return (fpath);
}
Exemplo n.º 3
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 `"'",

                     "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);
        }
Exemplo n.º 4
0
/*
** get_relfname
**
** convert absolut filename passed to <IMG> or <A HREF>
** to a relative filename (used with absolute URIs)
**
** params: absn...absolute filename passed to tag
**         curp...current path currently processed
**                hsc-file is in. (must end with "/")
** result: ptr to a buffer that contains the relative
**         path. this buffer is overwritten with the next call
*/
STRPTR get_relfname( STRPTR absnam, STRPTR curdir )
{
    char tmpb[ MAX_PATH ];   /* temp buffer */
    char fname[ MAX_FNAME ]; /* file name only */
    char abspa[ MAX_PATH ];  /* absolute path only */
    STRPTR tmpp1, tmpp2;     /* temp pointer */
    STRPTR rest_absp;        /* rest of current path */
    STRPTR absp;

    /*
    ** TODO: - handle out of mem
    **       - handle too long paths
    **       - optimise this routine; it contains
    **         some lines that are not really required
    **
    ** (frankly speaking, i don't really understand why
    ** this routine works, but it seems that is does)
    */

    /* init string array */
    relnam[0] = 0;
    strcpy( fname, get_fname( absnam ) );
    strcpy( abspa, get_fpath( absnam ) );
    absp = abspa;

    /*
    ** strip all equal subdirs
    */
    do {
        tmpp1 = get_nsdir( absp );
        strcpy( tmpb, tmpp1 );
        tmpp2 = get_nsdir( curdir );
        if (!upstrcmp( tmpb, tmpp2 )) {

            absp += strlen( tmpb );
            curdir += strlen( tmpp2 );

        }

    } while ( tmpb[0] && tmpp2[0] && (!upstrcmp( tmpb, tmpp2 )) );

    rest_absp = absp;


    /*
    ** for every subdir in absp unequal to
    ** corresponding subdir curdir, insert a parent dir
    */
    if ( curdir[0] )
        do {

            tmpp1 = get_nsdir( absp );
            strcpy( tmpb, tmpp1 );
            tmpp2 = get_nsdir( curdir );
            if ( upstrcmp( tmpb, tmpp2 )) {

                absp += strlen( tmpb );
                curdir += strlen( tmpp2 );
                strcat( relnam, PARENT_DIR );

            }


        } while ( tmpp2[0] && (upstrcmp( tmpb, tmpp2 )));

    strcat( relnam, rest_absp );
    strcat( relnam, fname );

    return ( relnam );
}
Exemplo n.º 5
0
void old_test_reldir( STRPTR absn, STRPTR curp )
{
    /*
    ** TODO: call upstrcmp() only when non-unix
    */
    STRPTR fname = strclone( get_fname( absn ) );  /* filename */
    STRPTR absop  = strclone( get_fpath( absn ) ); /* absolute path */
    STRPTR ocurp  = strclone( curp ); /* copy of curp for output */
    STRPTR absp   = absop; /* working copy of absolute path */

    char newp[ MAX_PATH ]; /* new path (result) */
    char tmpb[ MAX_PATH ]; /* temp buffer */
    STRPTR tmpp1, tmpp2; /* temp pointer */
    STRPTR rest_absp;    /* rest of current path */

    newp[0] = 0;

    /*
    ** strip equal subdir
    */
    do {
        tmpp1 = get_nsdir( absp );
        strcpy( tmpb, tmpp1 );
        tmpp2 = get_nsdir( curp );
        if (!upstrcmp( tmpb, tmpp2 )) {

            absp += strlen( tmpb );
            curp += strlen( tmpp2 );

        }

    } while ( tmpb[0] && tmpp2[0] && (!upstrcmp( tmpb, tmpp2 )) );

    rest_absp = absp;


    /*
    ** for every subdir in absp unequal to
    ** corresponding subdir curp, insert a parent dir
    */
    do {

        tmpp1 = get_nsdir( absp );
        strcpy( tmpb, tmpp1 );
        tmpp2 = get_nsdir( curp );
        if ( upstrcmp( tmpb, tmpp2 )) {

            absp += strlen( tmpb );
            curp += strlen( tmpp2 );
            strcat( newp, PARENT_DIR );

        }


    } while ( tmpp2[0] && (upstrcmp( tmpb, tmpp2 )));

    strcat( newp, rest_absp );
    strcat( newp, fname );

    printf( "\"%s\" and \"%s\" -> \"%s\"\n", absn, ocurp, newp );

    ufreestr( fname );
    ufreestr( ocurp );
    ufreestr( absop );
}
Exemplo n.º 6
0
STRPTR get_relfname( STRPTR absn, STRPTR curp )
{
    char tmpb[ MAX_PATH ];   /* temp buffer */
    char fname[ MAX_FNAME ]; /* file name only */
    char abspa[ MAX_PATH ];  /* absolute path only */
    STRPTR tmpp1, tmpp2;     /* temp pointer */
    STRPTR rest_absp;        /* rest of current path */
    STRPTR absp;

    /*
    ** TODO: handle out of mem
    */

    /* init string array */
    newp[0] = 0;
    strcpy( fname, get_fname( absn ) );
    strcpy( abspa, get_fpath( absn ) );
    absp = abspa;

    /*
    ** strip all equal subdirs
    */
    do {
        tmpp1 = get_nsdir( absp );
        strcpy( tmpb, tmpp1 );
        tmpp2 = get_nsdir( curp );
        if (!upstrcmp( tmpb, tmpp2 )) {

            absp += strlen( tmpb );
            curp += strlen( tmpp2 );

        }

    } while ( tmpb[0] && tmpp2[0] && (!upstrcmp( tmpb, tmpp2 )) );

    rest_absp = absp;


    /*
    ** for every subdir in absp unequal to
    ** corresponding subdir curp, insert a parent dir
    */
    if ( curp[0] )
        do {

            tmpp1 = get_nsdir( absp );
            strcpy( tmpb, tmpp1 );
            tmpp2 = get_nsdir( curp );
            if ( upstrcmp( tmpb, tmpp2 )) {

                absp += strlen( tmpb );
                curp += strlen( tmpp2 );
                strcat( newp, PARENT_DIR );

            }


        } while ( tmpp2[0] && (upstrcmp( tmpb, tmpp2 )));

    strcat( newp, rest_absp );
    strcat( newp, fname );

    return ( newp );
}