1989-02-07 11:04:05 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1994-06-27 08:03:14 +00:00
|
|
|
/* $Id$ */
|
1989-02-07 11:04:05 +00:00
|
|
|
/* M A C R O R E P L A C E M E N T */
|
2006-07-19 10:28:43 +00:00
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
#include <assert.h>
|
2006-07-19 10:28:43 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-05-12 19:45:55 +00:00
|
|
|
#include "parameters.h"
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
#ifndef NOPP
|
|
|
|
|
2017-11-10 22:31:11 +00:00
|
|
|
#include <ack_string.h>
|
1989-02-07 11:04:05 +00:00
|
|
|
#include <alloc.h>
|
2013-05-12 19:45:55 +00:00
|
|
|
#include "idf.h"
|
1989-02-07 11:04:05 +00:00
|
|
|
#include "input.h"
|
|
|
|
#include "macro.h"
|
|
|
|
#include "arith.h"
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include "replace.h"
|
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
extern struct idf *GetIdentifier();
|
|
|
|
extern int InputLevel;
|
|
|
|
struct repl *ReplaceList; /* list of currently active macros */
|
1989-02-07 11:04:05 +00:00
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
void macro2buffer();
|
|
|
|
void getactuals();
|
|
|
|
void expand_defined();
|
|
|
|
|
1989-02-07 11:04:05 +00:00
|
|
|
int
|
|
|
|
replace(idf)
|
|
|
|
register struct idf *idf;
|
|
|
|
{
|
|
|
|
/* replace is called by the lexical analyzer to perform
|
|
|
|
macro replacement. The routine actualy functions as a
|
|
|
|
higher interface to the real thing: expand_macro().
|
|
|
|
*/
|
|
|
|
struct repl *repl;
|
1989-09-29 16:20:38 +00:00
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
if (!(idf->id_macro)) return 0;
|
1989-09-29 16:20:38 +00:00
|
|
|
if (idf->id_macro->mc_flag & NOREPLACE)
|
1989-09-19 16:13:23 +00:00
|
|
|
return 0;
|
1989-02-07 11:04:05 +00:00
|
|
|
repl = new_repl();
|
1989-11-22 13:58:36 +00:00
|
|
|
repl->r_ptr = repl->r_text = Malloc(repl->r_size = LAPBUF);
|
1989-02-07 11:04:05 +00:00
|
|
|
repl->r_args = new_args();
|
1989-09-19 16:13:23 +00:00
|
|
|
repl->r_idf = idf;
|
1989-09-29 16:20:38 +00:00
|
|
|
if (!expand_macro(repl, idf))
|
1989-02-07 11:04:05 +00:00
|
|
|
return 0;
|
1989-09-19 16:13:23 +00:00
|
|
|
InputLevel++;
|
1990-04-25 15:09:51 +00:00
|
|
|
InsertText(repl->r_text, (int)(repl->r_ptr - repl->r_text));
|
1989-09-19 16:13:23 +00:00
|
|
|
idf->id_macro->mc_flag |= NOREPLACE;
|
1989-09-29 16:20:38 +00:00
|
|
|
repl->r_level = InputLevel;
|
1989-02-07 11:04:05 +00:00
|
|
|
repl->next = ReplaceList;
|
|
|
|
ReplaceList = repl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unstackrepl()
|
|
|
|
{
|
1989-09-19 16:13:23 +00:00
|
|
|
Unstacked++;
|
|
|
|
}
|
1989-02-07 11:04:05 +00:00
|
|
|
|
1989-11-22 13:58:36 +00:00
|
|
|
freeargs(args)
|
|
|
|
struct args *args;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
/* We must don't know how many parameters were specified, so be
|
|
|
|
* prepared to free all NPARAMS parameters.
|
|
|
|
* When an expvec is !0, the rawvec will also be !0.
|
|
|
|
* When an expvec is 0, all remaining vectors will also be 0.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NPARAMS; i++) {
|
|
|
|
if (args->a_expvec[i]) {
|
|
|
|
free(args->a_expvec[i]);
|
|
|
|
free(args->a_rawvec[i]);
|
|
|
|
} else break;
|
|
|
|
}
|
|
|
|
free_args(args);
|
|
|
|
}
|
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
EnableMacros()
|
|
|
|
{
|
|
|
|
register struct repl *r = ReplaceList, *prev = 0;
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(Unstacked > 0);
|
1989-09-19 16:13:23 +00:00
|
|
|
while(r) {
|
|
|
|
struct repl *nxt = r->next;
|
|
|
|
|
|
|
|
if (r->r_level > InputLevel) {
|
|
|
|
r->r_idf->id_macro->mc_flag &= ~NOREPLACE;
|
|
|
|
if (!prev) ReplaceList = nxt;
|
|
|
|
else prev->next = nxt;
|
1989-11-22 13:58:36 +00:00
|
|
|
free(r->r_text);
|
|
|
|
freeargs(r->r_args);
|
1989-09-19 16:13:23 +00:00
|
|
|
free_repl(r);
|
|
|
|
}
|
|
|
|
else prev = r;
|
|
|
|
r = nxt;
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
Unstacked = 0;
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
expand_macro(repl, idf)
|
1989-02-07 11:04:05 +00:00
|
|
|
register struct repl *repl;
|
|
|
|
register struct idf *idf;
|
|
|
|
{
|
|
|
|
/* expand_macro() does the actual macro replacement.
|
|
|
|
"idf" is a description of the identifier which
|
|
|
|
caused the replacement.
|
|
|
|
If the identifier represents a function-like macro
|
|
|
|
call, the number of actual parameters is checked
|
|
|
|
against the number of formal parameters. Note that
|
|
|
|
in ANSI C the parameters are expanded first;
|
|
|
|
this is done by calling getactuals().
|
|
|
|
When the possible parameters are expanded, the replace-
|
|
|
|
ment list associated with "idf" is expanded.
|
|
|
|
expand_macro() returns 1 if the replacement succeeded
|
|
|
|
and 0 if some error occurred.
|
1989-09-19 16:13:23 +00:00
|
|
|
|
|
|
|
A special case is "defined". This acts as a unary operator
|
|
|
|
on a single, unexpanded identifier, which may be surrounded
|
1989-11-22 13:58:36 +00:00
|
|
|
by parenthesis. The function expand_defined() handles this.
|
1989-02-07 11:04:05 +00:00
|
|
|
*/
|
|
|
|
register struct macro *mac = idf->id_macro;
|
|
|
|
struct args *args = repl->r_args;
|
|
|
|
register int ch;
|
|
|
|
|
|
|
|
if (mac->mc_nps != -1) { /* with parameter list */
|
|
|
|
if (mac->mc_flag & FUNC) {
|
|
|
|
/* the following assertion won't compile:
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(!strcmp("defined", idf->id_text));
|
1989-09-19 16:13:23 +00:00
|
|
|
expand the assert macro by hand (??? dirty, temporary)
|
1989-02-07 11:04:05 +00:00
|
|
|
*/
|
1989-09-19 16:13:23 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (strcmp("defined", idf->id_text))
|
|
|
|
crash("in %s, %u: assertion %s failed",
|
1989-09-29 16:20:38 +00:00
|
|
|
__FILE__, __LINE__ - 2,
|
1989-09-19 16:13:23 +00:00
|
|
|
"strcmp(\"defined\", idf->id_text)");
|
|
|
|
#endif
|
1989-02-07 11:04:05 +00:00
|
|
|
if (!AccDefined) return 0;
|
1989-09-19 16:13:23 +00:00
|
|
|
expand_defined(repl);
|
|
|
|
return 1;
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ch = GetChar();
|
|
|
|
ch = skipspaces(ch,1);
|
|
|
|
if (ch != '(') { /* no replacement if no () */
|
1998-02-09 09:49:00 +00:00
|
|
|
ChPushBack(ch);
|
1989-02-07 11:04:05 +00:00
|
|
|
return 0;
|
|
|
|
} else
|
1989-09-19 16:13:23 +00:00
|
|
|
getactuals(repl, idf);
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mac->mc_flag & FUNC) /* this macro leads to special action */
|
|
|
|
macro_func(idf);
|
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
macro2buffer(repl, idf, args);
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
/* According to the ANSI definition:
|
|
|
|
|
|
|
|
#define a +
|
|
|
|
a+b; --> + + b ;
|
1989-09-29 16:20:38 +00:00
|
|
|
|
1989-02-07 11:04:05 +00:00
|
|
|
'a' must be substituded, but the result should be
|
1989-11-22 13:58:36 +00:00
|
|
|
three tokens: + + ID. Therefore a token separator is
|
|
|
|
inserted after the replacement.
|
1989-02-07 11:04:05 +00:00
|
|
|
*/
|
1991-02-21 12:08:13 +00:00
|
|
|
if (repl->r_text == repl->r_ptr || *(repl->r_ptr - 1) != TOKSEP) {
|
|
|
|
add2repl(repl, TOKSEP);
|
|
|
|
}
|
1989-02-07 11:04:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
void
|
1989-09-19 16:13:23 +00:00
|
|
|
expand_defined(repl)
|
|
|
|
register struct repl *repl;
|
|
|
|
{
|
|
|
|
register int ch = GetChar();
|
|
|
|
struct idf *id;
|
|
|
|
int parens = 0;
|
|
|
|
|
|
|
|
ch = skipspaces(ch, 0);
|
|
|
|
|
|
|
|
if (ch == '(') {
|
|
|
|
parens++;
|
|
|
|
ch = GetChar();
|
|
|
|
ch = skipspaces(ch, 0);
|
|
|
|
}
|
|
|
|
if ((class(ch) != STIDF) && (class(ch) != STELL)) {
|
|
|
|
error("identifier missing");
|
|
|
|
if (parens && ch != ')') error(") missing");
|
1998-02-09 09:49:00 +00:00
|
|
|
if (!parens || ch != ')') ChPushBack(ch);
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, '0');
|
1989-09-19 16:13:23 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-02-09 09:49:00 +00:00
|
|
|
ChPushBack(ch);
|
1989-09-19 16:13:23 +00:00
|
|
|
id = GetIdentifier(0);
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(id || class(ch) == STELL);
|
1989-09-19 16:13:23 +00:00
|
|
|
ch = GetChar();
|
|
|
|
ch = skipspaces(ch, 0);
|
|
|
|
if (parens && ch != ')') error(") missing");
|
1998-02-09 09:49:00 +00:00
|
|
|
if (!parens || ch != ')') ChPushBack(ch);
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, (id && id->id_macro) ? '1' : '0');
|
1990-01-16 15:21:15 +00:00
|
|
|
add2repl(repl, ' ');
|
1989-11-22 13:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newarg(args)
|
|
|
|
struct args *args;
|
|
|
|
{
|
|
|
|
args->a_expptr = args->a_expbuf = Malloc(args->a_expsize = ARGBUF);
|
|
|
|
args->a_rawptr = args->a_rawbuf = Malloc(args->a_rawsize = ARGBUF);
|
1989-09-19 16:13:23 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
void
|
1989-09-19 16:13:23 +00:00
|
|
|
getactuals(repl, idf)
|
1989-09-29 16:20:38 +00:00
|
|
|
struct repl *repl;
|
1989-02-07 11:04:05 +00:00
|
|
|
register struct idf *idf;
|
|
|
|
{
|
|
|
|
/* Get the actual parameters from the input stream.
|
|
|
|
The hard part is done by actual(), only comma's and
|
|
|
|
other syntactic trivialities are checked here.
|
|
|
|
*/
|
1989-09-19 16:13:23 +00:00
|
|
|
register struct args *args = repl->r_args;
|
1989-02-07 11:04:05 +00:00
|
|
|
register int nps = idf->id_macro->mc_nps;
|
|
|
|
register int argcnt;
|
|
|
|
register int ch;
|
|
|
|
|
|
|
|
argcnt = 0;
|
1989-11-22 13:58:36 +00:00
|
|
|
newarg(args);
|
1989-02-07 11:04:05 +00:00
|
|
|
if ((ch = GetChar()) != ')') {
|
1989-09-29 16:20:38 +00:00
|
|
|
UnGetChar();
|
1989-09-19 16:13:23 +00:00
|
|
|
while ((ch = actual(repl)) != ')' ) {
|
1989-02-07 11:04:05 +00:00
|
|
|
if (ch != ',') {
|
|
|
|
lexerror("illegal macro call");
|
|
|
|
return;
|
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, '\0', 1);
|
1989-11-22 13:58:36 +00:00
|
|
|
args->a_expvec[argcnt] = args->a_expbuf;
|
|
|
|
args->a_rawvec[argcnt] = args->a_rawbuf;
|
1989-02-07 11:04:05 +00:00
|
|
|
++argcnt;
|
|
|
|
if (argcnt == STDC_NPARAMS)
|
1989-11-08 16:52:34 +00:00
|
|
|
lexstrict("number of parameters exceeds ANSI standard");
|
1989-02-07 11:04:05 +00:00
|
|
|
if (argcnt >= NPARAMS)
|
|
|
|
fatal("argument vector overflow");
|
1989-11-22 13:58:36 +00:00
|
|
|
newarg(args);
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, '\0', 1);
|
1989-11-22 13:58:36 +00:00
|
|
|
args->a_expvec[argcnt] = args->a_expbuf;
|
|
|
|
args->a_rawvec[argcnt] = args->a_rawbuf;
|
1989-02-07 11:04:05 +00:00
|
|
|
++argcnt;
|
|
|
|
}
|
|
|
|
if (argcnt < nps)
|
|
|
|
lexerror("too few macro arguments");
|
1989-09-19 16:13:23 +00:00
|
|
|
else if (argcnt > nps)
|
1989-02-07 11:04:05 +00:00
|
|
|
lexerror("too many macro arguments");
|
|
|
|
}
|
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
saveraw(repl)
|
|
|
|
struct repl *repl;
|
|
|
|
{
|
|
|
|
register struct repl *nrepl = ReplaceList;
|
|
|
|
register struct args *ap = nrepl->r_args;
|
|
|
|
register char *p;
|
|
|
|
|
|
|
|
/* stash identifier name */
|
|
|
|
for (p = nrepl->r_idf->id_text; *p != '\0'; p++)
|
1989-11-22 13:58:36 +00:00
|
|
|
stash(repl, *p, -1);
|
1989-09-19 16:13:23 +00:00
|
|
|
|
|
|
|
/* The following code deals with expanded function
|
|
|
|
like macro calls. It makes the following code
|
|
|
|
work:
|
|
|
|
|
1989-09-29 16:20:38 +00:00
|
|
|
#define def(a,b) x(a,b)
|
1989-09-19 16:13:23 +00:00
|
|
|
#define glue(a,b) a ## b
|
|
|
|
|
|
|
|
glue(abc,def(a,b))
|
1989-09-29 16:20:38 +00:00
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
Results in:
|
|
|
|
|
|
|
|
abcdef(a,b);
|
|
|
|
*/
|
|
|
|
if (ap->a_rawvec[0]) {
|
|
|
|
/* stash arguments */
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
for (i = 0; ap->a_rawvec[i] != (char *)0; i++) {
|
1990-01-26 14:59:50 +00:00
|
|
|
if (i == 0) stash(repl, '(', -1);
|
|
|
|
else stash(repl, ',', -1);
|
1989-09-19 16:13:23 +00:00
|
|
|
for (p = ap->a_rawvec[i]; *p != '\0'; p++)
|
1989-11-22 13:58:36 +00:00
|
|
|
stash(repl, *p, -1);
|
1989-09-19 16:13:23 +00:00
|
|
|
}
|
1990-01-26 14:59:50 +00:00
|
|
|
stash(repl, ')', -1);
|
1989-09-19 16:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1989-02-07 11:04:05 +00:00
|
|
|
int
|
1989-09-19 16:13:23 +00:00
|
|
|
actual(repl)
|
|
|
|
struct repl *repl;
|
1989-02-07 11:04:05 +00:00
|
|
|
{
|
|
|
|
/* This routine deals with the scanning of an actual parameter.
|
1989-09-19 16:13:23 +00:00
|
|
|
It keeps in account the opening and closing brackets,
|
1989-02-07 11:04:05 +00:00
|
|
|
preprocessor numbers, strings and character constants.
|
|
|
|
*/
|
1991-02-18 15:50:39 +00:00
|
|
|
register int ch = 0;
|
1989-09-19 16:13:23 +00:00
|
|
|
register int level = 0, nostashraw = 0;
|
1991-02-18 15:50:39 +00:00
|
|
|
int lastch;
|
1993-03-30 09:41:00 +00:00
|
|
|
static int Unstacked_missed;
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
while (1) {
|
1991-02-18 15:50:39 +00:00
|
|
|
lastch = ch;
|
1989-02-07 11:04:05 +00:00
|
|
|
ch = GetChar();
|
|
|
|
|
1993-03-30 09:41:00 +00:00
|
|
|
if (nostashraw
|
|
|
|
&& nostashraw >= Unstacked_missed) {
|
|
|
|
nostashraw -= Unstacked_missed;
|
|
|
|
Unstacked_missed = 0;
|
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
if (Unstacked) {
|
|
|
|
nostashraw -= Unstacked;
|
1993-03-30 09:41:00 +00:00
|
|
|
if (nostashraw < 0) {
|
|
|
|
Unstacked_missed = -nostashraw;
|
|
|
|
nostashraw = 0;
|
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
EnableMacros();
|
|
|
|
}
|
1989-02-07 11:04:05 +00:00
|
|
|
if (class(ch) == STIDF || class(ch) == STELL) {
|
|
|
|
/* Scan a preprocessor identifier token. If the
|
|
|
|
token is a macro, it is expanded first.
|
|
|
|
*/
|
|
|
|
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
|
|
|
|
register char *p = buf;
|
|
|
|
register struct idf *idef;
|
|
|
|
register int pos = -1;
|
|
|
|
extern int idfsize;
|
1989-09-19 16:13:23 +00:00
|
|
|
int NoExpandMacro;
|
|
|
|
|
|
|
|
if (ch == NOEXPM) {
|
|
|
|
NoExpandMacro= 1;
|
|
|
|
ch = GetChar();
|
|
|
|
} else NoExpandMacro = 0;
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (++pos < idfsize) {
|
|
|
|
*p++ = ch;
|
|
|
|
}
|
|
|
|
ch = GetChar();
|
|
|
|
} while (in_idf(ch));
|
|
|
|
*p++ = '\0';
|
1994-03-01 15:04:52 +00:00
|
|
|
ch = '\0'; /* It could be an unstashed TOKSEP */
|
1989-02-07 11:04:05 +00:00
|
|
|
UnGetChar();
|
|
|
|
|
|
|
|
/* When the identifier has an associated macro
|
|
|
|
replacement list, it's expanded.
|
|
|
|
*/
|
1991-06-19 16:12:56 +00:00
|
|
|
idef = findidf(buf);
|
|
|
|
if (!idef || NoExpandMacro || !replace(idef)) {
|
|
|
|
if (NoExpandMacro
|
|
|
|
|| (idef && idef->id_macro
|
|
|
|
&& (idef->id_macro->mc_flag & NOREPLACE)))
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, NOEXPM, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
for (p = buf; *p != '\0'; p++)
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, *p, !nostashraw);
|
|
|
|
} else {
|
|
|
|
if (!nostashraw) saveraw(repl);
|
|
|
|
nostashraw++;
|
|
|
|
}
|
|
|
|
} else if (class(ch) == STNUM) {
|
|
|
|
/* a preprocessing number has the following
|
|
|
|
regular expression:
|
|
|
|
[0-9|"."[0-9]]{[0-9"."a-zA-Z_]|{[Ee][+-]}}*
|
1989-02-07 11:04:05 +00:00
|
|
|
*/
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
|
|
|
if (ch == '.') {
|
|
|
|
ch = GetChar();
|
|
|
|
if (class(ch) != STNUM) {
|
1994-03-01 15:04:52 +00:00
|
|
|
ch = '\0'; /* It could be an unstashed TOKSEP */
|
1989-09-19 16:13:23 +00:00
|
|
|
UnGetChar();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else stash(repl, ch, !nostashraw);
|
|
|
|
}
|
|
|
|
ch = GetChar();
|
|
|
|
while (in_idf(ch) || ch == '.') {
|
|
|
|
stash(repl, ch, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
if ((ch = GetChar()) == 'e' || ch == 'E') {
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
ch = GetChar();
|
|
|
|
if (ch == '+' || ch == '-') {
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
ch = GetChar();
|
|
|
|
}
|
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
}
|
1994-03-01 15:04:52 +00:00
|
|
|
ch = '\0'; /* It could be an unstashed TOKSEP */
|
1989-02-07 11:04:05 +00:00
|
|
|
UnGetChar();
|
1990-01-26 14:59:50 +00:00
|
|
|
} else if (ch == '(') {
|
|
|
|
/* a comma may occur between parentheses */
|
1989-02-07 11:04:05 +00:00
|
|
|
level++;
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1990-01-26 14:59:50 +00:00
|
|
|
} else if (ch == ')') {
|
1989-02-07 11:04:05 +00:00
|
|
|
level--;
|
1990-01-26 14:59:50 +00:00
|
|
|
/* closing parenthesis of macro call */
|
|
|
|
if (level < 0) return ')';
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
} else if (ch == ',') {
|
|
|
|
if (level <= 0) { /* comma separator for next argument */
|
|
|
|
if (level)
|
|
|
|
lexerror("unbalanced parenthesis");
|
1989-09-19 16:13:23 +00:00
|
|
|
if (!nostashraw)
|
|
|
|
return ','; /* ??? */
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
} else if (ch == '\n') {
|
|
|
|
/* newlines are accepted as white spaces */
|
|
|
|
LineNumber++;
|
|
|
|
/* This piece of code needs some explanation:
|
|
|
|
consider the call of a macro defined as:
|
|
|
|
#define sum(a,b) (a+b)
|
|
|
|
in the following form:
|
|
|
|
sum(
|
1989-11-22 13:58:36 +00:00
|
|
|
/_* comment *_/ #include phone_number
|
1989-02-07 11:04:05 +00:00
|
|
|
,2);
|
|
|
|
in which case the include must be handled
|
|
|
|
interpreted as such.
|
|
|
|
*/
|
1989-11-22 13:58:36 +00:00
|
|
|
|
1990-01-26 14:59:50 +00:00
|
|
|
a_new_line: ch = GetChar();
|
1989-11-22 13:58:36 +00:00
|
|
|
while (class(ch) == STSKIP || ch == '/') {
|
|
|
|
if (ch == '/') {
|
|
|
|
if ((ch = GetChar()) == '*' && !InputLevel) {
|
|
|
|
skipcomment();
|
|
|
|
stash(repl, ' ', !nostashraw);
|
|
|
|
ch = GetChar();
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
UnGetChar();
|
|
|
|
ch = '/';
|
|
|
|
}
|
|
|
|
stash(repl, '/', !nostashraw);
|
|
|
|
break;
|
|
|
|
} else ch = GetChar();
|
|
|
|
}
|
1990-01-26 14:59:50 +00:00
|
|
|
|
|
|
|
if (ch == '#') {
|
1989-02-07 11:04:05 +00:00
|
|
|
domacro();
|
1990-11-13 16:50:55 +00:00
|
|
|
/* Clear File_Inserted since domacro could
|
|
|
|
* be called again, which calls GetToken().
|
|
|
|
*/
|
|
|
|
File_Inserted = 0;
|
1990-01-26 14:59:50 +00:00
|
|
|
goto a_new_line;
|
|
|
|
} else if (ch == EOI) {
|
1989-09-19 16:13:23 +00:00
|
|
|
lexerror("unterminated macro call");
|
|
|
|
return ')';
|
|
|
|
}
|
1989-11-22 13:58:36 +00:00
|
|
|
if (ch != '/') {
|
|
|
|
UnGetChar();
|
1994-03-01 15:04:52 +00:00
|
|
|
ch = ' ';
|
1989-11-22 13:58:36 +00:00
|
|
|
stash(repl, ' ', !nostashraw);
|
|
|
|
}
|
1989-02-07 11:04:05 +00:00
|
|
|
} else if (ch == '/') {
|
|
|
|
/* comments are treated as one white space token */
|
1989-09-19 16:13:23 +00:00
|
|
|
if ((ch = GetChar()) == '*' && !InputLevel) {
|
1989-02-07 11:04:05 +00:00
|
|
|
skipcomment();
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ' ', !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
} else {
|
|
|
|
UnGetChar();
|
1994-03-01 15:04:52 +00:00
|
|
|
ch = '/';
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, '/', !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
} else if (ch == '\'' || ch == '"') {
|
|
|
|
/* Strings are considered as ONE token, thus no
|
|
|
|
replacement within strings.
|
|
|
|
*/
|
|
|
|
register int match = ch;
|
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
while ((ch = GetChar()) != EOI) {
|
|
|
|
if (ch == match)
|
|
|
|
break;
|
|
|
|
if (ch == '\\') {
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
ch = GetChar();
|
|
|
|
} else if (ch == '\n') {
|
|
|
|
lexerror("newline in string");
|
|
|
|
LineNumber++;
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, match, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
break;
|
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
if (ch != match) {
|
|
|
|
lexerror("unterminated macro call");
|
|
|
|
return ')';
|
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1991-02-18 15:50:39 +00:00
|
|
|
} else {
|
|
|
|
if (lastch == TOKSEP && ch == TOKSEP) continue;
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, !nostashraw);
|
1991-02-18 15:50:39 +00:00
|
|
|
}
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_func(idef)
|
|
|
|
register struct idf *idef;
|
|
|
|
{
|
|
|
|
/* macro_func() performs the special actions needed with some
|
1989-09-29 16:20:38 +00:00
|
|
|
macros. These macros are __FILE__ and __LINE__ which
|
1989-02-07 11:04:05 +00:00
|
|
|
replacement texts must be evaluated at the time they are
|
|
|
|
used.
|
|
|
|
*/
|
|
|
|
register struct macro *mac = idef->id_macro;
|
|
|
|
static char FilNamBuf[PATHLENGTH];
|
|
|
|
|
|
|
|
switch (idef->id_text[2]) {
|
|
|
|
case 'F': /* __FILE__ */
|
|
|
|
FilNamBuf[0] = '"';
|
|
|
|
strcpy(&FilNamBuf[1], FileName);
|
|
|
|
strcat(FilNamBuf, "\"");
|
|
|
|
mac->mc_text = FilNamBuf;
|
|
|
|
mac->mc_length = strlen(FilNamBuf);
|
|
|
|
break;
|
|
|
|
case 'L': /* __LINE__ */
|
|
|
|
mac->mc_text = long2str((long)LineNumber, 10);
|
1989-09-19 16:13:23 +00:00
|
|
|
mac->mc_length = strlen(mac->mc_text);
|
1989-02-07 11:04:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("(macro_func)");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
void
|
1989-02-07 11:04:05 +00:00
|
|
|
macro2buffer(repl, idf, args)
|
|
|
|
register struct repl *repl;
|
|
|
|
register struct idf *idf;
|
|
|
|
register struct args *args;
|
|
|
|
{
|
|
|
|
/* macro2buffer expands the replacement list and places the
|
|
|
|
result onto the replacement buffer. It deals with the #
|
|
|
|
and ## operators, and inserts the actual parameters.
|
|
|
|
The argument buffer contains the raw argument (needed
|
|
|
|
for the ## operator), and the expanded argument (for
|
|
|
|
all other parameter substitutions).
|
|
|
|
|
|
|
|
The grammar of the replacement list is:
|
|
|
|
|
|
|
|
repl_list: TOKEN repl_list
|
|
|
|
| PARAMETER repl_list
|
|
|
|
| '#' PARAMETER
|
|
|
|
| TOKEN '##' TOKEN
|
|
|
|
| PARAMETER '##' TOKEN
|
|
|
|
| TOKEN '##' PARAMETER
|
|
|
|
| PARAMETER '##' PARAMETER
|
|
|
|
;
|
1989-09-29 16:20:38 +00:00
|
|
|
|
1989-02-07 11:04:05 +00:00
|
|
|
As the grammar indicates, we could make a DFA and
|
|
|
|
use this finite state machine for the replacement
|
|
|
|
list parsing (inserting the arguments, etc.).
|
|
|
|
|
|
|
|
Currently we go through the replacement list in a
|
|
|
|
linear fashion. This is VERY expensive, something
|
|
|
|
smarter should be done (but even a DFA is O(|s|)).
|
|
|
|
*/
|
|
|
|
register char *ptr = idf->id_macro->mc_text;
|
1989-09-19 16:13:23 +00:00
|
|
|
int err = 0;
|
1990-09-13 15:12:13 +00:00
|
|
|
int func = idf->id_macro->mc_nps != -1;
|
1989-02-07 11:04:05 +00:00
|
|
|
char *stringify();
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(ptr[idf->id_macro->mc_length] == '\0');
|
1989-02-07 11:04:05 +00:00
|
|
|
while (*ptr) {
|
1989-09-19 16:13:23 +00:00
|
|
|
if (*ptr == '\'' || *ptr == '"') {
|
|
|
|
register int delim = *ptr;
|
|
|
|
|
|
|
|
do {
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, *ptr);
|
1989-09-19 16:13:23 +00:00
|
|
|
if (*ptr == '\\')
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, *++ptr);
|
1989-09-19 16:13:23 +00:00
|
|
|
if (*ptr == '\0') {
|
1989-09-29 16:20:38 +00:00
|
|
|
lexerror("unterminated string");
|
|
|
|
return;
|
1989-09-19 16:13:23 +00:00
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
} while (*ptr != delim || *ptr == '\0');
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, *ptr++);
|
1990-09-25 13:46:59 +00:00
|
|
|
} else if (*ptr == '#' && (func || *(ptr+1) == '#')) {
|
1989-09-19 16:13:23 +00:00
|
|
|
if (*++ptr == '#') {
|
1989-11-22 13:58:36 +00:00
|
|
|
register int tmpindex;
|
1989-09-19 16:13:23 +00:00
|
|
|
/* ## - paste operator */
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
/* trim the actual replacement list */
|
|
|
|
--repl->r_ptr;
|
1989-11-22 13:58:36 +00:00
|
|
|
while (repl->r_ptr >= repl->r_text
|
|
|
|
&& is_wsp(*repl->r_ptr))
|
1989-09-29 16:20:38 +00:00
|
|
|
--repl->r_ptr;
|
1989-09-19 16:13:23 +00:00
|
|
|
|
1989-09-29 16:20:38 +00:00
|
|
|
/* ## occurred at the beginning of the replacement list.
|
|
|
|
*/
|
1989-11-22 13:58:36 +00:00
|
|
|
if (repl->r_ptr < repl->r_text) {
|
1989-09-29 16:20:38 +00:00
|
|
|
err = 1;
|
|
|
|
break;
|
1989-09-19 16:13:23 +00:00
|
|
|
}
|
|
|
|
|
1989-11-22 13:58:36 +00:00
|
|
|
if (repl->r_ptr >= repl->r_text
|
|
|
|
&& *repl->r_ptr == TOKSEP)
|
1989-09-29 16:20:38 +00:00
|
|
|
--repl->r_ptr;
|
1989-09-19 16:13:23 +00:00
|
|
|
|
|
|
|
++repl->r_ptr;
|
1989-11-22 13:58:36 +00:00
|
|
|
tmpindex = repl->r_ptr - repl->r_text;
|
|
|
|
/* tmpindex can be 0 */
|
1989-09-19 16:13:23 +00:00
|
|
|
|
|
|
|
/* skip space in macro replacement list */
|
|
|
|
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
/* ## occurred at the end of the replacement list.
|
1989-09-29 16:20:38 +00:00
|
|
|
*/
|
1989-09-19 16:13:23 +00:00
|
|
|
if (*ptr & FORMALP) {
|
1989-02-07 11:04:05 +00:00
|
|
|
register int n = *ptr++ & 0177;
|
1989-09-19 16:13:23 +00:00
|
|
|
register char *p;
|
1989-02-07 11:04:05 +00:00
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(n > 0);
|
1989-09-19 16:13:23 +00:00
|
|
|
p = args->a_rawvec[n-1];
|
|
|
|
if (p) { /* else macro argument missing */
|
1989-11-22 13:58:36 +00:00
|
|
|
while (is_wsp(*p)) p++;
|
1989-09-19 16:13:23 +00:00
|
|
|
if (*p == NOEXPM) p++;
|
|
|
|
while (*p)
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, *p++);
|
1989-09-19 16:13:23 +00:00
|
|
|
}
|
1989-11-22 13:58:36 +00:00
|
|
|
while (tmpindex > 0
|
|
|
|
&& in_idf(repl->r_text[tmpindex]))
|
|
|
|
tmpindex--;
|
|
|
|
if (tmpindex >= 0
|
|
|
|
&& repl->r_text[tmpindex] == NOEXPM)
|
|
|
|
repl->r_text[tmpindex] = TOKSEP;
|
1989-09-19 16:13:23 +00:00
|
|
|
} else if (*ptr == '\0') {
|
|
|
|
err = 1;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (in_idf(*ptr)) {
|
1989-11-22 13:58:36 +00:00
|
|
|
tmpindex--;
|
|
|
|
while (tmpindex > 0
|
|
|
|
&& in_idf(repl->r_text[tmpindex]))
|
|
|
|
tmpindex--;
|
|
|
|
if (tmpindex >= 0
|
|
|
|
&& repl->r_text[tmpindex] == NOEXPM)
|
|
|
|
repl->r_text[tmpindex] = TOKSEP;
|
1989-09-19 16:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
1990-09-13 15:12:13 +00:00
|
|
|
} else { /* # operator */
|
|
|
|
ptr = stringify(repl, ptr, args);
|
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
} else if (*ptr & FORMALP) {
|
|
|
|
/* insert actual parameter */
|
|
|
|
register int n = *ptr++ & 0177;
|
|
|
|
register char *p, *q;
|
1989-09-29 16:20:38 +00:00
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(n > 0);
|
1989-09-19 16:13:23 +00:00
|
|
|
|
|
|
|
/* This is VERY dirty, we look ahead for the
|
1989-11-22 13:58:36 +00:00
|
|
|
## operator. If it's found we use the raw
|
1989-09-19 16:13:23 +00:00
|
|
|
argument buffer instead of the expanded
|
|
|
|
one.
|
|
|
|
*/
|
|
|
|
for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*p); p++)
|
1989-09-29 16:20:38 +00:00
|
|
|
/* EMPTY */;
|
1989-09-19 16:13:23 +00:00
|
|
|
if (*p == '#' && p[1] == '#')
|
|
|
|
q = args->a_rawvec[n-1];
|
|
|
|
else
|
|
|
|
q = args->a_expvec[n-1];
|
|
|
|
|
|
|
|
if (q) /* else macro argument missing */
|
|
|
|
while (*q)
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, *q++);
|
1989-09-19 16:13:23 +00:00
|
|
|
|
1991-02-21 12:08:13 +00:00
|
|
|
if (repl->r_text == repl->r_ptr || *(repl->r_ptr - 1) != TOKSEP)
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, TOKSEP);
|
1990-09-13 15:12:13 +00:00
|
|
|
} else {
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, *ptr++);
|
1990-09-13 15:12:13 +00:00
|
|
|
}
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
if (err)
|
|
|
|
lexerror("illegal use of the ## operator");
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
stringify(repl, ptr, args)
|
|
|
|
register struct repl *repl;
|
|
|
|
register char *ptr;
|
|
|
|
register struct args *args;
|
|
|
|
{
|
|
|
|
/* If a parameter is immediately preceded by a # token
|
|
|
|
both are replaced by a single string literal that
|
|
|
|
contains the spelling of the token sequence for the
|
|
|
|
corresponding argument.
|
|
|
|
Each occurrence of white space between the argument's
|
|
|
|
tokens become a single space character in the string
|
|
|
|
literal. White spaces before the first token and after
|
|
|
|
the last token comprising the argument are deleted.
|
|
|
|
To retain the original spelling we insert backslashes
|
|
|
|
as appropriate. We only escape backslashes if they
|
|
|
|
occure within string tokens.
|
|
|
|
*/
|
|
|
|
register int space = 1; /* skip leading spaces */
|
|
|
|
register int delim = 0; /* string or character constant delim */
|
|
|
|
register int backslash = 0; /* last character was a \ */
|
|
|
|
|
|
|
|
/* skip spaces macro replacement list */
|
|
|
|
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (*ptr & FORMALP) {
|
|
|
|
register int n = *ptr++ & 0177;
|
|
|
|
register char *p;
|
1989-09-29 16:20:38 +00:00
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(n != 0);
|
1989-09-19 16:13:23 +00:00
|
|
|
p = args->a_rawvec[n-1];
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, '"');
|
1989-02-07 11:04:05 +00:00
|
|
|
while (*p) {
|
|
|
|
if (is_wsp(*p)) {
|
|
|
|
if (!space) {
|
|
|
|
space = 1;
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, ' ');
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
space = 0;
|
|
|
|
|
|
|
|
if (!delim && (*p == '"' || *p == '\''))
|
|
|
|
delim = *p;
|
|
|
|
else if (*p == delim && !backslash)
|
|
|
|
delim = 0;
|
|
|
|
backslash = *p == '\\';
|
|
|
|
if (*p == '"' || (delim && *p == '\\'))
|
1989-11-22 13:58:36 +00:00
|
|
|
add2repl(repl, '\\');
|
1989-09-19 16:13:23 +00:00
|
|
|
if (*p == TOKSEP || *p == NOEXPM) p++;
|
1989-11-22 13:58:36 +00:00
|
|
|
else add2repl(repl, *p++);
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* trim spaces in the replacement list */
|
|
|
|
for (--repl->r_ptr; is_wsp(*repl->r_ptr); repl->r_ptr--)
|
1989-09-29 16:20:38 +00:00
|
|
|
/* EMPTY */;
|
1989-11-22 13:58:36 +00:00
|
|
|
++repl->r_ptr; /* oops, one to far */
|
|
|
|
add2repl(repl, '"');
|
1989-02-07 11:04:05 +00:00
|
|
|
} else
|
|
|
|
error("illegal use of # operator");
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
1989-11-22 13:58:36 +00:00
|
|
|
/* The following routine is also called from domacro.c.
|
|
|
|
*/
|
|
|
|
add2repl(repl, ch)
|
|
|
|
register struct repl *repl;
|
|
|
|
int ch;
|
|
|
|
{
|
|
|
|
register int index = repl->r_ptr - repl->r_text;
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(index < repl->r_size);
|
1990-01-26 14:59:50 +00:00
|
|
|
if (index + 2 >= repl->r_size) {
|
1990-10-01 15:28:28 +00:00
|
|
|
repl->r_text = Realloc(repl->r_text, (unsigned) (repl->r_size <<= 1));
|
1989-11-22 13:58:36 +00:00
|
|
|
repl->r_ptr = repl->r_text + index;
|
|
|
|
}
|
|
|
|
*repl->r_ptr++ = ch;
|
|
|
|
*repl->r_ptr = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the variable stashraw is negative, we must only stash into the raw
|
|
|
|
* buffer. If the variable is zero, we must only stash into the expanded
|
|
|
|
* buffer. Otherwise, we must use both buffers.
|
|
|
|
*/
|
1989-09-19 16:13:23 +00:00
|
|
|
stash(repl, ch, stashraw)
|
|
|
|
struct repl *repl;
|
1989-02-07 11:04:05 +00:00
|
|
|
register int ch;
|
1989-09-19 16:13:23 +00:00
|
|
|
int stashraw;
|
1989-02-07 11:04:05 +00:00
|
|
|
{
|
|
|
|
/* Stash characters into the macro expansion buffer.
|
|
|
|
*/
|
1989-09-19 16:13:23 +00:00
|
|
|
register struct args *args = repl->r_args;
|
1989-11-22 13:58:36 +00:00
|
|
|
register int index = args->a_expptr - args->a_expbuf;
|
1989-09-19 16:13:23 +00:00
|
|
|
|
1989-11-22 13:58:36 +00:00
|
|
|
if (stashraw >= 0) {
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(index < args->a_expsize);
|
1989-11-22 13:58:36 +00:00
|
|
|
if (index + 1 >= args->a_expsize) {
|
|
|
|
args->a_expbuf = Realloc(args->a_expbuf,
|
1990-10-01 15:28:28 +00:00
|
|
|
(unsigned) (args->a_expsize <<= 1));
|
1989-11-22 13:58:36 +00:00
|
|
|
args->a_expptr = args->a_expbuf + index;
|
|
|
|
}
|
|
|
|
*args->a_expptr++ = ch;
|
|
|
|
}
|
1989-02-07 11:04:05 +00:00
|
|
|
|
1989-09-19 16:13:23 +00:00
|
|
|
if (stashraw) {
|
1989-11-22 13:58:36 +00:00
|
|
|
index = args->a_rawptr - args->a_rawbuf;
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(index < args->a_rawsize);
|
1989-11-22 13:58:36 +00:00
|
|
|
if (index + 1 >= args->a_rawsize) {
|
|
|
|
args->a_rawbuf = Realloc(args->a_rawbuf,
|
1990-10-01 15:28:28 +00:00
|
|
|
(unsigned)(args->a_rawsize <<= 1));
|
1989-11-22 13:58:36 +00:00
|
|
|
args->a_rawptr = args->a_rawbuf + index;
|
|
|
|
}
|
1989-09-19 16:13:23 +00:00
|
|
|
*args->a_rawptr++ = ch;
|
|
|
|
}
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* NOPP */
|