ppbuiltin.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1986-2011 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
*
* preprocessor builtin macro support
*/
#include "pplib.h"
#include <times.h>
/*
* process a #(...) builtin macro call
* `#(' has already been seen
*/
void
ppbuiltin(void)
{
register int c;
register char* p;
register char* a;
int n;
int op;
char* token;
char* t;
long number;
long onumber;
{
*p = 0;
}
{
case V_DEFAULT:
n = 0;
if ((c = pplex()) == ',')
{
op = -1;
c = pplex();
}
for (;;)
{
if (!c)
{
break;
}
if (c == '(') n++;
else if (c == ')' && !n--) break;
c = pplex();
}
break;
case V_EMPTY:
else
{
*p = '0';
n = 0;
for (;;)
{
if (!c)
{
break;
}
if (c == '(') n++;
else if (c == ')' && !n--) break;
c = pplex();
}
}
*(p + 1) = 0;
break;
case V_ITERATE:
n = 0;
if ((c = pplex()) != T_ID || !(sym = ppsymref(pp.symtab, pp.token)) || !sym->macro || sym->macro->arity != 1 || (c = pplex()) != ',')
{
for (;;)
{
if (!c)
{
break;
}
if (c == '(') n++;
else if (c == ')' && !n--) break;
c = pplex();
}
}
else while (c != ')')
{
if (!c || !(c = pplex()))
{
break;
}
while (c)
{
if (c == '(') n++;
else if (c == ')' && !n--) break;
else if (c == ',' && !n) break;
c = pplex();
}
}
break;
default:
while (c != ')')
{
if (!c)
{
break;
}
}
switch (op)
{
case V_ARGC:
c = -1;
{
break;
}
break;
case V_BASE:
break;
case V_DATE:
{
*(p + 20) = 0;
for (p += 7; *p = *(p + 9); p++);
}
break;
case V_FILE:
p = error_info.file;
break;
case V_LINE:
break;
case V_PATH:
break;
case V_SOURCE:
p = error_info.file;
break;
case V_STDC:
p[0] = ((pp.state & (COMPATIBILITY|TRANSITION)) || (pp.mode & (HOSTED|HOSTEDTRANSITION)) == (HOSTED|HOSTEDTRANSITION)) ? '0' : '1';
p[1] = 0;
break;
case V_TIME:
{
*(p + 8) = 0;
}
break;
case V_VERSION:
break;
case V_DIRECTIVE:
break;
case V_GETENV:
if (!(p = getenv(a))) p = "";
break;
case V_GETMAC:
break;
case V_GETOPT:
break;
case V_GETPRD:
break;
case V__PRAGMA:
if ((c = pplex()) == '(')
{
c = pplex();
{
if ((c = pplex()) == ')')
{
PUSH_BUFFER(p, a, 1);
}
sfstrclose(sp);
}
}
if (c != ')')
return;
case V_FUNCTION:
op = 0;
while (c = BACK(a, p))
{
if (c == '"' || c == '\'')
{
op = 0;
}
else if (c == '\n')
{
token = a;
while (c = BACK(a, p))
if (c == '\n')
{
a = token;
break;
}
break;
}
else if (c == ' ')
/*ignore*/;
else if (c == '{') /* '}' */
op = 1;
else if (op == 1)
{
if (c == ')')
{
op = 2;
n = 1;
}
else
op = 0;
}
else if (op == 2)
{
if (c == ')')
n++;
else if (c == '(' && !--n)
op = 3;
}
else if (op == 3)
{
if (ppisidig(c))
{
if (a > token)
{
}
for (; a <= token; *p++ = *a++);
*p = 0;
{
op = 0;
p = t;
continue;
}
}
else
op = 0;
break;
}
}
if (op == 3)
else
p = "__FUNCTION__";
break;
default:
p = a;
break;
}
break;
}
{
strcpy(a, p);
for (;;)
{
switch (*p++ = *a++)
{
case 0:
break;
case MARK:
*p++ = MARK;
/*FALLTHROUGH*/
default:
continue;
}
break;
}
}
PUSH_STRING(p);
else
{
else
{
}
}
}