axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] HyperDoc


From: Gabriel Dos Reis
Subject: [Axiom-developer] HyperDoc
Date: 08 Apr 2007 20:35:47 -0500

"Bill Page" <address@hidden> writes:

[...]

| I think the build is ok now and I can start AXIOMsys. But I
| do get an error when I try hyperdoc:
| 
| -bash-3.00$ axiom
| (HyperDoc) read_ht_db: No ht.db file found

OK, I found where the bug comes from.  It is a very stupid bug.

A while ago, I added support for relative paths -- that was a
necessary step to make axiom.build-improvements buildable on Windows.
I believe that is when HyperDoc stopped working.  The reason?
Well, a very sloppy logic in the HyperDoc source code. 


More precisely, the function src/hyper/addfile.c:build_ht_filename

static int
build_ht_filename(char *fname, char *aname, char *name)
{
    char cdir[256];
    char *c_dir;
    char *HTPATH;
    char *trace;
    char *trace2;
    int ht_file;

    if (cwd(name)) {
        /* user wants to use the current working directory */
        c_dir = (char *) getcwd(cdir, 254);
        strcpy(fname, c_dir);

        /* Now add the rest of the filename */
        strcat(fname, "/");
        strcat(fname, &name[2]);

        /** now copy the actual file name to addname **/
        for (trace = &name[strlen(name)]; trace != name &&
             (*trace != '/'); trace--);
        if (trace == name) {
            fprintf(stderr, "ht_open_file: Didn't expect a filename like %s\n",
                    name);
            exit(-1);
        }
        trace++;
        strcpy(aname, trace);

        /** add  the .ht extension if needed **/
        extend_ht(aname);
        extend_ht(fname);

        /* Now just try to access the file */
        return (access(fname, R_OK));
    }
    else if (pathname(name)) {
        /* filename already has the path specified */
        strcpy(fname, name);

        /** now copy the actual file name to addname **/
        for (trace = &name[strlen(name)]; trace != name &&
             (*trace != '/'); trace--);
        if (trace == name) {
            fprintf(stderr, "ht_open_file: Didn't expect a filename like %s\n",
                    name);
            exit(-1);
        }
        trace++;
        strcpy(aname, trace);

        /** add  the .ht extension if needed **/
        extend_ht(aname);
        extend_ht(fname);

        /* Now just try to access the file */
        return (access(fname, R_OK));
    }
    else {/** If not I am going to have to append path names to it **/
        HTPATH = (char *) getenv("HTPATH");
        if (HTPATH == NULL) {
        /** The user does not have a HTPATH, so I will use the the directory
        $AXIOM/share/hypertex/pages/ as the default path ***/
          char *spad = (char *) getenv("AXIOM");
          if (spad == NULL) {
            fprintf(stderr,
            "ht_file_open:Cannot find ht data base: setenv HTPATH or AXIOM\n");
             exit(-1);
          }
          HTPATH = (char *) halloc(1024 * sizeof(char), "HTPATH");
          strcpy(HTPATH, spad);
          strcat(HTPATH, "/share/hypertex/pages");
        }

        /** Now that I have filled HTPATH, I should try to open a file by the
          given name **/
        strcpy(aname, name);
        extend_ht(aname);
        for (ht_file = -1, trace2 = HTPATH;
             ht_file == -1 && *trace2 != '\0';) {
            for (trace = fname; *trace2 != '\0' && (*trace2 != ':');)
                *trace++ = *trace2++;
            *trace++ = '/';
            *trace = 0;
            if (!strcmp(fname, "./")) {
                /** The person wishes me to check the current directory too **/
                getcwd(fname, 256);
                strcat(fname, "/");
            }
            if (*trace2)
                trace2++;
            strcat(fname, aname);
            ht_file = access(fname, R_OK);
        }
        return (ht_file);
    }
}


The comment fragment

    if (cwd(name)) {
        /* user wants to use the current working directory */

is deceptive because here is how it is deduced that user wanst the
current working directory


   #define cwd(n) ((n[0] == '.' && n[1] == '/')?(1):(0))


That is only the first two characters are tested!
It happens that in the build machinery we use things like

  ./../../target/i686-ps-linux-gnu

and teh cwd() macro thinks that that is current working directory!
Ahem.

The other fragment

    else if (pathname(name)) {
        /* filename already has the path specified */

is equally deceptive.



-- Gaby




reply via email to

[Prev in Thread] Current Thread [Next in Thread]