ack/util/opt/main.c

102 lines
1.7 KiB
C
Raw Permalink Normal View History

/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Hans van Staveren
*/
#include <stdlib.h>
1984-05-17 13:42:36 +00:00
#include <stdio.h>
#include "param.h"
#include "types.h"
#include "tes.h"
1984-05-17 13:42:36 +00:00
#include "alloc.h"
#include "system.h"
#include <em_spec.h>
1984-05-17 13:42:36 +00:00
#include "ext.h"
#include "util.h"
#include "getline.h"
#include "putline.h"
/* Other external definitions */
extern void cleanup(void);
void flags(register char *s)
{
for (s++; *s; s++)
switch (*s)
{
case 'L':
Lflag = TRUE;
break;
case 'n':
nflag = TRUE;
break;
case 'm':
if (*(s + 1) == 'l')
{
s++;
repl_longmuls = TRUE;
}
repl_muls = atoi(s + 1);
break;
}
}
void fileinit(void)
{
if (readshort() != (short) sp_magic)
error("wrong input file");
if (Lflag)
{
tempname = sys_maketempfile("opt", "dat");
outfile = fopen(tempname, "wb");
if (outfile == NULL)
error("can't create %s", tempname);
}
else
{
sys_setbinarymode(stdout);
outfile = stdout;
outshort(sp_magic);
}
}
1984-05-17 13:42:36 +00:00
/*
* Main program for EM optimizer
*/
int main(int argc, char* argv[])
{
#ifndef USEMALLOC
1988-04-19 19:46:28 +00:00
int somespace[STACKROOM];
#endif
1984-05-17 13:42:36 +00:00
progname = argv[0];
while (argc-- > 1 && **++argv == '-')
1984-05-17 13:42:36 +00:00
flags(*argv);
if (argc > 1)
{
fprintf(stderr, "Usage: %s [-Ln] [-m<num>] [name]\n", progname);
exit(EXIT_FAILURE);
1984-05-17 13:42:36 +00:00
}
if (argc)
{
if (freopen(*argv, "rb", stdin) == NULL)
error("Cannot open %s", *argv);
}
else
sys_setbinarymode(stdin);
1984-05-17 13:42:36 +00:00
fileinit();
#ifdef USEMALLOC
coreinit();
#else
coreinit((short *) somespace, (short *) (somespace + STACKROOM));
#endif
1984-05-17 13:42:36 +00:00
getlines();
cleanup();
return (EXIT_SUCCESS);
1984-05-17 13:42:36 +00:00
}