1 /* Loglan82 Compiler&Interpreter
2 Copyright (C) 1981-1993 Institute of Informatics, University of Warsaw
3 Copyright (C) 1993, 1994 LITA, Pau
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 contacts: Andrzej.Salwicki@univ-pau.fr
22 LITA Departement d'Informatique
24 Avenue de l'Universite
26 tel. ++33 59923154 fax. ++33 59841696
28 =======================================================================
42 * @brief Utility routines
46 * Compute entier (floor)
68 word shift(word x, word n)
75 return ((x >> -n) & ~(~(word)0 << (8 * sizeof(word) + n)));
80 * Get ASCIIZ string from arrayof char
82 char *asciiz(virtaddr *virt)
88 if (member(virt, &am)) {
89 /* length of the string */
91 /* allocate buffer for the string */
92 cp = ballocate(len + 1);
97 for (i = 0; i < len; i++)
98 cp[i] = (char) M[am + 3 + i];
100 /* terminate string with 0 byte */
105 /* reference to none */
111 * Add extension to a file name
113 void addext(char *fname, char *ext)
118 while (*cp != '\0' && *cp != '.')
128 * Print error message and abort
130 void abend(char *msg)
132 fprintf(stderr, "Error: %s\n", msg);
137 /* Pseudo random number generator */
139 static int ranpat1 = 7, ranpat2 = 503, ranpat3 = 15661;
142 * Initializes random number generator
149 ranpat1 = tim % 30269;
150 ranpat2 = tim % 30307;
151 ranpat3 = tim % 30323;
155 * Produces next pseudo random number
157 * @see ranset must be invoked before running this function
164 ranpat1 = 171 * (ranpat1 % 177) - 2 * (ranpat1 / 177);
168 ranpat2 = 172 * (ranpat2 % 176) - 35 * (ranpat2 / 176);
173 ranpat3 = 170 * (ranpat3 % 178) - 63 * (ranpat3 / 178);
178 r = ranpat1 / 30269.0 + ranpat2 / 30307.0 + ranpat3 / 30323.0;
184 * Copy a block of memory
186 * @param from[in] source block to copy from
187 * @param to[out] destination block to copy to
188 * @param len number of character to copy
190 void moveblock(char *from, char *to, word len)
197 /**************************************************************
200 void dump(word pix, word from, int len)
207 printf("%6ld: ", (long) from);
208 for (i = 0; i < LINE; i++)
209 printf("%7ld", (long)M[from++]);
214 **************************************************************/