Use the QVM build toolchain from ioq3
This commit is contained in:
@@ -9,7 +9,7 @@ char rcsid[] = "cpp.c - faked rcsid";
|
||||
|
||||
#define OUTS 16384
|
||||
char outbuf[OUTS];
|
||||
char *outp = outbuf;
|
||||
char *outbufp = outbuf;
|
||||
Source *cursource;
|
||||
int nerrs;
|
||||
struct token nltoken = { NL, 0, 0, 0, 1, (uchar*)"\n" };
|
||||
@@ -19,6 +19,15 @@ int ifdepth;
|
||||
int ifsatisfied[NIF];
|
||||
int skipping;
|
||||
|
||||
time_t reproducible_time()
|
||||
{
|
||||
char *source_date_epoch;
|
||||
time_t t;
|
||||
if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
|
||||
(t = (time_t)strtol(source_date_epoch, NULL, 10)) <= 0)
|
||||
return time(NULL);
|
||||
return t;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@@ -28,7 +37,7 @@ main(int argc, char **argv)
|
||||
char ebuf[BUFSIZ];
|
||||
|
||||
setbuf(stderr, ebuf);
|
||||
t = time(NULL);
|
||||
t = reproducible_time();
|
||||
curtime = ctime(&t);
|
||||
maketokenrow(3, &tr);
|
||||
expandlex();
|
||||
@@ -51,7 +60,7 @@ process(Tokenrow *trp)
|
||||
for (;;) {
|
||||
if (trp->tp >= trp->lp) {
|
||||
trp->tp = trp->lp = trp->bp;
|
||||
outp = outbuf;
|
||||
outbufp = outbuf;
|
||||
anymacros |= gettokens(trp, 1);
|
||||
trp->tp = trp->bp;
|
||||
}
|
||||
@@ -250,7 +259,6 @@ control(Tokenrow *trp)
|
||||
break;
|
||||
}
|
||||
setempty(trp);
|
||||
return;
|
||||
}
|
||||
|
||||
void *
|
||||
|
||||
@@ -143,7 +143,7 @@ void setobjname(char *);
|
||||
|
||||
char *basepath( char *fname );
|
||||
|
||||
extern char *outp;
|
||||
extern char *outbufp;
|
||||
extern Token nltoken;
|
||||
extern Source *cursource;
|
||||
extern char *curtime;
|
||||
|
||||
@@ -108,7 +108,6 @@ doinclude(Tokenrow *trp)
|
||||
return;
|
||||
syntax:
|
||||
error(ERROR, "Syntax error in #include");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -121,7 +120,7 @@ genline(void)
|
||||
static Tokenrow tr = { &ta, &ta, &ta+1, 1 };
|
||||
uchar *p;
|
||||
|
||||
ta.t = p = (uchar*)outp;
|
||||
ta.t = p = (uchar*)outbufp;
|
||||
strcpy((char*)p, "#line ");
|
||||
p += sizeof("#line ")-1;
|
||||
p = (uchar*)outnum((char*)p, cursource->line);
|
||||
@@ -134,8 +133,8 @@ genline(void)
|
||||
strcpy((char*)p, cursource->filename);
|
||||
p += strlen((char*)p);
|
||||
*p++ = '"'; *p++ = '\n';
|
||||
ta.len = (char*)p-outp;
|
||||
outp = (char*)p;
|
||||
ta.len = (char*)p-outbufp;
|
||||
outbufp = (char*)p;
|
||||
tr.tp = tr.bp;
|
||||
puttokens(&tr);
|
||||
}
|
||||
|
||||
@@ -511,6 +511,25 @@ foldline(Source *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This doesn't have proper tracking across read() to only remove \r from \r\n sequence.
|
||||
// The lexer doesn't correctly handle standalone \r anyway though.
|
||||
int
|
||||
crlf_to_lf(unsigned char *buf, int n) {
|
||||
int i, count;
|
||||
|
||||
count = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (buf[i] == '\r') {
|
||||
continue;
|
||||
}
|
||||
|
||||
buf[count++] = buf[i];
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int
|
||||
fillbuf(Source *s)
|
||||
{
|
||||
@@ -521,6 +540,7 @@ fillbuf(Source *s)
|
||||
error(FATAL, "Input buffer overflow");
|
||||
if (s->fd<0 || (n=read(s->fd, (char *)s->inl, INS/8)) <= 0)
|
||||
n = 0;
|
||||
n = crlf_to_lf(s->inl, n);
|
||||
if ((*s->inp&0xff) == EOB) /* sentinel character appears in input */
|
||||
*s->inp = EOFC;
|
||||
s->inl += n;
|
||||
|
||||
@@ -218,7 +218,6 @@ expand(Tokenrow *trp, Nlist *np)
|
||||
insertrow(trp, ntokc, &ntr);
|
||||
trp->tp -= rowlen(&ntr);
|
||||
dofree(ntr.bp);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -471,10 +470,10 @@ builtin(Tokenrow *trp, int biname)
|
||||
/* most are strings */
|
||||
tp->type = STRING;
|
||||
if (tp->wslen) {
|
||||
*outp++ = ' ';
|
||||
*outbufp++ = ' ';
|
||||
tp->wslen = 1;
|
||||
}
|
||||
op = outp;
|
||||
op = outbufp;
|
||||
*op++ = '"';
|
||||
switch (biname) {
|
||||
|
||||
@@ -509,7 +508,7 @@ builtin(Tokenrow *trp, int biname)
|
||||
}
|
||||
if (tp->type==STRING)
|
||||
*op++ = '"';
|
||||
tp->t = (uchar*)outp;
|
||||
tp->len = op - outp;
|
||||
outp = op;
|
||||
tp->t = (uchar*)outbufp;
|
||||
tp->len = op - outbufp;
|
||||
outbufp = op;
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ peektokens(Tokenrow *trp, char *str)
|
||||
if (str)
|
||||
fprintf(stderr, "%s ", str);
|
||||
if (tp<trp->bp || tp>trp->lp)
|
||||
fprintf(stderr, "(tp offset %d) ", tp-trp->bp);
|
||||
fprintf(stderr, "(tp offset %ld) ", (long int) (tp - trp->bp));
|
||||
for (tp=trp->bp; tp<trp->lp && tp<trp->bp+32; tp++) {
|
||||
if (tp->type!=NL) {
|
||||
int c = tp->t[tp->len];
|
||||
@@ -315,7 +315,7 @@ puttokens(Tokenrow *trp)
|
||||
if (wbp >= &wbuf[OBS]) {
|
||||
write(1, wbuf, OBS);
|
||||
if (wbp > &wbuf[OBS])
|
||||
memcpy(wbuf, wbuf+OBS, wbp - &wbuf[OBS]);
|
||||
memmove(wbuf, wbuf+OBS, wbp - &wbuf[OBS]);
|
||||
wbp -= OBS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include "cpp.h"
|
||||
|
||||
extern int lcc_getopt(int, char *const *, const char *);
|
||||
@@ -64,11 +65,22 @@ setup(int argc, char **argv)
|
||||
fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
|
||||
if ((fd = open(fp, 0)) <= 0)
|
||||
error(FATAL, "Can't open input file %s", fp);
|
||||
#ifdef WIN32
|
||||
_setmode(fd, _O_BINARY);
|
||||
#endif
|
||||
}
|
||||
if (optind+1<argc) {
|
||||
int fdo = creat(argv[optind+1], 0666);
|
||||
int fdo;
|
||||
#ifdef WIN32
|
||||
fdo = creat(argv[optind+1], _S_IREAD | _S_IWRITE);
|
||||
#else
|
||||
fdo = creat(argv[optind+1], 0666);
|
||||
#endif
|
||||
if (fdo<0)
|
||||
error(FATAL, "Can't open output file %s", argv[optind+1]);
|
||||
#ifdef WIN32
|
||||
_setmode(fdo, _O_BINARY);
|
||||
#endif
|
||||
dup2(fdo, 1);
|
||||
}
|
||||
if(Mflag)
|
||||
@@ -99,7 +111,8 @@ char *basepath( char *fname )
|
||||
/* memmove is defined here because some vendors don't provide it at
|
||||
all and others do a terrible job (like calling malloc) */
|
||||
// -- ouch, that hurts -- ln
|
||||
#ifndef MACOS_X /* always use the system memmove() on Mac OS X. --ryan. */
|
||||
/* always use the system memmove() on Mac OS X. --ryan. */
|
||||
#if !defined(__APPLE__) && !defined(_MSC_VER)
|
||||
#ifdef memmove
|
||||
#undef memmove
|
||||
#endif
|
||||
@@ -109,7 +122,7 @@ memmove(void *dp, const void *sp, size_t n)
|
||||
unsigned char *cdp, *csp;
|
||||
|
||||
if (n<=0)
|
||||
return 0;
|
||||
return dp;
|
||||
cdp = dp;
|
||||
csp = (unsigned char *)sp;
|
||||
if (cdp < csp) {
|
||||
@@ -123,6 +136,6 @@ memmove(void *dp, const void *sp, size_t n)
|
||||
*--cdp = *--csp;
|
||||
} while (--n);
|
||||
}
|
||||
return 0;
|
||||
return dp;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user