diff options
author | Pixel <> | 2001-04-17 01:04:24 +0000 |
---|---|---|
committer | Pixel <> | 2001-04-17 01:04:24 +0000 |
commit | 17d89e026ee39bd30f8604ab397708d9bceb2fbf (patch) | |
tree | 29e7053661656203ae56db7439de9b5c8de293b1 /src | |
parent | 4f2aa7d436bb50cef3f9a551f79fa03ea275ab77 (diff) |
GRou
Diffstat (limited to 'src')
-rw-r--r-- | src/simul.c | 109 |
1 files changed, 99 insertions, 10 deletions
diff --git a/src/simul.c b/src/simul.c index 1ae3d55..45c8092 100644 --- a/src/simul.c +++ b/src/simul.c @@ -1,22 +1,111 @@ #include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <signal.h> -#ifdef HAVE_CONFIG_H #include "config.h" -#else -#define _(x) x -#endif - #include "simulator.h" #include "alu.h" #include "terminal.h" +#include "exceptions.h" + +typedef void (*sighandler_t) (int); -int main(void) +void invite(void) { - openterm(); - Rapide = 1; + fprintf(stderr, _("Simul v1.0\n\n")); +} + +void usage(void) +{ + fprintf(stderr, _("Usage: linker [-q] [-d] binary\n")); + exit(0); +} + +void init_all(void) +{ + fprintf(stderr, _(" o Initialising the simulator... ")); + Initialisation(); + fprintf(stderr, _(" Done!\n")); +} + +void flush_all(void) +{ + Flush(); +} + +void segfaulthand(int i) +{ + exception(1, _("Signal received: segfault")); +} + +void ctrlbreakhand(int i) { debug = 1; - ChargeBinaire("progtest"); +} + +char * readargs(int argc, char ** argv) { + char * r = NULL; + + argc--; + argv++; + + while (argc) { + if (**argv == '-') { + switch ((*argv)[1]) { + case 'q': + Rapide = 1; + break; + case 'd': + debug = 1; + break; + default: + usage(); + } + } else { + if (r) { + usage(); + } + r = *argv; + } + argv++; + argc--; + } + + if (!r) { + usage(); + } + return r; +} + +int main(int argc, char **argv) +{ + int i; + char * nom; + + invite(); + + nom = readargs(argc, argv); + + signal(SIGSEGV, segfaulthand); + signal(SIGINT, ctrlbreakhand); + + fprintf(stderr, _("\nPerforming initialisation...\n\n")); + init_all(); + + pushcontext(_("Beginning simulation")); + + openterm(); + initterm(); + clearterm(); + ChargeBinaire(nom); clearterm(); - return (0); + + popcontext(); + + fprintf(stderr, _("\nPerforming shutdown...\n\n")); + flush_all(); + + fprintf(stderr, _("Exitting, bye!\n")); + return 0; } |