/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1986-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* include file search support
*/
#include "pplib.h"
#if ARCHIVE
#include <vdb.h>
#include <ls.h>
#endif
/*
* multiple include test
* fp is a canonicalized ppfile pointer
*
* test
*
* INC_CLEAR can be included again
* INC_TEST test if include required
* <symbol> ifndef guard symbol
*
* test!=INC_CLEAR returns 1 if file can be included again
*
* NOTE:
*
* (1) different hard links to the same file are treated as
* different files
*
* (2) symbolic links in combination with .. may cause two
* different files to be treated as the same file:
*
*/
int
{
message((-3, "search: %s: status=%s%s test=%s", fp->name, status == INC_CLEAR ? "[CLEAR]" : status == INC_TEST ? "[ONCE]" : status == INC_IGNORE ? "[IGNORE]" : status->name, (pp.mode & HOSTED) ? "[HOSTED]" : "", test == INC_CLEAR ? "[CLEAR]" : test == INC_TEST ? "[TEST]" : test->name));
if (status == INC_IGNORE)
{
return 0;
}
{
{
{
else
return 0;
}
return 1;
}
test = INC_IGNORE;
else
return 1;
}
return 1;
}
/*
* search for file using directories in dp
*/
static int
{
register char* prefix;
int fd;
int index;
int need;
int markhosted;
char* t;
prefix = 0;
{
*prefix = 0;
*prefix = '/';
prefix = t;
}
message((-3, "search: %s %s%s%s%s%s%s type=%s prefix=%s flags=|%s%s%s%s%s%s start=%s=\"%s\" pre=%s lcl=%s vnd=%s std=%s cur=%s",
dp ? (dp->index == INC_PREFIX ? "pre" : dp->index == INC_LOCAL ? "lcl" : dp->index == INC_VENDOR ? "vnd" : "std") : NiL,
));
if (flags & SEARCH_HOSTED)
need = TYPE_HOSTED;
else if (flags & SEARCH_VENDOR)
need = TYPE_VENDOR;
else
need = TYPE_INCLUDE;
{
message((-3, "search: fp=%s need=%02x index=%d dp=%s type=%02x index=%d", fp->name, need, index, dp->name, dp->type, dp->index));
#if ARCHIVE
{
{
continue;
}
{
register char* s;
char* e;
int delimiter;
int variant;
unsigned long siz;
unsigned long off;
/*
* check for vdb header archive
*/
{
continue;
}
variant = sfsprintf(pp.tmpbuf, MAXTOKEN, "%c%s%c%s:archive", VDB_DELIMITER, VDB_MAGIC, VDB_DELIMITER, pp.pass);
{
continue;
}
/*
* parse the options
*/
for (s += variant;;)
{
while (*s == ' ') s++;
e = s;
for (t = 0; *s && *s != ' '; s++)
if (*s == '=')
{
*s = 0;
t = s + 1;
}
if (*s)
*s++ = 0;
if (!*e)
break;
{
case X_CHECKPOINT:
#if CHECKPOINT
break;
#else
goto notvdb;
#endif
case X_HIDE:
if (t)
*e = 0;
else
break;
case X_MAP:
if (!t)
else
break;
default:
break;
}
}
{
continue;
}
if (variant = *s != 0)
s++;
goto notvdb;
goto notvdb;
goto notvdb;
goto notvdb;
goto notvdb;
s[siz] = 0;
goto notvdb;
if (!(s = strchr(s, '\n')))
goto notvdb;
s++;
while (e = strchr(s, '\n'))
{
break;
*t = 0;
if (!streq(s, VDB_DIRECTORY))
{
pathcanon(s, 0, 0);
if (pp.test & 0x0020) error(1, "VDB#%d %s %s index=%d data=<%lu,%lu>", __LINE__, dp->name, xp->name, index, ap->offset, ap->size);
}
s = e + 1;
}
goto notvdb;
#if POOL
#else
#endif
else
{
#if POOL
#endif
}
}
else
}
#endif
continue;
#if ARCHIVE
#endif
{
break;
if (!up)
{
t = prefix;
else
{
continue;
}
}
continue;
}
if (!(flags & SEARCH_NEXT) && index != dp->index && (!(need & TYPE_HOSTED) || dp->index == INC_STANDARD) && (!(need & TYPE_VENDOR) || dp->index == INC_VENDOR))
{
{
if (index == INC_PREFIX)
{
else
{
{
if (!(flags & SEARCH_INCLUDE))
return 0;
{
if (flags & SEARCH_TEST)
return 0;
}
}
}
}
else if (!xp)
{
continue;
}
else
{
if (!(flags & SEARCH_INCLUDE))
return 0;
{
if (flags & SEARCH_TEST)
return 0;
}
}
}
}
{
else
if (!(flags & SEARCH_SKIP))
{
int found;
found = 1;
else
{
found = 0;
{
found = 1;
break;
}
}
if (found)
{
flags |= SEARCH_FOUND;
continue;
}
if (!(flags & SEARCH_FOUND))
continue;
}
}
{
{
if (!(flags & SEARCH_INCLUDE))
return 0;
{
if (flags & SEARCH_TEST)
return 0;
}
}
break;
else
continue;
}
#if ARCHIVE
if (pp.test & 0x0040) error(1, "SEARCH#%d dir=%s%s%s%s%s file=%s%s path=%s index=%d", __LINE__, dp->name, (dp->type & TYPE_ARCHIVE) ? " ARCHIVE" : "", (dp->type & TYPE_BUFFER) ? " BUFFER" : "", (dp->type & TYPE_CHECKPOINT) ? " CHECKPOINT" : "", (dp->type & TYPE_DIRECTORY) ? " DIRECTORY" : "", fp->name, (fp->flags & INC_MEMBER(index)) ? " MEMBER" : "", pp.path, index);
{
fd = 0;
if (pp.test & 0x0010) error(1, "SEARCH#%d file=%s path=%s index=%d data=<%lu,%lu>", __LINE__, fp->name, pp.path, index, pp.member->offset, pp.member->size);
}
continue;
else
#endif
{
}
if (fd >= 0)
{
{
if (dp->c)
else
}
if (xp)
else if (!(markhosted = (dp->type & TYPE_HOSTED)) && dp->index == INC_PREFIX && (pp.mode & (FILEDEPS|HEADERDEPS|INIT)) == FILEDEPS)
{
markhosted = 1;
}
if (markhosted)
else
if (markhosted)
message((-2, "search: %s -> %s%s%s", fp->name, pp.path, (pp.mode & MARKC) ? " [C]" : "", (pp.mode & MARKHOSTED) ? " [hosted]" : ""));
#if ARCHIVE
{
#endif
if ((index == INC_STANDARD || index == INC_VENDOR) && type != T_HEADER && !(fp->flags & INC_BOUND(INC_LOCAL)))
{
}
#if ARCHIVE
}
#endif
if (flags & SEARCH_INCLUDE)
{
{
else
{
else
#if ARCHIVE
#endif
if (fd > 0)
if (flags & SEARCH_TEST)
return 0;
}
}
if ((pp.mode & (FILEDEPS|INIT)) == FILEDEPS && ((pp.mode & HEADERDEPS) || !(pp.mode & MARKHOSTED)) && !(xp->flags & INC_LISTED))
{
{
index = '\t';
}
else
index = ' ';
}
}
return fd;
}
if (xp)
break;
}
return -1;
}
/*
* search for an include file
* if (flags&SEARCH_INCLUDE) then
* if file found then open read file descriptor returned
* with pp.path set to the full path and
* pp.prefix set to the directory prefix
* otherwise 0 returned if file found but ignored
* otherwise -1 returned
* otherwise
* if file found then 0 returned
* otherwise -1 returned
*/
int
{
register char* s;
char* t;
int dospath;
int chop;
int fd;
int index;
int prefix;
pp.include = 0;
fd = -1;
chop = 0;
{
dospath = 1;
}
else
dospath = 0;
if (chop)
{
{
}
{
}
break;
}
while ((fp->flags & INC_MAPALL) || (fp->flags & INC_MAPHOSTED) && (pp.mode & HOSTED) || (fp->flags & INC_MAPNOHOSTED) && !(pp.mode & HOSTED))
{
break;
}
flags |= SEARCH_HOSTED;
flags |= SEARCH_VENDOR;
{
{
int n;
int m;
{
return -1;
if (fd > 0)
s = error_info.file;
error_info.file = s;
return fd;
}
}
file++;
else
flags |= SEARCH_NEXT;
#if _HUH_2002_05_28
{
return fd;
}
#endif
}
{
return 0;
}
else if (!(flags & SEARCH_NEXT))
flags |= SEARCH_SKIP;
else
{
{
/*
* look in directory of including file first
*/
{
*s = 0;
*s = '/';
}
else
}
{
/*
* look in prefix directory of including file first
*/
{
{
*s = 0;
fd = 0;
*s = '/';
}
else
fd = 0;
}
if (fd >= 0)
{
return fd;
}
}
else if (!prefix)
prefix = 1;
}
{
{
if (*s != '.')
{
goto again;
}
}
/*
* hackery for msdos files viewed through unix
*/
switch (dospath)
{
case 1:
{
file[0] = '/';
dospath = 2;
goto again;
}
break;
case 2:
file += 2;
goto again;
}
{
{
chop = 1;
goto again;
}
if (prefix > 0)
{
prefix = -1;
{
*s = 0;
{
}
*s = '/';
if (t)
goto again;
}
}
{
}
{
{
{
index = '\t';
}
else
index = ' ';
}
}
}
}
return fd;
}