1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
/* decode remaining preprocessor lines, minimal version. */
/* Copyright (C) GPL V2, derived from preproc.c by RDB. */
#include "bcc.h"
#include "input.h"
#include "os.h"
#include "output.h"
#include "parse.h"
#include "sc.h"
#include "scan.h"
#include "table.h"
#include "type.h"
#ifndef BUILTIN_CPP
FORWARD void control P((void));
FORWARD void asmcontrol P((void));
FORWARD void warningcntl P((void));
FORWARD void errorcntl P((void));
/* docontrol() - process control statement, #line and #asm only. */
PUBLIC void docontrol()
{
control();
skipline();
return;
}
/* control() - select and switch to control statement */
PRIVATE void control()
{
char sname[NAMESIZE + 1];
sym_t ctlcase;
struct symstruct *symptr;
if (ctext && asmmode)
{
comment();
outudec(input.linenumber);
outbyte(' ');
outline(lineptr);
}
sname[0] = '#'; /* prepare for bad control */
sname[1] = 0;
if (blanksident())
strcat(sname, gsname);
if (sname[1] == 0 && ch == EOL)
return;
if (SYMOFCHAR(ch) == INTCONST)
{ linecontol(); return; }
if ((symptr = findlorg(sname)) == NULL)
{
error(" bad control");
return;
}
ctlcase = symptr->offset.offsym;
switch (ctlcase)
{
case ASMCNTL:
if (asmmode)
error(" bad control");
else
asmcontrol();
break;
case ENDASMCNTL:
if (!asmmode)
error(" bad control");
asmmode = FALSE;
break;
case LINECNTL:
{ linecontol(); break; }
case WARNINGCNTL:
warningcntl();
break;
case ERRORCNTL:
errorcntl();
break;
default:
error(" bad control");
break;
}
}
/* asmcontrol() - process #asm */
PRIVATE void asmcontrol()
{
#ifdef ASM_BARE
char treasure; /* to save at least one leading blank */
#endif
asmmode = TRUE;
if (expect_statement)
return;
outnstr("!BCC_ASM");
dumplocs();
#ifndef ASM_BARE
cppscan(1);
#else
while (TRUE)
{
skipline();
skipeol();
if (eofile)
{
eofin("#asm");
break;
}
if (SYMOFCHAR(ch) == SPECIALCHAR)
specialchar();
treasure = 0;
if (SYMOFCHAR(ch) == WHITESPACE)
treasure = ch;
blanks();
if (ch == '#')
{
if (ctext)
{
register char *lptr;
comment();
if (treasure != 0)
outbyte(treasure);
lptr = lineptr;
while (*lptr++ != EOL) /* XXX - handle COEOL too */
outbyte(ch);
outnl();
}
gch1();
docontrol();
if (!asmmode)
break;
}
else
{
if (treasure != 0)
outbyte(treasure);
while (ch != EOL) /* XXX - handle COEOL too */
{
outbyte(ch);
gch1();
}
outnl();
}
}
#endif
outnstr("!BCC_ENDASM");
}
/* warningcntl() - process #warning */
PRIVATE void warningcntl()
{
char estr[256], *ep = estr;
*ep++ = '%'; *ep++ = 'w';
while( ch != EOL ) {
if (ep < estr+sizeof(estr)-2 )
*ep++ = ch;
gch1();
}
*ep = 0;
error(estr);
}
/* errorcntl() - process #error */
PRIVATE void errorcntl()
{
char estr[256], *ep = estr;
while( ch != EOL ) {
if (ep < estr+sizeof(estr)-2 )
*ep++ = ch;
gch1();
}
*ep = 0;
error(estr);
}
/* skipline() - skip rest of line */
PUBLIC void skipline()
{
while (TRUE)
{
blanks();
if (ch == EOL)
return;
if (ch == '\\')
{
gch1();
if (ch == EOL) /* XXX - I think blanks() eats \EOL */
return;
gch1(); /* XXX - escape() better? */
}
else if (ch == '"' || ch == '\'')
{
stringorcharconst();
charptr = constant.value.s;
}
else
gch1();
}
}
#endif
|