Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
include.c File Reference
#include "def.h"

Go to the source code of this file.

Functions

static int does_file_exist (char *file)
static boolean isdot (char *p)
static boolean isdotdot (char *p)
static boolean issymbolic (char *dir, char *component)
static void remove_dotdot (char *path)
struct inclistnewinclude (char *newfile, char *incstring)
void included_by (struct inclist *ip, struct inclist *newfile)
void inc_clean (void)
struct inclistinc_path (char *file, char *include, int type)

Variables

struct * inclistp
struct * inclistnext
char * includedirs []
char ** includedirsnext
char * notdotdot []
boolean show_where_not
boolean warn_multiple

Function Documentation

static int does_file_exist ( char *  file) [static]

Definition at line 45 of file include.c.

{
  struct stat sb;
  return stat(file, &sb) == 0 && !S_ISDIR(sb.st_mode);
}

Here is the caller graph for this function:

Definition at line 248 of file include.c.

{
       register struct inclist *ip;

       for (ip = inclist; ip < inclistp; ip++) {
              ip->i_flags &= ~MARKED;
       }
}

Here is the caller graph for this function:

struct inclist* inc_path ( char *  file,
char *  include,
int  type 
) [read]

Definition at line 258 of file include.c.

{
       static char          path[ BUFSIZ ];
       register char        **pp, *p;
       register struct inclist     *ip;

       /*
        * Check all previously found include files for a path that
        * has already been expanded.
        */
       if ((type == INCLUDE) || (type == INCLUDEDOT))
              inclistnext = inclist;
       ip = inclistnext;

       for (; ip->i_file; ip++) {
              if ((strcmp(ip->i_incstring, include) == 0) &&
                  !(ip->i_flags & INCLUDED_SYM)) {
                     inclistnext = ip + 1;
                     return ip;
              }
       }

       if (inclistnext == inclist) {
              /*
               * If the path was surrounded by "" or is an absolute path,
               * then check the exact path provided.
               */
              if ((type == INCLUDEDOT) ||
                  (type == INCLUDENEXTDOT) ||
                  (*include == '/')) {
                     if (does_file_exist(include))
                            return newinclude(include, include);
                     if (show_where_not)
                            warning1("\tnot in %s\n", include);
              }

              /*
               * If the path was surrounded by "" see if this include file is
               * in the directory of the file being parsed.
               */
              if ((type == INCLUDEDOT) || (type == INCLUDENEXTDOT)) {
                     for (p=file+strlen(file); p>file; p--)
                            if (*p == '/')
                                   break;
                     if (p == file) {
                            strcpy(path, include);
                     } else {
                            strncpy(path, file, (p-file) + 1);
                            path[ (p-file) + 1 ] = '\0';
                            strcpy(path + (p-file) + 1, include);
                     }
                     remove_dotdot(path);
                     if (does_file_exist(path))
                            return newinclude(path, include);
                     if (show_where_not)
                            warning1("\tnot in %s\n", path);
              }
       }

       /*
        * Check the include directories specified.  Standard include dirs
        * should be at the end.
        */
       if ((type == INCLUDE) || (type == INCLUDEDOT))
              includedirsnext = includedirs;
       pp = includedirsnext;

       for (; *pp; pp++) {
              sprintf(path, "%s/%s", *pp, include);
              remove_dotdot(path);
              if (does_file_exist(path)) {
                     includedirsnext = pp + 1;
                     return newinclude(path, include);
              }
              if (show_where_not)
                     warning1("\tnot in %s\n", path);
       }

       return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void included_by ( struct inclist ip,
struct inclist newfile 
)

Definition at line 198 of file include.c.

{
       register int i;

       if (ip == NULL)
              return;
       /*
        * Put this include file (newfile) on the list of files included
        * by 'file'.  If 'file' is NULL, then it is not an include
        * file itself (i.e. was probably mentioned on the command line).
        * If it is already on the list, don't stick it on again.
        */
       if (ip->i_list == NULL) {
              ip->i_list = (struct inclist **)
                     malloc(sizeof(struct inclist *) * ++ip->i_listlen);
              ip->i_merged = (boolean *)
                  malloc(sizeof(boolean) * ip->i_listlen);
       } else {
              for (i=0; i<ip->i_listlen; i++)
                     if (ip->i_list[ i ] == newfile) {
                         i = strlen(newfile->i_file);
                         if (!(ip->i_flags & INCLUDED_SYM) &&
                            !(i > 2 &&
                              newfile->i_file[i-1] == 'c' &&
                              newfile->i_file[i-2] == '.'))
                         {
                            /* only bitch if ip has */
                            /* no #include SYMBOL lines  */
                            /* and is not a .c file */
                            if (warn_multiple)
                            {
                                   warning("%s includes %s more than once!\n",
                                          ip->i_file, newfile->i_file);
                                   warning1("Already have\n");
                                   for (i=0; i<ip->i_listlen; i++)
                                          warning1("\t%s\n", ip->i_list[i]->i_file);
                            }
                         }
                         return;
                     }
              ip->i_list = (struct inclist **) realloc(ip->i_list,
                     sizeof(struct inclist *) * ++ip->i_listlen);
              ip->i_merged = (boolean *)
                  realloc(ip->i_merged, sizeof(boolean) * ip->i_listlen);
       }
       ip->i_list[ ip->i_listlen-1 ] = newfile;
       ip->i_merged[ ip->i_listlen-1 ] = FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static boolean isdot ( char *  p) [static]

Definition at line 61 of file include.c.

{
       if(p && *p++ == '.' && *p++ == '\0')
              return(TRUE);
       return(FALSE);
}

Here is the caller graph for this function:

static boolean isdotdot ( char *  p) [static]

Definition at line 69 of file include.c.

{
       if(p && *p++ == '.' && *p++ == '.' && *p++ == '\0')
              return(TRUE);
       return(FALSE);
}

Here is the caller graph for this function:

static boolean issymbolic ( char *  dir,
char *  component 
) [static]

Definition at line 77 of file include.c.

{
#ifdef S_IFLNK
       struct stat   st;
       char   buf[ BUFSIZ ], **pp;

       sprintf(buf, "%s%s%s", dir, *dir ? "/" : "", component);
       for (pp=notdotdot; *pp; pp++)
              if (strcmp(*pp, buf) == 0)
                     return (TRUE);
       if (lstat(buf, &st) == 0
       && (st.st_mode & S_IFMT) == S_IFLNK) {
              *pp++ = copy(buf);
              if (pp >= &notdotdot[ MAXDIRS ])
                     fatalerr("out of .. dirs, increase MAXDIRS\n");
              return(TRUE);
       }
#endif
       return(FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct inclist* newinclude ( char *  newfile,
char *  incstring 
) [read]

Definition at line 176 of file include.c.

{
       register struct inclist     *ip;

       /*
        * First, put this file on the global list of include files.
        */
       ip = inclistp++;
       if (inclistp == inclist + MAXFILES - 1)
              fatalerr("out of space: increase MAXFILES\n");
       ip->i_file = copy(newfile);

       if (incstring == NULL)
              ip->i_incstring = ip->i_file;
       else
              ip->i_incstring = copy(incstring);

       inclistnext = inclistp;
       return(ip);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void remove_dotdot ( char *  path) [static]

Definition at line 104 of file include.c.

{
       register char *end, *from, *to, **cp;
       char          *components[ MAXFILES ],
                     newpath[ BUFSIZ ];
       boolean              component_copied;

       /*
        * slice path up into components.
        */
       to = newpath;
       if (*path == '/')
              *to++ = '/';
       *to = '\0';
       cp = components;
       for (from=end=path; *end; end++)
              if (*end == '/') {
                     while (*end == '/')
                            *end++ = '\0';
                     if (*from)
                            *cp++ = from;
                     from = end;
              }
       *cp++ = from;
       *cp = NULL;

       /*
        * Recursively remove all 'x/..' component pairs.
        */
       cp = components;
       while(*cp) {
              if (!isdot(*cp) && !isdotdot(*cp) && isdotdot(*(cp+1))
                  && !issymbolic(newpath, *cp))
              {
                  char **fp = cp + 2;
                  char **tp = cp;

                  do 
                     *tp++ = *fp; /* move all the pointers down */
                  while (*fp++);
                  if (cp != components)
                     cp--;  /* go back and check for nested ".." */
              } else {
                  cp++;
              }
       }
       /*
        * Concatenate the remaining path elements.
        */
       cp = components;
       component_copied = FALSE;
       while(*cp) {
              if (component_copied)
                     *to++ = '/';
              component_copied = TRUE;
              for (from = *cp; *from; )
                     *to++ = *from++;
              *to = '\0';
              cp++;
       }
       *to++ = '\0';

       /*
        * copy the reconstituted path back to our pointer.
        */
       strcpy(path, newpath);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct * inclistnext

Definition at line 97 of file main.c.

struct * inclistp

Definition at line 96 of file main.c.

char* includedirs[]

Definition at line 101 of file main.c.

char ** includedirsnext

Definition at line 102 of file main.c.

char* notdotdot[]

Definition at line 103 of file main.c.

Definition at line 113 of file main.c.

Definition at line 115 of file main.c.