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
|
|
|
/* U S E R O P T I O N - H A N D L I N G */
|
|
|
|
|
2013-05-12 19:45:55 +00:00
|
|
|
#include "parameters.h"
|
2006-07-19 10:28:43 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1989-02-07 11:04:05 +00:00
|
|
|
#include <alloc.h>
|
2019-02-18 16:42:15 +00:00
|
|
|
#include "options.h"
|
1989-02-07 11:04:05 +00:00
|
|
|
#include "class.h"
|
|
|
|
#include "macro.h"
|
2013-05-18 11:15:53 +00:00
|
|
|
#include "idf.h"
|
1989-02-07 11:04:05 +00:00
|
|
|
#include "arith.h"
|
|
|
|
#include "sizes.h"
|
|
|
|
#include "align.h"
|
2019-02-18 16:42:15 +00:00
|
|
|
#include "error.h"
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
char options[128]; /* one for every char */
|
|
|
|
#ifdef LINT
|
|
|
|
char loptions[128]; /* one for every char */
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
extern int idfsize;
|
1991-03-01 13:51:37 +00:00
|
|
|
extern int density;
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
|
|
|
|
static int txt2int(register char **);
|
|
|
|
|
|
|
|
void do_option(char *text)
|
1989-02-07 11:04:05 +00:00
|
|
|
{
|
|
|
|
register char opt;
|
|
|
|
|
|
|
|
next_option: /* to allow combined one-char options */
|
|
|
|
switch (opt = *text++) {
|
|
|
|
|
|
|
|
case 0: /* to end the goto next_option loop */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
#ifndef LINT
|
|
|
|
fatal("illegal option: %c", opt);
|
1991-12-17 13:12:22 +00:00
|
|
|
#else /* LINT */
|
1989-02-07 11:04:05 +00:00
|
|
|
warning("illegal option: %c", opt);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-02-07 11:04:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
2019-02-23 16:46:05 +00:00
|
|
|
options[(int)*text++] = 1; /* flags, debug options etc. */
|
1989-02-07 11:04:05 +00:00
|
|
|
goto next_option;
|
|
|
|
|
1990-06-08 10:03:47 +00:00
|
|
|
#ifndef LINT
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1990-10-01 15:28:28 +00:00
|
|
|
#ifdef DBSYMTAB
|
|
|
|
case 'g': /* symbol table for debugger */
|
|
|
|
options['g'] = 1;
|
|
|
|
options['n'] = 1;
|
|
|
|
break;
|
|
|
|
#endif /* DBSYMTAB */
|
1990-06-08 10:03:47 +00:00
|
|
|
|
1989-02-07 11:04:05 +00:00
|
|
|
#ifndef LINT
|
|
|
|
#ifdef DATAFLOW
|
|
|
|
case 'd':
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* DATAFLOW */
|
1989-02-07 11:04:05 +00:00
|
|
|
case 'p': /* procentry/procexit */
|
|
|
|
case 'L' : /* no fil/lin */
|
|
|
|
case 'n': /* use no registers */
|
|
|
|
case 'w': /* no warnings will be given */
|
|
|
|
case 's': /* no stricts will be given */
|
1989-10-27 13:33:10 +00:00
|
|
|
case 'o': /* no complaints about old-style */
|
1989-02-07 11:04:05 +00:00
|
|
|
options[opt] = 1;
|
|
|
|
goto next_option;
|
1989-10-27 13:33:10 +00:00
|
|
|
case 'a': /* suppress all but errors diagnostics */
|
|
|
|
options['w'] = 1; /* implies -a */
|
|
|
|
options['s'] = 1;
|
|
|
|
goto next_option;
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
#ifdef LINT
|
|
|
|
case 'h': /* heuristic tests */
|
|
|
|
case 'v': /* no complaints about unused arguments */
|
|
|
|
case 'a': /* check long->int int->long conversions */
|
|
|
|
case 'b': /* don't report unreachable break-statements */
|
|
|
|
case 'x': /* complain about unused extern declared variables */
|
|
|
|
case 'u': /* no "used but not defined"; for pass 2 */
|
|
|
|
case 'L': /* lintlibrary */
|
|
|
|
loptions[opt] = 1;
|
|
|
|
goto next_option;
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
case 'M': /* maximum identifier length */
|
|
|
|
idfsize = txt2int(&text);
|
|
|
|
if (*text || idfsize <= 0)
|
|
|
|
fatal("malformed -M option");
|
|
|
|
if (idfsize > IDFSIZE)
|
|
|
|
fatal("maximum identifier length is %d", IDFSIZE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef LINT
|
|
|
|
case 'S' : { /* -Sint : static scope number for lint */
|
|
|
|
extern int stat_number;
|
|
|
|
stat_number = txt2int(&text);
|
|
|
|
break;
|
|
|
|
}
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-02-07 11:04:05 +00:00
|
|
|
|
|
|
|
case 'T' : {
|
|
|
|
#ifdef USE_TMP
|
|
|
|
extern char *C_tmpdir;
|
|
|
|
if (*text)
|
|
|
|
C_tmpdir = text;
|
|
|
|
else
|
|
|
|
C_tmpdir = ".";
|
1991-12-17 13:12:22 +00:00
|
|
|
#else /* USE_TMP */
|
1989-02-07 11:04:05 +00:00
|
|
|
warning("-T option ignored");
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* USE_TMP */
|
1989-02-07 11:04:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef LINT
|
1990-12-19 11:07:15 +00:00
|
|
|
#ifndef NOCROSS
|
1989-02-07 11:04:05 +00:00
|
|
|
case 'V' : /* set object sizes and alignment requirements */
|
|
|
|
{
|
|
|
|
register arith sz, algn;
|
|
|
|
char c;
|
|
|
|
|
2019-02-23 16:46:05 +00:00
|
|
|
while ( (c = *text++) !=0) {
|
1989-02-07 11:04:05 +00:00
|
|
|
sz = txt2int(&text);
|
|
|
|
algn = 0;
|
|
|
|
if (*text == '.') {
|
|
|
|
text++;
|
|
|
|
algn = txt2int(&text);
|
|
|
|
}
|
|
|
|
switch (c) {
|
|
|
|
case 's': /* short */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
short_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
short_align = algn;
|
|
|
|
break;
|
|
|
|
case 'w': /* word */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
dword_size = (word_size = sz) << 1;
|
|
|
|
if (algn != 0)
|
|
|
|
word_align = algn;
|
|
|
|
break;
|
|
|
|
case 'i': /* int */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
int_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
int_align = algn;
|
|
|
|
break;
|
|
|
|
case 'l': /* long */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
long_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
long_align = algn;
|
|
|
|
break;
|
|
|
|
case 'f': /* float */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
float_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
float_align = algn;
|
|
|
|
break;
|
|
|
|
case 'd': /* double */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
double_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
double_align = algn;
|
|
|
|
break;
|
|
|
|
case 'x': /* long double */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
lngdbl_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
lngdbl_align = algn;
|
|
|
|
break;
|
|
|
|
case 'p': /* pointer */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
pointer_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
pointer_align = algn;
|
|
|
|
break;
|
|
|
|
case 'r': /* adjust bitfields right */
|
|
|
|
#ifndef NOBITFIELD
|
|
|
|
options['r'] = 1;
|
1991-12-17 13:12:22 +00:00
|
|
|
#else /* NOBITFIELD */
|
1989-02-07 11:04:05 +00:00
|
|
|
warning("bitfields are not implemented");
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1989-02-07 11:04:05 +00:00
|
|
|
break;
|
|
|
|
case 'S': /* initial struct alignment */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
struct_align = sz;
|
|
|
|
break;
|
|
|
|
case 'U': /* initial union alignment */
|
|
|
|
if (sz != (arith)0)
|
|
|
|
union_align = sz;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("-V: bad type indicator %c\n", c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1991-03-01 13:51:37 +00:00
|
|
|
case 'S':
|
|
|
|
density = txt2int(&text);
|
|
|
|
break;
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* NOCROSS */
|
|
|
|
#endif /* LINT */
|
1989-02-07 11:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
static int txt2int(register char **tp)
|
1989-02-07 11:04:05 +00:00
|
|
|
{
|
|
|
|
/* the integer pointed to by *tp is read, while increasing
|
|
|
|
*tp; the resulting value is yielded.
|
|
|
|
*/
|
|
|
|
register int val = 0, ch;
|
|
|
|
|
|
|
|
while (ch = **tp, ch >= '0' && ch <= '9') {
|
|
|
|
val = val * 10 + ch - '0';
|
|
|
|
(*tp)++;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|