ack/util/grind/main.c

158 lines
2.3 KiB
C
Raw Normal View History

/* $Header$ */
1990-08-31 18:22:53 +00:00
#include <stdio.h>
#include <varargs.h>
#include "tokenname.h"
#include "position.h"
#include "file.h"
#include "symbol.h"
#include "scope.h"
1990-09-25 17:40:47 +00:00
#include "Lpars.h"
1990-08-31 18:22:53 +00:00
1990-09-21 16:58:20 +00:00
static char *usage = "Usage: %s [<ack.out>] [<a.out>]";
char *progname;
1990-08-31 18:22:53 +00:00
char *AckObj;
char *AObj;
char *dirs[] = { "", 0 };
FILE *db_out;
FILE *db_in;
int debug;
extern struct tokenname tkidf[];
extern char *strindex();
extern int eof_seen;
1990-10-17 17:00:03 +00:00
extern int interrupted;
1990-08-31 18:22:53 +00:00
1990-09-25 17:40:47 +00:00
static struct tokenname shorts[] = {
{LIST, "l"},
{CONT, "c"},
{STEP, "s"},
{NEXT, "n"},
{DELETE, "d"},
{PRINT, "p"},
{RESTORE, "r"},
{TRACE, "t"},
{WHERE, "w"},
1990-09-25 17:40:47 +00:00
{ 0, 0}
};
1990-08-31 18:22:53 +00:00
main(argc, argv)
char *argv[];
{
char *p;
db_out = stdout;
db_in = stdin;
progname = argv[0];
init_del();
1990-08-31 18:22:53 +00:00
while (p = strindex(progname, '/')) {
progname = p + 1;
}
1990-09-07 14:56:24 +00:00
if (argv[1] && argv[1][0] == '-') {
1990-08-31 18:22:53 +00:00
switch(argv[1][1]) {
case 'd':
debug++;
break;
default:
fatal(usage, progname);
}
argv++;
argc--;
}
if (argc > 3) {
fatal(usage, progname);
}
AckObj = argv[1] ? argv[1] : "a.out";
if (argc == 3) AObj = argv[2];
init_idf();
init_types();
init_scope();
init_languages();
if (DbRead(AckObj) && AObj == 0) AObj = AckObj;
1990-08-31 18:22:53 +00:00
else if (AObj == 0) AObj = "a.out";
reserve(tkidf);
1990-09-25 17:40:47 +00:00
reserve(shorts);
1990-08-31 18:22:53 +00:00
if (! init_run()) {
fatal("something wrong with file descriptors");
}
prompt();
Commands();
if (eof_seen) putc('\n', db_out);
1990-08-31 18:22:53 +00:00
exit(0);
}
prompt()
{
if (isatty(fileno(db_in))) {
fprintf(db_out, "-> ");
1990-08-31 18:22:53 +00:00
fflush(db_out);
}
}
/*VARARGS*/
1990-08-31 18:22:53 +00:00
fatal(va_alist)
va_dcl
{
va_list ap;
char *fmt;
va_start(ap);
{
fmt = va_arg(ap, char *);
fprintf(db_out, "%s: ", progname);
vfprintf(db_out, fmt, ap);
fprintf(db_out, "\n");
1990-08-31 18:22:53 +00:00
}
va_end(ap);
exit(1);
}
extern int errorgiven;
/*VARARGS*/
1990-08-31 18:22:53 +00:00
error(va_alist)
va_dcl
{
va_list ap;
char *fmt;
1990-10-17 17:00:03 +00:00
if (! interrupted) {
va_start(ap);
{
fmt = va_arg(ap, char *);
fprintf(db_out, "%s: ", progname);
vfprintf(db_out, fmt, ap);
fprintf(db_out, "\n");
}
va_end(ap);
1990-08-31 18:22:53 +00:00
}
errorgiven = 1;
}
/*VARARGS*/
1990-09-14 14:37:26 +00:00
warning(va_alist)
va_dcl
{
va_list ap;
char *fmt;
va_start(ap);
{
fmt = va_arg(ap, char *);
fprintf(db_out, "%s: ", progname);
vfprintf(db_out, fmt, ap);
fprintf(db_out, "\n");
1990-09-14 14:37:26 +00:00
}
va_end(ap);
}
1990-08-31 18:22:53 +00:00
rd_fatal()
{
fatal("read error in %s", AckObj);
}
No_Mem()
{
fatal("out of memory");
}