Kaydet (Commit) 4f4b7415 authored tarafından Nils Fuhrmann's avatar Nils Fuhrmann

Moved cpp from cpp to soltools

üst 12430b86
#define ABC \
ggg
ABC
/* Standards --------------------------------------------------------------- */
#define NOTHING
NOTHING
#define SYMBOL symbol
#undef SYMBOL
#define SYMBOL _symbol_
< SYMBOL > // < _symbol_ >
xSYMBOLx // xSYMBOLx
+SYMBOL- // +_symbol_-
>SYMBOL< // >_symbol_<
<SYMBOL> // <_symbol_>
#define FALSE 0
#define TRUE !FALSE
a = x > 0 ? TRUE : FALSE // a = x > 0 ? !0 : 0
#define A x
#define B y
#define MAC(a, b) \
T() { a(); return b; } // T() { x(); return y; }
MAC(A,B);
#ifdef MAC
MAC(X,Y)
#endif // MAC
/* Recursions -------------------------------------------------------------- */
#define y x
#define x y
x // x
#define Test(a) a
#define b Test(b)
a = b; // a = b;
#define func abc(func)
a = func // a = abc(func)
#define func1 func(abc)
a = func1 // a = abc(func)(abc)
#define args(func, args) func args
args(t1, (args(t2, (x, y)))) // t1 (t2 (x, y))
#define ARGS(a) a
#define __ ARGS
int foo __((int x)); // int foo (int x);
/* Concatinations ---------------------------------------------------------- */
#define tail _Test
// Txt_##tail // Txt_##_Test
#define z(e,f) e##_##f
z ( abc, xyz ) // abc_xyz
#define CAT( var ) fix##.var
CAT( a ) // fix.a
#define CAT3( class, ref ) class##ref::class##ref
CAT3( a, b ) // ab::ab
#define CAT2( var ) fix##var::fix##var
CAT2( a ) // fixa::fixa
/* Extrems ----------------------------------------------------------------- */
#define MAKE_X( name ) name##_Test
#define MAKE_Y( name ) MAKE_X( name##_Sym )
MAKE_Y( Txt ); // Txt_Sym_Test;
/* Extensions -------------------------------------------------------------- */
/*
#ident "(c)# Test.txt"
#if #machine(i386)
# error illegal machine
#endif
char machine[6];
*/
/* Last bug ----------------------------------------------------------------- */
#define Cfstrcpy Cstrcpy
#define Cstrcpy( s1, s2 ) strcpy( s1, s2 )
Cfstrcpy(Par1,Par2 ) // blub( Par1, Par2 )
/* ---------------------------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include "cpp.h"
#define OUTS 16384
char outbuf[OUTS];
char *outptr = outbuf;
Source *cursource;
int nerrs;
struct token nltoken = {NL, 0, 0, 1, (uchar *) "\n"};
char *curtime;
int incdepth;
int ifdepth;
int ifsatisfied[NIF];
int skipping;
char rcsid[] = "$Version 1.2 $ $Revision: 1.1 $ $Date: 2001-04-19 08:20:22 $";
int
#ifdef _WIN32
__cdecl
#endif // _WIN32
main(int argc, char **argv)
{
Tokenrow tr;
time_t t;
char ebuf[BUFSIZ];
fprintf(stderr,"%s","cpp version 17.8.1999\n");
setbuf(stderr, ebuf);
t = time(NULL);
curtime = ctime(&t);
maketokenrow(3, &tr);
expandlex();
setup(argc, argv);
fixlex();
if (!Pflag)
genline();
process(&tr);
flushout();
fflush(stderr);
exit(nerrs > 0);
return 0;
}
void
process(Tokenrow * trp)
{
int anymacros = 0; /* S390: XDBX strzt ab! */
for (;;)
{
if (trp->tp >= trp->lp)
{
trp->tp = trp->lp = trp->bp;
outptr = outbuf;
anymacros |= gettokens(trp, 1);
trp->tp = trp->bp;
}
if (trp->tp->type == END)
{
if (--incdepth >= 0)
{
if (cursource->ifdepth)
error(ERROR,
"Unterminated conditional in #include");
unsetsource();
cursource->line += cursource->lineinc;
trp->tp = trp->lp;
if (!Pflag)
genline();
continue;
}
if (ifdepth)
error(ERROR, "Unterminated #if/#ifdef/#ifndef");
break;
}
if (trp->tp->type == SHARP)
{
trp->tp += 1;
control(trp);
}
else
if (!skipping && anymacros)
expandrow(trp, NULL);
if (skipping)
setempty(trp);
puttokens(trp);
anymacros = 0;
cursource->line += cursource->lineinc;
if (cursource->lineinc > 1)
{
if (!Pflag)
genline();
}
}
}
void
control(Tokenrow * trp)
{
Nlist *np;
Token *tp;
tp = trp->tp;
if (tp->type != NAME)
{
if (tp->type == NUMBER)
goto kline;
if (tp->type != NL)
error(ERROR, "Unidentifiable control line");
return; /* else empty line */
}
if ((np = lookup(tp, 0)) == NULL || (np->flag & ISKW) == 0 && !skipping)
{
error(WARNING, "Unknown preprocessor control %t", tp);
return;
}
if (skipping)
{
switch (np->val)
{
case KENDIF:
if (--ifdepth < skipping)
skipping = 0;
--cursource->ifdepth;
setempty(trp);
return;
case KIFDEF:
case KIFNDEF:
case KIF:
if (++ifdepth >= NIF)
error(FATAL, "#if too deeply nested");
++cursource->ifdepth;
return;
case KELIF:
case KELSE:
if (ifdepth <= skipping)
break;
return;
default:
return;
}
}
switch (np->val)
{
case KDEFINE:
dodefine(trp);
break;
case KUNDEF:
tp += 1;
if (tp->type != NAME || trp->lp - trp->bp != 4)
{
error(ERROR, "Syntax error in #undef");
break;
}
if ((np = lookup(tp, 0)) != NULL)
{
np->flag &= ~ISDEFINED;
if (Mflag)
{
if (np->ap)
error(INFO, "Macro deletion of %s(%r)", np->name, np->ap);
else
error(INFO, "Macro deletion of %s", np->name);
}
}
break;
case KPRAGMA:
case KIDENT:
for (tp = trp->tp - 1; ((tp->type != NL) && (tp < trp->lp)); tp++)
tp->type = UNCLASS;
return;
case KIFDEF:
case KIFNDEF:
case KIF:
if (++ifdepth >= NIF)
error(FATAL, "#if too deeply nested");
++cursource->ifdepth;
ifsatisfied[ifdepth] = 0;
if (eval(trp, np->val))
ifsatisfied[ifdepth] = 1;
else
skipping = ifdepth;
break;
case KELIF:
if (ifdepth == 0)
{
error(ERROR, "#elif with no #if");
return;
}
if (ifsatisfied[ifdepth] == 2)
error(ERROR, "#elif after #else");
if (eval(trp, np->val))
{
if (ifsatisfied[ifdepth])
skipping = ifdepth;
else
{
skipping = 0;
ifsatisfied[ifdepth] = 1;
}
}
else
skipping = ifdepth;
break;
case KELSE:
if (ifdepth == 0 || cursource->ifdepth == 0)
{
error(ERROR, "#else with no #if");
return;
}
if (ifsatisfied[ifdepth] == 2)
error(ERROR, "#else after #else");
if (trp->lp - trp->bp != 3)
error(ERROR, "Syntax error in #else");
skipping = ifsatisfied[ifdepth] ? ifdepth : 0;
ifsatisfied[ifdepth] = 2;
break;
case KENDIF:
if (ifdepth == 0 || cursource->ifdepth == 0)
{
error(ERROR, "#endif with no #if");
return;
}
--ifdepth;
--cursource->ifdepth;
if (trp->lp - trp->bp != 3)
error(WARNING, "Syntax error in #endif");
break;
case KERROR:
trp->tp = tp + 1;
error(WARNING, "#error directive: %r", trp);
break;
case KLINE:
trp->tp = tp + 1;
expandrow(trp, "<line>");
tp = trp->bp + 2;
kline:
if (tp + 1 >= trp->lp || tp->type != NUMBER || tp + 3 < trp->lp
|| (tp + 3 == trp->lp && ((tp + 1)->type != STRING) || *(tp + 1)->t == 'L'))
{
error(ERROR, "Syntax error in #line");
return;
}
cursource->line = atol((char *) tp->t) - 1;
if (cursource->line < 0 || cursource->line >= 32768)
error(WARNING, "#line specifies number out of range");
tp = tp + 1;
if (tp + 1 < trp->lp)
cursource->filename = (char *) newstring(tp->t + 1, tp->len - 2, 0);
return;
case KDEFINED:
error(ERROR, "Bad syntax for control line");
break;
case KIMPORT:
doinclude(trp, -1, 1);
trp->lp = trp->bp;
return;
case KINCLUDE:
doinclude(trp, -1, 0);
trp->lp = trp->bp;
return;
case KINCLUDENEXT:
doinclude(trp, cursource->pathdepth, 0);
trp->lp = trp->bp;
return;
case KEVAL:
eval(trp, np->val);
break;
default:
error(ERROR, "Preprocessor control `%t' not yet implemented", tp);
break;
}
setempty(trp);
return;
}
void *
domalloc(int size)
{
void *p = malloc(size);
if (p == NULL)
error(FATAL, "Out of memory from malloc");
return p;
}
void
dofree(void *p)
{
free(p);
}
void
error(enum errtype type, char *string,...)
{
va_list ap;
char c, *cp, *ep;
Token *tp;
Tokenrow *trp;
Source *s;
int i;
fprintf(stderr, "cpp: ");
for (s = cursource; s; s = s->next)
if (*s->filename)
fprintf(stderr, "%s:%d ", s->filename, s->line);
va_start(ap, string);
for (ep = string; *ep; ep++)
{
if (*ep == '%')
{
switch (*++ep)
{
case 'c':
c = va_arg(ap, char);
fprintf(stderr, "%c", c);
break;
case 's':
cp = va_arg(ap, char *);
fprintf(stderr, "%s", cp);
break;
case 'd':
i = va_arg(ap, int);
fprintf(stderr, "%d", i);
break;
case 't':
tp = va_arg(ap, Token *);
fprintf(stderr, "%.*s", tp->len, tp->t);
break;
case 'r':
trp = va_arg(ap, Tokenrow *);
for (tp = trp->tp; tp < trp->lp && tp->type != NL; tp++)
{
if (tp > trp->tp && tp->wslen)
fputc(' ', stderr);
fprintf(stderr, "%.*s", tp->len, tp->t);
}
break;
default:
fputc(*ep, stderr);
break;
}
}
else
fputc(*ep, stderr);
}
va_end(ap);
fputc('\n', stderr);
if (type == FATAL)
exit(1);
if (type != WARNING)
nerrs = 1;
fflush(stderr);
}
This diff is collapsed.
#include <stdio.h>
#include <string.h>
#define EPR fprintf(stderr,
#define ERR(str, chr) if(opterr) { EPR "%s%c\n", str, chr); }
int opterr = 1;
int optind = 1;
int optopt;
char *optarg;
int
getopt(int argc, char *const argv[], const char *opts)
{
static int sp = 1;
register c;
register char *cp;
if (sp == 1)
if (optind >= argc ||
argv[optind][0] != '-' || argv[optind][1] == '\0')
return -1;
else
if (strcmp(argv[optind], "--") == 0)
{
optind++;
return -1;
}
optopt = c = argv[optind][sp];
if (c == ':' || (cp = strchr(opts, c)) == 0)
{
ERR(": illegal option -- ", c);
if (argv[optind][++sp] == '\0')
{
optind++;
sp = 1;
}
return '?';
}
if (*++cp == ':')
{
if (argv[optind][sp + 1] != '\0')
optarg = &argv[optind++][sp + 1];
else
if (++optind >= argc)
{
ERR(": option requires an argument -- ", c);
sp = 1;
return '?';
}
else
optarg = argv[optind++];
sp = 1;
}
else
{
if (argv[optind][++sp] == '\0')
{
sp = 1;
optind++;
}
optarg = 0;
}
return c;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#if (defined(_WIN32) || defined(_MSDOS) || defined(__IBMC__)) && !(defined S390)
# include <io.h>
#else
# include <unistd.h>
#endif
#ifdef __hpux
# define _HPUX_SOURCE
#endif
#ifdef _MSC_VER
# define _POSIX_
#endif
#ifdef S390
# define PATH_MAX _POSIX_PATH_MAX
#endif
#ifdef __IBMC__
# include <fcntl.h>
# define PATH_MAX _MAX_PATH
#endif
#include <limits.h>
#include "cpp.h"
Includelist includelist[NINCLUDE];
Wraplist wraplist[NINCLUDE];
void
doinclude(Tokenrow * trp, int depth, int import)
{
char fname[PATH_MAX], iname[PATH_MAX];
Includelist *ip;
int angled, len, fd, i;
trp->tp += 1;
if (trp->tp >= trp->lp)
goto syntax;
if (trp->tp->type != STRING && trp->tp->type != LT)
{
len = trp->tp - trp->bp;
expandrow(trp, "<include>");
trp->tp = trp->bp + len;
}
if (trp->tp->type == STRING)
{
len = trp->tp->len - 2;
if (len > sizeof(fname) - 1)
len = sizeof(fname) - 1;
strncpy(fname, (char *) trp->tp->t + 1, len);
angled = 0;
}
else
{
if (trp->tp->type == LT)
{
len = 0;
trp->tp++;
while (trp->tp->type != GT)
{
if (trp->tp > trp->lp || len + trp->tp->len + 2 >= sizeof(fname))
goto syntax;
strncpy(fname + len, (char *) trp->tp->t, trp->tp->len);
len += trp->tp->len;
trp->tp++;
}
angled = 1;
}
else
goto syntax;
}
trp->tp += 2;
if (trp->tp < trp->lp || len == 0)
goto syntax;
fname[len] = '\0';
if (fname[0] == '/')
{
fd = open(fname, O_RDONLY);
strcpy(iname, fname);
}
else
{
for (fd = -1, i = (depth < 0) ? (NINCLUDE - 1) : (depth - 1); i >= 0; i--)
{
ip = &includelist[i];
if (ip->file == NULL || ip->deleted || (angled && ip->always == 0))
continue;
if (strlen(fname) + strlen(ip->file) + 2 > sizeof(iname))
continue;
strcpy(iname, ip->file);
strcat(iname, "/");
strcat(iname, fname);
if ((fd = open(iname, O_RDONLY)) >= 0)
break;
}
}
if (fd >= 0)
{
if (++incdepth > NINC )
error(FATAL, "#%s too deeply nested", import ? "import" : "include");
if (Xflag)
genimport(fname, angled, iname, import);
if (Iflag)
error(INFO, "Open %s file [%s]", import ? "import" : "include", iname );
for (i = NINCLUDE - 1; i >= 0; i--)
{
if ((wraplist[i].file != NULL) &&
(strncmp(wraplist[i].file, iname, strlen(wraplist[i].file)) == 0))
break;
}
setsource((char *) newstring((uchar *) iname, strlen(iname), 0), i, fd, NULL, (i >= 0) ? 1 : 0);
if (!Pflag)
genline();
}
else
{
trp->tp = trp->bp + 2;
error(ERROR, "Could not find %s file %r", import ? "import" : "include", trp);
}
return;
syntax:
error(ERROR, "Syntax error in #%s", import ? "import" : "include");
return;
}
/*
* Generate a line directive for cursource
*/
void
genline(void)
{
static Token ta = {UNCLASS};
static Tokenrow tr = {&ta, &ta, &ta + 1, 1};
uchar *p;
ta.t = p = (uchar *) outptr;
strcpy((char *) p, "#line ");
p += sizeof("#line ") - 1;
p = (uchar *) outnum((char *) p, cursource->line);
*p++ = ' ';
*p++ = '"';
if (cursource->filename[0] != '/' && wd[0])
{
strcpy((char *) p, wd);
p += strlen(wd);
*p++ = '/';
}
strcpy((char *) p, cursource->filename);
p += strlen((char *) p);
*p++ = '"';
*p++ = '\n';
ta.len = (char *) p - outptr;
outptr = (char *) p;
tr.tp = tr.bp;
puttokens(&tr);
}
/*
* Generate a pragma import/include directive
*/
void
genimport(char *fname, int angled, char *iname, int import)
{
static Token ta = {UNCLASS};
static Tokenrow tr = {&ta, &ta, &ta + 1, 1};
uchar *p;
ta.t = p = (uchar *) outptr;
if (import)
strcpy((char *) p, "#pragma import");
else
strcpy((char *) p, "#pragma include");
p += strlen((char *) p);
*p++ = '(';
*p++ = angled ? '<' : '"';
strcpy((char *) p, fname);
p += strlen(fname);
*p++ = angled ? '>' : '"';
*p++ = ',';
*p++ = '"';
strcpy((char *) p, iname);
p += strlen(iname);
*p++ = '"';
*p++ = ')';
*p++ = '\n';
ta.len = (char *) p - outptr;
outptr = (char *) p;
tr.tp = tr.bp;
puttokens(&tr);
}
/*
* Generate a extern C directive
*/
void
genwrap(int end)
{
static Token ta = {UNCLASS};
static Tokenrow tr = {&ta, &ta, &ta + 1, 1};
uchar *p;
if (Cplusplus)
{
ta.t = p = (uchar *) outptr;
if (! end)
strcpy((char *) p, "extern \"C\" {");
else
strcpy((char *) p, "}");
p += strlen((char *) p);
*p++ = '\n';
ta.len = (char *) p - outptr;
outptr = (char *) p;
tr.tp = tr.bp;
puttokens(&tr);
}
}
This diff is collapsed.
This diff is collapsed.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cpp.h"
/*
Nlist * pMacro;
Token * pTokenWhereMacroBecomesValid;
struct macroValidator *
pNext;
*/
void
mvl_init(MacroValidatorList * out_pValidators)
{
out_pValidators->pFirst = 0;
out_pValidators->nextFreeIdentifier = 1;
}
void
mvl_destruct(MacroValidatorList * out_pValidators)
{
MacroValidator * pV = out_pValidators->pFirst;
MacroValidator * pDel;
for ( pDel = out_pValidators->pFirst;
pDel != 0;
pDel = pV )
{
pV = pV->pNext;
pDel->pMacro->flag &= (~ISACTIVE);
dofree(pDel);
}
}
#define INVALID_TILL_ENDOFROW 32000
/* If in_pTokenWhereMacroBecomesValid == 0, the macro is at row end
and therefore there does not exist any token, where the macro becomes
valid again. It is revalidated, when the row was processed complete.
*/
void
mvl_add( MacroValidatorList * inout_pValidators,
Nlist * in_pMacro,
Token * in_pTokenWhereMacroBecomesValid )
{
MacroValidator * pNew = new(MacroValidator);
pNew->pMacro = in_pMacro;
if (in_pTokenWhereMacroBecomesValid == 0)
{
pNew->nTokenWhereMacroBecomesValid = INVALID_TILL_ENDOFROW;
}
else if (in_pTokenWhereMacroBecomesValid->identifier > 0)
{
pNew->nTokenWhereMacroBecomesValid = in_pTokenWhereMacroBecomesValid->identifier;
}
else
{
pNew->nTokenWhereMacroBecomesValid = inout_pValidators->nextFreeIdentifier;
in_pTokenWhereMacroBecomesValid->identifier = inout_pValidators->nextFreeIdentifier;
inout_pValidators->nextFreeIdentifier++;
}
pNew->pNext = inout_pValidators->pFirst;
inout_pValidators->pFirst = pNew;
}
void
mvl_move( MacroValidatorList * inout_pValidators,
int in_nSpace )
{
/*
MacroValidator * pV;
for ( pV = inout_pValidators->pFirst;
pV != 0;
pV = pV->pNext )
{
pV->pTokenWhereMacroBecomesValid += in_nSpace;
}
*/
}
void
mvl_check( MacroValidatorList * inout_pValidators,
Token * inout_pTokenToCheck)
{
MacroValidator * pV; /* Running pointer */
MacroValidator * pCheckedOnes; /* Here new list is built. */
pCheckedOnes = 0;
for ( pV = inout_pValidators->pFirst;
pV != 0;
pV = inout_pValidators->pFirst )
{
inout_pValidators->pFirst = pV->pNext;
if (pV->nTokenWhereMacroBecomesValid == inout_pTokenToCheck->identifier)
{
pV->pMacro->flag &= (~ISACTIVE);
dofree(pV);
}
else
{
pV->pNext = pCheckedOnes;
pCheckedOnes = pV;
}
} /* end for */
/* Assign new built list (too old ones were removed) to
original list:
*/
inout_pValidators->pFirst = pCheckedOnes;
}
void
tokenrow_zeroTokenIdentifiers(Tokenrow* trp)
{
Token * tp;
for (tp = trp->bp; tp < trp->lp; tp++)
{
tp->identifier = 0;
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cpp.h"
extern int getopt(int, char *const *, const char *);
extern char *optarg;
extern int optind;
extern int Cplusplus;
Nlist *kwdefined;
char wd[128];
/*
ER: Tabelle extra gross gemacht, da es anscheinend ein Problem mit der
der Verkettung gibt, irgendwann irgendwo wird mal ein nlist->next
ueberschrieben, was in eineme SIGSEGV resultiert.
Den GDB mit watchpoint hab ich aber nach 2 Tagen abgebrochen..
so loeppts jedenfalls erstmal..
*/
#define NLSIZE 15000
static Nlist *nlist[NLSIZE];
struct kwtab
{
char *kw;
int val;
int flag;
} kwtab[] =
{
"if", KIF, ISKW,
"ifdef", KIFDEF, ISKW,
"ifndef", KIFNDEF, ISKW,
"elif", KELIF, ISKW,
"else", KELSE, ISKW,
"endif", KENDIF, ISKW,
"include", KINCLUDE, ISKW,
"include_next", KINCLUDENEXT, ISKW,
"import", KIMPORT, ISKW,
"define", KDEFINE, ISKW,
"undef", KUNDEF, ISKW,
"line", KLINE, ISKW,
"error", KERROR, ISKW,
"pragma", KPRAGMA, ISKW,
"ident", KIDENT, ISKW,
"eval", KEVAL, ISKW,
"defined", KDEFINED, ISDEFINED + ISUNCHANGE,
"machine", KMACHINE, ISDEFINED + ISUNCHANGE,
"__LINE__", KLINENO, ISMAC + ISUNCHANGE,
"__FILE__", KFILE, ISMAC + ISUNCHANGE,
"__DATE__", KDATE, ISMAC + ISUNCHANGE,
"__TIME__", KTIME, ISMAC + ISUNCHANGE,
"__STDC__", KSTDC, ISUNCHANGE,
NULL
};
unsigned long namebit[077 + 1];
Nlist *np;
void
setup_kwtab(void)
{
struct kwtab *kp;
Nlist *np;
Token t;
static Token deftoken[1] = {{NAME, 0, 0, 7, (uchar *) "defined"}};
static Tokenrow deftr = {deftoken, deftoken, deftoken + 1, 1};
for (kp = kwtab; kp->kw; kp++)
{
t.t = (uchar *) kp->kw;
t.len = strlen(kp->kw);
np = lookup(&t, 1);
np->flag = kp->flag;
np->val = kp->val;
if (np->val == KDEFINED)
{
kwdefined = np;
np->val = NAME;
np->vp = &deftr;
np->ap = 0;
}
}
}
Nlist *
lookup(Token * tp, int install)
{
unsigned int h;
Nlist *np;
uchar *cp, *cpe;
h = 0;
for (cp = tp->t, cpe = cp + tp->len; cp < cpe;)
h += *cp++;
h %= NLSIZE;
np = nlist[h];
while (np)
{
if (*tp->t == *np->name && tp->len == (unsigned int)np->len
&& strncmp((char *)tp->t, (char *)np->name, tp->len) == 0)
return np;
np = np->next;
}
if (install)
{
np = new(Nlist);
np->vp = NULL;
np->ap = NULL;
np->flag = 0;
np->val = 0;
np->len = tp->len;
np->name = newstring(tp->t, tp->len, 0);
np->next = nlist[h];
nlist[h] = np;
quickset(tp->t[0], tp->len > 1 ? tp->t[1] : 0);
return np;
}
return NULL;
}
This diff is collapsed.
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#if (defined(_WIN32) || defined(_MSDOS) || defined(__IBMC__)) && !(defined S390)
#include <io.h>
#else
#include <unistd.h>
#endif
#include "cpp.h"
extern int getopt(int, char *const *, const char *);
extern char *optarg, rcsid[];
extern int optind;
int Pflag = 0; /* print no line information */
int Iflag = 0; /* print includes */
int Mflag = 0; /* print macor expansion */
int Aflag = 0; /* translate character sets */
int Xflag = 0; /* print pragma for include/import */
int Vflag = 0; /* verbose flag */
int Cflag = 0; /* do not remove any comments */
int Dflag = 0; /* add parameter check to delete op */
int Cplusplus = 0;
void
setup(int argc, char **argv)
{
int c, fd, i, n;
char *fp, *dp;
Tokenrow tr;
extern void setup_kwtab(void);
setup_kwtab();
while ((c = getopt(argc, argv, "NOPV:I:D:U:F:A:X:u:l:+")) != -1)
switch (c)
{
case 'N':
for (i = 0; i < NINCLUDE; i++)
if (includelist[i].always == 1)
includelist[i].deleted = 1;
break;
case 'I':
for (i = NINCLUDE - 2; i >= 0; i--)
{
if (includelist[i].file == NULL)
{
includelist[i].always = 1;
includelist[i].file = optarg;
break;
}
}
if (i < 0)
error(FATAL, "Too many -I directives");
break;
case 'D':
case 'U':
case 'A':
setsource("<cmdarg>", -1, -1, optarg, 0);
maketokenrow(3, &tr);
gettokens(&tr, 1);
doadefine(&tr, c);
unsetsource();
break;
case 'P': /* Lineinfo */
Pflag++;
break;
case 'V':
for (n = 0; (c = optarg[n]) != '\0'; n++)
switch (c)
{
case 'i':
Iflag++;
break;
case 'm':
Mflag = 1;
break;
case 'x':
Mflag = 2;
break;
case 't':
Vflag++;
break;
case 'v':
fprintf(stderr, "%s %s\n", argv[0], rcsid);
break;
default:
error(WARNING, "Unknown verbose option %c", c);
}
break;
case 'X':
for (n = 0; (c = optarg[n]) != '\0'; n++)
switch (c)
{
case 'a':
Aflag++;
break;
case 'i':
Xflag++;
break;
case 'c':
Cflag++;
break;
case 'd':
Dflag++;
break;
case 'w':
dp = &optarg[n + 1];
n += strlen(dp);
while (isspace(*dp)) dp++;
for (i = NINCLUDE - 1; i >= 0; i--)
{
if (wraplist[i].file == NULL)
{
wraplist[i].file = dp;
break;
}
}
if (i < 0)
error(WARNING, "Too many -Xw directives");
break;
default:
error(WARNING, "Unknown extension option %c", c);
}
break;
case '+':
Cplusplus++;
break;
case 'u': /* -undef fuer GCC (dummy) */
case 'l': /* -lang-c++ fuer GCC (dummy) */
break;
default:
break;
}
dp = ".";
fp = "<stdin>";
fd = 0;
if (optind < argc)
{
if ((fp = strrchr(argv[optind], '/')) != NULL)
{
int len = fp - argv[optind];
dp = (char *) newstring((uchar *) argv[optind], len + 1, 0);
dp[len] = '\0';
}
fp = (char *) newstring((uchar *) argv[optind], strlen(argv[optind]), 0);
if ((fd = open(fp, O_RDONLY)) <= 0)
error(FATAL, "Can't open input file %s", fp);
}
if (optind + 1 < argc)
{
int fdo = creat(argv[optind + 1], 0666);
if (fdo < 0)
error(FATAL, "Can't open output file %s", argv[optind + 1]);
dup2(fdo, 1);
}
includelist[NINCLUDE - 1].always = 0;
includelist[NINCLUDE - 1].file = dp;
setsource(fp, -1, fd, NULL, 0);
}
/* memmove is defined here because some vendors don't provide it at
all and others do a terrible job (like calling malloc) */
#if !defined(__IBMC__) && !defined(_WIN32)
void *
memmove(void *dp, const void *sp, size_t n)
{
unsigned char *cdp, *csp;
if (n <= 0)
return 0;
cdp = dp;
csp = (unsigned char *) sp;
if (cdp < csp)
{
do
{
*cdp++ = *csp++;
} while (--n);
}
else
{
cdp += n;
csp += n;
do
{
*--cdp = *--csp;
} while (--n);
}
return 0;
}
#endif
/* $Id: cpp.h,v 1.1 2001-04-19 08:20:22 nf Exp $ */
#define INS 32768 /* input buffer */
#define OBS 8092 /* outbut buffer */
#define NARG 32 /* Max number arguments to a macro */
#define NINCLUDE 32 /* Max number of include directories (-I) */
#define NIF 64 /* depth of nesting of #if */
#define NINC 32 /* depth of nesting of #include */
#ifndef EOF
#define EOF (-1)
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef __alpha
typedef unsigned char uchar;
#endif
enum toktype
{
END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP,
EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS,
ARROW, SBRA, SKET, LP, RP, DOT, AND, STAR, PLUS, MINUS,
TILDE, NOT, SLASH, PCT, LT, GT, CIRC, OR, QUEST,
COLON, ASGN, COMMA, SHARP, SEMIC, CBRA, CKET,
ASPLUS, ASMINUS, ASSTAR, ASSLASH, ASPCT, ASCIRC, ASLSH,
ASRSH, ASOR, ASAND, ELLIPS,
DSHARP1, NAME1, NAME2, DEFINED, UMINUS, ARCHITECTURE, IDENT,
COMMENT
};
enum kwtype
{
KIF, KIFDEF, KIFNDEF, KELIF, KELSE, KENDIF, KINCLUDE, KINCLUDENEXT,
KIMPORT, KDEFINE, KUNDEF, KLINE, KERROR, KPRAGMA, KIDENT, KDEFINED,
KMACHINE, KLINENO, KFILE, KDATE, KTIME, KSTDC, KEVAL
};
#define ISDEFINED 0x01 /* has #defined value */
#define ISKW 0x02 /* is PP keyword */
#define ISUNCHANGE 0x04 /* can't be #defined in PP */
#define ISMAC 0x08 /* builtin macro, e.g. __LINE__ */
#define ISARCHITECTURE 0x10 /* architecture */
#define ISACTIVE 0x80 /* is macro currently expanded */
#ifdef S390
/* 0xfe und 0xfd fallen auf der S/390 auf Control-Chars */
#define EOB 0x07
#define EOFC 0x08
#else
#define EOB 0xFE /* sentinel for end of input buffer */
#define EOFC 0xFD /* sentinel for end of input file */
#endif
#define XPWS 1 /* token flag: white space to assure token sep. */
#define XTWS 2
typedef struct token
{
unsigned char type;
unsigned char flag;
unsigned int wslen;
unsigned int len;
uchar *t;
unsigned int identifier; /* used from macro processor to identify where a macro becomes valid again. */
} Token;
typedef struct tokenrow
{
Token *tp; /* current one to scan */
Token *bp; /* base (allocated value) */
Token *lp; /* last+1 token used */
int max; /* number allocated */
} Tokenrow;
typedef struct source
{
char *filename; /* name of file of the source */
int line; /* current line number */
int lineinc; /* adjustment for \\n lines */
uchar *inb; /* input buffer */
uchar *inp; /* input pointer */
uchar *inl; /* end of input */
int fd; /* input source */
int ifdepth; /* conditional nesting in include */
int pathdepth;
int wrap;
struct source *next; /* stack for #include */
} Source;
typedef struct nlist
{
struct nlist *next;
uchar *name;
int len;
Tokenrow *vp; /* value as macro */
Tokenrow *ap; /* list of argument names, if any */
char val; /* value as preprocessor name */
char flag; /* is defined, is pp name */
uchar *loc; /* location of definition */
} Nlist;
typedef struct includelist
{
char deleted;
char always;
char *file;
} Includelist;
typedef struct wraplist
{
char *file;
} Wraplist;
#define new(t) (t *)domalloc(sizeof(t))
#define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037)))
#define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037))
extern unsigned long namebit[077 + 1];
enum errtype
{
INFO, WARNING, ERROR, FATAL
};
// NP
typedef struct macroValidator
{
Nlist * pMacro;
unsigned int nTokenWhereMacroBecomesValid;
struct macroValidator *
pNext;
} MacroValidator;
typedef struct mvl
{
MacroValidator * pFirst;
unsigned int nextFreeIdentifier;
} MacroValidatorList;
void mvl_init(
MacroValidatorList *
out_pValidators);
void mvl_destruct(
MacroValidatorList *
out_pValidators);
/* Adds MacroValidator to the list.
*/
void mvl_add(
MacroValidatorList *
inout_pValidators,
Nlist * in_pMacro,
Token * in_pTokenWhereMacroBecomesValid);
/* Updates all token pointers within the list, when the tokens have
moved, by
pTokenWhereMacroBecomesValid += in_nNrofTokens;
.
*/
void mvl_move(
MacroValidatorList *
inout_pValidators,
int in_nSpace); // in pointer units.
/* Checks if one of the validators within the list points to
the token in_pTokenToCheck. If so, the macro is set valid and
the validator is removed.
*/
void mvl_check(
MacroValidatorList *
inout_pValidators,
Token * inout_pTokenToCheck);
void tokenrow_zeroTokenIdentifiers(Tokenrow* trp);
void expandlex(void);
void fixlex(void);
void setup(int, char **);
int gettokens(Tokenrow *, int);
int comparetokens(Tokenrow *, Tokenrow *);
Source *setsource(char *, int, int, char *, int);
void unsetsource(void);
void puttokens(Tokenrow *);
void process(Tokenrow *);
void *domalloc(int);
void dofree(void *);
void error(enum errtype, char *,...);
void flushout(void);
int fillbuf(Source *);
int trigraph(Source *);
int foldline(Source *);
Nlist *lookup(Token *, int);
void control(Tokenrow *);
void dodefine(Tokenrow *);
void doadefine(Tokenrow *, int);
void doinclude(Tokenrow *, int, int);
void doif(Tokenrow *, enum kwtype);
void expand(Tokenrow *, Nlist *, MacroValidatorList *);
void builtin(Tokenrow *, int);
int gatherargs(Tokenrow *, Tokenrow **, int *);
void substargs(Nlist *, Tokenrow *, Tokenrow **);
void expandrow(Tokenrow *, char *);
void maketokenrow(int, Tokenrow *);
Tokenrow *copytokenrow(Tokenrow *, Tokenrow *);
Token *growtokenrow(Tokenrow *);
Tokenrow *normtokenrow(Tokenrow *);
void adjustrow(Tokenrow *, int);
void movetokenrow(Tokenrow *, Tokenrow *);
void insertrow(Tokenrow *, int, Tokenrow *);
void peektokens(Tokenrow *, char *);
void doconcat(Tokenrow *);
Tokenrow *stringify(Tokenrow *);
int lookuparg(Nlist *, Token *);
long eval(Tokenrow *, int);
void genline(void);
void genimport(char *, int, char *, int);
void genwrap(int);
void setempty(Tokenrow *);
void makespace(Tokenrow *, Token *);
char *outnum(char *, int);
int digit(int);
uchar *newstring(uchar *, int, int);
#define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
extern char *outptr;
extern Token nltoken;
extern Source *cursource;
extern char *curtime;
extern int incdepth;
extern int ifdepth;
extern int ifsatisfied[NIF];
extern int Mflag;
extern int Iflag;
extern int Pflag;
extern int Aflag;
extern int Lflag;
extern int Xflag;
extern int Vflag;
extern int Cflag;
extern int Dflag;
extern int Cplusplus;
extern int skipping;
extern Nlist *kwdefined;
extern Includelist includelist[NINCLUDE];
extern Wraplist wraplist[NINCLUDE];
extern char wd[];
#*************************************************************************
#*
#* Makefile fuer Cpp NP 23.12.1998
#*
#*************************************************************************
PRJ=..
PRJNAME=soltools
TARGET=cpp
TARGETTYPE=CUI
# --- Settings -----------------------------------------------------
.INCLUDE : settings.mk
# --- Files --------------------------------------------------------
OBJFILES= \
$(OBJ)$/_cpp.obj \
$(OBJ)$/_eval.obj \
$(OBJ)$/_getopt.obj \
$(OBJ)$/_include.obj \
$(OBJ)$/_lex.obj \
$(OBJ)$/_macro.obj \
$(OBJ)$/_mcrvalid.obj \
$(OBJ)$/_nlist.obj \
$(OBJ)$/_tokens.obj \
$(OBJ)$/_unix.obj
APP1TARGET = $(TARGET)
APP1STACK = 1000000
APP1OBJS = $(OBJ)$/_cpp.obj
APP1STDLIBS = $(STDLIBCUIMT)
APP1LIBS = $(LB)$/$(TARGET).lib
APP1DEPN = $(LB)$/$(TARGET).lib
# --- Targets ------------------------------------------------------
.INCLUDE : target.mk
......@@ -2,4 +2,5 @@ so soltools usr1 - all so_usr1 NULL
so soltools\ldump nmake - n so_ldump NULL
so soltools\mkdepend nmake - all so_mkdep NULL
so soltools\checkdll nmake - u so_chkdl NULL
so soltools\cpp nmake - all so_cpp__ NULL
so soltools\javadep nmake - all so_jvdep NULL
......@@ -4,3 +4,4 @@
..\%__SRC%\bin\javadep.exe %_DEST%\bin%_EXT%\javadep.exe
..\%__SRC%\bin\javadep %_DEST%\bin%_EXT%\javadep
..\%__SRC%\bin\checkdll %_DEST%\bin%_EXT%\checkdll
..\%__SRC%\bin\cpp %_DEST%\bin%_EXT%\cpp.lcc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment