Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / pass1 / main.c
1      /* Loglan82 Compiler&Interpreter
2      Copyright (C) 1981-1993 Institute of Informatics, University of Warsaw
3      Copyright (C)  1993, 1994 LITA, Pau
4      
5      This program is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published by
7      the Free Software Foundation; either version 2 of the License, or
8      (at your option) any later version.
9      
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14      
15
16 =======================================================================
17 */
18
19 #if WSIZE==4
20         typedef long word;
21 #elif WSIZE==2
22         typedef short word;
23 #else
24  Define WSIZE to 2 or 4 !
25 #endif
26
27 char blank_[ (unsigned long)( 302 + LMEMSIZE ) * WSIZE ]; /* whole memory of compiler */
28
29
30 #include "stdio.h"
31 #include "signal.h"
32
33 #ifndef SIGIOT
34 #ifdef SIGTRAP
35 #define SIGIOT SIGTRAP
36 #else
37 #define SIGIOT SIGILL
38 #endif
39 #endif
40
41
42 static void sigdie(s, kill) register char *s; int kill; {
43    /* print error message, then clear buffers */
44    fflush(stdout);
45    fflush(stderr);
46    fprintf(stderr, "%s\n", s);
47    fflush(stderr);
48
49    if(kill) {
50       /* now get a core */
51       signal(SIGIOT, 0);
52       abort();
53    }
54    else
55       exit(1);
56 }
57
58 static void sigfdie(n){ sigdie("Floating Exception", 1);}
59 static void sigidie(n){ sigdie("IOT Trap", 1);          }
60 static void sigqdie(n){ sigdie("Quit signal", 1);       }
61 static void signdie(n){sigdie("Interrupt", 0);          }
62 static void sigtdie(n){ sigdie("Killed", 0);            }
63
64
65 int main(argc, argv) int argc; char **argv; {
66
67    word parlen, i;
68    char parbuf[128];
69
70    signal(SIGFPE, sigfdie);     /* ignore underflow, enable overflow */
71    signal(SIGIOT, sigidie);
72 #ifdef SIGQUIT
73    if( (int)signal(SIGQUIT,sigqdie) & 01) signal(SIGQUIT, SIG_IGN);
74 #endif
75    if( (int)signal(SIGINT, signdie) & 01) signal(SIGINT, SIG_IGN);
76    signal(SIGTERM,sigtdie);
77
78 #ifdef pdp11
79    ldfps(01200); /* detect overflow as an exception */
80 #endif
81
82    parbuf[ 0 ] = '\0';
83    for (i = 1; i < argc; i++)
84    {
85        strcat( parbuf, " " );
86        strcat( parbuf, argv[i] );
87    }
88    parlen = strlen(parbuf);
89    loglan_( &parlen, parbuf );
90
91    return 0;
92 }
93
94