Beispiel #1
0
/*
 * get_mid_estr
 *
 * get a part from a expstr; compare BASIC's "MID$()"
 *
 * params: dest...destination expstr where to store result part
 *         src....source expstr where to get part from
 *         from...position of char where to begin part (0=first char)
 *         num....number of chars to get
 * result: TRUE and result in dest if ok; else FALSE is returned an
 *         dest is left untouched
 *
 * NOTE: it is possible to use the source-exstr as destination-expstr,
 *       because the result is copied to a temp. expstr before
 *       ( example: get_mid_estr( hugo, hugo, 3, 4 ); )
 */
BOOL get_mid_estr(EXPSTR * dest, EXPSTR * src, size_t from, size_t num)
{
    BOOL ok = FALSE;
    EXPSTR *tmp = init_estr(dest->es_step);

    if (tmp)
    {

        STRPTR old_data = tmp->es_data;

        /* check size */
        if (from >= src->es_len)
            from = src->es_len - 1;
        if (from + num >= src->es_len)
            num = src->es_len - from - 1;

        /* set new mem for tmp */
        ok = set_estr_mem(tmp, modadj(num + 1, tmp->es_step));

        if (ok)
        {

            /* copy data */
            strncpy(estr2str(tmp), estr2str(src) + from, num);
            tmp->es_data[num] = 0;
            tmp->es_len = num + 1;
            ufree(old_data);

            ok = estrcpy(dest, tmp);

        }
        del_estr(tmp);

    }
    return (ok);
}
Beispiel #2
0
/*
 * Gets the value of a prom property at either root or options node.  It
 * returns 1 if it is successful, otherwise it returns 0 .
 */
static int
get_prom(int prom_fd, prom_node_t node_name,
	char *property_name, char *property_value, size_t len)
{
	union {
		char buf[PBUFSIZE + sizeof (uint_t)];
		struct openpromio opp;
	} oppbuf;
	register struct openpromio *opp = &(oppbuf.opp);
	int	got_it = 0;

	if (prom_fd == -1) {
		return (0);
	}

	switch (node_name) {
	case root:
		(void *) memset(oppbuf.buf, 0, PBUFSIZE);
		opp->oprom_size = PBUFSIZE;
		if (ioctl(prom_fd, OPROMNEXT, opp) < 0) {
			return (0);
		}

		/*
		 * Passing null string will give us the first property.
		 */
		(void *) memset(oppbuf.buf, 0, PBUFSIZE);
		do {
			opp->oprom_size = PBUFSIZE;
			if (ioctl(prom_fd, OPROMNXTPROP, opp) < 0) {
				return (0);
			}
			if (strcmp(opp->oprom_array, property_name) == 0) {
				got_it++;
				break;
			}
		} while (opp->oprom_size > 0);

		if (!got_it) {
			return (0);
		}
		if (got_it && property_value == NULL) {
			return (1);
		}
		opp->oprom_size = PBUFSIZE;
		if (ioctl(prom_fd, OPROMGETPROP, opp) < 0) {
			return (0);
		}
		if (opp->oprom_size == 0) {
			*property_value = '\0';
		} else {
			estrcpy(property_value, opp->oprom_array, len);
		}
		break;
	case options:
		estrcpy(opp->oprom_array, property_name, PBUFSIZE);
		opp->oprom_size = PBUFSIZE;
		if (ioctl(prom_fd, OPROMGETOPT, opp) < 0) {
			return (0);
		}
		if (opp->oprom_size == 0) {
			return (0);
		}
		if (property_value != NULL) {
			estrcpy(property_value, opp->oprom_array, len);
		}
		break;
	default:
		logerror("Only root node and options node are supported.\n");
		return (0);
	}

	return (1);
}
Beispiel #3
0
nsresult
XRemoteClient::DoSendCommandLine(Window aWindow, int32_t argc, char **argv,
                                 const char* aDesktopStartupID,
                                 char **aResponse, bool *aDestroyed)
{
  *aDestroyed = false;

  char cwdbuf[MAX_PATH];
  if (!getcwd(cwdbuf, MAX_PATH))
    return NS_ERROR_UNEXPECTED;

  // the commandline property is constructed as an array of int32_t
  // followed by a series of null-terminated strings:
  //
  // [argc][offsetargv0][offsetargv1...]<workingdir>\0<argv[0]>\0argv[1]...\0
  // (offset is from the beginning of the buffer)

  static char desktopStartupPrefix[] = " DESKTOP_STARTUP_ID=";

  int32_t argvlen = strlen(cwdbuf);
  for (int i = 0; i < argc; ++i) {
    int32_t len = strlen(argv[i]);
    if (i == 0 && aDesktopStartupID) {
      len += sizeof(desktopStartupPrefix) - 1 + strlen(aDesktopStartupID);
    }
    argvlen += len;
  }

  int32_t* buffer = (int32_t*) malloc(argvlen + argc + 1 +
                                      sizeof(int32_t) * (argc + 1));
  if (!buffer)
    return NS_ERROR_OUT_OF_MEMORY;

  buffer[0] = TO_LITTLE_ENDIAN32(argc);

  char *bufend = (char*) (buffer + argc + 1);

  bufend = estrcpy(cwdbuf, bufend);

  for (int i = 0; i < argc; ++i) {
    buffer[i + 1] = TO_LITTLE_ENDIAN32(bufend - ((char*) buffer));
    bufend = estrcpy(argv[i], bufend);
    if (i == 0 && aDesktopStartupID) {
      bufend = estrcpy(desktopStartupPrefix, bufend - 1);
      bufend = estrcpy(aDesktopStartupID, bufend - 1);
    }
  }

#ifdef DEBUG_bsmedberg
  int32_t   debug_argc   = TO_LITTLE_ENDIAN32(*buffer);
  char *debug_workingdir = (char*) (buffer + argc + 1);

  printf("Sending command line:\n"
         "  working dir: %s\n"
         "  argc:\t%i",
         debug_workingdir,
         debug_argc);

  int32_t  *debug_offset = buffer + 1;
  for (int debug_i = 0; debug_i < debug_argc; ++debug_i)
    printf("  argv[%i]:\t%s\n", debug_i,
           ((char*) buffer) + TO_LITTLE_ENDIAN32(debug_offset[debug_i]));
#endif

  XChangeProperty (mDisplay, aWindow, mMozCommandLineAtom, XA_STRING, 8,
                   PropModeReplace, (unsigned char *) buffer,
                   bufend - ((char*) buffer));
  free(buffer);

  if (!WaitForResponse(aWindow, aResponse, aDestroyed, mMozCommandLineAtom))
    return NS_ERROR_FAILURE;
  
  return NS_OK;
}
Beispiel #4
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);
        }
Beispiel #5
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));
             }
        );
Beispiel #6
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);
}
Beispiel #7
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));
         }
    );