Quantcast
Channel: Icepack-linux and Neck Pads » linux scripts code
Viewing all articles
Browse latest Browse all 8

linux kernel code scripts unifdef.c 8

$
0
0

/*
* Skip macro arguments.
*/
static const char *
skipargs(const char *cp)
{
const char *ocp = cp;
int level = 0;
cp = skipcomment(cp);
if (*cp != ‘(‘)
return (cp);
do {
if (*cp == ‘(‘)
level++;
if (*cp == ‘)’)
level–;
cp = skipcomment(cp+1);
} while (level != 0 && *cp != ‘\0′);
if (level == 0)
return (cp);
else
/* Rewind and re-detect the syntax error later. */
return (ocp);
}

/*
* Skip over an identifier.
*/
static const char *
skipsym(const char *cp)
{
while (!endsym(*cp))
++cp;
return (cp);
}

/*
* Look for the symbol in the symbol table. If it is found, we return
* the symbol table index, else we return -1.
*/
static int
findsym(const char *str)
{
const char *cp;
int symind;

cp = skipsym(str);
if (cp == str)
return (-1);
if (symlist) {
if (symdepth && firstsym)
printf(“%s%3d”, zerosyms ? “” : “\n”, depth);
firstsym = zerosyms = false;
printf(“%s%.*s%s”,
symdepth ? ” ” : “”,
(int)(cp-str), str,
symdepth ? “” : “\n”);
/* we don’t care about the value of the symbol */
return (0);
}
for (symind = 0; symind < nsyms; ++symind) {
if (strlcmp(symname[symind], str, cp-str) == 0) {
debug(“findsym %s %s”, symname[symind],
value[symind] ? value[symind] : “”);
return (symind);
}
}
return (-1);
}

/*
* Add a symbol to the symbol table.
*/
static void
addsym(bool ignorethis, bool definethis, char *sym)
{
int symind;
char *val;

symind = findsym(sym);
if (symind < 0) {
if (nsyms >= MAXSYMS)
errx(2, “too many symbols”);
symind = nsyms++;
}
symname[symind] = sym;
ignore[symind] = ignorethis;
val = sym + (skipsym(sym) – sym);
if (definethis) {
if (*val == ‘=’) {
value[symind] = val+1;
*val = ‘\0′;
} else if (*val == ‘\0′)
value[symind] = “1″;
else
usage();
} else {
if (*val != ‘\0′)
usage();
value[symind] = NULL;
}
debug(“addsym %s=%s”, symname[symind],
value[symind] ? value[symind] : “undef”);
}

/*
* Compare s with n characters of t.
* The same as strncmp() except that it checks that s[n] == ‘\0′.
*/
static int
strlcmp(const char *s, const char *t, size_t n)
{
while (n– && *t != ‘\0′)
if (*s != *t)
return ((unsigned char)*s – (unsigned char)*t);
else
++s, ++t;
return ((unsigned char)*s);
}

/*
* Diagnostics.
*/
static void
debug(const char *msg, …)
{
va_list ap;

if (debugging) {
va_start(ap, msg);
vwarnx(msg, ap);
va_end(ap);
}
}

static void
error(const char *msg)
{
if (depth == 0)
warnx(“%s: %d: %s”, filename, linenum, msg);
else
warnx(“%s: %d: %s (#if line %d depth %d)”,
filename, linenum, msg, stifline[depth], depth);
closeout();
errx(2, “output may be truncated”);
}


Viewing all articles
Browse latest Browse all 8

Trending Articles