Author Topic: Include not work  (Read 8168 times)

nobody

  • Guest
Include not work
« on: December 27, 2006, 04:44:24 PM »
some code like this:

; foo/foo.asm
%include "bar.inc"
.....

; bar/bar.inc
.....

command:
  nasm -felf -Ibar foo/foo.asm

output:
  foo/foo.asm:1: fatal: unable to open include file `bar.inc'

I had to changed the source "preproc.c" line #1169:

static FILE *inc_fopen(char *file)
{
    FILE *fp;
    char *prefix = "", *combine;
    IncPath *ip = ipath;
    static int namelen = 0;
    int len = strlen(file);
    int pflen = 0;                         /** here **/

while (1) {
        /** and here **/
       pflen = strlen(prefix);
        combine = nasm_malloc(pflen + len + 2);
        strcpy(combine, prefix);
       if ('/' != *(prefix + pflen - 1)) {
           combine[pflen++] = '/';
           combine[pflen] = '\0';
        }
        /** end **/
        strcat(combine, file);
        fp = fopen(combine, "r");
        if (pass == 0 && fp) {
            namelen += strlen(combine) + 1;
            if (namelen > 62) {
                printf(" \\\n  ");
                namelen = 2;
            }
            printf(" %s", combine);
        }
        nasm_free(combine);
        if (fp)
            return fp;
        if (!ip)
            break;
        prefix = ip->path;
        ip = ip->next;
    }

error(ERR_FATAL, "unable to open include file `%s'", file);
    return NULL;                /* never reached - placate compilers */
}

and it worked.

I know I could write foo.asm like this:
%include "/bar.inc"
but it's ugly, itsn't it?

nobody

  • Guest
Re: Include not work
« Reply #1 on: December 27, 2006, 05:18:35 PM »
Does that even compile? Thought you'd need "if('/'==..." Well, I don't know C much...

In any case, that breaks documented behavior. We *had* something like that in, for a while - checked for '\' *or* '/', actually. Took it back out, because it broke existing code.

The documented way to do this is not "%include "\bar.inc", but "-I bar\" ('\' or '/'. as your OS requires).

The beauty of Nasm is that you can run your own "private forked version" if you want to. You won't be the only one! But Nasm works, as documented, as it is... Nice work, just the same!

Best,
Frank

nobody

  • Guest
Re: Include not work
« Reply #2 on: December 27, 2006, 05:55:29 PM »
Oh yeah... you had "!=", not just "="... sorry. Told ya I wasn't good at C!

Best,
Frank