1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
/* $Id: $ */
/* Copyright (C) 1997 Sverre Hvammen Johansen,
* Department of Informatics, University of Oslo.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "file.h"
#include "simfile.h"
/******************************************************************************
RUTINEOPTIONS */
static char
__roptions (antarg, arg1)
long antarg;
char arg1[];
{
long i,
size = 0;
if (antarg < 2)
return (__TRUE);
if (!__dynsize)
return (__TRUE);
if (arg1[0] != '-')
return (__TRUE);
if (arg1[1] != 'm' && arg1[1] != 'k' && arg1[1] != 'M' && arg1[1] != 'K')
return (__TRUE);
for (i = 2; arg1[i] >= '0' && arg1[i] <= '9'; i++)
size = size * 10 + arg1[i] - '0';
if (arg1[1] == 'm' || arg1[1] == 'M')
size *= 1024;
if (arg1[i] == '\0')
{
__maxsize = __poolsize = size;
if (arg1[1] == 'k' || arg1[1] == 'K')
(void) fprintf (stderr, "Poolsize is changed to %dK\n", __poolsize);
else
(void) fprintf (stderr, "Poolsize is changed to %dM\n",
__poolsize / 1024);
}
return (__TRUE);
}
/******************************************************************************
RutineAllocDynMem */
static void
__rallocdynmem (size)
long size;
{
__min = (__dhp) calloc ((unsigned) (size), (unsigned) 1);
if (!__min)
__rerror ("Allocdynmem: Virtual memory exhausted");
__fri = __min;
__max = (__dhp) ((char *) __min + size);
}
/******************************************************************************
RUTINESTART */
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#if HAVE_SIGFPE
RETSIGTYPE
__rfloat_trap ()
{
__rerror ("Arithmetic overflow");
}
#endif
#if HAVE_SIGSEGV
RETSIGTYPE
__rseg_trap ()
{
__rerror ("System error: Segmentation violation");
}
#endif
#if HAVE_SIGILL
RETSIGTYPE
__rillegal_trap ()
{
__rerror ("System error: Illegal instruction");
}
#endif
#if HAVE_SIGTRAP
RETSIGTYPE
__rtrace_trap ()
{
__rerror ("System error: Trace trap");
}
#endif
#if HAVE_SIGSYS
RETSIGTYPE
__rsys_trap ()
{
__rerror ("System error: Bad argument to system call");
}
#endif
#if HAVE_SIGBUS
RETSIGTYPE
__rbus_trap ()
{
__rerror ("System error: Bus error");
}
#endif
__rstart (argc, argv)
int argc;
char *argv[];
{
#if CLOCK
clock ();
#endif
__sysin.s.s.file = stdin;
__sysout.s.s.s.file = stdout;
__syserr.s.s.s.file = stderr;
__argc = (long) argc;
__argv = (long) argv;
__progname = argv[0];
__roptions (argc, argv[1]);
__init ();
/* SYSIN :- new infile("...");
* SYSOUT :- new printfile("...");
* SYSIN.open(blanks(INPUT_LINE_LENGTH));
* SYSOUT.open(blanks(OUTPUT_LINE_LENGTH));
* inspect SYSIN do
* inspect SYSOUT do */
if (__poolsize)
__rallocdynmem (__poolsize * (long) 1024);
else
__rallocdynmem (DYNMEMSIZEKB * (long) 1024);
__lb = __pb = (__dhp) & __blokk0FILE;
/* Fyller IMAGE til stdin og stdout med blanke */
__rtextvalassign (&((__bs2FILE *) __rsysin ())->IMAGE, (__txtvp) & __tk0);
__rtextvalassign (&((__bs2FILE *) __rsysout ())->IMAGE, (__txtvp) & __tk0);
__rtextvalassign (&((__bs2FILE *) __rsyserr ())->IMAGE, (__txtvp) & __tk0);
/* Kobler c1,c2 i blokk0 til objektene av infile og printfile * henholdsvis
*
* * * * * * * * * * sysin og sysout. */
__blokk0FILE.c1 = __rsysin ();
__blokk0FILE.c2 = __rsysout ();
#if HAVE_SIGFPE
signal (SIGFPE, __rfloat_trap);
#endif
#if HAVE_SIGSEGV
signal (SIGSEGV, __rseg_trap);
#endif
#if HAVE_SIGILL
signal (SIGILL, __rillegal_trap);
#endif
#if HAVE_SIGTRAP
signal (SIGTRAP, __rtrace_trap);
#endif
#if HAVE_SIGSYS
signal (SIGSYS, __rsys_trap);
#endif
#if HAVE_SIGBUS
signal (SIGBUS, __rbus_trap);
#endif
}
/******************************************************************************
RUTINESLUTT */
__rslutt ()
{
if (__gc && ((__bs1FILE *) __blokk0FILE.c2)->open)
{
__rpoutimage (__blokk0FILE.c2);
printf ("%d garbage collection(s) in %.1f seconds.", __gc, __gbctime);
if (__chpoolsize)
{
printf (" Poolsize changed to ");
if (__poolsize >= 1024)
printf ("%dM while running.", __poolsize / 1024);
else
printf ("%dK while running.", __poolsize);
}
printf ("\n");
}
__riclose (__rsysin ());
__roclose (__rsysout ());
__roclose (__rsyserr ());
}
|