/* Copyright 1995, 1997 J"orn Rennecke */
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <signal.h>
#include "common.h"
#include "lex.h"
#include "object.h"
svalue master_name, boot_fun;
svalue driver_hook[NUM_DRIVER_HOOKS];
char *mudlib = MUDLIB;
int main(int argc, char **argv) {
char **argp, *arg;
int i;
init_alloc();
init_global_strings();
master_name = make_string(MASTER_NAME, strlen(MASTER_NAME));
boot_fun = make_string(BOOT_FUN, strlen(BOOT_FUN));
for (argp = &argv[1], i = argc; --i > 0; ) {
arg = *argp++;
if (*arg == '-') switch(arg[1]) {
case 'D':
if (arg[2]) {
commandline_define(arg+2);
continue;
}
break;
case 'M':
arg += 2;
if (!*arg && --i > 0)
arg = *argp++;
FREE_SVALUE(master_name);
master_name = make_string(arg, strlen(arg));
break;
case 'm':
arg += 2;
if (!*arg && --i > 0)
arg = *argp++;
mudlib = arg;
break;
#ifdef YYDEBUG
case 'y':
{
extern int yydebug;
yydebug++;
break;
}
#endif
#ifdef LEXDEBUG
case 'l':
{
extern int lexdebug;
lexdebug++;
break;
}
#endif
#if TIME_TO_SWAP > 0
case 's':
if (arg[2] == 'v') {
time_to_swap_variables =
(unsigned)atoi(&arg[3])/ASYNC_GRANULARITY;
if (time_to_swap_variables < 0)
time_to_swap_variables = (unsigned)~0>>1;
} else if (arg[2] == 'f') {
extern void name_swap_file(char*);
name_swap_file(&arg[3]);
} else {
time_to_swap = (unsigned)atoi(&arg[2])/ASYNC_GRANULARITY;
if (time_to_swap < 0)
time_to_swap = (unsigned)~0>>1;
}
continue;
#endif
} else if (isdigit(*arg)) {
extern int port_number;
port_number = atoi(arg);
}
}
if (chdir(mudlib) < 0)
fatal("Bad mudlib directory: %s\n", mudlib);
if (mudlib[0] != '/') {
#ifdef MAXPATHLEN
char path[MAXPATHLEN];
#else
char path[2048];
#endif
#ifdef HAVE_GETCWD
if (!getcwd(path, sizeof(path) ))
#else
if (!getwd(path))
#endif
{
perror("get(c)wd failed");
fatal("must be able to obtain current directory name\n");
}
mudlib = strdup(path);
}
initialize_host_ip_number();
initialize_uids();
initialize_lex();
initialize_interpreter();
(void)signal(SIGFPE, fpe_handler);
init_otable();
init_comm();
schedule(); /* enter main loop */
}
void fatal(char *fmt, ...) {
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
sleep(1);
/* make a nice core */
(void)signal(SIGFPE, SIG_DFL);
*((char*)0) = 0/0;
/* if this didnt work.. */
abort();
}
void debug_message(char *fmt, ...) {
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
}
svalue *f_shutdown(svalue * sp) {
exit(0);
return sp;
}