ack/lang/cem/cpp.ansi/options.c

146 lines
3 KiB
C
Raw Permalink Normal View History

1989-10-23 10:35:56 +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-24 14:02:31 +00:00
/* $Id$ */
1989-10-23 10:35:56 +00:00
/* USER-OPTION HANDLING */
#include <stdlib.h>
#include <string.h>
#include "alloc.h"
#include "parameters.h"
1989-10-23 10:35:56 +00:00
#include "class.h"
#include "macro.h"
#include "domacro.h"
1989-10-23 10:35:56 +00:00
#include "idf.h"
#include "error.h"
1989-10-23 10:35:56 +00:00
char options[128]; /* one for every char */
int inc_pos = 1; /* place where next -I goes */
int inc_max;
int inc_total;
int do_preprocess = 1;
int do_dependencies = 0;
1989-10-23 10:35:56 +00:00
char **inctable;
char *dep_file = 0;
1989-10-23 10:35:56 +00:00
extern int idfsize;
static int txt2int(char **tp);
void do_option(char *text)
1989-10-23 10:35:56 +00:00
{
switch(*text++) {
case '-':
options[*text] = 1;
break;
case 'u':
if (! strcmp(text, "ndef")) {
/* ignore -undef */
break;
}
/* fall through */
1989-10-23 10:35:56 +00:00
default:
error("illegal option: %c", text[-1]);
break;
case 'A' : /* for Amake */
case 'd' : /* dependency generation */
do_dependencies = 1;
if (*text) {
dep_file = text;
}
else {
do_preprocess = 0;
}
1989-10-31 10:02:48 +00:00
break;
case 'i':
case 'm':
case 'o': /* ignore garbage after #else or #endif */
1989-10-23 10:35:56 +00:00
case 'C' : /* comment output */
options[*(text-1)] = 1;
1989-10-23 10:35:56 +00:00
break;
case 'D' : /* -Dname : predefine name */
{
register char *cp = text, *name, *mactext;
unsigned maclen;
1989-10-23 10:35:56 +00:00
1990-02-21 16:38:45 +00:00
if (class(*cp) != STIDF && class(*cp) != STELL) {
1989-10-23 10:35:56 +00:00
error("identifier missing in -D%s", text);
break;
}
name = cp;
while (*cp && in_idf(*cp))
++cp;
if (!*cp) { /* -Dname */
maclen = 1;
mactext = Salloc("1", 2);
} else
1989-10-23 10:35:56 +00:00
if (*cp == '=') { /* -Dname=text */
*cp++ = '\0'; /* end of name */
maclen = strlen(cp);
mactext = Salloc(cp, maclen + 1);
1989-10-23 10:35:56 +00:00
}
else { /* -Dname?? */
error("malformed option -D%s", text);
break;
}
1990-10-02 17:19:17 +00:00
macro_def(str2idf(name, 0), mactext, -1, (int)maclen, NOFLAG);
1989-10-23 10:35:56 +00:00
break;
}
case 'I' : /* -Ipath : insert "path" into include list */
if (*text) {
register int i;
register char *new = text;
if (++inc_total > inc_max) {
1990-07-25 13:00:40 +00:00
inctable = (char **)
1990-10-02 17:19:17 +00:00
Realloc((char *)inctable,
(unsigned)((inc_max+=10)*sizeof(char *)));
1989-10-23 10:35:56 +00:00
}
1990-07-25 13:00:40 +00:00
1990-09-27 16:39:54 +00:00
for(i = inc_pos++; i < inc_total; i++) {
1990-07-25 13:00:40 +00:00
char *tmp = inctable[i];
inctable[i] = new;
1989-10-23 10:35:56 +00:00
new = tmp;
}
}
else inctable[inc_pos] = 0;
break;
case 'M': /* maximum identifier length */
idfsize = txt2int(&text);
if (*text)
error("malformed -M option");
if (idfsize > IDFSIZE) {
warning("maximum identifier length is %d", IDFSIZE);
idfsize = IDFSIZE;
}
if (idfsize < 8) {
warning("minimum identifier length is 8");
idfsize = 8;
}
break;
case 'P' : /* run preprocessor stand-alone, without #'s */
options['P'] = 1;
break;
case 'U' : /* -Uname : undefine predefined */
if (*text) do_undef(text);
1989-10-23 10:35:56 +00:00
break;
}
}
static int txt2int(char **tp)
1989-10-23 10:35:56 +00:00
{
/* the integer pointed to by *tp is read, while increasing
*tp; the resulting value is yielded.
*/
register int val = 0;
register int ch;
while (ch = **tp, ch >= '0' && ch <= '9') {
val = val * 10 + ch - '0';
(*tp)++;
}
return val;
}