Removed dummy GNU function declarations.
[vlp.git] / src / int / util.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              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.
18
19  contacts:  Andrzej.Salwicki@univ-pau.fr
20
21 or             Andrzej Salwicki
22                 LITA   Departement d'Informatique
23                 Universite de Pau
24                 Avenue de l'Universite
25                 64000 Pau   FRANCE
26                  tel.  ++33 59923154    fax. ++33 59841696
27
28 =======================================================================
29 */
30
31 #include "depend.h"
32 #include "genint.h"
33 #include "int.h"
34 #include "process.h"
35 #include "intproto.h"
36
37
38 #include <time.h>
39
40 /* Utility routines */
41
42 /**
43  * Compute entier (floor)
44  */
45 word entier(double x)
46 {
47     word i;
48
49     if (x >= 0.0)
50     {
51         i = (word)x;
52         return(i);
53     }
54     else
55     {
56         i = (word)(-x);
57         i = -i;
58         if ((double)i <= x) return(i);  else return(i-1);
59     }
60 }
61
62 /**
63  * shift x by n bits
64  */
65 word shift(word x, word n)
66 {
67     if (n == 0) return (x);
68     if (n > 0) return (x << n);
69     else return ( (x >> -n) & ~(~(word)0 << (8*sizeof(word)+n)) );
70 }
71
72
73 /**
74  * Get ASCIIZ string from arrayof char
75  */
76 char *asciiz(virtaddr *virt)
77 {
78     word am;
79     int len, i;
80     char *cp;
81
82     if (member(virt, &am))
83     {
84         len = M[ am ]-3;                /* length of the string */
85         cp = ballocate(len+1);          /* allocate buffer for the string */
86         if (cp == NULL) errsignal(RTEMEMOV);
87         for (i = 0;  i < len;  i++) cp[ i ] = (char) M[ am+3+i ];
88         cp[ len ] = '\0';               /* terminate string with 0 byte */
89         return (cp);
90     }
91     else errsignal(RTEREFTN);           /* reference to none */
92 }
93
94 /**
95  * Add extension to a file name
96  */
97 void addext(char *fname, char *ext)
98 {
99     char *cp;
100
101     cp = fname;
102     while (*cp != '\0' && *cp != '.') cp++;
103     strcpy(cp, ext);
104 }
105
106 void usage()
107 {
108 }
109
110 /**
111  * Print error message and abort
112  */
113 void abend(char *msg)
114 {
115     fprintf(stderr, "Error: %s\n", msg);
116     exit(8);
117 } /* end abend */
118
119
120 /* Pseudo random number generator */
121
122 static int ranpat1 = 7, ranpat2 = 503, ranpat3 = 15661;
123
124 /**
125  * Initialize generator
126  */
127 void ranset()
128 {
129     long tim;
130
131     time(&tim);
132     ranpat1 = tim % 30269;
133     ranpat2 = tim % 30307;
134     ranpat3 = tim % 30323;
135 }
136
137 /**
138  * Produce next pseudo random number
139  */
140 double prandom()
141 {
142     int i;
143     double r;
144
145     ranpat1 = 171*(ranpat1 % 177)- 2*(ranpat1 / 177);
146     if (ranpat1 < 0) ranpat1 += 30269;
147     ranpat2 = 172*(ranpat2 % 176)-35*(ranpat2 / 176);
148     if (ranpat2 < 0) ranpat2 += 30307;
149     ranpat3 = 170*(ranpat3 % 178)-63*(ranpat3 / 178);
150     if (ranpat3 < 0) ranpat3 += 30323;
151     r = ranpat1/30269.0 + ranpat2/30307.0 + ranpat3/30323.0;
152     i = (int)r;
153     return (r-i);
154 }
155
156 /**
157  * Copy a block of memory
158  */
159 void moveblock(char *from, char *to, word len)
160 {
161         while (len-- > 0) {
162                 *to++ = *from++;
163         }
164 }
165
166 /**************************************************************
167
168 #define LINE    10
169 void dump(pix, from, len)
170 word pix, from;
171 int len;
172 {
173     int i;
174     memory M;
175
176     M = process[ pix ].M;
177     while (len > 0)
178     {
179         printf("%6ld: ", (long) from);
180         for (i = 0; i < LINE; i++) printf("%7ld", (long)M[from++]);
181         putchar('\n');
182         len -= LINE;
183     }
184 }
185
186  **************************************************************/
187