> 
> And then lookup makes tons of sense with the beginning just always being
> one of "angle_includepath", "quote_includepath" or "stream->next_path".

Something like this.
First cut - it seems to work but rather untested.

I succeeded doing a 'make C=2 kernel/'

I will test tomorrow - heading for bed now.

The "fetch dir of input file" looks wrong and needs to go to a better
place. No need to do it once for all include files.

        Sam
        
===== lib.c 1.112 vs edited =====
--- 1.112/lib.c 2005-01-14 23:11:01 +01:00
+++ edited/lib.c        2005-01-17 22:27:14 +01:00
@@ -428,16 +428,8 @@
 
        switch (arg[1]) {
        case '-':
-               /* Explaining '-I-' with a google search:
-                *
-                *      "Specifying -I after -I- searches for #include 
directories.
-                *       If -I- is specified before, it searches for #include 
"file"
-                *       and not #include ."
-                *
-                * Which didn't explain it at all to me. Maybe somebody else can
-                * explain it properly. We ignore it for now.
-                */
-               return next;
+               add_pre_buffer("#split_include\n");
+               break;
 
        case '\0':      /* Plain "-I" */
                path = *++next;
@@ -465,7 +457,7 @@
                char *path = *++next;
                if (!path)
                        die("missing argument for -isystem option");
-               add_pre_buffer("#add_include \"%s/\"\n", path);
+               add_pre_buffer("#add_system \"%s/\"\n", path);
        }
        return next;
 }
===== pre-process.c 1.123 vs edited =====
--- 1.123/pre-process.c 2004-12-09 19:55:29 +01:00
+++ edited/pre-process.c        2005-01-17 22:50:20 +01:00
@@ -36,16 +36,20 @@
 static unsigned char elif_ignore[MAX_NEST];
 enum { ELIF_IGNORE = 1, ELIF_SEEN_ELSE = 2 };
 
+static char current_c_file[PATH_MAX];
+
 #define INCLUDEPATHS 300
 const char *includepath[INCLUDEPATHS+1] = {
+       current_c_file,
        "/usr/include",
        "/usr/local/include",
        GCC_INTERNAL_INCLUDE,
        NULL
 };
 
-static const char **sys_includepath = includepath + 0;
-static const char **gcc_includepath = includepath + 2;
+static const char **quote_includepath = includepath;
+static const char **angle_includepath = includepath + 1;
+static const char **sys_includepath   = includepath + 1;
 
 #define MARK_STREAM_NONCONST(pos) do {                                 \
        if (stream->constant != CONSTANT_FILE_NOPE) {                   \
@@ -613,9 +617,10 @@
        return 0;
 }
 
-static int try_include(const char *path, int plen, const char *filename, int 
flen, struct token **where, const char **next_path)
+static int try_include(const char *path, const char *filename, int flen, 
struct token **where, const char **next_path)
 {
        int fd;
+       int plen = strlen(path);
        static char fullname[PATH_MAX];
 
        memcpy(fullname, path, plen);
@@ -642,38 +647,34 @@
        const char *path;
 
        while ((path = *pptr++) != NULL) {
-               if (!try_include(path, strlen(path), filename, flen, list, 
pptr))
+               if (!try_include(path, filename, flen, list, pptr))
                        continue;
                return 1;
        }
        return 0;
 }
-       
+
 
 static void do_include(int local, struct stream *stream, struct token **list, 
struct token *token, const char *filename, const char **path)
 {
+       char *slash;
        int flen = strlen(filename) + 1;
 
        /* Absolute path? */
        if (filename[0] == '/') {
-               if (try_include("", 0, filename, flen, list, includepath))
+               if (try_include("", filename, flen, list, includepath))
                        return;
                goto out;
        }
 
-       /* Same directory as current stream? */
-       if (local) {
-               const char *path;
-               char *slash;
-               int plen;
-
-               path = stream->name;
-               slash = strrchr(path, '/');
-               plen = slash ? slash - path : 0;
-
-               if (try_include(path, plen, filename, flen, list, includepath))
-                       return;
-       }
+       /* Fetch dir of input file */
+       strcpy(current_c_file, stream->name);
+       if ((slash = strrchr(current_c_file, '/')) != NULL)
+               *slash = '\0';
+
+       if (!path)
+               /* Do not search quote include if <> is in use */
+               path = local ? quote_includepath : angle_includepath;
 
        /* Check the standard include paths.. */
        if (do_include_path(path, list, token, filename, flen))
@@ -723,7 +724,7 @@
 
 static int handle_include(struct stream *stream, struct token **list, struct 
token *token)
 {
-       return handle_include_path(stream, list, token, includepath);
+       return handle_include_path(stream, list, token, NULL);
 }
 
 static int handle_include_next(struct stream *stream, struct token **list, 
struct token *token)
@@ -1328,8 +1329,6 @@
 
 static int handle_nostdinc(struct stream *stream, struct token **line, struct 
token *token)
 {
-       int stdinc;
-
        if (false_nesting)
                return free_preprocessor_line(token);
 
@@ -1337,18 +1336,7 @@
         * Do we have any non-system includes?
         * Clear them out if so..
         */
-       stdinc = gcc_includepath - sys_includepath;
-       if (stdinc) {
-               const char **src = gcc_includepath;
-               const char **dst = sys_includepath;
-               for (;;) {
-                       if (!(*dst = *src))
-                               break;
-                       dst++;
-                       src++;
-               }
-               gcc_includepath -= stdinc;
-       }
+       *sys_includepath = NULL;
        return free_preprocessor_line(token);
 }
 
@@ -1361,10 +1349,16 @@
        if (includepath[INCLUDEPATHS-2])
                error_die(token->pos, "too many include path entries");
 
+       /* check that this is not a duplicate */
+       dst = includepath;
+       while (*dst) {
+               if (strcmp(*dst, path) == 0)
+                       return;
+               dst++;
+       }
        next = path;
        dst = sys_includepath;
        sys_includepath++;
-       gcc_includepath++;
 
        /*
         * Move them all up starting at "sys_includepath",
@@ -1394,6 +1388,58 @@
        }
 }
 
+static void add_system_entry(struct token *token, const char *path)
+{
+       const char **dst = includepath;
+
+       /* Need one free entry.. */
+       if (includepath[INCLUDEPATHS-2])
+               error_die(token->pos, "too many include path entries");
+
+       /* Add to the end */
+       while (*dst)
+               dst++;
+       *dst = path;
+       dst++;
+       *dst = NULL;
+}
+
+static int handle_add_system(struct stream *stream, struct token **line, 
struct token *token)
+{
+       for (;;) {
+               token = token->next;
+               if (eof_token(token))
+                       return 1;
+               if (token_type(token) != TOKEN_STRING) {
+                       warning(token->pos, "expected path string");
+                       return 1;
+               }
+               add_system_entry(token, token->string->data);
+       }
+}
+
+static int handle_split_include(struct stream *stream, struct token **line, 
struct token *token)
+{
+       if (false_nesting)
+               return free_preprocessor_line(token);
+
+       /*
+        * -I-
+        *  From info gcc:
+        *  Split the include path.  Any directories specified with `-I'
+        *  options before `-I-' are searched only for headers requested with
+        *  `#include "FILE"'; they are not searched for `#include <FILE>'.
+        *  If additional directories are specified with `-I' options after
+        *  the `-I-', those directories are searched for all `#include'
+        *  directives.
+        *  In addition, `-I-' inhibits the use of the directory of the current
+        *  file directory as the first search directory for `#include "FILE"'.
+        */
+       quote_includepath = includepath+1;
+       angle_includepath = sys_includepath;
+       return free_preprocessor_line(token);
+}
+
 /*
  * We replace "#pragma xxx" with "__pragma__" in the token
  * stream. Just as an example.
@@ -1453,8 +1499,10 @@
                { "line",       handle_line },
 
                // our internal preprocessor tokens
-               { "nostdinc",   handle_nostdinc },
-               { "add_include", handle_add_include },
+               { "nostdinc",      handle_nostdinc },
+               { "add_include",   handle_add_include },
+               { "add_system",    handle_add_system },
+               { "split_include", handle_split_include },
        };
 
        for (i = 0; i < (sizeof (handlers) / sizeof (handlers[0])); i++) {
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to