]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | @c Copyright (C) 2000-2023 Free Software Foundation, Inc. |
1eee94d3 GM |
2 | @c This file is part of GNU Modula-2. |
3 | ||
4 | @c Permission is granted to copy, distribute and/or modify this document | |
5 | @c under the terms of the GNU Free Documentation License, Version 1.2 or | |
6 | @c any later version published by the Free Software Foundation. | |
7 | @menu | |
8 | * Base libraries::Basic M2F compatible libraries | |
9 | * PIM and Logitech 3.0 Compatible::PIM and Logitech 3.0 compatible libraries | |
10 | * PIM coroutine support::PIM compatible process support | |
11 | * M2 ISO Libraries::ISO defined libraries | |
12 | @end menu | |
13 | ||
14 | @c ============================================================ | |
15 | ||
16 | @node Base libraries, PIM and Logitech 3.0 Compatible, , Libraries | |
17 | @section Base libraries | |
18 | ||
19 | @c README.texi describes the pim libraries. | |
83ffe9cd | 20 | @c Copyright @copyright{} 2000-2023 Free Software Foundation, Inc. |
1eee94d3 GM |
21 | @c |
22 | @c This is part of the GM2 manual. | |
23 | @c For copying conditions, see the file gcc/doc/include/fdl.texi. | |
24 | ||
25 | These are the base libraries for the GNU Modula-2 compiler. These | |
26 | modules originally came from the M2F compiler and have been cleaned up | |
27 | and extended. They provide a basic interface to the underlying | |
28 | operating system via libc. They also include a number of libraries to | |
29 | allow access to compiler built-ins. Perhaps the largest difference to | |
30 | PIM and ISO libraries is the @code{DynamicString} module which | |
31 | declares the type @code{String}. The heavy use of this opaque data | |
32 | type results in a number of equivalent modules that can either handle | |
33 | @code{ARRAY OF CHAR} or @code{String}. | |
34 | ||
35 | These modules have been extensively tested and are used throughout | |
36 | building the GNU Modula-2 compiler. | |
37 | @menu | |
38 | * gm2-libs/ASCII::ASCII.def | |
39 | * gm2-libs/Args::Args.def | |
40 | * gm2-libs/Assertion::Assertion.def | |
41 | * gm2-libs/Break::Break.def | |
42 | * gm2-libs/Builtins::Builtins.def | |
43 | * gm2-libs/COROUTINES::COROUTINES.def | |
44 | * gm2-libs/CmdArgs::CmdArgs.def | |
45 | * gm2-libs/Debug::Debug.def | |
46 | * gm2-libs/DynamicStrings::DynamicStrings.def | |
47 | * gm2-libs/Environment::Environment.def | |
48 | * gm2-libs/FIO::FIO.def | |
49 | * gm2-libs/FormatStrings::FormatStrings.def | |
50 | * gm2-libs/FpuIO::FpuIO.def | |
51 | * gm2-libs/GetOpt::GetOpt.def | |
52 | * gm2-libs/IO::IO.def | |
53 | * gm2-libs/Indexing::Indexing.def | |
54 | * gm2-libs/LMathLib0::LMathLib0.def | |
55 | * gm2-libs/LegacyReal::LegacyReal.def | |
56 | * gm2-libs/M2Dependent::M2Dependent.def | |
57 | * gm2-libs/M2EXCEPTION::M2EXCEPTION.def | |
58 | * gm2-libs/M2LINK::M2LINK.def | |
59 | * gm2-libs/M2RTS::M2RTS.def | |
60 | * gm2-libs/MathLib0::MathLib0.def | |
61 | * gm2-libs/MemUtils::MemUtils.def | |
62 | * gm2-libs/NumberIO::NumberIO.def | |
63 | * gm2-libs/OptLib::OptLib.def | |
64 | * gm2-libs/PushBackInput::PushBackInput.def | |
65 | * gm2-libs/RTExceptions::RTExceptions.def | |
66 | * gm2-libs/RTint::RTint.def | |
67 | * gm2-libs/SArgs::SArgs.def | |
68 | * gm2-libs/SCmdArgs::SCmdArgs.def | |
69 | * gm2-libs/SEnvironment::SEnvironment.def | |
70 | * gm2-libs/SFIO::SFIO.def | |
71 | * gm2-libs/SMathLib0::SMathLib0.def | |
72 | * gm2-libs/SYSTEM::SYSTEM.def | |
73 | * gm2-libs/Scan::Scan.def | |
74 | * gm2-libs/Selective::Selective.def | |
75 | * gm2-libs/StdIO::StdIO.def | |
76 | * gm2-libs/Storage::Storage.def | |
77 | * gm2-libs/StrCase::StrCase.def | |
78 | * gm2-libs/StrIO::StrIO.def | |
79 | * gm2-libs/StrLib::StrLib.def | |
80 | * gm2-libs/StringConvert::StringConvert.def | |
81 | * gm2-libs/SysExceptions::SysExceptions.def | |
82 | * gm2-libs/SysStorage::SysStorage.def | |
83 | * gm2-libs/TimeString::TimeString.def | |
84 | * gm2-libs/UnixArgs::UnixArgs.def | |
85 | * gm2-libs/cbuiltin::cbuiltin.def | |
86 | * gm2-libs/cgetopt::cgetopt.def | |
87 | * gm2-libs/cxxabi::cxxabi.def | |
88 | * gm2-libs/dtoa::dtoa.def | |
89 | * gm2-libs/errno::errno.def | |
90 | * gm2-libs/gdbif::gdbif.def | |
91 | * gm2-libs/ldtoa::ldtoa.def | |
92 | * gm2-libs/libc::libc.def | |
93 | * gm2-libs/libm::libm.def | |
94 | * gm2-libs/sckt::sckt.def | |
95 | * gm2-libs/termios::termios.def | |
96 | * gm2-libs/wrapc::wrapc.def | |
97 | @end menu | |
98 | ||
99 | @node gm2-libs/ASCII, gm2-libs/Args, , Base libraries | |
100 | @subsection gm2-libs/ASCII | |
101 | ||
102 | @example | |
103 | DEFINITION MODULE ASCII ; | |
104 | ||
105 | EXPORT QUALIFIED | |
106 | nul, soh, stx, etx, eot, enq, ack, bel, | |
107 | bs , ht , nl , vt , np , cr , so , si , | |
108 | dle, dc1, dc2, dc3, dc4, nak, syn, etb, | |
109 | can, em , sub, esc, fs , gs , rs , us , | |
110 | sp , (* All the above are in order *) | |
111 | lf, ff, eof, del, tab, EOL ; | |
112 | ||
113 | (* | |
114 | Note that lf, eof and EOL are added. | |
115 | *) | |
116 | ||
117 | CONST | |
118 | @findex nul (const) | |
119 | @findex soh (const) | |
120 | @findex stx (const) | |
121 | @findex etx (const) | |
122 | nul=000C; soh=001C; stx=002C; etx=003C; | |
123 | @findex eot (const) | |
124 | @findex enq (const) | |
125 | @findex ack (const) | |
126 | @findex bel (const) | |
127 | eot=004C; enq=005C; ack=006C; bel=007C; | |
128 | @findex bs (const) | |
129 | @findex ht (const) | |
130 | @findex nl (const) | |
131 | @findex vt (const) | |
132 | bs =010C; ht =011C; nl =012C; vt =013C; | |
133 | @findex np (const) | |
134 | @findex cr (const) | |
135 | @findex so (const) | |
136 | @findex si (const) | |
137 | np =014C; cr =015C; so =016C; si =017C; | |
138 | @findex dle (const) | |
139 | @findex dc1 (const) | |
140 | @findex dc2 (const) | |
141 | @findex dc3 (const) | |
142 | dle=020C; dc1=021C; dc2=022C; dc3=023C; | |
143 | @findex dc4 (const) | |
144 | @findex nak (const) | |
145 | @findex syn (const) | |
146 | @findex etb (const) | |
147 | dc4=024C; nak=025C; syn=026C; etb=027C; | |
148 | @findex can (const) | |
149 | @findex em (const) | |
150 | @findex sub (const) | |
151 | @findex esc (const) | |
152 | can=030C; em =031C; sub=032C; esc=033C; | |
153 | @findex fs (const) | |
154 | @findex gs (const) | |
155 | @findex rs (const) | |
156 | @findex us (const) | |
157 | fs =034C; gs =035C; rs =036C; us =037C; | |
158 | @findex sp (const) | |
159 | sp =040C; (* All the above are in order *) | |
160 | @findex lf (const) | |
161 | @findex ff (const) | |
162 | @findex eof (const) | |
163 | @findex tab (const) | |
164 | lf =nl ; ff =np ; eof=eot ; tab=ht ; | |
165 | @findex del (const) | |
166 | @findex EOL (const) | |
167 | del=177C; EOL=nl ; | |
168 | ||
169 | END ASCII. | |
170 | @end example | |
171 | @page | |
172 | ||
173 | @node gm2-libs/Args, gm2-libs/Assertion, gm2-libs/ASCII, Base libraries | |
174 | @subsection gm2-libs/Args | |
175 | ||
176 | @example | |
177 | DEFINITION MODULE Args ; | |
178 | ||
179 | EXPORT QUALIFIED GetArg, Narg ; | |
180 | ||
181 | ||
182 | (* | |
183 | GetArg - returns the nth argument from the command line. | |
184 | The success of the operation is returned. | |
185 | *) | |
186 | ||
187 | @findex GetArg | |
188 | PROCEDURE GetArg (VAR a: ARRAY OF CHAR; n: CARDINAL) : BOOLEAN ; | |
189 | ||
190 | ||
191 | (* | |
192 | Narg - returns the number of arguments available from | |
193 | command line. | |
194 | *) | |
195 | ||
196 | @findex Narg | |
197 | PROCEDURE Narg () : CARDINAL ; | |
198 | ||
199 | ||
200 | END Args. | |
201 | @end example | |
202 | @page | |
203 | ||
204 | @node gm2-libs/Assertion, gm2-libs/Break, gm2-libs/Args, Base libraries | |
205 | @subsection gm2-libs/Assertion | |
206 | ||
207 | @example | |
208 | DEFINITION MODULE Assertion ; | |
209 | ||
210 | EXPORT QUALIFIED Assert ; | |
211 | ||
212 | ||
213 | (* | |
214 | Assert - tests the boolean Condition, if it fails then HALT | |
215 | is called. | |
216 | *) | |
217 | ||
218 | @findex Assert | |
219 | PROCEDURE Assert (Condition: BOOLEAN) ; | |
220 | ||
221 | ||
222 | END Assertion. | |
223 | @end example | |
224 | @page | |
225 | ||
226 | @node gm2-libs/Break, gm2-libs/Builtins, gm2-libs/Assertion, Base libraries | |
227 | @subsection gm2-libs/Break | |
228 | ||
229 | @example | |
230 | DEFINITION MODULE Break ; | |
231 | ||
232 | END Break. | |
233 | @end example | |
234 | @page | |
235 | ||
236 | @node gm2-libs/Builtins, gm2-libs/COROUTINES, gm2-libs/Break, Base libraries | |
237 | @subsection gm2-libs/Builtins | |
238 | ||
239 | @example | |
240 | DEFINITION MODULE Builtins ; | |
241 | ||
242 | FROM SYSTEM IMPORT ADDRESS ; | |
243 | ||
244 | (* floating point intrinsic procedure functions *) | |
245 | ||
246 | @findex isfinitef | |
247 | PROCEDURE __BUILTIN__ isfinitef (x: SHORTREAL) : BOOLEAN ; | |
248 | @findex isfinite | |
249 | PROCEDURE __BUILTIN__ isfinite (x: REAL) : BOOLEAN ; | |
250 | @findex isfinitel | |
251 | PROCEDURE __BUILTIN__ isfinitel (x: LONGREAL) : BOOLEAN ; | |
252 | ||
253 | @findex sinf | |
254 | PROCEDURE __BUILTIN__ sinf (x: SHORTREAL) : SHORTREAL ; | |
255 | @findex sin | |
256 | PROCEDURE __BUILTIN__ sin (x: REAL) : REAL ; | |
257 | @findex sinl | |
258 | PROCEDURE __BUILTIN__ sinl (x: LONGREAL) : LONGREAL ; | |
259 | ||
260 | @findex cosf | |
261 | PROCEDURE __BUILTIN__ cosf (x: SHORTREAL) : SHORTREAL ; | |
262 | @findex cos | |
263 | PROCEDURE __BUILTIN__ cos (x: REAL) : REAL ; | |
264 | @findex cosl | |
265 | PROCEDURE __BUILTIN__ cosl (x: LONGREAL) : LONGREAL ; | |
266 | ||
267 | @findex sqrtf | |
268 | PROCEDURE __BUILTIN__ sqrtf (x: SHORTREAL) : SHORTREAL ; | |
269 | @findex sqrt | |
270 | PROCEDURE __BUILTIN__ sqrt (x: REAL) : REAL ; | |
271 | @findex sqrtl | |
272 | PROCEDURE __BUILTIN__ sqrtl (x: LONGREAL) : LONGREAL ; | |
273 | ||
274 | @findex atan2f | |
275 | PROCEDURE __BUILTIN__ atan2f (x, y: SHORTREAL) : SHORTREAL ; | |
276 | @findex atan2 | |
277 | PROCEDURE __BUILTIN__ atan2 (x, y: REAL) : REAL ; | |
278 | @findex atan2l | |
279 | PROCEDURE __BUILTIN__ atan2l (x, y: LONGREAL) : LONGREAL ; | |
280 | ||
281 | @findex fabsf | |
282 | PROCEDURE __BUILTIN__ fabsf (x: SHORTREAL) : SHORTREAL ; | |
283 | @findex fabs | |
284 | PROCEDURE __BUILTIN__ fabs (x: REAL) : REAL ; | |
285 | @findex fabsl | |
286 | PROCEDURE __BUILTIN__ fabsl (x: LONGREAL) : LONGREAL ; | |
287 | ||
288 | @findex logf | |
289 | PROCEDURE __BUILTIN__ logf (x: SHORTREAL) : SHORTREAL ; | |
290 | @findex log | |
291 | PROCEDURE __BUILTIN__ log (x: REAL) : REAL ; | |
292 | @findex logl | |
293 | PROCEDURE __BUILTIN__ logl (x: LONGREAL) : LONGREAL ; | |
294 | ||
295 | @findex expf | |
296 | PROCEDURE __BUILTIN__ expf (x: SHORTREAL) : SHORTREAL ; | |
297 | @findex exp | |
298 | PROCEDURE __BUILTIN__ exp (x: REAL) : REAL ; | |
299 | @findex expl | |
300 | PROCEDURE __BUILTIN__ expl (x: LONGREAL) : LONGREAL ; | |
301 | ||
302 | @findex log10f | |
303 | PROCEDURE __BUILTIN__ log10f (x: SHORTREAL) : SHORTREAL ; | |
304 | @findex log10 | |
305 | PROCEDURE __BUILTIN__ log10 (x: REAL) : REAL ; | |
306 | @findex log10l | |
307 | PROCEDURE __BUILTIN__ log10l (x: LONGREAL) : LONGREAL ; | |
308 | ||
309 | @findex exp10f | |
310 | PROCEDURE __BUILTIN__ exp10f (x: SHORTREAL) : SHORTREAL ; | |
311 | @findex exp10 | |
312 | PROCEDURE __BUILTIN__ exp10 (x: REAL) : REAL ; | |
313 | @findex exp10l | |
314 | PROCEDURE __BUILTIN__ exp10l (x: LONGREAL) : LONGREAL ; | |
315 | ||
316 | @findex ilogbf | |
317 | PROCEDURE __BUILTIN__ ilogbf (x: SHORTREAL) : INTEGER ; | |
318 | @findex ilogb | |
319 | PROCEDURE __BUILTIN__ ilogb (x: REAL) : INTEGER ; | |
320 | @findex ilogbl | |
321 | PROCEDURE __BUILTIN__ ilogbl (x: LONGREAL) : INTEGER ; | |
322 | ||
323 | @findex huge_val | |
324 | PROCEDURE __BUILTIN__ huge_val () : REAL ; | |
325 | @findex huge_valf | |
326 | PROCEDURE __BUILTIN__ huge_valf () : SHORTREAL ; | |
327 | @findex huge_vall | |
328 | PROCEDURE __BUILTIN__ huge_vall () : LONGREAL ; | |
329 | ||
330 | @findex significand | |
331 | PROCEDURE __BUILTIN__ significand (r: REAL) : REAL ; | |
332 | @findex significandf | |
333 | PROCEDURE __BUILTIN__ significandf (s: SHORTREAL) : SHORTREAL ; | |
334 | @findex significandl | |
335 | PROCEDURE __BUILTIN__ significandl (l: LONGREAL) : LONGREAL ; | |
336 | ||
337 | @findex modf | |
338 | PROCEDURE __BUILTIN__ modf (x: REAL; VAR y: REAL) : REAL ; | |
339 | @findex modff | |
340 | PROCEDURE __BUILTIN__ modff (x: SHORTREAL; | |
341 | VAR y: SHORTREAL) : SHORTREAL ; | |
342 | @findex modfl | |
343 | PROCEDURE __BUILTIN__ modfl (x: LONGREAL; VAR y: LONGREAL) : LONGREAL ; | |
344 | ||
345 | @findex signbit | |
346 | PROCEDURE __BUILTIN__ signbit (r: REAL) : INTEGER ; | |
347 | @findex signbitf | |
348 | PROCEDURE __BUILTIN__ signbitf (s: SHORTREAL) : INTEGER ; | |
349 | @findex signbitl | |
350 | PROCEDURE __BUILTIN__ signbitl (l: LONGREAL) : INTEGER ; | |
351 | ||
352 | @findex nextafter | |
353 | PROCEDURE __BUILTIN__ nextafter (x, y: REAL) : REAL ; | |
354 | @findex nextafterf | |
355 | PROCEDURE __BUILTIN__ nextafterf (x, y: SHORTREAL) : SHORTREAL ; | |
356 | @findex nextafterl | |
357 | PROCEDURE __BUILTIN__ nextafterl (x, y: LONGREAL) : LONGREAL ; | |
358 | ||
359 | @findex nexttoward | |
360 | PROCEDURE __BUILTIN__ nexttoward (x, y: REAL) : LONGREAL ; | |
361 | @findex nexttowardf | |
362 | PROCEDURE __BUILTIN__ nexttowardf (x, y: SHORTREAL) : LONGREAL ; | |
363 | @findex nexttowardl | |
364 | PROCEDURE __BUILTIN__ nexttowardl (x, y: LONGREAL) : LONGREAL ; | |
365 | ||
366 | @findex scalb | |
367 | PROCEDURE __BUILTIN__ scalb (x, n: REAL) : REAL ; | |
368 | @findex scalbf | |
369 | PROCEDURE __BUILTIN__ scalbf (x, n: SHORTREAL) : SHORTREAL ; | |
370 | @findex scalbl | |
371 | PROCEDURE __BUILTIN__ scalbl (x, n: LONGREAL) : LONGREAL ; | |
372 | ||
373 | @findex scalbln | |
374 | PROCEDURE __BUILTIN__ scalbln (x: REAL; n: LONGINT) : REAL ; | |
375 | @findex scalblnf | |
376 | PROCEDURE __BUILTIN__ scalblnf (x: SHORTREAL; n: LONGINT) : SHORTREAL ; | |
377 | @findex scalblnl | |
378 | PROCEDURE __BUILTIN__ scalblnl (x: LONGREAL; n: LONGINT) : LONGREAL ; | |
379 | ||
380 | @findex scalbn | |
381 | PROCEDURE __BUILTIN__ scalbn (x: REAL; n: INTEGER) : REAL ; | |
382 | @findex scalbnf | |
383 | PROCEDURE __BUILTIN__ scalbnf (x: SHORTREAL; n: INTEGER) : SHORTREAL ; | |
384 | @findex scalbnl | |
385 | PROCEDURE __BUILTIN__ scalbnl (x: LONGREAL; n: INTEGER) : LONGREAL ; | |
386 | ||
387 | (* complex arithmetic intrincic procedure functions *) | |
388 | ||
389 | @findex cabsf | |
390 | PROCEDURE __BUILTIN__ cabsf (z: SHORTCOMPLEX) : SHORTREAL ; | |
391 | @findex cabs | |
392 | PROCEDURE __BUILTIN__ cabs (z: COMPLEX) : REAL ; | |
393 | @findex cabsl | |
394 | PROCEDURE __BUILTIN__ cabsl (z: LONGCOMPLEX) : LONGREAL ; | |
395 | ||
396 | @findex cargf | |
397 | PROCEDURE __BUILTIN__ cargf (z: SHORTCOMPLEX) : SHORTREAL ; | |
398 | @findex carg | |
399 | PROCEDURE __BUILTIN__ carg (z: COMPLEX) : REAL ; | |
400 | @findex cargl | |
401 | PROCEDURE __BUILTIN__ cargl (z: LONGCOMPLEX) : LONGREAL ; | |
402 | ||
403 | @findex conjf | |
404 | PROCEDURE __BUILTIN__ conjf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
405 | @findex conj | |
406 | PROCEDURE __BUILTIN__ conj (z: COMPLEX) : COMPLEX ; | |
407 | @findex conjl | |
408 | PROCEDURE __BUILTIN__ conjl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
409 | ||
410 | @findex cpowerf | |
411 | PROCEDURE __BUILTIN__ cpowerf (base: SHORTCOMPLEX; | |
412 | exp: SHORTREAL) : SHORTCOMPLEX ; | |
413 | @findex cpower | |
414 | PROCEDURE __BUILTIN__ cpower (base: COMPLEX; exp: REAL) : COMPLEX ; | |
415 | @findex cpowerl | |
416 | PROCEDURE __BUILTIN__ cpowerl (base: LONGCOMPLEX; | |
417 | exp: LONGREAL) : LONGCOMPLEX ; | |
418 | ||
419 | @findex csqrtf | |
420 | PROCEDURE __BUILTIN__ csqrtf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
421 | @findex csqrt | |
422 | PROCEDURE __BUILTIN__ csqrt (z: COMPLEX) : COMPLEX ; | |
423 | @findex csqrtl | |
424 | PROCEDURE __BUILTIN__ csqrtl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
425 | ||
426 | @findex cexpf | |
427 | PROCEDURE __BUILTIN__ cexpf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
428 | @findex cexp | |
429 | PROCEDURE __BUILTIN__ cexp (z: COMPLEX) : COMPLEX ; | |
430 | @findex cexpl | |
431 | PROCEDURE __BUILTIN__ cexpl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
432 | ||
433 | @findex clnf | |
434 | PROCEDURE __BUILTIN__ clnf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
435 | @findex cln | |
436 | PROCEDURE __BUILTIN__ cln (z: COMPLEX) : COMPLEX ; | |
437 | @findex clnl | |
438 | PROCEDURE __BUILTIN__ clnl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
439 | ||
440 | @findex csinf | |
441 | PROCEDURE __BUILTIN__ csinf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
442 | @findex csin | |
443 | PROCEDURE __BUILTIN__ csin (z: COMPLEX) : COMPLEX ; | |
444 | @findex csinl | |
445 | PROCEDURE __BUILTIN__ csinl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
446 | ||
447 | @findex ccosf | |
448 | PROCEDURE __BUILTIN__ ccosf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
449 | @findex ccos | |
450 | PROCEDURE __BUILTIN__ ccos (z: COMPLEX) : COMPLEX ; | |
451 | @findex ccosl | |
452 | PROCEDURE __BUILTIN__ ccosl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
453 | ||
454 | @findex ctanf | |
455 | PROCEDURE __BUILTIN__ ctanf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
456 | @findex ctan | |
457 | PROCEDURE __BUILTIN__ ctan (z: COMPLEX) : COMPLEX ; | |
458 | @findex ctanl | |
459 | PROCEDURE __BUILTIN__ ctanl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
460 | ||
461 | @findex carcsinf | |
462 | PROCEDURE __BUILTIN__ carcsinf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
463 | @findex carcsin | |
464 | PROCEDURE __BUILTIN__ carcsin (z: COMPLEX) : COMPLEX ; | |
465 | @findex carcsinl | |
466 | PROCEDURE __BUILTIN__ carcsinl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
467 | ||
468 | @findex carccosf | |
469 | PROCEDURE __BUILTIN__ carccosf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
470 | @findex carccos | |
471 | PROCEDURE __BUILTIN__ carccos (z: COMPLEX) : COMPLEX ; | |
472 | @findex carccosl | |
473 | PROCEDURE __BUILTIN__ carccosl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
474 | ||
475 | @findex carctanf | |
476 | PROCEDURE __BUILTIN__ carctanf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
477 | @findex carctan | |
478 | PROCEDURE __BUILTIN__ carctan (z: COMPLEX) : COMPLEX ; | |
479 | @findex carctanl | |
480 | PROCEDURE __BUILTIN__ carctanl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
481 | ||
482 | (* memory and string intrincic procedure functions *) | |
483 | ||
484 | @findex alloca | |
485 | PROCEDURE __BUILTIN__ alloca (i: CARDINAL) : ADDRESS ; | |
486 | @findex memcpy | |
487 | PROCEDURE __BUILTIN__ memcpy (dest, src: ADDRESS; | |
488 | nbytes: CARDINAL) : ADDRESS ; | |
489 | @findex index | |
490 | PROCEDURE __BUILTIN__ index (s: ADDRESS; c: INTEGER) : ADDRESS ; | |
491 | @findex rindex | |
492 | PROCEDURE __BUILTIN__ rindex (s: ADDRESS; c: INTEGER) : ADDRESS ; | |
493 | @findex memcmp | |
494 | PROCEDURE __BUILTIN__ memcmp (s1, s2: ADDRESS; | |
495 | nbytes: CARDINAL) : INTEGER ; | |
496 | @findex memset | |
497 | PROCEDURE __BUILTIN__ memset (s: ADDRESS; c: INTEGER; | |
498 | nbytes: CARDINAL) : ADDRESS ; | |
499 | @findex memmove | |
500 | PROCEDURE __BUILTIN__ memmove (s1, s2: ADDRESS; | |
501 | nbytes: CARDINAL) : ADDRESS ; | |
502 | @findex strcat | |
503 | PROCEDURE __BUILTIN__ strcat (dest, src: ADDRESS) : ADDRESS ; | |
504 | @findex strncat | |
505 | PROCEDURE __BUILTIN__ strncat (dest, src: ADDRESS; | |
506 | nbytes: CARDINAL) : ADDRESS ; | |
507 | @findex strcpy | |
508 | PROCEDURE __BUILTIN__ strcpy (dest, src: ADDRESS) : ADDRESS ; | |
509 | @findex strncpy | |
510 | PROCEDURE __BUILTIN__ strncpy (dest, src: ADDRESS; | |
511 | nbytes: CARDINAL) : ADDRESS ; | |
512 | @findex strcmp | |
513 | PROCEDURE __BUILTIN__ strcmp (s1, s2: ADDRESS) : INTEGER ; | |
514 | @findex strncmp | |
515 | PROCEDURE __BUILTIN__ strncmp (s1, s2: ADDRESS; | |
516 | nbytes: CARDINAL) : INTEGER ; | |
517 | @findex strlen | |
518 | PROCEDURE __BUILTIN__ strlen (s: ADDRESS) : INTEGER ; | |
519 | @findex strstr | |
520 | PROCEDURE __BUILTIN__ strstr (haystack, needle: ADDRESS) : ADDRESS ; | |
521 | @findex strpbrk | |
522 | PROCEDURE __BUILTIN__ strpbrk (s, accept: ADDRESS) : ADDRESS ; | |
523 | @findex strspn | |
524 | PROCEDURE __BUILTIN__ strspn (s, accept: ADDRESS) : CARDINAL ; | |
525 | @findex strcspn | |
526 | PROCEDURE __BUILTIN__ strcspn (s, accept: ADDRESS) : CARDINAL ; | |
527 | @findex strchr | |
528 | PROCEDURE __BUILTIN__ strchr (s: ADDRESS; c: INTEGER) : ADDRESS ; | |
529 | @findex strrchr | |
530 | PROCEDURE __BUILTIN__ strrchr (s: ADDRESS; c: INTEGER) : ADDRESS ; | |
531 | ||
532 | (* | |
533 | longjmp - this GCC builtin restricts the val to always 1. | |
534 | *) | |
535 | (* do not use these two builtins, as gcc, only really | |
536 | anticipates that the Ada front end should use them | |
537 | and it only uses them in its runtime exception handling. | |
538 | We leave them here in the hope that someday they will | |
539 | behave more like their libc counterparts. *) | |
540 | ||
541 | @findex longjmp | |
542 | PROCEDURE __BUILTIN__ longjmp (env: ADDRESS; val: INTEGER) ; | |
543 | @findex setjmp | |
544 | PROCEDURE __BUILTIN__ setjmp (env: ADDRESS) : INTEGER ; | |
545 | ||
546 | ||
547 | (* | |
548 | frame_address - returns the address of the frame. | |
549 | The current frame is obtained if level is 0, | |
550 | the next level up if level is 1 etc. | |
551 | *) | |
552 | ||
553 | @findex frame_address | |
554 | PROCEDURE __BUILTIN__ frame_address (level: CARDINAL) : ADDRESS ; | |
555 | ||
556 | ||
557 | (* | |
558 | return_address - returns the return address of function. | |
559 | The current function return address is | |
560 | obtained if level is 0, | |
561 | the next level up if level is 1 etc. | |
562 | *) | |
563 | ||
564 | @findex return_address | |
565 | PROCEDURE __BUILTIN__ return_address (level: CARDINAL) : ADDRESS ; | |
566 | ||
567 | ||
568 | (* | |
569 | alloca_trace - this is a no-op which is used for internal debugging. | |
570 | *) | |
571 | ||
572 | @findex alloca_trace | |
573 | PROCEDURE alloca_trace (returned: ADDRESS; nBytes: CARDINAL) : ADDRESS ; | |
574 | ||
575 | ||
576 | END Builtins. | |
577 | @end example | |
578 | @page | |
579 | ||
580 | @node gm2-libs/COROUTINES, gm2-libs/CmdArgs, gm2-libs/Builtins, Base libraries | |
581 | @subsection gm2-libs/COROUTINES | |
582 | ||
583 | @example | |
584 | DEFINITION MODULE FOR "C" COROUTINES ; | |
585 | ||
586 | CONST | |
587 | UnassignedPriority = 0 ; | |
588 | ||
589 | TYPE | |
590 | @findex INTERRUPTSOURCE (type) | |
591 | INTERRUPTSOURCE = CARDINAL ; | |
592 | @findex PROTECTION (type) | |
593 | PROTECTION = [UnassignedPriority..7] ; | |
594 | ||
595 | END COROUTINES. | |
596 | @end example | |
597 | @page | |
598 | ||
599 | @node gm2-libs/CmdArgs, gm2-libs/Debug, gm2-libs/COROUTINES, Base libraries | |
600 | @subsection gm2-libs/CmdArgs | |
601 | ||
602 | @example | |
603 | DEFINITION MODULE CmdArgs ; | |
604 | ||
605 | EXPORT QUALIFIED GetArg, Narg ; | |
606 | ||
607 | ||
608 | (* | |
609 | GetArg - returns the nth argument from the command line, CmdLine | |
610 | the success of the operation is returned. | |
611 | *) | |
612 | ||
613 | @findex GetArg | |
614 | PROCEDURE GetArg (CmdLine: ARRAY OF CHAR; | |
615 | n: CARDINAL; VAR Argi: ARRAY OF CHAR) : BOOLEAN ; | |
616 | ||
617 | ||
618 | (* | |
619 | Narg - returns the number of arguments available from | |
620 | command line, CmdLine. | |
621 | *) | |
622 | ||
623 | @findex Narg | |
624 | PROCEDURE Narg (CmdLine: ARRAY OF CHAR) : CARDINAL ; | |
625 | ||
626 | ||
627 | END CmdArgs. | |
628 | @end example | |
629 | @page | |
630 | ||
631 | @node gm2-libs/Debug, gm2-libs/DynamicStrings, gm2-libs/CmdArgs, Base libraries | |
632 | @subsection gm2-libs/Debug | |
633 | ||
634 | @example | |
635 | DEFINITION MODULE Debug ; | |
636 | ||
637 | (* | |
638 | Description: provides some simple debugging routines. | |
639 | *) | |
640 | ||
641 | EXPORT QUALIFIED Halt, DebugString ; | |
642 | ||
643 | ||
644 | (* | |
645 | Halt - writes a message in the format: | |
646 | Module:Line:Message | |
647 | ||
648 | It then terminates by calling HALT. | |
649 | *) | |
650 | ||
651 | @findex Halt | |
652 | PROCEDURE Halt (Message: ARRAY OF CHAR; | |
653 | LineNo: CARDINAL; | |
654 | Module: ARRAY OF CHAR) ; | |
655 | ||
656 | ||
657 | (* | |
658 | DebugString - writes a string to the debugging device (Scn.Write). | |
659 | It interprets \n as carriage return, linefeed. | |
660 | *) | |
661 | ||
662 | @findex DebugString | |
663 | PROCEDURE DebugString (a: ARRAY OF CHAR) ; | |
664 | ||
665 | ||
666 | END Debug. | |
667 | @end example | |
668 | @page | |
669 | ||
670 | @node gm2-libs/DynamicStrings, gm2-libs/Environment, gm2-libs/Debug, Base libraries | |
671 | @subsection gm2-libs/DynamicStrings | |
672 | ||
673 | @example | |
674 | DEFINITION MODULE DynamicStrings ; | |
675 | ||
676 | FROM SYSTEM IMPORT ADDRESS ; | |
677 | EXPORT QUALIFIED String, | |
678 | InitString, KillString, Fin, InitStringCharStar, | |
679 | InitStringChar, Index, RIndex, | |
680 | Mark, Length, ConCat, ConCatChar, Assign, Dup, Add, | |
681 | Equal, EqualCharStar, EqualArray, ToUpper, ToLower, | |
682 | CopyOut, Mult, Slice, | |
683 | RemoveWhitePrefix, RemoveWhitePostfix, RemoveComment, | |
684 | char, string, | |
685 | InitStringDB, InitStringCharStarDB, InitStringCharDB, | |
686 | MultDB, DupDB, SliceDB, | |
687 | PushAllocation, PopAllocation, PopAllocationExemption ; | |
688 | ||
689 | TYPE | |
690 | @findex String (type) | |
691 | String ; | |
692 | ||
693 | ||
694 | (* | |
695 | InitString - creates and returns a String type object. | |
696 | Initial contents are, a. | |
697 | *) | |
698 | ||
699 | @findex InitString | |
700 | PROCEDURE InitString (a: ARRAY OF CHAR) : String ; | |
701 | ||
702 | ||
703 | (* | |
704 | KillString - frees String, s, and its contents. | |
705 | NIL is returned. | |
706 | *) | |
707 | ||
708 | @findex KillString | |
709 | PROCEDURE KillString (s: String) : String ; | |
710 | ||
711 | ||
712 | (* | |
713 | Fin - finishes with a string, it calls KillString with, s. | |
714 | The purpose of the procedure is to provide a short cut | |
715 | to calling KillString and then testing the return result. | |
716 | *) | |
717 | ||
718 | @findex Fin | |
719 | PROCEDURE Fin (s: String) ; | |
720 | ||
721 | ||
722 | (* | |
723 | InitStringCharStar - initializes and returns a String to contain | |
724 | the C string. | |
725 | *) | |
726 | ||
727 | @findex InitStringCharStar | |
728 | PROCEDURE InitStringCharStar (a: ADDRESS) : String ; | |
729 | ||
730 | ||
731 | (* | |
732 | InitStringChar - initializes and returns a String to contain the | |
733 | single character, ch. | |
734 | *) | |
735 | ||
736 | @findex InitStringChar | |
737 | PROCEDURE InitStringChar (ch: CHAR) : String ; | |
738 | ||
739 | ||
740 | (* | |
741 | Mark - marks String, s, ready for garbage collection. | |
742 | *) | |
743 | ||
744 | @findex Mark | |
745 | PROCEDURE Mark (s: String) : String ; | |
746 | ||
747 | ||
748 | (* | |
749 | Length - returns the length of the String, s. | |
750 | *) | |
751 | ||
752 | @findex Length | |
753 | PROCEDURE Length (s: String) : CARDINAL ; | |
754 | ||
755 | ||
756 | (* | |
757 | ConCat - returns String, a, after the contents of, b, | |
758 | have been appended. | |
759 | *) | |
760 | ||
761 | @findex ConCat | |
762 | PROCEDURE ConCat (a, b: String) : String ; | |
763 | ||
764 | ||
765 | (* | |
766 | ConCatChar - returns String, a, after character, ch, | |
767 | has been appended. | |
768 | *) | |
769 | ||
770 | @findex ConCatChar | |
771 | PROCEDURE ConCatChar (a: String; ch: CHAR) : String ; | |
772 | ||
773 | ||
774 | (* | |
775 | Assign - assigns the contents of, b, into, a. | |
776 | String, a, is returned. | |
777 | *) | |
778 | ||
779 | @findex Assign | |
780 | PROCEDURE Assign (a, b: String) : String ; | |
781 | ||
782 | ||
783 | (* | |
784 | Dup - duplicate a String, s, returning the copy of s. | |
785 | *) | |
786 | ||
787 | @findex Dup | |
788 | PROCEDURE Dup (s: String) : String ; | |
789 | ||
790 | ||
791 | (* | |
792 | Add - returns a new String which contains the contents of a and b. | |
793 | *) | |
794 | ||
795 | @findex Add | |
796 | PROCEDURE Add (a, b: String) : String ; | |
797 | ||
798 | ||
799 | (* | |
800 | Equal - returns TRUE if String, a, and, b, are equal. | |
801 | *) | |
802 | ||
803 | @findex Equal | |
804 | PROCEDURE Equal (a, b: String) : BOOLEAN ; | |
805 | ||
806 | ||
807 | (* | |
808 | EqualCharStar - returns TRUE if contents of String, s, is | |
809 | the same as the string, a. | |
810 | *) | |
811 | ||
812 | @findex EqualCharStar | |
813 | PROCEDURE EqualCharStar (s: String; a: ADDRESS) : BOOLEAN ; | |
814 | ||
815 | ||
816 | (* | |
817 | EqualArray - returns TRUE if contents of String, s, is the | |
818 | same as the string, a. | |
819 | *) | |
820 | ||
821 | @findex EqualArray | |
822 | PROCEDURE EqualArray (s: String; a: ARRAY OF CHAR) : BOOLEAN ; | |
823 | ||
824 | ||
825 | (* | |
826 | Mult - returns a new string which is n concatenations of String, s. | |
827 | If n<=0 then an empty string is returned. | |
828 | *) | |
829 | ||
830 | @findex Mult | |
831 | PROCEDURE Mult (s: String; n: CARDINAL) : String ; | |
832 | ||
833 | ||
834 | (* | |
835 | Slice - returns a new string which contains the elements | |
836 | low..high-1 | |
837 | ||
838 | strings start at element 0 | |
839 | Slice(s, 0, 2) will return elements 0, 1 but not 2 | |
840 | Slice(s, 1, 3) will return elements 1, 2 but not 3 | |
841 | Slice(s, 2, 0) will return elements 2..max | |
842 | Slice(s, 3, -1) will return elements 3..max-1 | |
843 | Slice(s, 4, -2) will return elements 4..max-2 | |
844 | *) | |
845 | ||
846 | @findex Slice | |
847 | PROCEDURE Slice (s: String; low, high: INTEGER) : String ; | |
848 | ||
849 | ||
850 | (* | |
851 | Index - returns the indice of the first occurance of, ch, in | |
852 | String, s. -1 is returned if, ch, does not exist. | |
853 | The search starts at position, o. | |
854 | *) | |
855 | ||
856 | @findex Index | |
857 | PROCEDURE Index (s: String; ch: CHAR; o: CARDINAL) : INTEGER ; | |
858 | ||
859 | ||
860 | (* | |
861 | RIndex - returns the indice of the last occurance of, ch, | |
862 | in String, s. The search starts at position, o. | |
863 | -1 is returned if, ch, is not found. | |
864 | *) | |
865 | ||
866 | @findex RIndex | |
867 | PROCEDURE RIndex (s: String; ch: CHAR; o: CARDINAL) : INTEGER ; | |
868 | ||
869 | ||
870 | (* | |
871 | RemoveComment - assuming that, comment, is a comment delimiter | |
872 | which indicates anything to its right is a comment | |
873 | then strip off the comment and also any white space | |
874 | on the remaining right hand side. | |
875 | It leaves any white space on the left hand side | |
876 | alone. | |
877 | *) | |
878 | ||
879 | @findex RemoveComment | |
880 | PROCEDURE RemoveComment (s: String; comment: CHAR) : String ; | |
881 | ||
882 | ||
883 | (* | |
884 | RemoveWhitePrefix - removes any leading white space from String, s. | |
885 | A new string is returned. | |
886 | *) | |
887 | ||
888 | @findex RemoveWhitePrefix | |
889 | PROCEDURE RemoveWhitePrefix (s: String) : String ; | |
890 | ||
891 | ||
892 | (* | |
893 | RemoveWhitePostfix - removes any leading white space from String, s. | |
894 | A new string is returned. | |
895 | *) | |
896 | ||
897 | @findex RemoveWhitePostfix | |
898 | PROCEDURE RemoveWhitePostfix (s: String) : String ; | |
899 | ||
900 | ||
901 | (* | |
902 | ToUpper - returns string, s, after it has had its lower case | |
903 | characters replaced by upper case characters. | |
904 | The string, s, is not duplicated. | |
905 | *) | |
906 | ||
907 | @findex ToUpper | |
908 | PROCEDURE ToUpper (s: String) : String ; | |
909 | ||
910 | ||
911 | (* | |
912 | ToLower - returns string, s, after it has had its upper case | |
913 | characters replaced by lower case characters. | |
914 | The string, s, is not duplicated. | |
915 | *) | |
916 | ||
917 | @findex ToLower | |
918 | PROCEDURE ToLower (s: String) : String ; | |
919 | ||
920 | ||
921 | (* | |
922 | CopyOut - copies string, s, to a. | |
923 | *) | |
924 | ||
925 | @findex CopyOut | |
926 | PROCEDURE CopyOut (VAR a: ARRAY OF CHAR; s: String) ; | |
927 | ||
928 | ||
929 | (* | |
930 | char - returns the character, ch, at position, i, in String, s. | |
931 | As Slice the index can be negative so: | |
932 | ||
933 | char(s, 0) will return the first character | |
934 | char(s, 1) will return the second character | |
935 | char(s, -1) will return the last character | |
936 | char(s, -2) will return the penultimate character | |
937 | ||
938 | a nul character is returned if the index is out of range. | |
939 | *) | |
940 | ||
941 | @findex char | |
942 | PROCEDURE char (s: String; i: INTEGER) : CHAR ; | |
943 | ||
944 | ||
945 | (* | |
946 | string - returns the C style char * of String, s. | |
947 | *) | |
948 | ||
949 | @findex string | |
950 | PROCEDURE string (s: String) : ADDRESS ; | |
951 | ||
952 | ||
953 | (* | |
954 | to easily debug an application using this library one could use | |
955 | use the following macro processing defines: | |
956 | ||
957 | #define InitString(X) InitStringDB(X, __FILE__, __LINE__) | |
958 | #define InitStringCharStar(X) InitStringCharStarDB(X, \ | |
959 | __FILE__, __LINE__) | |
960 | #define InitStringChar(X) InitStringCharDB(X, __FILE__, __LINE__) | |
961 | #define Mult(X,Y) MultDB(X, Y, __FILE__, __LINE__) | |
962 | #define Dup(X) DupDB(X, __FILE__, __LINE__) | |
963 | #define Slice(X,Y,Z) SliceDB(X, Y, Z, __FILE__, __LINE__) | |
964 | ||
965 | and then invoke gm2 with the -fcpp flag. | |
966 | *) | |
967 | ||
968 | ||
969 | (* | |
970 | InitStringDB - the debug version of InitString. | |
971 | *) | |
972 | ||
973 | @findex InitStringDB | |
974 | PROCEDURE InitStringDB (a: ARRAY OF CHAR; | |
975 | file: ARRAY OF CHAR; line: CARDINAL) : String ; | |
976 | ||
977 | ||
978 | (* | |
979 | InitStringCharStarDB - the debug version of InitStringCharStar. | |
980 | *) | |
981 | ||
982 | @findex InitStringCharStarDB | |
983 | PROCEDURE InitStringCharStarDB (a: ADDRESS; | |
984 | file: ARRAY OF CHAR; | |
985 | line: CARDINAL) : String ; | |
986 | ||
987 | ||
988 | (* | |
989 | InitStringCharDB - the debug version of InitStringChar. | |
990 | *) | |
991 | ||
992 | @findex InitStringCharDB | |
993 | PROCEDURE InitStringCharDB (ch: CHAR; | |
994 | file: ARRAY OF CHAR; | |
995 | line: CARDINAL) : String ; | |
996 | ||
997 | ||
998 | (* | |
999 | MultDB - the debug version of MultDB. | |
1000 | *) | |
1001 | ||
1002 | @findex MultDB | |
1003 | PROCEDURE MultDB (s: String; n: CARDINAL; | |
1004 | file: ARRAY OF CHAR; line: CARDINAL) : String ; | |
1005 | ||
1006 | ||
1007 | (* | |
1008 | DupDB - the debug version of Dup. | |
1009 | *) | |
1010 | ||
1011 | @findex DupDB | |
1012 | PROCEDURE DupDB (s: String; | |
1013 | file: ARRAY OF CHAR; line: CARDINAL) : String ; | |
1014 | ||
1015 | ||
1016 | (* | |
1017 | SliceDB - debug version of Slice. | |
1018 | *) | |
1019 | ||
1020 | @findex SliceDB | |
1021 | PROCEDURE SliceDB (s: String; low, high: INTEGER; | |
1022 | file: ARRAY OF CHAR; line: CARDINAL) : String ; | |
1023 | ||
1024 | (* | |
1025 | PushAllocation - pushes the current allocation/deallocation lists. | |
1026 | *) | |
1027 | ||
1028 | @findex PushAllocation | |
1029 | PROCEDURE PushAllocation ; | |
1030 | ||
1031 | ||
1032 | (* | |
1033 | PopAllocation - test to see that all strings are deallocated since | |
1034 | the last push. Then it pops to the previous | |
1035 | allocation/deallocation lists. | |
1036 | ||
1037 | If halt is true then the application terminates | |
1038 | with an exit code of 1. | |
1039 | *) | |
1040 | ||
1041 | @findex PopAllocation | |
1042 | PROCEDURE PopAllocation (halt: BOOLEAN) ; | |
1043 | ||
1044 | ||
1045 | (* | |
1046 | PopAllocationExemption - test to see that all strings are | |
1047 | deallocated, except string, e, since | |
1048 | the last push. | |
1049 | Then it pops to the previous | |
1050 | allocation/deallocation lists. | |
1051 | ||
1052 | If halt is true then the application | |
1053 | terminates with an exit code of 1. | |
1054 | ||
1055 | The string, e, is returned unmodified, | |
1056 | *) | |
1057 | ||
1058 | @findex PopAllocationExemption | |
1059 | PROCEDURE PopAllocationExemption (halt: BOOLEAN; e: String) : String ; | |
1060 | ||
1061 | ||
1062 | END DynamicStrings. | |
1063 | @end example | |
1064 | @page | |
1065 | ||
1066 | @node gm2-libs/Environment, gm2-libs/FIO, gm2-libs/DynamicStrings, Base libraries | |
1067 | @subsection gm2-libs/Environment | |
1068 | ||
1069 | @example | |
1070 | DEFINITION MODULE Environment ; | |
1071 | ||
1072 | EXPORT QUALIFIED GetEnvironment, PutEnvironment ; | |
1073 | ||
1074 | ||
1075 | (* | |
1076 | GetEnvironment - gets the environment variable Env and places | |
1077 | a copy of its value into string, dest. | |
1078 | It returns TRUE if the string Env was found in | |
1079 | the processes environment. | |
1080 | *) | |
1081 | ||
1082 | @findex GetEnvironment | |
1083 | PROCEDURE GetEnvironment (Env: ARRAY OF CHAR; | |
1084 | VAR dest: ARRAY OF CHAR) : BOOLEAN ; | |
1085 | ||
1086 | ||
1087 | (* | |
1088 | PutEnvironment - change or add an environment variable definition | |
1089 | EnvDef. | |
1090 | TRUE is returned if the environment variable was | |
1091 | set or changed successfully. | |
1092 | *) | |
1093 | ||
1094 | @findex PutEnvironment | |
1095 | PROCEDURE PutEnvironment (EnvDef: ARRAY OF CHAR) : BOOLEAN ; | |
1096 | ||
1097 | ||
1098 | END Environment. | |
1099 | @end example | |
1100 | @page | |
1101 | ||
1102 | @node gm2-libs/FIO, gm2-libs/FormatStrings, gm2-libs/Environment, Base libraries | |
1103 | @subsection gm2-libs/FIO | |
1104 | ||
1105 | @example | |
1106 | DEFINITION MODULE FIO ; | |
1107 | ||
1108 | (* Provides a simple buffered file input/output library. *) | |
1109 | ||
1110 | ||
1111 | FROM SYSTEM IMPORT ADDRESS, BYTE ; | |
1112 | ||
1113 | EXPORT QUALIFIED (* types *) | |
1114 | File, | |
1115 | (* procedures *) | |
1116 | OpenToRead, OpenToWrite, OpenForRandom, Close, | |
1117 | EOF, EOLN, WasEOLN, IsNoError, Exists, IsActive, | |
1118 | exists, openToRead, openToWrite, openForRandom, | |
1119 | SetPositionFromBeginning, | |
1120 | SetPositionFromEnd, | |
1121 | FindPosition, | |
1122 | ReadChar, ReadString, | |
1123 | WriteChar, WriteString, WriteLine, | |
1124 | WriteCardinal, ReadCardinal, | |
1125 | UnReadChar, | |
1126 | WriteNBytes, ReadNBytes, | |
1127 | FlushBuffer, | |
1128 | GetUnixFileDescriptor, | |
1129 | GetFileName, getFileName, getFileNameLength, | |
1130 | FlushOutErr, | |
1131 | (* variables *) | |
1132 | StdIn, StdOut, StdErr ; | |
1133 | ||
1134 | TYPE | |
1135 | @findex File (type) | |
1136 | File = CARDINAL ; | |
1137 | ||
1138 | (* the following variables are initialized to their UNIX equivalents *) | |
1139 | VAR | |
1140 | @findex StdIn (var) | |
1141 | @findex StdOut (var) | |
1142 | @findex StdErr (var) | |
1143 | StdIn, StdOut, StdErr: File ; | |
1144 | ||
1145 | ||
1146 | ||
1147 | (* | |
1148 | IsNoError - returns a TRUE if no error has occured on file, f. | |
1149 | *) | |
1150 | ||
1151 | @findex IsNoError | |
1152 | PROCEDURE IsNoError (f: File) : BOOLEAN ; | |
1153 | ||
1154 | ||
1155 | (* | |
1156 | IsActive - returns TRUE if the file, f, is still active. | |
1157 | *) | |
1158 | ||
1159 | @findex IsActive | |
1160 | PROCEDURE IsActive (f: File) : BOOLEAN ; | |
1161 | ||
1162 | ||
1163 | (* | |
1164 | Exists - returns TRUE if a file named, fname exists for reading. | |
1165 | *) | |
1166 | ||
1167 | @findex Exists | |
1168 | PROCEDURE Exists (fname: ARRAY OF CHAR) : BOOLEAN ; | |
1169 | ||
1170 | ||
1171 | (* | |
1172 | OpenToRead - attempts to open a file, fname, for reading and | |
1173 | it returns this file. | |
1174 | The success of this operation can be checked by | |
1175 | calling IsNoError. | |
1176 | *) | |
1177 | ||
1178 | @findex OpenToRead | |
1179 | PROCEDURE OpenToRead (fname: ARRAY OF CHAR) : File ; | |
1180 | ||
1181 | ||
1182 | (* | |
1183 | OpenToWrite - attempts to open a file, fname, for write and | |
1184 | it returns this file. | |
1185 | The success of this operation can be checked by | |
1186 | calling IsNoError. | |
1187 | *) | |
1188 | ||
1189 | @findex OpenToWrite | |
1190 | PROCEDURE OpenToWrite (fname: ARRAY OF CHAR) : File ; | |
1191 | ||
1192 | ||
1193 | (* | |
1194 | OpenForRandom - attempts to open a file, fname, for random access | |
1195 | read or write and it returns this file. | |
1196 | The success of this operation can be checked by | |
1197 | calling IsNoError. | |
1198 | towrite, determines whether the file should be | |
1199 | opened for writing or reading. | |
1200 | newfile, determines whether a file should be | |
1201 | created if towrite is TRUE or whether the | |
1202 | previous file should be left alone, | |
1203 | allowing this descriptor to seek | |
1204 | and modify an existing file. | |
1205 | *) | |
1206 | ||
1207 | @findex OpenForRandom | |
1208 | PROCEDURE OpenForRandom (fname: ARRAY OF CHAR; | |
1209 | towrite, newfile: BOOLEAN) : File ; | |
1210 | ||
1211 | ||
1212 | (* | |
1213 | Close - close a file which has been previously opened using: | |
1214 | OpenToRead, OpenToWrite, OpenForRandom. | |
1215 | It is correct to close a file which has an error status. | |
1216 | *) | |
1217 | ||
1218 | @findex Close | |
1219 | PROCEDURE Close (f: File) ; | |
1220 | ||
1221 | ||
1222 | (* the following functions are functionally equivalent to the above | |
1223 | except they allow C style names. | |
1224 | *) | |
1225 | ||
1226 | @findex exists | |
1227 | PROCEDURE exists (fname: ADDRESS; flength: CARDINAL) : BOOLEAN ; | |
1228 | @findex openToRead | |
1229 | PROCEDURE openToRead (fname: ADDRESS; flength: CARDINAL) : File ; | |
1230 | @findex openToWrite | |
1231 | PROCEDURE openToWrite (fname: ADDRESS; flength: CARDINAL) : File ; | |
1232 | @findex openForRandom | |
1233 | PROCEDURE openForRandom (fname: ADDRESS; flength: CARDINAL; | |
1234 | towrite, newfile: BOOLEAN) : File ; | |
1235 | ||
1236 | ||
1237 | (* | |
1238 | FlushBuffer - flush contents of the FIO file, f, to libc. | |
1239 | *) | |
1240 | ||
1241 | @findex FlushBuffer | |
1242 | PROCEDURE FlushBuffer (f: File) ; | |
1243 | ||
1244 | ||
1245 | (* | |
1246 | ReadNBytes - reads nBytes of a file into memory area, dest, returning | |
1247 | the number of bytes actually read. | |
1248 | This function will consume from the buffer and then | |
1249 | perform direct libc reads. It is ideal for large reads. | |
1250 | *) | |
1251 | ||
1252 | @findex ReadNBytes | |
1253 | PROCEDURE ReadNBytes (f: File; nBytes: CARDINAL; | |
1254 | dest: ADDRESS) : CARDINAL ; | |
1255 | ||
1256 | ||
1257 | (* | |
1258 | ReadAny - reads HIGH(a) bytes into, a. All input | |
1259 | is fully buffered, unlike ReadNBytes and thus is more | |
1260 | suited to small reads. | |
1261 | *) | |
1262 | ||
1263 | @findex ReadAny | |
1264 | PROCEDURE ReadAny (f: File; VAR a: ARRAY OF BYTE) ; | |
1265 | ||
1266 | ||
1267 | (* | |
1268 | WriteNBytes - writes nBytes from memory area src to a file | |
1269 | returning the number of bytes actually written. | |
1270 | This function will flush the buffer and then | |
1271 | write the nBytes using a direct write from libc. | |
1272 | It is ideal for large writes. | |
1273 | *) | |
1274 | ||
1275 | @findex WriteNBytes | |
1276 | PROCEDURE WriteNBytes (f: File; nBytes: CARDINAL; | |
1277 | src: ADDRESS) : CARDINAL ; | |
1278 | ||
1279 | ||
1280 | (* | |
1281 | WriteAny - writes HIGH(a) bytes onto, file, f. All output | |
1282 | is fully buffered, unlike WriteNBytes and thus is more | |
1283 | suited to small writes. | |
1284 | *) | |
1285 | ||
1286 | @findex WriteAny | |
1287 | PROCEDURE WriteAny (f: File; VAR a: ARRAY OF BYTE) ; | |
1288 | ||
1289 | ||
1290 | (* | |
1291 | WriteChar - writes a single character to file, f. | |
1292 | *) | |
1293 | ||
1294 | @findex WriteChar | |
1295 | PROCEDURE WriteChar (f: File; ch: CHAR) ; | |
1296 | ||
1297 | ||
1298 | (* | |
1299 | EOF - tests to see whether a file, f, has reached end of file. | |
1300 | *) | |
1301 | ||
1302 | @findex EOF | |
1303 | PROCEDURE EOF (f: File) : BOOLEAN ; | |
1304 | ||
1305 | ||
1306 | (* | |
1307 | EOLN - tests to see whether a file, f, is about to read a newline. | |
1308 | It does NOT consume the newline. It reads the next character | |
1309 | and then immediately unreads the character. | |
1310 | *) | |
1311 | ||
1312 | @findex EOLN | |
1313 | PROCEDURE EOLN (f: File) : BOOLEAN ; | |
1314 | ||
1315 | ||
1316 | (* | |
1317 | WasEOLN - tests to see whether a file, f, has just read a newline | |
1318 | character. | |
1319 | *) | |
1320 | ||
1321 | @findex WasEOLN | |
1322 | PROCEDURE WasEOLN (f: File) : BOOLEAN ; | |
1323 | ||
1324 | ||
1325 | (* | |
1326 | ReadChar - returns a character read from file, f. | |
1327 | Sensible to check with IsNoError or EOF after calling | |
1328 | this function. | |
1329 | *) | |
1330 | ||
1331 | @findex ReadChar | |
1332 | PROCEDURE ReadChar (f: File) : CHAR ; | |
1333 | ||
1334 | ||
1335 | (* | |
1336 | UnReadChar - replaces a character, ch, back into file, f. | |
1337 | This character must have been read by ReadChar | |
1338 | and it does not allow successive calls. It may | |
1339 | only be called if the previous read was successful, | |
1340 | end of file or end of line seen. | |
1341 | *) | |
1342 | ||
1343 | @findex UnReadChar | |
1344 | PROCEDURE UnReadChar (f: File ; ch: CHAR) ; | |
1345 | ||
1346 | ||
1347 | (* | |
1348 | WriteLine - writes out a linefeed to file, f. | |
1349 | *) | |
1350 | ||
1351 | @findex WriteLine | |
1352 | PROCEDURE WriteLine (f: File) ; | |
1353 | ||
1354 | ||
1355 | (* | |
1356 | WriteString - writes a string to file, f. | |
1357 | *) | |
1358 | ||
1359 | @findex WriteString | |
1360 | PROCEDURE WriteString (f: File; a: ARRAY OF CHAR) ; | |
1361 | ||
1362 | ||
1363 | (* | |
1364 | ReadString - reads a string from file, f, into string, a. | |
1365 | It terminates the string if HIGH is reached or | |
1366 | if a newline is seen or an error occurs. | |
1367 | *) | |
1368 | ||
1369 | @findex ReadString | |
1370 | PROCEDURE ReadString (f: File; VAR a: ARRAY OF CHAR) ; | |
1371 | ||
1372 | ||
1373 | (* | |
1374 | WriteCardinal - writes a CARDINAL to file, f. | |
1375 | It writes the binary image of the CARDINAL. | |
1376 | to file, f. | |
1377 | *) | |
1378 | ||
1379 | @findex WriteCardinal | |
1380 | PROCEDURE WriteCardinal (f: File; c: CARDINAL) ; | |
1381 | ||
1382 | ||
1383 | (* | |
1384 | ReadCardinal - reads a CARDINAL from file, f. | |
1385 | It reads a bit image of a CARDINAL | |
1386 | from file, f. | |
1387 | *) | |
1388 | ||
1389 | @findex ReadCardinal | |
1390 | PROCEDURE ReadCardinal (f: File) : CARDINAL ; | |
1391 | ||
1392 | ||
1393 | (* | |
1394 | GetUnixFileDescriptor - returns the UNIX file descriptor of a file. | |
1395 | Useful when combining FIO.mod with select | |
1396 | (in Selective.def - but note the comments in | |
1397 | Selective about using read/write primatives) | |
1398 | *) | |
1399 | ||
1400 | @findex GetUnixFileDescriptor | |
1401 | PROCEDURE GetUnixFileDescriptor (f: File) : INTEGER ; | |
1402 | ||
1403 | ||
1404 | (* | |
1405 | SetPositionFromBeginning - sets the position from the beginning | |
1406 | of the file. | |
1407 | *) | |
1408 | ||
1409 | @findex SetPositionFromBeginning | |
1410 | PROCEDURE SetPositionFromBeginning (f: File; pos: LONGINT) ; | |
1411 | ||
1412 | ||
1413 | (* | |
1414 | SetPositionFromEnd - sets the position from the end of the file. | |
1415 | *) | |
1416 | ||
1417 | @findex SetPositionFromEnd | |
1418 | PROCEDURE SetPositionFromEnd (f: File; pos: LONGINT) ; | |
1419 | ||
1420 | ||
1421 | (* | |
1422 | FindPosition - returns the current absolute position in file, f. | |
1423 | *) | |
1424 | ||
1425 | @findex FindPosition | |
1426 | PROCEDURE FindPosition (f: File) : LONGINT ; | |
1427 | ||
1428 | ||
1429 | (* | |
1430 | GetFileName - assigns, a, with the filename associated with, f. | |
1431 | *) | |
1432 | ||
1433 | @findex GetFileName | |
1434 | PROCEDURE GetFileName (f: File; VAR a: ARRAY OF CHAR) ; | |
1435 | ||
1436 | ||
1437 | (* | |
1438 | getFileName - returns the address of the filename associated with, f. | |
1439 | *) | |
1440 | ||
1441 | @findex getFileName | |
1442 | PROCEDURE getFileName (f: File) : ADDRESS ; | |
1443 | ||
1444 | ||
1445 | (* | |
1446 | getFileNameLength - returns the number of characters associated with | |
1447 | filename, f. | |
1448 | *) | |
1449 | ||
1450 | @findex getFileNameLength | |
1451 | PROCEDURE getFileNameLength (f: File) : CARDINAL ; | |
1452 | ||
1453 | ||
1454 | (* | |
1455 | FlushOutErr - flushes, StdOut, and, StdErr. | |
1456 | *) | |
1457 | ||
1458 | @findex FlushOutErr | |
1459 | PROCEDURE FlushOutErr ; | |
1460 | ||
1461 | ||
1462 | END FIO. | |
1463 | @end example | |
1464 | @page | |
1465 | ||
1466 | @node gm2-libs/FormatStrings, gm2-libs/FpuIO, gm2-libs/FIO, Base libraries | |
1467 | @subsection gm2-libs/FormatStrings | |
1468 | ||
1469 | @example | |
1470 | DEFINITION MODULE FormatStrings ; | |
1471 | ||
1472 | FROM SYSTEM IMPORT BYTE ; | |
1473 | FROM DynamicStrings IMPORT String ; | |
1474 | EXPORT QUALIFIED Sprintf0, Sprintf1, Sprintf2, Sprintf3, Sprintf4, | |
1475 | HandleEscape ; | |
1476 | ||
1477 | ||
1478 | (* | |
1479 | Sprintf0 - returns a String containing, fmt, after it has had its | |
1480 | escape sequences translated. | |
1481 | *) | |
1482 | ||
1483 | @findex Sprintf0 | |
1484 | PROCEDURE Sprintf0 (fmt: String) : String ; | |
1485 | ||
1486 | ||
1487 | (* | |
1488 | Sprintf1 - returns a String containing, fmt, together with | |
1489 | encapsulated entity, w. It only formats the | |
1490 | first %s or %d with n. | |
1491 | *) | |
1492 | ||
1493 | @findex Sprintf1 | |
1494 | PROCEDURE Sprintf1 (fmt: String; w: ARRAY OF BYTE) : String ; | |
1495 | ||
1496 | ||
1497 | (* | |
1498 | Sprintf2 - returns a string, fmt, which has been formatted. | |
1499 | *) | |
1500 | ||
1501 | @findex Sprintf2 | |
1502 | PROCEDURE Sprintf2 (fmt: String; w1, w2: ARRAY OF BYTE) : String ; | |
1503 | ||
1504 | ||
1505 | (* | |
1506 | Sprintf3 - returns a string, fmt, which has been formatted. | |
1507 | *) | |
1508 | ||
1509 | @findex Sprintf3 | |
1510 | PROCEDURE Sprintf3 (fmt: String; w1, w2, w3: ARRAY OF BYTE) : String ; | |
1511 | ||
1512 | ||
1513 | (* | |
1514 | Sprintf4 - returns a string, fmt, which has been formatted. | |
1515 | *) | |
1516 | ||
1517 | @findex Sprintf4 | |
1518 | PROCEDURE Sprintf4 (fmt: String; | |
1519 | w1, w2, w3, w4: ARRAY OF BYTE) : String ; | |
1520 | ||
1521 | ||
1522 | (* | |
1523 | HandleEscape - translates \a, \b, \e, \f, \n, \r, \x[hex] \[octal] | |
1524 | into their respective ascii codes. It also converts | |
1525 | \[any] into a single [any] character. | |
1526 | *) | |
1527 | ||
1528 | @findex HandleEscape | |
1529 | PROCEDURE HandleEscape (s: String) : String ; | |
1530 | ||
1531 | ||
1532 | END FormatStrings. | |
1533 | @end example | |
1534 | @page | |
1535 | ||
1536 | @node gm2-libs/FpuIO, gm2-libs/GetOpt, gm2-libs/FormatStrings, Base libraries | |
1537 | @subsection gm2-libs/FpuIO | |
1538 | ||
1539 | @example | |
1540 | DEFINITION MODULE FpuIO ; | |
1541 | ||
1542 | EXPORT QUALIFIED ReadReal, WriteReal, StrToReal, RealToStr, | |
1543 | ReadLongReal, WriteLongReal, StrToLongReal, | |
1544 | LongRealToStr, | |
1545 | ReadLongInt, WriteLongInt, StrToLongInt, | |
1546 | LongIntToStr ; | |
1547 | ||
1548 | ||
1549 | @findex ReadReal | |
1550 | PROCEDURE ReadReal (VAR x: REAL) ; | |
1551 | @findex WriteReal | |
1552 | PROCEDURE WriteReal (x: REAL; TotalWidth, FractionWidth: CARDINAL) ; | |
1553 | @findex StrToReal | |
1554 | PROCEDURE StrToReal (a: ARRAY OF CHAR ; VAR x: REAL) ; | |
1555 | @findex RealToStr | |
1556 | PROCEDURE RealToStr (x: REAL; TotalWidth, FractionWidth: CARDINAL; | |
1557 | VAR a: ARRAY OF CHAR) ; | |
1558 | ||
1559 | @findex ReadLongReal | |
1560 | PROCEDURE ReadLongReal (VAR x: LONGREAL) ; | |
1561 | @findex WriteLongReal | |
1562 | PROCEDURE WriteLongReal (x: LONGREAL; | |
1563 | TotalWidth, FractionWidth: CARDINAL) ; | |
1564 | @findex StrToLongReal | |
1565 | PROCEDURE StrToLongReal (a: ARRAY OF CHAR ; VAR x: LONGREAL) ; | |
1566 | @findex LongRealToStr | |
1567 | PROCEDURE LongRealToStr (x: LONGREAL; | |
1568 | TotalWidth, FractionWidth: CARDINAL; | |
1569 | VAR a: ARRAY OF CHAR) ; | |
1570 | ||
1571 | @findex ReadLongInt | |
1572 | PROCEDURE ReadLongInt (VAR x: LONGINT) ; | |
1573 | @findex WriteLongInt | |
1574 | PROCEDURE WriteLongInt (x: LONGINT; n: CARDINAL) ; | |
1575 | @findex StrToLongInt | |
1576 | PROCEDURE StrToLongInt (a: ARRAY OF CHAR ; VAR x: LONGINT) ; | |
1577 | @findex LongIntToStr | |
1578 | PROCEDURE LongIntToStr (x: LONGINT; n: CARDINAL; VAR a: ARRAY OF CHAR) ; | |
1579 | ||
1580 | ||
1581 | END FpuIO. | |
1582 | @end example | |
1583 | @page | |
1584 | ||
1585 | @node gm2-libs/GetOpt, gm2-libs/IO, gm2-libs/FpuIO, Base libraries | |
1586 | @subsection gm2-libs/GetOpt | |
1587 | ||
1588 | @example | |
1589 | DEFINITION MODULE GetOpt ; | |
1590 | ||
1591 | FROM SYSTEM IMPORT ADDRESS ; | |
1592 | FROM DynamicStrings IMPORT String ; | |
1593 | ||
1594 | CONST | |
1595 | @findex no_argument (const) | |
1596 | no_argument = 0 ; | |
1597 | @findex required_argument (const) | |
1598 | required_argument = 1 ; | |
1599 | @findex optional_argument (const) | |
1600 | optional_argument = 2 ; | |
1601 | ||
1602 | TYPE | |
1603 | @findex LongOptions (type) | |
1604 | LongOptions ; | |
1605 | @findex PtrToInteger (type) | |
1606 | PtrToInteger = POINTER TO INTEGER ; | |
1607 | ||
1608 | (* | |
1609 | GetOpt - call C getopt and fill in the parameters: | |
1610 | optarg, optind, opterr and optop. | |
1611 | *) | |
1612 | ||
1613 | @findex GetOpt | |
1614 | PROCEDURE GetOpt (argc: INTEGER; argv: ADDRESS; optstring: String; | |
1615 | VAR optarg: String; | |
1616 | VAR optind, opterr, optopt: INTEGER) : CHAR ; | |
1617 | ||
1618 | ||
1619 | (* | |
1620 | InitLongOptions - creates and returns a LongOptions empty array. | |
1621 | *) | |
1622 | ||
1623 | @findex InitLongOptions | |
1624 | PROCEDURE InitLongOptions () : LongOptions ; | |
1625 | ||
1626 | ||
1627 | (* | |
1628 | AddLongOption - appends long option @{name, has_arg, flag, val@} to the | |
1629 | array of options and new long options array is | |
1630 | returned. | |
1631 | The old array, lo, should no longer be used. | |
1632 | ||
1633 | (from man 3 getopt) | |
1634 | The meanings of the different fields are: | |
1635 | ||
1636 | name is the name of the long option. | |
1637 | ||
1638 | has_arg | |
1639 | is: no_argument (or 0) if the option does not take an | |
1640 | argument; required_argument (or 1) if the option | |
1641 | requires an argument; or optional_argument (or 2) if | |
1642 | the option takes an optional argument. | |
1643 | ||
1644 | flag specifies how results are returned for a long option. | |
1645 | If flag is NULL, then getopt_long() returns val. | |
1646 | (For example, the calling program may set val to the | |
1647 | equivalent short option character). Otherwise, | |
1648 | getopt_long() returns 0, and flag points to a | |
1649 | variable which is set to val if the option is found, | |
1650 | but left unchanged if the option is not found. | |
1651 | ||
1652 | val is the value to return, or to load into the variable | |
1653 | pointed to by flag. | |
1654 | ||
1655 | The last element of the array has to be filled with zeros. | |
1656 | *) | |
1657 | ||
1658 | @findex AddLongOption | |
1659 | PROCEDURE AddLongOption (lo: LongOptions; | |
1660 | name: String; has_arg: INTEGER; | |
1661 | flag: PtrToInteger; | |
1662 | val: INTEGER) : LongOptions ; | |
1663 | ||
1664 | ||
1665 | (* | |
1666 | KillLongOptions - returns NIL and also frees up memory | |
1667 | associated with, lo. | |
1668 | *) | |
1669 | ||
1670 | @findex KillLongOptions | |
1671 | PROCEDURE KillLongOptions (lo: LongOptions) : LongOptions ; | |
1672 | ||
1673 | ||
1674 | (* | |
1675 | GetOptLong - works like GetOpt but will accept long options (using | |
1676 | two dashes). If the program only accepts long options | |
1677 | then optstring should be an empty string, not NIL. | |
1678 | *) | |
1679 | ||
1680 | @findex GetOptLong | |
1681 | PROCEDURE GetOptLong (argc: INTEGER; argv: ADDRESS; optstring: String; | |
1682 | longopts: LongOptions; | |
1683 | VAR longindex: INTEGER) : INTEGER ; | |
1684 | ||
1685 | ||
1686 | (* | |
1687 | GetOptLongOnly - works like GetOptLong except that a single dash | |
1688 | can be used for a long option. | |
1689 | *) | |
1690 | ||
1691 | @findex GetOptLongOnly | |
1692 | PROCEDURE GetOptLongOnly (argc: INTEGER; argv: ADDRESS; | |
1693 | optstring: String; longopts: LongOptions; | |
1694 | VAR longindex: INTEGER) : INTEGER ; | |
1695 | ||
1696 | ||
1697 | END GetOpt. | |
1698 | @end example | |
1699 | @page | |
1700 | ||
1701 | @node gm2-libs/IO, gm2-libs/Indexing, gm2-libs/GetOpt, Base libraries | |
1702 | @subsection gm2-libs/IO | |
1703 | ||
1704 | @example | |
1705 | DEFINITION MODULE IO ; | |
1706 | ||
1707 | (* | |
1708 | Description: provides Read, Write, Errors procedures that map onto UNIX | |
1709 | file descriptors 0, 1 and 2. This is achieved by using | |
1710 | FIO if we are in buffered mode and using libc.write | |
1711 | if not. | |
1712 | *) | |
1713 | ||
1714 | EXPORT QUALIFIED Read, Write, Error, | |
1715 | UnBufferedMode, BufferedMode, | |
1716 | EchoOn, EchoOff ; | |
1717 | ||
1718 | ||
1719 | @findex Read | |
1720 | PROCEDURE Read (VAR ch: CHAR) ; | |
1721 | @findex Write | |
1722 | PROCEDURE Write (ch: CHAR) ; | |
1723 | @findex Error | |
1724 | PROCEDURE Error (ch: CHAR) ; | |
1725 | ||
1726 | ||
1727 | (* | |
1728 | UnBufferedMode - places file descriptor, fd, into an unbuffered mode. | |
1729 | *) | |
1730 | ||
1731 | @findex UnBufferedMode | |
1732 | PROCEDURE UnBufferedMode (fd: INTEGER; input: BOOLEAN) ; | |
1733 | ||
1734 | ||
1735 | (* | |
1736 | BufferedMode - places file descriptor, fd, into a buffered mode. | |
1737 | *) | |
1738 | ||
1739 | @findex BufferedMode | |
1740 | PROCEDURE BufferedMode (fd: INTEGER; input: BOOLEAN) ; | |
1741 | ||
1742 | ||
1743 | (* | |
1744 | EchoOn - turns on echoing for file descriptor, fd. This | |
1745 | only really makes sence for a file descriptor opened | |
1746 | for terminal input or maybe some specific file descriptor | |
1747 | which is attached to a particular piece of hardware. | |
1748 | *) | |
1749 | ||
1750 | @findex EchoOn | |
1751 | PROCEDURE EchoOn (fd: INTEGER; input: BOOLEAN) ; | |
1752 | ||
1753 | ||
1754 | (* | |
1755 | EchoOff - turns off echoing for file descriptor, fd. This | |
1756 | only really makes sence for a file descriptor opened | |
1757 | for terminal input or maybe some specific file descriptor | |
1758 | which is attached to a particular piece of hardware. | |
1759 | *) | |
1760 | ||
1761 | @findex EchoOff | |
1762 | PROCEDURE EchoOff (fd: INTEGER; input: BOOLEAN) ; | |
1763 | ||
1764 | ||
1765 | END IO. | |
1766 | @end example | |
1767 | @page | |
1768 | ||
1769 | @node gm2-libs/Indexing, gm2-libs/LMathLib0, gm2-libs/IO, Base libraries | |
1770 | @subsection gm2-libs/Indexing | |
1771 | ||
1772 | @example | |
1773 | DEFINITION MODULE Indexing ; | |
1774 | ||
1775 | FROM SYSTEM IMPORT ADDRESS ; | |
1776 | EXPORT QUALIFIED Index, InitIndex, KillIndex, GetIndice, PutIndice, | |
1777 | HighIndice, LowIndice, InBounds, IsIndiceInIndex, | |
1778 | RemoveIndiceFromIndex, IncludeIndiceIntoIndex, | |
1779 | ForeachIndiceInIndexDo, DeleteIndice, DebugIndex ; | |
1780 | ||
1781 | TYPE | |
1782 | @findex Index (type) | |
1783 | Index ; | |
1784 | @findex IndexProcedure (type) | |
1785 | IndexProcedure = PROCEDURE (ADDRESS) ; | |
1786 | ||
1787 | ||
1788 | (* | |
1789 | InitIndex - creates and returns an Index. | |
1790 | *) | |
1791 | ||
1792 | @findex InitIndex | |
1793 | PROCEDURE InitIndex (low: CARDINAL) : Index ; | |
1794 | ||
1795 | ||
1796 | (* | |
1797 | KillIndex - returns Index to free storage. | |
1798 | *) | |
1799 | ||
1800 | @findex KillIndex | |
1801 | PROCEDURE KillIndex (i: Index) : Index ; | |
1802 | ||
1803 | ||
1804 | (* | |
1805 | DebugIndex - turns on debugging within an index. | |
1806 | *) | |
1807 | ||
1808 | @findex DebugIndex | |
1809 | PROCEDURE DebugIndex (i: Index) : Index ; | |
1810 | ||
1811 | ||
1812 | (* | |
1813 | InBounds - returns TRUE if indice, n, is within the bounds | |
1814 | of the dynamic array. | |
1815 | *) | |
1816 | ||
1817 | @findex InBounds | |
1818 | PROCEDURE InBounds (i: Index; n: CARDINAL) : BOOLEAN ; | |
1819 | ||
1820 | ||
1821 | (* | |
1822 | HighIndice - returns the last legally accessible indice of this array. | |
1823 | *) | |
1824 | ||
1825 | @findex HighIndice | |
1826 | PROCEDURE HighIndice (i: Index) : CARDINAL ; | |
1827 | ||
1828 | ||
1829 | (* | |
1830 | LowIndice - returns the first legally accessible indice of this array. | |
1831 | *) | |
1832 | ||
1833 | @findex LowIndice | |
1834 | PROCEDURE LowIndice (i: Index) : CARDINAL ; | |
1835 | ||
1836 | ||
1837 | (* | |
1838 | PutIndice - places, a, into the dynamic array at position i[n] | |
1839 | *) | |
1840 | ||
1841 | @findex PutIndice | |
1842 | PROCEDURE PutIndice (i: Index; n: CARDINAL; a: ADDRESS) ; | |
1843 | ||
1844 | ||
1845 | (* | |
1846 | GetIndice - retrieves, element i[n] from the dynamic array. | |
1847 | *) | |
1848 | ||
1849 | @findex GetIndice | |
1850 | PROCEDURE GetIndice (i: Index; n: CARDINAL) : ADDRESS ; | |
1851 | ||
1852 | ||
1853 | (* | |
1854 | IsIndiceInIndex - returns TRUE if, a, is in the index, i. | |
1855 | *) | |
1856 | ||
1857 | @findex IsIndiceInIndex | |
1858 | PROCEDURE IsIndiceInIndex (i: Index; a: ADDRESS) : BOOLEAN ; | |
1859 | ||
1860 | ||
1861 | (* | |
1862 | RemoveIndiceFromIndex - removes, a, from Index, i. | |
1863 | *) | |
1864 | ||
1865 | @findex RemoveIndiceFromIndex | |
1866 | PROCEDURE RemoveIndiceFromIndex (i: Index; a: ADDRESS) ; | |
1867 | ||
1868 | ||
1869 | (* | |
1870 | DeleteIndice - delete i[j] from the array. | |
1871 | *) | |
1872 | ||
1873 | @findex DeleteIndice | |
1874 | PROCEDURE DeleteIndice (i: Index; j: CARDINAL) ; | |
1875 | ||
1876 | ||
1877 | (* | |
1878 | IncludeIndiceIntoIndex - if the indice is not in the index, then | |
1879 | add it at the end. | |
1880 | *) | |
1881 | ||
1882 | @findex IncludeIndiceIntoIndex | |
1883 | PROCEDURE IncludeIndiceIntoIndex (i: Index; a: ADDRESS) ; | |
1884 | ||
1885 | ||
1886 | (* | |
1887 | ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j]) | |
1888 | *) | |
1889 | ||
1890 | @findex ForeachIndiceInIndexDo | |
1891 | PROCEDURE ForeachIndiceInIndexDo (i: Index; p: IndexProcedure) ; | |
1892 | ||
1893 | ||
1894 | END Indexing. | |
1895 | @end example | |
1896 | @page | |
1897 | ||
1898 | @node gm2-libs/LMathLib0, gm2-libs/LegacyReal, gm2-libs/Indexing, Base libraries | |
1899 | @subsection gm2-libs/LMathLib0 | |
1900 | ||
1901 | @example | |
1902 | DEFINITION MODULE LMathLib0 ; | |
1903 | ||
1904 | CONST | |
1905 | pi = 3.1415926535897932384626433832795028841972; | |
1906 | exp1 = 2.7182818284590452353602874713526624977572; | |
1907 | ||
1908 | ||
1909 | @findex sqrt | |
1910 | PROCEDURE __BUILTIN__ sqrt (x: LONGREAL) : LONGREAL ; | |
1911 | @findex exp | |
1912 | PROCEDURE exp (x: LONGREAL) : LONGREAL ; | |
1913 | @findex ln | |
1914 | PROCEDURE ln (x: LONGREAL) : LONGREAL ; | |
1915 | @findex sin | |
1916 | PROCEDURE __BUILTIN__ sin (x: LONGREAL) : LONGREAL ; | |
1917 | @findex cos | |
1918 | PROCEDURE __BUILTIN__ cos (x: LONGREAL) : LONGREAL ; | |
1919 | @findex tan | |
1920 | PROCEDURE tan (x: LONGREAL) : LONGREAL ; | |
1921 | @findex arctan | |
1922 | PROCEDURE arctan (x: LONGREAL) : LONGREAL ; | |
1923 | @findex entier | |
1924 | PROCEDURE entier (x: LONGREAL) : INTEGER ; | |
1925 | ||
1926 | ||
1927 | END LMathLib0. | |
1928 | @end example | |
1929 | @page | |
1930 | ||
1931 | @node gm2-libs/LegacyReal, gm2-libs/M2Dependent, gm2-libs/LMathLib0, Base libraries | |
1932 | @subsection gm2-libs/LegacyReal | |
1933 | ||
1934 | @example | |
1935 | DEFINITION MODULE LegacyReal ; | |
1936 | ||
1937 | TYPE | |
1938 | REAL = SHORTREAL ; | |
1939 | ||
1940 | ||
1941 | END LegacyReal. | |
1942 | @end example | |
1943 | @page | |
1944 | ||
1945 | @node gm2-libs/M2Dependent, gm2-libs/M2EXCEPTION, gm2-libs/LegacyReal, Base libraries | |
1946 | @subsection gm2-libs/M2Dependent | |
1947 | ||
1948 | @example | |
1949 | DEFINITION MODULE M2Dependent ; | |
1950 | ||
1951 | FROM SYSTEM IMPORT ADDRESS ; | |
1952 | ||
1953 | ||
1954 | TYPE | |
1955 | @findex ArgCVEnvP (type) | |
1956 | ArgCVEnvP = PROCEDURE (INTEGER, ADDRESS, ADDRESS) ; | |
1957 | ||
1958 | ||
1959 | @findex ConstructModules | |
1960 | PROCEDURE ConstructModules (applicationmodule: ADDRESS; | |
1961 | argc: INTEGER; argv, envp: ADDRESS) ; | |
1962 | ||
1963 | @findex DeconstructModules | |
1964 | PROCEDURE DeconstructModules (applicationmodule: ADDRESS; | |
1965 | argc: INTEGER; argv, envp: ADDRESS) ; | |
1966 | ||
1967 | ||
1968 | (* | |
1969 | RegisterModule - adds module name to the list of outstanding | |
1970 | modules which need to have their dependencies | |
1971 | explored to determine initialization order. | |
1972 | *) | |
1973 | ||
1974 | @findex RegisterModule | |
1975 | PROCEDURE RegisterModule (name: ADDRESS; | |
1976 | init, fini: ArgCVEnvP; | |
1977 | dependencies: PROC) ; | |
1978 | ||
1979 | ||
1980 | (* | |
1981 | RequestDependant - used to specify that modulename is dependant upon | |
1982 | module dependantmodule. | |
1983 | *) | |
1984 | ||
1985 | @findex RequestDependant | |
1986 | PROCEDURE RequestDependant (modulename, dependantmodule: ADDRESS) ; | |
1987 | ||
1988 | ||
1989 | END M2Dependent. | |
1990 | @end example | |
1991 | @page | |
1992 | ||
1993 | @node gm2-libs/M2EXCEPTION, gm2-libs/M2LINK, gm2-libs/M2Dependent, Base libraries | |
1994 | @subsection gm2-libs/M2EXCEPTION | |
1995 | ||
1996 | @example | |
1997 | DEFINITION MODULE M2EXCEPTION; | |
1998 | ||
1999 | ||
2000 | (* This enumerated list of exceptions must match the exceptions in gm2-libs-iso to | |
2001 | allow mixed module dialect projects. *) | |
2002 | ||
2003 | TYPE | |
2004 | @findex M2Exceptions (type) | |
2005 | M2Exceptions = | |
2006 | (indexException, rangeException, caseSelectException, invalidLocation, | |
2007 | functionException, wholeValueException, wholeDivException, realValueException, | |
2008 | realDivException, complexValueException, complexDivException, protException, | |
2009 | sysException, coException, exException | |
2010 | ); | |
2011 | ||
2012 | ||
2013 | (* If the program or coroutine is in the exception state then return the enumeration | |
2014 | value representing the exception cause. If it is not in the exception state then | |
2015 | raises and exception (exException). *) | |
2016 | ||
2017 | @findex M2Exception | |
2018 | PROCEDURE M2Exception () : M2Exceptions; | |
2019 | ||
2020 | (* Returns TRUE if the program or coroutine is in the exception state. | |
2021 | Returns FALSE if the program or coroutine is not in the exception state. *) | |
2022 | ||
2023 | @findex IsM2Exception | |
2024 | PROCEDURE IsM2Exception () : BOOLEAN; | |
2025 | ||
2026 | ||
2027 | END M2EXCEPTION. | |
2028 | @end example | |
2029 | @page | |
2030 | ||
2031 | @node gm2-libs/M2LINK, gm2-libs/M2RTS, gm2-libs/M2EXCEPTION, Base libraries | |
2032 | @subsection gm2-libs/M2LINK | |
2033 | ||
2034 | @example | |
2035 | DEFINITION MODULE FOR "C" M2LINK ; | |
2036 | ||
2037 | ||
2038 | TYPE | |
2039 | @findex PtrToChar (type) | |
2040 | PtrToChar = POINTER TO CHAR ; | |
2041 | ||
2042 | (* These variables are set by the compiler in the program module | |
2043 | according to linking command line options. *) | |
2044 | ||
2045 | VAR | |
2046 | @findex ForcedModuleInitOrder (var) | |
2047 | ForcedModuleInitOrder: PtrToChar ; | |
2048 | @findex StaticInitialization (var) | |
2049 | StaticInitialization : BOOLEAN ; | |
2050 | ||
2051 | ||
2052 | @findex END M2LINK. (var) | |
2053 | END M2LINK. | |
2054 | @end example | |
2055 | @page | |
2056 | ||
2057 | @node gm2-libs/M2RTS, gm2-libs/MathLib0, gm2-libs/M2LINK, Base libraries | |
2058 | @subsection gm2-libs/M2RTS | |
2059 | ||
2060 | @example | |
2061 | DEFINITION MODULE M2RTS ; | |
2062 | ||
2063 | FROM SYSTEM IMPORT ADDRESS ; | |
2064 | ||
2065 | ||
2066 | TYPE | |
2067 | @findex ArgCVEnvP (type) | |
2068 | ArgCVEnvP = PROCEDURE (INTEGER, ADDRESS, ADDRESS) ; | |
2069 | ||
2070 | ||
2071 | @findex ConstructModules | |
2072 | PROCEDURE ConstructModules (applicationmodule: ADDRESS; | |
2073 | argc: INTEGER; argv, envp: ADDRESS) ; | |
2074 | ||
2075 | @findex DeconstructModules | |
2076 | PROCEDURE DeconstructModules (applicationmodule: ADDRESS; | |
2077 | argc: INTEGER; argv, envp: ADDRESS) ; | |
2078 | ||
2079 | ||
2080 | (* | |
2081 | RegisterModule - adds module name to the list of outstanding | |
2082 | modules which need to have their dependencies | |
2083 | explored to determine initialization order. | |
2084 | *) | |
2085 | ||
2086 | @findex RegisterModule | |
2087 | PROCEDURE RegisterModule (name: ADDRESS; | |
2088 | init, fini: ArgCVEnvP; | |
2089 | dependencies: PROC) ; | |
2090 | ||
2091 | ||
2092 | (* | |
2093 | RequestDependant - used to specify that modulename is dependant upon | |
2094 | module dependantmodule. | |
2095 | *) | |
2096 | ||
2097 | @findex RequestDependant | |
2098 | PROCEDURE RequestDependant (modulename, dependantmodule: ADDRESS) ; | |
2099 | ||
2100 | ||
2101 | (* | |
2102 | InstallTerminationProcedure - installs a procedure, p, which will | |
2103 | be called when the procedure | |
2104 | ExecuteTerminationProcedures | |
2105 | is invoked. It returns TRUE is the | |
2106 | procedure is installed. | |
2107 | *) | |
2108 | ||
2109 | @findex InstallTerminationProcedure | |
2110 | PROCEDURE InstallTerminationProcedure (p: PROC) : BOOLEAN ; | |
2111 | ||
2112 | ||
2113 | (* | |
2114 | ExecuteInitialProcedures - executes the initial procedures installed | |
2115 | by InstallInitialProcedure. | |
2116 | *) | |
2117 | ||
2118 | @findex ExecuteInitialProcedures | |
2119 | PROCEDURE ExecuteInitialProcedures ; | |
2120 | ||
2121 | ||
2122 | (* | |
2123 | InstallInitialProcedure - installs a procedure to be executed just | |
2124 | before the BEGIN code section of the main | |
2125 | program module. | |
2126 | *) | |
2127 | ||
2128 | @findex InstallInitialProcedure | |
2129 | PROCEDURE InstallInitialProcedure (p: PROC) : BOOLEAN ; | |
2130 | ||
2131 | ||
2132 | (* | |
2133 | ExecuteTerminationProcedures - calls each installed termination procedure | |
2134 | in reverse order. | |
2135 | *) | |
2136 | ||
2137 | @findex ExecuteTerminationProcedures | |
2138 | PROCEDURE ExecuteTerminationProcedures ; | |
2139 | ||
2140 | ||
2141 | (* | |
2142 | Terminate - provides compatibility for pim. It call exit with | |
2143 | the exitcode provided in a prior call to ExitOnHalt | |
2144 | (or zero if ExitOnHalt was never called). It does | |
2145 | not call ExecuteTerminationProcedures. | |
2146 | *) | |
2147 | ||
2148 | @findex Terminate | |
2149 | PROCEDURE Terminate <* noreturn *> ; | |
2150 | ||
2151 | ||
2152 | (* | |
2153 | HALT - terminate the current program. The procedure Terminate | |
2154 | is called before the program is stopped. The parameter | |
2155 | exitcode is optional. If the parameter is not supplied | |
2156 | HALT will call libc 'abort', otherwise it will exit with | |
2157 | the code supplied. Supplying a parameter to HALT has the | |
2158 | same effect as calling ExitOnHalt with the same code and | |
2159 | then calling HALT with no parameter. | |
2160 | *) | |
2161 | ||
2162 | @findex HALT | |
2163 | PROCEDURE HALT ([exitcode: INTEGER = -1]) <* noreturn *> ; | |
2164 | ||
2165 | ||
2166 | (* | |
2167 | Halt - provides a more user friendly version of HALT, which takes | |
2168 | four parameters to aid debugging. | |
2169 | *) | |
2170 | ||
2171 | @findex Halt | |
2172 | PROCEDURE Halt (file: ARRAY OF CHAR; line: CARDINAL; | |
2173 | function: ARRAY OF CHAR; description: ARRAY OF CHAR) | |
2174 | <* noreturn *> ; | |
2175 | ||
2176 | ||
2177 | (* | |
2178 | ExitOnHalt - if HALT is executed then call exit with the exit code, e. | |
2179 | *) | |
2180 | ||
2181 | @findex ExitOnHalt | |
2182 | PROCEDURE ExitOnHalt (e: INTEGER) ; | |
2183 | ||
2184 | ||
2185 | (* | |
2186 | ErrorMessage - emits an error message to stderr and then calls exit (1). | |
2187 | *) | |
2188 | ||
2189 | @findex ErrorMessage | |
2190 | PROCEDURE ErrorMessage (message: ARRAY OF CHAR; | |
2191 | file: ARRAY OF CHAR; | |
2192 | line: CARDINAL; | |
2193 | function: ARRAY OF CHAR) <* noreturn *> ; | |
2194 | ||
2195 | ||
2196 | (* | |
2197 | Length - returns the length of a string, a. This is called whenever | |
2198 | the user calls LENGTH and the parameter cannot be calculated | |
2199 | at compile time. | |
2200 | *) | |
2201 | ||
2202 | @findex Length | |
2203 | PROCEDURE Length (a: ARRAY OF CHAR) : CARDINAL ; | |
2204 | ||
2205 | ||
2206 | (* | |
2207 | The following are the runtime exception handler routines. | |
2208 | *) | |
2209 | ||
2210 | @findex AssignmentException | |
2211 | PROCEDURE AssignmentException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2212 | @findex ReturnException | |
2213 | PROCEDURE ReturnException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2214 | @findex IncException | |
2215 | PROCEDURE IncException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2216 | @findex DecException | |
2217 | PROCEDURE DecException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2218 | @findex InclException | |
2219 | PROCEDURE InclException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2220 | @findex ExclException | |
2221 | PROCEDURE ExclException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2222 | @findex ShiftException | |
2223 | PROCEDURE ShiftException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2224 | @findex RotateException | |
2225 | PROCEDURE RotateException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2226 | @findex StaticArraySubscriptException | |
2227 | PROCEDURE StaticArraySubscriptException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2228 | @findex DynamicArraySubscriptException | |
2229 | PROCEDURE DynamicArraySubscriptException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2230 | @findex ForLoopBeginException | |
2231 | PROCEDURE ForLoopBeginException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2232 | @findex ForLoopToException | |
2233 | PROCEDURE ForLoopToException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2234 | @findex ForLoopEndException | |
2235 | PROCEDURE ForLoopEndException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2236 | @findex PointerNilException | |
2237 | PROCEDURE PointerNilException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2238 | @findex NoReturnException | |
2239 | PROCEDURE NoReturnException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2240 | @findex CaseException | |
2241 | PROCEDURE CaseException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2242 | @findex WholeNonPosDivException | |
2243 | PROCEDURE WholeNonPosDivException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2244 | @findex WholeNonPosModException | |
2245 | PROCEDURE WholeNonPosModException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2246 | @findex WholeZeroDivException | |
2247 | PROCEDURE WholeZeroDivException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2248 | @findex WholeZeroRemException | |
2249 | PROCEDURE WholeZeroRemException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2250 | @findex WholeValueException | |
2251 | PROCEDURE WholeValueException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2252 | @findex RealValueException | |
2253 | PROCEDURE RealValueException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2254 | @findex ParameterException | |
2255 | PROCEDURE ParameterException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2256 | @findex NoException | |
2257 | PROCEDURE NoException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
2258 | ||
2259 | ||
2260 | END M2RTS. | |
2261 | @end example | |
2262 | @page | |
2263 | ||
2264 | @node gm2-libs/MathLib0, gm2-libs/MemUtils, gm2-libs/M2RTS, Base libraries | |
2265 | @subsection gm2-libs/MathLib0 | |
2266 | ||
2267 | @example | |
2268 | DEFINITION MODULE MathLib0 ; | |
2269 | ||
2270 | CONST | |
2271 | pi = 3.1415926535897932384626433832795028841972; | |
2272 | exp1 = 2.7182818284590452353602874713526624977572; | |
2273 | ||
2274 | ||
2275 | @findex sqrt | |
2276 | PROCEDURE __BUILTIN__ sqrt (x: REAL) : REAL ; | |
2277 | @findex exp | |
2278 | PROCEDURE exp (x: REAL) : REAL ; | |
2279 | @findex ln | |
2280 | PROCEDURE ln (x: REAL) : REAL ; | |
2281 | @findex sin | |
2282 | PROCEDURE __BUILTIN__ sin (x: REAL) : REAL ; | |
2283 | @findex cos | |
2284 | PROCEDURE __BUILTIN__ cos (x: REAL) : REAL ; | |
2285 | @findex tan | |
2286 | PROCEDURE tan (x: REAL) : REAL ; | |
2287 | @findex arctan | |
2288 | PROCEDURE arctan (x: REAL) : REAL ; | |
2289 | @findex entier | |
2290 | PROCEDURE entier (x: REAL) : INTEGER ; | |
2291 | ||
2292 | ||
2293 | END MathLib0. | |
2294 | @end example | |
2295 | @page | |
2296 | ||
2297 | @node gm2-libs/MemUtils, gm2-libs/NumberIO, gm2-libs/MathLib0, Base libraries | |
2298 | @subsection gm2-libs/MemUtils | |
2299 | ||
2300 | @example | |
2301 | DEFINITION MODULE MemUtils ; | |
2302 | ||
2303 | FROM SYSTEM IMPORT ADDRESS ; | |
2304 | EXPORT QUALIFIED MemCopy, MemZero ; | |
2305 | ||
2306 | ||
2307 | (* | |
2308 | MemCopy - copys a region of memory to the required destination. | |
2309 | *) | |
2310 | ||
2311 | @findex MemCopy | |
2312 | PROCEDURE MemCopy (from: ADDRESS; length: CARDINAL; to: ADDRESS) ; | |
2313 | ||
2314 | ||
2315 | (* | |
2316 | MemZero - sets a region of memory: a..a+length to zero. | |
2317 | *) | |
2318 | ||
2319 | @findex MemZero | |
2320 | PROCEDURE MemZero (a: ADDRESS; length: CARDINAL) ; | |
2321 | ||
2322 | ||
2323 | END MemUtils. | |
2324 | @end example | |
2325 | @page | |
2326 | ||
2327 | @node gm2-libs/NumberIO, gm2-libs/OptLib, gm2-libs/MemUtils, Base libraries | |
2328 | @subsection gm2-libs/NumberIO | |
2329 | ||
2330 | @example | |
2331 | DEFINITION MODULE NumberIO ; | |
2332 | ||
2333 | EXPORT QUALIFIED ReadCard, WriteCard, ReadHex, WriteHex, ReadInt, WriteInt, | |
2334 | CardToStr, StrToCard, StrToHex, HexToStr, StrToInt, IntToStr, | |
2335 | ReadOct, WriteOct, OctToStr, StrToOct, | |
2336 | ReadBin, WriteBin, BinToStr, StrToBin, | |
2337 | StrToBinInt, StrToHexInt, StrToOctInt ; | |
2338 | ||
2339 | ||
2340 | @findex ReadCard | |
2341 | PROCEDURE ReadCard (VAR x: CARDINAL) ; | |
2342 | ||
2343 | @findex WriteCard | |
2344 | PROCEDURE WriteCard (x, n: CARDINAL) ; | |
2345 | ||
2346 | @findex ReadHex | |
2347 | PROCEDURE ReadHex (VAR x: CARDINAL) ; | |
2348 | ||
2349 | @findex WriteHex | |
2350 | PROCEDURE WriteHex (x, n: CARDINAL) ; | |
2351 | ||
2352 | @findex ReadInt | |
2353 | PROCEDURE ReadInt (VAR x: INTEGER) ; | |
2354 | ||
2355 | @findex WriteInt | |
2356 | PROCEDURE WriteInt (x: INTEGER ; n: CARDINAL) ; | |
2357 | ||
2358 | @findex CardToStr | |
2359 | PROCEDURE CardToStr (x, n: CARDINAL ; VAR a: ARRAY OF CHAR) ; | |
2360 | ||
2361 | @findex StrToCard | |
2362 | PROCEDURE StrToCard (a: ARRAY OF CHAR ; VAR x: CARDINAL) ; | |
2363 | ||
2364 | @findex HexToStr | |
2365 | PROCEDURE HexToStr (x, n: CARDINAL ; VAR a: ARRAY OF CHAR) ; | |
2366 | ||
2367 | @findex StrToHex | |
2368 | PROCEDURE StrToHex (a: ARRAY OF CHAR ; VAR x: CARDINAL) ; | |
2369 | ||
2370 | @findex IntToStr | |
2371 | PROCEDURE IntToStr (x: INTEGER ; n: CARDINAL ; VAR a: ARRAY OF CHAR) ; | |
2372 | ||
2373 | @findex StrToInt | |
2374 | PROCEDURE StrToInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ; | |
2375 | ||
2376 | @findex ReadOct | |
2377 | PROCEDURE ReadOct (VAR x: CARDINAL) ; | |
2378 | ||
2379 | @findex WriteOct | |
2380 | PROCEDURE WriteOct (x, n: CARDINAL) ; | |
2381 | ||
2382 | @findex OctToStr | |
2383 | PROCEDURE OctToStr (x, n: CARDINAL ; VAR a: ARRAY OF CHAR) ; | |
2384 | ||
2385 | @findex StrToOct | |
2386 | PROCEDURE StrToOct (a: ARRAY OF CHAR ; VAR x: CARDINAL) ; | |
2387 | ||
2388 | @findex ReadBin | |
2389 | PROCEDURE ReadBin (VAR x: CARDINAL) ; | |
2390 | ||
2391 | @findex WriteBin | |
2392 | PROCEDURE WriteBin (x, n: CARDINAL) ; | |
2393 | ||
2394 | @findex BinToStr | |
2395 | PROCEDURE BinToStr (x, n: CARDINAL ; VAR a: ARRAY OF CHAR) ; | |
2396 | ||
2397 | @findex StrToBin | |
2398 | PROCEDURE StrToBin (a: ARRAY OF CHAR ; VAR x: CARDINAL) ; | |
2399 | ||
2400 | @findex StrToBinInt | |
2401 | PROCEDURE StrToBinInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ; | |
2402 | ||
2403 | @findex StrToHexInt | |
2404 | PROCEDURE StrToHexInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ; | |
2405 | ||
2406 | @findex StrToOctInt | |
2407 | PROCEDURE StrToOctInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ; | |
2408 | ||
2409 | ||
2410 | END NumberIO. | |
2411 | @end example | |
2412 | @page | |
2413 | ||
2414 | @node gm2-libs/OptLib, gm2-libs/PushBackInput, gm2-libs/NumberIO, Base libraries | |
2415 | @subsection gm2-libs/OptLib | |
2416 | ||
2417 | @example | |
2418 | DEFINITION MODULE OptLib ; | |
2419 | ||
2420 | FROM SYSTEM IMPORT ADDRESS ; | |
2421 | FROM DynamicStrings IMPORT String ; | |
2422 | ||
2423 | TYPE | |
2424 | @findex Option (type) | |
2425 | Option ; | |
2426 | ||
2427 | ||
2428 | (* | |
2429 | InitOption - constructor for Option. | |
2430 | *) | |
2431 | ||
2432 | @findex InitOption | |
2433 | PROCEDURE InitOption (argc: INTEGER; argv: ADDRESS) : Option ; | |
2434 | ||
2435 | ||
2436 | (* | |
2437 | KillOption - deconstructor for Option. | |
2438 | *) | |
2439 | ||
2440 | @findex KillOption | |
2441 | PROCEDURE KillOption (o: Option) : Option ; | |
2442 | ||
2443 | ||
2444 | (* | |
2445 | Dup - duplicate the option array inside, o. | |
2446 | Notice that this does not duplicate all the contents | |
2447 | (strings) of argv. | |
2448 | Shallow copy of the top level indices. | |
2449 | *) | |
2450 | ||
2451 | @findex Dup | |
2452 | PROCEDURE Dup (o: Option) : Option ; | |
2453 | ||
2454 | ||
2455 | (* | |
2456 | Slice - return a new option which has elements [low:high] from the | |
2457 | options, o. | |
2458 | *) | |
2459 | ||
2460 | @findex Slice | |
2461 | PROCEDURE Slice (o: Option; low, high: INTEGER) : Option ; | |
2462 | ||
2463 | ||
2464 | (* | |
2465 | IndexStrCmp - returns the index in the argv array which matches | |
2466 | string, s. -1 is returned if the string is not found. | |
2467 | *) | |
2468 | ||
2469 | @findex IndexStrCmp | |
2470 | PROCEDURE IndexStrCmp (o: Option; s: String) : INTEGER ; | |
2471 | ||
2472 | ||
2473 | (* | |
2474 | IndexStrNCmp - returns the index in the argv array where the first | |
2475 | characters are matched by string, s. | |
2476 | -1 is returned if the string is not found. | |
2477 | *) | |
2478 | ||
2479 | @findex IndexStrNCmp | |
2480 | PROCEDURE IndexStrNCmp (o: Option; s: String) : INTEGER ; | |
2481 | ||
2482 | ||
2483 | (* | |
2484 | ConCat - returns the concatenation of a and b. | |
2485 | *) | |
2486 | ||
2487 | @findex ConCat | |
2488 | PROCEDURE ConCat (a, b: Option) : Option ; | |
2489 | ||
2490 | ||
2491 | (* | |
2492 | GetArgv - return the argv component of option. | |
2493 | *) | |
2494 | ||
2495 | @findex GetArgv | |
2496 | PROCEDURE GetArgv (o: Option) : ADDRESS ; | |
2497 | ||
2498 | ||
2499 | (* | |
2500 | GetArgc - return the argc component of option. | |
2501 | *) | |
2502 | ||
2503 | @findex GetArgc | |
2504 | PROCEDURE GetArgc (o: Option) : INTEGER ; | |
2505 | ||
2506 | ||
2507 | END OptLib. | |
2508 | @end example | |
2509 | @page | |
2510 | ||
2511 | @node gm2-libs/PushBackInput, gm2-libs/RTExceptions, gm2-libs/OptLib, Base libraries | |
2512 | @subsection gm2-libs/PushBackInput | |
2513 | ||
2514 | @example | |
2515 | DEFINITION MODULE PushBackInput ; | |
2516 | ||
2517 | FROM FIO IMPORT File ; | |
2518 | FROM DynamicStrings IMPORT String ; | |
2519 | ||
2520 | EXPORT QUALIFIED Open, PutCh, GetCh, Error, WarnError, WarnString, | |
2521 | Close, SetDebug, GetExitStatus, PutStr, | |
2522 | PutString, GetColumnPosition, GetCurrentLine ; | |
2523 | ||
2524 | ||
2525 | (* | |
2526 | Open - opens a file for reading. | |
2527 | *) | |
2528 | ||
2529 | @findex Open | |
2530 | PROCEDURE Open (a: ARRAY OF CHAR) : File ; | |
2531 | ||
2532 | ||
2533 | (* | |
2534 | GetCh - gets a character from either the push back stack or | |
2535 | from file, f. | |
2536 | *) | |
2537 | ||
2538 | @findex GetCh | |
2539 | PROCEDURE GetCh (f: File) : CHAR ; | |
2540 | ||
2541 | ||
2542 | (* | |
2543 | PutCh - pushes a character onto the push back stack, it also | |
2544 | returns the character which has been pushed. | |
2545 | *) | |
2546 | ||
2547 | @findex PutCh | |
2548 | PROCEDURE PutCh (ch: CHAR) : CHAR ; | |
2549 | ||
2550 | ||
2551 | (* | |
2552 | PutString - pushes a string onto the push back stack. | |
2553 | *) | |
2554 | ||
2555 | @findex PutString | |
2556 | PROCEDURE PutString (a: ARRAY OF CHAR) ; | |
2557 | ||
2558 | ||
2559 | (* | |
2560 | PutStr - pushes a dynamic string onto the push back stack. | |
2561 | The string, s, is not deallocated. | |
2562 | *) | |
2563 | ||
2564 | @findex PutStr | |
2565 | PROCEDURE PutStr (s: String) ; | |
2566 | ||
2567 | ||
2568 | (* | |
2569 | Error - emits an error message with the appropriate file, line combination. | |
2570 | *) | |
2571 | ||
2572 | @findex Error | |
2573 | PROCEDURE Error (a: ARRAY OF CHAR) ; | |
2574 | ||
2575 | ||
2576 | (* | |
2577 | WarnError - emits an error message with the appropriate file, line combination. | |
2578 | It does not terminate but when the program finishes an exit status of | |
2579 | 1 will be issued. | |
2580 | *) | |
2581 | ||
2582 | @findex WarnError | |
2583 | PROCEDURE WarnError (a: ARRAY OF CHAR) ; | |
2584 | ||
2585 | ||
2586 | (* | |
2587 | WarnString - emits an error message with the appropriate file, line combination. | |
2588 | It does not terminate but when the program finishes an exit status of | |
2589 | 1 will be issued. | |
2590 | *) | |
2591 | ||
2592 | @findex WarnString | |
2593 | PROCEDURE WarnString (s: String) ; | |
2594 | ||
2595 | ||
2596 | (* | |
2597 | Close - closes the opened file. | |
2598 | *) | |
2599 | ||
2600 | @findex Close | |
2601 | PROCEDURE Close (f: File) ; | |
2602 | ||
2603 | ||
2604 | (* | |
2605 | GetExitStatus - returns the exit status which will be 1 if any warnings were issued. | |
2606 | *) | |
2607 | ||
2608 | @findex GetExitStatus | |
2609 | PROCEDURE GetExitStatus () : CARDINAL ; | |
2610 | ||
2611 | ||
2612 | (* | |
2613 | SetDebug - sets the debug flag on or off. | |
2614 | *) | |
2615 | ||
2616 | @findex SetDebug | |
2617 | PROCEDURE SetDebug (d: BOOLEAN) ; | |
2618 | ||
2619 | ||
2620 | (* | |
2621 | GetColumnPosition - returns the column position of the current character. | |
2622 | *) | |
2623 | ||
2624 | @findex GetColumnPosition | |
2625 | PROCEDURE GetColumnPosition () : CARDINAL ; | |
2626 | ||
2627 | ||
2628 | (* | |
2629 | GetCurrentLine - returns the current line number. | |
2630 | *) | |
2631 | ||
2632 | @findex GetCurrentLine | |
2633 | PROCEDURE GetCurrentLine () : CARDINAL ; | |
2634 | ||
2635 | ||
2636 | END PushBackInput. | |
2637 | @end example | |
2638 | @page | |
2639 | ||
2640 | @node gm2-libs/RTExceptions, gm2-libs/RTint, gm2-libs/PushBackInput, Base libraries | |
2641 | @subsection gm2-libs/RTExceptions | |
2642 | ||
2643 | @example | |
2644 | DEFINITION MODULE RTExceptions ; | |
2645 | ||
2646 | (* Runtime exception handler routines. This should | |
2647 | be considered as a system module for GNU Modula-2 | |
2648 | and allow the compiler to interface with exception | |
2649 | handling. *) | |
2650 | ||
2651 | FROM SYSTEM IMPORT ADDRESS ; | |
2652 | EXPORT QUALIFIED EHBlock, | |
2653 | Raise, SetExceptionBlock, GetExceptionBlock, | |
2654 | GetTextBuffer, GetTextBufferSize, GetNumber, | |
2655 | InitExceptionBlock, KillExceptionBlock, | |
2656 | PushHandler, PopHandler, | |
2657 | BaseExceptionsThrow, DefaultErrorCatch, | |
2658 | IsInExceptionState, SetExceptionState, | |
2659 | SwitchExceptionState, GetBaseExceptionBlock, | |
2660 | SetExceptionSource, GetExceptionSource ; | |
2661 | ||
2662 | TYPE | |
2663 | @findex EHBlock (type) | |
2664 | EHBlock ; | |
2665 | @findex ProcedureHandler (type) | |
2666 | ProcedureHandler = PROCEDURE ; | |
2667 | ||
2668 | ||
2669 | (* | |
2670 | Raise - invoke the exception handler associated with, number, | |
2671 | in the active EHBlock. It keeps a record of the number | |
2672 | and message in the EHBlock for later use. | |
2673 | *) | |
2674 | ||
2675 | @findex Raise | |
2676 | PROCEDURE Raise (number: CARDINAL; | |
2677 | file: ADDRESS; line: CARDINAL; | |
2678 | column: CARDINAL; function: ADDRESS; | |
2679 | message: ADDRESS) ; | |
2680 | ||
2681 | ||
2682 | (* | |
2683 | SetExceptionBlock - sets, source, as the active EHB. | |
2684 | *) | |
2685 | ||
2686 | @findex SetExceptionBlock | |
2687 | PROCEDURE SetExceptionBlock (source: EHBlock) ; | |
2688 | ||
2689 | ||
2690 | (* | |
2691 | GetExceptionBlock - returns the active EHB. | |
2692 | *) | |
2693 | ||
2694 | @findex GetExceptionBlock | |
2695 | PROCEDURE GetExceptionBlock () : EHBlock ; | |
2696 | ||
2697 | ||
2698 | (* | |
2699 | GetTextBuffer - returns the address of the EHB buffer. | |
2700 | *) | |
2701 | ||
2702 | @findex GetTextBuffer | |
2703 | PROCEDURE GetTextBuffer (e: EHBlock) : ADDRESS ; | |
2704 | ||
2705 | ||
2706 | (* | |
2707 | GetTextBufferSize - return the size of the EHB text buffer. | |
2708 | *) | |
2709 | ||
2710 | @findex GetTextBufferSize | |
2711 | PROCEDURE GetTextBufferSize (e: EHBlock) : CARDINAL ; | |
2712 | ||
2713 | ||
2714 | (* | |
2715 | GetNumber - return the exception number associated with, | |
2716 | source. | |
2717 | *) | |
2718 | ||
2719 | @findex GetNumber | |
2720 | PROCEDURE GetNumber (source: EHBlock) : CARDINAL ; | |
2721 | ||
2722 | ||
2723 | (* | |
2724 | InitExceptionBlock - creates and returns a new exception block. | |
2725 | *) | |
2726 | ||
2727 | @findex InitExceptionBlock | |
2728 | PROCEDURE InitExceptionBlock () : EHBlock ; | |
2729 | ||
2730 | ||
2731 | (* | |
2732 | KillExceptionBlock - destroys the EHB, e, and all its handlers. | |
2733 | *) | |
2734 | ||
2735 | @findex KillExceptionBlock | |
2736 | PROCEDURE KillExceptionBlock (e: EHBlock) : EHBlock ; | |
2737 | ||
2738 | ||
2739 | (* | |
2740 | PushHandler - install a handler in EHB, e. | |
2741 | *) | |
2742 | ||
2743 | @findex PushHandler | |
2744 | PROCEDURE PushHandler (e: EHBlock; number: CARDINAL; p: ProcedureHandler) ; | |
2745 | ||
2746 | ||
2747 | (* | |
2748 | PopHandler - removes the handler associated with, number, from | |
2749 | EHB, e. | |
2750 | *) | |
2751 | ||
2752 | @findex PopHandler | |
2753 | PROCEDURE PopHandler (e: EHBlock; number: CARDINAL) ; | |
2754 | ||
2755 | ||
2756 | (* | |
2757 | DefaultErrorCatch - displays the current error message in | |
2758 | the current exception block and then | |
2759 | calls HALT. | |
2760 | *) | |
2761 | ||
2762 | @findex DefaultErrorCatch | |
2763 | PROCEDURE DefaultErrorCatch ; | |
2764 | ||
2765 | ||
2766 | (* | |
2767 | BaseExceptionsThrow - configures the Modula-2 exceptions to call | |
2768 | THROW which in turn can be caught by an | |
2769 | exception block. If this is not called then | |
2770 | a Modula-2 exception will simply call an | |
2771 | error message routine and then HALT. | |
2772 | *) | |
2773 | ||
2774 | @findex BaseExceptionsThrow | |
2775 | PROCEDURE BaseExceptionsThrow ; | |
2776 | ||
2777 | ||
2778 | (* | |
2779 | IsInExceptionState - returns TRUE if the program is currently | |
2780 | in the exception state. | |
2781 | *) | |
2782 | ||
2783 | @findex IsInExceptionState | |
2784 | PROCEDURE IsInExceptionState () : BOOLEAN ; | |
2785 | ||
2786 | ||
2787 | (* | |
2788 | SetExceptionState - returns the current exception state and | |
2789 | then sets the current exception state to, | |
2790 | to. | |
2791 | *) | |
2792 | ||
2793 | @findex SetExceptionState | |
2794 | PROCEDURE SetExceptionState (to: BOOLEAN) : BOOLEAN ; | |
2795 | ||
2796 | ||
2797 | (* | |
2798 | SwitchExceptionState - assigns, from, with the current exception | |
2799 | state and then assigns the current exception | |
2800 | to, to. | |
2801 | *) | |
2802 | ||
2803 | @findex SwitchExceptionState | |
2804 | PROCEDURE SwitchExceptionState (VAR from: BOOLEAN; to: BOOLEAN) ; | |
2805 | ||
2806 | ||
2807 | (* | |
2808 | GetBaseExceptionBlock - returns the initial language exception block | |
2809 | created. | |
2810 | *) | |
2811 | ||
2812 | @findex GetBaseExceptionBlock | |
2813 | PROCEDURE GetBaseExceptionBlock () : EHBlock ; | |
2814 | ||
2815 | ||
2816 | (* | |
2817 | SetExceptionSource - sets the current exception source to, source. | |
2818 | *) | |
2819 | ||
2820 | @findex SetExceptionSource | |
2821 | PROCEDURE SetExceptionSource (source: ADDRESS) ; | |
2822 | ||
2823 | ||
2824 | (* | |
2825 | GetExceptionSource - returns the current exception source. | |
2826 | *) | |
2827 | ||
2828 | @findex GetExceptionSource | |
2829 | PROCEDURE GetExceptionSource () : ADDRESS ; | |
2830 | ||
2831 | ||
2832 | END RTExceptions. | |
2833 | @end example | |
2834 | @page | |
2835 | ||
2836 | @node gm2-libs/RTint, gm2-libs/SArgs, gm2-libs/RTExceptions, Base libraries | |
2837 | @subsection gm2-libs/RTint | |
2838 | ||
2839 | @example | |
2840 | DEFINITION MODULE RTint ; | |
2841 | ||
2842 | (* Provides users of the COROUTINES library with the | |
2843 | ability to create interrupt sources based on | |
2844 | file descriptors and timeouts. *) | |
2845 | ||
2846 | FROM SYSTEM IMPORT ADDRESS ; | |
2847 | ||
2848 | TYPE | |
2849 | @findex DispatchVector (type) | |
2850 | DispatchVector = PROCEDURE (CARDINAL, CARDINAL, ADDRESS) ; | |
2851 | ||
2852 | ||
2853 | (* | |
2854 | InitInputVector - returns an interrupt vector which is associated | |
2855 | with the file descriptor, fd. | |
2856 | *) | |
2857 | ||
2858 | @findex InitInputVector | |
2859 | PROCEDURE InitInputVector (fd: INTEGER; pri: CARDINAL) : CARDINAL ; | |
2860 | ||
2861 | ||
2862 | (* | |
2863 | InitOutputVector - returns an interrupt vector which is associated | |
2864 | with the file descriptor, fd. | |
2865 | *) | |
2866 | ||
2867 | @findex InitOutputVector | |
2868 | PROCEDURE InitOutputVector (fd: INTEGER; pri: CARDINAL) : CARDINAL ; | |
2869 | ||
2870 | ||
2871 | (* | |
2872 | InitTimeVector - returns an interrupt vector associated with | |
2873 | the relative time. | |
2874 | *) | |
2875 | ||
2876 | @findex InitTimeVector | |
2877 | PROCEDURE InitTimeVector (micro, secs: CARDINAL; pri: CARDINAL) : CARDINAL ; | |
2878 | ||
2879 | ||
2880 | (* | |
2881 | ReArmTimeVector - reprimes the vector, vec, to deliver an interrupt | |
2882 | at the new relative time. | |
2883 | *) | |
2884 | ||
2885 | @findex ReArmTimeVector | |
2886 | PROCEDURE ReArmTimeVector (vec: CARDINAL; micro, secs: CARDINAL) ; | |
2887 | ||
2888 | ||
2889 | (* | |
2890 | GetTimeVector - assigns, micro, and, secs, with the remaining | |
2891 | time before this interrupt will expire. | |
2892 | This value is only updated when a Listen | |
2893 | occurs. | |
2894 | *) | |
2895 | ||
2896 | @findex GetTimeVector | |
2897 | PROCEDURE GetTimeVector (vec: CARDINAL; VAR micro, secs: CARDINAL) ; | |
2898 | ||
2899 | ||
2900 | (* | |
2901 | AttachVector - adds the pointer, p, to be associated with the interrupt | |
2902 | vector. It returns the previous value attached to this | |
2903 | vector. | |
2904 | *) | |
2905 | ||
2906 | @findex AttachVector | |
2907 | PROCEDURE AttachVector (vec: CARDINAL; p: ADDRESS) : ADDRESS ; | |
2908 | ||
2909 | ||
2910 | (* | |
2911 | IncludeVector - includes, vec, into the dispatcher list of | |
2912 | possible interrupt causes. | |
2913 | *) | |
2914 | ||
2915 | @findex IncludeVector | |
2916 | PROCEDURE IncludeVector (vec: CARDINAL) ; | |
2917 | ||
2918 | ||
2919 | (* | |
2920 | ExcludeVector - excludes, vec, from the dispatcher list of | |
2921 | possible interrupt causes. | |
2922 | *) | |
2923 | ||
2924 | @findex ExcludeVector | |
2925 | PROCEDURE ExcludeVector (vec: CARDINAL) ; | |
2926 | ||
2927 | ||
2928 | (* | |
2929 | Listen - will either block indefinitely (until an interrupt) | |
2930 | or alteratively will test to see whether any interrupts | |
2931 | are pending. | |
2932 | If a pending interrupt was found then, call, is called | |
2933 | and then this procedure returns. | |
2934 | It only listens for interrupts > pri. | |
2935 | *) | |
2936 | ||
2937 | @findex Listen | |
2938 | PROCEDURE Listen (untilInterrupt: BOOLEAN; | |
2939 | call: DispatchVector; | |
2940 | pri: CARDINAL) ; | |
2941 | ||
2942 | ||
2943 | (* | |
2944 | Init - allows the user to force the initialize order. | |
2945 | *) | |
2946 | ||
2947 | @findex Init | |
2948 | PROCEDURE Init ; | |
2949 | ||
2950 | ||
2951 | END RTint. | |
2952 | @end example | |
2953 | @page | |
2954 | ||
2955 | @node gm2-libs/SArgs, gm2-libs/SCmdArgs, gm2-libs/RTint, Base libraries | |
2956 | @subsection gm2-libs/SArgs | |
2957 | ||
2958 | @example | |
2959 | DEFINITION MODULE SArgs ; | |
2960 | ||
2961 | FROM DynamicStrings IMPORT String ; | |
2962 | EXPORT QUALIFIED GetArg, Narg ; | |
2963 | ||
2964 | ||
2965 | (* | |
2966 | GetArg - returns the nth argument from the command line. | |
2967 | The success of the operation is returned. | |
2968 | If TRUE is returned then the string, s, contains a | |
2969 | new string, otherwise s is set to NIL. | |
2970 | *) | |
2971 | ||
2972 | @findex GetArg | |
2973 | PROCEDURE GetArg (VAR s: String ; n: CARDINAL) : BOOLEAN ; | |
2974 | ||
2975 | ||
2976 | (* | |
2977 | Narg - returns the number of arguments available from | |
2978 | command line. | |
2979 | *) | |
2980 | ||
2981 | @findex Narg | |
2982 | PROCEDURE Narg() : CARDINAL ; | |
2983 | ||
2984 | ||
2985 | END SArgs. | |
2986 | @end example | |
2987 | @page | |
2988 | ||
2989 | @node gm2-libs/SCmdArgs, gm2-libs/SEnvironment, gm2-libs/SArgs, Base libraries | |
2990 | @subsection gm2-libs/SCmdArgs | |
2991 | ||
2992 | @example | |
2993 | DEFINITION MODULE SCmdArgs ; | |
2994 | ||
2995 | FROM DynamicStrings IMPORT String ; | |
2996 | ||
2997 | EXPORT QUALIFIED GetArg, Narg ; | |
2998 | ||
2999 | ||
3000 | (* | |
3001 | GetArg - returns the nth argument from the command line, CmdLine | |
3002 | the success of the operation is returned. | |
3003 | *) | |
3004 | ||
3005 | @findex GetArg | |
3006 | PROCEDURE GetArg (CmdLine: String; | |
3007 | n: CARDINAL; VAR Argi: String) : BOOLEAN ; | |
3008 | ||
3009 | ||
3010 | (* | |
3011 | Narg - returns the number of arguments available from | |
3012 | command line, CmdLine. | |
3013 | *) | |
3014 | ||
3015 | @findex Narg | |
3016 | PROCEDURE Narg (CmdLine: String) : CARDINAL ; | |
3017 | ||
3018 | ||
3019 | END SCmdArgs. | |
3020 | @end example | |
3021 | @page | |
3022 | ||
3023 | @node gm2-libs/SEnvironment, gm2-libs/SFIO, gm2-libs/SCmdArgs, Base libraries | |
3024 | @subsection gm2-libs/SEnvironment | |
3025 | ||
3026 | @example | |
3027 | DEFINITION MODULE SEnvironment ; | |
3028 | ||
3029 | ||
3030 | FROM DynamicStrings IMPORT String ; | |
3031 | EXPORT QUALIFIED GetEnvironment ; | |
3032 | ||
3033 | ||
3034 | (* | |
3035 | GetEnvironment - gets the environment variable Env and places | |
3036 | a copy of its value into String, dest. | |
3037 | It returns TRUE if the string Env was found in | |
3038 | the processes environment. | |
3039 | *) | |
3040 | ||
3041 | @findex GetEnvironment | |
3042 | PROCEDURE GetEnvironment (Env: String; | |
3043 | VAR dest: String) : BOOLEAN ; | |
3044 | ||
3045 | ||
3046 | (* | |
3047 | PutEnvironment - change or add an environment variable definition EnvDef. | |
3048 | TRUE is returned if the environment variable was | |
3049 | set or changed successfully. | |
3050 | *) | |
3051 | ||
3052 | @findex PutEnvironment | |
3053 | PROCEDURE PutEnvironment (EnvDef: String) : BOOLEAN ; | |
3054 | ||
3055 | ||
3056 | END SEnvironment. | |
3057 | @end example | |
3058 | @page | |
3059 | ||
3060 | @node gm2-libs/SFIO, gm2-libs/SMathLib0, gm2-libs/SEnvironment, Base libraries | |
3061 | @subsection gm2-libs/SFIO | |
3062 | ||
3063 | @example | |
3064 | DEFINITION MODULE SFIO ; | |
3065 | ||
3066 | FROM DynamicStrings IMPORT String ; | |
3067 | FROM FIO IMPORT File ; | |
3068 | ||
3069 | EXPORT QUALIFIED OpenToRead, OpenToWrite, OpenForRandom, Exists, WriteS, ReadS ; | |
3070 | ||
3071 | ||
3072 | (* | |
3073 | Exists - returns TRUE if a file named, fname exists for reading. | |
3074 | *) | |
3075 | ||
3076 | @findex Exists | |
3077 | PROCEDURE Exists (fname: String) : BOOLEAN ; | |
3078 | ||
3079 | ||
3080 | (* | |
3081 | OpenToRead - attempts to open a file, fname, for reading and | |
3082 | it returns this file. | |
3083 | The success of this operation can be checked by | |
3084 | calling IsNoError. | |
3085 | *) | |
3086 | ||
3087 | @findex OpenToRead | |
3088 | PROCEDURE OpenToRead (fname: String) : File ; | |
3089 | ||
3090 | ||
3091 | (* | |
3092 | OpenToWrite - attempts to open a file, fname, for write and | |
3093 | it returns this file. | |
3094 | The success of this operation can be checked by | |
3095 | calling IsNoError. | |
3096 | *) | |
3097 | ||
3098 | @findex OpenToWrite | |
3099 | PROCEDURE OpenToWrite (fname: String) : File ; | |
3100 | ||
3101 | ||
3102 | (* | |
3103 | OpenForRandom - attempts to open a file, fname, for random access | |
3104 | read or write and it returns this file. | |
3105 | The success of this operation can be checked by | |
3106 | calling IsNoError. | |
3107 | towrite, determines whether the file should be | |
3108 | opened for writing or reading. | |
3109 | if towrite is TRUE or whether the previous file should | |
3110 | be left alone, allowing this descriptor to seek | |
3111 | and modify an existing file. | |
3112 | *) | |
3113 | ||
3114 | @findex OpenForRandom | |
3115 | PROCEDURE OpenForRandom (fname: String; towrite, newfile: BOOLEAN) : File ; | |
3116 | ||
3117 | ||
3118 | (* | |
3119 | WriteS - writes a string, s, to, file. It returns the String, s. | |
3120 | *) | |
3121 | ||
3122 | @findex WriteS | |
3123 | PROCEDURE WriteS (file: File; s: String) : String ; | |
3124 | ||
3125 | ||
3126 | (* | |
3127 | ReadS - reads a string, s, from, file. It returns the String, s. | |
3128 | It stops reading the string at the end of line or end of file. | |
3129 | It consumes the newline at the end of line but does not place | |
3130 | this into the returned string. | |
3131 | *) | |
3132 | ||
3133 | @findex ReadS | |
3134 | PROCEDURE ReadS (file: File) : String ; | |
3135 | ||
3136 | ||
3137 | END SFIO. | |
3138 | @end example | |
3139 | @page | |
3140 | ||
3141 | @node gm2-libs/SMathLib0, gm2-libs/SYSTEM, gm2-libs/SFIO, Base libraries | |
3142 | @subsection gm2-libs/SMathLib0 | |
3143 | ||
3144 | @example | |
3145 | DEFINITION MODULE SMathLib0 ; | |
3146 | ||
3147 | CONST | |
3148 | pi = 3.1415926535897932384626433832795028841972; | |
3149 | exp1 = 2.7182818284590452353602874713526624977572; | |
3150 | ||
3151 | ||
3152 | @findex sqrt | |
3153 | PROCEDURE __BUILTIN__ sqrt (x: SHORTREAL) : SHORTREAL ; | |
3154 | @findex exp | |
3155 | PROCEDURE exp (x: SHORTREAL) : SHORTREAL ; | |
3156 | @findex ln | |
3157 | PROCEDURE ln (x: SHORTREAL) : SHORTREAL ; | |
3158 | @findex sin | |
3159 | PROCEDURE __BUILTIN__ sin (x: SHORTREAL) : SHORTREAL ; | |
3160 | @findex cos | |
3161 | PROCEDURE __BUILTIN__ cos (x: SHORTREAL) : SHORTREAL ; | |
3162 | @findex tan | |
3163 | PROCEDURE tan (x: SHORTREAL) : SHORTREAL ; | |
3164 | @findex arctan | |
3165 | PROCEDURE arctan (x: SHORTREAL) : SHORTREAL ; | |
3166 | @findex entier | |
3167 | PROCEDURE entier (x: SHORTREAL) : INTEGER ; | |
3168 | ||
3169 | ||
3170 | END SMathLib0. | |
3171 | @end example | |
3172 | @page | |
3173 | ||
3174 | @node gm2-libs/SYSTEM, gm2-libs/Scan, gm2-libs/SMathLib0, Base libraries | |
3175 | @subsection gm2-libs/SYSTEM | |
3176 | ||
3177 | @example | |
3178 | DEFINITION MODULE SYSTEM ; | |
3179 | ||
3180 | EXPORT QUALIFIED BITSPERBYTE, BYTESPERWORD, | |
3181 | ADDRESS, WORD, BYTE, CSIZE_T, CSSIZE_T, (* | |
3182 | Target specific data types. *) | |
3183 | ADR, TSIZE, ROTATE, SHIFT, THROW, TBITSIZE ; | |
3184 | (* SIZE is also exported if -fpim2 is used. *) | |
3185 | ||
3186 | CONST | |
3187 | @findex BITSPERBYTE (const) | |
3188 | BITSPERBYTE = __ATTRIBUTE__ __BUILTIN__ ((BITS_PER_UNIT)) ; | |
3189 | @findex BYTESPERWORD (const) | |
3190 | BYTESPERWORD = __ATTRIBUTE__ __BUILTIN__ ((UNITS_PER_WORD)) ; | |
3191 | ||
3192 | (* Note that the full list of system and sized datatypes include: | |
3193 | LOC, WORD, BYTE, ADDRESS, | |
3194 | ||
3195 | (and the non language standard target types) | |
3196 | ||
3197 | INTEGER8, INTEGER16, INTEGER32, INTEGER64, | |
3198 | CARDINAL8, CARDINAL16, CARDINAL32, CARDINAL64, | |
3199 | WORD16, WORD32, WORD64, BITSET8, BITSET16, | |
3200 | BITSET32, REAL32, REAL64, REAL128, COMPLEX32, | |
3201 | COMPLEX64, COMPLEX128, CSIZE_T, CSSIZE_T. | |
3202 | ||
3203 | Also note that the non-standard data types will | |
3204 | move into another module in the future. *) | |
3205 | ||
3206 | ||
3207 | (* The following types are supported on this target: | |
3208 | TYPE | |
3209 | (* Target specific data types. *) | |
3210 | *) | |
3211 | ||
3212 | ||
3213 | (* | |
3214 | all the functions below are declared internally to gm2 | |
3215 | ====================================================== | |
3216 | ||
3217 | @findex ADR | |
3218 | PROCEDURE ADR (VAR v: <anytype>): ADDRESS; | |
3219 | (* Returns the address of variable v. *) | |
3220 | ||
3221 | @findex SIZE | |
3222 | PROCEDURE SIZE (v: <type>) : ZType; | |
3223 | (* Returns the number of BYTES used to store a v of | |
3224 | any specified <type>. Only available if -fpim2 is used. | |
3225 | *) | |
3226 | ||
3227 | @findex TSIZE | |
3228 | PROCEDURE TSIZE (<type>) : CARDINAL; | |
3229 | (* Returns the number of BYTES used to store a value of the | |
3230 | specified <type>. | |
3231 | *) | |
3232 | ||
3233 | @findex ROTATE | |
3234 | PROCEDURE ROTATE (val: <a set type>; | |
3235 | num: INTEGER): <type of first parameter>; | |
3236 | (* Returns a bit sequence obtained from val by rotating up/right | |
3237 | or down/right by the absolute value of num. The direction is | |
3238 | down/right if the sign of num is negative, otherwise the direction | |
3239 | is up/left. | |
3240 | *) | |
3241 | ||
3242 | @findex SHIFT | |
3243 | PROCEDURE SHIFT (val: <a set type>; | |
3244 | num: INTEGER): <type of first parameter>; | |
3245 | (* Returns a bit sequence obtained from val by shifting up/left | |
3246 | or down/right by the absolute value of num, introducing | |
3247 | zeros as necessary. The direction is down/right if the sign of | |
3248 | num is negative, otherwise the direction is up/left. | |
3249 | *) | |
3250 | ||
3251 | @findex THROW | |
3252 | PROCEDURE THROW (i: INTEGER) ; | |
3253 | (* | |
3254 | THROW is a GNU extension and was not part of the PIM or ISO | |
3255 | standards. It throws an exception which will be caught by the | |
3256 | EXCEPT block (assuming it exists). This is a compiler builtin | |
3257 | function which interfaces to the GCC exception handling runtime | |
3258 | system. | |
3259 | GCC uses the term throw, hence the naming distinction between | |
3260 | the GCC builtin and the Modula-2 runtime library procedure Raise. | |
3261 | The later library procedure Raise will call SYSTEM.THROW after | |
3262 | performing various housekeeping activities. | |
3263 | *) | |
3264 | ||
3265 | @findex TBITSIZE | |
3266 | PROCEDURE TBITSIZE (<type>) : CARDINAL ; | |
3267 | (* Returns the minimum number of bits necessary to represent | |
3268 | <type>. This procedure function is only useful for determining | |
3269 | the number of bits used for any type field within a packed RECORD. | |
3270 | It is not particularly useful elsewhere since <type> might be | |
3271 | optimized for speed, for example a BOOLEAN could occupy a WORD. | |
3272 | *) | |
3273 | *) | |
3274 | ||
3275 | (* The following procedures are invoked by GNU Modula-2 to | |
3276 | shift non word sized set types. They are not strictly part | |
3277 | of the core PIM Modula-2, however they are used | |
3278 | to implement the SHIFT procedure defined above, | |
3279 | which are in turn used by the Logitech compatible libraries. | |
3280 | ||
3281 | Users will access these procedures by using the procedure | |
3282 | SHIFT above and GNU Modula-2 will map SHIFT onto one of | |
3283 | the following procedures. | |
3284 | *) | |
3285 | ||
3286 | (* | |
3287 | ShiftVal - is a runtime procedure whose job is to implement | |
3288 | the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will | |
3289 | inline a SHIFT of a single WORD sized set and will only | |
3290 | call this routine for larger sets. | |
3291 | *) | |
3292 | ||
3293 | @findex ShiftVal | |
3294 | PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET; | |
3295 | SetSizeInBits: CARDINAL; | |
3296 | ShiftCount: INTEGER) ; | |
3297 | ||
3298 | ||
3299 | (* | |
3300 | ShiftLeft - performs the shift left for a multi word set. | |
3301 | This procedure might be called by the back end of | |
3302 | GNU Modula-2 depending whether amount is known at | |
3303 | compile time. | |
3304 | *) | |
3305 | ||
3306 | @findex ShiftLeft | |
3307 | PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET; | |
3308 | SetSizeInBits: CARDINAL; | |
3309 | ShiftCount: CARDINAL) ; | |
3310 | ||
3311 | (* | |
3312 | ShiftRight - performs the shift left for a multi word set. | |
3313 | This procedure might be called by the back end of | |
3314 | GNU Modula-2 depending whether amount is known at | |
3315 | compile time. | |
3316 | *) | |
3317 | ||
3318 | @findex ShiftRight | |
3319 | PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET; | |
3320 | SetSizeInBits: CARDINAL; | |
3321 | ShiftCount: CARDINAL) ; | |
3322 | ||
3323 | ||
3324 | (* | |
3325 | RotateVal - is a runtime procedure whose job is to implement | |
3326 | the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will | |
3327 | inline a ROTATE of a single WORD (or less) | |
3328 | sized set and will only call this routine for larger | |
3329 | sets. | |
3330 | *) | |
3331 | ||
3332 | @findex RotateVal | |
3333 | PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET; | |
3334 | SetSizeInBits: CARDINAL; | |
3335 | RotateCount: INTEGER) ; | |
3336 | ||
3337 | ||
3338 | (* | |
3339 | RotateLeft - performs the rotate left for a multi word set. | |
3340 | This procedure might be called by the back end of | |
3341 | GNU Modula-2 depending whether amount is known at | |
3342 | compile time. | |
3343 | *) | |
3344 | ||
3345 | @findex RotateLeft | |
3346 | PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET; | |
3347 | SetSizeInBits: CARDINAL; | |
3348 | RotateCount: CARDINAL) ; | |
3349 | ||
3350 | ||
3351 | (* | |
3352 | RotateRight - performs the rotate right for a multi word set. | |
3353 | This procedure might be called by the back end of | |
3354 | GNU Modula-2 depending whether amount is known at | |
3355 | compile time. | |
3356 | *) | |
3357 | ||
3358 | @findex RotateRight | |
3359 | PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET; | |
3360 | SetSizeInBits: CARDINAL; | |
3361 | RotateCount: CARDINAL) ; | |
3362 | ||
3363 | ||
3364 | END SYSTEM. | |
3365 | @end example | |
3366 | @page | |
3367 | ||
3368 | @node gm2-libs/Scan, gm2-libs/Selective, gm2-libs/SYSTEM, Base libraries | |
3369 | @subsection gm2-libs/Scan | |
3370 | ||
3371 | @example | |
3372 | DEFINITION MODULE Scan ; | |
3373 | ||
3374 | (* Provides a primitive symbol fetching from input. | |
3375 | Symbols are delimited by spaces and tabs. | |
3376 | Limitation only allows one source file at | |
3377 | a time to deliver symbols. *) | |
3378 | ||
3379 | ||
3380 | EXPORT QUALIFIED GetNextSymbol, WriteError, | |
3381 | OpenSource, CloseSource, | |
3382 | TerminateOnError, DefineComments ; | |
3383 | ||
3384 | ||
3385 | (* OpenSource - opens a source file for reading. *) | |
3386 | ||
3387 | @findex OpenSource | |
3388 | PROCEDURE OpenSource (a: ARRAY OF CHAR) : BOOLEAN ; | |
3389 | ||
3390 | ||
3391 | (* CloseSource - closes the current source file from reading. *) | |
3392 | ||
3393 | @findex CloseSource | |
3394 | PROCEDURE CloseSource ; | |
3395 | ||
3396 | ||
3397 | (* GetNextSymbol gets the next source symbol and returns it in a. *) | |
3398 | ||
3399 | @findex GetNextSymbol | |
3400 | PROCEDURE GetNextSymbol (VAR a: ARRAY OF CHAR) ; | |
3401 | ||
3402 | ||
3403 | (* WriteError writes a message, a, under the source line, which *) | |
3404 | (* attempts to pinpoint the Symbol at fault. *) | |
3405 | ||
3406 | @findex WriteError | |
3407 | PROCEDURE WriteError (a: ARRAY OF CHAR) ; | |
3408 | ||
3409 | ||
3410 | (* | |
3411 | TerminateOnError - exits with status 1 if we call WriteError. | |
3412 | *) | |
3413 | ||
3414 | @findex TerminateOnError | |
3415 | PROCEDURE TerminateOnError ; | |
3416 | ||
3417 | ||
3418 | (* | |
3419 | DefineComments - defines the start of comments within the source | |
3420 | file. | |
3421 | ||
3422 | The characters in Start define the comment start | |
3423 | and characters in End define the end. | |
3424 | The BOOLEAN eoln determine whether the comment | |
3425 | is terminated by end of line. If eoln is TRUE | |
3426 | then End is ignored. | |
3427 | ||
3428 | If this procedure is never called then no comments | |
3429 | are allowed. | |
3430 | *) | |
3431 | ||
3432 | @findex DefineComments | |
3433 | PROCEDURE DefineComments (Start, End: ARRAY OF CHAR; eoln: BOOLEAN) ; | |
3434 | ||
3435 | ||
3436 | END Scan. | |
3437 | @end example | |
3438 | @page | |
3439 | ||
3440 | @node gm2-libs/Selective, gm2-libs/StdIO, gm2-libs/Scan, Base libraries | |
3441 | @subsection gm2-libs/Selective | |
3442 | ||
3443 | @example | |
3444 | DEFINITION MODULE Selective ; | |
3445 | ||
3446 | FROM SYSTEM IMPORT ADDRESS ; | |
3447 | ||
3448 | EXPORT QUALIFIED SetOfFd, Timeval, | |
3449 | InitSet, KillSet, InitTime, KillTime, | |
3450 | GetTime, SetTime, | |
3451 | FdZero, FdSet, FdClr, FdIsSet, Select, | |
3452 | MaxFdsPlusOne, WriteCharRaw, ReadCharRaw, | |
3453 | GetTimeOfDay ; | |
3454 | ||
3455 | TYPE | |
3456 | @findex SetOfFd (type) | |
3457 | SetOfFd = ADDRESS ; (* Hidden type in Selective.c *) | |
3458 | @findex Timeval (type) | |
3459 | Timeval = ADDRESS ; (* Hidden type in Selective.c *) | |
3460 | ||
3461 | ||
3462 | @findex Select | |
3463 | PROCEDURE Select (nooffds: CARDINAL; | |
3464 | readfds, writefds, exceptfds: SetOfFd; | |
3465 | timeout: Timeval) : INTEGER ; | |
3466 | ||
3467 | @findex InitTime | |
3468 | PROCEDURE InitTime (sec, usec: CARDINAL) : Timeval ; | |
3469 | @findex KillTime | |
3470 | PROCEDURE KillTime (t: Timeval) : Timeval ; | |
3471 | @findex GetTime | |
3472 | PROCEDURE GetTime (t: Timeval; VAR sec, usec: CARDINAL) ; | |
3473 | @findex SetTime | |
3474 | PROCEDURE SetTime (t: Timeval; sec, usec: CARDINAL) ; | |
3475 | @findex InitSet | |
3476 | PROCEDURE InitSet () : SetOfFd ; | |
3477 | @findex KillSet | |
3478 | PROCEDURE KillSet (s: SetOfFd) : SetOfFd ; | |
3479 | @findex FdZero | |
3480 | PROCEDURE FdZero (s: SetOfFd) ; | |
3481 | @findex FdSet | |
3482 | PROCEDURE FdSet (fd: INTEGER; s: SetOfFd) ; | |
3483 | @findex FdClr | |
3484 | PROCEDURE FdClr (fd: INTEGER; s: SetOfFd) ; | |
3485 | @findex FdIsSet | |
3486 | PROCEDURE FdIsSet (fd: INTEGER; s: SetOfFd) : BOOLEAN ; | |
3487 | @findex MaxFdsPlusOne | |
3488 | PROCEDURE MaxFdsPlusOne (a, b: INTEGER) : INTEGER ; | |
3489 | ||
3490 | (* you must use the raw routines with select - not the FIO buffered routines *) | |
3491 | @findex WriteCharRaw | |
3492 | PROCEDURE WriteCharRaw (fd: INTEGER; ch: CHAR) ; | |
3493 | @findex ReadCharRaw | |
3494 | PROCEDURE ReadCharRaw (fd: INTEGER) : CHAR ; | |
3495 | ||
3496 | (* | |
3497 | GetTimeOfDay - fills in a record, Timeval, filled in with the | |
3498 | current system time in seconds and microseconds. | |
3499 | It returns zero (see man 3p gettimeofday) | |
3500 | *) | |
3501 | ||
3502 | @findex GetTimeOfDay | |
3503 | PROCEDURE GetTimeOfDay (tv: Timeval) : INTEGER ; | |
3504 | ||
3505 | ||
3506 | END Selective. | |
3507 | @end example | |
3508 | @page | |
3509 | ||
3510 | @node gm2-libs/StdIO, gm2-libs/Storage, gm2-libs/Selective, Base libraries | |
3511 | @subsection gm2-libs/StdIO | |
3512 | ||
3513 | @example | |
3514 | DEFINITION MODULE StdIO ; | |
3515 | ||
3516 | EXPORT QUALIFIED ProcRead, ProcWrite, | |
3517 | Read, Write, | |
3518 | PushOutput, PopOutput, GetCurrentOutput, | |
3519 | PushInput, PopInput, GetCurrentInput ; | |
3520 | ||
3521 | ||
3522 | TYPE | |
3523 | @findex ProcWrite (type) | |
3524 | ProcWrite = PROCEDURE (CHAR) ; | |
3525 | @findex ProcRead (type) | |
3526 | ProcRead = PROCEDURE (VAR CHAR) ; | |
3527 | ||
3528 | ||
3529 | (* | |
3530 | Read - is the generic procedure that all higher application layers | |
3531 | should use to receive a character. | |
3532 | *) | |
3533 | ||
3534 | @findex Read | |
3535 | PROCEDURE Read (VAR ch: CHAR) ; | |
3536 | ||
3537 | ||
3538 | (* | |
3539 | Write - is the generic procedure that all higher application layers | |
3540 | should use to emit a character. | |
3541 | *) | |
3542 | ||
3543 | @findex Write | |
3544 | PROCEDURE Write (ch: CHAR) ; | |
3545 | ||
3546 | ||
3547 | (* | |
3548 | PushOutput - pushes the current Write procedure onto a stack, | |
3549 | any future references to Write will actually invoke | |
3550 | procedure, p. | |
3551 | *) | |
3552 | ||
3553 | @findex PushOutput | |
3554 | PROCEDURE PushOutput (p: ProcWrite) ; | |
3555 | ||
3556 | ||
3557 | (* | |
3558 | PopOutput - restores Write to use the previous output procedure. | |
3559 | *) | |
3560 | ||
3561 | @findex PopOutput | |
3562 | PROCEDURE PopOutput ; | |
3563 | ||
3564 | ||
3565 | (* | |
3566 | GetCurrentOutput - returns the current output procedure. | |
3567 | *) | |
3568 | ||
3569 | @findex GetCurrentOutput | |
3570 | PROCEDURE GetCurrentOutput () : ProcWrite ; | |
3571 | ||
3572 | ||
3573 | (* | |
3574 | PushInput - pushes the current Read procedure onto a stack, | |
3575 | any future references to Read will actually invoke | |
3576 | procedure, p. | |
3577 | *) | |
3578 | ||
3579 | @findex PushInput | |
3580 | PROCEDURE PushInput (p: ProcRead) ; | |
3581 | ||
3582 | ||
3583 | (* | |
3584 | PopInput - restores Write to use the previous output procedure. | |
3585 | *) | |
3586 | ||
3587 | @findex PopInput | |
3588 | PROCEDURE PopInput ; | |
3589 | ||
3590 | ||
3591 | (* | |
3592 | GetCurrentInput - returns the current input procedure. | |
3593 | *) | |
3594 | ||
3595 | @findex GetCurrentInput | |
3596 | PROCEDURE GetCurrentInput () : ProcRead ; | |
3597 | ||
3598 | ||
3599 | END StdIO. | |
3600 | @end example | |
3601 | @page | |
3602 | ||
3603 | @node gm2-libs/Storage, gm2-libs/StrCase, gm2-libs/StdIO, Base libraries | |
3604 | @subsection gm2-libs/Storage | |
3605 | ||
3606 | @example | |
3607 | DEFINITION MODULE Storage ; | |
3608 | ||
3609 | FROM SYSTEM IMPORT ADDRESS ; | |
3610 | ||
3611 | EXPORT QUALIFIED ALLOCATE, DEALLOCATE, REALLOCATE, Available ; | |
3612 | ||
3613 | ||
3614 | ||
3615 | (* | |
3616 | ALLOCATE - attempt to allocate memory from the heap. | |
3617 | NIL is returned in, a, if ALLOCATE fails. | |
3618 | *) | |
3619 | ||
3620 | @findex ALLOCATE | |
3621 | PROCEDURE ALLOCATE (VAR a: ADDRESS ; Size: CARDINAL) ; | |
3622 | ||
3623 | ||
3624 | (* | |
3625 | DEALLOCATE - return, Size, bytes to the heap. | |
3626 | The variable, a, is set to NIL. | |
3627 | *) | |
3628 | ||
3629 | @findex DEALLOCATE | |
3630 | PROCEDURE DEALLOCATE (VAR a: ADDRESS ; Size: CARDINAL) ; | |
3631 | ||
3632 | ||
3633 | (* | |
3634 | REALLOCATE - attempts to reallocate storage. The address, | |
3635 | a, should either be NIL in which case ALLOCATE | |
3636 | is called, or alternatively it should have already | |
3637 | been initialized by ALLOCATE. The allocated storage | |
3638 | is resized accordingly. | |
3639 | *) | |
3640 | ||
3641 | @findex REALLOCATE | |
3642 | PROCEDURE REALLOCATE (VAR a: ADDRESS; Size: CARDINAL) ; | |
3643 | ||
3644 | ||
3645 | (* | |
3646 | Available - returns TRUE if, Size, bytes can be allocated. | |
3647 | *) | |
3648 | ||
3649 | @findex Available | |
3650 | PROCEDURE Available (Size: CARDINAL) : BOOLEAN ; | |
3651 | ||
3652 | ||
3653 | END Storage. | |
3654 | @end example | |
3655 | @page | |
3656 | ||
3657 | @node gm2-libs/StrCase, gm2-libs/StrIO, gm2-libs/Storage, Base libraries | |
3658 | @subsection gm2-libs/StrCase | |
3659 | ||
3660 | @example | |
3661 | DEFINITION MODULE StrCase ; | |
3662 | ||
3663 | ||
3664 | EXPORT QUALIFIED StrToUpperCase, StrToLowerCase, Cap, Lower ; | |
3665 | ||
3666 | ||
3667 | (* | |
3668 | StrToUpperCase - converts string, a, to uppercase returning the | |
3669 | result in, b. | |
3670 | *) | |
3671 | ||
3672 | @findex StrToUpperCase | |
3673 | PROCEDURE StrToUpperCase (a: ARRAY OF CHAR ; VAR b: ARRAY OF CHAR) ; | |
3674 | ||
3675 | ||
3676 | (* | |
3677 | StrToLowerCase - converts string, a, to lowercase returning the | |
3678 | result in, b. | |
3679 | *) | |
3680 | ||
3681 | @findex StrToLowerCase | |
3682 | PROCEDURE StrToLowerCase (a: ARRAY OF CHAR ; VAR b: ARRAY OF CHAR) ; | |
3683 | ||
3684 | ||
3685 | (* | |
3686 | Cap - converts a lower case character into a capital character. | |
3687 | If the character is not a lower case character 'a'..'z' | |
3688 | then the character is simply returned unaltered. | |
3689 | *) | |
3690 | ||
3691 | @findex Cap | |
3692 | PROCEDURE Cap (ch: CHAR) : CHAR ; | |
3693 | ||
3694 | ||
3695 | (* | |
3696 | Lower - converts an upper case character into a lower case character. | |
3697 | If the character is not an upper case character 'A'..'Z' | |
3698 | then the character is simply returned unaltered. | |
3699 | *) | |
3700 | ||
3701 | @findex Lower | |
3702 | PROCEDURE Lower (ch: CHAR) : CHAR ; | |
3703 | ||
3704 | ||
3705 | END StrCase. | |
3706 | @end example | |
3707 | @page | |
3708 | ||
3709 | @node gm2-libs/StrIO, gm2-libs/StrLib, gm2-libs/StrCase, Base libraries | |
3710 | @subsection gm2-libs/StrIO | |
3711 | ||
3712 | @example | |
3713 | DEFINITION MODULE StrIO ; | |
3714 | ||
3715 | EXPORT QUALIFIED ReadString, WriteString, | |
3716 | WriteLn ; | |
3717 | ||
3718 | ||
3719 | (* | |
3720 | WriteLn - writes a carriage return and a newline | |
3721 | character. | |
3722 | *) | |
3723 | ||
3724 | @findex WriteLn | |
3725 | PROCEDURE WriteLn ; | |
3726 | ||
3727 | ||
3728 | (* | |
3729 | ReadString - reads a sequence of characters into a string. | |
3730 | Line editing accepts Del, Ctrl H, Ctrl W and | |
3731 | Ctrl U. | |
3732 | *) | |
3733 | ||
3734 | @findex ReadString | |
3735 | PROCEDURE ReadString (VAR a: ARRAY OF CHAR) ; | |
3736 | ||
3737 | ||
3738 | (* | |
3739 | WriteString - writes a string to the default output. | |
3740 | *) | |
3741 | ||
3742 | @findex WriteString | |
3743 | PROCEDURE WriteString (a: ARRAY OF CHAR) ; | |
3744 | ||
3745 | ||
3746 | END StrIO. | |
3747 | @end example | |
3748 | @page | |
3749 | ||
3750 | @node gm2-libs/StrLib, gm2-libs/StringConvert, gm2-libs/StrIO, Base libraries | |
3751 | @subsection gm2-libs/StrLib | |
3752 | ||
3753 | @example | |
3754 | DEFINITION MODULE StrLib ; | |
3755 | ||
3756 | EXPORT QUALIFIED StrConCat, StrLen, StrCopy, StrEqual, StrLess, | |
3757 | IsSubString, StrRemoveWhitePrefix ; | |
3758 | ||
3759 | ||
3760 | (* | |
3761 | StrConCat - combines a and b into c. | |
3762 | *) | |
3763 | ||
3764 | @findex StrConCat | |
3765 | PROCEDURE StrConCat (a, b: ARRAY OF CHAR; VAR c: ARRAY OF CHAR) ; | |
3766 | ||
3767 | ||
3768 | (* | |
3769 | StrLess - returns TRUE if string, a, alphabetically occurs before | |
3770 | string, b. | |
3771 | *) | |
3772 | ||
3773 | @findex StrLess | |
3774 | PROCEDURE StrLess (a, b: ARRAY OF CHAR) : BOOLEAN ; | |
3775 | ||
3776 | ||
3777 | (* | |
3778 | StrEqual - performs a = b on two strings. | |
3779 | *) | |
3780 | ||
3781 | @findex StrEqual | |
3782 | PROCEDURE StrEqual (a, b: ARRAY OF CHAR) : BOOLEAN ; | |
3783 | ||
3784 | ||
3785 | (* | |
3786 | StrLen - returns the length of string, a. | |
3787 | *) | |
3788 | ||
3789 | @findex StrLen | |
3790 | PROCEDURE StrLen (a: ARRAY OF CHAR) : CARDINAL ; | |
3791 | ||
3792 | ||
3793 | (* | |
3794 | StrCopy - copy string src into string dest providing dest is large enough. | |
3795 | If dest is smaller than a then src then the string is truncated when | |
3796 | dest is full. Add a nul character if there is room in dest. | |
3797 | *) | |
3798 | ||
3799 | @findex StrCopy | |
3800 | PROCEDURE StrCopy (src: ARRAY OF CHAR ; VAR dest: ARRAY OF CHAR) ; | |
3801 | ||
3802 | ||
3803 | (* | |
3804 | IsSubString - returns true if b is a subcomponent of a. | |
3805 | *) | |
3806 | ||
3807 | @findex IsSubString | |
3808 | PROCEDURE IsSubString (a, b: ARRAY OF CHAR) : BOOLEAN ; | |
3809 | ||
3810 | ||
3811 | (* | |
3812 | StrRemoveWhitePrefix - copies string, into string, b, excluding any white | |
3813 | space infront of a. | |
3814 | *) | |
3815 | ||
3816 | @findex StrRemoveWhitePrefix | |
3817 | PROCEDURE StrRemoveWhitePrefix (a: ARRAY OF CHAR; VAR b: ARRAY OF CHAR) ; | |
3818 | ||
3819 | ||
3820 | END StrLib. | |
3821 | @end example | |
3822 | @page | |
3823 | ||
3824 | @node gm2-libs/StringConvert, gm2-libs/SysExceptions, gm2-libs/StrLib, Base libraries | |
3825 | @subsection gm2-libs/StringConvert | |
3826 | ||
3827 | @example | |
3828 | DEFINITION MODULE StringConvert ; | |
3829 | ||
3830 | FROM DynamicStrings IMPORT String ; | |
3831 | EXPORT QUALIFIED IntegerToString, StringToInteger, | |
3832 | StringToLongInteger, LongIntegerToString, | |
3833 | StringToCardinal, CardinalToString, | |
3834 | StringToLongCardinal, LongCardinalToString, | |
3835 | StringToShortCardinal, ShortCardinalToString, | |
3836 | StringToLongreal, LongrealToString, | |
3837 | ToSigFig, | |
3838 | stoi, itos, ctos, stoc, hstoi, ostoi, bstoi, | |
3839 | hstoc, ostoc, bstoc, | |
3840 | stor, stolr ; | |
3841 | ||
3842 | ||
3843 | (* | |
3844 | IntegerToString - converts INTEGER, i, into a String. The field with | |
3845 | can be specified if non zero. Leading characters | |
3846 | are defined by padding and this function will | |
3847 | prepend a + if sign is set to TRUE. | |
3848 | The base allows the caller to generate binary, | |
3849 | octal, decimal, hexidecimal numbers. | |
3850 | The value of lower is only used when hexidecimal | |
3851 | numbers are generated and if TRUE then digits | |
3852 | abcdef are used, and if FALSE then ABCDEF are used. | |
3853 | *) | |
3854 | ||
3855 | @findex IntegerToString | |
3856 | PROCEDURE IntegerToString (i: INTEGER; width: CARDINAL; padding: CHAR; sign: BOOLEAN; | |
3857 | base: CARDINAL; lower: BOOLEAN) : String ; | |
3858 | ||
3859 | ||
3860 | (* | |
3861 | CardinalToString - converts CARDINAL, c, into a String. The field | |
3862 | width can be specified if non zero. Leading | |
3863 | characters are defined by padding. | |
3864 | The base allows the caller to generate binary, | |
3865 | octal, decimal, hexidecimal numbers. | |
3866 | The value of lower is only used when hexidecimal | |
3867 | numbers are generated and if TRUE then digits | |
3868 | abcdef are used, and if FALSE then ABCDEF are used. | |
3869 | *) | |
3870 | ||
3871 | @findex CardinalToString | |
3872 | PROCEDURE CardinalToString (c: CARDINAL; width: CARDINAL; padding: CHAR; | |
3873 | base: CARDINAL; lower: BOOLEAN) : String ; | |
3874 | ||
3875 | ||
3876 | (* | |
3877 | StringToInteger - converts a string, s, of, base, into an INTEGER. | |
3878 | Leading white space is ignored. It stops converting | |
3879 | when either the string is exhausted or if an illegal | |
3880 | numeral is found. | |
3881 | The parameter found is set TRUE if a number was found. | |
3882 | *) | |
3883 | ||
3884 | @findex StringToInteger | |
3885 | PROCEDURE StringToInteger (s: String; base: CARDINAL; VAR found: BOOLEAN) : INTEGER ; | |
3886 | ||
3887 | ||
3888 | (* | |
3889 | StringToCardinal - converts a string, s, of, base, into a CARDINAL. | |
3890 | Leading white space is ignored. It stops converting | |
3891 | when either the string is exhausted or if an illegal | |
3892 | numeral is found. | |
3893 | The parameter found is set TRUE if a number was found. | |
3894 | *) | |
3895 | ||
3896 | @findex StringToCardinal | |
3897 | PROCEDURE StringToCardinal (s: String; base: CARDINAL; VAR found: BOOLEAN) : CARDINAL ; | |
3898 | ||
3899 | ||
3900 | (* | |
3901 | LongIntegerToString - converts LONGINT, i, into a String. The field with | |
3902 | can be specified if non zero. Leading characters | |
3903 | are defined by padding and this function will | |
3904 | prepend a + if sign is set to TRUE. | |
3905 | The base allows the caller to generate binary, | |
3906 | octal, decimal, hexidecimal numbers. | |
3907 | The value of lower is only used when hexidecimal | |
3908 | numbers are generated and if TRUE then digits | |
3909 | abcdef are used, and if FALSE then ABCDEF are used. | |
3910 | *) | |
3911 | ||
3912 | @findex LongIntegerToString | |
3913 | PROCEDURE LongIntegerToString (i: LONGINT; width: CARDINAL; padding: CHAR; | |
3914 | sign: BOOLEAN; base: CARDINAL; lower: BOOLEAN) : String ; | |
3915 | ||
3916 | ||
3917 | ||
3918 | (* | |
3919 | StringToLongInteger - converts a string, s, of, base, into an LONGINT. | |
3920 | Leading white space is ignored. It stops converting | |
3921 | when either the string is exhausted or if an illegal | |
3922 | numeral is found. | |
3923 | The parameter found is set TRUE if a number was found. | |
3924 | *) | |
3925 | ||
3926 | @findex StringToLongInteger | |
3927 | PROCEDURE StringToLongInteger (s: String; base: CARDINAL; VAR found: BOOLEAN) : LONGINT ; | |
3928 | ||
3929 | ||
3930 | (* | |
3931 | LongCardinalToString - converts LONGCARD, c, into a String. The field | |
3932 | width can be specified if non zero. Leading | |
3933 | characters are defined by padding. | |
3934 | The base allows the caller to generate binary, | |
3935 | octal, decimal, hexidecimal numbers. | |
3936 | The value of lower is only used when hexidecimal | |
3937 | numbers are generated and if TRUE then digits | |
3938 | abcdef are used, and if FALSE then ABCDEF are used. | |
3939 | *) | |
3940 | ||
3941 | @findex LongCardinalToString | |
3942 | PROCEDURE LongCardinalToString (c: LONGCARD; width: CARDINAL; padding: CHAR; | |
3943 | base: CARDINAL; lower: BOOLEAN) : String ; | |
3944 | ||
3945 | ||
3946 | (* | |
3947 | StringToLongCardinal - converts a string, s, of, base, into a LONGCARD. | |
3948 | Leading white space is ignored. It stops converting | |
3949 | when either the string is exhausted or if an illegal | |
3950 | numeral is found. | |
3951 | The parameter found is set TRUE if a number was found. | |
3952 | *) | |
3953 | ||
3954 | @findex StringToLongCardinal | |
3955 | PROCEDURE StringToLongCardinal (s: String; base: CARDINAL; VAR found: BOOLEAN) : LONGCARD ; | |
3956 | ||
3957 | ||
3958 | (* | |
3959 | ShortCardinalToString - converts SHORTCARD, c, into a String. The field | |
3960 | width can be specified if non zero. Leading | |
3961 | characters are defined by padding. | |
3962 | The base allows the caller to generate binary, | |
3963 | octal, decimal, hexidecimal numbers. | |
3964 | The value of lower is only used when hexidecimal | |
3965 | numbers are generated and if TRUE then digits | |
3966 | abcdef are used, and if FALSE then ABCDEF are used. | |
3967 | *) | |
3968 | ||
3969 | @findex ShortCardinalToString | |
3970 | PROCEDURE ShortCardinalToString (c: SHORTCARD; width: CARDINAL; padding: CHAR; | |
3971 | base: CARDINAL; lower: BOOLEAN) : String ; | |
3972 | ||
3973 | ||
3974 | (* | |
3975 | StringToShortCardinal - converts a string, s, of, base, into a SHORTCARD. | |
3976 | Leading white space is ignored. It stops converting | |
3977 | when either the string is exhausted or if an illegal | |
3978 | numeral is found. | |
3979 | The parameter found is set TRUE if a number was found. | |
3980 | *) | |
3981 | ||
3982 | @findex StringToShortCardinal | |
3983 | PROCEDURE StringToShortCardinal (s: String; base: CARDINAL; | |
3984 | VAR found: BOOLEAN) : SHORTCARD ; | |
3985 | ||
3986 | ||
3987 | (* | |
3988 | stoi - decimal string to INTEGER | |
3989 | *) | |
3990 | ||
3991 | @findex stoi | |
3992 | PROCEDURE stoi (s: String) : INTEGER ; | |
3993 | ||
3994 | ||
3995 | (* | |
3996 | itos - integer to decimal string. | |
3997 | *) | |
3998 | ||
3999 | @findex itos | |
4000 | PROCEDURE itos (i: INTEGER; width: CARDINAL; padding: CHAR; sign: BOOLEAN) : String ; | |
4001 | ||
4002 | ||
4003 | (* | |
4004 | ctos - cardinal to decimal string. | |
4005 | *) | |
4006 | ||
4007 | @findex ctos | |
4008 | PROCEDURE ctos (c: CARDINAL; width: CARDINAL; padding: CHAR) : String ; | |
4009 | ||
4010 | ||
4011 | (* | |
4012 | stoc - decimal string to CARDINAL | |
4013 | *) | |
4014 | ||
4015 | @findex stoc | |
4016 | PROCEDURE stoc (s: String) : CARDINAL ; | |
4017 | ||
4018 | ||
4019 | (* | |
4020 | hstoi - hexidecimal string to INTEGER | |
4021 | *) | |
4022 | ||
4023 | @findex hstoi | |
4024 | PROCEDURE hstoi (s: String) : INTEGER ; | |
4025 | ||
4026 | ||
4027 | (* | |
4028 | ostoi - octal string to INTEGER | |
4029 | *) | |
4030 | ||
4031 | @findex ostoi | |
4032 | PROCEDURE ostoi (s: String) : INTEGER ; | |
4033 | ||
4034 | ||
4035 | (* | |
4036 | bstoi - binary string to INTEGER | |
4037 | *) | |
4038 | ||
4039 | @findex bstoi | |
4040 | PROCEDURE bstoi (s: String) : INTEGER ; | |
4041 | ||
4042 | ||
4043 | (* | |
4044 | hstoc - hexidecimal string to CARDINAL | |
4045 | *) | |
4046 | ||
4047 | @findex hstoc | |
4048 | PROCEDURE hstoc (s: String) : CARDINAL ; | |
4049 | ||
4050 | ||
4051 | (* | |
4052 | ostoc - octal string to CARDINAL | |
4053 | *) | |
4054 | ||
4055 | @findex ostoc | |
4056 | PROCEDURE ostoc (s: String) : CARDINAL ; | |
4057 | ||
4058 | ||
4059 | (* | |
4060 | bstoc - binary string to CARDINAL | |
4061 | *) | |
4062 | ||
4063 | @findex bstoc | |
4064 | PROCEDURE bstoc (s: String) : CARDINAL ; | |
4065 | ||
4066 | ||
4067 | (* | |
4068 | StringToLongreal - returns a LONGREAL and sets found to TRUE | |
4069 | if a legal number is seen. | |
4070 | *) | |
4071 | ||
4072 | @findex StringToLongreal | |
4073 | PROCEDURE StringToLongreal (s: String; VAR found: BOOLEAN) : LONGREAL ; | |
4074 | ||
4075 | ||
4076 | (* | |
4077 | LongrealToString - converts a LONGREAL number, Real, which has, | |
4078 | TotalWidth, and FractionWidth into a string. | |
4079 | ||
4080 | So for example: | |
4081 | ||
4082 | LongrealToString(1.0, 4, 2) -> '1.00' | |
4083 | LongrealToString(12.3, 5, 2) -> '12.30' | |
4084 | LongrealToString(12.3, 6, 2) -> ' 12.30' | |
4085 | LongrealToString(12.3, 6, 3) -> '12.300' | |
4086 | ||
4087 | if total width is too small then the fraction | |
4088 | becomes truncated. | |
4089 | ||
4090 | LongrealToString(12.3, 5, 3) -> '12.30' | |
4091 | ||
4092 | If TotalWidth is 0 then the function | |
4093 | will return the value of x which is converted | |
4094 | into as a fixed point number with exhaustive | |
4095 | precision. | |
4096 | *) | |
4097 | ||
4098 | @findex LongrealToString | |
4099 | PROCEDURE LongrealToString (x: LONGREAL; | |
4100 | TotalWidth, FractionWidth: CARDINAL) : String ; | |
4101 | ||
4102 | ||
4103 | (* | |
4104 | stor - returns a REAL given a string. | |
4105 | *) | |
4106 | ||
4107 | @findex stor | |
4108 | PROCEDURE stor (s: String) : REAL ; | |
4109 | ||
4110 | ||
4111 | (* | |
4112 | stolr - returns a LONGREAL given a string. | |
4113 | *) | |
4114 | ||
4115 | @findex stolr | |
4116 | PROCEDURE stolr (s: String) : LONGREAL ; | |
4117 | ||
4118 | ||
4119 | (* | |
4120 | ToSigFig - returns a floating point or base 10 integer | |
4121 | string which is accurate to, n, significant | |
4122 | figures. It will return a new String | |
4123 | and, s, will be destroyed. | |
4124 | ||
4125 | ||
4126 | So: 12.345 | |
4127 | ||
4128 | rounded to the following significant figures yields | |
4129 | ||
4130 | 5 12.345 | |
4131 | 4 12.34 | |
4132 | 3 12.3 | |
4133 | 2 12 | |
4134 | 1 10 | |
4135 | *) | |
4136 | ||
4137 | @findex ToSigFig | |
4138 | PROCEDURE ToSigFig (s: String; n: CARDINAL) : String ; | |
4139 | ||
4140 | ||
4141 | (* | |
4142 | ToDecimalPlaces - returns a floating point or base 10 integer | |
4143 | string which is accurate to, n, decimal | |
4144 | places. It will return a new String | |
4145 | and, s, will be destroyed. | |
4146 | Decimal places yields, n, digits after | |
4147 | the . | |
4148 | ||
4149 | So: 12.345 | |
4150 | ||
4151 | rounded to the following decimal places yields | |
4152 | ||
4153 | 5 12.34500 | |
4154 | 4 12.3450 | |
4155 | 3 12.345 | |
4156 | 2 12.34 | |
4157 | 1 12.3 | |
4158 | *) | |
4159 | ||
4160 | @findex ToDecimalPlaces | |
4161 | PROCEDURE ToDecimalPlaces (s: String; n: CARDINAL) : String ; | |
4162 | ||
4163 | ||
4164 | END StringConvert. | |
4165 | @end example | |
4166 | @page | |
4167 | ||
4168 | @node gm2-libs/SysExceptions, gm2-libs/SysStorage, gm2-libs/StringConvert, Base libraries | |
4169 | @subsection gm2-libs/SysExceptions | |
4170 | ||
4171 | @example | |
4172 | DEFINITION MODULE SysExceptions ; | |
4173 | ||
4174 | (* Provides a mechanism for the underlying libraries to | |
4175 | configure the exception routines. This mechanism | |
4176 | is used by both the ISO and PIM libraries. | |
4177 | It is written to be ISO compliant and this also | |
4178 | allows for mixed dialect projects. *) | |
4179 | ||
4180 | FROM SYSTEM IMPORT ADDRESS ; | |
4181 | ||
4182 | TYPE | |
4183 | @findex PROCEXCEPTION (type) | |
4184 | PROCEXCEPTION = PROCEDURE (ADDRESS) ; | |
4185 | ||
4186 | @findex InitExceptionHandlers | |
4187 | PROCEDURE InitExceptionHandlers (indexf, range, casef, invalidloc, | |
4188 | function, wholevalue, wholediv, | |
4189 | realvalue, realdiv, complexvalue, | |
4190 | complexdiv, protection, systemf, | |
4191 | coroutine, exception: PROCEXCEPTION) ; | |
4192 | ||
4193 | ||
4194 | END SysExceptions. | |
4195 | @end example | |
4196 | @page | |
4197 | ||
4198 | @node gm2-libs/SysStorage, gm2-libs/TimeString, gm2-libs/SysExceptions, Base libraries | |
4199 | @subsection gm2-libs/SysStorage | |
4200 | ||
4201 | @example | |
4202 | DEFINITION MODULE SysStorage ; | |
4203 | ||
4204 | (* Provides dynamic allocation for the system components. | |
4205 | This allows the application to use the traditional Storage module | |
4206 | which can be handled differently. *) | |
4207 | ||
4208 | FROM SYSTEM IMPORT ADDRESS ; | |
4209 | EXPORT QUALIFIED ALLOCATE, DEALLOCATE, REALLOCATE, Available, Init ; | |
4210 | ||
4211 | ||
4212 | (* | |
4213 | ALLOCATE - attempt to allocate memory from the heap. | |
4214 | NIL is returned in, a, if ALLOCATE fails. | |
4215 | *) | |
4216 | ||
4217 | @findex ALLOCATE | |
4218 | PROCEDURE ALLOCATE (VAR a: ADDRESS ; size: CARDINAL) ; | |
4219 | ||
4220 | ||
4221 | (* | |
4222 | DEALLOCATE - return, size, bytes to the heap. | |
4223 | The variable, a, is set to NIL. | |
4224 | *) | |
4225 | ||
4226 | @findex DEALLOCATE | |
4227 | PROCEDURE DEALLOCATE (VAR a: ADDRESS ; size: CARDINAL) ; | |
4228 | ||
4229 | ||
4230 | (* | |
4231 | REALLOCATE - attempts to reallocate storage. The address, | |
4232 | a, should either be NIL in which case ALLOCATE | |
4233 | is called, or alternatively it should have already | |
4234 | been initialized by ALLOCATE. The allocated storage | |
4235 | is resized accordingly. | |
4236 | *) | |
4237 | ||
4238 | @findex REALLOCATE | |
4239 | PROCEDURE REALLOCATE (VAR a: ADDRESS; size: CARDINAL) ; | |
4240 | ||
4241 | ||
4242 | (* | |
4243 | Available - returns TRUE if, size, bytes can be allocated. | |
4244 | *) | |
4245 | ||
4246 | @findex Available | |
4247 | PROCEDURE Available (size: CARDINAL) : BOOLEAN; | |
4248 | ||
4249 | ||
4250 | (* | |
4251 | Init - initializes the heap. | |
4252 | This does nothing on a GNU/Linux system. | |
4253 | But it remains here since it might be used in an | |
4254 | embedded system. | |
4255 | *) | |
4256 | ||
4257 | @findex Init | |
4258 | PROCEDURE Init ; | |
4259 | ||
4260 | ||
4261 | END SysStorage. | |
4262 | @end example | |
4263 | @page | |
4264 | ||
4265 | @node gm2-libs/TimeString, gm2-libs/UnixArgs, gm2-libs/SysStorage, Base libraries | |
4266 | @subsection gm2-libs/TimeString | |
4267 | ||
4268 | @example | |
4269 | DEFINITION MODULE TimeString ; | |
4270 | ||
4271 | EXPORT QUALIFIED GetTimeString ; | |
4272 | ||
4273 | ||
4274 | (* | |
4275 | GetTimeString - places the time in ascii format into array, a. | |
4276 | ||
4277 | *) | |
4278 | ||
4279 | @findex GetTimeString | |
4280 | PROCEDURE GetTimeString (VAR a: ARRAY OF CHAR) ; | |
4281 | ||
4282 | ||
4283 | END TimeString. | |
4284 | @end example | |
4285 | @page | |
4286 | ||
4287 | @node gm2-libs/UnixArgs, gm2-libs/cbuiltin, gm2-libs/TimeString, Base libraries | |
4288 | @subsection gm2-libs/UnixArgs | |
4289 | ||
4290 | @example | |
4291 | DEFINITION MODULE UnixArgs ; | |
4292 | ||
4293 | FROM SYSTEM IMPORT ADDRESS ; | |
4294 | ||
4295 | EXPORT QUALIFIED GetArgC, GetArgV, GetEnvV ; | |
4296 | ||
4297 | @findex GetArgC | |
4298 | PROCEDURE GetArgC () : INTEGER ; | |
4299 | @findex GetArgV | |
4300 | PROCEDURE GetArgV () : ADDRESS ; | |
4301 | @findex GetEnvV | |
4302 | PROCEDURE GetEnvV () : ADDRESS ; | |
4303 | ||
4304 | ||
4305 | END UnixArgs. | |
4306 | @end example | |
4307 | @page | |
4308 | ||
4309 | @node gm2-libs/cbuiltin, gm2-libs/cgetopt, gm2-libs/UnixArgs, Base libraries | |
4310 | @subsection gm2-libs/cbuiltin | |
4311 | ||
4312 | @example | |
4313 | DEFINITION MODULE FOR "C" cbuiltin ; | |
4314 | ||
4315 | FROM SYSTEM IMPORT ADDRESS ; | |
4316 | EXPORT UNQUALIFIED alloca, memcpy, | |
4317 | isfinite, isfinitef, isfinitel, | |
4318 | isinf_sign, isinf_signf, isinf_signl, | |
4319 | sinf, sinl, sin, | |
4320 | cosf, cosl, cos, | |
4321 | atan2f, atan2l, atan2, | |
4322 | sqrtf, sqrtl, sqrt, | |
4323 | fabsf, fabsl, fabs, | |
4324 | logf, logl, log, | |
4325 | expf, expl, exp, | |
4326 | log10f, log10l, log10, | |
4327 | exp10f, exp10l, exp10, | |
4328 | ilogbf, ilogbl, ilogb, | |
4329 | significand, significandf, significandl, | |
4330 | modf, modff, modfl, | |
4331 | nextafter, nextafterf, nextafterl, | |
4332 | nexttoward, nexttowardf, nexttowardl, | |
4333 | scalb, scalbf, scalbl, | |
4334 | scalbn, scalbnf, scalbnl, | |
4335 | scalbln, scalblnf, scalblnl, | |
4336 | ||
4337 | cabsf, cabsl, cabs, | |
4338 | cargf, carg, cargl, | |
4339 | conjf, conj, conjl, | |
4340 | cpowf, cpow, cpowl, | |
4341 | csqrtf, csqrt, csqrtl, | |
4342 | cexpf, cexp, cexpl, | |
4343 | clogf, clog, clogl, | |
4344 | csinf, csin, csinl, | |
4345 | ccosf, ccos, ccosl, | |
4346 | ctanf, ctan, ctanl, | |
4347 | casinf, casin, casinl, | |
4348 | cacosf, cacos, cacosl, | |
4349 | catanf, catan, catanl, | |
4350 | ||
4351 | index, rindex, | |
4352 | memcmp, memset, memmove, | |
4353 | strcat, strncat, strcpy, strncpy, strcmp, strncmp, | |
4354 | strlen, strstr, strpbrk, strspn, strcspn, strchr, strrchr ; | |
4355 | ||
4356 | @findex alloca | |
4357 | PROCEDURE alloca (i: CARDINAL) : ADDRESS ; | |
4358 | @findex memcpy | |
4359 | PROCEDURE memcpy (dest, src: ADDRESS; n: CARDINAL) : ADDRESS ; | |
4360 | @findex isfinite | |
4361 | PROCEDURE isfinite (x: REAL) : BOOLEAN ; | |
4362 | @findex isfinitel | |
4363 | PROCEDURE isfinitel (x: LONGREAL) : BOOLEAN ; | |
4364 | @findex isfinitef | |
4365 | PROCEDURE isfinitef (x: SHORTREAL) : BOOLEAN ; | |
4366 | @findex isinf_sign | |
4367 | PROCEDURE isinf_sign (x: REAL) : BOOLEAN ; | |
4368 | @findex isinf_signl | |
4369 | PROCEDURE isinf_signl (x: LONGREAL) : BOOLEAN ; | |
4370 | @findex isinf_signf | |
4371 | PROCEDURE isinf_signf (x: SHORTREAL) : BOOLEAN ; | |
4372 | @findex sinf | |
4373 | PROCEDURE sinf (x: SHORTREAL) : SHORTREAL ; | |
4374 | @findex sin | |
4375 | PROCEDURE sin (x: REAL) : REAL ; | |
4376 | @findex sinl | |
4377 | PROCEDURE sinl (x: LONGREAL) : LONGREAL ; | |
4378 | @findex cosf | |
4379 | PROCEDURE cosf (x: SHORTREAL) : SHORTREAL ; | |
4380 | @findex cos | |
4381 | PROCEDURE cos (x: REAL) : REAL ; | |
4382 | @findex cosl | |
4383 | PROCEDURE cosl (x: LONGREAL) : LONGREAL ; | |
4384 | @findex atan2f | |
4385 | PROCEDURE atan2f (x, y: SHORTREAL) : SHORTREAL ; | |
4386 | @findex atan2 | |
4387 | PROCEDURE atan2 (x, y: REAL) : REAL ; | |
4388 | @findex atan2l | |
4389 | PROCEDURE atan2l (x, y: LONGREAL) : LONGREAL ; | |
4390 | @findex sqrtf | |
4391 | PROCEDURE sqrtf (x: SHORTREAL) : SHORTREAL ; | |
4392 | @findex sqrt | |
4393 | PROCEDURE sqrt (x: REAL) : REAL ; | |
4394 | @findex sqrtl | |
4395 | PROCEDURE sqrtl (x: LONGREAL) : LONGREAL ; | |
4396 | @findex fabsf | |
4397 | PROCEDURE fabsf (x: SHORTREAL) : SHORTREAL ; | |
4398 | @findex fabs | |
4399 | PROCEDURE fabs (x: REAL) : REAL ; | |
4400 | @findex fabsl | |
4401 | PROCEDURE fabsl (x: LONGREAL) : LONGREAL ; | |
4402 | @findex logf | |
4403 | PROCEDURE logf (x: SHORTREAL) : SHORTREAL ; | |
4404 | @findex log | |
4405 | PROCEDURE log (x: REAL) : REAL ; | |
4406 | @findex logl | |
4407 | PROCEDURE logl (x: LONGREAL) : LONGREAL ; | |
4408 | @findex expf | |
4409 | PROCEDURE expf (x: SHORTREAL) : SHORTREAL ; | |
4410 | @findex exp | |
4411 | PROCEDURE exp (x: REAL) : REAL ; | |
4412 | @findex expl | |
4413 | PROCEDURE expl (x: LONGREAL) : LONGREAL ; | |
4414 | @findex log10f | |
4415 | PROCEDURE log10f (x: SHORTREAL) : SHORTREAL ; | |
4416 | @findex log10 | |
4417 | PROCEDURE log10 (x: REAL) : REAL ; | |
4418 | @findex log10l | |
4419 | PROCEDURE log10l (x: LONGREAL) : LONGREAL ; | |
4420 | @findex exp10f | |
4421 | PROCEDURE exp10f (x: SHORTREAL) : SHORTREAL ; | |
4422 | @findex exp10 | |
4423 | PROCEDURE exp10 (x: REAL) : REAL ; | |
4424 | @findex exp10l | |
4425 | PROCEDURE exp10l (x: LONGREAL) : LONGREAL ; | |
4426 | @findex ilogbf | |
4427 | PROCEDURE ilogbf (x: SHORTREAL) : INTEGER ; | |
4428 | @findex ilogb | |
4429 | PROCEDURE ilogb (x: REAL) : INTEGER ; | |
4430 | @findex ilogbl | |
4431 | PROCEDURE ilogbl (x: LONGREAL) : INTEGER ; | |
4432 | ||
4433 | @findex significand | |
4434 | PROCEDURE significand (r: REAL) : REAL ; | |
4435 | @findex significandf | |
4436 | PROCEDURE significandf (s: SHORTREAL) : SHORTREAL ; | |
4437 | @findex significandl | |
4438 | PROCEDURE significandl (l: LONGREAL) : LONGREAL ; | |
4439 | ||
4440 | @findex modf | |
4441 | PROCEDURE modf (x: REAL; VAR y: REAL) : REAL ; | |
4442 | @findex modff | |
4443 | PROCEDURE modff (x: SHORTREAL; VAR y: SHORTREAL) : SHORTREAL ; | |
4444 | @findex modfl | |
4445 | PROCEDURE modfl (x: LONGREAL; VAR y: LONGREAL) : LONGREAL ; | |
4446 | ||
4447 | @findex nextafter | |
4448 | PROCEDURE nextafter (x, y: REAL) : REAL ; | |
4449 | @findex nextafterf | |
4450 | PROCEDURE nextafterf (x, y: SHORTREAL) : SHORTREAL ; | |
4451 | @findex nextafterl | |
4452 | PROCEDURE nextafterl (x, y: LONGREAL) : LONGREAL ; | |
4453 | ||
4454 | @findex nexttoward | |
4455 | PROCEDURE nexttoward (x, y: REAL) : REAL ; | |
4456 | @findex nexttowardf | |
4457 | PROCEDURE nexttowardf (x, y: SHORTREAL) : SHORTREAL ; | |
4458 | @findex nexttowardl | |
4459 | PROCEDURE nexttowardl (x, y: LONGREAL) : LONGREAL ; | |
4460 | ||
4461 | @findex scalb | |
4462 | PROCEDURE scalb (x, n: REAL) : REAL ; | |
4463 | @findex scalbf | |
4464 | PROCEDURE scalbf (x, n: SHORTREAL) : SHORTREAL ; | |
4465 | @findex scalbl | |
4466 | PROCEDURE scalbl (x, n: LONGREAL) : LONGREAL ; | |
4467 | ||
4468 | @findex scalbn | |
4469 | PROCEDURE scalbn (x: REAL; n: INTEGER) : REAL ; | |
4470 | @findex scalbnf | |
4471 | PROCEDURE scalbnf (x: SHORTREAL; n: INTEGER) : SHORTREAL ; | |
4472 | @findex scalbnl | |
4473 | PROCEDURE scalbnl (x: LONGREAL; n: INTEGER) : LONGREAL ; | |
4474 | ||
4475 | @findex scalbln | |
4476 | PROCEDURE scalbln (x: REAL; n: LONGINT) : REAL ; | |
4477 | @findex scalblnf | |
4478 | PROCEDURE scalblnf (x: SHORTREAL; n: LONGINT) : SHORTREAL ; | |
4479 | @findex scalblnl | |
4480 | PROCEDURE scalblnl (x: LONGREAL; n: LONGINT) : LONGREAL ; | |
4481 | ||
4482 | @findex cabsf | |
4483 | PROCEDURE cabsf (z: SHORTCOMPLEX) : SHORTREAL ; | |
4484 | @findex cabs | |
4485 | PROCEDURE cabs (z: COMPLEX) : REAL ; | |
4486 | @findex cabsl | |
4487 | PROCEDURE cabsl (z: LONGCOMPLEX) : LONGREAL ; | |
4488 | ||
4489 | @findex cargf | |
4490 | PROCEDURE cargf (z: SHORTCOMPLEX) : SHORTREAL ; | |
4491 | @findex carg | |
4492 | PROCEDURE carg (z: COMPLEX) : REAL ; | |
4493 | @findex cargl | |
4494 | PROCEDURE cargl (z: LONGCOMPLEX) : LONGREAL ; | |
4495 | ||
4496 | @findex conjf | |
4497 | PROCEDURE conjf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4498 | @findex conj | |
4499 | PROCEDURE conj (z: COMPLEX) : COMPLEX ; | |
4500 | @findex conjl | |
4501 | PROCEDURE conjl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4502 | ||
4503 | @findex cpowf | |
4504 | PROCEDURE cpowf (base: SHORTCOMPLEX; exp: SHORTREAL) : SHORTCOMPLEX ; | |
4505 | @findex cpow | |
4506 | PROCEDURE cpow (base: COMPLEX; exp: REAL) : COMPLEX ; | |
4507 | @findex cpowl | |
4508 | PROCEDURE cpowl (base: LONGCOMPLEX; exp: LONGREAL) : LONGCOMPLEX ; | |
4509 | ||
4510 | @findex csqrtf | |
4511 | PROCEDURE csqrtf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4512 | @findex csqrt | |
4513 | PROCEDURE csqrt (z: COMPLEX) : COMPLEX ; | |
4514 | @findex csqrtl | |
4515 | PROCEDURE csqrtl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4516 | ||
4517 | @findex cexpf | |
4518 | PROCEDURE cexpf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4519 | @findex cexp | |
4520 | PROCEDURE cexp (z: COMPLEX) : COMPLEX ; | |
4521 | @findex cexpl | |
4522 | PROCEDURE cexpl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4523 | ||
4524 | @findex clogf | |
4525 | PROCEDURE clogf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4526 | @findex clog | |
4527 | PROCEDURE clog (z: COMPLEX) : COMPLEX ; | |
4528 | @findex clogl | |
4529 | PROCEDURE clogl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4530 | ||
4531 | @findex csinf | |
4532 | PROCEDURE csinf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4533 | @findex csin | |
4534 | PROCEDURE csin (z: COMPLEX) : COMPLEX ; | |
4535 | @findex csinl | |
4536 | PROCEDURE csinl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4537 | ||
4538 | @findex ccosf | |
4539 | PROCEDURE ccosf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4540 | @findex ccos | |
4541 | PROCEDURE ccos (z: COMPLEX) : COMPLEX ; | |
4542 | @findex ccosl | |
4543 | PROCEDURE ccosl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4544 | ||
4545 | @findex ctanf | |
4546 | PROCEDURE ctanf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4547 | @findex ctan | |
4548 | PROCEDURE ctan (z: COMPLEX) : COMPLEX ; | |
4549 | @findex ctanl | |
4550 | PROCEDURE ctanl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4551 | ||
4552 | @findex casinf | |
4553 | PROCEDURE casinf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4554 | @findex casin | |
4555 | PROCEDURE casin (z: COMPLEX) : COMPLEX ; | |
4556 | @findex casinl | |
4557 | PROCEDURE casinl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4558 | ||
4559 | @findex cacosf | |
4560 | PROCEDURE cacosf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4561 | @findex cacos | |
4562 | PROCEDURE cacos (z: COMPLEX) : COMPLEX ; | |
4563 | @findex cacosl | |
4564 | PROCEDURE cacosl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4565 | ||
4566 | @findex catanf | |
4567 | PROCEDURE catanf (z: SHORTCOMPLEX) : SHORTCOMPLEX ; | |
4568 | @findex catan | |
4569 | PROCEDURE catan (z: COMPLEX) : COMPLEX ; | |
4570 | @findex catanl | |
4571 | PROCEDURE catanl (z: LONGCOMPLEX) : LONGCOMPLEX ; | |
4572 | ||
4573 | @findex index | |
4574 | PROCEDURE index (s: ADDRESS; c: INTEGER) : ADDRESS ; | |
4575 | @findex rindex | |
4576 | PROCEDURE rindex (s: ADDRESS; c: INTEGER) : ADDRESS ; | |
4577 | @findex memcmp | |
4578 | PROCEDURE memcmp (s1, s2: ADDRESS; n: CARDINAL) : INTEGER ; | |
4579 | @findex memmove | |
4580 | PROCEDURE memmove (s1, s2: ADDRESS; n: CARDINAL) : ADDRESS ; | |
4581 | @findex memset | |
4582 | PROCEDURE memset (s: ADDRESS; c: INTEGER; n: CARDINAL) : ADDRESS ; | |
4583 | @findex strcat | |
4584 | PROCEDURE strcat (dest, src: ADDRESS) : ADDRESS ; | |
4585 | @findex strncat | |
4586 | PROCEDURE strncat (dest, src: ADDRESS; n: CARDINAL) : ADDRESS ; | |
4587 | @findex strcpy | |
4588 | PROCEDURE strcpy (dest, src: ADDRESS) : ADDRESS ; | |
4589 | @findex strncpy | |
4590 | PROCEDURE strncpy (dest, src: ADDRESS; n: CARDINAL) : ADDRESS ; | |
4591 | @findex strcmp | |
4592 | PROCEDURE strcmp (s1, s2: ADDRESS) : INTEGER ; | |
4593 | @findex strncmp | |
4594 | PROCEDURE strncmp (s1, s2: ADDRESS; n: CARDINAL) : INTEGER ; | |
4595 | @findex strlen | |
4596 | PROCEDURE strlen (s: ADDRESS) : INTEGER ; | |
4597 | @findex strstr | |
4598 | PROCEDURE strstr (haystack, needle: ADDRESS) : ADDRESS ; | |
4599 | @findex strpbrk | |
4600 | PROCEDURE strpbrk (s, accept: ADDRESS) : ADDRESS ; | |
4601 | @findex strspn | |
4602 | PROCEDURE strspn (s, accept: ADDRESS) : CARDINAL ; | |
4603 | @findex strcspn | |
4604 | PROCEDURE strcspn (s, accept: ADDRESS) : CARDINAL ; | |
4605 | @findex strchr | |
4606 | PROCEDURE strchr (s: ADDRESS; c: INTEGER) : ADDRESS ; | |
4607 | @findex strrchr | |
4608 | PROCEDURE strrchr (s: ADDRESS; c: INTEGER) : ADDRESS ; | |
4609 | ||
4610 | END cbuiltin. | |
4611 | @end example | |
4612 | @page | |
4613 | ||
4614 | @node gm2-libs/cgetopt, gm2-libs/cxxabi, gm2-libs/cbuiltin, Base libraries | |
4615 | @subsection gm2-libs/cgetopt | |
4616 | ||
4617 | @example | |
4618 | DEFINITION MODULE cgetopt ; | |
4619 | ||
4620 | FROM SYSTEM IMPORT ADDRESS ; | |
4621 | ||
4622 | ||
4623 | TYPE | |
4624 | @findex Options (type) | |
4625 | Options = ADDRESS ; | |
4626 | ||
4627 | VAR | |
4628 | @findex optarg (var) | |
4629 | optarg : ADDRESS ; | |
4630 | @findex optind (var) | |
4631 | @findex opterr (var) | |
4632 | @findex optopt (var) | |
4633 | optind, opterr, optopt: INTEGER ; | |
4634 | ||
4635 | ||
4636 | (* | |
4637 | getopt - the getopt() function parses the command-line arguments. | |
4638 | Its arguments argc and argv are the argument count and array as | |
4639 | passed to the main() function on program invocation. An element of | |
4640 | argv that starts with '-' (and is not exactly "-" or "--") is an | |
4641 | option element. The characters of this element (aside from the | |
4642 | initial '-') are option characters. If getopt() is called | |
4643 | repeatedly, it returns successively each of the option characters | |
4644 | from each of the option elements. | |
4645 | *) | |
4646 | ||
4647 | @findex getopt | |
4648 | PROCEDURE getopt (argc: INTEGER; argv: ADDRESS; optstring: ADDRESS) : CHAR ; | |
4649 | ||
4650 | ||
4651 | (* | |
4652 | getopt_long - works like getopt() except that it also accepts long options, | |
4653 | started with two dashes. (If the program accepts only long | |
4654 | options, then optstring should be specified as an empty string (""), | |
4655 | not NULL.) Long option names may be abbreviated if the abbreviation | |
4656 | is unique or is an exact match for some defined option. A | |
4657 | long option may take a parameter, of the form --arg=param or | |
4658 | --arg param. | |
4659 | *) | |
4660 | ||
4661 | @findex getopt_long | |
4662 | PROCEDURE getopt_long (argc: INTEGER; argv: ADDRESS; optstring: ADDRESS; | |
4663 | longopts: ADDRESS; VAR longindex: INTEGER) : INTEGER ; | |
4664 | ||
4665 | ||
4666 | (* | |
4667 | getopt_long_only - a wrapper for the C getopt_long_only. | |
4668 | *) | |
4669 | ||
4670 | @findex getopt_long_only | |
4671 | PROCEDURE getopt_long_only (argc: INTEGER; argv: ADDRESS; optstring: ADDRESS; | |
4672 | longopts: ADDRESS; VAR longindex: INTEGER) : INTEGER ; | |
4673 | ||
4674 | ||
4675 | (* | |
4676 | InitOptions - constructor for empty Options. | |
4677 | *) | |
4678 | ||
4679 | @findex InitOptions | |
4680 | PROCEDURE InitOptions () : Options ; | |
4681 | ||
4682 | ||
4683 | (* | |
4684 | KillOptions - deconstructor for empty Options. | |
4685 | *) | |
4686 | ||
4687 | @findex KillOptions | |
4688 | PROCEDURE KillOptions (o: Options) : Options ; | |
4689 | ||
4690 | ||
4691 | (* | |
4692 | SetOption - set option[index] with @{name, has_arg, flag, val@}. | |
4693 | *) | |
4694 | ||
4695 | @findex SetOption | |
4696 | PROCEDURE SetOption (o: Options; index: CARDINAL; | |
4697 | name: ADDRESS; has_arg: BOOLEAN; | |
4698 | VAR flag: INTEGER; val: INTEGER) ; | |
4699 | ||
4700 | ||
4701 | (* | |
4702 | GetLongOptionArray - return a pointer to the C array containing all | |
4703 | long options. | |
4704 | *) | |
4705 | ||
4706 | @findex GetLongOptionArray | |
4707 | PROCEDURE GetLongOptionArray (o: Options) : ADDRESS ; | |
4708 | ||
4709 | ||
4710 | END cgetopt. | |
4711 | @end example | |
4712 | @page | |
4713 | ||
4714 | @node gm2-libs/cxxabi, gm2-libs/dtoa, gm2-libs/cgetopt, Base libraries | |
4715 | @subsection gm2-libs/cxxabi | |
4716 | ||
4717 | @example | |
4718 | DEFINITION MODULE FOR "C" cxxabi ; | |
4719 | ||
4720 | (* This should only be used by the compiler and it matches the | |
4721 | g++ implementation. *) | |
4722 | ||
4723 | FROM SYSTEM IMPORT ADDRESS ; | |
4724 | EXPORT UNQUALIFIED __cxa_begin_catch, __cxa_end_catch, __cxa_rethrow ; | |
4725 | ||
4726 | ||
4727 | @findex __cxa_begin_catch | |
4728 | PROCEDURE __cxa_begin_catch (a: ADDRESS) : ADDRESS ; | |
4729 | @findex __cxa_end_catch | |
4730 | PROCEDURE __cxa_end_catch ; | |
4731 | @findex __cxa_rethrow | |
4732 | PROCEDURE __cxa_rethrow ; | |
4733 | ||
4734 | ||
4735 | END cxxabi. | |
4736 | @end example | |
4737 | @page | |
4738 | ||
4739 | @node gm2-libs/dtoa, gm2-libs/errno, gm2-libs/cxxabi, Base libraries | |
4740 | @subsection gm2-libs/dtoa | |
4741 | ||
4742 | @example | |
4743 | DEFINITION MODULE dtoa ; | |
4744 | ||
4745 | FROM SYSTEM IMPORT ADDRESS ; | |
4746 | ||
4747 | TYPE | |
4748 | @findex Mode (type) | |
4749 | Mode = (maxsignificant, decimaldigits) ; | |
4750 | ||
4751 | ||
4752 | (* | |
4753 | strtod - returns a REAL given a string, s. It will set | |
4754 | error to TRUE if the number is too large. | |
4755 | *) | |
4756 | ||
4757 | @findex strtod | |
4758 | PROCEDURE strtod (s: ADDRESS; VAR error: BOOLEAN) : REAL ; | |
4759 | ||
4760 | ||
4761 | (* | |
4762 | dtoa - converts a REAL, d, into a string. The address of the | |
4763 | string is returned. | |
4764 | mode indicates the type of conversion required. | |
4765 | ndigits determines the number of digits according to mode. | |
4766 | decpt the position of the decimal point. | |
4767 | sign does the string have a sign? | |
4768 | *) | |
4769 | ||
4770 | @findex dtoa | |
4771 | PROCEDURE dtoa (d : REAL; | |
4772 | mode : Mode; | |
4773 | ndigits : INTEGER; | |
4774 | VAR decpt: INTEGER; | |
4775 | VAR sign : BOOLEAN) : ADDRESS ; | |
4776 | ||
4777 | ||
4778 | END dtoa. | |
4779 | @end example | |
4780 | @page | |
4781 | ||
4782 | @node gm2-libs/errno, gm2-libs/gdbif, gm2-libs/dtoa, Base libraries | |
4783 | @subsection gm2-libs/errno | |
4784 | ||
4785 | @example | |
4786 | DEFINITION MODULE errno ; | |
4787 | ||
4788 | CONST | |
4789 | EINTR = 4 ; (* system call interrupted *) | |
4790 | ERANGE = 34 ; (* result is too large *) | |
4791 | EAGAIN = 11 ; (* retry the system call *) | |
4792 | ||
4793 | @findex geterrno | |
4794 | PROCEDURE geterrno () : INTEGER ; | |
4795 | ||
4796 | ||
4797 | END errno. | |
4798 | @end example | |
4799 | @page | |
4800 | ||
4801 | @node gm2-libs/gdbif, gm2-libs/ldtoa, gm2-libs/errno, Base libraries | |
4802 | @subsection gm2-libs/gdbif | |
4803 | ||
4804 | @example | |
4805 | DEFINITION MODULE gdbif ; | |
4806 | ||
4807 | (* Provides interactive connectivity with gdb useful for debugging | |
4808 | Modula-2 shared libraries. *) | |
4809 | ||
4810 | EXPORT UNQUALIFIED sleepSpin, finishSpin, connectSpin ; | |
4811 | ||
4812 | ||
4813 | (* | |
4814 | finishSpin - sets boolean mustWait to FALSE. | |
4815 | *) | |
4816 | ||
4817 | @findex finishSpin | |
4818 | PROCEDURE finishSpin ; | |
4819 | ||
4820 | ||
4821 | (* | |
4822 | sleepSpin - waits for the boolean variable mustWait to become FALSE. | |
4823 | It sleeps for a second between each test of the variable. | |
4824 | *) | |
4825 | ||
4826 | @findex sleepSpin | |
4827 | PROCEDURE sleepSpin ; | |
4828 | ||
4829 | ||
4830 | (* | |
4831 | connectSpin - breakpoint placeholder. Its only purpose is to allow users | |
4832 | to set a breakpoint. This procedure is called once | |
4833 | sleepSpin is released from its spin (via a call from | |
4834 | finishSpin). | |
4835 | *) | |
4836 | ||
4837 | @findex connectSpin | |
4838 | PROCEDURE connectSpin ; | |
4839 | ||
4840 | ||
4841 | END gdbif. | |
4842 | @end example | |
4843 | @page | |
4844 | ||
4845 | @node gm2-libs/ldtoa, gm2-libs/libc, gm2-libs/gdbif, Base libraries | |
4846 | @subsection gm2-libs/ldtoa | |
4847 | ||
4848 | @example | |
4849 | DEFINITION MODULE ldtoa ; | |
4850 | ||
4851 | FROM SYSTEM IMPORT ADDRESS ; | |
4852 | ||
4853 | TYPE | |
4854 | @findex Mode (type) | |
4855 | Mode = (maxsignificant, decimaldigits) ; | |
4856 | ||
4857 | ||
4858 | (* | |
4859 | strtold - returns a LONGREAL given a C string, s. It will set | |
4860 | error to TRUE if the number is too large or badly formed. | |
4861 | *) | |
4862 | ||
4863 | @findex strtold | |
4864 | PROCEDURE strtold (s: ADDRESS; VAR error: BOOLEAN) : LONGREAL ; | |
4865 | ||
4866 | ||
4867 | (* | |
4868 | ldtoa - converts a LONGREAL, d, into a string. The address of the | |
4869 | string is returned. | |
4870 | mode indicates the type of conversion required. | |
4871 | ndigits determines the number of digits according to mode. | |
4872 | decpt the position of the decimal point. | |
4873 | sign does the string have a sign? | |
4874 | *) | |
4875 | ||
4876 | @findex ldtoa | |
4877 | PROCEDURE ldtoa (d : LONGREAL; | |
4878 | mode : Mode; | |
4879 | ndigits : INTEGER; | |
4880 | VAR decpt: INTEGER; | |
4881 | VAR sign : BOOLEAN) : ADDRESS ; | |
4882 | ||
4883 | ||
4884 | END ldtoa. | |
4885 | @end example | |
4886 | @page | |
4887 | ||
4888 | @node gm2-libs/libc, gm2-libs/libm, gm2-libs/ldtoa, Base libraries | |
4889 | @subsection gm2-libs/libc | |
4890 | ||
4891 | @example | |
4892 | DEFINITION MODULE FOR "C" libc ; | |
4893 | ||
4894 | FROM SYSTEM IMPORT ADDRESS, CSIZE_T, CSSIZE_T ; | |
4895 | ||
4896 | EXPORT UNQUALIFIED time_t, timeb, tm, ptrToTM, | |
4897 | write, read, | |
4898 | system, abort, | |
4899 | malloc, free, | |
4900 | exit, isatty, | |
4901 | getenv, putenv, getpid, | |
4902 | dup, close, open, lseek, | |
4903 | readv, writev, | |
4904 | perror, creat, | |
4905 | getcwd, chown, strlen, strcpy, strncpy, | |
4906 | unlink, setenv, | |
4907 | memcpy, memset, memmove, printf, realloc, | |
4908 | rand, srand, | |
4909 | time, localtime, ftime, | |
4910 | shutdown, rename, setjmp, longjmp, atexit, | |
4911 | ttyname, sleep, execv ; | |
4912 | ||
4913 | ||
4914 | TYPE | |
4915 | @findex time_t (type) | |
4916 | time_t = LONGINT ; | |
4917 | ||
4918 | @findex ptrToTM (type) | |
4919 | ptrToTM = POINTER TO tm ; | |
4920 | @findex tm (type) | |
4921 | tm = RECORD | |
4922 | tm_sec: INTEGER ; (* Seconds. [0-60] (1 leap second) *) | |
4923 | tm_min: INTEGER ; (* Minutes. [0-59] *) | |
4924 | tm_hour: INTEGER ; (* Hours. [0-23] *) | |
4925 | tm_mday: INTEGER ; (* Day. [1-31] *) | |
4926 | tm_mon: INTEGER ; (* Month. [0-11] *) | |
4927 | tm_year: INTEGER ; (* Year - 1900. *) | |
4928 | tm_wday: INTEGER ; (* Day of week. [0-6] *) | |
4929 | tm_yday: INTEGER ; (* Days in year.[0-365] *) | |
4930 | tm_isdst: INTEGER ; (* DST. [-1/0/1] *) | |
4931 | tm_gmtoff: LONGINT ; (* Seconds east of UTC. *) | |
4932 | tm_zone: ADDRESS ; (* char * zone name *) | |
4933 | @findex END (type) | |
4934 | END ; | |
4935 | ||
4936 | @findex timeb (type) | |
4937 | timeb = RECORD | |
4938 | time : time_t ; | |
4939 | millitm : SHORTCARD ; | |
4940 | timezone: SHORTCARD ; | |
4941 | dstflag : SHORTCARD ; | |
4942 | @findex END (type) | |
4943 | END ; | |
4944 | ||
4945 | @findex exitP (type) | |
4946 | exitP = PROCEDURE () : INTEGER ; | |
4947 | ||
4948 | ||
4949 | (* | |
4950 | ssize_t write (int d, void *buf, size_t nbytes) | |
4951 | *) | |
4952 | ||
4953 | @findex write | |
4954 | PROCEDURE write (d: INTEGER; buf: ADDRESS; nbytes: CSIZE_T) : [ CSSIZE_T ] ; | |
4955 | ||
4956 | ||
4957 | (* | |
4958 | ssize_t read (int d, void *buf, size_t nbytes) | |
4959 | *) | |
4960 | ||
4961 | @findex read | |
4962 | PROCEDURE read (d: INTEGER; buf: ADDRESS; nbytes: CSIZE_T) : [ CSSIZE_T ] ; | |
4963 | ||
4964 | ||
4965 | (* | |
4966 | int system(string) | |
4967 | char *string; | |
4968 | *) | |
4969 | ||
4970 | @findex system | |
4971 | PROCEDURE system (a: ADDRESS) : [ INTEGER ] ; | |
4972 | ||
4973 | ||
4974 | (* | |
4975 | abort - generate a fault | |
4976 | ||
4977 | abort() first closes all open files if possible, then sends | |
4978 | an IOT signal to the process. This signal usually results | |
4979 | in termination with a core dump, which may be used for | |
4980 | debugging. | |
4981 | ||
4982 | It is possible for abort() to return control if is caught or | |
4983 | ignored, in which case the value returned is that of the | |
4984 | kill(2V) system call. | |
4985 | *) | |
4986 | ||
4987 | @findex abort | |
4988 | PROCEDURE abort <* noreturn *> ; | |
4989 | ||
4990 | ||
4991 | (* | |
4992 | malloc - memory allocator. | |
4993 | ||
4994 | void *malloc(size_t size); | |
4995 | ||
4996 | malloc() returns a pointer to a block of at least size | |
4997 | bytes, which is appropriately aligned. If size is zero, | |
4998 | malloc() returns a non-NULL pointer, but this pointer should | |
4999 | not be dereferenced. | |
5000 | *) | |
5001 | ||
5002 | @findex malloc | |
5003 | PROCEDURE malloc (size: CSIZE_T) : ADDRESS ; | |
5004 | ||
5005 | ||
5006 | (* | |
5007 | free - memory deallocator. | |
5008 | ||
5009 | free (void *ptr); | |
5010 | ||
5011 | free() releases a previously allocated block. Its argument | |
5012 | is a pointer to a block previously allocated by malloc, | |
5013 | calloc, realloc, malloc, or memalign. | |
5014 | *) | |
5015 | ||
5016 | @findex free | |
5017 | PROCEDURE free (ptr: ADDRESS) ; | |
5018 | ||
5019 | ||
5020 | (* | |
5021 | void *realloc (void *ptr, size_t size); | |
5022 | ||
5023 | realloc changes the size of the memory block pointed to | |
5024 | by ptr to size bytes. The contents will be unchanged to | |
5025 | the minimum of the old and new sizes; newly allocated memory | |
5026 | will be uninitialized. If ptr is NIL, the call is | |
5027 | equivalent to malloc(size); if size is equal to zero, the | |
5028 | call is equivalent to free(ptr). Unless ptr is NIL, it | |
5029 | must have been returned by an earlier call to malloc(), | |
5030 | realloc. | |
5031 | *) | |
5032 | ||
5033 | @findex realloc | |
5034 | PROCEDURE realloc (ptr: ADDRESS; size: CSIZE_T) : ADDRESS ; | |
5035 | ||
5036 | ||
5037 | (* | |
5038 | isatty - does this descriptor refer to a terminal. | |
5039 | *) | |
5040 | ||
5041 | @findex isatty | |
5042 | PROCEDURE isatty (fd: INTEGER) : INTEGER ; | |
5043 | ||
5044 | ||
5045 | (* | |
5046 | exit - returns control to the invoking process. Result, r, is | |
5047 | returned. | |
5048 | *) | |
5049 | ||
5050 | @findex exit | |
5051 | PROCEDURE exit (r: INTEGER) <* noreturn *> ; | |
5052 | ||
5053 | ||
5054 | (* | |
5055 | getenv - returns the C string for the equivalent C environment | |
5056 | variable. | |
5057 | *) | |
5058 | ||
5059 | @findex getenv | |
5060 | PROCEDURE getenv (s: ADDRESS) : ADDRESS ; | |
5061 | ||
5062 | ||
5063 | (* | |
5064 | putenv - change or add an environment variable. | |
5065 | *) | |
5066 | ||
5067 | @findex putenv | |
5068 | PROCEDURE putenv (s: ADDRESS) : INTEGER ; | |
5069 | ||
5070 | ||
5071 | (* | |
5072 | getpid - returns the UNIX process identification number. | |
5073 | *) | |
5074 | ||
5075 | @findex getpid | |
5076 | PROCEDURE getpid () : INTEGER ; | |
5077 | ||
5078 | ||
5079 | (* | |
5080 | dup - duplicates the file descriptor, d. | |
5081 | *) | |
5082 | ||
5083 | @findex dup | |
5084 | PROCEDURE dup (d: INTEGER) : INTEGER ; | |
5085 | ||
5086 | ||
5087 | (* | |
5088 | close - closes the file descriptor, d. | |
5089 | *) | |
5090 | ||
5091 | @findex close | |
5092 | PROCEDURE close (d: INTEGER) : [ INTEGER ] ; | |
5093 | ||
5094 | ||
5095 | (* | |
5096 | open - open the file, filename with flag and mode. | |
5097 | *) | |
5098 | ||
5099 | @findex open | |
5100 | PROCEDURE open (filename: ADDRESS; oflag: INTEGER; ...) : INTEGER ; | |
5101 | ||
5102 | ||
5103 | (* | |
5104 | creat - creates a new file | |
5105 | *) | |
5106 | ||
5107 | @findex creat | |
5108 | PROCEDURE creat (filename: ADDRESS; mode: CARDINAL) : INTEGER; | |
5109 | ||
5110 | ||
5111 | (* | |
5112 | lseek - calls unix lseek: | |
5113 | ||
5114 | off_t lseek(int fildes, off_t offset, int whence); | |
5115 | *) | |
5116 | ||
5117 | @findex lseek | |
5118 | PROCEDURE lseek (fd: INTEGER; offset: LONGINT; whence: INTEGER) : LONGINT ; | |
5119 | ||
5120 | ||
5121 | (* | |
5122 | perror - writes errno and string. (ARRAY OF CHAR is translated onto ADDRESS). | |
5123 | *) | |
5124 | ||
5125 | @findex perror | |
5126 | PROCEDURE perror (string: ARRAY OF CHAR); | |
5127 | ||
5128 | ||
5129 | (* | |
5130 | readv - reads an io vector of bytes. | |
5131 | *) | |
5132 | ||
5133 | @findex readv | |
5134 | PROCEDURE readv (fd: INTEGER; v: ADDRESS; n: INTEGER) : [ INTEGER ] ; | |
5135 | ||
5136 | ||
5137 | (* | |
5138 | writev - writes an io vector of bytes. | |
5139 | *) | |
5140 | ||
5141 | @findex writev | |
5142 | PROCEDURE writev (fd: INTEGER; v: ADDRESS; n: INTEGER) : [ INTEGER ] ; | |
5143 | ||
5144 | ||
5145 | (* | |
5146 | getcwd - copies the absolute pathname of the | |
5147 | current working directory to the array pointed to by buf, | |
5148 | which is of length size. | |
5149 | ||
5150 | If the current absolute path name would require a buffer | |
5151 | longer than size elements, NULL is returned, and errno is | |
5152 | set to ERANGE; an application should check for this error, | |
5153 | and allocate a larger buffer if necessary. | |
5154 | *) | |
5155 | ||
5156 | @findex getcwd | |
5157 | PROCEDURE getcwd (buf: ADDRESS; size: CSIZE_T) : ADDRESS ; | |
5158 | ||
5159 | ||
5160 | (* | |
5161 | chown - The owner of the file specified by path or by fd is | |
5162 | changed. Only the super-user may change the owner of a | |
5163 | file. The owner of a file may change the group of the | |
5164 | file to any group of which that owner is a member. The | |
5165 | super-user may change the group arbitrarily. | |
5166 | ||
5167 | If the owner or group is specified as -1, then that ID is | |
5168 | not changed. | |
5169 | ||
5170 | On success, zero is returned. On error, -1 is returned, | |
5171 | and errno is set appropriately. | |
5172 | *) | |
5173 | ||
5174 | @findex chown | |
5175 | PROCEDURE chown (filename: ADDRESS; uid, gid: INTEGER) : [ INTEGER ] ; | |
5176 | ||
5177 | ||
5178 | (* | |
5179 | strlen - returns the length of string, a. | |
5180 | *) | |
5181 | ||
5182 | @findex strlen | |
5183 | PROCEDURE strlen (a: ADDRESS) : CSIZE_T ; | |
5184 | ||
5185 | ||
5186 | (* | |
5187 | strcpy - copies string, src, into, dest. | |
5188 | It returns dest. | |
5189 | *) | |
5190 | ||
5191 | @findex strcpy | |
5192 | PROCEDURE strcpy (dest, src: ADDRESS) : [ ADDRESS ] ; | |
5193 | ||
5194 | ||
5195 | (* | |
5196 | strncpy - copies string, src, into, dest, copying at most, n, bytes. | |
5197 | It returns dest. | |
5198 | *) | |
5199 | ||
5200 | @findex strncpy | |
5201 | PROCEDURE strncpy (dest, src: ADDRESS; n: CARDINAL) : [ ADDRESS ] ; | |
5202 | ||
5203 | ||
5204 | (* | |
5205 | unlink - removes file and returns 0 if successful. | |
5206 | *) | |
5207 | ||
5208 | @findex unlink | |
5209 | PROCEDURE unlink (file: ADDRESS) : [ INTEGER ] ; | |
5210 | ||
5211 | ||
5212 | (* | |
5213 | memcpy - copy memory area | |
5214 | ||
5215 | SYNOPSIS | |
5216 | ||
5217 | #include <string.h> | |
5218 | ||
5219 | void *memcpy(void *dest, const void *src, size_t n); | |
5220 | It returns dest. | |
5221 | *) | |
5222 | ||
5223 | @findex memcpy | |
5224 | PROCEDURE memcpy (dest, src: ADDRESS; size: CSIZE_T) : [ ADDRESS ] ; | |
5225 | ||
5226 | ||
5227 | (* | |
5228 | memset - fill memory with a constant byte | |
5229 | ||
5230 | SYNOPSIS | |
5231 | ||
5232 | #include <string.h> | |
5233 | ||
5234 | void *memset(void *s, int c, size_t n); | |
5235 | It returns s. | |
5236 | *) | |
5237 | ||
5238 | @findex memset | |
5239 | PROCEDURE memset (s: ADDRESS; c: INTEGER; size: CSIZE_T) : [ ADDRESS ] ; | |
5240 | ||
5241 | ||
5242 | (* | |
5243 | memmove - copy memory areas which may overlap | |
5244 | ||
5245 | SYNOPSIS | |
5246 | ||
5247 | #include <string.h> | |
5248 | ||
5249 | void *memmove(void *dest, const void *src, size_t n); | |
5250 | It returns dest. | |
5251 | *) | |
5252 | ||
5253 | @findex memmove | |
5254 | PROCEDURE memmove (dest, src: ADDRESS; size: CSIZE_T) : [ ADDRESS ] ; | |
5255 | ||
5256 | ||
5257 | (* | |
5258 | int printf(const char *format, ...); | |
5259 | *) | |
5260 | ||
5261 | @findex printf | |
5262 | PROCEDURE printf (format: ARRAY OF CHAR; ...) : [ INTEGER ] ; | |
5263 | ||
5264 | ||
5265 | (* | |
5266 | setenv - sets environment variable, name, to value. | |
5267 | It will overwrite an existing value if, overwrite, | |
5268 | is true. It returns 0 on success and -1 for an error. | |
5269 | *) | |
5270 | ||
5271 | @findex setenv | |
5272 | PROCEDURE setenv (name: ADDRESS; value: ADDRESS; overwrite: INTEGER) : [ INTEGER ] ; | |
5273 | ||
5274 | ||
5275 | (* | |
5276 | srand - initialize the random number seed. | |
5277 | *) | |
5278 | ||
5279 | @findex srand | |
5280 | PROCEDURE srand (seed: INTEGER) ; | |
5281 | ||
5282 | ||
5283 | (* | |
5284 | rand - return a random integer. | |
5285 | *) | |
5286 | ||
5287 | @findex rand | |
5288 | PROCEDURE rand () : INTEGER ; | |
5289 | ||
5290 | ||
5291 | (* | |
5292 | time - returns a pointer to the time_t value. If, a, | |
5293 | is not NIL then the libc value is copied into | |
5294 | memory at address, a. | |
5295 | *) | |
5296 | ||
5297 | @findex time | |
5298 | PROCEDURE time (a: ADDRESS) : time_t ; | |
5299 | ||
5300 | ||
5301 | (* | |
5302 | localtime - returns a pointer to the libc copy of the tm | |
5303 | structure. | |
5304 | *) | |
5305 | ||
5306 | @findex localtime | |
5307 | PROCEDURE localtime (VAR t: time_t) : ADDRESS ; | |
5308 | ||
5309 | ||
5310 | (* | |
5311 | ftime - return date and time. | |
5312 | *) | |
5313 | ||
5314 | @findex ftime | |
5315 | PROCEDURE ftime (VAR t: timeb) : [ INTEGER ] ; | |
5316 | ||
5317 | ||
5318 | (* | |
5319 | shutdown - shutdown a socket, s. | |
5320 | if how = 0, then no more reads are allowed. | |
5321 | if how = 1, then no more writes are allowed. | |
5322 | if how = 2, then mo more reads or writes are allowed. | |
5323 | *) | |
5324 | ||
5325 | @findex shutdown | |
5326 | PROCEDURE shutdown (s: INTEGER; how: INTEGER) : [ INTEGER ] ; | |
5327 | ||
5328 | ||
5329 | (* | |
5330 | rename - change the name or location of a file | |
5331 | *) | |
5332 | ||
5333 | @findex rename | |
5334 | PROCEDURE rename (oldpath, newpath: ADDRESS) : [ INTEGER ] ; | |
5335 | ||
5336 | ||
5337 | (* | |
5338 | setjmp - returns 0 if returning directly, and non-zero | |
5339 | when returning from longjmp using the saved | |
5340 | context. | |
5341 | *) | |
5342 | ||
5343 | @findex setjmp | |
5344 | PROCEDURE setjmp (env: ADDRESS) : INTEGER ; | |
5345 | ||
5346 | ||
5347 | (* | |
5348 | longjmp - restores the environment saved by the last call | |
5349 | of setjmp with the corresponding env argument. | |
5350 | After longjmp is completed, program execution | |
5351 | continues as if the corresponding call of setjmp | |
5352 | had just returned the value val. The value of | |
5353 | val must not be zero. | |
5354 | *) | |
5355 | ||
5356 | @findex longjmp | |
5357 | PROCEDURE longjmp (env: ADDRESS; val: INTEGER) ; | |
5358 | ||
5359 | ||
5360 | (* | |
5361 | atexit - execute, proc, when the function exit is called. | |
5362 | *) | |
5363 | ||
5364 | @findex atexit | |
5365 | PROCEDURE atexit (proc: exitP) : [ INTEGER ] ; | |
5366 | ||
5367 | ||
5368 | (* | |
5369 | ttyname - returns a pointer to a string determining the ttyname. | |
5370 | *) | |
5371 | ||
5372 | @findex ttyname | |
5373 | PROCEDURE ttyname (filedes: INTEGER) : ADDRESS ; | |
5374 | ||
5375 | ||
5376 | (* | |
5377 | sleep - calling thread sleeps for seconds. | |
5378 | *) | |
5379 | ||
5380 | @findex sleep | |
5381 | PROCEDURE sleep (seconds: CARDINAL) : [ CARDINAL ] ; | |
5382 | ||
5383 | ||
5384 | (* | |
5385 | execv - execute a file. | |
5386 | *) | |
5387 | ||
5388 | @findex execv | |
5389 | PROCEDURE execv (pathname: ADDRESS; argv: ADDRESS) : [ INTEGER ] ; | |
5390 | ||
5391 | ||
5392 | END libc. | |
5393 | @end example | |
5394 | @page | |
5395 | ||
5396 | @node gm2-libs/libm, gm2-libs/sckt, gm2-libs/libc, Base libraries | |
5397 | @subsection gm2-libs/libm | |
5398 | ||
5399 | @example | |
5400 | DEFINITION MODULE FOR "C" libm ; | |
5401 | ||
5402 | (* Users are strongly advised to use MathLib0 or RealMath as calls | |
5403 | to functions within these modules will generate inline code. | |
5404 | This module is used by MathLib0 and RealMath when inline code cannot | |
5405 | be generated. *) | |
5406 | ||
5407 | EXPORT UNQUALIFIED sin, sinl, sinf, | |
5408 | cos, cosl, cosf, | |
5409 | tan, tanl, tanf, | |
5410 | sqrt, sqrtl, sqrtf, | |
5411 | asin, asinl, asinf, | |
5412 | acos, acosl, acosf, | |
5413 | atan, atanl, atanf, | |
5414 | atan2, atan2l, atan2f, | |
5415 | exp, expl, expf, | |
5416 | log, logl, logf, | |
5417 | exp10, exp10l, exp10f, | |
5418 | pow, powl, powf, | |
5419 | floor, floorl, floorf, | |
5420 | ceil, ceill, ceilf ; | |
5421 | ||
5422 | @findex sin | |
5423 | PROCEDURE sin (x: REAL) : REAL ; | |
5424 | @findex sinl | |
5425 | PROCEDURE sinl (x: LONGREAL) : LONGREAL ; | |
5426 | @findex sinf | |
5427 | PROCEDURE sinf (x: SHORTREAL) : SHORTREAL ; | |
5428 | @findex cos | |
5429 | PROCEDURE cos (x: REAL) : REAL ; | |
5430 | @findex cosl | |
5431 | PROCEDURE cosl (x: LONGREAL) : LONGREAL ; | |
5432 | @findex cosf | |
5433 | PROCEDURE cosf (x: SHORTREAL) : SHORTREAL ; | |
5434 | @findex tan | |
5435 | PROCEDURE tan (x: REAL) : REAL ; | |
5436 | @findex tanl | |
5437 | PROCEDURE tanl (x: LONGREAL) : LONGREAL ; | |
5438 | @findex tanf | |
5439 | PROCEDURE tanf (x: SHORTREAL) : SHORTREAL ; | |
5440 | @findex sqrt | |
5441 | PROCEDURE sqrt (x: REAL) : REAL ; | |
5442 | @findex sqrtl | |
5443 | PROCEDURE sqrtl (x: LONGREAL) : LONGREAL ; | |
5444 | @findex sqrtf | |
5445 | PROCEDURE sqrtf (x: SHORTREAL) : SHORTREAL ; | |
5446 | @findex asin | |
5447 | PROCEDURE asin (x: REAL) : REAL ; | |
5448 | @findex asinl | |
5449 | PROCEDURE asinl (x: LONGREAL) : LONGREAL ; | |
5450 | @findex asinf | |
5451 | PROCEDURE asinf (x: SHORTREAL) : SHORTREAL ; | |
5452 | @findex acos | |
5453 | PROCEDURE acos (x: REAL) : REAL ; | |
5454 | @findex acosl | |
5455 | PROCEDURE acosl (x: LONGREAL) : LONGREAL ; | |
5456 | @findex acosf | |
5457 | PROCEDURE acosf (x: SHORTREAL) : SHORTREAL ; | |
5458 | @findex atan | |
5459 | PROCEDURE atan (x: REAL) : REAL ; | |
5460 | @findex atanl | |
5461 | PROCEDURE atanl (x: LONGREAL) : LONGREAL ; | |
5462 | @findex atanf | |
5463 | PROCEDURE atanf (x: SHORTREAL) : SHORTREAL ; | |
5464 | @findex atan2 | |
5465 | PROCEDURE atan2 (x, y: REAL) : REAL ; | |
5466 | @findex atan2l | |
5467 | PROCEDURE atan2l (x, y: LONGREAL) : LONGREAL ; | |
5468 | @findex atan2f | |
5469 | PROCEDURE atan2f (x, y: SHORTREAL) : SHORTREAL ; | |
5470 | @findex exp | |
5471 | PROCEDURE exp (x: REAL) : REAL ; | |
5472 | @findex expl | |
5473 | PROCEDURE expl (x: LONGREAL) : LONGREAL ; | |
5474 | @findex expf | |
5475 | PROCEDURE expf (x: SHORTREAL) : SHORTREAL ; | |
5476 | @findex log | |
5477 | PROCEDURE log (x: REAL) : REAL ; | |
5478 | @findex logl | |
5479 | PROCEDURE logl (x: LONGREAL) : LONGREAL ; | |
5480 | @findex logf | |
5481 | PROCEDURE logf (x: SHORTREAL) : SHORTREAL ; | |
5482 | @findex exp10 | |
5483 | PROCEDURE exp10 (x: REAL) : REAL ; | |
5484 | @findex exp10l | |
5485 | PROCEDURE exp10l (x: LONGREAL) : LONGREAL ; | |
5486 | @findex exp10f | |
5487 | PROCEDURE exp10f (x: SHORTREAL) : SHORTREAL ; | |
5488 | @findex pow | |
5489 | PROCEDURE pow (x, y: REAL) : REAL ; | |
5490 | @findex powl | |
5491 | PROCEDURE powl (x, y: LONGREAL) : LONGREAL ; | |
5492 | @findex powf | |
5493 | PROCEDURE powf (x, y: SHORTREAL) : SHORTREAL ; | |
5494 | @findex floor | |
5495 | PROCEDURE floor (x: REAL) : REAL ; | |
5496 | @findex floorl | |
5497 | PROCEDURE floorl (x: LONGREAL) : LONGREAL ; | |
5498 | @findex floorf | |
5499 | PROCEDURE floorf (x: SHORTREAL) : SHORTREAL ; | |
5500 | @findex ceil | |
5501 | PROCEDURE ceil (x: REAL) : REAL ; | |
5502 | @findex ceill | |
5503 | PROCEDURE ceill (x: LONGREAL) : LONGREAL ; | |
5504 | @findex ceilf | |
5505 | PROCEDURE ceilf (x: SHORTREAL) : SHORTREAL ; | |
5506 | ||
5507 | END libm. | |
5508 | @end example | |
5509 | @page | |
5510 | ||
5511 | @node gm2-libs/sckt, gm2-libs/termios, gm2-libs/libm, Base libraries | |
5512 | @subsection gm2-libs/sckt | |
5513 | ||
5514 | @example | |
5515 | DEFINITION MODULE sckt ; | |
5516 | ||
5517 | FROM SYSTEM IMPORT ADDRESS ; | |
5518 | EXPORT UNQUALIFIED tcpServerState, | |
5519 | tcpServerEstablish, tcpServerEstablishPort, | |
5520 | tcpServerAccept, getLocalIP, | |
5521 | tcpServerPortNo, tcpServerIP, tcpServerSocketFd, | |
5522 | tcpServerClientIP, tcpServerClientPortNo, | |
5523 | tcpClientState, | |
5524 | tcpClientSocket, tcpClientSocketIP, tcpClientConnect, | |
5525 | tcpClientPortNo, tcpClientIP, tcpClientSocketFd ; | |
5526 | ||
5527 | TYPE | |
5528 | @findex tcpServerState (type) | |
5529 | tcpServerState = ADDRESS ; | |
5530 | @findex tcpClientState (type) | |
5531 | tcpClientState = ADDRESS ; | |
5532 | ||
5533 | ||
5534 | (* | |
5535 | tcpServerEstablish - returns a tcpState containing the relevant | |
5536 | information about a socket declared to receive | |
5537 | tcp connections. | |
5538 | *) | |
5539 | ||
5540 | @findex tcpServerEstablish | |
5541 | PROCEDURE tcpServerEstablish () : tcpServerState ; | |
5542 | ||
5543 | ||
5544 | (* | |
5545 | tcpServerEstablishPort - returns a tcpState containing the relevant | |
5546 | information about a socket declared to receive | |
5547 | tcp connections. This method attempts to use | |
5548 | the port specified by the parameter. | |
5549 | *) | |
5550 | ||
5551 | @findex tcpServerEstablishPort | |
5552 | PROCEDURE tcpServerEstablishPort (port: CARDINAL) : tcpServerState ; | |
5553 | ||
5554 | ||
5555 | (* | |
5556 | tcpServerAccept - returns a file descriptor once a client has connected and | |
5557 | been accepted. | |
5558 | *) | |
5559 | ||
5560 | @findex tcpServerAccept | |
5561 | PROCEDURE tcpServerAccept (s: tcpServerState) : INTEGER ; | |
5562 | ||
5563 | ||
5564 | (* | |
5565 | tcpServerPortNo - returns the portNo from structure, s. | |
5566 | *) | |
5567 | ||
5568 | @findex tcpServerPortNo | |
5569 | PROCEDURE tcpServerPortNo (s: tcpServerState) : CARDINAL ; | |
5570 | ||
5571 | ||
5572 | (* | |
5573 | tcpSocketFd - returns the sockFd from structure, s. | |
5574 | *) | |
5575 | ||
5576 | @findex tcpServerSocketFd | |
5577 | PROCEDURE tcpServerSocketFd (s: tcpServerState) : INTEGER ; | |
5578 | ||
5579 | ||
5580 | (* | |
5581 | getLocalIP - returns the IP address of this machine. | |
5582 | *) | |
5583 | ||
5584 | @findex getLocalIP | |
5585 | PROCEDURE getLocalIP (s: tcpServerState) : CARDINAL ; | |
5586 | ||
5587 | ||
5588 | (* | |
5589 | tcpServerIP - returns the IP address from structure, s. | |
5590 | *) | |
5591 | ||
5592 | @findex tcpServerIP | |
5593 | PROCEDURE tcpServerIP (s: tcpServerState) : CARDINAL ; | |
5594 | ||
5595 | ||
5596 | (* | |
5597 | tcpServerClientIP - returns the IP address of the client who | |
5598 | has connected to server, s. | |
5599 | *) | |
5600 | ||
5601 | @findex tcpServerClientIP | |
5602 | PROCEDURE tcpServerClientIP (s: tcpServerState) : CARDINAL ; | |
5603 | ||
5604 | ||
5605 | (* | |
5606 | tcpServerClientPortNo - returns the port number of the client who | |
5607 | has connected to server, s. | |
5608 | *) | |
5609 | ||
5610 | @findex tcpServerClientPortNo | |
5611 | PROCEDURE tcpServerClientPortNo (s: tcpServerState) : CARDINAL ; | |
5612 | ||
5613 | ||
5614 | (* | |
5615 | tcpClientSocket - returns a file descriptor (socket) which has | |
5616 | connected to, serverName:portNo. | |
5617 | *) | |
5618 | ||
5619 | @findex tcpClientSocket | |
5620 | PROCEDURE tcpClientSocket (serverName: ADDRESS; portNo: CARDINAL) : tcpClientState ; | |
5621 | ||
5622 | ||
5623 | (* | |
5624 | tcpClientSocketIP - returns a file descriptor (socket) which has | |
5625 | connected to, ip:portNo. | |
5626 | *) | |
5627 | ||
5628 | @findex tcpClientSocketIP | |
5629 | PROCEDURE tcpClientSocketIP (ip: CARDINAL; portNo: CARDINAL) : tcpClientState ; | |
5630 | ||
5631 | ||
5632 | (* | |
5633 | tcpClientConnect - returns the file descriptor associated with, s, | |
5634 | once a connect has been performed. | |
5635 | *) | |
5636 | ||
5637 | @findex tcpClientConnect | |
5638 | PROCEDURE tcpClientConnect (s: tcpClientState) : INTEGER ; | |
5639 | ||
5640 | ||
5641 | (* | |
5642 | tcpClientPortNo - returns the portNo from structure, s. | |
5643 | *) | |
5644 | ||
5645 | @findex tcpClientPortNo | |
5646 | PROCEDURE tcpClientPortNo (s: tcpClientState) : INTEGER ; | |
5647 | ||
5648 | ||
5649 | (* | |
5650 | tcpClientSocketFd - returns the sockFd from structure, s. | |
5651 | *) | |
5652 | ||
5653 | @findex tcpClientSocketFd | |
5654 | PROCEDURE tcpClientSocketFd (s: tcpClientState) : INTEGER ; | |
5655 | ||
5656 | ||
5657 | (* | |
5658 | tcpClientIP - returns the IP address from structure, s. | |
5659 | *) | |
5660 | ||
5661 | @findex tcpClientIP | |
5662 | PROCEDURE tcpClientIP (s: tcpClientState) : CARDINAL ; | |
5663 | ||
5664 | ||
5665 | END sckt. | |
5666 | @end example | |
5667 | @page | |
5668 | ||
5669 | @node gm2-libs/termios, gm2-libs/wrapc, gm2-libs/sckt, Base libraries | |
5670 | @subsection gm2-libs/termios | |
5671 | ||
5672 | @example | |
5673 | DEFINITION MODULE termios ; | |
5674 | ||
5675 | FROM SYSTEM IMPORT ADDRESS ; | |
5676 | ||
5677 | TYPE | |
5678 | @findex TERMIOS (type) | |
5679 | TERMIOS = ADDRESS ; | |
5680 | ||
5681 | @findex ControlChar (type) | |
5682 | ControlChar = (vintr, vquit, verase, vkill, veof, vtime, vmin, | |
5683 | vswtc, vstart, vstop, vsusp, veol, vreprint, vdiscard, | |
5684 | vwerase, vlnext, veol2) ; | |
5685 | ||
5686 | @findex Flag (type) | |
5687 | Flag = ( | |
5688 | (* input flag bits *) | |
5689 | ignbrk, ibrkint, ignpar, iparmrk, inpck, istrip, inlcr, | |
5690 | igncr, icrnl, iuclc, ixon, ixany, ixoff, imaxbel, | |
5691 | (* output flag bits *) | |
5692 | opost, olcuc, onlcr, ocrnl, onocr, onlret, ofill, ofdel, | |
5693 | onl0, onl1, ocr0, ocr1, ocr2, ocr3, | |
5694 | otab0, otab1, otab2, otab3, obs0, obs1, off0, off1, ovt0, ovt1, | |
5695 | (* baud rate *) | |
5696 | b0, b50, b75, b110, b135, b150, b200, b300, b600, b1200, | |
5697 | b1800, b2400, b4800, b9600, b19200, b38400, | |
5698 | b57600, b115200, b240400, b460800, b500000, b576000, | |
5699 | b921600, b1000000, b1152000, b1500000, b2000000, b2500000, | |
5700 | b3000000, b3500000, b4000000, maxbaud, crtscts, | |
5701 | (* character size *) | |
5702 | cs5, cs6, cs7, cs8, cstopb, cread, parenb, parodd, hupcl, clocal, | |
5703 | (* local flags *) | |
5704 | lisig, licanon, lxcase, lecho, lechoe, lechok, lechonl, lnoflsh, | |
5705 | ltopstop, lechoctl, lechoprt, lechoke, lflusho, lpendin, liexten) ; | |
5706 | ||
5707 | ||
5708 | (* | |
5709 | InitTermios - new data structure. | |
5710 | *) | |
5711 | ||
5712 | @findex InitTermios | |
5713 | PROCEDURE InitTermios () : TERMIOS ; | |
5714 | ||
5715 | ||
5716 | (* | |
5717 | KillTermios - delete data structure. | |
5718 | *) | |
5719 | ||
5720 | @findex KillTermios | |
5721 | PROCEDURE KillTermios (t: TERMIOS) : TERMIOS ; | |
5722 | ||
5723 | ||
5724 | (* | |
5725 | cfgetospeed - return output baud rate. | |
5726 | *) | |
5727 | ||
5728 | @findex cfgetospeed | |
5729 | PROCEDURE cfgetospeed (t: TERMIOS) : INTEGER ; | |
5730 | ||
5731 | ||
5732 | (* | |
5733 | cfgetispeed - return input baud rate. | |
5734 | *) | |
5735 | ||
5736 | @findex cfgetispeed | |
5737 | PROCEDURE cfgetispeed (t: TERMIOS) : INTEGER ; | |
5738 | ||
5739 | ||
5740 | (* | |
5741 | cfsetospeed - set output baud rate. | |
5742 | *) | |
5743 | ||
5744 | @findex cfsetospeed | |
5745 | PROCEDURE cfsetospeed (t: TERMIOS; b: CARDINAL) : INTEGER ; | |
5746 | ||
5747 | ||
5748 | (* | |
5749 | cfsetispeed - set input baud rate. | |
5750 | *) | |
5751 | ||
5752 | @findex cfsetispeed | |
5753 | PROCEDURE cfsetispeed (t: TERMIOS; b: CARDINAL) : INTEGER ; | |
5754 | ||
5755 | ||
5756 | (* | |
5757 | cfsetspeed - set input and output baud rate. | |
5758 | *) | |
5759 | ||
5760 | @findex cfsetspeed | |
5761 | PROCEDURE cfsetspeed (t: TERMIOS; b: CARDINAL) : INTEGER ; | |
5762 | ||
5763 | ||
5764 | (* | |
5765 | tcgetattr - get state of, fd, into, t. | |
5766 | *) | |
5767 | ||
5768 | @findex tcgetattr | |
5769 | PROCEDURE tcgetattr (fd: INTEGER; t: TERMIOS) : INTEGER ; | |
5770 | ||
5771 | ||
5772 | (* | |
5773 | The following three functions return the different option values. | |
5774 | *) | |
5775 | ||
5776 | @findex tcsnow | |
5777 | PROCEDURE tcsnow () : INTEGER ; (* alter fd now *) | |
5778 | @findex tcsdrain | |
5779 | PROCEDURE tcsdrain () : INTEGER ; (* alter when all output has been sent *) | |
5780 | @findex tcsflush | |
5781 | PROCEDURE tcsflush () : INTEGER ; (* like drain, except discard any pending input *) | |
5782 | ||
5783 | ||
5784 | (* | |
5785 | tcsetattr - set state of, fd, to, t, using option. | |
5786 | *) | |
5787 | ||
5788 | @findex tcsetattr | |
5789 | PROCEDURE tcsetattr (fd: INTEGER; option: INTEGER; t: TERMIOS) : INTEGER ; | |
5790 | ||
5791 | ||
5792 | (* | |
5793 | cfmakeraw - sets, t, to raw mode. | |
5794 | *) | |
5795 | ||
5796 | @findex cfmakeraw | |
5797 | PROCEDURE cfmakeraw (t: TERMIOS) ; | |
5798 | ||
5799 | ||
5800 | (* | |
5801 | tcsendbreak - send zero bits for duration. | |
5802 | *) | |
5803 | ||
5804 | @findex tcsendbreak | |
5805 | PROCEDURE tcsendbreak (fd: INTEGER; duration: INTEGER) : INTEGER ; | |
5806 | ||
5807 | ||
5808 | (* | |
5809 | tcdrain - waits for pending output to be written on, fd. | |
5810 | *) | |
5811 | ||
5812 | @findex tcdrain | |
5813 | PROCEDURE tcdrain (fd: INTEGER) : INTEGER ; | |
5814 | ||
5815 | ||
5816 | (* | |
5817 | tcflushi - flush input. | |
5818 | *) | |
5819 | ||
5820 | @findex tcflushi | |
5821 | PROCEDURE tcflushi (fd: INTEGER) : INTEGER ; | |
5822 | ||
5823 | ||
5824 | (* | |
5825 | tcflusho - flush output. | |
5826 | *) | |
5827 | ||
5828 | @findex tcflusho | |
5829 | PROCEDURE tcflusho (fd: INTEGER) : INTEGER ; | |
5830 | ||
5831 | ||
5832 | (* | |
5833 | tcflushio - flush input and output. | |
5834 | *) | |
5835 | ||
5836 | @findex tcflushio | |
5837 | PROCEDURE tcflushio (fd: INTEGER) : INTEGER ; | |
5838 | ||
5839 | ||
5840 | (* | |
5841 | tcflowoni - restart input on, fd. | |
5842 | *) | |
5843 | ||
5844 | @findex tcflowoni | |
5845 | PROCEDURE tcflowoni (fd: INTEGER) : INTEGER ; | |
5846 | ||
5847 | ||
5848 | (* | |
5849 | tcflowoffi - stop input on, fd. | |
5850 | *) | |
5851 | ||
5852 | @findex tcflowoffi | |
5853 | PROCEDURE tcflowoffi (fd: INTEGER) : INTEGER ; | |
5854 | ||
5855 | ||
5856 | (* | |
5857 | tcflowono - restart output on, fd. | |
5858 | *) | |
5859 | ||
5860 | @findex tcflowono | |
5861 | PROCEDURE tcflowono (fd: INTEGER) : INTEGER ; | |
5862 | ||
5863 | ||
5864 | (* | |
5865 | tcflowoffo - stop output on, fd. | |
5866 | *) | |
5867 | ||
5868 | @findex tcflowoffo | |
5869 | PROCEDURE tcflowoffo (fd: INTEGER) : INTEGER ; | |
5870 | ||
5871 | ||
5872 | (* | |
5873 | GetFlag - sets a flag value from, t, in, b, and returns TRUE | |
5874 | if, t, supports, f. | |
5875 | *) | |
5876 | ||
5877 | @findex GetFlag | |
5878 | PROCEDURE GetFlag (t: TERMIOS; f: Flag; VAR b: BOOLEAN) : BOOLEAN ; | |
5879 | ||
5880 | ||
5881 | (* | |
5882 | SetFlag - sets a flag value in, t, to, b, and returns TRUE if | |
5883 | this flag value is supported. | |
5884 | *) | |
5885 | ||
5886 | @findex SetFlag | |
5887 | PROCEDURE SetFlag (t: TERMIOS; f: Flag; b: BOOLEAN) : BOOLEAN ; | |
5888 | ||
5889 | ||
5890 | (* | |
5891 | GetChar - sets a CHAR, ch, value from, t, and returns TRUE if | |
5892 | this value is supported. | |
5893 | *) | |
5894 | ||
5895 | @findex GetChar | |
5896 | PROCEDURE GetChar (t: TERMIOS; c: ControlChar; VAR ch: CHAR) : BOOLEAN ; | |
5897 | ||
5898 | ||
5899 | (* | |
5900 | SetChar - sets a CHAR value in, t, and returns TRUE if, c, | |
5901 | is supported. | |
5902 | *) | |
5903 | ||
5904 | @findex SetChar | |
5905 | PROCEDURE SetChar (t: TERMIOS; c: ControlChar; ch: CHAR) : BOOLEAN ; | |
5906 | ||
5907 | ||
5908 | END termios. | |
5909 | @end example | |
5910 | @page | |
5911 | ||
5912 | @node gm2-libs/wrapc, , gm2-libs/termios, Base libraries | |
5913 | @subsection gm2-libs/wrapc | |
5914 | ||
5915 | @example | |
5916 | DEFINITION MODULE wrapc ; | |
5917 | ||
5918 | FROM SYSTEM IMPORT ADDRESS ; | |
5919 | ||
5920 | EXPORT QUALIFIED strtime, filesize, fileinode, | |
5921 | getrand, getusername, filemtime, | |
5922 | getnameuidgid, signbit, signbitf, signbitl, | |
5923 | isfinite, isfinitel, isfinitef ; | |
5924 | ||
5925 | ||
5926 | (* | |
5927 | strtime - returns the C string for the equivalent C asctime | |
5928 | function. | |
5929 | *) | |
5930 | ||
5931 | @findex strtime | |
5932 | PROCEDURE strtime () : ADDRESS ; | |
5933 | ||
5934 | ||
5935 | (* | |
5936 | filesize - assigns the size of a file, f, into low, high and | |
5937 | returns zero if successful. | |
5938 | *) | |
5939 | ||
5940 | @findex filesize | |
5941 | PROCEDURE filesize (f: INTEGER; VAR low, high: CARDINAL) : INTEGER ; | |
5942 | ||
5943 | ||
5944 | (* | |
5945 | fileinode - return the inode associated with file, f. | |
5946 | *) | |
5947 | ||
5948 | @findex fileinode | |
5949 | PROCEDURE fileinode (f: INTEGER; VAR low, high: CARDINAL) : INTEGER ; | |
5950 | ||
5951 | ||
5952 | (* | |
5953 | filemtime - returns the mtime of a file, f. | |
5954 | *) | |
5955 | ||
5956 | @findex filemtime | |
5957 | PROCEDURE filemtime (f: INTEGER) : INTEGER ; | |
5958 | ||
5959 | ||
5960 | (* | |
5961 | getrand - returns a random number between 0..n-1 | |
5962 | *) | |
5963 | ||
5964 | @findex getrand | |
5965 | PROCEDURE getrand (n: INTEGER) : INTEGER ; | |
5966 | ||
5967 | ||
5968 | (* | |
5969 | getusername - returns a C string describing the current user. | |
5970 | *) | |
5971 | ||
5972 | @findex getusername | |
5973 | PROCEDURE getusername () : ADDRESS ; | |
5974 | ||
5975 | ||
5976 | (* | |
5977 | getnameuidgid - fills in the, uid, and, gid, which represents | |
5978 | user, name. | |
5979 | *) | |
5980 | ||
5981 | @findex getnameuidgid | |
5982 | PROCEDURE getnameuidgid (name: ADDRESS; VAR uid, gid: INTEGER) ; | |
5983 | ||
5984 | ||
5985 | (* | |
5986 | in C these procedure functions are really macros, so we provide | |
5987 | real C functions and let gm2 call these if the builtins | |
5988 | are unavailable. | |
5989 | *) | |
5990 | ||
5991 | @findex signbit | |
5992 | PROCEDURE signbit (r: REAL) : INTEGER ; | |
5993 | @findex signbitf | |
5994 | PROCEDURE signbitf (s: SHORTREAL) : INTEGER ; | |
5995 | @findex signbitl | |
5996 | PROCEDURE signbitl (l: LONGREAL) : INTEGER ; | |
5997 | ||
5998 | ||
5999 | (* | |
6000 | isfinite - provide non builtin alternative to the gcc builtin isfinite. | |
6001 | Returns 1 if x is finite and 0 if it is not. | |
6002 | *) | |
6003 | ||
6004 | @findex isfinite | |
6005 | PROCEDURE isfinite (x: REAL) : INTEGER ; | |
6006 | ||
6007 | ||
6008 | (* | |
6009 | isfinitef - provide non builtin alternative to the gcc builtin isfinite. | |
6010 | Returns 1 if x is finite and 0 if it is not. | |
6011 | *) | |
6012 | ||
6013 | @findex isfinitef | |
6014 | PROCEDURE isfinitef (x: SHORTREAL) : INTEGER ; | |
6015 | ||
6016 | ||
6017 | (* | |
6018 | isfinitel - provide non builtin alternative to the gcc builtin isfinite. | |
6019 | Returns 1 if x is finite and 0 if it is not. | |
6020 | *) | |
6021 | ||
6022 | @findex isfinitel | |
6023 | PROCEDURE isfinitel (x: LONGREAL) : INTEGER ; | |
6024 | ||
6025 | ||
6026 | END wrapc. | |
6027 | @end example | |
6028 | @page | |
6029 | ||
6030 | ||
6031 | @c ------------------------------------------------------------ | |
6032 | @node PIM and Logitech 3.0 Compatible, PIM coroutine support, Base libraries, Libraries | |
6033 | @section PIM and Logitech 3.0 Compatible | |
6034 | ||
6035 | @c README.texi describes the additional PIM libraries. | |
83ffe9cd | 6036 | @c Copyright @copyright{} 2000-2023 Free Software Foundation, Inc. |
1eee94d3 GM |
6037 | @c |
6038 | @c This is part of the GM2 manual. | |
6039 | @c For copying conditions, see the file gcc/doc/include/fdl.texi. | |
6040 | ||
6041 | These modules are provided to enable legacy Modula-2 applications to | |
6042 | build with GNU Modula-2. It is advised that these module should not | |
6043 | be used for new projects, maybe the ISO libraries or the native | |
6044 | compiler PIM libraries (FIO) should be used instead. | |
6045 | ||
6046 | Here is an outline of the module layering: | |
6047 | ||
6048 | @example | |
6049 | ||
6050 | InOut RealInOut LongIO CardinalIO | |
6051 | \ | | / | |
6052 | Terminal | |
6053 | ----------------------------------- | |
6054 | | | |
6055 | Termbase | |
6056 | / \ | |
6057 | Keyboard Display | |
6058 | ||
6059 | @end example | |
6060 | ||
6061 | Above the line are user level PIM [234] and Logitech 3.0 compatible | |
6062 | modules. Below the line Logitech 3.0 advised that these modules | |
6063 | should be considered part of the runtime system. The libraries do | |
6064 | not provide all the features found in the Logitech libraries as | |
6065 | a number of these features were MS-DOS related. Essentially the | |
6066 | basic input/output, file system, string manipulation and conversion | |
6067 | routines are provided. Access to DOSCALL, graphics, time and date | |
6068 | are not as these were constrained by the limitations of MS-DOS. | |
6069 | ||
6070 | The following libraries are contained within the base GNU Modula-2 | |
6071 | libraries and are also Logitech-3.0 compatible: @xref{gm2-libs/ASCII}, | |
6072 | @xref{gm2-libs/Storage} and @xref{gm2-libs/MathLib0}. These libraries | |
6073 | are always available for any dialect of the language (although their | |
6074 | implementation and behaviour might differ, for example Storage ISO and | |
6075 | PIM). | |
6076 | ||
6077 | The following libraries are Logitech-3.0 compatible but fall outside | |
6078 | the base GNU Modula-2 libraries. | |
6079 | @menu | |
6080 | * gm2-libs-pim/BitBlockOps::BitBlockOps.def | |
6081 | * gm2-libs-pim/BitByteOps::BitByteOps.def | |
6082 | * gm2-libs-pim/BitWordOps::BitWordOps.def | |
6083 | * gm2-libs-pim/BlockOps::BlockOps.def | |
6084 | * gm2-libs-pim/Break::Break.def | |
6085 | * gm2-libs-pim/CardinalIO::CardinalIO.def | |
6086 | * gm2-libs-pim/Conversions::Conversions.def | |
6087 | * gm2-libs-pim/DebugPMD::DebugPMD.def | |
6088 | * gm2-libs-pim/DebugTrace::DebugTrace.def | |
6089 | * gm2-libs-pim/Delay::Delay.def | |
6090 | * gm2-libs-pim/Display::Display.def | |
6091 | * gm2-libs-pim/ErrorCode::ErrorCode.def | |
6092 | * gm2-libs-pim/FileSystem::FileSystem.def | |
6093 | * gm2-libs-pim/FloatingUtilities::FloatingUtilities.def | |
6094 | * gm2-libs-pim/InOut::InOut.def | |
6095 | * gm2-libs-pim/Keyboard::Keyboard.def | |
6096 | * gm2-libs-pim/LongIO::LongIO.def | |
6097 | * gm2-libs-pim/NumberConversion::NumberConversion.def | |
6098 | * gm2-libs-pim/Random::Random.def | |
6099 | * gm2-libs-pim/RealConversions::RealConversions.def | |
6100 | * gm2-libs-pim/RealInOut::RealInOut.def | |
6101 | * gm2-libs-pim/Strings::Strings.def | |
6102 | * gm2-libs-pim/Termbase::Termbase.def | |
6103 | * gm2-libs-pim/Terminal::Terminal.def | |
6104 | * gm2-libs-pim/TimeDate::TimeDate.def | |
6105 | @end menu | |
6106 | ||
6107 | @node gm2-libs-pim/BitBlockOps, gm2-libs-pim/BitByteOps, , PIM and Logitech 3.0 Compatible | |
6108 | @subsection gm2-libs-pim/BitBlockOps | |
6109 | ||
6110 | @example | |
6111 | DEFINITION MODULE BitBlockOps ; | |
6112 | ||
6113 | ||
6114 | FROM SYSTEM IMPORT ADDRESS ; | |
6115 | ||
6116 | ||
6117 | (* | |
6118 | BlockAnd - performs a bitwise AND on blocks | |
6119 | [dest..dest+size-1] := [dest..dest+size-1] AND | |
6120 | [src..src+size-1] | |
6121 | *) | |
6122 | ||
6123 | @findex BlockAnd | |
6124 | PROCEDURE BlockAnd (dest, src: ADDRESS; size: CARDINAL) ; | |
6125 | ||
6126 | ||
6127 | (* | |
6128 | BlockOr - performs a bitwise OR on blocks | |
6129 | [dest..dest+size-1] := [dest..dest+size-1] OR | |
6130 | [src..src+size-1] | |
6131 | *) | |
6132 | ||
6133 | @findex BlockOr | |
6134 | PROCEDURE BlockOr (dest, src: ADDRESS; size: CARDINAL) ; | |
6135 | ||
6136 | ||
6137 | (* | |
6138 | BlockXor - performs a bitwise XOR on blocks | |
6139 | [dest..dest+size-1] := [dest..dest+size-1] XOR | |
6140 | [src..src+size-1] | |
6141 | *) | |
6142 | ||
6143 | @findex BlockXor | |
6144 | PROCEDURE BlockXor (dest, src: ADDRESS; size: CARDINAL) ; | |
6145 | ||
6146 | ||
6147 | (* | |
6148 | BlockNot - performs a bitsize NOT on the block as defined | |
6149 | by: [dest..dest+size-1] | |
6150 | *) | |
6151 | ||
6152 | @findex BlockNot | |
6153 | PROCEDURE BlockNot (dest: ADDRESS; size: CARDINAL) ; | |
6154 | ||
6155 | ||
6156 | (* | |
6157 | BlockShr - performs a block shift right of, count, bits. | |
6158 | Where the block is defined as: | |
6159 | [dest..dest+size-1]. | |
6160 | The block is considered to be an ARRAY OF BYTEs | |
6161 | which is shifted, bit at a time over each byte in | |
6162 | turn. The left most byte is considered the byte | |
6163 | located at the lowest address. | |
6164 | If you require an endianness SHIFT use | |
6165 | the SYSTEM.SHIFT procedure and declare the | |
6166 | block as a POINTER TO set type. | |
6167 | *) | |
6168 | ||
6169 | @findex BlockShr | |
6170 | PROCEDURE BlockShr (dest: ADDRESS; size, count: CARDINAL) ; | |
6171 | ||
6172 | ||
6173 | (* | |
6174 | BlockShl - performs a block shift left of, count, bits. | |
6175 | Where the block is defined as: | |
6176 | [dest..dest+size-1]. | |
6177 | The block is considered to be an ARRAY OF BYTEs | |
6178 | which is shifted, bit at a time over each byte in | |
6179 | turn. The left most byte is considered the byte | |
6180 | located at the lowest address. | |
6181 | If you require an endianness SHIFT use | |
6182 | the SYSTEM.SHIFT procedure and declare the | |
6183 | block as a POINTER TO set type. | |
6184 | *) | |
6185 | ||
6186 | @findex BlockShl | |
6187 | PROCEDURE BlockShl (dest: ADDRESS; size, count: CARDINAL) ; | |
6188 | ||
6189 | ||
6190 | (* | |
6191 | BlockRor - performs a block rotate right of, count, bits. | |
6192 | Where the block is defined as: | |
6193 | [dest..dest+size-1]. | |
6194 | The block is considered to be an ARRAY OF BYTEs | |
6195 | which is rotated, bit at a time over each byte in | |
6196 | turn. The left most byte is considered the byte | |
6197 | located at the lowest address. | |
6198 | If you require an endianness ROTATE use | |
6199 | the SYSTEM.ROTATE procedure and declare the | |
6200 | block as a POINTER TO set type. | |
6201 | *) | |
6202 | ||
6203 | @findex BlockRor | |
6204 | PROCEDURE BlockRor (dest: ADDRESS; size, count: CARDINAL) ; | |
6205 | ||
6206 | ||
6207 | (* | |
6208 | BlockRol - performs a block rotate left of, count, bits. | |
6209 | Where the block is defined as: | |
6210 | [dest..dest+size-1]. | |
6211 | The block is considered to be an ARRAY OF BYTEs | |
6212 | which is rotated, bit at a time over each byte in | |
6213 | turn. The left most byte is considered the byte | |
6214 | located at the lowest address. | |
6215 | If you require an endianness ROTATE use | |
6216 | the SYSTEM.ROTATE procedure and declare the | |
6217 | block as a POINTER TO set type. | |
6218 | *) | |
6219 | ||
6220 | @findex BlockRol | |
6221 | PROCEDURE BlockRol (dest: ADDRESS; size, count: CARDINAL) ; | |
6222 | ||
6223 | ||
6224 | END BitBlockOps. | |
6225 | @end example | |
6226 | @page | |
6227 | ||
6228 | @node gm2-libs-pim/BitByteOps, gm2-libs-pim/BitWordOps, gm2-libs-pim/BitBlockOps, PIM and Logitech 3.0 Compatible | |
6229 | @subsection gm2-libs-pim/BitByteOps | |
6230 | ||
6231 | @example | |
6232 | DEFINITION MODULE BitByteOps ; | |
6233 | ||
6234 | FROM SYSTEM IMPORT BYTE ; | |
6235 | ||
6236 | ||
6237 | (* | |
6238 | GetBits - returns the bits firstBit..lastBit from source. | |
6239 | Bit 0 of byte maps onto the firstBit of source. | |
6240 | *) | |
6241 | ||
6242 | @findex GetBits | |
6243 | PROCEDURE GetBits (source: BYTE; firstBit, lastBit: CARDINAL) : BYTE ; | |
6244 | ||
6245 | ||
6246 | (* | |
6247 | SetBits - sets bits in, byte, starting at, firstBit, and ending at, | |
6248 | lastBit, with, pattern. The bit zero of, pattern, will | |
6249 | be placed into, byte, at position, firstBit. | |
6250 | *) | |
6251 | ||
6252 | @findex SetBits | |
6253 | PROCEDURE SetBits (VAR byte: BYTE; firstBit, lastBit: CARDINAL; | |
6254 | pattern: BYTE) ; | |
6255 | ||
6256 | ||
6257 | (* | |
6258 | ByteAnd - returns a bitwise (left AND right) | |
6259 | *) | |
6260 | ||
6261 | @findex ByteAnd | |
6262 | PROCEDURE ByteAnd (left, right: BYTE) : BYTE ; | |
6263 | ||
6264 | ||
6265 | (* | |
6266 | ByteOr - returns a bitwise (left OR right) | |
6267 | *) | |
6268 | ||
6269 | @findex ByteOr | |
6270 | PROCEDURE ByteOr (left, right: BYTE) : BYTE ; | |
6271 | ||
6272 | ||
6273 | (* | |
6274 | ByteXor - returns a bitwise (left XOR right) | |
6275 | *) | |
6276 | ||
6277 | @findex ByteXor | |
6278 | PROCEDURE ByteXor (left, right: BYTE) : BYTE ; | |
6279 | ||
6280 | ||
6281 | (* | |
6282 | ByteNot - returns a byte with all bits inverted. | |
6283 | *) | |
6284 | ||
6285 | @findex ByteNot | |
6286 | PROCEDURE ByteNot (byte: BYTE) : BYTE ; | |
6287 | ||
6288 | ||
6289 | (* | |
6290 | ByteShr - returns a, byte, which has been shifted, count | |
6291 | bits to the right. | |
6292 | *) | |
6293 | ||
6294 | @findex ByteShr | |
6295 | PROCEDURE ByteShr (byte: BYTE; count: CARDINAL) : BYTE ; | |
6296 | ||
6297 | ||
6298 | (* | |
6299 | ByteShl - returns a, byte, which has been shifted, count | |
6300 | bits to the left. | |
6301 | *) | |
6302 | ||
6303 | @findex ByteShl | |
6304 | PROCEDURE ByteShl (byte: BYTE; count: CARDINAL) : BYTE ; | |
6305 | ||
6306 | ||
6307 | (* | |
6308 | ByteSar - shift byte arthemetic right. Preserves the top | |
6309 | end bit and as the value is shifted right. | |
6310 | *) | |
6311 | ||
6312 | @findex ByteSar | |
6313 | PROCEDURE ByteSar (byte: BYTE; count: CARDINAL) : BYTE ; | |
6314 | ||
6315 | ||
6316 | (* | |
6317 | ByteRor - returns a, byte, which has been rotated, count | |
6318 | bits to the right. | |
6319 | *) | |
6320 | ||
6321 | @findex ByteRor | |
6322 | PROCEDURE ByteRor (byte: BYTE; count: CARDINAL) : BYTE ; | |
6323 | ||
6324 | ||
6325 | (* | |
6326 | ByteRol - returns a, byte, which has been rotated, count | |
6327 | bits to the left. | |
6328 | *) | |
6329 | ||
6330 | @findex ByteRol | |
6331 | PROCEDURE ByteRol (byte: BYTE; count: CARDINAL) : BYTE ; | |
6332 | ||
6333 | ||
6334 | (* | |
6335 | HighNibble - returns the top nibble only from, byte. | |
6336 | The top nibble of, byte, is extracted and | |
6337 | returned in the bottom nibble of the return | |
6338 | value. | |
6339 | *) | |
6340 | ||
6341 | @findex HighNibble | |
6342 | PROCEDURE HighNibble (byte: BYTE) : BYTE ; | |
6343 | ||
6344 | ||
6345 | (* | |
6346 | LowNibble - returns the low nibble only from, byte. | |
6347 | The top nibble is replaced by zeros. | |
6348 | *) | |
6349 | ||
6350 | @findex LowNibble | |
6351 | PROCEDURE LowNibble (byte: BYTE) : BYTE ; | |
6352 | ||
6353 | ||
6354 | (* | |
6355 | Swap - swaps the low and high nibbles in the, byte. | |
6356 | *) | |
6357 | ||
6358 | @findex Swap | |
6359 | PROCEDURE Swap (byte: BYTE) : BYTE ; | |
6360 | ||
6361 | ||
6362 | END BitByteOps. | |
6363 | @end example | |
6364 | @page | |
6365 | ||
6366 | @node gm2-libs-pim/BitWordOps, gm2-libs-pim/BlockOps, gm2-libs-pim/BitByteOps, PIM and Logitech 3.0 Compatible | |
6367 | @subsection gm2-libs-pim/BitWordOps | |
6368 | ||
6369 | @example | |
6370 | DEFINITION MODULE BitWordOps ; | |
6371 | ||
6372 | FROM SYSTEM IMPORT WORD ; | |
6373 | ||
6374 | ||
6375 | (* | |
6376 | GetBits - returns the bits firstBit..lastBit from source. | |
6377 | Bit 0 of word maps onto the firstBit of source. | |
6378 | *) | |
6379 | ||
6380 | @findex GetBits | |
6381 | PROCEDURE GetBits (source: WORD; firstBit, lastBit: CARDINAL) : WORD ; | |
6382 | ||
6383 | ||
6384 | (* | |
6385 | SetBits - sets bits in, word, starting at, firstBit, and ending at, | |
6386 | lastBit, with, pattern. The bit zero of, pattern, will | |
6387 | be placed into, word, at position, firstBit. | |
6388 | *) | |
6389 | ||
6390 | @findex SetBits | |
6391 | PROCEDURE SetBits (VAR word: WORD; firstBit, lastBit: CARDINAL; | |
6392 | pattern: WORD) ; | |
6393 | ||
6394 | ||
6395 | (* | |
6396 | WordAnd - returns a bitwise (left AND right) | |
6397 | *) | |
6398 | ||
6399 | @findex WordAnd | |
6400 | PROCEDURE WordAnd (left, right: WORD) : WORD ; | |
6401 | ||
6402 | ||
6403 | (* | |
6404 | WordOr - returns a bitwise (left OR right) | |
6405 | *) | |
6406 | ||
6407 | @findex WordOr | |
6408 | PROCEDURE WordOr (left, right: WORD) : WORD ; | |
6409 | ||
6410 | ||
6411 | (* | |
6412 | WordXor - returns a bitwise (left XOR right) | |
6413 | *) | |
6414 | ||
6415 | @findex WordXor | |
6416 | PROCEDURE WordXor (left, right: WORD) : WORD ; | |
6417 | ||
6418 | ||
6419 | (* | |
6420 | WordNot - returns a word with all bits inverted. | |
6421 | *) | |
6422 | ||
6423 | @findex WordNot | |
6424 | PROCEDURE WordNot (word: WORD) : WORD ; | |
6425 | ||
6426 | ||
6427 | (* | |
6428 | WordShr - returns a, word, which has been shifted, count | |
6429 | bits to the right. | |
6430 | *) | |
6431 | ||
6432 | @findex WordShr | |
6433 | PROCEDURE WordShr (word: WORD; count: CARDINAL) : WORD ; | |
6434 | ||
6435 | ||
6436 | (* | |
6437 | WordShl - returns a, word, which has been shifted, count | |
6438 | bits to the left. | |
6439 | *) | |
6440 | ||
6441 | @findex WordShl | |
6442 | PROCEDURE WordShl (word: WORD; count: CARDINAL) : WORD ; | |
6443 | ||
6444 | ||
6445 | (* | |
6446 | WordSar - shift word arthemetic right. Preserves the top | |
6447 | end bit and as the value is shifted right. | |
6448 | *) | |
6449 | ||
6450 | @findex WordSar | |
6451 | PROCEDURE WordSar (word: WORD; count: CARDINAL) : WORD ; | |
6452 | ||
6453 | ||
6454 | (* | |
6455 | WordRor - returns a, word, which has been rotated, count | |
6456 | bits to the right. | |
6457 | *) | |
6458 | ||
6459 | @findex WordRor | |
6460 | PROCEDURE WordRor (word: WORD; count: CARDINAL) : WORD ; | |
6461 | ||
6462 | ||
6463 | (* | |
6464 | WordRol - returns a, word, which has been rotated, count | |
6465 | bits to the left. | |
6466 | *) | |
6467 | ||
6468 | @findex WordRol | |
6469 | PROCEDURE WordRol (word: WORD; count: CARDINAL) : WORD ; | |
6470 | ||
6471 | ||
6472 | (* | |
6473 | HighByte - returns the top byte only from, word. | |
6474 | The byte is returned in the bottom byte | |
6475 | in the return value. | |
6476 | *) | |
6477 | ||
6478 | @findex HighByte | |
6479 | PROCEDURE HighByte (word: WORD) : WORD ; | |
6480 | ||
6481 | ||
6482 | (* | |
6483 | LowByte - returns the low byte only from, word. | |
6484 | The byte is returned in the bottom byte | |
6485 | in the return value. | |
6486 | *) | |
6487 | ||
6488 | @findex LowByte | |
6489 | PROCEDURE LowByte (word: WORD) : WORD ; | |
6490 | ||
6491 | ||
6492 | (* | |
6493 | Swap - byte flips the contents of word. | |
6494 | *) | |
6495 | ||
6496 | @findex Swap | |
6497 | PROCEDURE Swap (word: WORD) : WORD ; | |
6498 | ||
6499 | ||
6500 | END BitWordOps. | |
6501 | @end example | |
6502 | @page | |
6503 | ||
6504 | @node gm2-libs-pim/BlockOps, gm2-libs-pim/Break, gm2-libs-pim/BitWordOps, PIM and Logitech 3.0 Compatible | |
6505 | @subsection gm2-libs-pim/BlockOps | |
6506 | ||
6507 | @example | |
6508 | DEFINITION MODULE BlockOps ; | |
6509 | ||
6510 | FROM SYSTEM IMPORT ADDRESS ; | |
6511 | ||
6512 | ||
6513 | (* | |
6514 | MoveBlockForward - moves, n, bytes from, src, to, dest. | |
6515 | Starts copying from src and keep copying | |
6516 | until, n, bytes have been copied. | |
6517 | *) | |
6518 | ||
6519 | @findex BlockMoveForward | |
6520 | PROCEDURE BlockMoveForward (dest, src: ADDRESS; n: CARDINAL) ; | |
6521 | ||
6522 | ||
6523 | (* | |
6524 | MoveBlockBackward - moves, n, bytes from, src, to, dest. | |
6525 | Starts copying from src+n and keeps copying | |
6526 | until, n, bytes have been copied. | |
6527 | The last datum to be copied will be the byte | |
6528 | at address, src. | |
6529 | *) | |
6530 | ||
6531 | @findex BlockMoveBackward | |
6532 | PROCEDURE BlockMoveBackward (dest, src: ADDRESS; n: CARDINAL) ; | |
6533 | ||
6534 | ||
6535 | (* | |
6536 | BlockClear - fills, block..block+n-1, with zero's. | |
6537 | *) | |
6538 | ||
6539 | @findex BlockClear | |
6540 | PROCEDURE BlockClear (block: ADDRESS; n: CARDINAL) ; | |
6541 | ||
6542 | ||
6543 | (* | |
6544 | BlockSet - fills, n, bytes starting at, block, with a pattern | |
6545 | defined at address pattern..pattern+patternSize-1. | |
6546 | *) | |
6547 | ||
6548 | @findex BlockSet | |
6549 | PROCEDURE BlockSet (block: ADDRESS; n: CARDINAL; | |
6550 | pattern: ADDRESS; patternSize: CARDINAL) ; | |
6551 | ||
6552 | ||
6553 | (* | |
6554 | BlockEqual - returns TRUE if the blocks defined, a..a+n-1, and, | |
6555 | b..b+n-1 contain the same bytes. | |
6556 | *) | |
6557 | ||
6558 | @findex BlockEqual | |
6559 | PROCEDURE BlockEqual (a, b: ADDRESS; n: CARDINAL) : BOOLEAN ; | |
6560 | ||
6561 | ||
6562 | (* | |
6563 | BlockPosition - searches for a pattern as defined by | |
6564 | pattern..patternSize-1 in the block, | |
6565 | block..block+blockSize-1. It returns | |
6566 | the offset from block indicating the | |
6567 | first occurence of, pattern. | |
6568 | MAX(CARDINAL) is returned if no match | |
6569 | is detected. | |
6570 | *) | |
6571 | ||
6572 | @findex BlockPosition | |
6573 | PROCEDURE BlockPosition (block: ADDRESS; blockSize: CARDINAL; | |
6574 | pattern: ADDRESS; patternSize: CARDINAL) : CARDINAL ; | |
6575 | ||
6576 | ||
6577 | END BlockOps. | |
6578 | @end example | |
6579 | @page | |
6580 | ||
6581 | @node gm2-libs-pim/Break, gm2-libs-pim/CardinalIO, gm2-libs-pim/BlockOps, PIM and Logitech 3.0 Compatible | |
6582 | @subsection gm2-libs-pim/Break | |
6583 | ||
6584 | @example | |
6585 | DEFINITION MODULE Break ; | |
6586 | ||
6587 | ||
6588 | EXPORT QUALIFIED EnableBreak, DisableBreak, InstallBreak, UnInstallBreak ; | |
6589 | ||
6590 | ||
6591 | (* | |
6592 | EnableBreak - enable the current break handler. | |
6593 | *) | |
6594 | ||
6595 | @findex EnableBreak | |
6596 | PROCEDURE EnableBreak ; | |
6597 | ||
6598 | ||
6599 | (* | |
6600 | DisableBreak - disable the current break handler (and all | |
6601 | installed handlers). | |
6602 | *) | |
6603 | ||
6604 | @findex DisableBreak | |
6605 | PROCEDURE DisableBreak ; | |
6606 | ||
6607 | ||
6608 | (* | |
6609 | InstallBreak - installs a procedure, p, to be invoked when | |
6610 | a ctrl-c is caught. Any number of these | |
6611 | procedures may be stacked. Only the top | |
6612 | procedure is run when ctrl-c is caught. | |
6613 | *) | |
6614 | ||
6615 | @findex InstallBreak | |
6616 | PROCEDURE InstallBreak (p: PROC) ; | |
6617 | ||
6618 | ||
6619 | (* | |
6620 | UnInstallBreak - pops the break handler stack. | |
6621 | *) | |
6622 | ||
6623 | @findex UnInstallBreak | |
6624 | PROCEDURE UnInstallBreak ; | |
6625 | ||
6626 | ||
6627 | END Break. | |
6628 | @end example | |
6629 | @page | |
6630 | ||
6631 | @node gm2-libs-pim/CardinalIO, gm2-libs-pim/Conversions, gm2-libs-pim/Break, PIM and Logitech 3.0 Compatible | |
6632 | @subsection gm2-libs-pim/CardinalIO | |
6633 | ||
6634 | @example | |
6635 | DEFINITION MODULE CardinalIO ; | |
6636 | ||
6637 | EXPORT QUALIFIED Done, | |
6638 | ReadCardinal, WriteCardinal, ReadHex, WriteHex, | |
6639 | ReadLongCardinal, WriteLongCardinal, ReadLongHex, | |
6640 | WriteLongHex, | |
6641 | ReadShortCardinal, WriteShortCardinal, ReadShortHex, | |
6642 | WriteShortHex ; | |
6643 | ||
6644 | ||
6645 | VAR | |
6646 | @findex Done (var) | |
6647 | Done: BOOLEAN ; | |
6648 | ||
6649 | ||
6650 | (* | |
6651 | ReadCardinal - read an unsigned decimal number from the terminal. | |
6652 | The read continues until a space, newline, esc or | |
6653 | end of file is reached. | |
6654 | *) | |
6655 | ||
6656 | @findex ReadCardinal | |
6657 | PROCEDURE ReadCardinal (VAR c: CARDINAL) ; | |
6658 | ||
6659 | ||
6660 | (* | |
6661 | WriteCardinal - writes the value, c, to the terminal and ensures | |
6662 | that at least, n, characters are written. The number | |
6663 | will be padded out by preceeding spaces if necessary. | |
6664 | *) | |
6665 | ||
6666 | @findex WriteCardinal | |
6667 | PROCEDURE WriteCardinal (c: CARDINAL; n: CARDINAL) ; | |
6668 | ||
6669 | ||
6670 | (* | |
6671 | ReadHex - reads in an unsigned hexadecimal number from the terminal. | |
6672 | The read continues until a space, newline, esc or | |
6673 | end of file is reached. | |
6674 | *) | |
6675 | ||
6676 | @findex ReadHex | |
6677 | PROCEDURE ReadHex (VAR c: CARDINAL) ; | |
6678 | ||
6679 | ||
6680 | (* | |
6681 | WriteHex - writes out a CARDINAL, c, in hexadecimal format padding | |
6682 | with, n, characters (leading with '0') | |
6683 | *) | |
6684 | ||
6685 | @findex WriteHex | |
6686 | PROCEDURE WriteHex (c: CARDINAL; n: CARDINAL) ; | |
6687 | ||
6688 | ||
6689 | (* | |
6690 | ReadLongCardinal - read an unsigned decimal number from the terminal. | |
6691 | The read continues until a space, newline, esc or | |
6692 | end of file is reached. | |
6693 | *) | |
6694 | ||
6695 | @findex ReadLongCardinal | |
6696 | PROCEDURE ReadLongCardinal (VAR c: LONGCARD) ; | |
6697 | ||
6698 | ||
6699 | (* | |
6700 | WriteLongCardinal - writes the value, c, to the terminal and ensures | |
6701 | that at least, n, characters are written. The number | |
6702 | will be padded out by preceeding spaces if necessary. | |
6703 | *) | |
6704 | ||
6705 | @findex WriteLongCardinal | |
6706 | PROCEDURE WriteLongCardinal (c: LONGCARD; n: CARDINAL) ; | |
6707 | ||
6708 | ||
6709 | (* | |
6710 | ReadLongHex - reads in an unsigned hexadecimal number from the terminal. | |
6711 | The read continues until a space, newline, esc or | |
6712 | end of file is reached. | |
6713 | *) | |
6714 | ||
6715 | @findex ReadLongHex | |
6716 | PROCEDURE ReadLongHex (VAR c: LONGCARD) ; | |
6717 | ||
6718 | ||
6719 | (* | |
6720 | WriteLongHex - writes out a LONGCARD, c, in hexadecimal format padding | |
6721 | with, n, characters (leading with '0') | |
6722 | *) | |
6723 | ||
6724 | @findex WriteLongHex | |
6725 | PROCEDURE WriteLongHex (c: LONGCARD; n: CARDINAL) ; | |
6726 | ||
6727 | ||
6728 | (* | |
6729 | WriteShortCardinal - writes the value, c, to the terminal and ensures | |
6730 | that at least, n, characters are written. The number | |
6731 | will be padded out by preceeding spaces if necessary. | |
6732 | *) | |
6733 | ||
6734 | @findex WriteShortCardinal | |
6735 | PROCEDURE WriteShortCardinal (c: SHORTCARD; n: CARDINAL) ; | |
6736 | ||
6737 | ||
6738 | (* | |
6739 | ReadShortCardinal - read an unsigned decimal number from the terminal. | |
6740 | The read continues until a space, newline, esc or | |
6741 | end of file is reached. | |
6742 | *) | |
6743 | ||
6744 | @findex ReadShortCardinal | |
6745 | PROCEDURE ReadShortCardinal (VAR c: SHORTCARD) ; | |
6746 | ||
6747 | ||
6748 | (* | |
6749 | ReadShortHex - reads in an unsigned hexadecimal number from the terminal. | |
6750 | The read continues until a space, newline, esc or | |
6751 | end of file is reached. | |
6752 | *) | |
6753 | ||
6754 | @findex ReadShortHex | |
6755 | PROCEDURE ReadShortHex (VAR c: SHORTCARD) ; | |
6756 | ||
6757 | ||
6758 | (* | |
6759 | WriteShortHex - writes out a SHORTCARD, c, in hexadecimal format padding | |
6760 | with, n, characters (leading with '0') | |
6761 | *) | |
6762 | ||
6763 | @findex WriteShortHex | |
6764 | PROCEDURE WriteShortHex (c: SHORTCARD; n: CARDINAL) ; | |
6765 | ||
6766 | ||
6767 | END CardinalIO. | |
6768 | @end example | |
6769 | @page | |
6770 | ||
6771 | @node gm2-libs-pim/Conversions, gm2-libs-pim/DebugPMD, gm2-libs-pim/CardinalIO, PIM and Logitech 3.0 Compatible | |
6772 | @subsection gm2-libs-pim/Conversions | |
6773 | ||
6774 | @example | |
6775 | DEFINITION MODULE Conversions ; | |
6776 | ||
6777 | EXPORT QUALIFIED ConvertOctal, ConvertHex, ConvertCardinal, | |
6778 | ConvertInteger, ConvertLongInt, ConvertShortInt ; | |
6779 | ||
6780 | (* | |
6781 | ConvertOctal - converts a CARDINAL, num, into an octal/hex/decimal | |
6782 | string and right justifies the string. It adds | |
6783 | spaces rather than '0' to pad out the string | |
6784 | to len characters. | |
6785 | ||
6786 | If the length of str is < num then the number is | |
6787 | truncated on the right. | |
6788 | *) | |
6789 | ||
6790 | @findex ConvertOctal | |
6791 | PROCEDURE ConvertOctal (num, len: CARDINAL; VAR str: ARRAY OF CHAR) ; | |
6792 | @findex ConvertHex | |
6793 | PROCEDURE ConvertHex (num, len: CARDINAL; VAR str: ARRAY OF CHAR) ; | |
6794 | @findex ConvertCardinal | |
6795 | PROCEDURE ConvertCardinal (num, len: CARDINAL; VAR str: ARRAY OF CHAR) ; | |
6796 | ||
6797 | (* | |
6798 | The INTEGER counterparts will add a '-' if, num, is <0 | |
6799 | *) | |
6800 | ||
6801 | @findex ConvertInteger | |
6802 | PROCEDURE ConvertInteger (num: INTEGER; len: CARDINAL; VAR str: ARRAY OF CHAR) ; | |
6803 | @findex ConvertLongInt | |
6804 | PROCEDURE ConvertLongInt (num: LONGINT; len: CARDINAL; VAR str: ARRAY OF CHAR) ; | |
6805 | @findex ConvertShortInt | |
6806 | PROCEDURE ConvertShortInt (num: SHORTINT; len: CARDINAL; VAR str: ARRAY OF CHAR) ; | |
6807 | ||
6808 | ||
6809 | END Conversions. | |
6810 | @end example | |
6811 | @page | |
6812 | ||
6813 | @node gm2-libs-pim/DebugPMD, gm2-libs-pim/DebugTrace, gm2-libs-pim/Conversions, PIM and Logitech 3.0 Compatible | |
6814 | @subsection gm2-libs-pim/DebugPMD | |
6815 | ||
6816 | @example | |
6817 | DEFINITION MODULE DebugPMD ; | |
6818 | ||
6819 | END DebugPMD. | |
6820 | @end example | |
6821 | @page | |
6822 | ||
6823 | @node gm2-libs-pim/DebugTrace, gm2-libs-pim/Delay, gm2-libs-pim/DebugPMD, PIM and Logitech 3.0 Compatible | |
6824 | @subsection gm2-libs-pim/DebugTrace | |
6825 | ||
6826 | @example | |
6827 | DEFINITION MODULE DebugTrace ; | |
6828 | ||
6829 | END DebugTrace. | |
6830 | @end example | |
6831 | @page | |
6832 | ||
6833 | @node gm2-libs-pim/Delay, gm2-libs-pim/Display, gm2-libs-pim/DebugTrace, PIM and Logitech 3.0 Compatible | |
6834 | @subsection gm2-libs-pim/Delay | |
6835 | ||
6836 | @example | |
6837 | DEFINITION MODULE Delay ; | |
6838 | ||
6839 | EXPORT QUALIFIED Delay ; | |
6840 | ||
6841 | ||
6842 | (* | |
6843 | milliSec - delays the program by approximately, milliSec, milliseconds. | |
6844 | *) | |
6845 | ||
6846 | @findex Delay | |
6847 | PROCEDURE Delay (milliSec: INTEGER) ; | |
6848 | ||
6849 | ||
6850 | END Delay. | |
6851 | @end example | |
6852 | @page | |
6853 | ||
6854 | @node gm2-libs-pim/Display, gm2-libs-pim/ErrorCode, gm2-libs-pim/Delay, PIM and Logitech 3.0 Compatible | |
6855 | @subsection gm2-libs-pim/Display | |
6856 | ||
6857 | @example | |
6858 | DEFINITION MODULE Display ; | |
6859 | ||
6860 | EXPORT QUALIFIED Write ; | |
6861 | ||
6862 | ||
6863 | (* | |
6864 | Write - display a character to the stdout. | |
6865 | ASCII.EOL moves to the beginning of the next line. | |
6866 | ASCII.del erases the character to the left of the cursor. | |
6867 | *) | |
6868 | ||
6869 | @findex Write | |
6870 | PROCEDURE Write (ch: CHAR) ; | |
6871 | ||
6872 | ||
6873 | END Display. | |
6874 | @end example | |
6875 | @page | |
6876 | ||
6877 | @node gm2-libs-pim/ErrorCode, gm2-libs-pim/FileSystem, gm2-libs-pim/Display, PIM and Logitech 3.0 Compatible | |
6878 | @subsection gm2-libs-pim/ErrorCode | |
6879 | ||
6880 | @example | |
6881 | DEFINITION MODULE ErrorCode ; | |
6882 | ||
6883 | EXPORT QUALIFIED SetErrorCode, GetErrorCode, ExitToOS ; | |
6884 | ||
6885 | ||
6886 | (* | |
6887 | SetErrorCode - sets the exit value which will be used if | |
6888 | the application terminates normally. | |
6889 | *) | |
6890 | ||
6891 | @findex SetErrorCode | |
6892 | PROCEDURE SetErrorCode (value: INTEGER) ; | |
6893 | ||
6894 | ||
6895 | (* | |
6896 | GetErrorCode - returns the current value to be used upon | |
6897 | application termination. | |
6898 | *) | |
6899 | ||
6900 | @findex GetErrorCode | |
6901 | PROCEDURE GetErrorCode (VAR value: INTEGER) ; | |
6902 | ||
6903 | ||
6904 | (* | |
6905 | ExitToOS - terminate the application and exit returning | |
6906 | the last value set by SetErrorCode to the OS. | |
6907 | *) | |
6908 | ||
6909 | @findex ExitToOS | |
6910 | PROCEDURE ExitToOS ; | |
6911 | ||
6912 | ||
6913 | END ErrorCode. | |
6914 | @end example | |
6915 | @page | |
6916 | ||
6917 | @node gm2-libs-pim/FileSystem, gm2-libs-pim/FloatingUtilities, gm2-libs-pim/ErrorCode, PIM and Logitech 3.0 Compatible | |
6918 | @subsection gm2-libs-pim/FileSystem | |
6919 | ||
6920 | @example | |
6921 | DEFINITION MODULE FileSystem ; | |
6922 | ||
6923 | (* Use this module sparingly, FIO or the ISO file modules have a | |
6924 | much cleaner interface. *) | |
6925 | ||
6926 | FROM SYSTEM IMPORT WORD, BYTE, ADDRESS ; | |
6927 | IMPORT FIO ; | |
6928 | FROM DynamicStrings IMPORT String ; | |
6929 | ||
6930 | EXPORT QUALIFIED File, Response, Flag, FlagSet, | |
6931 | ||
6932 | Create, Close, Lookup, Rename, Delete, | |
6933 | SetRead, SetWrite, SetModify, SetOpen, | |
6934 | Doio, SetPos, GetPos, Length, Reset, | |
6935 | ||
6936 | ReadWord, ReadChar, ReadByte, ReadNBytes, | |
6937 | WriteWord, WriteChar, WriteByte, WriteNBytes ; | |
6938 | ||
6939 | TYPE | |
6940 | @findex File (type) | |
6941 | File = RECORD | |
6942 | res : Response ; | |
6943 | flags : FlagSet ; | |
6944 | eof : BOOLEAN ; | |
6945 | lastWord: WORD ; | |
6946 | lastByte: BYTE ; | |
6947 | fio : FIO.File ; | |
6948 | highpos, | |
6949 | lowpos : CARDINAL ; | |
6950 | name : String ; | |
6951 | @findex END (type) | |
6952 | END ; | |
6953 | ||
6954 | @findex Flag (type) | |
6955 | Flag = ( | |
6956 | read, (* read access mode *) | |
6957 | write, (* write access mode *) | |
6958 | modify, | |
6959 | truncate, (* truncate file when closed *) | |
6960 | again, (* reread the last character *) | |
6961 | temporary, (* file is temporary *) | |
6962 | opened (* file has been opened *) | |
6963 | ); | |
6964 | ||
6965 | @findex FlagSet (type) | |
6966 | FlagSet = SET OF Flag; | |
6967 | ||
6968 | @findex Response (type) | |
6969 | Response = (done, notdone, notsupported, callerror, | |
6970 | unknownfile, paramerror, toomanyfiles, | |
6971 | @findex userdeverror) (type) | |
6972 | userdeverror) ; | |
6973 | ||
6974 | @findex Command (type) | |
6975 | Command = (create, close, lookup, rename, delete, | |
6976 | setread, setwrite, setmodify, setopen, | |
6977 | doio, setpos, getpos, length) ; | |
6978 | ||
6979 | ||
6980 | (* | |
6981 | Create - creates a temporary file. To make the file perminant | |
6982 | the file must be renamed. | |
6983 | *) | |
6984 | ||
6985 | @findex Create | |
6986 | PROCEDURE Create (VAR f: File) ; | |
6987 | ||
6988 | ||
6989 | (* | |
6990 | Close - closes an open file. | |
6991 | *) | |
6992 | ||
6993 | @findex Close | |
6994 | PROCEDURE Close (f: File) ; | |
6995 | ||
6996 | ||
6997 | (* | |
6998 | Lookup - looks for a file, filename. If the file is found | |
6999 | then, f, is opened. If it is not found and, newFile, | |
7000 | is TRUE then a new file is created and attached to, f. | |
7001 | If, newFile, is FALSE and no file was found then f.res | |
7002 | is set to notdone. | |
7003 | *) | |
7004 | ||
7005 | @findex Lookup | |
7006 | PROCEDURE Lookup (VAR f: File; filename: ARRAY OF CHAR; newFile: BOOLEAN) ; | |
7007 | ||
7008 | ||
7009 | (* | |
7010 | Rename - rename a file and change a temporary file to a permanent | |
7011 | file. f.res is set appropriately. | |
7012 | *) | |
7013 | ||
7014 | @findex Rename | |
7015 | PROCEDURE Rename (VAR f: File; newname: ARRAY OF CHAR) ; | |
7016 | ||
7017 | ||
7018 | (* | |
7019 | Delete - deletes a file, name, and sets the f.res field. | |
7020 | f.res is set appropriately. | |
7021 | *) | |
7022 | ||
7023 | @findex Delete | |
7024 | PROCEDURE Delete (name: ARRAY OF CHAR; VAR f: File) ; | |
7025 | ||
7026 | ||
7027 | (* | |
7028 | ReadWord - reads a WORD, w, from file, f. | |
7029 | f.res is set appropriately. | |
7030 | *) | |
7031 | ||
7032 | @findex ReadWord | |
7033 | PROCEDURE ReadWord (VAR f: File; VAR w: WORD) ; | |
7034 | ||
7035 | ||
7036 | (* | |
7037 | WriteWord - writes one word to a file, f. | |
7038 | f.res is set appropriately. | |
7039 | *) | |
7040 | ||
7041 | @findex WriteWord | |
7042 | PROCEDURE WriteWord (VAR f: File; w: WORD) ; | |
7043 | ||
7044 | ||
7045 | (* | |
7046 | ReadChar - reads one character from a file, f. | |
7047 | *) | |
7048 | ||
7049 | @findex ReadChar | |
7050 | PROCEDURE ReadChar (VAR f: File; VAR ch: CHAR) ; | |
7051 | ||
7052 | ||
7053 | (* | |
7054 | WriteChar - writes a character, ch, to a file, f. | |
7055 | f.res is set appropriately. | |
7056 | *) | |
7057 | ||
7058 | @findex WriteChar | |
7059 | PROCEDURE WriteChar (VAR f: File; ch: CHAR) ; | |
7060 | ||
7061 | ||
7062 | (* | |
7063 | ReadByte - reads a BYTE, b, from file, f. | |
7064 | f.res is set appropriately. | |
7065 | *) | |
7066 | ||
7067 | @findex ReadByte | |
7068 | PROCEDURE ReadByte (VAR f: File; VAR b: BYTE) ; | |
7069 | ||
7070 | ||
7071 | (* | |
7072 | WriteByte - writes one BYTE, b, to a file, f. | |
7073 | f.res is set appropriately. | |
7074 | *) | |
7075 | ||
7076 | @findex WriteByte | |
7077 | PROCEDURE WriteByte (VAR f: File; b: BYTE) ; | |
7078 | ||
7079 | ||
7080 | (* | |
7081 | ReadNBytes - reads a sequence of bytes from a file, f. | |
7082 | *) | |
7083 | ||
7084 | @findex ReadNBytes | |
7085 | PROCEDURE ReadNBytes (VAR f: File; a: ADDRESS; amount: CARDINAL; | |
7086 | VAR actuallyRead: CARDINAL) ; | |
7087 | ||
7088 | ||
7089 | (* | |
7090 | WriteNBytes - writes a sequence of bytes to file, f. | |
7091 | *) | |
7092 | ||
7093 | @findex WriteNBytes | |
7094 | PROCEDURE WriteNBytes (VAR f: File; a: ADDRESS; amount: CARDINAL; | |
7095 | VAR actuallyWritten: CARDINAL) ; | |
7096 | ||
7097 | ||
7098 | (* | |
7099 | Again - returns the last character read to the internal buffer | |
7100 | so that it can be read again. | |
7101 | *) | |
7102 | ||
7103 | @findex Again | |
7104 | PROCEDURE Again (VAR f: File) ; | |
7105 | ||
7106 | ||
7107 | (* | |
7108 | SetRead - puts the file, f, into the read state. | |
7109 | The file position is unchanged. | |
7110 | *) | |
7111 | ||
7112 | @findex SetRead | |
7113 | PROCEDURE SetRead (VAR f: File) ; | |
7114 | ||
7115 | ||
7116 | (* | |
7117 | SetWrite - puts the file, f, into the write state. | |
7118 | The file position is unchanged. | |
7119 | *) | |
7120 | ||
7121 | @findex SetWrite | |
7122 | PROCEDURE SetWrite (VAR f: File) ; | |
7123 | ||
7124 | ||
7125 | (* | |
7126 | SetModify - puts the file, f, into the modify state. | |
7127 | The file position is unchanged but the file can be | |
7128 | read and written. | |
7129 | *) | |
7130 | ||
7131 | @findex SetModify | |
7132 | PROCEDURE SetModify (VAR f: File) ; | |
7133 | ||
7134 | ||
7135 | (* | |
7136 | SetOpen - places a file, f, into the open state. The file may | |
7137 | have been in the read/write/modify state before and | |
7138 | in which case the previous buffer contents are flushed | |
7139 | and the file state is reset to open. The position is | |
7140 | unaltered. | |
7141 | *) | |
7142 | ||
7143 | @findex SetOpen | |
7144 | PROCEDURE SetOpen (VAR f: File) ; | |
7145 | ||
7146 | ||
7147 | (* | |
7148 | Reset - places a file, f, into the open state and reset the | |
7149 | position to the start of the file. | |
7150 | *) | |
7151 | ||
7152 | @findex Reset | |
7153 | PROCEDURE Reset (VAR f: File) ; | |
7154 | ||
7155 | ||
7156 | (* | |
7157 | SetPos - lseek to a position within a file. | |
7158 | *) | |
7159 | ||
7160 | @findex SetPos | |
7161 | PROCEDURE SetPos (VAR f: File; high, low: CARDINAL) ; | |
7162 | ||
7163 | ||
7164 | (* | |
7165 | GetPos - return the position within a file. | |
7166 | *) | |
7167 | ||
7168 | @findex GetPos | |
7169 | PROCEDURE GetPos (VAR f: File; VAR high, low: CARDINAL) ; | |
7170 | ||
7171 | ||
7172 | (* | |
7173 | Length - returns the length of file, in, high, and, low. | |
7174 | *) | |
7175 | ||
7176 | @findex Length | |
7177 | PROCEDURE Length (VAR f: File; VAR high, low: CARDINAL) ; | |
7178 | ||
7179 | ||
7180 | (* | |
7181 | Doio - effectively flushes a file in write mode, rereads the | |
7182 | current buffer from disk if in read mode and writes | |
7183 | and rereads the buffer if in modify mode. | |
7184 | *) | |
7185 | ||
7186 | @findex Doio | |
7187 | PROCEDURE Doio (VAR f: File) ; | |
7188 | ||
7189 | ||
7190 | (* | |
7191 | FileNameChar - checks to see whether the character, ch, is | |
7192 | legal in a filename. nul is returned if the | |
7193 | character was illegal. | |
7194 | *) | |
7195 | ||
7196 | @findex FileNameChar | |
7197 | PROCEDURE FileNameChar (ch: CHAR) ; | |
7198 | ||
7199 | ||
7200 | END FileSystem. | |
7201 | @end example | |
7202 | @page | |
7203 | ||
7204 | @node gm2-libs-pim/FloatingUtilities, gm2-libs-pim/InOut, gm2-libs-pim/FileSystem, PIM and Logitech 3.0 Compatible | |
7205 | @subsection gm2-libs-pim/FloatingUtilities | |
7206 | ||
7207 | @example | |
7208 | DEFINITION MODULE FloatingUtilities ; | |
7209 | ||
7210 | EXPORT QUALIFIED Frac, Round, Float, Trunc, | |
7211 | Fracl, Roundl, Floatl, Truncl ; | |
7212 | ||
7213 | ||
7214 | (* | |
7215 | Frac - returns the fractional component of, r. | |
7216 | *) | |
7217 | ||
7218 | @findex Frac | |
7219 | PROCEDURE Frac (r: REAL) : REAL ; | |
7220 | ||
7221 | ||
7222 | (* | |
7223 | Int - returns the integer part of r. It rounds the value towards zero. | |
7224 | *) | |
7225 | ||
7226 | @findex Int | |
7227 | PROCEDURE Int (r: REAL) : INTEGER ; | |
7228 | ||
7229 | ||
7230 | (* | |
7231 | Round - returns the number rounded to the nearest integer. | |
7232 | *) | |
7233 | ||
7234 | @findex Round | |
7235 | PROCEDURE Round (r: REAL) : INTEGER ; | |
7236 | ||
7237 | ||
7238 | (* | |
7239 | Float - returns a REAL value corresponding to, i. | |
7240 | *) | |
7241 | ||
7242 | @findex Float | |
7243 | PROCEDURE Float (i: INTEGER) : REAL ; | |
7244 | ||
7245 | ||
7246 | (* | |
7247 | Trunc - round to the nearest integer not larger in absolute | |
7248 | value. | |
7249 | *) | |
7250 | ||
7251 | @findex Trunc | |
7252 | PROCEDURE Trunc (r: REAL) : INTEGER ; | |
7253 | ||
7254 | ||
7255 | (* | |
7256 | Fracl - returns the fractional component of, r. | |
7257 | *) | |
7258 | ||
7259 | @findex Fracl | |
7260 | PROCEDURE Fracl (r: LONGREAL) : LONGREAL ; | |
7261 | ||
7262 | ||
7263 | (* | |
7264 | Intl - returns the integer part of r. It rounds the value towards zero. | |
7265 | *) | |
7266 | ||
7267 | @findex Intl | |
7268 | PROCEDURE Intl (r: LONGREAL) : LONGINT ; | |
7269 | ||
7270 | ||
7271 | (* | |
7272 | Roundl - returns the number rounded to the nearest integer. | |
7273 | *) | |
7274 | ||
7275 | @findex Roundl | |
7276 | PROCEDURE Roundl (r: LONGREAL) : LONGINT ; | |
7277 | ||
7278 | ||
7279 | (* | |
7280 | Floatl - returns a REAL value corresponding to, i. | |
7281 | *) | |
7282 | ||
7283 | @findex Floatl | |
7284 | PROCEDURE Floatl (i: INTEGER) : LONGREAL ; | |
7285 | ||
7286 | ||
7287 | (* | |
7288 | Truncl - round to the nearest integer not larger in absolute | |
7289 | value. | |
7290 | *) | |
7291 | ||
7292 | @findex Truncl | |
7293 | PROCEDURE Truncl (r: LONGREAL) : LONGINT ; | |
7294 | ||
7295 | ||
7296 | END FloatingUtilities. | |
7297 | @end example | |
7298 | @page | |
7299 | ||
7300 | @node gm2-libs-pim/InOut, gm2-libs-pim/Keyboard, gm2-libs-pim/FloatingUtilities, PIM and Logitech 3.0 Compatible | |
7301 | @subsection gm2-libs-pim/InOut | |
7302 | ||
7303 | @example | |
7304 | DEFINITION MODULE InOut ; | |
7305 | ||
7306 | IMPORT ASCII ; | |
7307 | FROM DynamicStrings IMPORT String ; | |
7308 | EXPORT QUALIFIED EOL, Done, termCH, OpenInput, OpenOutput, | |
7309 | CloseInput, CloseOutput, | |
7310 | Read, ReadString, ReadInt, ReadCard, | |
7311 | Write, WriteLn, WriteString, WriteInt, WriteCard, | |
7312 | WriteOct, WriteHex, | |
7313 | ReadS, WriteS ; | |
7314 | ||
7315 | CONST | |
7316 | @findex EOL (const) | |
7317 | EOL = ASCII.EOL ; | |
7318 | ||
7319 | VAR | |
7320 | @findex Done (var) | |
7321 | Done : BOOLEAN ; | |
7322 | @findex termCH (var) | |
7323 | termCH: CHAR ; | |
7324 | ||
7325 | ||
7326 | (* | |
7327 | OpenInput - reads a string from stdin as the filename for reading. | |
7328 | If the filename ends with `.' then it appends the defext | |
7329 | extension. The global variable Done is set if all | |
7330 | was successful. | |
7331 | *) | |
7332 | ||
7333 | @findex OpenInput | |
7334 | PROCEDURE OpenInput (defext: ARRAY OF CHAR) ; | |
7335 | ||
7336 | ||
7337 | (* | |
7338 | CloseInput - closes an opened input file and returns input back to | |
7339 | StdIn. | |
7340 | *) | |
7341 | ||
7342 | @findex CloseInput | |
7343 | PROCEDURE CloseInput ; | |
7344 | ||
7345 | ||
7346 | (* | |
7347 | OpenOutput - reads a string from stdin as the filename for writing. | |
7348 | If the filename ends with `.' then it appends the defext | |
7349 | extension. The global variable Done is set if all | |
7350 | was successful. | |
7351 | *) | |
7352 | ||
7353 | @findex OpenOutput | |
7354 | PROCEDURE OpenOutput (defext: ARRAY OF CHAR) ; | |
7355 | ||
7356 | ||
7357 | (* | |
7358 | CloseOutput - closes an opened output file and returns output back to | |
7359 | StdOut. | |
7360 | *) | |
7361 | ||
7362 | @findex CloseOutput | |
7363 | PROCEDURE CloseOutput ; | |
7364 | ||
7365 | ||
7366 | (* | |
7367 | Read - reads a single character from the current input file. | |
7368 | Done is set to FALSE if end of file is reached or an | |
7369 | error occurs. | |
7370 | *) | |
7371 | ||
7372 | @findex Read | |
7373 | PROCEDURE Read (VAR ch: CHAR) ; | |
7374 | ||
7375 | ||
7376 | (* | |
7377 | ReadString - reads a sequence of characters. Leading white space | |
7378 | is ignored and the string is terminated with a character | |
7379 | <= ' ' | |
7380 | *) | |
7381 | ||
7382 | @findex ReadString | |
7383 | PROCEDURE ReadString (VAR s: ARRAY OF CHAR) ; | |
7384 | ||
7385 | ||
7386 | (* | |
7387 | WriteString - writes a string to the output file. | |
7388 | *) | |
7389 | ||
7390 | @findex WriteString | |
7391 | PROCEDURE WriteString (s: ARRAY OF CHAR) ; | |
7392 | ||
7393 | ||
7394 | (* | |
7395 | Write - writes out a single character, ch, to the current output file. | |
7396 | *) | |
7397 | ||
7398 | @findex Write | |
7399 | PROCEDURE Write (ch: CHAR) ; | |
7400 | ||
7401 | ||
7402 | (* | |
7403 | WriteLn - writes a newline to the output file. | |
7404 | *) | |
7405 | ||
7406 | @findex WriteLn | |
7407 | PROCEDURE WriteLn ; | |
7408 | ||
7409 | ||
7410 | (* | |
7411 | ReadInt - reads a string and converts it into an INTEGER, x. | |
7412 | Done is set if an INTEGER is read. | |
7413 | *) | |
7414 | ||
7415 | @findex ReadInt | |
7416 | PROCEDURE ReadInt (VAR x: INTEGER) ; | |
7417 | ||
7418 | ||
7419 | (* | |
7420 | ReadInt - reads a string and converts it into an INTEGER, x. | |
7421 | Done is set if an INTEGER is read. | |
7422 | *) | |
7423 | ||
7424 | @findex ReadCard | |
7425 | PROCEDURE ReadCard (VAR x: CARDINAL) ; | |
7426 | ||
7427 | ||
7428 | (* | |
7429 | WriteCard - writes the CARDINAL, x, to the output file. It ensures | |
7430 | that the number occupies, n, characters. Leading spaces | |
7431 | are added if required. | |
7432 | *) | |
7433 | ||
7434 | @findex WriteCard | |
7435 | PROCEDURE WriteCard (x, n: CARDINAL) ; | |
7436 | ||
7437 | ||
7438 | (* | |
7439 | WriteInt - writes the INTEGER, x, to the output file. It ensures | |
7440 | that the number occupies, n, characters. Leading spaces | |
7441 | are added if required. | |
7442 | *) | |
7443 | ||
7444 | @findex WriteInt | |
7445 | PROCEDURE WriteInt (x: INTEGER; n: CARDINAL) ; | |
7446 | ||
7447 | ||
7448 | (* | |
7449 | WriteOct - writes the CARDINAL, x, to the output file in octal. | |
7450 | It ensures that the number occupies, n, characters. | |
7451 | Leading spaces are added if required. | |
7452 | *) | |
7453 | ||
7454 | @findex WriteOct | |
7455 | PROCEDURE WriteOct (x, n: CARDINAL) ; | |
7456 | ||
7457 | ||
7458 | (* | |
7459 | WriteHex - writes the CARDINAL, x, to the output file in hexadecimal. | |
7460 | It ensures that the number occupies, n, characters. | |
7461 | Leading spaces are added if required. | |
7462 | *) | |
7463 | ||
7464 | @findex WriteHex | |
7465 | PROCEDURE WriteHex (x, n: CARDINAL) ; | |
7466 | ||
7467 | ||
7468 | (* | |
7469 | ReadS - returns a string which has is a sequence of characters. | |
7470 | Leading white space is ignored and string is terminated | |
7471 | with a character <= ' '. | |
7472 | *) | |
7473 | ||
7474 | @findex ReadS | |
7475 | PROCEDURE ReadS () : String ; | |
7476 | ||
7477 | ||
7478 | (* | |
7479 | WriteS - writes a String to the output device. | |
7480 | It returns the string, s. | |
7481 | *) | |
7482 | ||
7483 | @findex WriteS | |
7484 | PROCEDURE WriteS (s: String) : String ; | |
7485 | ||
7486 | ||
7487 | END InOut. | |
7488 | @end example | |
7489 | @page | |
7490 | ||
7491 | @node gm2-libs-pim/Keyboard, gm2-libs-pim/LongIO, gm2-libs-pim/InOut, PIM and Logitech 3.0 Compatible | |
7492 | @subsection gm2-libs-pim/Keyboard | |
7493 | ||
7494 | @example | |
7495 | DEFINITION MODULE Keyboard ; | |
7496 | ||
7497 | EXPORT QUALIFIED Read, KeyPressed ; | |
7498 | ||
7499 | ||
7500 | (* | |
7501 | Read - reads a character from StdIn. If necessary it will wait | |
7502 | for a key to become present on StdIn. | |
7503 | *) | |
7504 | ||
7505 | @findex Read | |
7506 | PROCEDURE Read (VAR ch: CHAR) ; | |
7507 | ||
7508 | ||
7509 | (* | |
7510 | KeyPressed - returns TRUE if a character can be read from StdIn | |
7511 | without blocking the caller. | |
7512 | *) | |
7513 | ||
7514 | @findex KeyPressed | |
7515 | PROCEDURE KeyPressed () : BOOLEAN ; | |
7516 | ||
7517 | ||
7518 | END Keyboard. | |
7519 | @end example | |
7520 | @page | |
7521 | ||
7522 | @node gm2-libs-pim/LongIO, gm2-libs-pim/NumberConversion, gm2-libs-pim/Keyboard, PIM and Logitech 3.0 Compatible | |
7523 | @subsection gm2-libs-pim/LongIO | |
7524 | ||
7525 | @example | |
7526 | DEFINITION MODULE LongIO ; | |
7527 | ||
7528 | EXPORT QUALIFIED Done, ReadLongInt, WriteLongInt ; | |
7529 | ||
7530 | VAR | |
7531 | @findex Done (var) | |
7532 | Done: BOOLEAN ; | |
7533 | ||
7534 | @findex ReadLongInt | |
7535 | PROCEDURE ReadLongInt (VAR i: LONGINT) ; | |
7536 | @findex WriteLongInt | |
7537 | PROCEDURE WriteLongInt (i: LONGINT; n: CARDINAL) ; | |
7538 | ||
7539 | ||
7540 | END LongIO. | |
7541 | @end example | |
7542 | @page | |
7543 | ||
7544 | @node gm2-libs-pim/NumberConversion, gm2-libs-pim/Random, gm2-libs-pim/LongIO, PIM and Logitech 3.0 Compatible | |
7545 | @subsection gm2-libs-pim/NumberConversion | |
7546 | ||
7547 | @example | |
7548 | DEFINITION MODULE NumberConversion ; | |
7549 | ||
7550 | (* --fixme-- finish this. *) | |
7551 | ||
7552 | END NumberConversion. | |
7553 | @end example | |
7554 | @page | |
7555 | ||
7556 | @node gm2-libs-pim/Random, gm2-libs-pim/RealConversions, gm2-libs-pim/NumberConversion, PIM and Logitech 3.0 Compatible | |
7557 | @subsection gm2-libs-pim/Random | |
7558 | ||
7559 | @example | |
7560 | DEFINITION MODULE Random ; | |
7561 | ||
7562 | FROM SYSTEM IMPORT BYTE ; | |
7563 | EXPORT QUALIFIED Randomize, RandomInit, RandomBytes, RandomCard, RandomInt, RandomReal, RandomLongReal ; | |
7564 | ||
7565 | ||
7566 | (* | |
7567 | Randomize - initialize the random number generator with a seed | |
7568 | based on the microseconds. | |
7569 | *) | |
7570 | ||
7571 | @findex Randomize | |
7572 | PROCEDURE Randomize ; | |
7573 | ||
7574 | ||
7575 | (* | |
7576 | RandomInit - initialize the random number generator with value, seed. | |
7577 | *) | |
7578 | ||
7579 | @findex RandomInit | |
7580 | PROCEDURE RandomInit (seed: CARDINAL) ; | |
7581 | ||
7582 | ||
7583 | (* | |
7584 | RandomBytes - fills in an array with random values. | |
7585 | *) | |
7586 | ||
7587 | @findex RandomBytes | |
7588 | PROCEDURE RandomBytes (VAR a: ARRAY OF BYTE) ; | |
7589 | ||
7590 | ||
7591 | (* | |
7592 | RandomInt - return an INTEGER in the range 0..bound-1 | |
7593 | *) | |
7594 | ||
7595 | @findex RandomInt | |
7596 | PROCEDURE RandomInt (bound: INTEGER) : INTEGER ; | |
7597 | ||
7598 | ||
7599 | (* | |
7600 | RandomCard - return a CARDINAL in the range 0..bound-1 | |
7601 | *) | |
7602 | ||
7603 | @findex RandomCard | |
7604 | PROCEDURE RandomCard (bound: CARDINAL) : CARDINAL ; | |
7605 | ||
7606 | ||
7607 | (* | |
7608 | RandomReal - return a REAL number in the range 0.0..1.0 | |
7609 | *) | |
7610 | ||
7611 | @findex RandomReal | |
7612 | PROCEDURE RandomReal () : REAL ; | |
7613 | ||
7614 | ||
7615 | (* | |
7616 | RandomLongReal - return a LONGREAL number in the range 0.0..1.0 | |
7617 | *) | |
7618 | ||
7619 | @findex RandomLongReal | |
7620 | PROCEDURE RandomLongReal () : LONGREAL ; | |
7621 | ||
7622 | ||
7623 | END Random. | |
7624 | @end example | |
7625 | @page | |
7626 | ||
7627 | @node gm2-libs-pim/RealConversions, gm2-libs-pim/RealInOut, gm2-libs-pim/Random, PIM and Logitech 3.0 Compatible | |
7628 | @subsection gm2-libs-pim/RealConversions | |
7629 | ||
7630 | @example | |
7631 | DEFINITION MODULE RealConversions ; | |
7632 | ||
7633 | EXPORT QUALIFIED SetNoOfExponentDigits, | |
7634 | RealToString, StringToReal, | |
7635 | LongRealToString, StringToLongReal ; | |
7636 | ||
7637 | ||
7638 | (* | |
7639 | SetNoOfExponentDigits - sets the number of exponent digits to be | |
7640 | used during future calls of LongRealToString | |
7641 | and RealToString providing that the width | |
7642 | is sufficient. | |
7643 | If this value is set to 0 (the default) then | |
7644 | the number digits used is the minimum necessary. | |
7645 | *) | |
7646 | ||
7647 | @findex SetNoOfExponentDigits | |
7648 | PROCEDURE SetNoOfExponentDigits (places: CARDINAL) ; | |
7649 | ||
7650 | ||
7651 | (* | |
7652 | RealToString - converts a real, r, into a right justified string, str. | |
7653 | The number of digits to the right of the decimal point | |
7654 | is given in, digits. The value, width, represents the | |
7655 | maximum number of characters to be used in the string, | |
7656 | str. | |
7657 | ||
7658 | If digits is negative then exponent notation is used | |
7659 | whereas if digits is positive then fixed point notation | |
7660 | is used. | |
7661 | ||
7662 | If, r, is less than 0.0 then a '-' preceeds the value, | |
7663 | str. However, if, r, is >= 0.0 a '+' is not added. | |
7664 | ||
7665 | If the conversion of, r, to a string requires more | |
7666 | than, width, characters then the string, str, is set | |
7667 | to a nul string and, ok is assigned FALSE. | |
7668 | ||
7669 | For fixed point notation the minimum width required is | |
7670 | ABS(width)+8 | |
7671 | ||
7672 | For exponent notation the minimum width required is | |
7673 | ABS(digits)+2+log10(magnitude). | |
7674 | ||
7675 | if r is a NaN then the string 'nan' is returned formatted and | |
7676 | ok will be FALSE. | |
7677 | *) | |
7678 | ||
7679 | @findex RealToString | |
7680 | PROCEDURE RealToString (r: REAL; digits, width: INTEGER; | |
7681 | VAR str: ARRAY OF CHAR; VAR ok: BOOLEAN) ; | |
7682 | ||
7683 | ||
7684 | (* | |
7685 | LongRealToString - converts a real, r, into a right justified string, str. | |
7686 | The number of digits to the right of the decimal point | |
7687 | is given in, digits. The value, width, represents the | |
7688 | maximum number of characters to be used in the string, | |
7689 | str. | |
7690 | ||
7691 | If digits is negative then exponent notation is used | |
7692 | whereas if digits is positive then fixed point notation | |
7693 | is used. | |
7694 | ||
7695 | If, r, is less than 0.0 then a '-' preceeds the value, | |
7696 | str. However, if, r, is >= 0.0 a '+' is not added. | |
7697 | ||
7698 | If the conversion of, r, to a string requires more | |
7699 | than, width, characters then the string, str, is set | |
7700 | to a nul string and, ok is assigned FALSE. | |
7701 | ||
7702 | For fixed point notation the minimum width required is | |
7703 | ABS(width)+8 | |
7704 | ||
7705 | For exponent notation the minimum width required is | |
7706 | ABS(digits)+2+log10(magnitude). | |
7707 | ||
7708 | Examples: | |
7709 | RealToString(100.0, 10, 10, a, ok) -> '100.000000' | |
7710 | RealToString(100.0, -5, 12, a, ok) -> ' 1.00000E+2' | |
7711 | ||
7712 | RealToString(123.456789, 10, 10, a, ok) -> '123.456789' | |
7713 | RealToString(123.456789, -5, 13, a, ok) -> ' 1.23456E+2' | |
7714 | ||
7715 | RealToString(123.456789, -2, 15, a, ok) -> ' 1.23E+2' | |
7716 | ||
7717 | if r is a NaN then the string 'nan' is returned formatted and | |
7718 | ok will be FALSE. | |
7719 | *) | |
7720 | ||
7721 | @findex LongRealToString | |
7722 | PROCEDURE LongRealToString (r: LONGREAL; digits, width: INTEGER; | |
7723 | VAR str: ARRAY OF CHAR; VAR ok: BOOLEAN) ; | |
7724 | ||
7725 | ||
7726 | (* | |
7727 | StringToReal - converts, str, into a REAL, r. The parameter, ok, is | |
7728 | set to TRUE if the conversion was successful. | |
7729 | *) | |
7730 | ||
7731 | @findex StringToReal | |
7732 | PROCEDURE StringToReal (str: ARRAY OF CHAR; VAR r: REAL; VAR ok: BOOLEAN) ; | |
7733 | ||
7734 | ||
7735 | (* | |
7736 | StringToLongReal - converts, str, into a LONGREAL, r. The parameter, ok, is | |
7737 | set to TRUE if the conversion was successful. | |
7738 | *) | |
7739 | ||
7740 | @findex StringToLongReal | |
7741 | PROCEDURE StringToLongReal (str: ARRAY OF CHAR; VAR r: LONGREAL; VAR ok: BOOLEAN) ; | |
7742 | ||
7743 | ||
7744 | END RealConversions. | |
7745 | @end example | |
7746 | @page | |
7747 | ||
7748 | @node gm2-libs-pim/RealInOut, gm2-libs-pim/Strings, gm2-libs-pim/RealConversions, PIM and Logitech 3.0 Compatible | |
7749 | @subsection gm2-libs-pim/RealInOut | |
7750 | ||
7751 | @example | |
7752 | DEFINITION MODULE RealInOut ; | |
7753 | ||
7754 | EXPORT QUALIFIED SetNoOfDecimalPlaces, | |
7755 | ReadReal, WriteReal, WriteRealOct, | |
7756 | ReadLongReal, WriteLongReal, WriteLongRealOct, | |
7757 | ReadShortReal, WriteShortReal, WriteShortRealOct, | |
7758 | Done ; | |
7759 | ||
7760 | CONST | |
7761 | @findex DefaultDecimalPlaces (const) | |
7762 | DefaultDecimalPlaces = 6 ; | |
7763 | ||
7764 | VAR | |
7765 | @findex Done (var) | |
7766 | Done: BOOLEAN ; | |
7767 | ||
7768 | ||
7769 | (* | |
7770 | SetNoOfDecimalPlaces - number of decimal places WriteReal and | |
7771 | WriteLongReal should emit. This procedure | |
7772 | can be used to override the default | |
7773 | DefaultDecimalPlaces constant. | |
7774 | *) | |
7775 | ||
7776 | @findex SetNoOfDecimalPlaces | |
7777 | PROCEDURE SetNoOfDecimalPlaces (places: CARDINAL) ; | |
7778 | ||
7779 | ||
7780 | (* | |
7781 | ReadReal - reads a real number, legal syntaxes include: | |
7782 | 100, 100.0, 100e0, 100E0, 100E-1, E2, +1E+2, 1e+2 | |
7783 | *) | |
7784 | ||
7785 | @findex ReadReal | |
7786 | PROCEDURE ReadReal (VAR x: REAL) ; | |
7787 | ||
7788 | ||
7789 | (* | |
7790 | WriteReal - writes a real to the terminal. The real number | |
7791 | is right justified and, n, is the minimum field | |
7792 | width. | |
7793 | *) | |
7794 | ||
7795 | @findex WriteReal | |
7796 | PROCEDURE WriteReal (x: REAL; n: CARDINAL) ; | |
7797 | ||
7798 | ||
7799 | (* | |
7800 | WriteRealOct - writes the real to terminal in octal words. | |
7801 | *) | |
7802 | ||
7803 | @findex WriteRealOct | |
7804 | PROCEDURE WriteRealOct (x: REAL) ; | |
7805 | ||
7806 | ||
7807 | (* | |
7808 | ReadLongReal - reads a LONGREAL number, legal syntaxes include: | |
7809 | 100, 100.0, 100e0, 100E0, 100E-1, E2, +1E+2, 1e+2 | |
7810 | *) | |
7811 | ||
7812 | @findex ReadLongReal | |
7813 | PROCEDURE ReadLongReal (VAR x: LONGREAL) ; | |
7814 | ||
7815 | ||
7816 | (* | |
7817 | WriteLongReal - writes a LONGREAL to the terminal. The real number | |
7818 | is right justified and, n, is the minimum field | |
7819 | width. | |
7820 | *) | |
7821 | ||
7822 | @findex WriteLongReal | |
7823 | PROCEDURE WriteLongReal (x: LONGREAL; n: CARDINAL) ; | |
7824 | ||
7825 | ||
7826 | (* | |
7827 | WriteLongRealOct - writes the LONGREAL to terminal in octal words. | |
7828 | *) | |
7829 | ||
7830 | @findex WriteLongRealOct | |
7831 | PROCEDURE WriteLongRealOct (x: LONGREAL) ; | |
7832 | ||
7833 | ||
7834 | (* | |
7835 | ReadShortReal - reads a SHORTREAL number, legal syntaxes include: | |
7836 | 100, 100.0, 100e0, 100E0, 100E-1, E2, +1E+2, 1e+2 | |
7837 | *) | |
7838 | ||
7839 | @findex ReadShortReal | |
7840 | PROCEDURE ReadShortReal (VAR x: SHORTREAL) ; | |
7841 | ||
7842 | ||
7843 | (* | |
7844 | WriteShortReal - writes a SHORTREAL to the terminal. The real number | |
7845 | is right justified and, n, is the minimum field | |
7846 | width. | |
7847 | *) | |
7848 | ||
7849 | @findex WriteShortReal | |
7850 | PROCEDURE WriteShortReal (x: SHORTREAL; n: CARDINAL) ; | |
7851 | ||
7852 | ||
7853 | (* | |
7854 | WriteShortRealOct - writes the SHORTREAL to terminal in octal words. | |
7855 | *) | |
7856 | ||
7857 | @findex WriteShortRealOct | |
7858 | PROCEDURE WriteShortRealOct (x: SHORTREAL) ; | |
7859 | ||
7860 | ||
7861 | END RealInOut. | |
7862 | @end example | |
7863 | @page | |
7864 | ||
7865 | @node gm2-libs-pim/Strings, gm2-libs-pim/Termbase, gm2-libs-pim/RealInOut, PIM and Logitech 3.0 Compatible | |
7866 | @subsection gm2-libs-pim/Strings | |
7867 | ||
7868 | @example | |
7869 | DEFINITION MODULE Strings ; | |
7870 | ||
7871 | EXPORT QUALIFIED Assign, Insert, Delete, Pos, Copy, ConCat, Length, | |
7872 | CompareStr ; | |
7873 | ||
7874 | (* | |
7875 | Assign - dest := source. | |
7876 | *) | |
7877 | ||
7878 | @findex Assign | |
7879 | PROCEDURE Assign (VAR dest: ARRAY OF CHAR; source: ARRAY OF CHAR) ; | |
7880 | ||
7881 | ||
7882 | (* | |
7883 | Insert - insert the string, substr, into str at position, index. | |
7884 | substr, is added to the end of, str, if, index >= length(str) | |
7885 | *) | |
7886 | ||
7887 | @findex Insert | |
7888 | PROCEDURE Insert (substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR; | |
7889 | index: CARDINAL) ; | |
7890 | ||
7891 | ||
7892 | (* | |
7893 | Delete - delete len characters from, str, starting at, index. | |
7894 | *) | |
7895 | ||
7896 | @findex Delete | |
7897 | PROCEDURE Delete (VAR str: ARRAY OF CHAR; index: CARDINAL; length: CARDINAL) ; | |
7898 | ||
7899 | ||
7900 | (* | |
7901 | Pos - return the first position of, substr, in, str. | |
7902 | *) | |
7903 | ||
7904 | @findex Pos | |
7905 | PROCEDURE Pos (substr, str: ARRAY OF CHAR) : CARDINAL ; | |
7906 | ||
7907 | ||
7908 | (* | |
7909 | Copy - copy at most, length, characters in, substr, to, str, | |
7910 | starting at position, index. | |
7911 | *) | |
7912 | ||
7913 | @findex Copy | |
7914 | PROCEDURE Copy (str: ARRAY OF CHAR; | |
7915 | index, length: CARDINAL; VAR result: ARRAY OF CHAR) ; | |
7916 | ||
7917 | (* | |
7918 | ConCat - concatenates two strings, s1, and, s2 | |
7919 | and places the result into, dest. | |
7920 | *) | |
7921 | ||
7922 | @findex ConCat | |
7923 | PROCEDURE ConCat (s1, s2: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR) ; | |
7924 | ||
7925 | ||
7926 | (* | |
7927 | Length - return the length of string, s. | |
7928 | *) | |
7929 | ||
7930 | @findex Length | |
7931 | PROCEDURE Length (s: ARRAY OF CHAR) : CARDINAL ; | |
7932 | ||
7933 | ||
7934 | (* | |
7935 | CompareStr - compare two strings, left, and, right. | |
7936 | *) | |
7937 | ||
7938 | @findex CompareStr | |
7939 | PROCEDURE CompareStr (left, right: ARRAY OF CHAR) : INTEGER ; | |
7940 | ||
7941 | ||
7942 | END Strings. | |
7943 | @end example | |
7944 | @page | |
7945 | ||
7946 | @node gm2-libs-pim/Termbase, gm2-libs-pim/Terminal, gm2-libs-pim/Strings, PIM and Logitech 3.0 Compatible | |
7947 | @subsection gm2-libs-pim/Termbase | |
7948 | ||
7949 | @example | |
7950 | DEFINITION MODULE Termbase ; | |
7951 | ||
7952 | (* | |
7953 | Initially the read routines from Keyboard and the | |
7954 | write routine from Display is assigned to the Read, | |
7955 | KeyPressed and Write procedures. | |
7956 | *) | |
7957 | ||
7958 | EXPORT QUALIFIED ReadProcedure, StatusProcedure, WriteProcedure, | |
7959 | AssignRead, AssignWrite, UnAssignRead, UnAssignWrite, | |
7960 | Read, KeyPressed, Write ; | |
7961 | ||
7962 | TYPE | |
7963 | @findex ReadProcedure (type) | |
7964 | ReadProcedure = PROCEDURE (VAR CHAR) ; | |
7965 | @findex WriteProcedure (type) | |
7966 | WriteProcedure = PROCEDURE (CHAR) ; | |
7967 | @findex StatusProcedure (type) | |
7968 | StatusProcedure = PROCEDURE () : BOOLEAN ; | |
7969 | ||
7970 | ||
7971 | (* | |
7972 | AssignRead - assigns a read procedure and status procedure for terminal | |
7973 | input. Done is set to TRUE if successful. Subsequent | |
7974 | Read and KeyPressed calls are mapped onto the user supplied | |
7975 | procedures. The previous read and status procedures are | |
7976 | uncovered and reused after UnAssignRead is called. | |
7977 | *) | |
7978 | ||
7979 | @findex AssignRead | |
7980 | PROCEDURE AssignRead (rp: ReadProcedure; sp: StatusProcedure; | |
7981 | VAR Done: BOOLEAN) ; | |
7982 | ||
7983 | ||
7984 | (* | |
7985 | UnAssignRead - undo the last call to AssignRead and set Done to TRUE | |
7986 | on success. | |
7987 | *) | |
7988 | ||
7989 | @findex UnAssignRead | |
7990 | PROCEDURE UnAssignRead (VAR Done: BOOLEAN) ; | |
7991 | ||
7992 | ||
7993 | (* | |
7994 | Read - reads a single character using the currently active read | |
7995 | procedure. | |
7996 | *) | |
7997 | ||
7998 | @findex Read | |
7999 | PROCEDURE Read (VAR ch: CHAR) ; | |
8000 | ||
8001 | ||
8002 | (* | |
8003 | KeyPressed - returns TRUE if a character is available to be read. | |
8004 | *) | |
8005 | ||
8006 | @findex KeyPressed | |
8007 | PROCEDURE KeyPressed () : BOOLEAN ; | |
8008 | ||
8009 | ||
8010 | (* | |
8011 | AssignWrite - assigns a write procedure for terminal output. | |
8012 | Done is set to TRUE if successful. Subsequent | |
8013 | Write calls are mapped onto the user supplied | |
8014 | procedure. The previous write procedure is | |
8015 | uncovered and reused after UnAssignWrite is called. | |
8016 | *) | |
8017 | ||
8018 | @findex AssignWrite | |
8019 | PROCEDURE AssignWrite (wp: WriteProcedure; VAR Done: BOOLEAN) ; | |
8020 | ||
8021 | ||
8022 | (* | |
8023 | UnAssignWrite - undo the last call to AssignWrite and set Done to TRUE | |
8024 | on success. | |
8025 | *) | |
8026 | ||
8027 | @findex UnAssignWrite | |
8028 | PROCEDURE UnAssignWrite (VAR Done: BOOLEAN) ; | |
8029 | ||
8030 | ||
8031 | (* | |
8032 | Write - writes a single character using the currently active write | |
8033 | procedure. | |
8034 | *) | |
8035 | ||
8036 | @findex Write | |
8037 | PROCEDURE Write (VAR ch: CHAR) ; | |
8038 | ||
8039 | ||
8040 | END Termbase. | |
8041 | @end example | |
8042 | @page | |
8043 | ||
8044 | @node gm2-libs-pim/Terminal, gm2-libs-pim/TimeDate, gm2-libs-pim/Termbase, PIM and Logitech 3.0 Compatible | |
8045 | @subsection gm2-libs-pim/Terminal | |
8046 | ||
8047 | @example | |
8048 | DEFINITION MODULE Terminal ; | |
8049 | ||
8050 | (* | |
8051 | It provides simple terminal input output | |
8052 | routines which all utilize the TermBase module. | |
8053 | *) | |
8054 | ||
8055 | EXPORT QUALIFIED Read, KeyPressed, ReadAgain, ReadString, Write, | |
8056 | WriteString, WriteLn ; | |
8057 | ||
8058 | ||
8059 | (* | |
8060 | Read - reads a single character. | |
8061 | *) | |
8062 | ||
8063 | @findex Read | |
8064 | PROCEDURE Read (VAR ch: CHAR) ; | |
8065 | ||
8066 | ||
8067 | (* | |
8068 | KeyPressed - returns TRUE if a character can be read without blocking | |
8069 | the caller. | |
8070 | *) | |
8071 | ||
8072 | @findex KeyPressed | |
8073 | PROCEDURE KeyPressed () : BOOLEAN ; | |
8074 | ||
8075 | ||
8076 | (* | |
8077 | ReadString - reads a sequence of characters. | |
8078 | Tabs are expanded into 8 spaces and <cr> or <lf> terminates | |
8079 | the string. | |
8080 | *) | |
8081 | ||
8082 | @findex ReadString | |
8083 | PROCEDURE ReadString (VAR s: ARRAY OF CHAR) ; | |
8084 | ||
8085 | ||
8086 | (* | |
8087 | ReadAgain - makes the last character readable again. | |
8088 | *) | |
8089 | ||
8090 | @findex ReadAgain | |
8091 | PROCEDURE ReadAgain ; | |
8092 | ||
8093 | ||
8094 | (* | |
8095 | Write - writes a single character to the Termbase module. | |
8096 | *) | |
8097 | ||
8098 | @findex Write | |
8099 | PROCEDURE Write (ch: CHAR) ; | |
8100 | ||
8101 | ||
8102 | (* | |
8103 | WriteString - writes out a string which is terminated by a <nul> | |
8104 | character or the end of string HIGH(s). | |
8105 | *) | |
8106 | ||
8107 | @findex WriteString | |
8108 | PROCEDURE WriteString (s: ARRAY OF CHAR) ; | |
8109 | ||
8110 | ||
8111 | (* | |
8112 | WriteLn - writes a lf character. | |
8113 | *) | |
8114 | ||
8115 | @findex WriteLn | |
8116 | PROCEDURE WriteLn ; | |
8117 | ||
8118 | ||
8119 | END Terminal. | |
8120 | @end example | |
8121 | @page | |
8122 | ||
8123 | @node gm2-libs-pim/TimeDate, , gm2-libs-pim/Terminal, PIM and Logitech 3.0 Compatible | |
8124 | @subsection gm2-libs-pim/TimeDate | |
8125 | ||
8126 | @example | |
8127 | DEFINITION MODULE TimeDate ; | |
8128 | ||
8129 | (* | |
8130 | Legacy compatibility - you are advised to use cleaner | |
8131 | designed modules based on 'man 3 strtime' | |
8132 | and friends for new projects as the day value here is ugly. | |
8133 | [it was mapped onto MSDOS pre 2000]. | |
8134 | *) | |
8135 | ||
8136 | EXPORT QUALIFIED Time, GetTime, SetTime, CompareTime, TimeToZero, | |
8137 | TimeToString ; | |
8138 | ||
8139 | TYPE | |
8140 | (* | |
8141 | day holds: bits 0..4 = day of month (1..31) | |
8142 | 5..8 = month of year (1..12) | |
8143 | 9.. = year - 1900 | |
8144 | minute holds: hours * 60 + minutes | |
8145 | millisec holds: seconds * 1000 + millisec | |
8146 | which is reset to 0 every minute | |
8147 | *) | |
8148 | ||
8149 | Time = RECORD | |
8150 | day, minute, millisec: CARDINAL ; | |
8151 | END ; | |
8152 | ||
8153 | ||
8154 | (* | |
8155 | GetTime - returns the current date and time. | |
8156 | *) | |
8157 | ||
8158 | @findex GetTime | |
8159 | PROCEDURE GetTime (VAR curTime: Time) ; | |
8160 | ||
8161 | ||
8162 | (* | |
8163 | SetTime - does nothing, but provides compatibility with | |
8164 | the Logitech-3.0 library. | |
8165 | *) | |
8166 | ||
8167 | @findex SetTime | |
8168 | PROCEDURE SetTime (curTime: Time) ; | |
8169 | ||
8170 | ||
8171 | (* | |
8172 | CompareTime - compare two dates and time which returns: | |
8173 | ||
8174 | -1 if t1 < t2 | |
8175 | 0 if t1 = t2 | |
8176 | 1 if t1 > t2 | |
8177 | *) | |
8178 | ||
8179 | @findex CompareTime | |
8180 | PROCEDURE CompareTime (t1, t2: Time) : INTEGER ; | |
8181 | ||
8182 | ||
8183 | (* | |
8184 | TimeToZero - initializes, t, to zero. | |
8185 | *) | |
8186 | ||
8187 | @findex TimeToZero | |
8188 | PROCEDURE TimeToZero (VAR t: Time) ; | |
8189 | ||
8190 | ||
8191 | (* | |
8192 | TimeToString - convert time, t, to a string. | |
8193 | The string, s, should be at least 19 characters | |
8194 | long and the returned string will be | |
8195 | ||
8196 | yyyy-mm-dd hh:mm:ss | |
8197 | *) | |
8198 | ||
8199 | @findex TimeToString | |
8200 | PROCEDURE TimeToString (t: Time; VAR s: ARRAY OF CHAR) ; | |
8201 | ||
8202 | ||
8203 | END TimeDate. | |
8204 | @end example | |
8205 | @page | |
8206 | ||
8207 | ||
8208 | @c ------------------------------------------------------------ | |
8209 | @node PIM coroutine support, M2 ISO Libraries, PIM and Logitech 3.0 Compatible, Libraries | |
8210 | @section PIM coroutine support | |
8211 | ||
8212 | @c README.texi describes the PIM coroutine libraries. | |
83ffe9cd | 8213 | @c Copyright @copyright{} 2000-2023 Free Software Foundation, Inc. |
1eee94d3 GM |
8214 | @c |
8215 | @c This is part of the GM2 manual. | |
8216 | @c For copying conditions, see the file gcc/doc/include/fdl.texi. | |
8217 | ||
8218 | This directory contains a PIM @code{SYSTEM} containing the | |
8219 | @code{PROCESS} primitives built on top of @code{gthread}s. | |
8220 | @menu | |
8221 | * gm2-libs-coroutines/Debug::Debug.def | |
8222 | * gm2-libs-coroutines/Executive::Executive.def | |
8223 | * gm2-libs-coroutines/KeyBoardLEDs::KeyBoardLEDs.def | |
8224 | * gm2-libs-coroutines/SYSTEM::SYSTEM.def | |
8225 | * gm2-libs-coroutines/TimerHandler::TimerHandler.def | |
8226 | @end menu | |
8227 | ||
8228 | @node gm2-libs-coroutines/Debug, gm2-libs-coroutines/Executive, , PIM coroutine support | |
8229 | @subsection gm2-libs-coroutines/Debug | |
8230 | ||
8231 | @example | |
8232 | DEFINITION MODULE Debug ; | |
8233 | ||
8234 | (* | |
8235 | Description: provides some simple debugging routines. | |
8236 | *) | |
8237 | ||
8238 | EXPORT QUALIFIED Halt, DebugString, PushOutput ; | |
8239 | ||
8240 | TYPE | |
8241 | @findex WriteP (type) | |
8242 | WriteP = PROCEDURE (CHAR) ; | |
8243 | ||
8244 | ||
8245 | (* | |
8246 | Halt - writes a message in the format: | |
8247 | Module:Line:Message | |
8248 | ||
8249 | It then terminates by calling HALT. | |
8250 | *) | |
8251 | ||
8252 | @findex Halt | |
8253 | PROCEDURE Halt (File : ARRAY OF CHAR; | |
8254 | LineNo : CARDINAL; | |
8255 | Function, | |
8256 | Message : ARRAY OF CHAR) ; | |
8257 | ||
8258 | ||
8259 | (* | |
8260 | DebugString - writes a string to the debugging device (Scn.Write). | |
8261 | It interprets \n as carriage return, linefeed. | |
8262 | *) | |
8263 | ||
8264 | @findex DebugString | |
8265 | PROCEDURE DebugString (a: ARRAY OF CHAR) ; | |
8266 | ||
8267 | ||
8268 | (* | |
8269 | PushOutput - pushes the output procedure, p, which is used Debug. | |
8270 | *) | |
8271 | ||
8272 | @findex PushOutput | |
8273 | PROCEDURE PushOutput (p: WriteP) ; | |
8274 | ||
8275 | ||
8276 | (* | |
8277 | PopOutput - pops the current output procedure from the stack. | |
8278 | *) | |
8279 | ||
8280 | @findex PopOutput | |
8281 | PROCEDURE PopOutput ; | |
8282 | ||
8283 | ||
8284 | END Debug. | |
8285 | @end example | |
8286 | @page | |
8287 | ||
8288 | @node gm2-libs-coroutines/Executive, gm2-libs-coroutines/KeyBoardLEDs, gm2-libs-coroutines/Debug, PIM coroutine support | |
8289 | @subsection gm2-libs-coroutines/Executive | |
8290 | ||
8291 | @example | |
8292 | DEFINITION MODULE Executive ; | |
8293 | ||
8294 | EXPORT QUALIFIED SEMAPHORE, DESCRIPTOR, | |
8295 | InitProcess, KillProcess, Resume, Suspend, InitSemaphore, | |
8296 | Wait, Signal, WaitForIO, Ps, GetCurrentProcess, | |
8297 | RotateRunQueue, ProcessName, DebugProcess ; | |
8298 | ||
8299 | TYPE | |
8300 | @findex SEMAPHORE (type) | |
8301 | SEMAPHORE ; (* defines Dijkstra's semaphores *) | |
8302 | @findex DESCRIPTOR (type) | |
8303 | DESCRIPTOR ; (* handle onto a process *) | |
8304 | ||
8305 | ||
8306 | (* | |
8307 | InitProcess - initializes a process which is held in the suspended | |
8308 | state. When the process is resumed it will start executing | |
8309 | procedure, p. The process has a maximum stack size of, | |
8310 | StackSize, bytes and its textual name is, Name. | |
8311 | The StackSize should be at least 5000 bytes. | |
8312 | *) | |
8313 | ||
8314 | @findex InitProcess | |
8315 | PROCEDURE InitProcess (p: PROC; StackSize: CARDINAL; | |
8316 | Name: ARRAY OF CHAR) : DESCRIPTOR ; | |
8317 | ||
8318 | ||
8319 | (* | |
8320 | KillProcess - kills the current process. Notice that if InitProcess | |
8321 | is called again, it might reuse the DESCRIPTOR of the | |
8322 | killed process. It is the responsibility of the caller | |
8323 | to ensure all other processes understand this process | |
8324 | is different. | |
8325 | *) | |
8326 | ||
8327 | @findex KillProcess | |
8328 | PROCEDURE KillProcess ; | |
8329 | ||
8330 | ||
8331 | (* | |
8332 | Resume - resumes a suspended process. If all is successful then the process, p, | |
8333 | is returned. If it fails then NIL is returned. | |
8334 | *) | |
8335 | ||
8336 | @findex Resume | |
8337 | PROCEDURE Resume (d: DESCRIPTOR) : DESCRIPTOR ; | |
8338 | ||
8339 | ||
8340 | (* | |
8341 | Suspend - suspend the calling process. | |
8342 | The process can only continue running if another process | |
8343 | Resumes it. | |
8344 | *) | |
8345 | ||
8346 | @findex Suspend | |
8347 | PROCEDURE Suspend ; | |
8348 | ||
8349 | ||
8350 | (* | |
8351 | InitSemaphore - creates a semaphore whose initial value is, v, and | |
8352 | whose name is, Name. | |
8353 | *) | |
8354 | ||
8355 | @findex InitSemaphore | |
8356 | PROCEDURE InitSemaphore (v: CARDINAL; Name: ARRAY OF CHAR) : SEMAPHORE ; | |
8357 | ||
8358 | ||
8359 | (* | |
8360 | Wait - performs dijkstra's P operation on a semaphore. | |
8361 | A process which calls this procedure will | |
8362 | wait until the value of the semaphore is > 0 | |
8363 | and then it will decrement this value. | |
8364 | *) | |
8365 | ||
8366 | @findex Wait | |
8367 | PROCEDURE Wait (s: SEMAPHORE) ; | |
8368 | ||
8369 | ||
8370 | (* | |
8371 | Signal - performs dijkstra's V operation on a semaphore. | |
8372 | A process which calls the procedure will increment | |
8373 | the semaphores value. | |
8374 | *) | |
8375 | ||
8376 | @findex Signal | |
8377 | PROCEDURE Signal (s: SEMAPHORE) ; | |
8378 | ||
8379 | ||
8380 | (* | |
8381 | WaitForIO - waits for an interrupt to occur on vector, VectorNo. | |
8382 | *) | |
8383 | ||
8384 | @findex WaitForIO | |
8385 | PROCEDURE WaitForIO (VectorNo: CARDINAL) ; | |
8386 | ||
8387 | ||
8388 | (* | |
8389 | Ps - displays a process list together with process status. | |
8390 | *) | |
8391 | ||
8392 | @findex Ps | |
8393 | PROCEDURE Ps ; | |
8394 | ||
8395 | ||
8396 | (* | |
8397 | GetCurrentProcess - returns the descriptor of the current running | |
8398 | process. | |
8399 | *) | |
8400 | ||
8401 | @findex GetCurrentProcess | |
8402 | PROCEDURE GetCurrentProcess () : DESCRIPTOR ; | |
8403 | ||
8404 | ||
8405 | (* | |
8406 | RotateRunQueue - rotates the process run queue. | |
8407 | It does not call the scheduler. | |
8408 | *) | |
8409 | ||
8410 | @findex RotateRunQueue | |
8411 | PROCEDURE RotateRunQueue ; | |
8412 | ||
8413 | ||
8414 | (* | |
8415 | ProcessName - displays the name of process, d, through | |
8416 | DebugString. | |
8417 | *) | |
8418 | ||
8419 | @findex ProcessName | |
8420 | PROCEDURE ProcessName (d: DESCRIPTOR) ; | |
8421 | ||
8422 | ||
8423 | (* | |
8424 | DebugProcess - gdb debug handle to enable users to debug deadlocked | |
8425 | semaphore processes. | |
8426 | *) | |
8427 | ||
8428 | @findex DebugProcess | |
8429 | PROCEDURE DebugProcess (d: DESCRIPTOR) ; | |
8430 | ||
8431 | ||
8432 | END Executive. | |
8433 | @end example | |
8434 | @page | |
8435 | ||
8436 | @node gm2-libs-coroutines/KeyBoardLEDs, gm2-libs-coroutines/SYSTEM, gm2-libs-coroutines/Executive, PIM coroutine support | |
8437 | @subsection gm2-libs-coroutines/KeyBoardLEDs | |
8438 | ||
8439 | @example | |
8440 | DEFINITION MODULE KeyBoardLEDs ; | |
8441 | ||
8442 | ||
8443 | EXPORT QUALIFIED SwitchLeds, | |
8444 | SwitchScroll, SwitchNum, SwitchCaps ; | |
8445 | ||
8446 | ||
8447 | (* | |
8448 | SwitchLeds - switch the keyboard LEDs to the state defined | |
8449 | by the BOOLEAN variables. TRUE = ON. | |
8450 | *) | |
8451 | ||
8452 | @findex SwitchLeds | |
8453 | PROCEDURE SwitchLeds (NumLock, CapsLock, ScrollLock: BOOLEAN) ; | |
8454 | ||
8455 | ||
8456 | (* | |
8457 | SwitchScroll - switchs the scroll LED on or off. | |
8458 | *) | |
8459 | ||
8460 | @findex SwitchScroll | |
8461 | PROCEDURE SwitchScroll (Scroll: BOOLEAN) ; | |
8462 | ||
8463 | ||
8464 | (* | |
8465 | SwitchNum - switches the Num LED on or off. | |
8466 | *) | |
8467 | ||
8468 | @findex SwitchNum | |
8469 | PROCEDURE SwitchNum (Num: BOOLEAN) ; | |
8470 | ||
8471 | ||
8472 | (* | |
8473 | SwitchCaps - switches the Caps LED on or off. | |
8474 | *) | |
8475 | ||
8476 | @findex SwitchCaps | |
8477 | PROCEDURE SwitchCaps (Caps: BOOLEAN) ; | |
8478 | ||
8479 | ||
8480 | END KeyBoardLEDs. | |
8481 | @end example | |
8482 | @page | |
8483 | ||
8484 | @node gm2-libs-coroutines/SYSTEM, gm2-libs-coroutines/TimerHandler, gm2-libs-coroutines/KeyBoardLEDs, PIM coroutine support | |
8485 | @subsection gm2-libs-coroutines/SYSTEM | |
8486 | ||
8487 | @example | |
8488 | DEFINITION MODULE SYSTEM ; | |
8489 | ||
8490 | (* This module is designed to be used on a native operating system | |
8491 | rather than an embedded system as it implements the coroutine | |
8492 | primitives TRANSFER, IOTRANSFER and | |
8493 | NEWPROCESS through the GNU Pthread library. *) | |
8494 | ||
8495 | FROM COROUTINES IMPORT PROTECTION ; | |
8496 | ||
8497 | EXPORT QUALIFIED (* the following are built into the compiler: *) | |
8498 | ADDRESS, WORD, BYTE, CSIZE_T, CSSIZE_T, (* | |
8499 | Target specific data types. *) | |
8500 | ADR, TSIZE, ROTATE, SHIFT, THROW, TBITSIZE, | |
8501 | (* SIZE is exported depending upon -fpim2 and | |
8502 | -fpedantic. *) | |
8503 | (* The rest are implemented in SYSTEM.mod. *) | |
8504 | PROCESS, TRANSFER, NEWPROCESS, IOTRANSFER, | |
8505 | LISTEN, | |
8506 | ListenLoop, TurnInterrupts, | |
8507 | (* Internal GM2 compiler functions. *) | |
8508 | ShiftVal, ShiftLeft, ShiftRight, | |
8509 | RotateVal, RotateLeft, RotateRight ; | |
8510 | ||
8511 | ||
8512 | TYPE | |
8513 | @findex PROCESS (type) | |
8514 | PROCESS = RECORD | |
8515 | context: INTEGER ; | |
8516 | @findex END (type) | |
8517 | END ; | |
8518 | ||
8519 | (* Note that the full list of system and sized datatypes include: | |
8520 | LOC, WORD, BYTE, ADDRESS, | |
8521 | ||
8522 | (and the non language standard target types) | |
8523 | ||
8524 | INTEGER8, INTEGER16, INTEGER32, INTEGER64, | |
8525 | CARDINAL8, CARDINAL16, CARDINAL32, CARDINAL64, | |
8526 | WORD16, WORD32, WORD64, BITSET8, BITSET16, | |
8527 | BITSET32, REAL32, REAL64, REAL128, COMPLEX32, | |
8528 | COMPLEX64, COMPLEX128, CSIZE_T, CSSIZE_T. | |
8529 | ||
8530 | Also note that the non-standard data types will | |
8531 | move into another module in the future. *) | |
8532 | ||
8533 | (* The following types are supported on this target: | |
8534 | (* Target specific data types. *) | |
8535 | *) | |
8536 | ||
8537 | ||
8538 | (* | |
8539 | TRANSFER - save the current volatile environment into, p1. | |
8540 | Restore the volatile environment from, p2. | |
8541 | *) | |
8542 | ||
8543 | @findex TRANSFER | |
8544 | PROCEDURE TRANSFER (VAR p1: PROCESS; p2: PROCESS) ; | |
8545 | ||
8546 | ||
8547 | (* | |
8548 | NEWPROCESS - p is a parameterless procedure, a, is the origin of | |
8549 | the workspace used for the process stack and containing | |
8550 | the volatile environment of the process. StackSize, is | |
8551 | the maximum size of the stack in bytes which can be used | |
8552 | by this process. new, is the new process. | |
8553 | *) | |
8554 | ||
8555 | @findex NEWPROCESS | |
8556 | PROCEDURE NEWPROCESS (p: PROC; a: ADDRESS; StackSize: CARDINAL; VAR new: PROCESS) ; | |
8557 | ||
8558 | ||
8559 | (* | |
8560 | IOTRANSFER - saves the current volatile environment into, First, | |
8561 | and restores volatile environment, Second. | |
8562 | When an interrupt, InterruptNo, is encountered then | |
8563 | the reverse takes place. (The then current volatile | |
8564 | environment is shelved onto Second and First is resumed). | |
8565 | ||
8566 | NOTE: that upon interrupt the Second might not be the | |
8567 | same process as that before the original call to | |
8568 | IOTRANSFER. | |
8569 | *) | |
8570 | ||
8571 | @findex IOTRANSFER | |
8572 | PROCEDURE IOTRANSFER (VAR First, Second: PROCESS; InterruptNo: CARDINAL) ; | |
8573 | ||
8574 | ||
8575 | (* | |
8576 | LISTEN - briefly listen for any interrupts. | |
8577 | *) | |
8578 | ||
8579 | @findex LISTEN | |
8580 | PROCEDURE LISTEN ; | |
8581 | ||
8582 | ||
8583 | (* | |
8584 | ListenLoop - should be called instead of users writing: | |
8585 | ||
8586 | LOOP | |
8587 | LISTEN | |
8588 | END | |
8589 | ||
8590 | It performs the same function but yields | |
8591 | control back to the underlying operating system | |
8592 | via a call to pth_select. | |
8593 | It also checks for deadlock. | |
8594 | This function returns when an interrupt occurs ie | |
8595 | a file descriptor becomes ready or a time event | |
8596 | expires. See the module RTint. | |
8597 | *) | |
8598 | ||
8599 | @findex ListenLoop | |
8600 | PROCEDURE ListenLoop ; | |
8601 | ||
8602 | ||
8603 | (* | |
8604 | TurnInterrupts - switches processor interrupts to the protection | |
8605 | level, to. It returns the old value. | |
8606 | *) | |
8607 | ||
8608 | @findex TurnInterrupts | |
8609 | PROCEDURE TurnInterrupts (to: PROTECTION) : PROTECTION ; | |
8610 | ||
8611 | ||
8612 | (* | |
8613 | all the functions below are declared internally to gm2 | |
8614 | ==================================================== | |
8615 | ||
8616 | @findex ADR | |
8617 | PROCEDURE ADR (VAR v: <anytype>): ADDRESS; | |
8618 | (* Returns the address of variable v. *) | |
8619 | ||
8620 | @findex SIZE | |
8621 | PROCEDURE SIZE (v: <type>) : ZType; | |
8622 | (* Returns the number of BYTES used to store a v of | |
8623 | any specified <type>. Only available if -fpim2 is used. | |
8624 | *) | |
8625 | ||
8626 | @findex TSIZE | |
8627 | PROCEDURE TSIZE (<type>) : CARDINAL; | |
8628 | (* Returns the number of BYTES used to store a value of the | |
8629 | specified <type>. | |
8630 | *) | |
8631 | ||
8632 | @findex ROTATE | |
8633 | PROCEDURE ROTATE (val: <a set type>; | |
8634 | num: INTEGER): <type of first parameter>; | |
8635 | (* Returns a bit sequence obtained from val by rotating up or down | |
8636 | (left or right) by the absolute value of num. The direction is | |
8637 | down if the sign of num is negative, otherwise the direction is up. | |
8638 | *) | |
8639 | ||
8640 | @findex SHIFT | |
8641 | PROCEDURE SHIFT (val: <a set type>; | |
8642 | num: INTEGER): <type of first parameter>; | |
8643 | (* Returns a bit sequence obtained from val by shifting up or down | |
8644 | (left or right) by the absolute value of num, introducing | |
8645 | zeros as necessary. The direction is down if the sign of | |
8646 | num is negative, otherwise the direction is up. | |
8647 | *) | |
8648 | ||
8649 | @findex THROW | |
8650 | PROCEDURE THROW (i: INTEGER) ; | |
8651 | (* | |
8652 | THROW is a GNU extension and was not part of the PIM or ISO | |
8653 | standards. It throws an exception which will be caught by the EXCEPT | |
8654 | block (assuming it exists). This is a compiler builtin function which | |
8655 | interfaces to the GCC exception handling runtime system. | |
8656 | GCC uses the term throw, hence the naming distinction between | |
8657 | the GCC builtin and the Modula-2 runtime library procedure Raise. | |
8658 | The later library procedure Raise will call SYSTEM.THROW after | |
8659 | performing various housekeeping activities. | |
8660 | *) | |
8661 | ||
8662 | @findex TBITSIZE | |
8663 | PROCEDURE TBITSIZE (<type>) : CARDINAL ; | |
8664 | (* Returns the minimum number of bits necessary to represent | |
8665 | <type>. This procedure function is only useful for determining | |
8666 | the number of bits used for any type field within a packed RECORD. | |
8667 | It is not particularly useful elsewhere since <type> might be | |
8668 | optimized for speed, for example a BOOLEAN could occupy a WORD. | |
8669 | *) | |
8670 | *) | |
8671 | ||
8672 | (* The following procedures are invoked by GNU Modula-2 to | |
8673 | shift non word sized set types. They are not strictly part | |
8674 | of the core PIM Modula-2, however they are used | |
8675 | to implement the SHIFT procedure defined above, | |
8676 | which are in turn used by the Logitech compatible libraries. | |
8677 | ||
8678 | Users will access these procedures by using the procedure | |
8679 | SHIFT above and GNU Modula-2 will map SHIFT onto one of | |
8680 | the following procedures. | |
8681 | *) | |
8682 | ||
8683 | (* | |
8684 | ShiftVal - is a runtime procedure whose job is to implement | |
8685 | the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will | |
8686 | inline a SHIFT of a single WORD sized set and will | |
8687 | only call this routine for larger sets. | |
8688 | *) | |
8689 | ||
8690 | @findex ShiftVal | |
8691 | PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET; | |
8692 | SetSizeInBits: CARDINAL; | |
8693 | ShiftCount: INTEGER) ; | |
8694 | ||
8695 | ||
8696 | (* | |
8697 | ShiftLeft - performs the shift left for a multi word set. | |
8698 | This procedure might be called by the back end of | |
8699 | GNU Modula-2 depending whether amount is known at | |
8700 | compile time. | |
8701 | *) | |
8702 | ||
8703 | @findex ShiftLeft | |
8704 | PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET; | |
8705 | SetSizeInBits: CARDINAL; | |
8706 | ShiftCount: CARDINAL) ; | |
8707 | ||
8708 | (* | |
8709 | ShiftRight - performs the shift left for a multi word set. | |
8710 | This procedure might be called by the back end of | |
8711 | GNU Modula-2 depending whether amount is known at | |
8712 | compile time. | |
8713 | *) | |
8714 | ||
8715 | @findex ShiftRight | |
8716 | PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET; | |
8717 | SetSizeInBits: CARDINAL; | |
8718 | ShiftCount: CARDINAL) ; | |
8719 | ||
8720 | ||
8721 | (* | |
8722 | RotateVal - is a runtime procedure whose job is to implement | |
8723 | the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will | |
8724 | inline a ROTATE of a single WORD (or less) | |
8725 | sized set and will only call this routine for | |
8726 | larger sets. | |
8727 | *) | |
8728 | ||
8729 | @findex RotateVal | |
8730 | PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET; | |
8731 | SetSizeInBits: CARDINAL; | |
8732 | RotateCount: INTEGER) ; | |
8733 | ||
8734 | ||
8735 | (* | |
8736 | RotateLeft - performs the rotate left for a multi word set. | |
8737 | This procedure might be called by the back end of | |
8738 | GNU Modula-2 depending whether amount is known | |
8739 | at compile time. | |
8740 | *) | |
8741 | ||
8742 | @findex RotateLeft | |
8743 | PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET; | |
8744 | SetSizeInBits: CARDINAL; | |
8745 | RotateCount: CARDINAL) ; | |
8746 | ||
8747 | ||
8748 | (* | |
8749 | RotateRight - performs the rotate right for a multi word set. | |
8750 | This procedure might be called by the back end of | |
8751 | GNU Modula-2 depending whether amount is known at | |
8752 | compile time. | |
8753 | *) | |
8754 | ||
8755 | @findex RotateRight | |
8756 | PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET; | |
8757 | SetSizeInBits: CARDINAL; | |
8758 | RotateCount: CARDINAL) ; | |
8759 | ||
8760 | ||
8761 | END SYSTEM. | |
8762 | @end example | |
8763 | @page | |
8764 | ||
8765 | @node gm2-libs-coroutines/TimerHandler, , gm2-libs-coroutines/SYSTEM, PIM coroutine support | |
8766 | @subsection gm2-libs-coroutines/TimerHandler | |
8767 | ||
8768 | @example | |
8769 | DEFINITION MODULE TimerHandler ; | |
8770 | ||
8771 | (* It also provides the Executive with a basic round robin scheduler. *) | |
8772 | ||
8773 | EXPORT QUALIFIED TicksPerSecond, GetTicks, | |
8774 | EVENT, | |
8775 | Sleep, ArmEvent, WaitOn, Cancel, ReArmEvent ; | |
8776 | ||
8777 | ||
8778 | CONST | |
8779 | @findex TicksPerSecond (const) | |
8780 | TicksPerSecond = 25 ; (* Number of ticks per second. *) | |
8781 | ||
8782 | TYPE | |
8783 | @findex EVENT (type) | |
8784 | EVENT ; | |
8785 | ||
8786 | ||
8787 | (* | |
8788 | GetTicks - returns the number of ticks since boottime. | |
8789 | *) | |
8790 | ||
8791 | @findex GetTicks | |
8792 | PROCEDURE GetTicks () : CARDINAL ; | |
8793 | ||
8794 | ||
8795 | (* | |
8796 | Sleep - suspends the current process for a time, t. | |
8797 | The time is measured in ticks. | |
8798 | *) | |
8799 | ||
8800 | @findex Sleep | |
8801 | PROCEDURE Sleep (t: CARDINAL) ; | |
8802 | ||
8803 | ||
8804 | (* | |
8805 | ArmEvent - initializes an event, e, to occur at time, t. | |
8806 | The time, t, is measured in ticks. | |
8807 | The event is NOT placed onto the event queue. | |
8808 | *) | |
8809 | ||
8810 | @findex ArmEvent | |
8811 | PROCEDURE ArmEvent (t: CARDINAL) : EVENT ; | |
8812 | ||
8813 | ||
8814 | (* | |
8815 | WaitOn - places event, e, onto the event queue and then the calling | |
8816 | process suspends. It is resumed up by either the event | |
8817 | expiring or the event, e, being cancelled. | |
8818 | TRUE is returned if the event was cancelled | |
8819 | FALSE is returned if the event expires. | |
8820 | The event, e, is always assigned to NIL when the function | |
8821 | finishes. | |
8822 | *) | |
8823 | ||
8824 | @findex WaitOn | |
8825 | PROCEDURE WaitOn (VAR e: EVENT) : BOOLEAN ; | |
8826 | ||
8827 | ||
8828 | (* | |
8829 | Cancel - cancels the event, e, on the event queue and makes | |
8830 | the appropriate process runnable again. | |
8831 | TRUE is returned if the event was cancelled and | |
8832 | FALSE is returned is the event was not found or | |
8833 | no process was waiting on this event. | |
8834 | *) | |
8835 | ||
8836 | @findex Cancel | |
8837 | PROCEDURE Cancel (e: EVENT) : BOOLEAN ; | |
8838 | ||
8839 | ||
8840 | (* | |
8841 | ReArmEvent - removes an event, e, from the event queue. A new time | |
8842 | is given to this event and it is then re-inserted onto the | |
8843 | event queue in the correct place. | |
8844 | TRUE is returned if this occurred | |
8845 | FALSE is returned if the event was not found. | |
8846 | *) | |
8847 | ||
8848 | @findex ReArmEvent | |
8849 | PROCEDURE ReArmEvent (e: EVENT; t: CARDINAL) : BOOLEAN ; | |
8850 | ||
8851 | ||
8852 | END TimerHandler. | |
8853 | @end example | |
8854 | @page | |
8855 | ||
8856 | ||
8857 | @c ------------------------------------------------------------ | |
8858 | @node M2 ISO Libraries, , PIM coroutine support, Libraries | |
8859 | @section M2 ISO Libraries | |
8860 | ||
8861 | @c README.texi describes the ISO libraries. | |
83ffe9cd | 8862 | @c Copyright @copyright{} 2000-2023 Free Software Foundation, Inc. |
1eee94d3 GM |
8863 | @c |
8864 | @c This is part of the GM2 manual. | |
8865 | @c For copying conditions, see the file gcc/doc/include/fdl.texi. | |
8866 | ||
8867 | This directory contains the ISO definition modules and some | |
8868 | corresponding implementation modules. The definition files: | |
8869 | @file{ChanConsts.def}, @file{CharClass.def}, @file{ComplexMath.def}, | |
8870 | @file{ConvStringLong.def}, @file{ConvStringReal.def}, | |
8871 | @file{ConvTypes.def}, @file{COROUTINES.def}, @file{EXCEPTIONS.def}, | |
8872 | @file{GeneralUserExceptions.def}, @file{IOChan.def}, | |
8873 | @file{IOConsts.def}, @file{IOLink.def}, @file{IOLink.def}, | |
8874 | @file{IOResult.def}, @file{LongComplexMath.def}, @file{LongConv.def}, | |
8875 | @file{LongIO.def}, @file{LongMath.def}, @file{LongStr.def}, | |
8876 | @file{LowLong.def}, @file{LowReal.def}, @file{M2EXCEPTION.def}, | |
8877 | @file{Processes.def}, @file{ProgramArgs.def}, @file{RawIO.def}, | |
8878 | @file{RealConv.def}, @file{RealIO.def}, @file{RealMath.def}, | |
8879 | @file{RealStr.def}, @file{RndFile.def}, @file{Semaphores.def}, | |
8880 | @file{SeqFile.def}, @file{SIOResult.def}, @file{SLongIO.def}, | |
8881 | @file{SRawIO.def}, @file{SRealIO.def}, @file{StdChans.def}, | |
8882 | @file{STextIO.def}, @file{Storage.def}, @file{StreamFile.def}, | |
8883 | @file{Strings.def}, @file{SWholeIO.def}, @file{SysClock.def}, | |
8884 | @file{SYSTEM.def}, @file{TERMINATION.def}, @file{TextIO.def}, | |
8885 | @file{WholeConv.def}, @file{WholeIO.def} and @file{WholeStr.def} | |
8886 | were defined by the International Standard | |
8887 | Information technology - programming languages BS ISO/IEC | |
8888 | 10514-1:1996E Part 1: Modula-2, Base Language. | |
8889 | ||
8890 | The Copyright to the definition files @file{ChanConsts.def}, | |
8891 | @file{CharClass.def}, @file{ComplexMath.def}, | |
8892 | @file{ConvStringLong.def}, @file{ConvStringReal.def}, | |
8893 | @file{ConvTypes.def}, @file{COROUTINES.def}, @file{EXCEPTIONS.def}, | |
8894 | @file{GeneralUserExceptions.def}, @file{IOChan.def}, | |
8895 | @file{IOConsts.def}, @file{IOLink.def}, @file{IOLink.def}, | |
8896 | @file{IOResult.def}, @file{LongComplexMath.def}, @file{LongConv.def}, | |
8897 | @file{LongIO.def}, @file{LongMath.def}, @file{LongStr.def}, | |
8898 | @file{LowLong.def}, @file{LowReal.def}, @file{M2EXCEPTION.def}, | |
8899 | @file{Processes.def}, @file{ProgramArgs.def}, @file{RawIO.def}, | |
8900 | @file{RealConv.def}, @file{RealIO.def}, @file{RealMath.def}, | |
8901 | @file{RealStr.def}, @file{RndFile.def}, @file{Semaphores.def}, | |
8902 | @file{SeqFile.def}, @file{SIOResult.def}, @file{SLongIO.def}, | |
8903 | @file{SRawIO.def}, @file{SRealIO.def}, @file{StdChans.def}, | |
8904 | @file{STextIO.def}, @file{Storage.def}, @file{StreamFile.def}, | |
8905 | @file{Strings.def}, @file{SWholeIO.def}, @file{SysClock.def}, | |
8906 | @file{SYSTEM.def}, @file{TERMINATION.def}, @file{TextIO.def}, | |
8907 | @file{WholeConv.def}, @file{WholeIO.def} and @file{WholeStr.def} | |
8908 | belong to ISO/IEC (International Organization for Standardization and | |
8909 | International Electrotechnical Commission). The licence allows them | |
8910 | to be distributed with the compiler (as described on page | |
8911 | 707 of the Information technology - Programming languages Part 1: | |
8912 | Modula-2, Base Language. BS ISO/IEC 10514-1:1996). | |
8913 | ||
8914 | All implementation modules and @file{ClientSocket.def}, | |
8915 | @file{LongWholeIO.def}, @file{M2RTS.def}, @file{MemStream.def}, | |
8916 | @file{pth.def}, @file{RandomNumber.def}, @file{RTdata.def}, | |
8917 | @file{RTentity.def}, @file{RTfio.def}, @file{RTio.def}, | |
8918 | @file{ShortComplexMath.def}, @file{ShortIO.def}, | |
8919 | @file{ShortWholeIO.def}, @file{SimpleCipher.def}, | |
8920 | @file{SLongWholeIO.def}, @file{SShortIO.def}, | |
8921 | @file{SShortWholeIO.def}, @file{StringChan.def} and | |
8922 | @file{wraptime.def} are Copyright of the FSF and are held under the | |
8923 | GPLv3 with runtime exceptions. | |
8924 | ||
8925 | Under Section 7 of GPL version 3, you are granted additional | |
8926 | permissions described in the GCC Runtime Library Exception, version | |
8927 | 3.1, as published by the Free Software Foundation. | |
8928 | ||
8929 | You should have received a copy of the GNU General Public License and | |
8930 | a copy of the GCC Runtime Library Exception along with this program; | |
8931 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
8932 | @url{http://www.gnu.org/licenses/}. | |
8933 | ||
8934 | Notice that GNU Modula-2 contains additional libraries for | |
8935 | input/output of @code{SHORTREAL}, @code{SHORTCARD}, @code{SHORTINT}, | |
8936 | @code{LONGCARD}, @code{LONGINT} data types. It also provides a | |
8937 | @code{RandomNumber}, @code{SimpleCipher} and @code{ClientSocket} | |
8938 | modules as well as low level modules which allow the IO libraries to | |
8939 | coexist with their PIM counterparts. | |
8940 | @menu | |
8941 | * gm2-libs-iso/COROUTINES::COROUTINES.def | |
8942 | * gm2-libs-iso/ChanConsts::ChanConsts.def | |
8943 | * gm2-libs-iso/CharClass::CharClass.def | |
8944 | * gm2-libs-iso/ClientSocket::ClientSocket.def | |
8945 | * gm2-libs-iso/ComplexMath::ComplexMath.def | |
8946 | * gm2-libs-iso/ConvStringLong::ConvStringLong.def | |
8947 | * gm2-libs-iso/ConvStringReal::ConvStringReal.def | |
8948 | * gm2-libs-iso/ConvTypes::ConvTypes.def | |
8949 | * gm2-libs-iso/EXCEPTIONS::EXCEPTIONS.def | |
8950 | * gm2-libs-iso/ErrnoCategory::ErrnoCategory.def | |
8951 | * gm2-libs-iso/GeneralUserExceptions::GeneralUserExceptions.def | |
8952 | * gm2-libs-iso/IOChan::IOChan.def | |
8953 | * gm2-libs-iso/IOConsts::IOConsts.def | |
8954 | * gm2-libs-iso/IOLink::IOLink.def | |
8955 | * gm2-libs-iso/IOResult::IOResult.def | |
8956 | * gm2-libs-iso/LongComplexMath::LongComplexMath.def | |
8957 | * gm2-libs-iso/LongConv::LongConv.def | |
8958 | * gm2-libs-iso/LongIO::LongIO.def | |
8959 | * gm2-libs-iso/LongMath::LongMath.def | |
8960 | * gm2-libs-iso/LongStr::LongStr.def | |
8961 | * gm2-libs-iso/LongWholeIO::LongWholeIO.def | |
8962 | * gm2-libs-iso/LowLong::LowLong.def | |
8963 | * gm2-libs-iso/LowReal::LowReal.def | |
8964 | * gm2-libs-iso/LowShort::LowShort.def | |
8965 | * gm2-libs-iso/M2EXCEPTION::M2EXCEPTION.def | |
8966 | * gm2-libs-iso/M2RTS::M2RTS.def | |
8967 | * gm2-libs-iso/MemStream::MemStream.def | |
8968 | * gm2-libs-iso/Preemptive::Preemptive.def | |
8969 | * gm2-libs-iso/Processes::Processes.def | |
8970 | * gm2-libs-iso/ProgramArgs::ProgramArgs.def | |
8971 | * gm2-libs-iso/RTco::RTco.def | |
8972 | * gm2-libs-iso/RTdata::RTdata.def | |
8973 | * gm2-libs-iso/RTentity::RTentity.def | |
8974 | * gm2-libs-iso/RTfio::RTfio.def | |
8975 | * gm2-libs-iso/RTgen::RTgen.def | |
8976 | * gm2-libs-iso/RTgenif::RTgenif.def | |
8977 | * gm2-libs-iso/RTio::RTio.def | |
8978 | * gm2-libs-iso/RandomNumber::RandomNumber.def | |
8979 | * gm2-libs-iso/RawIO::RawIO.def | |
8980 | * gm2-libs-iso/RealConv::RealConv.def | |
8981 | * gm2-libs-iso/RealIO::RealIO.def | |
8982 | * gm2-libs-iso/RealMath::RealMath.def | |
8983 | * gm2-libs-iso/RealStr::RealStr.def | |
8984 | * gm2-libs-iso/RndFile::RndFile.def | |
8985 | * gm2-libs-iso/SIOResult::SIOResult.def | |
8986 | * gm2-libs-iso/SLongIO::SLongIO.def | |
8987 | * gm2-libs-iso/SLongWholeIO::SLongWholeIO.def | |
8988 | * gm2-libs-iso/SRawIO::SRawIO.def | |
8989 | * gm2-libs-iso/SRealIO::SRealIO.def | |
8990 | * gm2-libs-iso/SShortIO::SShortIO.def | |
8991 | * gm2-libs-iso/SShortWholeIO::SShortWholeIO.def | |
8992 | * gm2-libs-iso/STextIO::STextIO.def | |
8993 | * gm2-libs-iso/SWholeIO::SWholeIO.def | |
8994 | * gm2-libs-iso/SYSTEM::SYSTEM.def | |
8995 | * gm2-libs-iso/Semaphores::Semaphores.def | |
8996 | * gm2-libs-iso/SeqFile::SeqFile.def | |
8997 | * gm2-libs-iso/ShortComplexMath::ShortComplexMath.def | |
8998 | * gm2-libs-iso/ShortIO::ShortIO.def | |
8999 | * gm2-libs-iso/ShortWholeIO::ShortWholeIO.def | |
9000 | * gm2-libs-iso/SimpleCipher::SimpleCipher.def | |
9001 | * gm2-libs-iso/StdChans::StdChans.def | |
9002 | * gm2-libs-iso/Storage::Storage.def | |
9003 | * gm2-libs-iso/StreamFile::StreamFile.def | |
9004 | * gm2-libs-iso/StringChan::StringChan.def | |
9005 | * gm2-libs-iso/Strings::Strings.def | |
9006 | * gm2-libs-iso/SysClock::SysClock.def | |
9007 | * gm2-libs-iso/TERMINATION::TERMINATION.def | |
9008 | * gm2-libs-iso/TermFile::TermFile.def | |
9009 | * gm2-libs-iso/TextIO::TextIO.def | |
9010 | * gm2-libs-iso/WholeConv::WholeConv.def | |
9011 | * gm2-libs-iso/WholeIO::WholeIO.def | |
9012 | * gm2-libs-iso/WholeStr::WholeStr.def | |
9013 | * gm2-libs-iso/wrapsock::wrapsock.def | |
9014 | * gm2-libs-iso/wraptime::wraptime.def | |
9015 | @end menu | |
9016 | ||
9017 | @node gm2-libs-iso/COROUTINES, gm2-libs-iso/ChanConsts, , M2 ISO Libraries | |
9018 | @subsection gm2-libs-iso/COROUTINES | |
9019 | ||
9020 | @example | |
9021 | DEFINITION MODULE COROUTINES; | |
9022 | ||
9023 | (* Facilities for coroutines and the handling of interrupts *) | |
9024 | ||
9025 | IMPORT SYSTEM ; | |
9026 | ||
9027 | ||
9028 | CONST | |
9029 | @findex UnassignedPriority (const) | |
9030 | UnassignedPriority = 0 ; | |
9031 | ||
9032 | TYPE | |
9033 | @findex COROUTINE (type) | |
9034 | COROUTINE ; (* Values of this type are created dynamically by NEWCOROUTINE | |
9035 | and identify the coroutine in subsequent operations *) | |
9036 | @findex INTERRUPTSOURCE (type) | |
9037 | INTERRUPTSOURCE = CARDINAL ; | |
9038 | @findex PROTECTION (type) | |
9039 | PROTECTION = [UnassignedPriority..7] ; | |
9040 | ||
9041 | ||
9042 | @findex NEWCOROUTINE | |
9043 | PROCEDURE NEWCOROUTINE (procBody: PROC; | |
9044 | workspace: SYSTEM.ADDRESS; | |
9045 | size: CARDINAL; | |
9046 | VAR cr: COROUTINE; | |
9047 | [initProtection: PROTECTION = UnassignedPriority]); | |
9048 | (* Creates a new coroutine whose body is given by procBody, and | |
9049 | returns the identity of the coroutine in cr. workspace is a | |
9050 | pointer to the work space allocated to the coroutine; size | |
9051 | specifies the size of this workspace in terms of SYSTEM.LOC. | |
9052 | ||
9053 | The optarg, initProtection, may contain a single parameter which | |
9054 | specifies the initial protection level of the coroutine. | |
9055 | *) | |
9056 | ||
9057 | @findex TRANSFER | |
9058 | PROCEDURE TRANSFER (VAR from: COROUTINE; to: COROUTINE); | |
9059 | (* Returns the identity of the calling coroutine in from, and | |
9060 | transfers control to the coroutine specified by to. | |
9061 | *) | |
9062 | ||
9063 | @findex IOTRANSFER | |
9064 | PROCEDURE IOTRANSFER (VAR from: COROUTINE; to: COROUTINE); | |
9065 | (* Returns the identity of the calling coroutine in from and | |
9066 | transfers control to the coroutine specified by to. On | |
9067 | occurrence of an interrupt, associated with the caller, control | |
9068 | is transferred back to the caller, and the identity of the | |
9069 | interrupted coroutine is returned in from. The calling coroutine | |
9070 | must be associated with a source of interrupts. | |
9071 | *) | |
9072 | ||
9073 | @findex ATTACH | |
9074 | PROCEDURE ATTACH (source: INTERRUPTSOURCE); | |
9075 | (* Associates the specified source of interrupts with the calling | |
9076 | coroutine. *) | |
9077 | ||
9078 | @findex DETACH | |
9079 | PROCEDURE DETACH (source: INTERRUPTSOURCE); | |
9080 | (* Dissociates the specified source of interrupts from the calling | |
9081 | coroutine. *) | |
9082 | ||
9083 | @findex IsATTACHED | |
9084 | PROCEDURE IsATTACHED (source: INTERRUPTSOURCE): BOOLEAN; | |
9085 | (* Returns TRUE if and only if the specified source of interrupts is | |
9086 | currently associated with a coroutine; otherwise returns FALSE. | |
9087 | *) | |
9088 | ||
9089 | @findex HANDLER | |
9090 | PROCEDURE HANDLER (source: INTERRUPTSOURCE): COROUTINE; | |
9091 | (* Returns the coroutine, if any, that is associated with the source | |
9092 | of interrupts. The result is undefined if IsATTACHED(source) = | |
9093 | FALSE. | |
9094 | *) | |
9095 | ||
9096 | @findex CURRENT | |
9097 | PROCEDURE CURRENT (): COROUTINE; | |
9098 | (* Returns the identity of the calling coroutine. *) | |
9099 | ||
9100 | @findex LISTEN | |
9101 | PROCEDURE LISTEN (p: PROTECTION); | |
9102 | (* Momentarily changes the protection of the calling coroutine to | |
9103 | p. *) | |
9104 | ||
9105 | @findex PROT | |
9106 | PROCEDURE PROT (): PROTECTION; | |
9107 | (* Returns the protection of the calling coroutine. *) | |
9108 | ||
9109 | ||
9110 | (* | |
9111 | TurnInterrupts - switches processor interrupts to the protection | |
9112 | level, to. It returns the old value. | |
9113 | *) | |
9114 | ||
9115 | @findex TurnInterrupts | |
9116 | PROCEDURE TurnInterrupts (to: PROTECTION) : PROTECTION ; | |
9117 | ||
9118 | ||
9119 | (* | |
9120 | ListenLoop - should be called instead of users writing: | |
9121 | ||
9122 | LOOP | |
9123 | LISTEN | |
9124 | END | |
9125 | ||
9126 | It performs the same function but yields | |
9127 | control back to the underlying operating system. | |
9128 | It also checks for deadlock. | |
9129 | Note that this function does return when an interrupt occurs. | |
9130 | (File descriptor becomes ready or time event expires). | |
9131 | *) | |
9132 | ||
9133 | @findex ListenLoop | |
9134 | PROCEDURE ListenLoop ; | |
9135 | ||
9136 | ||
9137 | END COROUTINES. | |
9138 | @end example | |
9139 | @page | |
9140 | ||
9141 | @node gm2-libs-iso/ChanConsts, gm2-libs-iso/CharClass, gm2-libs-iso/COROUTINES, M2 ISO Libraries | |
9142 | @subsection gm2-libs-iso/ChanConsts | |
9143 | ||
9144 | @example | |
9145 | DEFINITION MODULE ChanConsts; | |
9146 | ||
9147 | (* Common types and values for channel open requests and results *) | |
9148 | ||
9149 | TYPE | |
9150 | @findex ChanFlags (type) | |
9151 | ChanFlags = (* Request flags possibly given when a channel is opened *) | |
9152 | ( readFlag, (* input operations are requested/available *) | |
9153 | writeFlag, (* output operations are requested/available *) | |
9154 | oldFlag, (* a file may/must/did exist before the channel is opened *) | |
9155 | textFlag, (* text operations are requested/available *) | |
9156 | rawFlag, (* raw operations are requested/available *) | |
9157 | interactiveFlag, (* interactive use is requested/applies *) | |
9158 | echoFlag (* echoing by interactive device on removal of characters from input | |
9159 | stream requested/applies *) | |
9160 | ); | |
9161 | ||
9162 | @findex FlagSet (type) | |
9163 | FlagSet = SET OF ChanFlags; | |
9164 | ||
9165 | (* Singleton values of FlagSet, to allow for example, read + write *) | |
9166 | ||
9167 | CONST | |
9168 | @findex read (const) | |
9169 | read = FlagSet@{readFlag@}; (* input operations are requested/available *) | |
9170 | @findex write (const) | |
9171 | write = FlagSet@{writeFlag@}; (* output operations are requested/available *) | |
9172 | @findex old (const) | |
9173 | old = FlagSet@{oldFlag@}; (* a file may/must/did exist before the channel is opened *) | |
9174 | @findex text (const) | |
9175 | text = FlagSet@{textFlag@}; (* text operations are requested/available *) | |
9176 | @findex raw (const) | |
9177 | raw = FlagSet@{rawFlag@}; (* raw operations are requested/available *) | |
9178 | @findex interactive (const) | |
9179 | interactive = FlagSet@{interactiveFlag@}; (* interactive use is requested/applies *) | |
9180 | @findex echo (const) | |
9181 | echo = FlagSet@{echoFlag@}; (* echoing by interactive device on removal of characters from | |
9182 | input stream requested/applies *) | |
9183 | ||
9184 | TYPE | |
9185 | @findex OpenResults (type) | |
9186 | OpenResults = (* Possible results of open requests *) | |
9187 | (opened, (* the open succeeded as requested *) | |
9188 | wrongNameFormat, (* given name is in the wrong format for the implementation *) | |
9189 | wrongFlags, (* given flags include a value that does not apply to the device *) | |
9190 | tooManyOpen, (* this device cannot support any more open channels *) | |
9191 | outOfChans, (* no more channels can be allocated *) | |
9192 | wrongPermissions, (* file or directory permissions do not allow request *) | |
9193 | noRoomOnDevice, (* storage limits on the device prevent the open *) | |
9194 | noSuchFile, (* a needed file does not exist *) | |
9195 | fileExists, (* a file of the given name already exists when a new one is required *) | |
9196 | wrongFileType, (* the file is of the wrong type to support the required operations *) | |
9197 | noTextOperations, (* text operations have been requested, but are not supported *) | |
9198 | noRawOperations, (* raw operations have been requested, but are not supported *) | |
9199 | noMixedOperations,(* text and raw operations have been requested, but they | |
9200 | are not supported in combination *) | |
9201 | alreadyOpen, (* the source/destination is already open for operations not supported | |
9202 | in combination with the requested operations *) | |
9203 | otherProblem (* open failed for some other reason *) | |
9204 | ); | |
9205 | ||
9206 | END ChanConsts. | |
9207 | ||
9208 | @end example | |
9209 | @page | |
9210 | ||
9211 | @node gm2-libs-iso/CharClass, gm2-libs-iso/ClientSocket, gm2-libs-iso/ChanConsts, M2 ISO Libraries | |
9212 | @subsection gm2-libs-iso/CharClass | |
9213 | ||
9214 | @example | |
9215 | DEFINITION MODULE CharClass; | |
9216 | ||
9217 | (* Classification of values of the type CHAR *) | |
9218 | ||
9219 | @findex IsNumeric | |
9220 | PROCEDURE IsNumeric (ch: CHAR): BOOLEAN; | |
9221 | (* Returns TRUE if and only if ch is classified as a numeric character *) | |
9222 | ||
9223 | @findex IsLetter | |
9224 | PROCEDURE IsLetter (ch: CHAR): BOOLEAN; | |
9225 | (* Returns TRUE if and only if ch is classified as a letter *) | |
9226 | ||
9227 | @findex IsUpper | |
9228 | PROCEDURE IsUpper (ch: CHAR): BOOLEAN; | |
9229 | (* Returns TRUE if and only if ch is classified as an upper case letter *) | |
9230 | ||
9231 | @findex IsLower | |
9232 | PROCEDURE IsLower (ch: CHAR): BOOLEAN; | |
9233 | (* Returns TRUE if and only if ch is classified as a lower case letter *) | |
9234 | ||
9235 | @findex IsControl | |
9236 | PROCEDURE IsControl (ch: CHAR): BOOLEAN; | |
9237 | (* Returns TRUE if and only if ch represents a control function *) | |
9238 | ||
9239 | @findex IsWhiteSpace | |
9240 | PROCEDURE IsWhiteSpace (ch: CHAR): BOOLEAN; | |
9241 | (* Returns TRUE if and only if ch represents a space character or a format effector *) | |
9242 | ||
9243 | END CharClass. | |
9244 | ||
9245 | @end example | |
9246 | @page | |
9247 | ||
9248 | @node gm2-libs-iso/ClientSocket, gm2-libs-iso/ComplexMath, gm2-libs-iso/CharClass, M2 ISO Libraries | |
9249 | @subsection gm2-libs-iso/ClientSocket | |
9250 | ||
9251 | @example | |
9252 | DEFINITION MODULE ClientSocket ; | |
9253 | ||
9254 | FROM IOChan IMPORT ChanId ; | |
9255 | FROM ChanConsts IMPORT FlagSet, OpenResults ; | |
9256 | ||
9257 | ||
9258 | (* | |
9259 | OpenSocket - opens a TCP client connection to host:port. | |
9260 | *) | |
9261 | ||
9262 | @findex OpenSocket | |
9263 | PROCEDURE OpenSocket (VAR cid: ChanId; | |
9264 | host: ARRAY OF CHAR; port: CARDINAL; | |
9265 | f: FlagSet; VAR res: OpenResults) ; | |
9266 | ||
9267 | (* | |
9268 | Close - if the channel identified by cid is not open to | |
9269 | a socket stream, the exception wrongDevice is | |
9270 | raised; otherwise closes the channel, and assigns | |
9271 | the value identifying the invalid channel to cid. | |
9272 | *) | |
9273 | ||
9274 | @findex Close | |
9275 | PROCEDURE Close (VAR cid: ChanId) ; | |
9276 | ||
9277 | ||
9278 | (* | |
9279 | IsSocket - tests if the channel identified by cid is open as | |
9280 | a client socket stream. | |
9281 | *) | |
9282 | ||
9283 | @findex IsSocket | |
9284 | PROCEDURE IsSocket (cid: ChanId) : BOOLEAN ; | |
9285 | ||
9286 | ||
9287 | END ClientSocket. | |
9288 | @end example | |
9289 | @page | |
9290 | ||
9291 | @node gm2-libs-iso/ComplexMath, gm2-libs-iso/ConvStringLong, gm2-libs-iso/ClientSocket, M2 ISO Libraries | |
9292 | @subsection gm2-libs-iso/ComplexMath | |
9293 | ||
9294 | @example | |
9295 | DEFINITION MODULE ComplexMath; | |
9296 | ||
9297 | (* Mathematical functions for the type COMPLEX *) | |
9298 | ||
9299 | CONST | |
9300 | @findex i (const) | |
9301 | i = CMPLX (0.0, 1.0); | |
9302 | @findex one (const) | |
9303 | one = CMPLX (1.0, 0.0); | |
9304 | @findex zero (const) | |
9305 | zero = CMPLX (0.0, 0.0); | |
9306 | ||
9307 | @findex abs | |
9308 | PROCEDURE __BUILTIN__ abs (z: COMPLEX): REAL; | |
9309 | (* Returns the length of z *) | |
9310 | ||
9311 | @findex arg | |
9312 | PROCEDURE __BUILTIN__ arg (z: COMPLEX): REAL; | |
9313 | (* Returns the angle that z subtends to the positive real axis *) | |
9314 | ||
9315 | @findex conj | |
9316 | PROCEDURE __BUILTIN__ conj (z: COMPLEX): COMPLEX; | |
9317 | (* Returns the complex conjugate of z *) | |
9318 | ||
9319 | @findex power | |
9320 | PROCEDURE __BUILTIN__ power (base: COMPLEX; exponent: REAL): COMPLEX; | |
9321 | (* Returns the value of the number base raised to the power exponent *) | |
9322 | ||
9323 | @findex sqrt | |
9324 | PROCEDURE __BUILTIN__ sqrt (z: COMPLEX): COMPLEX; | |
9325 | (* Returns the principal square root of z *) | |
9326 | ||
9327 | @findex exp | |
9328 | PROCEDURE __BUILTIN__ exp (z: COMPLEX): COMPLEX; | |
9329 | (* Returns the complex exponential of z *) | |
9330 | ||
9331 | @findex ln | |
9332 | PROCEDURE __BUILTIN__ ln (z: COMPLEX): COMPLEX; | |
9333 | (* Returns the principal value of the natural logarithm of z *) | |
9334 | ||
9335 | @findex sin | |
9336 | PROCEDURE __BUILTIN__ sin (z: COMPLEX): COMPLEX; | |
9337 | (* Returns the sine of z *) | |
9338 | ||
9339 | @findex cos | |
9340 | PROCEDURE __BUILTIN__ cos (z: COMPLEX): COMPLEX; | |
9341 | (* Returns the cosine of z *) | |
9342 | ||
9343 | @findex tan | |
9344 | PROCEDURE __BUILTIN__ tan (z: COMPLEX): COMPLEX; | |
9345 | (* Returns the tangent of z *) | |
9346 | ||
9347 | @findex arcsin | |
9348 | PROCEDURE __BUILTIN__ arcsin (z: COMPLEX): COMPLEX; | |
9349 | (* Returns the arcsine of z *) | |
9350 | ||
9351 | @findex arccos | |
9352 | PROCEDURE __BUILTIN__ arccos (z: COMPLEX): COMPLEX; | |
9353 | (* Returns the arccosine of z *) | |
9354 | ||
9355 | @findex arctan | |
9356 | PROCEDURE __BUILTIN__ arctan (z: COMPLEX): COMPLEX; | |
9357 | (* Returns the arctangent of z *) | |
9358 | ||
9359 | @findex polarToComplex | |
9360 | PROCEDURE polarToComplex (abs, arg: REAL): COMPLEX; | |
9361 | (* Returns the complex number with the specified polar coordinates *) | |
9362 | ||
9363 | @findex scalarMult | |
9364 | PROCEDURE scalarMult (scalar: REAL; z: COMPLEX): COMPLEX; | |
9365 | (* Returns the scalar product of scalar with z *) | |
9366 | ||
9367 | @findex IsCMathException | |
9368 | PROCEDURE IsCMathException (): BOOLEAN; | |
9369 | (* Returns TRUE if the current coroutine is in the exceptional | |
9370 | execution state because of the raising of an exception in a | |
9371 | routine from this module; otherwise returns FALSE. | |
9372 | *) | |
9373 | ||
9374 | END ComplexMath. | |
9375 | ||
9376 | @end example | |
9377 | @page | |
9378 | ||
9379 | @node gm2-libs-iso/ConvStringLong, gm2-libs-iso/ConvStringReal, gm2-libs-iso/ComplexMath, M2 ISO Libraries | |
9380 | @subsection gm2-libs-iso/ConvStringLong | |
9381 | ||
9382 | @example | |
9383 | DEFINITION MODULE ConvStringLong ; | |
9384 | ||
9385 | FROM DynamicStrings IMPORT String ; | |
9386 | ||
9387 | ||
9388 | (* | |
9389 | RealToFloatString - converts a real with, sigFigs, into a string | |
9390 | and returns the result as a string. | |
9391 | *) | |
9392 | ||
9393 | @findex RealToFloatString | |
9394 | PROCEDURE RealToFloatString (real: LONGREAL; sigFigs: CARDINAL) : String ; | |
9395 | ||
9396 | ||
9397 | (* | |
9398 | RealToEngString - converts the value of real to floating-point | |
9399 | string form, with sigFigs significant figures. | |
9400 | The number is scaled with one to three digits | |
9401 | in the whole number part and with an exponent | |
9402 | that is a multiple of three. | |
9403 | *) | |
9404 | ||
9405 | @findex RealToEngString | |
9406 | PROCEDURE RealToEngString (real: LONGREAL; sigFigs: CARDINAL) : String ; | |
9407 | ||
9408 | ||
9409 | (* | |
9410 | RealToFixedString - returns the number of characters in the fixed-point | |
9411 | string representation of real rounded to the given | |
9412 | place relative to the decimal point. | |
9413 | *) | |
9414 | ||
9415 | @findex RealToFixedString | |
9416 | PROCEDURE RealToFixedString (real: LONGREAL; place: INTEGER) : String ; | |
9417 | ||
9418 | ||
9419 | END ConvStringLong. | |
9420 | @end example | |
9421 | @page | |
9422 | ||
9423 | @node gm2-libs-iso/ConvStringReal, gm2-libs-iso/ConvTypes, gm2-libs-iso/ConvStringLong, M2 ISO Libraries | |
9424 | @subsection gm2-libs-iso/ConvStringReal | |
9425 | ||
9426 | @example | |
9427 | DEFINITION MODULE ConvStringReal ; | |
9428 | ||
9429 | FROM DynamicStrings IMPORT String ; | |
9430 | ||
9431 | ||
9432 | (* | |
9433 | RealToFloatString - converts a real with, sigFigs, into a string | |
9434 | and returns the result as a string. | |
9435 | *) | |
9436 | ||
9437 | @findex RealToFloatString | |
9438 | PROCEDURE RealToFloatString (real: REAL; sigFigs: CARDINAL) : String ; | |
9439 | ||
9440 | ||
9441 | (* | |
9442 | RealToEngString - converts the value of real to floating-point | |
9443 | string form, with sigFigs significant figures. | |
9444 | The number is scaled with one to three digits | |
9445 | in the whole number part and with an exponent | |
9446 | that is a multiple of three. | |
9447 | *) | |
9448 | ||
9449 | @findex RealToEngString | |
9450 | PROCEDURE RealToEngString (real: REAL; sigFigs: CARDINAL) : String ; | |
9451 | ||
9452 | ||
9453 | (* | |
9454 | RealToFixedString - returns the number of characters in the fixed-point | |
9455 | string representation of real rounded to the given | |
9456 | place relative to the decimal point. | |
9457 | *) | |
9458 | ||
9459 | @findex RealToFixedString | |
9460 | PROCEDURE RealToFixedString (real: REAL; place: INTEGER) : String ; | |
9461 | ||
9462 | ||
9463 | END ConvStringReal. | |
9464 | @end example | |
9465 | @page | |
9466 | ||
9467 | @node gm2-libs-iso/ConvTypes, gm2-libs-iso/EXCEPTIONS, gm2-libs-iso/ConvStringReal, M2 ISO Libraries | |
9468 | @subsection gm2-libs-iso/ConvTypes | |
9469 | ||
9470 | @example | |
9471 | DEFINITION MODULE ConvTypes; | |
9472 | ||
9473 | (* Common types used in the string conversion modules *) | |
9474 | ||
9475 | TYPE | |
9476 | @findex ConvResults (type) | |
9477 | ConvResults = (* Values of this type are used to express the format of a string *) | |
9478 | ( | |
9479 | strAllRight, (* the string format is correct for the corresponding conversion *) | |
9480 | strOutOfRange, (* the string is well-formed but the value cannot be represented *) | |
9481 | strWrongFormat, (* the string is in the wrong format for the conversion *) | |
9482 | strEmpty (* the given string is empty *) | |
9483 | ); | |
9484 | ||
9485 | @findex ScanClass (type) | |
9486 | ScanClass = (* Values of this type are used to classify input to finite state scanners *) | |
9487 | ( | |
9488 | padding, (* a leading or padding character at this point in the scan - ignore it *) | |
9489 | valid, (* a valid character at this point in the scan - accept it *) | |
9490 | invalid, (* an invalid character at this point in the scan - reject it *) | |
9491 | terminator (* a terminating character at this point in the scan (not part of token) *) | |
9492 | ); | |
9493 | ||
9494 | @findex ScanState (type) | |
9495 | ScanState = (* The type of lexical scanning control procedures *) | |
9496 | PROCEDURE (CHAR, VAR ScanClass, VAR ScanState); | |
9497 | ||
9498 | END ConvTypes. | |
9499 | ||
9500 | @end example | |
9501 | @page | |
9502 | ||
9503 | @node gm2-libs-iso/EXCEPTIONS, gm2-libs-iso/ErrnoCategory, gm2-libs-iso/ConvTypes, M2 ISO Libraries | |
9504 | @subsection gm2-libs-iso/EXCEPTIONS | |
9505 | ||
9506 | @example | |
9507 | DEFINITION MODULE EXCEPTIONS; | |
9508 | ||
9509 | (* Provides facilities for raising user exceptions | |
9510 | and for making enquiries concerning the current execution state. | |
9511 | *) | |
9512 | ||
9513 | TYPE | |
9514 | ExceptionSource; (* values of this type are used within library | |
9515 | modules to identify the source of raised | |
9516 | exceptions *) | |
9517 | @findex ExceptionNumber (type) | |
9518 | ExceptionNumber = CARDINAL; | |
9519 | ||
9520 | @findex AllocateSource | |
9521 | PROCEDURE AllocateSource(VAR newSource: ExceptionSource); | |
9522 | (* Allocates a unique value of type ExceptionSource *) | |
9523 | ||
9524 | @findex RAISE | |
9525 | PROCEDURE RAISE (source: ExceptionSource; | |
9526 | number: ExceptionNumber; message: ARRAY OF CHAR); | |
9527 | (* Associates the given values of source, number and message with | |
9528 | the current context and raises an exception. | |
9529 | *) | |
9530 | ||
9531 | @findex CurrentNumber | |
9532 | PROCEDURE CurrentNumber (source: ExceptionSource): ExceptionNumber; | |
9533 | (* If the current coroutine is in the exceptional execution state | |
9534 | because of the raising of an exception from source, returns | |
9535 | the corresponding number, and otherwise raises an exception. | |
9536 | *) | |
9537 | ||
9538 | @findex GetMessage | |
9539 | PROCEDURE GetMessage (VAR text: ARRAY OF CHAR); | |
9540 | (* If the current coroutine is in the exceptional execution state, | |
9541 | returns the possibly truncated string associated with the | |
9542 | current context. Otherwise, in normal execution state, | |
9543 | returns the empty string. | |
9544 | *) | |
9545 | ||
9546 | @findex IsCurrentSource | |
9547 | PROCEDURE IsCurrentSource (source: ExceptionSource): BOOLEAN; | |
9548 | (* If the current coroutine is in the exceptional execution state | |
9549 | because of the raising of an exception from source, returns | |
9550 | TRUE, and otherwise returns FALSE. | |
9551 | *) | |
9552 | ||
9553 | @findex IsExceptionalExecution | |
9554 | PROCEDURE IsExceptionalExecution (): BOOLEAN; | |
9555 | (* If the current coroutine is in the exceptional execution state | |
9556 | because of the raising of an exception, returns TRUE, and | |
9557 | otherwise returns FALSE. | |
9558 | *) | |
9559 | ||
9560 | END EXCEPTIONS. | |
9561 | @end example | |
9562 | @page | |
9563 | ||
9564 | @node gm2-libs-iso/ErrnoCategory, gm2-libs-iso/GeneralUserExceptions, gm2-libs-iso/EXCEPTIONS, M2 ISO Libraries | |
9565 | @subsection gm2-libs-iso/ErrnoCategory | |
9566 | ||
9567 | @example | |
9568 | DEFINITION MODULE ErrnoCategory ; | |
9569 | ||
9570 | (* | |
9571 | provides an interface to errno (if the system | |
9572 | supports it) which determines whether the current | |
9573 | errno is a hard or soft error. These distinctions | |
9574 | are needed by the ISO Modula-2 libraries. Not all | |
9575 | errno values are tested, only those which could be | |
9576 | related to a device. | |
9577 | *) | |
9578 | ||
9579 | IMPORT ChanConsts ; | |
9580 | ||
9581 | ||
9582 | (* | |
9583 | IsErrnoHard - returns TRUE if the value of errno is associated with | |
9584 | a hard device error. | |
9585 | *) | |
9586 | ||
9587 | @findex IsErrnoHard | |
9588 | PROCEDURE IsErrnoHard (e: INTEGER) : BOOLEAN ; | |
9589 | ||
9590 | ||
9591 | (* | |
9592 | IsErrnoSoft - returns TRUE if the value of errno is associated with | |
9593 | a soft device error. | |
9594 | *) | |
9595 | ||
9596 | @findex IsErrnoSoft | |
9597 | PROCEDURE IsErrnoSoft (e: INTEGER) : BOOLEAN ; | |
9598 | ||
9599 | ||
9600 | (* | |
9601 | UnAvailable - returns TRUE if the value of errno indicates that | |
9602 | the resource or device is unavailable for some | |
9603 | reason. | |
9604 | *) | |
9605 | ||
9606 | @findex UnAvailable | |
9607 | PROCEDURE UnAvailable (e: INTEGER) : BOOLEAN ; | |
9608 | ||
9609 | ||
9610 | (* | |
9611 | GetOpenResults - maps errno onto the ISO Modula-2 enumerated | |
9612 | type, OpenResults. | |
9613 | *) | |
9614 | ||
9615 | @findex GetOpenResults | |
9616 | PROCEDURE GetOpenResults (e: INTEGER) : ChanConsts.OpenResults ; | |
9617 | ||
9618 | ||
9619 | END ErrnoCategory. | |
9620 | @end example | |
9621 | @page | |
9622 | ||
9623 | @node gm2-libs-iso/GeneralUserExceptions, gm2-libs-iso/IOChan, gm2-libs-iso/ErrnoCategory, M2 ISO Libraries | |
9624 | @subsection gm2-libs-iso/GeneralUserExceptions | |
9625 | ||
9626 | @example | |
9627 | DEFINITION MODULE GeneralUserExceptions; | |
9628 | ||
9629 | (* Provides facilities for general user-defined exceptions *) | |
9630 | ||
9631 | TYPE | |
9632 | @findex GeneralExceptions (type) | |
9633 | GeneralExceptions = (problem, disaster); | |
9634 | ||
9635 | @findex RaiseGeneralException | |
9636 | PROCEDURE RaiseGeneralException (exception: GeneralExceptions; | |
9637 | text: ARRAY OF CHAR); | |
9638 | (* Raises exception using text as the associated message *) | |
9639 | ||
9640 | @findex IsGeneralException | |
9641 | PROCEDURE IsGeneralException (): BOOLEAN; | |
9642 | (* Returns TRUE if the current coroutine is in the exceptional | |
9643 | execution state because of the raising of an exception from | |
9644 | GeneralExceptions; otherwise returns FALSE. | |
9645 | *) | |
9646 | ||
9647 | @findex GeneralException | |
9648 | PROCEDURE GeneralException(): GeneralExceptions; | |
9649 | (* If the current coroutine is in the exceptional execution | |
9650 | state because of the raising of an exception from | |
9651 | GeneralExceptions, returns the corresponding enumeration value, | |
9652 | and otherwise raises an exception. | |
9653 | *) | |
9654 | ||
9655 | END GeneralUserExceptions. | |
9656 | @end example | |
9657 | @page | |
9658 | ||
9659 | @node gm2-libs-iso/IOChan, gm2-libs-iso/IOConsts, gm2-libs-iso/GeneralUserExceptions, M2 ISO Libraries | |
9660 | @subsection gm2-libs-iso/IOChan | |
9661 | ||
9662 | @example | |
9663 | DEFINITION MODULE IOChan; | |
9664 | ||
9665 | (* Types and procedures forming the interface to channels for | |
9666 | device-independent data transfer modules | |
9667 | *) | |
9668 | ||
9669 | IMPORT IOConsts, ChanConsts, SYSTEM; | |
9670 | ||
9671 | TYPE | |
9672 | ChanId; (* Values of this type are used to identify channels *) | |
9673 | ||
9674 | (* There is one pre-defined value identifying an invalid channel | |
9675 | on which no data transfer operations are available. It may | |
9676 | be used to initialize variables of type ChanId. | |
9677 | *) | |
9678 | ||
9679 | @findex InvalidChan | |
9680 | PROCEDURE InvalidChan (): ChanId; | |
9681 | (* Returns the value identifying the invalid channel. *) | |
9682 | ||
9683 | (* For each of the following operations, if the device supports | |
9684 | the operation on the channel, the behaviour of the procedure | |
9685 | conforms with the description below. The full behaviour is | |
9686 | defined for each device module. If the device does not | |
9687 | support the operation on the channel, the behaviour of the | |
9688 | procedure is to raise the exception notAvailable. | |
9689 | *) | |
9690 | ||
9691 | (* Text operations - these perform any required translation between the | |
9692 | internal and external representation of text. | |
9693 | *) | |
9694 | ||
9695 | @findex Look | |
9696 | PROCEDURE Look (cid: ChanId; VAR ch: CHAR; VAR res: IOConsts.ReadResults); | |
9697 | (* If there is a character as the next item in the input stream | |
9698 | cid, assigns its value to ch without removing it from the stream; | |
9699 | otherwise the value of ch is not defined. res (and the stored | |
9700 | read result) are set to the value allRight, endOfLine, or endOfInput. | |
9701 | *) | |
9702 | ||
9703 | @findex Skip | |
9704 | PROCEDURE Skip (cid: ChanId); | |
9705 | (* If the input stream cid has ended, the exception skipAtEnd | |
9706 | is raised; otherwise the next character or line mark in cid is | |
9707 | removed, and the stored read result is set to the value | |
9708 | allRight. | |
9709 | *) | |
9710 | ||
9711 | @findex SkipLook | |
9712 | PROCEDURE SkipLook (cid: ChanId; VAR ch: CHAR; VAR res: IOConsts.ReadResults); | |
9713 | (* If the input stream cid has ended, the exception skipAtEnd is | |
9714 | raised; otherwise the next character or line mark in cid is | |
9715 | removed. If there is a character as the next item in cid | |
9716 | stream, assigns its value to ch without removing it from the | |
9717 | stream. Otherwise, the value of ch is not defined. res | |
9718 | (and the stored read result) are set to the value allRight, | |
9719 | endOfLine, or endOfInput. | |
9720 | *) | |
9721 | ||
9722 | @findex WriteLn | |
9723 | PROCEDURE WriteLn (cid: ChanId); | |
9724 | (* Writes a line mark over the channel cid. *) | |
9725 | ||
9726 | @findex TextRead | |
9727 | PROCEDURE TextRead (cid: ChanId; to: SYSTEM.ADDRESS; maxChars: CARDINAL; | |
9728 | VAR charsRead: CARDINAL); | |
9729 | (* Reads at most maxChars characters from the current line in cid, | |
9730 | and assigns corresponding values to successive components of | |
9731 | an ARRAY OF CHAR variable for which the address of the first | |
9732 | component is to. The number of characters read is assigned to charsRead. | |
9733 | The stored read result is set to allRight, endOfLine, or endOfInput. | |
9734 | *) | |
9735 | ||
9736 | @findex TextWrite | |
9737 | PROCEDURE TextWrite (cid: ChanId; from: SYSTEM.ADDRESS; | |
9738 | charsToWrite: CARDINAL); | |
9739 | (* Writes a number of characters given by the value of charsToWrite, | |
9740 | from successive components of an ARRAY OF CHAR variable for which | |
9741 | the address of the first component is from, to the channel cid. | |
9742 | *) | |
9743 | ||
9744 | (* Direct raw operations - these do not effect translation between | |
9745 | the internal and external representation of data | |
9746 | *) | |
9747 | ||
9748 | @findex RawRead | |
9749 | PROCEDURE RawRead (cid: ChanId; to: SYSTEM.ADDRESS; maxLocs: CARDINAL; | |
9750 | VAR locsRead: CARDINAL); | |
9751 | (* Reads at most maxLocs items from cid, and assigns corresponding | |
9752 | values to successive components of an ARRAY OF LOC variable for | |
9753 | which the address of the first component is to. The number of | |
9754 | characters read is assigned to charsRead. The stored read result | |
9755 | is set to the value allRight, or endOfInput. | |
9756 | *) | |
9757 | ||
9758 | @findex RawWrite | |
9759 | PROCEDURE RawWrite (cid: ChanId; from: SYSTEM.ADDRESS; locsToWrite: CARDINAL); | |
9760 | (* Writes a number of items given by the value of charsToWrite, | |
9761 | from successive components of an ARRAY OF LOC variable for | |
9762 | which the address of the first component is from, to the channel cid. | |
9763 | *) | |
9764 | ||
9765 | (* Common operations *) | |
9766 | ||
9767 | @findex GetName | |
9768 | PROCEDURE GetName (cid: ChanId; VAR s: ARRAY OF CHAR); | |
9769 | (* Copies to s a name associated with the channel cid, possibly truncated | |
9770 | (depending on the capacity of s). | |
9771 | *) | |
9772 | ||
9773 | @findex Reset | |
9774 | PROCEDURE Reset (cid: ChanId); | |
9775 | (* Resets the channel cid to a state defined by the device module. *) | |
9776 | ||
9777 | @findex Flush | |
9778 | PROCEDURE Flush (cid: ChanId); | |
9779 | (* Flushes any data buffered by the device module out to the channel cid. *) | |
9780 | ||
9781 | (* Access to read results *) | |
9782 | ||
9783 | @findex SetReadResult | |
9784 | PROCEDURE SetReadResult (cid: ChanId; res: IOConsts.ReadResults); | |
9785 | (* Sets the read result value for the channel cid to the value res. *) | |
9786 | ||
9787 | @findex ReadResult | |
9788 | PROCEDURE ReadResult (cid: ChanId): IOConsts.ReadResults; | |
9789 | (* Returns the stored read result value for the channel cid. | |
9790 | (This is initially the value notKnown). | |
9791 | *) | |
9792 | ||
9793 | (* Users can discover which flags actually apply to a channel *) | |
9794 | ||
9795 | @findex CurrentFlags | |
9796 | PROCEDURE CurrentFlags (cid: ChanId): ChanConsts.FlagSet; | |
9797 | (* Returns the set of flags that currently apply to the channel cid. *) | |
9798 | ||
9799 | (* The following exceptions are defined for this module and its clients *) | |
9800 | ||
9801 | TYPE | |
9802 | @findex ChanExceptions (type) | |
9803 | ChanExceptions = | |
9804 | (wrongDevice, (* device specific operation on wrong device *) | |
9805 | notAvailable, (* operation attempted that is not available on that | |
9806 | channel *) | |
9807 | skipAtEnd, (* attempt to skip data from a stream that has ended *) | |
9808 | softDeviceError, (* device specific recoverable error *) | |
9809 | hardDeviceError, (* device specific non-recoverable error *) | |
9810 | textParseError, (* input data does not correspond to a character or | |
9811 | line mark - optional detection *) | |
9812 | notAChannel (* given value does not identify a channel - | |
9813 | optional detection *) | |
9814 | ); | |
9815 | ||
9816 | @findex IsChanException | |
9817 | PROCEDURE IsChanException (): BOOLEAN; | |
9818 | (* Returns TRUE if the current coroutine is in the exceptional | |
9819 | execution state because of the raising of an exception from | |
9820 | ChanExceptions; otherwise returns FALSE. | |
9821 | *) | |
9822 | ||
9823 | @findex ChanException | |
9824 | PROCEDURE ChanException (): ChanExceptions; | |
9825 | (* If the current coroutine is in the exceptional execution state | |
9826 | because of the raising of an exception from ChanExceptions, | |
9827 | returns the corresponding enumeration value, and otherwise | |
9828 | raises an exception. | |
9829 | *) | |
9830 | ||
9831 | (* When a device procedure detects a device error, it raises the | |
9832 | exception softDeviceError or hardDeviceError. If these | |
9833 | exceptions are handled, the following facilities may be | |
9834 | used to discover an implementation-defined error number for | |
9835 | the channel. | |
9836 | *) | |
9837 | ||
9838 | TYPE | |
9839 | @findex DeviceErrNum (type) | |
9840 | DeviceErrNum = INTEGER; | |
9841 | ||
9842 | @findex DeviceError | |
9843 | PROCEDURE DeviceError (cid: ChanId): DeviceErrNum; | |
9844 | (* If a device error exception has been raised for the channel cid, | |
9845 | returns the error number stored by the device module. | |
9846 | *) | |
9847 | ||
9848 | END IOChan. | |
9849 | @end example | |
9850 | @page | |
9851 | ||
9852 | @node gm2-libs-iso/IOConsts, gm2-libs-iso/IOLink, gm2-libs-iso/IOChan, M2 ISO Libraries | |
9853 | @subsection gm2-libs-iso/IOConsts | |
9854 | ||
9855 | @example | |
9856 | DEFINITION MODULE IOConsts; | |
9857 | ||
9858 | (* Types and constants for input/output modules *) | |
9859 | ||
9860 | TYPE | |
9861 | @findex ReadResults (type) | |
9862 | ReadResults = (* This type is used to classify the result of an input operation *) | |
9863 | ( | |
9864 | notKnown, (* no read result is set *) | |
9865 | allRight, (* data is as expected or as required *) | |
9866 | outOfRange, (* data cannot be represented *) | |
9867 | wrongFormat, (* data not in expected format *) | |
9868 | endOfLine, (* end of line seen before expected data *) | |
9869 | endOfInput (* end of input seen before expected data *) | |
9870 | ); | |
9871 | ||
9872 | END IOConsts. | |
9873 | ||
9874 | @end example | |
9875 | @page | |
9876 | ||
9877 | @node gm2-libs-iso/IOLink, gm2-libs-iso/IOResult, gm2-libs-iso/IOConsts, M2 ISO Libraries | |
9878 | @subsection gm2-libs-iso/IOLink | |
9879 | ||
9880 | @example | |
9881 | DEFINITION MODULE IOLink; | |
9882 | ||
9883 | (* Types and procedures for the standard implementation of channels *) | |
9884 | ||
9885 | IMPORT IOChan, IOConsts, ChanConsts, SYSTEM; | |
9886 | ||
9887 | TYPE | |
9888 | DeviceId; | |
9889 | (* Values of this type are used to identify new device modules, | |
9890 | and are normally obtained by them during their initialization. | |
9891 | *) | |
9892 | ||
9893 | @findex AllocateDeviceId | |
9894 | PROCEDURE AllocateDeviceId (VAR did: DeviceId); | |
9895 | (* Allocates a unique value of type DeviceId, and assigns this | |
9896 | value to did. *) | |
9897 | ||
9898 | @findex MakeChan | |
9899 | PROCEDURE MakeChan (did: DeviceId; VAR cid: IOChan.ChanId); | |
9900 | (* Attempts to make a new channel for the device module identified | |
9901 | by did. If no more channels can be made, the identity of | |
9902 | the invalid channel is assigned to cid. Otherwise, the identity | |
9903 | of a new channel is assigned to cid. | |
9904 | *) | |
9905 | ||
9906 | @findex UnMakeChan | |
9907 | PROCEDURE UnMakeChan (did: DeviceId; VAR cid: IOChan.ChanId); | |
9908 | (* If the device module identified by did is not the module that | |
9909 | made the channel identified by cid, the exception wrongDevice is | |
9910 | raised; otherwise the channel is deallocated, and the value | |
9911 | identifying the invalid channel is assigned to cid. | |
9912 | *) | |
9913 | ||
9914 | TYPE | |
9915 | @findex DeviceTablePtr (type) | |
9916 | DeviceTablePtr = POINTER TO DeviceTable; | |
9917 | (* Values of this type are used to refer to device tables *) | |
9918 | ||
9919 | TYPE | |
9920 | @findex LookProc (type) | |
9921 | LookProc = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR IOConsts.ReadResults) ; | |
9922 | @findex SkipProc (type) | |
9923 | SkipProc = PROCEDURE (DeviceTablePtr) ; | |
9924 | @findex SkipLookProc (type) | |
9925 | SkipLookProc = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR IOConsts.ReadResults) ; | |
9926 | @findex WriteLnProc (type) | |
9927 | WriteLnProc = PROCEDURE (DeviceTablePtr) ; | |
9928 | @findex TextReadProc (type) | |
9929 | TextReadProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL, VAR CARDINAL) ; | |
9930 | @findex TextWriteProc (type) | |
9931 | TextWriteProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL) ; | |
9932 | @findex RawReadProc (type) | |
9933 | RawReadProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL, VAR CARDINAL) ; | |
9934 | @findex RawWriteProc (type) | |
9935 | RawWriteProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL) ; | |
9936 | @findex GetNameProc (type) | |
9937 | GetNameProc = PROCEDURE (DeviceTablePtr, VAR ARRAY OF CHAR) ; | |
9938 | @findex ResetProc (type) | |
9939 | ResetProc = PROCEDURE (DeviceTablePtr) ; | |
9940 | @findex FlushProc (type) | |
9941 | FlushProc = PROCEDURE (DeviceTablePtr) ; | |
9942 | @findex FreeProc (type) | |
9943 | FreeProc = PROCEDURE (DeviceTablePtr) ; | |
9944 | (* Carry out the operations involved in closing the corresponding | |
9945 | channel, including flushing buffers, but do not unmake the | |
9946 | channel. | |
9947 | *) | |
9948 | ||
9949 | ||
9950 | TYPE | |
9951 | @findex DeviceData (type) | |
9952 | DeviceData = SYSTEM.ADDRESS; | |
9953 | ||
9954 | @findex DeviceTable (type) | |
9955 | DeviceTable = | |
9956 | RECORD (* Initialized by MakeChan to: *) | |
9957 | cd: DeviceData; (* the value NIL *) | |
9958 | did: DeviceId; (* the value given in the call of MakeChan *) | |
9959 | cid: IOChan.ChanId; (* the identity of the channel *) | |
9960 | result: IOConsts.ReadResults;(* the value notKnown *) | |
9961 | errNum: IOChan.DeviceErrNum; (* undefined *) | |
9962 | flags: ChanConsts.FlagSet; (* ChanConsts.FlagSet@{@} *) | |
9963 | doLook: LookProc; (* raise exception notAvailable *) | |
9964 | doSkip: SkipProc; (* raise exception notAvailable *) | |
9965 | doSkipLook: SkipLookProc; (* raise exception notAvailable *) | |
9966 | doLnWrite: WriteLnProc; (* raise exception notAvailable *) | |
9967 | doTextRead: TextReadProc; (* raise exception notAvailable *) | |
9968 | doTextWrite: TextWriteProc; (* raise exception notAvailable *) | |
9969 | doRawRead: RawReadProc; (* raise exception notAvailable *) | |
9970 | doRawWrite: RawWriteProc; (* raise exception notAvailable *) | |
9971 | doGetName: GetNameProc; (* return the empty string *) | |
9972 | doReset: ResetProc; (* do nothing *) | |
9973 | doFlush: FlushProc; (* do nothing *) | |
9974 | doFree: FreeProc; (* do nothing *) | |
9975 | END; | |
9976 | ||
9977 | ||
9978 | (* The pointer to the device table for a channel is obtained using the | |
9979 | following procedure: *) | |
9980 | ||
9981 | (* | |
9982 | If the device module identified by did is not the module that made | |
9983 | the channel identified by cid, the exception wrongDevice is raised. | |
9984 | *) | |
9985 | ||
9986 | @findex DeviceTablePtrValue | |
9987 | PROCEDURE DeviceTablePtrValue (cid: IOChan.ChanId; did: DeviceId): DeviceTablePtr; | |
9988 | ||
9989 | ||
9990 | (* | |
9991 | Tests if the device module identified by did is the module | |
9992 | that made the channel identified by cid. | |
9993 | *) | |
9994 | ||
9995 | @findex IsDevice | |
9996 | PROCEDURE IsDevice (cid: IOChan.ChanId; did: DeviceId) : BOOLEAN; | |
9997 | ||
9998 | ||
9999 | TYPE | |
10000 | @findex DevExceptionRange (type) | |
10001 | DevExceptionRange = IOChan.ChanExceptions; | |
10002 | ||
10003 | (* | |
10004 | ISO standard states defines | |
10005 | ||
10006 | DevExceptionRange = [IOChan.notAvailable .. IOChan.textParseError]; | |
10007 | ||
10008 | however this must be a bug as other modules need to raise | |
10009 | IOChan.wrongDevice exceptions. | |
10010 | *) | |
10011 | ||
10012 | @findex RAISEdevException | |
10013 | PROCEDURE RAISEdevException (cid: IOChan.ChanId; did: DeviceId; | |
10014 | x: DevExceptionRange; s: ARRAY OF CHAR); | |
10015 | ||
10016 | (* If the device module identified by did is not the module that made the channel | |
10017 | identified by cid, the exception wrongDevice is raised; otherwise the given exception | |
10018 | is raised, and the string value in s is included in the exception message. | |
10019 | *) | |
10020 | ||
10021 | @findex IsIOException | |
10022 | PROCEDURE IsIOException () : BOOLEAN; | |
10023 | (* Returns TRUE if the current coroutine is in the exceptional execution state | |
10024 | because of the raising af an exception from ChanExceptions; | |
10025 | otherwise FALSE. | |
10026 | *) | |
10027 | ||
10028 | @findex IOException | |
10029 | PROCEDURE IOException () : IOChan.ChanExceptions; | |
10030 | (* If the current coroutine is in the exceptional execution state because of the | |
10031 | raising af an exception from ChanExceptions, returns the corresponding | |
10032 | enumeration value, and otherwise raises an exception. | |
10033 | *) | |
10034 | ||
10035 | END IOLink. | |
10036 | @end example | |
10037 | @page | |
10038 | ||
10039 | @node gm2-libs-iso/IOResult, gm2-libs-iso/LongComplexMath, gm2-libs-iso/IOLink, M2 ISO Libraries | |
10040 | @subsection gm2-libs-iso/IOResult | |
10041 | ||
10042 | @example | |
10043 | DEFINITION MODULE IOResult; | |
10044 | ||
10045 | (* Read results for specified channels *) | |
10046 | ||
10047 | IMPORT IOConsts, IOChan; | |
10048 | ||
10049 | TYPE | |
10050 | @findex ReadResults (type) | |
10051 | ReadResults = IOConsts.ReadResults; | |
10052 | ||
10053 | (* | |
10054 | @findex ReadResults (type) | |
10055 | ReadResults = (* This type is used to classify the result of an input operation *) | |
10056 | ( | |
10057 | notKnown, (* no read result is set *) | |
10058 | allRight, (* data is as expected or as required *) | |
10059 | outOfRange, (* data cannot be represented *) | |
10060 | wrongFormat, (* data not in expected format *) | |
10061 | endOfLine, (* end of line seen before expected data *) | |
10062 | endOfInput (* end of input seen before expected data *) | |
10063 | ); | |
10064 | *) | |
10065 | ||
10066 | @findex ReadResult | |
10067 | PROCEDURE ReadResult (cid: IOChan.ChanId): ReadResults; | |
10068 | (* Returns the result for the last read operation on the channel cid. *) | |
10069 | ||
10070 | END IOResult. | |
10071 | ||
10072 | @end example | |
10073 | @page | |
10074 | ||
10075 | @node gm2-libs-iso/LongComplexMath, gm2-libs-iso/LongConv, gm2-libs-iso/IOResult, M2 ISO Libraries | |
10076 | @subsection gm2-libs-iso/LongComplexMath | |
10077 | ||
10078 | @example | |
10079 | DEFINITION MODULE LongComplexMath; | |
10080 | ||
10081 | (* Mathematical functions for the type LONGCOMPLEX *) | |
10082 | ||
10083 | CONST | |
10084 | @findex i (const) | |
10085 | i = CMPLX (0.0, 1.0); | |
10086 | @findex one (const) | |
10087 | one = CMPLX (1.0, 0.0); | |
10088 | @findex zero (const) | |
10089 | zero = CMPLX (0.0, 0.0); | |
10090 | ||
10091 | @findex abs | |
10092 | PROCEDURE abs (z: LONGCOMPLEX): LONGREAL; | |
10093 | (* Returns the length of z *) | |
10094 | ||
10095 | @findex arg | |
10096 | PROCEDURE arg (z: LONGCOMPLEX): LONGREAL; | |
10097 | (* Returns the angle that z subtends to the positive real axis *) | |
10098 | ||
10099 | @findex conj | |
10100 | PROCEDURE conj (z: LONGCOMPLEX): LONGCOMPLEX; | |
10101 | (* Returns the complex conjugate of z *) | |
10102 | ||
10103 | @findex power | |
10104 | PROCEDURE power (base: LONGCOMPLEX; exponent: LONGREAL): LONGCOMPLEX; | |
10105 | (* Returns the value of the number base raised to the power exponent *) | |
10106 | ||
10107 | @findex sqrt | |
10108 | PROCEDURE sqrt (z: LONGCOMPLEX): LONGCOMPLEX; | |
10109 | (* Returns the principal square root of z *) | |
10110 | ||
10111 | @findex exp | |
10112 | PROCEDURE exp (z: LONGCOMPLEX): LONGCOMPLEX; | |
10113 | (* Returns the complex exponential of z *) | |
10114 | ||
10115 | @findex ln | |
10116 | PROCEDURE ln (z: LONGCOMPLEX): LONGCOMPLEX; | |
10117 | (* Returns the principal value of the natural logarithm of z *) | |
10118 | ||
10119 | @findex sin | |
10120 | PROCEDURE sin (z: LONGCOMPLEX): LONGCOMPLEX; | |
10121 | (* Returns the sine of z *) | |
10122 | ||
10123 | @findex cos | |
10124 | PROCEDURE cos (z: LONGCOMPLEX): LONGCOMPLEX; | |
10125 | (* Returns the cosine of z *) | |
10126 | ||
10127 | @findex tan | |
10128 | PROCEDURE tan (z: LONGCOMPLEX): LONGCOMPLEX; | |
10129 | (* Returns the tangent of z *) | |
10130 | ||
10131 | @findex arcsin | |
10132 | PROCEDURE arcsin (z: LONGCOMPLEX): LONGCOMPLEX; | |
10133 | (* Returns the arcsine of z *) | |
10134 | ||
10135 | @findex arccos | |
10136 | PROCEDURE arccos (z: LONGCOMPLEX): LONGCOMPLEX; | |
10137 | (* Returns the arccosine of z *) | |
10138 | ||
10139 | @findex arctan | |
10140 | PROCEDURE arctan (z: LONGCOMPLEX): LONGCOMPLEX; | |
10141 | (* Returns the arctangent of z *) | |
10142 | ||
10143 | @findex polarToComplex | |
10144 | PROCEDURE polarToComplex (abs, arg: LONGREAL): LONGCOMPLEX; | |
10145 | (* Returns the complex number with the specified polar coordinates *) | |
10146 | ||
10147 | @findex scalarMult | |
10148 | PROCEDURE scalarMult (scalar: LONGREAL; z: LONGCOMPLEX): LONGCOMPLEX; | |
10149 | (* Returns the scalar product of scalar with z *) | |
10150 | ||
10151 | @findex IsCMathException | |
10152 | PROCEDURE IsCMathException (): BOOLEAN; | |
10153 | (* Returns TRUE if the current coroutine is in the exceptional execution state | |
10154 | because of the raising of an exception in a routine from this module; otherwise | |
10155 | returns FALSE. | |
10156 | *) | |
10157 | ||
10158 | END LongComplexMath. | |
10159 | ||
10160 | @end example | |
10161 | @page | |
10162 | ||
10163 | @node gm2-libs-iso/LongConv, gm2-libs-iso/LongIO, gm2-libs-iso/LongComplexMath, M2 ISO Libraries | |
10164 | @subsection gm2-libs-iso/LongConv | |
10165 | ||
10166 | @example | |
10167 | DEFINITION MODULE LongConv; | |
10168 | ||
10169 | (* Low-level LONGREAL/string conversions *) | |
10170 | ||
10171 | IMPORT | |
10172 | ConvTypes; | |
10173 | ||
10174 | TYPE | |
10175 | @findex ConvResults (type) | |
10176 | ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, | |
10177 | strWrongFormat, strEmpty *) | |
10178 | ||
10179 | @findex ScanReal | |
10180 | PROCEDURE ScanReal (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass; | |
10181 | VAR nextState: ConvTypes.ScanState); | |
10182 | (* Represents the start state of a finite state scanner for real | |
10183 | numbers - assigns class of inputCh to chClass and a procedure | |
10184 | representing the next state to nextState. | |
10185 | *) | |
10186 | ||
10187 | @findex FormatReal | |
10188 | PROCEDURE FormatReal (str: ARRAY OF CHAR): ConvResults; | |
10189 | (* Returns the format of the string value for conversion to LONGREAL. *) | |
10190 | ||
10191 | @findex ValueReal | |
10192 | PROCEDURE ValueReal (str: ARRAY OF CHAR): LONGREAL; | |
10193 | (* Returns the value corresponding to the real number string value | |
10194 | str if str is well-formed; otherwise raises the LongConv exception. | |
10195 | *) | |
10196 | ||
10197 | @findex LengthFloatReal | |
10198 | PROCEDURE LengthFloatReal (real: LONGREAL; sigFigs: CARDINAL): CARDINAL; | |
10199 | (* Returns the number of characters in the floating-point string | |
10200 | representation of real with sigFigs significant figures. | |
10201 | *) | |
10202 | ||
10203 | @findex LengthEngReal | |
10204 | PROCEDURE LengthEngReal (real: LONGREAL; sigFigs: CARDINAL): CARDINAL; | |
10205 | (* Returns the number of characters in the floating-point engineering | |
10206 | string representation of real with sigFigs significant figures. | |
10207 | *) | |
10208 | ||
10209 | @findex LengthFixedReal | |
10210 | PROCEDURE LengthFixedReal (real: LONGREAL; place: INTEGER): CARDINAL; | |
10211 | (* Returns the number of characters in the fixed-point string | |
10212 | representation of real rounded to the given place relative to the | |
10213 | decimal point. | |
10214 | *) | |
10215 | ||
10216 | @findex IsRConvException | |
10217 | PROCEDURE IsRConvException (): BOOLEAN; | |
10218 | (* Returns TRUE if the current coroutine is in the exceptional | |
10219 | execution state because of the raising of an exception in a | |
10220 | routine from this module; otherwise returns FALSE. | |
10221 | *) | |
10222 | ||
10223 | END LongConv. | |
10224 | ||
10225 | @end example | |
10226 | @page | |
10227 | ||
10228 | @node gm2-libs-iso/LongIO, gm2-libs-iso/LongMath, gm2-libs-iso/LongConv, M2 ISO Libraries | |
10229 | @subsection gm2-libs-iso/LongIO | |
10230 | ||
10231 | @example | |
10232 | DEFINITION MODULE LongIO; | |
10233 | ||
10234 | (* Input and output of long real numbers in decimal text form | |
10235 | over specified channels. The read result is of the type | |
10236 | IOConsts.ReadResults. | |
10237 | *) | |
10238 | ||
10239 | IMPORT IOChan; | |
10240 | ||
10241 | (* The text form of a signed fixed-point real number is | |
10242 | ["+" | "-"], decimal digit, @{decimal digit@}, [".", | |
10243 | @{decimal digit@}] | |
10244 | ||
10245 | The text form of a signed floating-point real number is | |
10246 | signed fixed-point real number, | |
10247 | "E", ["+" | "-"], decimal digit, @{decimal digit@} | |
10248 | *) | |
10249 | ||
10250 | @findex ReadReal | |
10251 | PROCEDURE ReadReal (cid: IOChan.ChanId; VAR real: LONGREAL); | |
10252 | (* Skips leading spaces, and removes any remaining characters | |
10253 | from cid that form part of a signed fixed or floating | |
10254 | point number. The value of this number is assigned to real. | |
10255 | The read result is set to the value allRight, outOfRange, | |
10256 | wrongFormat, endOfLine, or endOfInput. | |
10257 | *) | |
10258 | ||
10259 | @findex WriteFloat | |
10260 | PROCEDURE WriteFloat (cid: IOChan.ChanId; real: LONGREAL; | |
10261 | sigFigs: CARDINAL; width: CARDINAL); | |
10262 | (* Writes the value of real to cid in floating-point text form, | |
10263 | with sigFigs significant figures, in a field of the given | |
10264 | minimum width. | |
10265 | *) | |
10266 | ||
10267 | @findex WriteEng | |
10268 | PROCEDURE WriteEng (cid: IOChan.ChanId; real: LONGREAL; | |
10269 | sigFigs: CARDINAL; width: CARDINAL); | |
10270 | (* As for WriteFloat, except that the number is scaled with | |
10271 | one to three digits in the whole number part, and with an | |
10272 | exponent that is a multiple of three. | |
10273 | *) | |
10274 | ||
10275 | @findex WriteFixed | |
10276 | PROCEDURE WriteFixed (cid: IOChan.ChanId; real: LONGREAL; | |
10277 | place: INTEGER; width: CARDINAL); | |
10278 | (* Writes the value of real to cid in fixed-point text form, | |
10279 | rounded to the given place relative to the decimal point, | |
10280 | in a field of the given minimum width. | |
10281 | *) | |
10282 | ||
10283 | @findex WriteReal | |
10284 | PROCEDURE WriteReal (cid: IOChan.ChanId; real: LONGREAL; | |
10285 | width: CARDINAL); | |
10286 | (* Writes the value of real to cid, as WriteFixed if the | |
10287 | sign and magnitude can be shown in the given width, or | |
10288 | otherwise as WriteFloat. The number of places or | |
10289 | significant digits depends on the given width. | |
10290 | *) | |
10291 | ||
10292 | END LongIO. | |
10293 | ||
10294 | @end example | |
10295 | @page | |
10296 | ||
10297 | @node gm2-libs-iso/LongMath, gm2-libs-iso/LongStr, gm2-libs-iso/LongIO, M2 ISO Libraries | |
10298 | @subsection gm2-libs-iso/LongMath | |
10299 | ||
10300 | @example | |
10301 | DEFINITION MODULE LongMath; | |
10302 | ||
10303 | (* Mathematical functions for the type LONGREAL *) | |
10304 | ||
10305 | CONST | |
10306 | @findex pi (const) | |
10307 | pi = 3.1415926535897932384626433832795028841972; | |
10308 | @findex exp1 (const) | |
10309 | exp1 = 2.7182818284590452353602874713526624977572; | |
10310 | ||
10311 | @findex sqrt | |
10312 | PROCEDURE __BUILTIN__ sqrt (x: LONGREAL): LONGREAL; | |
10313 | (* Returns the positive square root of x *) | |
10314 | ||
10315 | @findex exp | |
10316 | PROCEDURE __BUILTIN__ exp (x: LONGREAL): LONGREAL; | |
10317 | (* Returns the exponential of x *) | |
10318 | ||
10319 | @findex ln | |
10320 | PROCEDURE __BUILTIN__ ln (x: LONGREAL): LONGREAL; | |
10321 | (* Returns the natural logarithm of x *) | |
10322 | ||
10323 | (* The angle in all trigonometric functions is measured in radians *) | |
10324 | ||
10325 | @findex sin | |
10326 | PROCEDURE __BUILTIN__ sin (x: LONGREAL): LONGREAL; | |
10327 | (* Returns the sine of x *) | |
10328 | ||
10329 | @findex cos | |
10330 | PROCEDURE __BUILTIN__ cos (x: LONGREAL): LONGREAL; | |
10331 | (* Returns the cosine of x *) | |
10332 | ||
10333 | @findex tan | |
10334 | PROCEDURE tan (x: LONGREAL): LONGREAL; | |
10335 | (* Returns the tangent of x *) | |
10336 | ||
10337 | @findex arcsin | |
10338 | PROCEDURE arcsin (x: LONGREAL): LONGREAL; | |
10339 | (* Returns the arcsine of x *) | |
10340 | ||
10341 | @findex arccos | |
10342 | PROCEDURE arccos (x: LONGREAL): LONGREAL; | |
10343 | (* Returns the arccosine of x *) | |
10344 | ||
10345 | @findex arctan | |
10346 | PROCEDURE arctan (x: LONGREAL): LONGREAL; | |
10347 | (* Returns the arctangent of x *) | |
10348 | ||
10349 | @findex power | |
10350 | PROCEDURE power (base, exponent: LONGREAL): LONGREAL; | |
10351 | (* Returns the value of the number base raised to the power exponent *) | |
10352 | ||
10353 | @findex round | |
10354 | PROCEDURE round (x: LONGREAL): INTEGER; | |
10355 | (* Returns the value of x rounded to the nearest integer *) | |
10356 | ||
10357 | @findex IsRMathException | |
10358 | PROCEDURE IsRMathException (): BOOLEAN; | |
10359 | (* Returns TRUE if the current coroutine is in the exceptional | |
10360 | execution state because of the raising of an exception in a | |
10361 | routine from this module; otherwise returns FALSE. | |
10362 | *) | |
10363 | ||
10364 | END LongMath. | |
10365 | ||
10366 | @end example | |
10367 | @page | |
10368 | ||
10369 | @node gm2-libs-iso/LongStr, gm2-libs-iso/LongWholeIO, gm2-libs-iso/LongMath, M2 ISO Libraries | |
10370 | @subsection gm2-libs-iso/LongStr | |
10371 | ||
10372 | @example | |
10373 | DEFINITION MODULE LongStr; | |
10374 | ||
10375 | (* LONGREAL/string conversions *) | |
10376 | ||
10377 | IMPORT | |
10378 | ConvTypes; | |
10379 | ||
10380 | TYPE | |
10381 | (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) | |
10382 | @findex ConvResults (type) | |
10383 | ConvResults = ConvTypes.ConvResults; | |
10384 | ||
10385 | (* the string form of a signed fixed-point real number is | |
10386 | ["+" | "-"], decimal digit, @{decimal digit@}, [".", | |
10387 | @{decimal digit@}] | |
10388 | *) | |
10389 | ||
10390 | (* the string form of a signed floating-point real number is | |
10391 | signed fixed-point real number, "E", ["+" | "-"], | |
10392 | decimal digit, @{decimal digit@} | |
10393 | *) | |
10394 | ||
10395 | @findex StrToReal | |
10396 | PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: LONGREAL; | |
10397 | VAR res: ConvResults); | |
10398 | (* Ignores any leading spaces in str. If the subsequent characters | |
10399 | in str are in the format of a signed real number, assigns a | |
10400 | corresponding value to real. Assigns a value indicating the | |
10401 | format of str to res. | |
10402 | *) | |
10403 | ||
10404 | @findex RealToFloat | |
10405 | PROCEDURE RealToFloat (real: LONGREAL; sigFigs: CARDINAL; | |
10406 | VAR str: ARRAY OF CHAR); | |
10407 | (* Converts the value of real to floating-point string form, with | |
10408 | sigFigs significant figures, and copies the possibly truncated | |
10409 | result to str. | |
10410 | *) | |
10411 | ||
10412 | @findex RealToEng | |
10413 | PROCEDURE RealToEng (real: LONGREAL; sigFigs: CARDINAL; | |
10414 | VAR str: ARRAY OF CHAR); | |
10415 | (* Converts the value of real to floating-point string form, with | |
10416 | sigFigs significant figures, and copies the possibly truncated | |
10417 | result to str. The number is scaled with one to three digits | |
10418 | in the whole number part and with an exponent that is a | |
10419 | multiple of three. | |
10420 | *) | |
10421 | ||
10422 | @findex RealToFixed | |
10423 | PROCEDURE RealToFixed (real: LONGREAL; place: INTEGER; | |
10424 | VAR str: ARRAY OF CHAR); | |
10425 | (* Converts the value of real to fixed-point string form, rounded | |
10426 | to the given place relative to the decimal point, and copies | |
10427 | the possibly truncated result to str. | |
10428 | *) | |
10429 | ||
10430 | @findex RealToStr | |
10431 | PROCEDURE RealToStr (real: LONGREAL; VAR str: ARRAY OF CHAR); | |
10432 | (* Converts the value of real as RealToFixed if the sign and | |
10433 | magnitude can be shown within the capacity of str, or | |
10434 | otherwise as RealToFloat, and copies the possibly truncated | |
10435 | result to str. The number of places or significant digits | |
10436 | depend on the capacity of str. | |
10437 | *) | |
10438 | ||
10439 | END LongStr. | |
10440 | ||
10441 | @end example | |
10442 | @page | |
10443 | ||
10444 | @node gm2-libs-iso/LongWholeIO, gm2-libs-iso/LowLong, gm2-libs-iso/LongStr, M2 ISO Libraries | |
10445 | @subsection gm2-libs-iso/LongWholeIO | |
10446 | ||
10447 | @example | |
10448 | DEFINITION MODULE LongWholeIO; | |
10449 | ||
10450 | (* Input and output of whole numbers in decimal text form | |
10451 | over specified channels. The read result is of the | |
10452 | type IOConsts.ReadResults. | |
10453 | *) | |
10454 | ||
10455 | IMPORT IOChan; | |
10456 | ||
10457 | (* The text form of a signed whole number is | |
10458 | ["+" | "-"], decimal digit, @{decimal digit@} | |
10459 | ||
10460 | The text form of an unsigned whole number is | |
10461 | decimal digit, @{decimal digit@} | |
10462 | *) | |
10463 | ||
10464 | @findex ReadInt | |
10465 | PROCEDURE ReadInt (cid: IOChan.ChanId; VAR int: LONGINT); | |
10466 | (* Skips leading spaces, and removes any remaining characters | |
10467 | from cid that form part of a signed whole number. The | |
10468 | value of this number is assigned to int. The read result | |
10469 | is set to the value allRight, outOfRange, wrongFormat, | |
10470 | endOfLine, or endOfInput. | |
10471 | *) | |
10472 | ||
10473 | @findex WriteInt | |
10474 | PROCEDURE WriteInt (cid: IOChan.ChanId; int: LONGINT; | |
10475 | width: CARDINAL); | |
10476 | (* Writes the value of int to cid in text form, in a field of | |
10477 | the given minimum width. *) | |
10478 | ||
10479 | @findex ReadCard | |
10480 | PROCEDURE ReadCard (cid: IOChan.ChanId; VAR card: LONGCARD); | |
10481 | (* Skips leading spaces, and removes any remaining characters | |
10482 | from cid that form part of an unsigned whole number. The | |
10483 | value of this number is assigned to card. The read result | |
10484 | is set to the value allRight, outOfRange, wrongFormat, | |
10485 | endOfLine, or endOfInput. | |
10486 | *) | |
10487 | ||
10488 | @findex WriteCard | |
10489 | PROCEDURE WriteCard (cid: IOChan.ChanId; card: LONGCARD; | |
10490 | width: CARDINAL); | |
10491 | (* Writes the value of card to cid in text form, in a field | |
10492 | of the given minimum width. *) | |
10493 | ||
10494 | END LongWholeIO. | |
10495 | @end example | |
10496 | @page | |
10497 | ||
10498 | @node gm2-libs-iso/LowLong, gm2-libs-iso/LowReal, gm2-libs-iso/LongWholeIO, M2 ISO Libraries | |
10499 | @subsection gm2-libs-iso/LowLong | |
10500 | ||
10501 | @example | |
10502 | DEFINITION MODULE LowLong; | |
10503 | ||
10504 | (* Access to underlying properties of the type LONGREAL *) | |
10505 | ||
10506 | CONST | |
10507 | @findex radix (const) | |
10508 | radix = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, radix> )) ; (* ZType *) | |
10509 | @findex places (const) | |
10510 | places = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, places> )) ; (* ZType *) | |
10511 | @findex expoMin (const) | |
10512 | expoMin = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, expoMin> )) ; (* ZType *) | |
10513 | @findex expoMax (const) | |
10514 | expoMax = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, expoMax> )) ; (* ZType *) | |
10515 | @findex large (const) | |
10516 | large = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, large> )) ; (* RType *) | |
10517 | @findex small (const) | |
10518 | small = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, small> )) ; (* RType *) | |
10519 | @findex IEC559 (const) | |
10520 | IEC559 = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, IEC559> )) ; (* BOOLEAN *) | |
10521 | @findex LIA1 (const) | |
10522 | LIA1 = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, LIA1> )) ; (* BOOLEAN *) | |
10523 | @findex ISO (const) | |
10524 | ISO = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, ISO> )) ; (* BOOLEAN *) | |
10525 | @findex IEEE (const) | |
10526 | IEEE = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, IEEE> )) ; (* BOOLEAN *) | |
10527 | @findex rounds (const) | |
10528 | rounds = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, rounds> )) ; (* BOOLEAN *) | |
10529 | @findex gUnderflow (const) | |
10530 | gUnderflow = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, gUnderflow> )) ; (* BOOLEAN *) | |
10531 | @findex exception (const) | |
10532 | exception = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, exception> )) ; (* BOOLEAN *) | |
10533 | @findex extend (const) | |
10534 | extend = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, extend> )) ; (* BOOLEAN *) | |
10535 | @findex nModes (const) | |
10536 | nModes = __ATTRIBUTE__ __BUILTIN__ (( <LONGREAL, nModes> )) ; (* ZType *) | |
10537 | ||
10538 | TYPE | |
10539 | @findex Modes (type) | |
10540 | Modes = PACKEDSET OF [0 .. nModes-1]; | |
10541 | ||
10542 | @findex exponent | |
10543 | PROCEDURE exponent (x: LONGREAL): INTEGER; | |
10544 | (* Returns the exponent value of x *) | |
10545 | ||
10546 | @findex fraction | |
10547 | PROCEDURE fraction (x: LONGREAL): LONGREAL; | |
10548 | (* Returns the significand (or significant part) of x *) | |
10549 | ||
10550 | @findex sign | |
10551 | PROCEDURE sign (x: LONGREAL): LONGREAL; | |
10552 | (* Returns the signum of x *) | |
10553 | ||
10554 | @findex succ | |
10555 | PROCEDURE succ (x: LONGREAL): LONGREAL; | |
10556 | (* Returns the next value of the type LONGREAL greater than x *) | |
10557 | ||
10558 | @findex ulp | |
10559 | PROCEDURE ulp (x: LONGREAL): LONGREAL; | |
10560 | (* Returns the value of a unit in the last place of x *) | |
10561 | ||
10562 | @findex pred | |
10563 | PROCEDURE pred (x: LONGREAL): LONGREAL; | |
10564 | (* Returns the previous value of the type LONGREAL less than x *) | |
10565 | ||
10566 | @findex intpart | |
10567 | PROCEDURE intpart (x: LONGREAL): LONGREAL; | |
10568 | (* Returns the integer part of x *) | |
10569 | ||
10570 | @findex fractpart | |
10571 | PROCEDURE fractpart (x: LONGREAL): LONGREAL; | |
10572 | (* Returns the fractional part of x *) | |
10573 | ||
10574 | @findex scale | |
10575 | PROCEDURE scale (x: LONGREAL; n: INTEGER): LONGREAL; | |
10576 | (* Returns the value of x * radix ** n *) | |
10577 | ||
10578 | @findex trunc | |
10579 | PROCEDURE trunc (x: LONGREAL; n: INTEGER): LONGREAL; | |
10580 | (* Returns the value of the first n places of x *) | |
10581 | ||
10582 | @findex round | |
10583 | PROCEDURE round (x: LONGREAL; n: INTEGER): LONGREAL; | |
10584 | (* Returns the value of x rounded to the first n places *) | |
10585 | ||
10586 | @findex synthesize | |
10587 | PROCEDURE synthesize (expart: INTEGER; frapart: LONGREAL): LONGREAL; | |
10588 | (* Returns a value of the type LONGREAL constructed from the given expart and frapart *) | |
10589 | ||
10590 | @findex setMode | |
10591 | PROCEDURE setMode (m: Modes); | |
10592 | (* Sets status flags appropriate to the underlying implementation of the type LONGREAL *) | |
10593 | ||
10594 | @findex currentMode | |
10595 | PROCEDURE currentMode (): Modes; | |
10596 | (* Returns the current status flags in the form set by setMode *) | |
10597 | ||
10598 | @findex IsLowException | |
10599 | PROCEDURE IsLowException (): BOOLEAN; | |
10600 | (* Returns TRUE if the current coroutine is in the exceptional execution state | |
10601 | because of the raising of an exception in a routine from this module; otherwise | |
10602 | returns FALSE. | |
10603 | *) | |
10604 | ||
10605 | END LowLong. | |
10606 | ||
10607 | @end example | |
10608 | @page | |
10609 | ||
10610 | @node gm2-libs-iso/LowReal, gm2-libs-iso/LowShort, gm2-libs-iso/LowLong, M2 ISO Libraries | |
10611 | @subsection gm2-libs-iso/LowReal | |
10612 | ||
10613 | @example | |
10614 | DEFINITION MODULE LowReal; | |
10615 | ||
10616 | (* Access to underlying properties of the type REAL *) | |
10617 | ||
10618 | CONST | |
10619 | @findex radix (const) | |
10620 | radix = __ATTRIBUTE__ __BUILTIN__ (( <REAL, radix> )) ; (* ZType *) | |
10621 | @findex places (const) | |
10622 | places = __ATTRIBUTE__ __BUILTIN__ (( <REAL, places> )) ; (* ZType *) | |
10623 | @findex expoMin (const) | |
10624 | expoMin = __ATTRIBUTE__ __BUILTIN__ (( <REAL, expoMin> )) ; (* ZType *) | |
10625 | @findex expoMax (const) | |
10626 | expoMax = __ATTRIBUTE__ __BUILTIN__ (( <REAL, expoMax> )) ; (* ZType *) | |
10627 | @findex large (const) | |
10628 | large = __ATTRIBUTE__ __BUILTIN__ (( <REAL, large> )) ; (* RType *) | |
10629 | @findex small (const) | |
10630 | small = __ATTRIBUTE__ __BUILTIN__ (( <REAL, small> )) ; (* RType *) | |
10631 | @findex IEC559 (const) | |
10632 | IEC559 = __ATTRIBUTE__ __BUILTIN__ (( <REAL, IEC559> )) ; (* BOOLEAN *) | |
10633 | @findex LIA1 (const) | |
10634 | LIA1 = __ATTRIBUTE__ __BUILTIN__ (( <REAL, LIA1> )) ; (* BOOLEAN *) | |
10635 | @findex ISO (const) | |
10636 | ISO = __ATTRIBUTE__ __BUILTIN__ (( <REAL, ISO> )) ; (* BOOLEAN *) | |
10637 | @findex IEEE (const) | |
10638 | IEEE = __ATTRIBUTE__ __BUILTIN__ (( <REAL, IEEE> )) ; (* BOOLEAN *) | |
10639 | @findex rounds (const) | |
10640 | rounds = __ATTRIBUTE__ __BUILTIN__ (( <REAL, rounds> )) ; (* BOOLEAN *) | |
10641 | @findex gUnderflow (const) | |
10642 | gUnderflow = __ATTRIBUTE__ __BUILTIN__ (( <REAL, gUnderflow> )) ; (* BOOLEAN *) | |
10643 | @findex exception (const) | |
10644 | exception = __ATTRIBUTE__ __BUILTIN__ (( <REAL, exception> )) ; (* BOOLEAN *) | |
10645 | @findex extend (const) | |
10646 | extend = __ATTRIBUTE__ __BUILTIN__ (( <REAL, extend> )) ; (* BOOLEAN *) | |
10647 | @findex nModes (const) | |
10648 | nModes = __ATTRIBUTE__ __BUILTIN__ (( <REAL, nModes> )) ; (* ZType *) | |
10649 | ||
10650 | TYPE | |
10651 | @findex Modes (type) | |
10652 | Modes = PACKEDSET OF [0..nModes-1]; | |
10653 | ||
10654 | @findex exponent | |
10655 | PROCEDURE exponent (x: REAL): INTEGER; | |
10656 | (* Returns the exponent value of x *) | |
10657 | ||
10658 | @findex fraction | |
10659 | PROCEDURE fraction (x: REAL): REAL; | |
10660 | (* Returns the significand (or significant part) of x *) | |
10661 | ||
10662 | @findex sign | |
10663 | PROCEDURE sign (x: REAL): REAL; | |
10664 | (* Returns the signum of x *) | |
10665 | ||
10666 | @findex succ | |
10667 | PROCEDURE succ (x: REAL): REAL; | |
10668 | (* Returns the next value of the type REAL greater than x *) | |
10669 | ||
10670 | @findex ulp | |
10671 | PROCEDURE ulp (x: REAL): REAL; | |
10672 | (* Returns the value of a unit in the last place of x *) | |
10673 | ||
10674 | @findex pred | |
10675 | PROCEDURE pred (x: REAL): REAL; | |
10676 | (* Returns the previous value of the type REAL less than x *) | |
10677 | ||
10678 | @findex intpart | |
10679 | PROCEDURE intpart (x: REAL): REAL; | |
10680 | (* Returns the integer part of x *) | |
10681 | ||
10682 | @findex fractpart | |
10683 | PROCEDURE fractpart (x: REAL): REAL; | |
10684 | (* Returns the fractional part of x *) | |
10685 | ||
10686 | @findex scale | |
10687 | PROCEDURE scale (x: REAL; n: INTEGER): REAL; | |
10688 | (* Returns the value of x * radix ** n *) | |
10689 | ||
10690 | @findex trunc | |
10691 | PROCEDURE trunc (x: REAL; n: INTEGER): REAL; | |
10692 | (* Returns the value of the first n places of x *) | |
10693 | ||
10694 | @findex round | |
10695 | PROCEDURE round (x: REAL; n: INTEGER): REAL; | |
10696 | (* Returns the value of x rounded to the first n places *) | |
10697 | ||
10698 | @findex synthesize | |
10699 | PROCEDURE synthesize (expart: INTEGER; frapart: REAL): REAL; | |
10700 | (* Returns a value of the type REAL constructed from the given expart and frapart *) | |
10701 | ||
10702 | @findex setMode | |
10703 | PROCEDURE setMode (m: Modes); | |
10704 | (* Sets status flags appropriate to the underlying implementation of the type REAL *) | |
10705 | ||
10706 | @findex currentMode | |
10707 | PROCEDURE currentMode (): Modes; | |
10708 | (* Returns the current status flags in the form set by setMode *) | |
10709 | ||
10710 | @findex IsLowException | |
10711 | PROCEDURE IsLowException (): BOOLEAN; | |
10712 | (* Returns TRUE if the current coroutine is in the exceptional execution state | |
10713 | because of the raising of an exception in a routine from this module; otherwise | |
10714 | returns FALSE. | |
10715 | *) | |
10716 | ||
10717 | END LowReal. | |
10718 | ||
10719 | @end example | |
10720 | @page | |
10721 | ||
10722 | @node gm2-libs-iso/LowShort, gm2-libs-iso/M2EXCEPTION, gm2-libs-iso/LowReal, M2 ISO Libraries | |
10723 | @subsection gm2-libs-iso/LowShort | |
10724 | ||
10725 | @example | |
10726 | DEFINITION MODULE LowShort; | |
10727 | ||
10728 | (* Access to underlying properties of the type SHORTREAL *) | |
10729 | ||
10730 | CONST | |
10731 | @findex radix (const) | |
10732 | radix = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, radix> )) ; (* ZType *) | |
10733 | @findex places (const) | |
10734 | places = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, places> )) ; (* ZType *) | |
10735 | @findex expoMin (const) | |
10736 | expoMin = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, expoMin> )) ; (* ZType *) | |
10737 | @findex expoMax (const) | |
10738 | expoMax = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, expoMax> )) ; (* ZType *) | |
10739 | @findex large (const) | |
10740 | large = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, large> )) ; (* RType *) | |
10741 | @findex small (const) | |
10742 | small = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, small> )) ; (* RType *) | |
10743 | @findex IEC559 (const) | |
10744 | IEC559 = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, IEC559> )) ; (* BOOLEAN *) | |
10745 | @findex LIA1 (const) | |
10746 | LIA1 = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, LIA1> )) ; (* BOOLEAN *) | |
10747 | @findex ISO (const) | |
10748 | ISO = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, ISO> )) ; (* BOOLEAN *) | |
10749 | @findex IEEE (const) | |
10750 | IEEE = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, IEEE> )) ; (* BOOLEAN *) | |
10751 | @findex rounds (const) | |
10752 | rounds = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, rounds> )) ; (* BOOLEAN *) | |
10753 | @findex gUnderflow (const) | |
10754 | gUnderflow = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, gUnderflow> )) ; (* BOOLEAN *) | |
10755 | @findex exception (const) | |
10756 | exception = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, exception> )) ; (* BOOLEAN *) | |
10757 | @findex extend (const) | |
10758 | extend = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, extend> )) ; (* BOOLEAN *) | |
10759 | @findex nModes (const) | |
10760 | nModes = __ATTRIBUTE__ __BUILTIN__ (( <SHORTREAL, nModes> )) ; (* ZType *) | |
10761 | ||
10762 | TYPE | |
10763 | @findex Modes (type) | |
10764 | Modes = PACKEDSET OF [0 .. nModes-1]; | |
10765 | ||
10766 | @findex exponent | |
10767 | PROCEDURE exponent (x: SHORTREAL): INTEGER; | |
10768 | (* Returns the exponent value of x *) | |
10769 | ||
10770 | @findex fraction | |
10771 | PROCEDURE fraction (x: SHORTREAL): SHORTREAL; | |
10772 | (* Returns the significand (or significant part) of x *) | |
10773 | ||
10774 | @findex sign | |
10775 | PROCEDURE sign (x: SHORTREAL): SHORTREAL; | |
10776 | (* Returns the signum of x *) | |
10777 | ||
10778 | @findex succ | |
10779 | PROCEDURE succ (x: SHORTREAL): SHORTREAL; | |
10780 | (* Returns the next value of the type SHORTREAL greater than x *) | |
10781 | ||
10782 | @findex ulp | |
10783 | PROCEDURE ulp (x: SHORTREAL): SHORTREAL; | |
10784 | (* Returns the value of a unit in the last place of x *) | |
10785 | ||
10786 | @findex pred | |
10787 | PROCEDURE pred (x: SHORTREAL): SHORTREAL; | |
10788 | (* Returns the previous value of the type SHORTREAL less than x *) | |
10789 | ||
10790 | @findex intpart | |
10791 | PROCEDURE intpart (x: SHORTREAL): SHORTREAL; | |
10792 | (* Returns the integer part of x *) | |
10793 | ||
10794 | @findex fractpart | |
10795 | PROCEDURE fractpart (x: SHORTREAL): SHORTREAL; | |
10796 | (* Returns the fractional part of x *) | |
10797 | ||
10798 | @findex scale | |
10799 | PROCEDURE scale (x: SHORTREAL; n: INTEGER): SHORTREAL; | |
10800 | (* Returns the value of x * radix ** n *) | |
10801 | ||
10802 | @findex trunc | |
10803 | PROCEDURE trunc (x: SHORTREAL; n: INTEGER): SHORTREAL; | |
10804 | (* Returns the value of the first n places of x *) | |
10805 | ||
10806 | @findex round | |
10807 | PROCEDURE round (x: SHORTREAL; n: INTEGER): SHORTREAL; | |
10808 | (* Returns the value of x rounded to the first n places *) | |
10809 | ||
10810 | @findex synthesize | |
10811 | PROCEDURE synthesize (expart: INTEGER; frapart: SHORTREAL): SHORTREAL; | |
10812 | (* Returns a value of the type SHORTREAL constructed from the given expart and frapart *) | |
10813 | ||
10814 | @findex setMode | |
10815 | PROCEDURE setMode (m: Modes); | |
10816 | (* Sets status flags appropriate to the underlying implementation of the type SHORTREAL *) | |
10817 | ||
10818 | @findex currentMode | |
10819 | PROCEDURE currentMode (): Modes; | |
10820 | (* Returns the current status flags in the form set by setMode *) | |
10821 | ||
10822 | @findex IsLowException | |
10823 | PROCEDURE IsLowException (): BOOLEAN; | |
10824 | (* Returns TRUE if the current coroutine is in the exceptional execution state | |
10825 | because of the raising of an exception in a routine from this module; otherwise | |
10826 | returns FALSE. | |
10827 | *) | |
10828 | ||
10829 | END LowShort. | |
10830 | @end example | |
10831 | @page | |
10832 | ||
10833 | @node gm2-libs-iso/M2EXCEPTION, gm2-libs-iso/M2RTS, gm2-libs-iso/LowShort, M2 ISO Libraries | |
10834 | @subsection gm2-libs-iso/M2EXCEPTION | |
10835 | ||
10836 | @example | |
10837 | DEFINITION MODULE M2EXCEPTION; | |
10838 | ||
10839 | (* Provides facilities for identifying language exceptions *) | |
10840 | ||
10841 | TYPE | |
10842 | @findex M2Exceptions (type) | |
10843 | M2Exceptions = | |
10844 | (indexException, rangeException, caseSelectException, invalidLocation, | |
10845 | functionException, wholeValueException, wholeDivException, realValueException, | |
10846 | realDivException, complexValueException, complexDivException, protException, | |
10847 | sysException, coException, exException | |
10848 | ); | |
10849 | ||
10850 | @findex M2Exception | |
10851 | PROCEDURE M2Exception (): M2Exceptions; | |
10852 | (* If the current coroutine is in the exceptional execution state because of the raising | |
10853 | of a language exception, returns the corresponding enumeration value, and otherwise | |
10854 | raises an exception. | |
10855 | *) | |
10856 | ||
10857 | @findex IsM2Exception | |
10858 | PROCEDURE IsM2Exception (): BOOLEAN; | |
10859 | (* If the current coroutine is in the exceptional execution state because of the raising | |
10860 | of a language exception, returns TRUE, and otherwise returns FALSE. | |
10861 | *) | |
10862 | ||
10863 | END M2EXCEPTION. | |
10864 | @end example | |
10865 | @page | |
10866 | ||
10867 | @node gm2-libs-iso/M2RTS, gm2-libs-iso/MemStream, gm2-libs-iso/M2EXCEPTION, M2 ISO Libraries | |
10868 | @subsection gm2-libs-iso/M2RTS | |
10869 | ||
10870 | @example | |
10871 | DEFINITION MODULE M2RTS ; | |
10872 | ||
10873 | FROM SYSTEM IMPORT ADDRESS ; | |
10874 | ||
10875 | ||
10876 | TYPE | |
10877 | @findex ArgCVEnvP (type) | |
10878 | ArgCVEnvP = PROCEDURE (INTEGER, ADDRESS, ADDRESS) ; | |
10879 | ||
10880 | ||
10881 | @findex ConstructModules | |
10882 | PROCEDURE ConstructModules (applicationmodule: ADDRESS; | |
10883 | argc: INTEGER; argv, envp: ADDRESS) ; | |
10884 | ||
10885 | @findex DeconstructModules | |
10886 | PROCEDURE DeconstructModules (applicationmodule: ADDRESS; | |
10887 | argc: INTEGER; argv, envp: ADDRESS) ; | |
10888 | ||
10889 | ||
10890 | (* | |
10891 | RegisterModule - adds module name to the list of outstanding | |
10892 | modules which need to have their dependencies | |
10893 | explored to determine initialization order. | |
10894 | *) | |
10895 | ||
10896 | @findex RegisterModule | |
10897 | PROCEDURE RegisterModule (name: ADDRESS; | |
10898 | init, fini: ArgCVEnvP; | |
10899 | dependencies: PROC) ; | |
10900 | ||
10901 | ||
10902 | (* | |
10903 | RequestDependant - used to specify that modulename is dependant upon | |
10904 | module dependantmodule. | |
10905 | *) | |
10906 | ||
10907 | @findex RequestDependant | |
10908 | PROCEDURE RequestDependant (modulename, dependantmodule: ADDRESS) ; | |
10909 | ||
10910 | ||
10911 | (* | |
10912 | ExecuteTerminationProcedures - calls each installed termination | |
10913 | procedure in reverse order. | |
10914 | *) | |
10915 | ||
10916 | @findex ExecuteTerminationProcedures | |
10917 | PROCEDURE ExecuteTerminationProcedures ; | |
10918 | ||
10919 | ||
10920 | (* | |
10921 | InstallTerminationProcedure - installs a procedure, p, which will | |
10922 | be called when the procedure | |
10923 | ExecuteTerminationProcedures | |
10924 | is invoked. It returns TRUE is the | |
10925 | procedure is installed. | |
10926 | *) | |
10927 | ||
10928 | @findex InstallTerminationProcedure | |
10929 | PROCEDURE InstallTerminationProcedure (p: PROC) : BOOLEAN ; | |
10930 | ||
10931 | ||
10932 | (* | |
10933 | ExecuteInitialProcedures - executes the initial procedures installed | |
10934 | by InstallInitialProcedure. | |
10935 | *) | |
10936 | ||
10937 | @findex ExecuteInitialProcedures | |
10938 | PROCEDURE ExecuteInitialProcedures ; | |
10939 | ||
10940 | ||
10941 | (* | |
10942 | InstallInitialProcedure - installs a procedure to be executed just | |
10943 | before the BEGIN code section of the main | |
10944 | program module. | |
10945 | *) | |
10946 | ||
10947 | @findex InstallInitialProcedure | |
10948 | PROCEDURE InstallInitialProcedure (p: PROC) : BOOLEAN ; | |
10949 | ||
10950 | ||
10951 | (* | |
10952 | HALT - terminate the current program. The procedure | |
10953 | ExecuteTerminationProcedures | |
10954 | is called before the program is stopped. The parameter | |
10955 | exitcode is optional. If the parameter is not supplied | |
10956 | HALT will call libc 'abort', otherwise it will exit with | |
10957 | the code supplied. Supplying a parameter to HALT has the | |
10958 | same effect as calling ExitOnHalt with the same code and | |
10959 | then calling HALT with no parameter. | |
10960 | *) | |
10961 | ||
10962 | @findex HALT | |
10963 | PROCEDURE HALT ([exitcode: INTEGER = -1]) ; | |
10964 | ||
10965 | ||
10966 | (* | |
10967 | Halt - provides a more user friendly version of HALT, which takes | |
10968 | four parameters to aid debugging. | |
10969 | *) | |
10970 | ||
10971 | @findex Halt | |
10972 | PROCEDURE Halt (file: ARRAY OF CHAR; line: CARDINAL; | |
10973 | function: ARRAY OF CHAR; description: ARRAY OF CHAR) ; | |
10974 | ||
10975 | ||
10976 | (* | |
10977 | ExitOnHalt - if HALT is executed then call exit with the exit code, e. | |
10978 | *) | |
10979 | ||
10980 | @findex ExitOnHalt | |
10981 | PROCEDURE ExitOnHalt (e: INTEGER) ; | |
10982 | ||
10983 | ||
10984 | (* | |
10985 | ErrorMessage - emits an error message to stderr and then calls exit (1). | |
10986 | *) | |
10987 | ||
10988 | @findex ErrorMessage | |
10989 | PROCEDURE ErrorMessage (message: ARRAY OF CHAR; | |
10990 | file: ARRAY OF CHAR; | |
10991 | line: CARDINAL; | |
10992 | function: ARRAY OF CHAR) ; | |
10993 | ||
10994 | ||
10995 | (* | |
10996 | IsTerminating - Returns true if any coroutine has started program termination | |
10997 | and false otherwise. | |
10998 | *) | |
10999 | ||
11000 | @findex IsTerminating | |
11001 | PROCEDURE IsTerminating () : BOOLEAN ; | |
11002 | ||
11003 | ||
11004 | (* | |
11005 | HasHalted - Returns true if a call to HALT has been made and false | |
11006 | otherwise. | |
11007 | *) | |
11008 | ||
11009 | @findex HasHalted | |
11010 | PROCEDURE HasHalted () : BOOLEAN ; | |
11011 | ||
11012 | ||
11013 | (* | |
11014 | Length - returns the length of a string, a. This is called whenever | |
11015 | the user calls LENGTH and the parameter cannot be calculated | |
11016 | at compile time. | |
11017 | *) | |
11018 | ||
11019 | @findex Length | |
11020 | PROCEDURE Length (a: ARRAY OF CHAR) : CARDINAL ; | |
11021 | ||
11022 | ||
11023 | (* | |
11024 | The following are the runtime exception handler routines. | |
11025 | *) | |
11026 | ||
11027 | @findex AssignmentException | |
11028 | PROCEDURE AssignmentException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11029 | @findex ReturnException | |
11030 | PROCEDURE ReturnException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11031 | @findex IncException | |
11032 | PROCEDURE IncException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11033 | @findex DecException | |
11034 | PROCEDURE DecException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11035 | @findex InclException | |
11036 | PROCEDURE InclException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11037 | @findex ExclException | |
11038 | PROCEDURE ExclException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11039 | @findex ShiftException | |
11040 | PROCEDURE ShiftException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11041 | @findex RotateException | |
11042 | PROCEDURE RotateException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11043 | @findex StaticArraySubscriptException | |
11044 | PROCEDURE StaticArraySubscriptException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11045 | @findex DynamicArraySubscriptException | |
11046 | PROCEDURE DynamicArraySubscriptException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11047 | @findex ForLoopBeginException | |
11048 | PROCEDURE ForLoopBeginException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11049 | @findex ForLoopToException | |
11050 | PROCEDURE ForLoopToException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11051 | @findex ForLoopEndException | |
11052 | PROCEDURE ForLoopEndException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11053 | @findex PointerNilException | |
11054 | PROCEDURE PointerNilException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11055 | @findex NoReturnException | |
11056 | PROCEDURE NoReturnException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11057 | @findex CaseException | |
11058 | PROCEDURE CaseException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11059 | @findex WholeNonPosDivException | |
11060 | PROCEDURE WholeNonPosDivException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11061 | @findex WholeNonPosModException | |
11062 | PROCEDURE WholeNonPosModException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11063 | @findex WholeZeroDivException | |
11064 | PROCEDURE WholeZeroDivException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11065 | @findex WholeZeroRemException | |
11066 | PROCEDURE WholeZeroRemException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11067 | @findex WholeValueException | |
11068 | PROCEDURE WholeValueException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11069 | @findex RealValueException | |
11070 | PROCEDURE RealValueException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11071 | @findex ParameterException | |
11072 | PROCEDURE ParameterException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11073 | @findex NoException | |
11074 | PROCEDURE NoException (filename: ADDRESS; line, column: CARDINAL; scope, message: ADDRESS) ; | |
11075 | ||
11076 | ||
11077 | END M2RTS. | |
11078 | @end example | |
11079 | @page | |
11080 | ||
11081 | @node gm2-libs-iso/MemStream, gm2-libs-iso/Preemptive, gm2-libs-iso/M2RTS, M2 ISO Libraries | |
11082 | @subsection gm2-libs-iso/MemStream | |
11083 | ||
11084 | @example | |
11085 | DEFINITION MODULE MemStream ; | |
11086 | ||
11087 | (* | |
11088 | Description: provides an ISO module which can write to a memory | |
11089 | buffer or read from a memory buffer. | |
11090 | *) | |
11091 | ||
11092 | FROM IOChan IMPORT ChanId ; | |
11093 | FROM ChanConsts IMPORT FlagSet, OpenResults ; | |
11094 | FROM SYSTEM IMPORT ADDRESS, LOC ; | |
11095 | ||
11096 | ||
11097 | (* | |
11098 | Attempts to obtain and open a channel connected to a contigeous | |
11099 | buffer in memory. The write flag is implied; without the raw | |
11100 | flag, text is implied. If successful, assigns to cid the identity of | |
11101 | the opened channel, assigns the value opened to res. | |
11102 | If a channel cannot be opened as required, | |
11103 | the value of res indicates the reason, and cid identifies the | |
11104 | invalid channel. | |
11105 | ||
11106 | The parameters, buffer, length and used maybe updated as | |
11107 | data is written. The buffer maybe reallocated | |
11108 | and its address might alter, however the parameters will | |
11109 | always reflect the current active buffer. When this | |
11110 | channel is closed the buffer is deallocated and | |
11111 | buffer will be set to NIL, length and used will be set to | |
11112 | zero. | |
11113 | *) | |
11114 | ||
11115 | @findex OpenWrite | |
11116 | PROCEDURE OpenWrite (VAR cid: ChanId; flags: FlagSet; | |
11117 | VAR res: OpenResults; | |
11118 | VAR buffer: ADDRESS; | |
11119 | VAR length: CARDINAL; | |
11120 | VAR used: CARDINAL; | |
11121 | deallocOnClose: BOOLEAN) ; | |
11122 | ||
11123 | ||
11124 | (* | |
11125 | Attempts to obtain and open a channel connected to a contigeous | |
11126 | buffer in memory. The read and old flags are implied; without | |
11127 | the raw flag, text is implied. If successful, assigns to cid the | |
11128 | identity of the opened channel, assigns the value opened to res, and | |
11129 | selects input mode, with the read position corresponding to the start | |
11130 | of the buffer. If a channel cannot be opened as required, the value of | |
11131 | res indicates the reason, and cid identifies the invalid channel. | |
11132 | *) | |
11133 | ||
11134 | @findex OpenRead | |
11135 | PROCEDURE OpenRead (VAR cid: ChanId; flags: FlagSet; | |
11136 | VAR res: OpenResults; | |
11137 | buffer: ADDRESS; length: CARDINAL; | |
11138 | deallocOnClose: BOOLEAN) ; | |
11139 | ||
11140 | ||
11141 | (* | |
11142 | Close - if the channel identified by cid is not open to | |
11143 | a memory stream, the exception wrongDevice is | |
11144 | raised; otherwise closes the channel, and assigns | |
11145 | the value identifying the invalid channel to cid. | |
11146 | *) | |
11147 | ||
11148 | @findex Close | |
11149 | PROCEDURE Close (VAR cid: ChanId) ; | |
11150 | ||
11151 | ||
11152 | (* | |
11153 | Rewrite - assigns the buffer index to zero. Subsequent | |
11154 | writes will overwrite the previous buffer contents. | |
11155 | *) | |
11156 | ||
11157 | @findex Rewrite | |
11158 | PROCEDURE Rewrite (cid: ChanId) ; | |
11159 | ||
11160 | ||
11161 | (* | |
11162 | Reread - assigns the buffer index to zero. Subsequent | |
11163 | reads will read the previous buffer contents. | |
11164 | *) | |
11165 | ||
11166 | @findex Reread | |
11167 | PROCEDURE Reread (cid: ChanId) ; | |
11168 | ||
11169 | ||
11170 | (* | |
11171 | IsMem - tests if the channel identified by cid is open as | |
11172 | a memory stream. | |
11173 | *) | |
11174 | ||
11175 | @findex IsMem | |
11176 | PROCEDURE IsMem (cid: ChanId) : BOOLEAN ; | |
11177 | ||
11178 | ||
11179 | END MemStream. | |
11180 | @end example | |
11181 | @page | |
11182 | ||
11183 | @node gm2-libs-iso/Preemptive, gm2-libs-iso/Processes, gm2-libs-iso/MemStream, M2 ISO Libraries | |
11184 | @subsection gm2-libs-iso/Preemptive | |
11185 | ||
11186 | @example | |
11187 | DEFINITION MODULE Preemptive ; | |
11188 | ||
11189 | ||
11190 | (* | |
11191 | initPreemptive - if microsecs > 0 then turn on preemptive scheduling. | |
11192 | if microsecs = 0 then preemptive scheduling is turned off. | |
11193 | *) | |
11194 | ||
11195 | @findex initPreemptive | |
11196 | PROCEDURE initPreemptive (seconds, microsecs: CARDINAL) ; | |
11197 | ||
11198 | ||
11199 | END Preemptive. | |
11200 | @end example | |
11201 | @page | |
11202 | ||
11203 | @node gm2-libs-iso/Processes, gm2-libs-iso/ProgramArgs, gm2-libs-iso/Preemptive, M2 ISO Libraries | |
11204 | @subsection gm2-libs-iso/Processes | |
11205 | ||
11206 | @example | |
11207 | DEFINITION MODULE Processes; | |
11208 | ||
11209 | (* This module allows concurrent algorithms to be expressed using | |
11210 | processes. A process is a unit of a program that has the | |
11211 | potential to run in parallel with other processes. | |
11212 | *) | |
11213 | ||
11214 | IMPORT SYSTEM; | |
11215 | ||
11216 | TYPE | |
11217 | ProcessId; (* Used to identify processes *) | |
11218 | @findex Parameter (type) | |
11219 | Parameter = SYSTEM.ADDRESS; (* Used to pass data between processes *) | |
11220 | @findex Body (type) | |
11221 | Body = PROC; (* Used as the type of a process body *) | |
11222 | @findex Urgency (type) | |
11223 | Urgency = INTEGER; (* Used by the internal scheduler *) | |
11224 | @findex Sources (type) | |
11225 | Sources = CARDINAL; (* Used to identify event sources *) | |
11226 | @findex ProcessesExceptions (type) | |
11227 | ProcessesExceptions = (* Exceptions raised by this module *) | |
11228 | (passiveProgram, processError); | |
11229 | ||
11230 | (* The following procedures create processes and switch control between | |
11231 | them. *) | |
11232 | ||
11233 | @findex Create | |
11234 | PROCEDURE Create (procBody: Body; extraSpace: CARDINAL; procUrg: Urgency; | |
11235 | procParams: Parameter; VAR procId: ProcessId); | |
11236 | (* Creates a new process with procBody as its body, and with urgency | |
11237 | and parameters given by procUrg and procParams. At least as | |
11238 | much workspace (in units of SYSTEM.LOC) as is specified by | |
11239 | extraSpace is allocated to the process. | |
11240 | An identity for the new process is returned in procId. | |
11241 | The process is created in the passive state; it will not run | |
11242 | until activated. | |
11243 | *) | |
11244 | ||
11245 | @findex Start | |
11246 | PROCEDURE Start (procBody: Body; extraSpace: CARDINAL; procUrg: Urgency; | |
11247 | procParams: Parameter; VAR procId: ProcessId); | |
11248 | (* Creates a new process, with parameters as for Create. | |
11249 | The process is created in the ready state; it is eligible to | |
11250 | run immediately. | |
11251 | *) | |
11252 | ||
11253 | @findex StopMe | |
11254 | PROCEDURE StopMe (); | |
11255 | (* Terminates the calling process. | |
11256 | The process must not be associated with a source of events. | |
11257 | *) | |
11258 | ||
11259 | @findex SuspendMe | |
11260 | PROCEDURE SuspendMe (); | |
11261 | (* Causes the calling process to enter the passive state. The | |
11262 | procedure only returns when the calling process is again | |
11263 | activated by another process. | |
11264 | *) | |
11265 | ||
11266 | @findex Activate | |
11267 | PROCEDURE Activate (procId: ProcessId); | |
11268 | (* Causes the process identified by procId to enter the ready | |
11269 | state, and thus to become eligible to run again. | |
11270 | *) | |
11271 | ||
11272 | @findex SuspendMeAndActivate | |
11273 | PROCEDURE SuspendMeAndActivate (procId: ProcessId); | |
11274 | (* Executes an atomic sequence of SuspendMe() and | |
11275 | Activate(procId). *) | |
11276 | ||
11277 | @findex Switch | |
11278 | PROCEDURE Switch (procId: ProcessId; VAR info: Parameter); | |
11279 | (* Causes the calling process to enter the passive state; the | |
11280 | process identified by procId becomes the currently executing | |
11281 | process. info is used to pass parameter information from the | |
11282 | calling to the activated process. On return, info will | |
11283 | contain information from the process that chooses to switch | |
11284 | back to this one (or will be NIL if Activate or | |
11285 | SuspendMeAndActivate are used instead of Switch). | |
11286 | *) | |
11287 | ||
11288 | @findex Wait | |
11289 | PROCEDURE Wait (); | |
11290 | (* Causes the calling process to enter the waiting state. | |
11291 | The procedure will return when the calling process is | |
11292 | activated by another process, or when one of its associated | |
11293 | eventSources has generated an event. | |
11294 | *) | |
11295 | ||
11296 | (* The following procedures allow the association of processes | |
11297 | with sources of external events. | |
11298 | *) | |
11299 | ||
11300 | @findex Attach | |
11301 | PROCEDURE Attach (eventSource: Sources); | |
11302 | (* Associates the specified eventSource with the calling | |
11303 | process. *) | |
11304 | ||
11305 | @findex Detach | |
11306 | PROCEDURE Detach (eventSource: Sources); | |
11307 | (* Dissociates the specified eventSource from the program. *) | |
11308 | ||
11309 | @findex IsAttached | |
11310 | PROCEDURE IsAttached (eventSource: Sources): BOOLEAN; | |
11311 | (* Returns TRUE if and only if the specified eventSource is | |
11312 | currently associated with one of the processes of the | |
11313 | program. | |
11314 | *) | |
11315 | ||
11316 | @findex Handler | |
11317 | PROCEDURE Handler (eventSource: Sources): ProcessId; | |
11318 | (* Returns the identity of the process, if any, that is | |
11319 | associated with the specified eventSource. | |
11320 | *) | |
11321 | ||
11322 | (* The following procedures allow processes to obtain their | |
11323 | identity, parameters, and urgency. | |
11324 | *) | |
11325 | ||
11326 | @findex Me | |
11327 | PROCEDURE Me (): ProcessId; | |
11328 | (* Returns the identity of the calling process (as assigned | |
11329 | when the process was first created). | |
11330 | *) | |
11331 | ||
11332 | @findex MyParam | |
11333 | PROCEDURE MyParam (): Parameter; | |
11334 | (* Returns the value specified as procParams when the calling | |
11335 | process was created. *) | |
11336 | ||
11337 | @findex UrgencyOf | |
11338 | PROCEDURE UrgencyOf (procId: ProcessId): Urgency; | |
11339 | (* Returns the urgency established when the process identified | |
11340 | by procId was first created. | |
11341 | *) | |
11342 | ||
11343 | (* The following procedure provides facilities for exception | |
11344 | handlers. *) | |
11345 | ||
11346 | @findex ProcessesException | |
11347 | PROCEDURE ProcessesException (): ProcessesExceptions; | |
11348 | (* If the current coroutine is in the exceptional execution state | |
11349 | because of the raising of a language exception, returns the | |
11350 | corresponding enumeration value, and otherwise raises an | |
11351 | exception. | |
11352 | *) | |
11353 | ||
11354 | @findex IsProcessesException | |
11355 | PROCEDURE IsProcessesException (): BOOLEAN; | |
11356 | (* Returns TRUE if the current coroutine is in the exceptional | |
11357 | execution state because of the raising of an exception in | |
11358 | a routine from this module; otherwise returns FALSE. | |
11359 | *) | |
11360 | ||
11361 | (* | |
11362 | Reschedule - rotates the ready queue and transfers to the process | |
11363 | with the highest run priority. | |
11364 | *) | |
11365 | ||
11366 | @findex Reschedule | |
11367 | PROCEDURE Reschedule ; | |
11368 | ||
11369 | ||
11370 | (* | |
11371 | displayProcesses - | |
11372 | *) | |
11373 | ||
11374 | @findex displayProcesses | |
11375 | PROCEDURE displayProcesses (message: ARRAY OF CHAR) ; | |
11376 | ||
11377 | ||
11378 | END Processes. | |
11379 | @end example | |
11380 | @page | |
11381 | ||
11382 | @node gm2-libs-iso/ProgramArgs, gm2-libs-iso/RTco, gm2-libs-iso/Processes, M2 ISO Libraries | |
11383 | @subsection gm2-libs-iso/ProgramArgs | |
11384 | ||
11385 | @example | |
11386 | DEFINITION MODULE ProgramArgs; | |
11387 | ||
11388 | (* Access to program arguments *) | |
11389 | ||
11390 | IMPORT IOChan; | |
11391 | ||
11392 | TYPE | |
11393 | @findex ChanId (type) | |
11394 | ChanId = IOChan.ChanId; | |
11395 | ||
11396 | @findex ArgChan | |
11397 | PROCEDURE ArgChan (): ChanId; | |
11398 | (* Returns a value that identifies a channel for reading | |
11399 | program arguments *) | |
11400 | ||
11401 | @findex IsArgPresent | |
11402 | PROCEDURE IsArgPresent (): BOOLEAN; | |
11403 | (* Tests if there is a current argument to read from. If not, | |
11404 | read <= IOChan.CurrentFlags() will be FALSE, and attempting | |
11405 | to read from the argument channel will raise the exception | |
11406 | notAvailable. | |
11407 | *) | |
11408 | ||
11409 | @findex NextArg | |
11410 | PROCEDURE NextArg (); | |
11411 | (* If there is another argument, causes subsequent input from the | |
11412 | argument device to come from the start of the next argument. | |
11413 | Otherwise there is no argument to read from, and a call of | |
11414 | IsArgPresent will return FALSE. | |
11415 | *) | |
11416 | ||
11417 | END ProgramArgs. | |
11418 | @end example | |
11419 | @page | |
11420 | ||
11421 | @node gm2-libs-iso/RTco, gm2-libs-iso/RTdata, gm2-libs-iso/ProgramArgs, M2 ISO Libraries | |
11422 | @subsection gm2-libs-iso/RTco | |
11423 | ||
11424 | @example | |
11425 | DEFINITION MODULE RTco ; | |
11426 | ||
11427 | FROM SYSTEM IMPORT ADDRESS ; | |
11428 | ||
11429 | ||
11430 | (* init initializes the module and allows the application to lazily invoke threads. *) | |
11431 | ||
11432 | @findex init | |
11433 | PROCEDURE init () : INTEGER ; | |
11434 | ||
11435 | @findex initThread | |
11436 | PROCEDURE initThread (p: PROC; stackSize: CARDINAL; interruptLevel: CARDINAL) : INTEGER ; | |
11437 | ||
11438 | @findex initSemaphore | |
11439 | PROCEDURE initSemaphore (value: CARDINAL) : INTEGER ; | |
11440 | ||
11441 | @findex wait | |
11442 | PROCEDURE wait (semaphore: INTEGER) ; | |
11443 | ||
11444 | @findex signal | |
11445 | PROCEDURE signal (semaphore: INTEGER) ; | |
11446 | ||
11447 | @findex transfer | |
11448 | PROCEDURE transfer (VAR p1: INTEGER; p2: INTEGER) ; | |
11449 | ||
11450 | @findex waitThread | |
11451 | PROCEDURE waitThread (tid: INTEGER) ; | |
11452 | ||
11453 | @findex signalThread | |
11454 | PROCEDURE signalThread (tid: INTEGER) ; | |
11455 | ||
11456 | @findex currentThread | |
11457 | PROCEDURE currentThread () : INTEGER ; | |
11458 | ||
11459 | ||
11460 | (* currentInterruptLevel returns the interrupt level of the current thread. *) | |
11461 | ||
11462 | @findex currentInterruptLevel | |
11463 | PROCEDURE currentInterruptLevel () : CARDINAL ; | |
11464 | ||
11465 | ||
11466 | (* turninterrupts returns the old interrupt level and assigns the interrupt level | |
11467 | to newLevel. *) | |
11468 | ||
11469 | @findex turnInterrupts | |
11470 | PROCEDURE turnInterrupts (newLevel: CARDINAL) : CARDINAL ; | |
11471 | ||
11472 | ||
11473 | (* | |
11474 | select access to the select system call which will be thread safe. | |
11475 | This is typically called from the idle process to wait for an interrupt. | |
11476 | *) | |
11477 | ||
11478 | @findex select | |
11479 | PROCEDURE select (p1: INTEGER; | |
11480 | p2: ADDRESS; | |
11481 | p3: ADDRESS; | |
11482 | p4: ADDRESS; | |
11483 | p5: ADDRESS) : INTEGER ; | |
11484 | ||
11485 | ||
11486 | END RTco. | |
11487 | @end example | |
11488 | @page | |
11489 | ||
11490 | @node gm2-libs-iso/RTdata, gm2-libs-iso/RTentity, gm2-libs-iso/RTco, M2 ISO Libraries | |
11491 | @subsection gm2-libs-iso/RTdata | |
11492 | ||
11493 | @example | |
11494 | DEFINITION MODULE RTdata ; | |
11495 | ||
11496 | (* | |
11497 | Description: provides a mechanism whereby devices can store | |
11498 | data attached to a device. | |
11499 | *) | |
11500 | ||
11501 | FROM SYSTEM IMPORT ADDRESS ; | |
11502 | FROM IOLink IMPORT DeviceTablePtr ; | |
11503 | ||
11504 | TYPE | |
11505 | @findex ModuleId (type) | |
11506 | ModuleId ; | |
11507 | @findex FreeProcedure (type) | |
11508 | FreeProcedure = PROCEDURE (ADDRESS) ; | |
11509 | ||
11510 | ||
11511 | (* | |
11512 | MakeModuleId - creates a unique module Id. | |
11513 | *) | |
11514 | ||
11515 | @findex MakeModuleId | |
11516 | PROCEDURE MakeModuleId (VAR m: ModuleId) ; | |
11517 | ||
11518 | ||
11519 | (* | |
11520 | InitData - adds, datum, to the device, d. The datum | |
11521 | is associated with ModuleID, m. | |
11522 | *) | |
11523 | ||
11524 | @findex InitData | |
11525 | PROCEDURE InitData (d: DeviceTablePtr; m: ModuleId; | |
11526 | datum: ADDRESS; f: FreeProcedure) ; | |
11527 | ||
11528 | ||
11529 | (* | |
11530 | GetData - returns the datum assocated with ModuleId, m. | |
11531 | *) | |
11532 | ||
11533 | @findex GetData | |
11534 | PROCEDURE GetData (d: DeviceTablePtr; m: ModuleId) : ADDRESS ; | |
11535 | ||
11536 | ||
11537 | (* | |
11538 | KillData - destroys the datum associated with ModuleId, m, | |
11539 | in device, d. It invokes the free procedure | |
11540 | given during InitData. | |
11541 | *) | |
11542 | ||
11543 | @findex KillData | |
11544 | PROCEDURE KillData (d: DeviceTablePtr; m: ModuleId) ; | |
11545 | ||
11546 | ||
11547 | END RTdata. | |
11548 | @end example | |
11549 | @page | |
11550 | ||
11551 | @node gm2-libs-iso/RTentity, gm2-libs-iso/RTfio, gm2-libs-iso/RTdata, M2 ISO Libraries | |
11552 | @subsection gm2-libs-iso/RTentity | |
11553 | ||
11554 | @example | |
11555 | DEFINITION MODULE RTentity ; | |
11556 | ||
11557 | (* | |
11558 | Description: provides a set of routines for maintaining an | |
11559 | efficient mechanism to group opaque (or pointer) | |
11560 | data structures together. Internally the | |
11561 | entities are grouped together using a binary | |
11562 | tree. It does not use Storage - and instead | |
11563 | uses malloc, free from libc as Storage uses the | |
11564 | module to detect erroneous deallocations. | |
11565 | *) | |
11566 | ||
11567 | IMPORT SYSTEM ; | |
11568 | ||
11569 | TYPE | |
11570 | @findex Group (type) | |
11571 | Group ; | |
11572 | ||
11573 | ||
11574 | @findex InitGroup | |
11575 | PROCEDURE InitGroup () : Group ; | |
11576 | @findex KillGroup | |
11577 | PROCEDURE KillGroup (g: Group) : Group ; | |
11578 | @findex GetKey | |
11579 | PROCEDURE GetKey (g: Group; a: SYSTEM.ADDRESS) : CARDINAL ; | |
11580 | @findex PutKey | |
11581 | PROCEDURE PutKey (g: Group; a: SYSTEM.ADDRESS; key: CARDINAL) ; | |
11582 | @findex DelKey | |
11583 | PROCEDURE DelKey (g: Group; a: SYSTEM.ADDRESS) ; | |
11584 | @findex IsIn | |
11585 | PROCEDURE IsIn (g: Group; a: SYSTEM.ADDRESS) : BOOLEAN ; | |
11586 | ||
11587 | ||
11588 | END RTentity. | |
11589 | @end example | |
11590 | @page | |
11591 | ||
11592 | @node gm2-libs-iso/RTfio, gm2-libs-iso/RTgen, gm2-libs-iso/RTentity, M2 ISO Libraries | |
11593 | @subsection gm2-libs-iso/RTfio | |
11594 | ||
11595 | @example | |
11596 | DEFINITION MODULE RTfio ; | |
11597 | ||
11598 | (* | |
11599 | Description: provides default FIO based methods for the RTgenif | |
11600 | procedures. These will be used by StreamFile, | |
11601 | SeqFile, StdChans, TermFile and RndFile. | |
11602 | *) | |
11603 | ||
11604 | FROM SYSTEM IMPORT ADDRESS ; | |
11605 | FROM IOLink IMPORT DeviceTablePtr; | |
11606 | FROM RTgenif IMPORT GenDevIF ; | |
11607 | ||
11608 | ||
11609 | (* | |
11610 | doreadchar - returns a CHAR from the file associated with, g. | |
11611 | *) | |
11612 | ||
11613 | @findex doreadchar | |
11614 | PROCEDURE doreadchar (g: GenDevIF; d: DeviceTablePtr) : CHAR ; | |
11615 | ||
11616 | ||
11617 | (* | |
11618 | dounreadchar - pushes a CHAR back onto the file associated | |
11619 | with, g. | |
11620 | *) | |
11621 | ||
11622 | @findex dounreadchar | |
11623 | PROCEDURE dounreadchar (g: GenDevIF; d: DeviceTablePtr; ch: CHAR) : CHAR ; | |
11624 | ||
11625 | ||
11626 | (* | |
11627 | dogeterrno - returns the errno relating to the generic device. | |
11628 | *) | |
11629 | ||
11630 | @findex dogeterrno | |
11631 | PROCEDURE dogeterrno (g: GenDevIF; d: DeviceTablePtr) : INTEGER ; | |
11632 | ||
11633 | ||
11634 | (* | |
11635 | dorbytes - reads upto, max, bytes setting, actual, and | |
11636 | returning FALSE if an error (not due to eof) | |
11637 | occurred. | |
11638 | *) | |
11639 | ||
11640 | @findex dorbytes | |
11641 | PROCEDURE dorbytes (g: GenDevIF; | |
11642 | d: DeviceTablePtr; | |
11643 | to: ADDRESS; | |
11644 | max: CARDINAL; | |
11645 | VAR actual: CARDINAL) : BOOLEAN ; | |
11646 | ||
11647 | (* | |
11648 | dowbytes - writes up to, nBytes. It returns FALSE | |
11649 | if an error occurred and it sets actual | |
11650 | to the amount of data written. | |
11651 | *) | |
11652 | ||
11653 | @findex dowbytes | |
11654 | PROCEDURE dowbytes (g: GenDevIF; | |
11655 | d: DeviceTablePtr; | |
11656 | from: ADDRESS; | |
11657 | nBytes: CARDINAL; | |
11658 | VAR actual: CARDINAL) : BOOLEAN ; | |
11659 | ||
11660 | ||
11661 | (* | |
11662 | dowriteln - attempt to write an end of line marker to the | |
11663 | file and returns TRUE if successful. | |
11664 | *) | |
11665 | ||
11666 | @findex dowriteln | |
11667 | PROCEDURE dowriteln (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; | |
11668 | ||
11669 | ||
11670 | (* | |
11671 | iseof - returns TRUE if end of file has been seen. | |
11672 | *) | |
11673 | ||
11674 | @findex iseof | |
11675 | PROCEDURE iseof (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; | |
11676 | ||
11677 | ||
11678 | (* | |
11679 | iseoln - returns TRUE if end of line has been seen. | |
11680 | *) | |
11681 | ||
11682 | @findex iseoln | |
11683 | PROCEDURE iseoln (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; | |
11684 | ||
11685 | ||
11686 | (* | |
11687 | iserror - returns TRUE if an error was seen on the device. | |
11688 | Note that reaching EOF is not classified as an | |
11689 | error. | |
11690 | *) | |
11691 | ||
11692 | @findex iserror | |
11693 | PROCEDURE iserror (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; | |
11694 | ||
11695 | ||
11696 | END RTfio. | |
11697 | @end example | |
11698 | @page | |
11699 | ||
11700 | @node gm2-libs-iso/RTgen, gm2-libs-iso/RTgenif, gm2-libs-iso/RTfio, M2 ISO Libraries | |
11701 | @subsection gm2-libs-iso/RTgen | |
11702 | ||
11703 | @example | |
11704 | DEFINITION MODULE RTgen ; | |
11705 | ||
11706 | (* | |
11707 | Description: provides a generic device interface between | |
11708 | ISO channels and the underlying PIM style | |
11709 | FIO procedure calls. | |
11710 | *) | |
11711 | ||
11712 | FROM RTgenif IMPORT GenDevIF ; | |
11713 | FROM IOLink IMPORT DeviceId, DeviceTablePtr; | |
11714 | FROM IOConsts IMPORT ReadResults ; | |
11715 | FROM SYSTEM IMPORT ADDRESS ; | |
11716 | ||
11717 | ||
11718 | TYPE | |
11719 | @findex ChanDev (type) | |
11720 | ChanDev ; | |
11721 | @findex DeviceType (type) | |
11722 | DeviceType = (seqfile, streamfile, programargs, stdchans, term, socket, rndfile) ; | |
11723 | ||
11724 | ||
11725 | (* | |
11726 | InitChanDev - initialize and return a ChanDev. | |
11727 | *) | |
11728 | ||
11729 | @findex InitChanDev | |
11730 | PROCEDURE InitChanDev (t: DeviceType; d: DeviceId; g: GenDevIF) : ChanDev ; | |
11731 | ||
11732 | ||
11733 | (* | |
11734 | KillChanDev - deallocates, g. | |
11735 | *) | |
11736 | ||
11737 | @findex KillChanDev | |
11738 | PROCEDURE KillChanDev (g: GenDevIF) : GenDevIF ; | |
11739 | ||
11740 | ||
11741 | (* | |
11742 | RaiseEOFinLook - returns TRUE if the Look procedure | |
11743 | should raise an exception if it | |
11744 | sees end of file. | |
11745 | *) | |
11746 | ||
11747 | @findex RaiseEOFinLook | |
11748 | PROCEDURE RaiseEOFinLook (g: ChanDev) : BOOLEAN ; | |
11749 | ||
11750 | ||
11751 | (* | |
11752 | RaiseEOFinSkip - returns TRUE if the Skip procedure | |
11753 | should raise an exception if it | |
11754 | sees end of file. | |
11755 | *) | |
11756 | ||
11757 | @findex RaiseEOFinSkip | |
11758 | PROCEDURE RaiseEOFinSkip (g: ChanDev) : BOOLEAN ; | |
11759 | ||
11760 | ||
11761 | @findex doLook | |
11762 | PROCEDURE doLook (g: ChanDev; | |
11763 | d: DeviceTablePtr; | |
11764 | VAR ch: CHAR; | |
11765 | VAR r: ReadResults) ; | |
11766 | ||
11767 | @findex doSkip | |
11768 | PROCEDURE doSkip (g: ChanDev; | |
11769 | d: DeviceTablePtr) ; | |
11770 | ||
11771 | @findex doSkipLook | |
11772 | PROCEDURE doSkipLook (g: ChanDev; | |
11773 | d: DeviceTablePtr; | |
11774 | VAR ch: CHAR; | |
11775 | VAR r: ReadResults) ; | |
11776 | ||
11777 | @findex doWriteLn | |
11778 | PROCEDURE doWriteLn (g: ChanDev; | |
11779 | d: DeviceTablePtr) ; | |
11780 | ||
11781 | @findex doReadText | |
11782 | PROCEDURE doReadText (g: ChanDev; | |
11783 | d: DeviceTablePtr; | |
11784 | to: ADDRESS; | |
11785 | maxChars: CARDINAL; | |
11786 | VAR charsRead: CARDINAL) ; | |
11787 | ||
11788 | @findex doWriteText | |
11789 | PROCEDURE doWriteText (g: ChanDev; | |
11790 | d: DeviceTablePtr; | |
11791 | from: ADDRESS; | |
11792 | charsToWrite: CARDINAL) ; | |
11793 | ||
11794 | @findex doReadLocs | |
11795 | PROCEDURE doReadLocs (g: ChanDev; | |
11796 | d: DeviceTablePtr; | |
11797 | to: ADDRESS; | |
11798 | maxLocs: CARDINAL; | |
11799 | VAR locsRead: CARDINAL) ; | |
11800 | ||
11801 | @findex doWriteLocs | |
11802 | PROCEDURE doWriteLocs (g: ChanDev; | |
11803 | d: DeviceTablePtr; | |
11804 | from: ADDRESS; | |
11805 | locsToWrite: CARDINAL) ; | |
11806 | ||
11807 | (* | |
11808 | checkErrno - checks a number of errno conditions and raises | |
11809 | appropriate ISO exceptions if they occur. | |
11810 | *) | |
11811 | ||
11812 | @findex checkErrno | |
11813 | PROCEDURE checkErrno (g: ChanDev; d: DeviceTablePtr) ; | |
11814 | ||
11815 | ||
11816 | END RTgen. | |
11817 | @end example | |
11818 | @page | |
11819 | ||
11820 | @node gm2-libs-iso/RTgenif, gm2-libs-iso/RTio, gm2-libs-iso/RTgen, M2 ISO Libraries | |
11821 | @subsection gm2-libs-iso/RTgenif | |
11822 | ||
11823 | @example | |
11824 | DEFINITION MODULE RTgenif ; | |
11825 | ||
11826 | (* | |
11827 | Description: provides a generic interface mechanism used | |
11828 | by RTgen. This is not an ISO module but rather | |
11829 | a runtime support module. | |
11830 | *) | |
11831 | ||
11832 | FROM SYSTEM IMPORT ADDRESS ; | |
11833 | FROM IOLink IMPORT DeviceId, DeviceTablePtr ; | |
11834 | ||
11835 | TYPE | |
11836 | @findex GenDevIF (type) | |
11837 | GenDevIF ; | |
11838 | @findex readchar (type) | |
11839 | readchar = PROCEDURE (GenDevIF, DeviceTablePtr) : CHAR ; | |
11840 | @findex unreadchar (type) | |
11841 | unreadchar = PROCEDURE (GenDevIF, DeviceTablePtr, CHAR) : CHAR ; | |
11842 | @findex geterrno (type) | |
11843 | geterrno = PROCEDURE (GenDevIF, DeviceTablePtr) : INTEGER ; | |
11844 | @findex readbytes (type) | |
11845 | readbytes = PROCEDURE (GenDevIF, DeviceTablePtr, ADDRESS, CARDINAL, VAR CARDINAL) : BOOLEAN ; | |
11846 | @findex writebytes (type) | |
11847 | writebytes = PROCEDURE (GenDevIF, DeviceTablePtr, ADDRESS, CARDINAL, VAR CARDINAL) : BOOLEAN ; | |
11848 | @findex writeln (type) | |
11849 | writeln = PROCEDURE (GenDevIF, DeviceTablePtr) : BOOLEAN ; | |
11850 | @findex iseof (type) | |
11851 | iseof = PROCEDURE (GenDevIF, DeviceTablePtr) : BOOLEAN ; | |
11852 | @findex iseoln (type) | |
11853 | iseoln = PROCEDURE (GenDevIF, DeviceTablePtr) : BOOLEAN ; | |
11854 | @findex iserror (type) | |
11855 | iserror = PROCEDURE (GenDevIF, DeviceTablePtr) : BOOLEAN ; | |
11856 | ||
11857 | ||
11858 | (* | |
11859 | InitGenDevIF - initializes a generic device. | |
11860 | *) | |
11861 | ||
11862 | @findex InitGenDevIF | |
11863 | PROCEDURE InitGenDevIF (d : DeviceId; | |
11864 | rc : readchar; | |
11865 | urc : unreadchar; | |
11866 | geterr: geterrno; | |
11867 | rbytes: readbytes; | |
11868 | wbytes: writebytes; | |
11869 | wl : writeln; | |
11870 | eof : iseof; | |
11871 | eoln : iseoln; | |
11872 | iserr : iserror) : GenDevIF ; | |
11873 | ||
11874 | ||
11875 | (* | |
11876 | getDID - returns the device id this generic interface. | |
11877 | *) | |
11878 | ||
11879 | @findex getDID | |
11880 | PROCEDURE getDID (g: GenDevIF) : DeviceId ; | |
11881 | ||
11882 | ||
11883 | (* | |
11884 | doReadChar - returns the next character from the generic | |
11885 | device. | |
11886 | *) | |
11887 | ||
11888 | @findex doReadChar | |
11889 | PROCEDURE doReadChar (g: GenDevIF; d: DeviceTablePtr) : CHAR ; | |
11890 | ||
11891 | ||
11892 | (* | |
11893 | doUnReadChar - pushes back a character to the generic device. | |
11894 | *) | |
11895 | ||
11896 | @findex doUnReadChar | |
11897 | PROCEDURE doUnReadChar (g: GenDevIF; d: DeviceTablePtr; ch: CHAR) : CHAR ; | |
11898 | ||
11899 | ||
11900 | (* | |
11901 | doGetErrno - returns the errno relating to the generic device. | |
11902 | *) | |
11903 | ||
11904 | @findex doGetErrno | |
11905 | PROCEDURE doGetErrno (g: GenDevIF; d: DeviceTablePtr) : INTEGER ; | |
11906 | ||
11907 | ||
11908 | (* | |
11909 | doRBytes - attempts to read, n, bytes from the generic device. | |
11910 | It set the actual amount read and returns a boolean | |
11911 | to determine whether an error occurred. | |
11912 | *) | |
11913 | ||
11914 | @findex doRBytes | |
11915 | PROCEDURE doRBytes (g: GenDevIF; d: DeviceTablePtr; | |
11916 | to: ADDRESS; max: CARDINAL; | |
11917 | VAR actual: CARDINAL) : BOOLEAN ; | |
11918 | ||
11919 | ||
11920 | (* | |
11921 | doWBytes - attempts to write, n, bytes to the generic device. | |
11922 | It sets the actual amount written and returns a | |
11923 | boolean to determine whether an error occurred. | |
11924 | *) | |
11925 | ||
11926 | @findex doWBytes | |
11927 | PROCEDURE doWBytes (g: GenDevIF; d: DeviceTablePtr; | |
11928 | from: ADDRESS; max: CARDINAL; | |
11929 | VAR actual: CARDINAL) : BOOLEAN ; | |
11930 | ||
11931 | ||
11932 | (* | |
11933 | doWrLn - writes an end of line marker and returns | |
11934 | TRUE if successful. | |
11935 | *) | |
11936 | ||
11937 | @findex doWrLn | |
11938 | PROCEDURE doWrLn (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; | |
11939 | ||
11940 | ||
11941 | (* | |
11942 | isEOF - returns true if the end of file was reached. | |
11943 | *) | |
11944 | ||
11945 | @findex isEOF | |
11946 | PROCEDURE isEOF (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; | |
11947 | ||
11948 | ||
11949 | (* | |
11950 | isEOLN - returns true if the end of line was reached. | |
11951 | *) | |
11952 | ||
11953 | @findex isEOLN | |
11954 | PROCEDURE isEOLN (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; | |
11955 | ||
11956 | ||
11957 | (* | |
11958 | isError - returns true if an error was seen in the device. | |
11959 | *) | |
11960 | ||
11961 | @findex isError | |
11962 | PROCEDURE isError (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; | |
11963 | ||
11964 | ||
11965 | (* | |
11966 | KillGenDevIF - deallocates a generic device. | |
11967 | *) | |
11968 | ||
11969 | @findex KillGenDevIF | |
11970 | PROCEDURE KillGenDevIF (g: GenDevIF) : GenDevIF ; | |
11971 | ||
11972 | ||
11973 | END RTgenif. | |
11974 | @end example | |
11975 | @page | |
11976 | ||
11977 | @node gm2-libs-iso/RTio, gm2-libs-iso/RandomNumber, gm2-libs-iso/RTgenif, M2 ISO Libraries | |
11978 | @subsection gm2-libs-iso/RTio | |
11979 | ||
11980 | @example | |
11981 | DEFINITION MODULE RTio ; | |
11982 | ||
11983 | (* | |
11984 | Description: provides low level routines for creating and destroying | |
11985 | ChanIds. This is necessary to allow multiple modules | |
11986 | to create, ChanId values, where ChanId is an opaque | |
11987 | type. | |
11988 | *) | |
11989 | ||
11990 | IMPORT FIO, IOLink ; | |
11991 | ||
11992 | TYPE | |
11993 | @findex ChanId (type) | |
11994 | ChanId ; | |
11995 | ||
11996 | ||
11997 | (* | |
11998 | InitChanId - return a new ChanId. | |
11999 | *) | |
12000 | ||
12001 | @findex InitChanId | |
12002 | PROCEDURE InitChanId () : ChanId ; | |
12003 | ||
12004 | ||
12005 | (* | |
12006 | KillChanId - deallocate a ChanId. | |
12007 | *) | |
12008 | ||
12009 | @findex KillChanId | |
12010 | PROCEDURE KillChanId (c: ChanId) : ChanId ; | |
12011 | ||
12012 | ||
12013 | (* | |
12014 | NilChanId - return a NIL pointer. | |
12015 | *) | |
12016 | ||
12017 | @findex NilChanId | |
12018 | PROCEDURE NilChanId () : ChanId ; | |
12019 | ||
12020 | ||
12021 | (* | |
12022 | GetDeviceId - returns the device id, from, c. | |
12023 | *) | |
12024 | ||
12025 | @findex GetDeviceId | |
12026 | PROCEDURE GetDeviceId (c: ChanId) : IOLink.DeviceId ; | |
12027 | ||
12028 | ||
12029 | (* | |
12030 | SetDeviceId - sets the device id in, c. | |
12031 | *) | |
12032 | ||
12033 | @findex SetDeviceId | |
12034 | PROCEDURE SetDeviceId (c: ChanId; d: IOLink.DeviceId) ; | |
12035 | ||
12036 | ||
12037 | (* | |
12038 | GetDevicePtr - returns the device table ptr, from, c. | |
12039 | *) | |
12040 | ||
12041 | @findex GetDevicePtr | |
12042 | PROCEDURE GetDevicePtr (c: ChanId) : IOLink.DeviceTablePtr ; | |
12043 | ||
12044 | ||
12045 | (* | |
12046 | SetDevicePtr - sets the device table ptr in, c. | |
12047 | *) | |
12048 | ||
12049 | @findex SetDevicePtr | |
12050 | PROCEDURE SetDevicePtr (c: ChanId; p: IOLink.DeviceTablePtr) ; | |
12051 | ||
12052 | ||
12053 | (* | |
12054 | GetFile - returns the file field from, c. | |
12055 | *) | |
12056 | ||
12057 | @findex GetFile | |
12058 | PROCEDURE GetFile (c: ChanId) : FIO.File ; | |
12059 | ||
12060 | ||
12061 | (* | |
12062 | SetFile - sets the file field in, c. | |
12063 | *) | |
12064 | ||
12065 | @findex SetFile | |
12066 | PROCEDURE SetFile (c: ChanId; f: FIO.File) ; | |
12067 | ||
12068 | ||
12069 | END RTio. | |
12070 | @end example | |
12071 | @page | |
12072 | ||
12073 | @node gm2-libs-iso/RandomNumber, gm2-libs-iso/RawIO, gm2-libs-iso/RTio, M2 ISO Libraries | |
12074 | @subsection gm2-libs-iso/RandomNumber | |
12075 | ||
12076 | @example | |
12077 | DEFINITION MODULE RandomNumber ; | |
12078 | ||
12079 | (* | |
12080 | Description: provides primitives for obtaining random numbers on | |
12081 | pervasive data types. | |
12082 | *) | |
12083 | ||
12084 | FROM SYSTEM IMPORT BYTE ; | |
12085 | EXPORT QUALIFIED Randomize, RandomInit, RandomBytes, | |
12086 | RandomCard, RandomShortCard, RandomLongCard, | |
12087 | RandomInt, RandomShortInt, RandomLongInt, | |
12088 | RandomReal, RandomLongReal, RandomShortReal ; | |
12089 | ||
12090 | ||
12091 | (* | |
12092 | Randomize - initialize the random number generator with a seed | |
12093 | based on the microseconds. | |
12094 | *) | |
12095 | ||
12096 | @findex Randomize | |
12097 | PROCEDURE Randomize ; | |
12098 | ||
12099 | ||
12100 | (* | |
12101 | RandomInit - initialize the random number generator with value, seed. | |
12102 | *) | |
12103 | ||
12104 | @findex RandomInit | |
12105 | PROCEDURE RandomInit (seed: CARDINAL) ; | |
12106 | ||
12107 | ||
12108 | (* | |
12109 | RandomBytes - fills in an array with random values. | |
12110 | *) | |
12111 | ||
12112 | @findex RandomBytes | |
12113 | PROCEDURE RandomBytes (VAR a: ARRAY OF BYTE) ; | |
12114 | ||
12115 | ||
12116 | (* | |
12117 | RandomInt - return an INTEGER in the range [low .. high]. | |
12118 | *) | |
12119 | ||
12120 | @findex RandomInt | |
12121 | PROCEDURE RandomInt (low, high: INTEGER) : INTEGER ; | |
12122 | ||
12123 | ||
12124 | (* | |
12125 | RandomShortInt - return an SHORTINT in the range [low..high]. | |
12126 | *) | |
12127 | ||
12128 | @findex RandomShortInt | |
12129 | PROCEDURE RandomShortInt (low, high: SHORTINT) : SHORTINT ; | |
12130 | ||
12131 | ||
12132 | (* | |
12133 | RandomLongInt - return an LONGINT in the range [low..high]. | |
12134 | *) | |
12135 | ||
12136 | @findex RandomLongInt | |
12137 | PROCEDURE RandomLongInt (low, high: LONGINT) : LONGINT ; | |
12138 | ||
12139 | ||
12140 | (* | |
12141 | RandomShortCard - return a SHORTCARD in the range [low..high]. | |
12142 | *) | |
12143 | ||
12144 | @findex RandomShortCard | |
12145 | PROCEDURE RandomShortCard (low, high: CARDINAL) : CARDINAL ; | |
12146 | ||
12147 | ||
12148 | (* | |
12149 | RandomCard - return a CARDINAL in the range [low..high]. | |
12150 | *) | |
12151 | ||
12152 | @findex RandomCard | |
12153 | PROCEDURE RandomCard (low, high: CARDINAL) : CARDINAL ; | |
12154 | ||
12155 | ||
12156 | (* | |
12157 | RandomLongCard - return an LONGCARD in the range [low..high]. | |
12158 | *) | |
12159 | ||
12160 | @findex RandomLongCard | |
12161 | PROCEDURE RandomLongCard (low, high: LONGCARD) : LONGCARD ; | |
12162 | ||
12163 | ||
12164 | (* | |
12165 | RandomReal - return a REAL number in the range 0.0..1.0 | |
12166 | *) | |
12167 | ||
12168 | @findex RandomReal | |
12169 | PROCEDURE RandomReal () : REAL ; | |
12170 | ||
12171 | ||
12172 | (* | |
12173 | RandomShortReal - return a SHORTREAL number in the range 0.0..1.0 | |
12174 | *) | |
12175 | ||
12176 | @findex RandomShortReal | |
12177 | PROCEDURE RandomShortReal () : SHORTREAL ; | |
12178 | ||
12179 | ||
12180 | (* | |
12181 | RandomLongReal - return a LONGREAL number in the range 0.0..1.0 | |
12182 | *) | |
12183 | ||
12184 | @findex RandomLongReal | |
12185 | PROCEDURE RandomLongReal () : LONGREAL ; | |
12186 | ||
12187 | ||
12188 | END RandomNumber. | |
12189 | @end example | |
12190 | @page | |
12191 | ||
12192 | @node gm2-libs-iso/RawIO, gm2-libs-iso/RealConv, gm2-libs-iso/RandomNumber, M2 ISO Libraries | |
12193 | @subsection gm2-libs-iso/RawIO | |
12194 | ||
12195 | @example | |
12196 | DEFINITION MODULE RawIO; | |
12197 | ||
12198 | (* Reading and writing data over specified channels using raw | |
12199 | operations, that is, with no conversion or interpretation. | |
12200 | The read result is of the type IOConsts.ReadResults. | |
12201 | *) | |
12202 | ||
12203 | IMPORT IOChan, SYSTEM; | |
12204 | ||
12205 | @findex Read | |
12206 | PROCEDURE Read (cid: IOChan.ChanId; VAR to: ARRAY OF SYSTEM.LOC); | |
12207 | (* Reads storage units from cid, and assigns them to | |
12208 | successive components of to. The read result is set | |
12209 | to the value allRight, wrongFormat, or endOfInput. | |
12210 | *) | |
12211 | ||
12212 | @findex Write | |
12213 | PROCEDURE Write (cid: IOChan.ChanId; from: ARRAY OF SYSTEM.LOC); | |
12214 | (* Writes storage units to cid from successive components | |
12215 | of from. *) | |
12216 | ||
12217 | END RawIO. | |
12218 | ||
12219 | @end example | |
12220 | @page | |
12221 | ||
12222 | @node gm2-libs-iso/RealConv, gm2-libs-iso/RealIO, gm2-libs-iso/RawIO, M2 ISO Libraries | |
12223 | @subsection gm2-libs-iso/RealConv | |
12224 | ||
12225 | @example | |
12226 | DEFINITION MODULE RealConv; | |
12227 | ||
12228 | (* Low-level REAL/string conversions *) | |
12229 | ||
12230 | IMPORT | |
12231 | ConvTypes; | |
12232 | ||
12233 | TYPE | |
12234 | (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) | |
12235 | @findex ConvResults (type) | |
12236 | ConvResults = ConvTypes.ConvResults; | |
12237 | ||
12238 | @findex ScanReal | |
12239 | PROCEDURE ScanReal (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass; | |
12240 | VAR nextState: ConvTypes.ScanState); | |
12241 | (* Represents the start state of a finite state scanner for real | |
12242 | numbers - assigns class of inputCh to chClass and a procedure | |
12243 | representing the next state to nextState. | |
12244 | *) | |
12245 | ||
12246 | @findex FormatReal | |
12247 | PROCEDURE FormatReal (str: ARRAY OF CHAR): ConvResults; | |
12248 | (* Returns the format of the string value for conversion to REAL. *) | |
12249 | ||
12250 | @findex ValueReal | |
12251 | PROCEDURE ValueReal (str: ARRAY OF CHAR): REAL; | |
12252 | (* Returns the value corresponding to the real number string value | |
12253 | str if str is well-formed; otherwise raises the RealConv | |
12254 | exception. | |
12255 | *) | |
12256 | ||
12257 | @findex LengthFloatReal | |
12258 | PROCEDURE LengthFloatReal (real: REAL; sigFigs: CARDINAL): CARDINAL; | |
12259 | (* Returns the number of characters in the floating-point string | |
12260 | representation of real with sigFigs significant figures. | |
12261 | *) | |
12262 | ||
12263 | @findex LengthEngReal | |
12264 | PROCEDURE LengthEngReal (real: REAL; sigFigs: CARDINAL): CARDINAL; | |
12265 | (* Returns the number of characters in the floating-point engineering | |
12266 | string representation of real with sigFigs significant figures. | |
12267 | *) | |
12268 | ||
12269 | @findex LengthFixedReal | |
12270 | PROCEDURE LengthFixedReal (real: REAL; place: INTEGER): CARDINAL; | |
12271 | (* Returns the number of characters in the fixed-point string | |
12272 | representation of real rounded to the given place relative to the | |
12273 | decimal point. | |
12274 | *) | |
12275 | ||
12276 | @findex IsRConvException | |
12277 | PROCEDURE IsRConvException (): BOOLEAN; | |
12278 | (* Returns TRUE if the current coroutine is in the exceptional | |
12279 | execution state because of the raising of an exception in a | |
12280 | routine from this module; otherwise returns FALSE. | |
12281 | *) | |
12282 | ||
12283 | END RealConv. | |
12284 | @end example | |
12285 | @page | |
12286 | ||
12287 | @node gm2-libs-iso/RealIO, gm2-libs-iso/RealMath, gm2-libs-iso/RealConv, M2 ISO Libraries | |
12288 | @subsection gm2-libs-iso/RealIO | |
12289 | ||
12290 | @example | |
12291 | DEFINITION MODULE RealIO; | |
12292 | ||
12293 | (* Input and output of real numbers in decimal text form | |
12294 | over specified channels. The read result is of the | |
12295 | type IOConsts.ReadResults. | |
12296 | *) | |
12297 | ||
12298 | IMPORT IOChan; | |
12299 | ||
12300 | (* The text form of a signed fixed-point real number is | |
12301 | ["+" | "-"], decimal digit, @{decimal digit@}, | |
12302 | [".", @{decimal digit@}] | |
12303 | ||
12304 | The text form of a signed floating-point real number is | |
12305 | signed fixed-point real number, | |
12306 | "E", ["+" | "-"], decimal digit, @{decimal digit@} | |
12307 | *) | |
12308 | ||
12309 | @findex ReadReal | |
12310 | PROCEDURE ReadReal (cid: IOChan.ChanId; VAR real: REAL); | |
12311 | (* Skips leading spaces, and removes any remaining characters | |
12312 | from cid that form part of a signed fixed or floating | |
12313 | point number. The value of this number is assigned to real. | |
12314 | The read result is set to the value allRight, outOfRange, | |
12315 | wrongFormat, endOfLine, or endOfInput. | |
12316 | *) | |
12317 | ||
12318 | @findex WriteFloat | |
12319 | PROCEDURE WriteFloat (cid: IOChan.ChanId; real: REAL; | |
12320 | sigFigs: CARDINAL; width: CARDINAL); | |
12321 | (* Writes the value of real to cid in floating-point text form, | |
12322 | with sigFigs significant figures, in a field of the given | |
12323 | minimum width. | |
12324 | *) | |
12325 | ||
12326 | @findex WriteEng | |
12327 | PROCEDURE WriteEng (cid: IOChan.ChanId; real: REAL; | |
12328 | sigFigs: CARDINAL; width: CARDINAL); | |
12329 | (* As for WriteFloat, except that the number is scaled with | |
12330 | one to three digits in the whole number part, and with an | |
12331 | exponent that is a multiple of three. | |
12332 | *) | |
12333 | ||
12334 | @findex WriteFixed | |
12335 | PROCEDURE WriteFixed (cid: IOChan.ChanId; real: REAL; | |
12336 | place: INTEGER; width: CARDINAL); | |
12337 | (* Writes the value of real to cid in fixed-point text form, | |
12338 | rounded to the given place relative to the decimal point, | |
12339 | in a field of the given minimum width. | |
12340 | *) | |
12341 | ||
12342 | @findex WriteReal | |
12343 | PROCEDURE WriteReal (cid: IOChan.ChanId; | |
12344 | real: REAL; width: CARDINAL); | |
12345 | (* Writes the value of real to cid, as WriteFixed if the sign | |
12346 | and magnitude can be shown in the given width, or otherwise | |
12347 | as WriteFloat. The number of places or significant digits | |
12348 | depends on the given width. | |
12349 | *) | |
12350 | ||
12351 | END RealIO. | |
12352 | @end example | |
12353 | @page | |
12354 | ||
12355 | @node gm2-libs-iso/RealMath, gm2-libs-iso/RealStr, gm2-libs-iso/RealIO, M2 ISO Libraries | |
12356 | @subsection gm2-libs-iso/RealMath | |
12357 | ||
12358 | @example | |
12359 | DEFINITION MODULE RealMath; | |
12360 | ||
12361 | (* Mathematical functions for the type REAL *) | |
12362 | ||
12363 | CONST | |
12364 | @findex pi (const) | |
12365 | pi = 3.1415926535897932384626433832795028841972; | |
12366 | @findex exp1 (const) | |
12367 | exp1 = 2.7182818284590452353602874713526624977572; | |
12368 | ||
12369 | @findex sqrt | |
12370 | PROCEDURE __BUILTIN__ sqrt (x: REAL): REAL; | |
12371 | (* Returns the positive square root of x *) | |
12372 | ||
12373 | @findex exp | |
12374 | PROCEDURE __BUILTIN__ exp (x: REAL): REAL; | |
12375 | (* Returns the exponential of x *) | |
12376 | ||
12377 | @findex ln | |
12378 | PROCEDURE __BUILTIN__ ln (x: REAL): REAL; | |
12379 | (* Returns the natural logarithm of x *) | |
12380 | ||
12381 | (* The angle in all trigonometric functions is measured in radians *) | |
12382 | ||
12383 | @findex sin | |
12384 | PROCEDURE __BUILTIN__ sin (x: REAL): REAL; | |
12385 | (* Returns the sine of x *) | |
12386 | ||
12387 | @findex cos | |
12388 | PROCEDURE __BUILTIN__ cos (x: REAL): REAL; | |
12389 | (* Returns the cosine of x *) | |
12390 | ||
12391 | @findex tan | |
12392 | PROCEDURE tan (x: REAL): REAL; | |
12393 | (* Returns the tangent of x *) | |
12394 | ||
12395 | @findex arcsin | |
12396 | PROCEDURE arcsin (x: REAL): REAL; | |
12397 | (* Returns the arcsine of x *) | |
12398 | ||
12399 | @findex arccos | |
12400 | PROCEDURE arccos (x: REAL): REAL; | |
12401 | (* Returns the arccosine of x *) | |
12402 | ||
12403 | @findex arctan | |
12404 | PROCEDURE arctan (x: REAL): REAL; | |
12405 | (* Returns the arctangent of x *) | |
12406 | ||
12407 | @findex power | |
12408 | PROCEDURE power (base, exponent: REAL) : REAL; | |
12409 | (* Returns the value of the number base raised to the power exponent *) | |
12410 | ||
12411 | @findex round | |
12412 | PROCEDURE round (x: REAL) : INTEGER; | |
12413 | (* Returns the value of x rounded to the nearest integer *) | |
12414 | ||
12415 | @findex IsRMathException | |
12416 | PROCEDURE IsRMathException () : BOOLEAN; | |
12417 | (* Returns TRUE if the current coroutine is in the exceptional execution state | |
12418 | because of the raising of an exception in a routine from this module; otherwise | |
12419 | returns FALSE. | |
12420 | *) | |
12421 | ||
12422 | END RealMath. | |
12423 | ||
12424 | @end example | |
12425 | @page | |
12426 | ||
12427 | @node gm2-libs-iso/RealStr, gm2-libs-iso/RndFile, gm2-libs-iso/RealMath, M2 ISO Libraries | |
12428 | @subsection gm2-libs-iso/RealStr | |
12429 | ||
12430 | @example | |
12431 | DEFINITION MODULE RealStr; | |
12432 | ||
12433 | (* REAL/string conversions *) | |
12434 | ||
12435 | IMPORT | |
12436 | ConvTypes; | |
12437 | ||
12438 | TYPE | |
12439 | (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) | |
12440 | @findex ConvResults (type) | |
12441 | ConvResults = ConvTypes.ConvResults; | |
12442 | ||
12443 | (* the string form of a signed fixed-point real number is | |
12444 | ["+" | "-"], decimal digit, @{decimal digit@}, [".", | |
12445 | @{decimal digit@}] | |
12446 | *) | |
12447 | ||
12448 | (* the string form of a signed floating-point real number is | |
12449 | signed fixed-point real number, "E", ["+" | "-"], | |
12450 | decimal digit, @{decimal digit@} | |
12451 | *) | |
12452 | ||
12453 | @findex StrToReal | |
12454 | PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: REAL; | |
12455 | VAR res: ConvResults); | |
12456 | (* Ignores any leading spaces in str. If the subsequent characters | |
12457 | in str are in the format of a signed real number, assigns a | |
12458 | corresponding value to real. Assigns a value indicating the | |
12459 | format of str to res. | |
12460 | *) | |
12461 | ||
12462 | @findex RealToFloat | |
12463 | PROCEDURE RealToFloat (real: REAL; sigFigs: CARDINAL; | |
12464 | VAR str: ARRAY OF CHAR); | |
12465 | (* Converts the value of real to floating-point string form, with | |
12466 | sigFigs significant figures, and copies the possibly truncated | |
12467 | result to str. | |
12468 | *) | |
12469 | ||
12470 | @findex RealToEng | |
12471 | PROCEDURE RealToEng (real: REAL; sigFigs: CARDINAL; | |
12472 | VAR str: ARRAY OF CHAR); | |
12473 | (* Converts the value of real to floating-point string form, with | |
12474 | sigFigs significant figures, and copies the possibly truncated | |
12475 | result to str. The number is scaled with one to three digits | |
12476 | in the whole number part and with an exponent that is a multiple | |
12477 | of three. | |
12478 | *) | |
12479 | ||
12480 | @findex RealToFixed | |
12481 | PROCEDURE RealToFixed (real: REAL; place: INTEGER; | |
12482 | VAR str: ARRAY OF CHAR); | |
12483 | (* Converts the value of real to fixed-point string form, rounded | |
12484 | to the given place relative to the decimal point, and copies | |
12485 | the possibly truncated result to str. | |
12486 | *) | |
12487 | ||
12488 | @findex RealToStr | |
12489 | PROCEDURE RealToStr (real: REAL; VAR str: ARRAY OF CHAR); | |
12490 | (* Converts the value of real as RealToFixed if the sign and | |
12491 | magnitude can be shown within the capacity of str, or | |
12492 | otherwise as RealToFloat, and copies the possibly truncated | |
12493 | result to str. The number of places or significant digits are | |
12494 | implementation-defined. | |
12495 | *) | |
12496 | ||
12497 | END RealStr. | |
12498 | ||
12499 | @end example | |
12500 | @page | |
12501 | ||
12502 | @node gm2-libs-iso/RndFile, gm2-libs-iso/SIOResult, gm2-libs-iso/RealStr, M2 ISO Libraries | |
12503 | @subsection gm2-libs-iso/RndFile | |
12504 | ||
12505 | @example | |
12506 | DEFINITION MODULE RndFile; | |
12507 | ||
12508 | (* Random access files *) | |
12509 | ||
12510 | IMPORT IOChan, ChanConsts, SYSTEM; | |
12511 | ||
12512 | TYPE | |
12513 | @findex ChanId (type) | |
12514 | ChanId = IOChan.ChanId; | |
12515 | @findex FlagSet (type) | |
12516 | FlagSet = ChanConsts.FlagSet; | |
12517 | @findex OpenResults (type) | |
12518 | OpenResults = ChanConsts.OpenResults; | |
12519 | ||
12520 | (* Accepted singleton values of FlagSet *) | |
12521 | ||
12522 | CONST | |
12523 | (* input operations are requested/available *) | |
12524 | @findex read (const) | |
12525 | read = FlagSet@{ChanConsts.readFlag@}; | |
12526 | (* output operations are requested/available *) | |
12527 | @findex write (const) | |
12528 | write = FlagSet@{ChanConsts.writeFlag@}; | |
12529 | (* a file may/must/did exist before the channel is opened *) | |
12530 | @findex old (const) | |
12531 | old = FlagSet@{ChanConsts.oldFlag@}; | |
12532 | (* text operations are requested/available *) | |
12533 | @findex text (const) | |
12534 | text = FlagSet@{ChanConsts.textFlag@}; | |
12535 | (* raw operations are requested/available *) | |
12536 | @findex raw (const) | |
12537 | raw = FlagSet@{ChanConsts.rawFlag@}; | |
12538 | ||
12539 | @findex OpenOld | |
12540 | PROCEDURE OpenOld (VAR cid: ChanId; name: ARRAY OF CHAR; flags: FlagSet; | |
12541 | VAR res: OpenResults); | |
12542 | (* Attempts to obtain and open a channel connected to a stored random | |
12543 | access file of the given name. | |
12544 | The old flag is implied; without the write flag, read is implied; | |
12545 | without the text flag, raw is implied. | |
12546 | If successful, assigns to cid the identity of the opened channel, | |
12547 | assigns the value opened to res, and sets the read/write position | |
12548 | to the start of the file. | |
12549 | If a channel cannot be opened as required, the value of res indicates | |
12550 | the reason, and cid identifies the invalid channel. | |
12551 | *) | |
12552 | ||
12553 | @findex OpenClean | |
12554 | PROCEDURE OpenClean (VAR cid: ChanId; name: ARRAY OF CHAR; flags: FlagSet; | |
12555 | VAR res: OpenResults); | |
12556 | (* Attempts to obtain and open a channel connected to a stored random | |
12557 | access file of the given name. | |
12558 | The write flag is implied; without the text flag, raw is implied. | |
12559 | If successful, assigns to cid the identity of the opened channel, | |
12560 | assigns the value opened to res, and truncates the file to zero length. | |
12561 | If a channel cannot be opened as required, the value of res indicates | |
12562 | the reason, and cid identifies the invalid channel. | |
12563 | *) | |
12564 | ||
12565 | @findex IsRndFile | |
12566 | PROCEDURE IsRndFile (cid: ChanId): BOOLEAN; | |
12567 | (* Tests if the channel identified by cid is open to a random access file. *) | |
12568 | ||
12569 | @findex IsRndFileException | |
12570 | PROCEDURE IsRndFileException (): BOOLEAN; | |
12571 | (* Returns TRUE if the current coroutine is in the exceptional execution | |
12572 | state because of the raising of a RndFile exception; otherwise returns | |
12573 | FALSE. | |
12574 | *) | |
12575 | ||
12576 | CONST | |
12577 | @findex FilePosSize (const) | |
12578 | FilePosSize = SIZE(LONGINT) ; | |
12579 | (* <implementation-defined whole number greater than zero>; *) | |
12580 | ||
12581 | TYPE | |
12582 | @findex FilePos (type) | |
12583 | FilePos = LONGINT ; (* ARRAY [1 .. FilePosSize] OF SYSTEM.LOC; *) | |
12584 | ||
12585 | @findex StartPos | |
12586 | PROCEDURE StartPos (cid: ChanId): FilePos; | |
12587 | (* If the channel identified by cid is not open to a random access file, | |
12588 | the exception wrongDevice is raised; otherwise returns the position of | |
12589 | the start of the file. | |
12590 | *) | |
12591 | ||
12592 | @findex CurrentPos | |
12593 | PROCEDURE CurrentPos (cid: ChanId): FilePos; | |
12594 | (* If the channel identified by cid is not open to a random access file, | |
12595 | the exception wrongDevice is raised; otherwise returns the position | |
12596 | of the current read/write position. | |
12597 | *) | |
12598 | ||
12599 | @findex EndPos | |
12600 | PROCEDURE EndPos (cid: ChanId): FilePos; | |
12601 | (* If the channel identified by cid is not open to a random access file, | |
12602 | the exception wrongDevice is raised; otherwise returns the first | |
12603 | position after which there have been no writes. | |
12604 | *) | |
12605 | ||
12606 | @findex NewPos | |
12607 | PROCEDURE NewPos (cid: ChanId; chunks: INTEGER; chunkSize: CARDINAL; | |
12608 | from: FilePos): FilePos; | |
12609 | (* If the channel identified by cid is not open to a random access file, | |
12610 | the exception wrongDevice is raised; otherwise returns the position | |
12611 | (chunks * chunkSize) relative to the position given by from, or | |
12612 | raises the exception posRange if the required position cannot be | |
12613 | represented as a value of type FilePos. | |
12614 | *) | |
12615 | ||
12616 | @findex SetPos | |
12617 | PROCEDURE SetPos (cid: ChanId; pos: FilePos); | |
12618 | (* If the channel identified by cid is not open to a random access file, | |
12619 | the exception wrongDevice is raised; otherwise sets the read/write | |
12620 | position to the value given by pos. | |
12621 | *) | |
12622 | ||
12623 | @findex Close | |
12624 | PROCEDURE Close (VAR cid: ChanId); | |
12625 | (* If the channel identified by cid is not open to a random access file, | |
12626 | the exception wrongDevice is raised; otherwise closes the channel, | |
12627 | and assigns the value identifying the invalid channel to cid. | |
12628 | *) | |
12629 | ||
12630 | END RndFile. | |
12631 | @end example | |
12632 | @page | |
12633 | ||
12634 | @node gm2-libs-iso/SIOResult, gm2-libs-iso/SLongIO, gm2-libs-iso/RndFile, M2 ISO Libraries | |
12635 | @subsection gm2-libs-iso/SIOResult | |
12636 | ||
12637 | @example | |
12638 | DEFINITION MODULE SIOResult; | |
12639 | ||
12640 | (* Read results for the default input channel *) | |
12641 | ||
12642 | IMPORT IOConsts; | |
12643 | ||
12644 | TYPE | |
12645 | @findex ReadResults (type) | |
12646 | ReadResults = IOConsts.ReadResults; | |
12647 | ||
12648 | (* | |
12649 | @findex ReadResults (type) | |
12650 | ReadResults = (* This type is used to classify the result of an input operation *) | |
12651 | ( | |
12652 | notKnown, (* no read result is set *) | |
12653 | allRight, (* data is as expected or as required *) | |
12654 | outOfRange, (* data cannot be represented *) | |
12655 | wrongFormat, (* data not in expected format *) | |
12656 | endOfLine, (* end of line seen before expected data *) | |
12657 | endOfInput (* end of input seen before expected data *) | |
12658 | ); | |
12659 | *) | |
12660 | ||
12661 | @findex ReadResult | |
12662 | PROCEDURE ReadResult (): ReadResults; | |
12663 | (* Returns the result for the last read operation on the default input channel. *) | |
12664 | ||
12665 | END SIOResult. | |
12666 | ||
12667 | @end example | |
12668 | @page | |
12669 | ||
12670 | @node gm2-libs-iso/SLongIO, gm2-libs-iso/SLongWholeIO, gm2-libs-iso/SIOResult, M2 ISO Libraries | |
12671 | @subsection gm2-libs-iso/SLongIO | |
12672 | ||
12673 | @example | |
12674 | DEFINITION MODULE SLongIO; | |
12675 | ||
12676 | (* Input and output of long real numbers in decimal text form | |
12677 | using default channels. The read result is of the type | |
12678 | IOConsts.ReadResults. | |
12679 | *) | |
12680 | ||
12681 | (* The text form of a signed fixed-point real number is | |
12682 | ["+" | "-"], decimal digit, @{decimal digit@}, | |
12683 | [".", @{decimal digit@}] | |
12684 | ||
12685 | The text form of a signed floating-point real number is | |
12686 | signed fixed-point real number, | |
12687 | "E", ["+" | "-"], decimal digit, @{decimal digit@} | |
12688 | *) | |
12689 | ||
12690 | @findex ReadReal | |
12691 | PROCEDURE ReadReal (VAR real: LONGREAL); | |
12692 | (* Skips leading spaces, and removes any remaining characters | |
12693 | from the default input channel that form part of a signed | |
12694 | fixed or floating point number. The value of this number | |
12695 | is assigned to real. The read result is set to the value | |
12696 | allRight, outOfRange, wrongFormat, endOfLine, or endOfInput. | |
12697 | *) | |
12698 | ||
12699 | @findex WriteFloat | |
12700 | PROCEDURE WriteFloat (real: LONGREAL; sigFigs: CARDINAL; | |
12701 | width: CARDINAL); | |
12702 | (* Writes the value of real to the default output channel in | |
12703 | floating-point text form, with sigFigs significant figures, | |
12704 | in a field of the given minimum width. | |
12705 | *) | |
12706 | ||
12707 | @findex WriteEng | |
12708 | PROCEDURE WriteEng (real: LONGREAL; sigFigs: CARDINAL; | |
12709 | width: CARDINAL); | |
12710 | (* As for WriteFloat, except that the number is scaled with | |
12711 | one to three digits in the whole number part, and with an | |
12712 | exponent that is a multiple of three. | |
12713 | *) | |
12714 | ||
12715 | @findex WriteFixed | |
12716 | PROCEDURE WriteFixed (real: LONGREAL; place: INTEGER; | |
12717 | width: CARDINAL); | |
12718 | (* Writes the value of real to the default output channel in | |
12719 | fixed-point text form, rounded to the given place relative | |
12720 | to the decimal point, in a field of the given minimum width. | |
12721 | *) | |
12722 | ||
12723 | @findex WriteReal | |
12724 | PROCEDURE WriteReal (real: LONGREAL; width: CARDINAL); | |
12725 | (* Writes the value of real to the default output channel, as | |
12726 | WriteFixed if the sign and magnitude can be shown in the | |
12727 | given width, or otherwise as WriteFloat. The number of | |
12728 | places or significant digits depends on the given width. | |
12729 | *) | |
12730 | ||
12731 | END SLongIO. | |
12732 | ||
12733 | @end example | |
12734 | @page | |
12735 | ||
12736 | @node gm2-libs-iso/SLongWholeIO, gm2-libs-iso/SRawIO, gm2-libs-iso/SLongIO, M2 ISO Libraries | |
12737 | @subsection gm2-libs-iso/SLongWholeIO | |
12738 | ||
12739 | @example | |
12740 | DEFINITION MODULE SLongWholeIO; | |
12741 | ||
12742 | (* Input and output of whole numbers in decimal text form over | |
12743 | default channels. The read result is of the type | |
12744 | IOConsts.ReadResults. | |
12745 | *) | |
12746 | ||
12747 | (* The text form of a signed whole number is | |
12748 | ["+" | "-"], decimal digit, @{decimal digit@} | |
12749 | ||
12750 | The text form of an unsigned whole number is | |
12751 | decimal digit, @{decimal digit@} | |
12752 | *) | |
12753 | ||
12754 | @findex ReadInt | |
12755 | PROCEDURE ReadInt (VAR int: LONGINT); | |
12756 | (* Skips leading spaces, and removes any remaining characters | |
12757 | from the default input channel that form part of a signed | |
12758 | whole number. The value of this number is assigned | |
12759 | to int. The read result is set to the value allRight, | |
12760 | outOfRange, wrongFormat, endOfLine, or endOfInput. | |
12761 | *) | |
12762 | ||
12763 | @findex WriteInt | |
12764 | PROCEDURE WriteInt (int: LONGINT; width: CARDINAL); | |
12765 | (* Writes the value of int to the default output channel in | |
12766 | text form, in a field of the given minimum width. | |
12767 | *) | |
12768 | ||
12769 | @findex ReadCard | |
12770 | PROCEDURE ReadCard (VAR card: LONGCARD); | |
12771 | (* Skips leading spaces, and removes any remaining characters | |
12772 | from the default input channel that form part of an | |
12773 | unsigned whole number. The value of this number is | |
12774 | assigned to card. The read result is set to the value | |
12775 | allRight, outOfRange, wrongFormat, endOfLine, or endOfInput. | |
12776 | *) | |
12777 | ||
12778 | @findex WriteCard | |
12779 | PROCEDURE WriteCard (card: LONGCARD; width: CARDINAL); | |
12780 | (* Writes the value of card to the default output channel in | |
12781 | text form, in a field of the given minimum width. | |
12782 | *) | |
12783 | ||
12784 | END SLongWholeIO. | |
12785 | @end example | |
12786 | @page | |
12787 | ||
12788 | @node gm2-libs-iso/SRawIO, gm2-libs-iso/SRealIO, gm2-libs-iso/SLongWholeIO, M2 ISO Libraries | |
12789 | @subsection gm2-libs-iso/SRawIO | |
12790 | ||
12791 | @example | |
12792 | DEFINITION MODULE SRawIO; | |
12793 | ||
12794 | (* Reading and writing data over default channels using raw operations, that is, with no | |
12795 | conversion or interpretation. The read result is of the type IOConsts.ReadResults. | |
12796 | *) | |
12797 | ||
12798 | IMPORT SYSTEM; | |
12799 | ||
12800 | @findex Read | |
12801 | PROCEDURE Read (VAR to: ARRAY OF SYSTEM.LOC); | |
12802 | (* Reads storage units from the default input channel, and assigns them to successive | |
12803 | components of to. The read result is set to the value allRight, wrongFormat, or | |
12804 | endOfInput. | |
12805 | *) | |
12806 | ||
12807 | @findex Write | |
12808 | PROCEDURE Write (from: ARRAY OF SYSTEM.LOC); | |
12809 | (* Writes storage units to the default output channel from successive components of from. | |
12810 | *) | |
12811 | ||
12812 | END SRawIO. | |
12813 | ||
12814 | @end example | |
12815 | @page | |
12816 | ||
12817 | @node gm2-libs-iso/SRealIO, gm2-libs-iso/SShortIO, gm2-libs-iso/SRawIO, M2 ISO Libraries | |
12818 | @subsection gm2-libs-iso/SRealIO | |
12819 | ||
12820 | @example | |
12821 | DEFINITION MODULE SRealIO; | |
12822 | ||
12823 | (* Input and output of real numbers in decimal text form over | |
12824 | default channels. The read result is of the type | |
12825 | IOConsts.ReadResults. | |
12826 | *) | |
12827 | ||
12828 | (* The text form of a signed fixed-point real number is | |
12829 | ["+" | "-"], decimal digit, @{decimal digit@}, | |
12830 | [".", @{decimal digit@}] | |
12831 | ||
12832 | The text form of a signed floating-point real number is | |
12833 | signed fixed-point real number, | |
12834 | "E", ["+" | "-"], decimal digit, @{decimal digit@} | |
12835 | *) | |
12836 | ||
12837 | @findex ReadReal | |
12838 | PROCEDURE ReadReal (VAR real: REAL); | |
12839 | (* Skips leading spaces, and removes any remaining characters | |
12840 | from the default input channel that form part of a signed | |
12841 | fixed or floating point number. The value of this number | |
12842 | is assigned to real. The read result is set to the value | |
12843 | allRight, outOfRange, wrongFormat, endOfLine, or endOfInput. | |
12844 | *) | |
12845 | ||
12846 | @findex WriteFloat | |
12847 | PROCEDURE WriteFloat (real: REAL; sigFigs: CARDINAL; width: CARDINAL); | |
12848 | (* Writes the value of real to the default output channel in | |
12849 | floating-point text form, with sigFigs significant figures, | |
12850 | in a field of the given minimum width. | |
12851 | *) | |
12852 | ||
12853 | @findex WriteEng | |
12854 | PROCEDURE WriteEng (real: REAL; sigFigs: CARDINAL; width: CARDINAL); | |
12855 | (* As for WriteFloat, except that the number is scaled with one to | |
12856 | three digits in the whole number part, and with an exponent that | |
12857 | is a multiple of three. | |
12858 | *) | |
12859 | ||
12860 | @findex WriteFixed | |
12861 | PROCEDURE WriteFixed (real: REAL; place: INTEGER; width: CARDINAL); | |
12862 | (* Writes the value of real to the default output channel in | |
12863 | fixed-point text form, rounded to the given place relative | |
12864 | to the decimal point, in a field of the given minimum width. | |
12865 | *) | |
12866 | ||
12867 | @findex WriteReal | |
12868 | PROCEDURE WriteReal (real: REAL; width: CARDINAL); | |
12869 | (* Writes the value of real to the default output channel, as | |
12870 | WriteFixed if the sign and magnitude can be shown in the | |
12871 | given width, or otherwise as WriteFloat. The number of | |
12872 | places or significant digits depends on the given width. | |
12873 | *) | |
12874 | ||
12875 | END SRealIO. | |
12876 | ||
12877 | @end example | |
12878 | @page | |
12879 | ||
12880 | @node gm2-libs-iso/SShortIO, gm2-libs-iso/SShortWholeIO, gm2-libs-iso/SRealIO, M2 ISO Libraries | |
12881 | @subsection gm2-libs-iso/SShortIO | |
12882 | ||
12883 | @example | |
12884 | DEFINITION MODULE SShortIO; | |
12885 | ||
12886 | (* Input and output of short real numbers in decimal text form | |
12887 | using default channels. The read result is of the type | |
12888 | IOConsts.ReadResults. | |
12889 | *) | |
12890 | ||
12891 | (* The text form of a signed fixed-point real number is | |
12892 | ["+" | "-"], decimal digit, @{decimal digit@}, | |
12893 | [".", @{decimal digit@}] | |
12894 | ||
12895 | The text form of a signed floating-point real number is | |
12896 | signed fixed-point real number, | |
12897 | "E", ["+" | "-"], decimal digit, @{decimal digit@} | |
12898 | *) | |
12899 | ||
12900 | @findex ReadReal | |
12901 | PROCEDURE ReadReal (VAR real: SHORTREAL); | |
12902 | (* Skips leading spaces, and removes any remaining characters | |
12903 | from the default input channel that form part of a signed | |
12904 | fixed or floating point number. The value of this number | |
12905 | is assigned to real. The read result is set to the value | |
12906 | allRight, outOfRange, wrongFormat, endOfLine, or endOfInput. | |
12907 | *) | |
12908 | ||
12909 | @findex WriteFloat | |
12910 | PROCEDURE WriteFloat (real: SHORTREAL; sigFigs: CARDINAL; | |
12911 | width: CARDINAL); | |
12912 | (* Writes the value of real to the default output channel in | |
12913 | floating-point text form, with sigFigs significant figures, | |
12914 | in a field of the given minimum width. | |
12915 | *) | |
12916 | ||
12917 | @findex WriteEng | |
12918 | PROCEDURE WriteEng (real: SHORTREAL; sigFigs: CARDINAL; | |
12919 | width: CARDINAL); | |
12920 | (* As for WriteFloat, except that the number is scaled with | |
12921 | one to three digits in the whole number part, and with an | |
12922 | exponent that is a multiple of three. | |
12923 | *) | |
12924 | ||
12925 | @findex WriteFixed | |
12926 | PROCEDURE WriteFixed (real: SHORTREAL; place: INTEGER; | |
12927 | width: CARDINAL); | |
12928 | (* Writes the value of real to the default output channel in | |
12929 | fixed-point text form, rounded to the given place relative | |
12930 | to the decimal point, in a field of the given minimum width. | |
12931 | *) | |
12932 | ||
12933 | @findex WriteReal | |
12934 | PROCEDURE WriteReal (real: SHORTREAL; width: CARDINAL); | |
12935 | (* Writes the value of real to the default output channel, as | |
12936 | WriteFixed if the sign and magnitude can be shown in the | |
12937 | given width, or otherwise as WriteFloat. The number of | |
12938 | places or significant digits depends on the given width. | |
12939 | *) | |
12940 | ||
12941 | END SShortIO. | |
12942 | ||
12943 | @end example | |
12944 | @page | |
12945 | ||
12946 | @node gm2-libs-iso/SShortWholeIO, gm2-libs-iso/STextIO, gm2-libs-iso/SShortIO, M2 ISO Libraries | |
12947 | @subsection gm2-libs-iso/SShortWholeIO | |
12948 | ||
12949 | @example | |
12950 | DEFINITION MODULE SShortWholeIO; | |
12951 | ||
12952 | (* Input and output of whole numbers in decimal text form over | |
12953 | default channels. The read result is of the type | |
12954 | IOConsts.ReadResults. | |
12955 | *) | |
12956 | ||
12957 | (* The text form of a signed whole number is | |
12958 | ["+" | "-"], decimal digit, @{decimal digit@} | |
12959 | ||
12960 | The text form of an unsigned whole number is | |
12961 | decimal digit, @{decimal digit@} | |
12962 | *) | |
12963 | ||
12964 | @findex ReadInt | |
12965 | PROCEDURE ReadInt (VAR int: SHORTINT); | |
12966 | (* Skips leading spaces, and removes any remaining characters | |
12967 | from the default input channel that form part of a signed | |
12968 | whole number. The value of this number is assigned | |
12969 | to int. The read result is set to the value allRight, | |
12970 | outOfRange, wrongFormat, endOfLine, or endOfInput. | |
12971 | *) | |
12972 | ||
12973 | @findex WriteInt | |
12974 | PROCEDURE WriteInt (int: SHORTINT; width: CARDINAL); | |
12975 | (* Writes the value of int to the default output channel in | |
12976 | text form, in a field of the given minimum width. | |
12977 | *) | |
12978 | ||
12979 | @findex ReadCard | |
12980 | PROCEDURE ReadCard (VAR card: SHORTCARD); | |
12981 | (* Skips leading spaces, and removes any remaining characters | |
12982 | from the default input channel that form part of an | |
12983 | unsigned whole number. The value of this number is | |
12984 | assigned to card. The read result is set to the value | |
12985 | allRight, outOfRange, wrongFormat, endOfLine, or endOfInput. | |
12986 | *) | |
12987 | ||
12988 | @findex WriteCard | |
12989 | PROCEDURE WriteCard (card: SHORTCARD; width: CARDINAL); | |
12990 | (* Writes the value of card to the default output channel in | |
12991 | text form, in a field of the given minimum width. | |
12992 | *) | |
12993 | ||
12994 | END SShortWholeIO. | |
12995 | @end example | |
12996 | @page | |
12997 | ||
12998 | @node gm2-libs-iso/STextIO, gm2-libs-iso/SWholeIO, gm2-libs-iso/SShortWholeIO, M2 ISO Libraries | |
12999 | @subsection gm2-libs-iso/STextIO | |
13000 | ||
13001 | @example | |
13002 | DEFINITION MODULE STextIO; | |
13003 | ||
13004 | (* Input and output of character and string types over default channels. The read result | |
13005 | is of the type IOConsts.ReadResults. | |
13006 | *) | |
13007 | ||
13008 | (* The following procedures do not read past line marks *) | |
13009 | ||
13010 | @findex ReadChar | |
13011 | PROCEDURE ReadChar (VAR ch: CHAR); | |
13012 | (* If possible, removes a character from the default input stream, and assigns the | |
13013 | corresponding value to ch. The read result is set to allRight, endOfLine or | |
13014 | endOfInput. | |
13015 | *) | |
13016 | ||
13017 | @findex ReadRestLine | |
13018 | PROCEDURE ReadRestLine (VAR s: ARRAY OF CHAR); | |
13019 | (* Removes any remaining characters from the default input stream before the next line | |
13020 | mark, copying to s as many as can be accommodated as a string value. The read result | |
13021 | is set to the value allRight, outOfRange, endOfLine, or endOfInput. | |
13022 | *) | |
13023 | ||
13024 | @findex ReadString | |
13025 | PROCEDURE ReadString (VAR s: ARRAY OF CHAR); | |
13026 | (* Removes only those characters from the default input stream before the next line mark | |
13027 | that can be accommodated in s as a string value, and copies them to s. The read result | |
13028 | is set to the value allRight, endOfLine, or endOfInput. | |
13029 | *) | |
13030 | ||
13031 | @findex ReadToken | |
13032 | PROCEDURE ReadToken (VAR s: ARRAY OF CHAR); | |
13033 | (* Skips leading spaces, and then removes characters from the default input stream before | |
13034 | the next space or line mark, copying to s as many as can be accommodated as a string | |
13035 | value. The read result is set to the value allRight, outOfRange, endOfLine, or | |
13036 | endOfInput. | |
13037 | *) | |
13038 | ||
13039 | (* The following procedure reads past the next line mark *) | |
13040 | ||
13041 | @findex SkipLine | |
13042 | PROCEDURE SkipLine; | |
13043 | (* Removes successive items from the default input stream up to and including the next | |
13044 | line mark or until the end of input is reached. The read result is set to the value | |
13045 | allRight, or endOfInput. | |
13046 | *) | |
13047 | ||
13048 | ||
13049 | (* Output procedures *) | |
13050 | ||
13051 | @findex WriteChar | |
13052 | PROCEDURE WriteChar (ch: CHAR); | |
13053 | (* Writes the value of ch to the default output stream. *) | |
13054 | ||
13055 | @findex WriteLn | |
13056 | PROCEDURE WriteLn; | |
13057 | (* Writes a line mark to the default output stream. *) | |
13058 | ||
13059 | @findex WriteString | |
13060 | PROCEDURE WriteString (s: ARRAY OF CHAR); | |
13061 | (* Writes the string value of s to the default output stream. *) | |
13062 | ||
13063 | END STextIO. | |
13064 | @end example | |
13065 | @page | |
13066 | ||
13067 | @node gm2-libs-iso/SWholeIO, gm2-libs-iso/SYSTEM, gm2-libs-iso/STextIO, M2 ISO Libraries | |
13068 | @subsection gm2-libs-iso/SWholeIO | |
13069 | ||
13070 | @example | |
13071 | DEFINITION MODULE SWholeIO; | |
13072 | ||
13073 | (* Input and output of whole numbers in decimal text form over | |
13074 | default channels. The read result is of the type | |
13075 | IOConsts.ReadResults. | |
13076 | *) | |
13077 | ||
13078 | (* The text form of a signed whole number is | |
13079 | ["+" | "-"], decimal digit, @{decimal digit@} | |
13080 | ||
13081 | The text form of an unsigned whole number is | |
13082 | decimal digit, @{decimal digit@} | |
13083 | *) | |
13084 | ||
13085 | @findex ReadInt | |
13086 | PROCEDURE ReadInt (VAR int: INTEGER); | |
13087 | (* Skips leading spaces, and removes any remaining characters | |
13088 | from the default input channel that form part of a signed | |
13089 | whole number. The value of this number is assigned | |
13090 | to int. The read result is set to the value allRight, | |
13091 | outOfRange, wrongFormat, endOfLine, or endOfInput. | |
13092 | *) | |
13093 | ||
13094 | @findex WriteInt | |
13095 | PROCEDURE WriteInt (int: INTEGER; width: CARDINAL); | |
13096 | (* Writes the value of int to the default output channel in | |
13097 | text form, in a field of the given minimum width. | |
13098 | *) | |
13099 | ||
13100 | @findex ReadCard | |
13101 | PROCEDURE ReadCard (VAR card: CARDINAL); | |
13102 | (* Skips leading spaces, and removes any remaining characters | |
13103 | from the default input channel that form part of an | |
13104 | unsigned whole number. The value of this number is | |
13105 | assigned to card. The read result is set to the value | |
13106 | allRight, outOfRange, wrongFormat, endOfLine, or endOfInput. | |
13107 | *) | |
13108 | ||
13109 | @findex WriteCard | |
13110 | PROCEDURE WriteCard (card: CARDINAL; width: CARDINAL); | |
13111 | (* Writes the value of card to the default output channel in | |
13112 | text form, in a field of the given minimum width. | |
13113 | *) | |
13114 | ||
13115 | END SWholeIO. | |
13116 | @end example | |
13117 | @page | |
13118 | ||
13119 | @node gm2-libs-iso/SYSTEM, gm2-libs-iso/Semaphores, gm2-libs-iso/SWholeIO, M2 ISO Libraries | |
13120 | @subsection gm2-libs-iso/SYSTEM | |
13121 | ||
13122 | @example | |
13123 | DEFINITION MODULE SYSTEM; | |
13124 | ||
13125 | (* Gives access to system programming facilities that are probably | |
13126 | non portable. *) | |
13127 | ||
13128 | (* The constants and types define underlying properties of storage *) | |
13129 | ||
13130 | EXPORT QUALIFIED BITSPERLOC, LOCSPERWORD, | |
13131 | LOC, BYTE, WORD, ADDRESS, CSIZE_T, CSSIZE_T, (* | |
13132 | Target specific data types. *) | |
13133 | ADDADR, SUBADR, DIFADR, MAKEADR, ADR, ROTATE, | |
13134 | SHIFT, CAST, TSIZE, | |
13135 | ||
13136 | (* Internal GM2 compiler functions *) | |
13137 | ShiftVal, ShiftLeft, ShiftRight, | |
13138 | RotateVal, RotateLeft, RotateRight, | |
13139 | THROW, TBITSIZE ; | |
13140 | ||
13141 | CONST | |
13142 | (* <implementation-defined constant> ; *) | |
13143 | @findex BITSPERLOC (const) | |
13144 | BITSPERLOC = __ATTRIBUTE__ __BUILTIN__ ((BITS_PER_UNIT)) ; | |
13145 | (* <implementation-defined constant> ; *) | |
13146 | @findex LOCSPERWORD (const) | |
13147 | LOCSPERWORD = __ATTRIBUTE__ __BUILTIN__ ((UNITS_PER_WORD)) ; | |
13148 | (* <implementation-defined constant> ; *) | |
13149 | @findex LOCSPERBYTE (const) | |
13150 | LOCSPERBYTE = 8 DIV BITSPERLOC ; | |
13151 | ||
13152 | (* Note that the full list of system and sized datatypes include: | |
13153 | LOC, WORD, BYTE, ADDRESS, | |
13154 | ||
13155 | (and the non language standard target types) | |
13156 | ||
13157 | INTEGER8, INTEGER16, INTEGER32, INTEGER64, | |
13158 | CARDINAL8, CARDINAL16, CARDINAL32, CARDINAL64, | |
13159 | WORD16, WORD32, WORD64, BITSET8, BITSET16, | |
13160 | BITSET32, REAL32, REAL64, REAL128, COMPLEX32, | |
13161 | COMPLEX64, COMPLEX128, CSIZE_T, CSSIZE_T. | |
13162 | ||
13163 | Also note that the non-standard data types will | |
13164 | move into another module in the future. *) | |
13165 | ||
13166 | (* | |
13167 | All the data types and procedures below are declared internally. | |
13168 | =============================================================== | |
13169 | ||
13170 | TYPE | |
13171 | (* Target specific data types. *) | |
13172 | ||
13173 | TYPE | |
13174 | LOC; (* A system basic type. Values are the uninterpreted | |
13175 | contents of the smallest addressable unit of storage *) | |
13176 | @findex ADDRESS (type) | |
13177 | ADDRESS = POINTER TO LOC; | |
13178 | @findex WORD (type) | |
13179 | WORD = ARRAY [0 .. LOCSPERWORD-1] OF LOC; | |
13180 | ||
13181 | (* BYTE and LOCSPERBYTE are provided if appropriate for machine *) | |
13182 | ||
13183 | TYPE | |
13184 | @findex BYTE (type) | |
13185 | BYTE = ARRAY [0 .. LOCSPERBYTE-1] OF LOC; | |
13186 | ||
13187 | @findex ADDADR | |
13188 | PROCEDURE ADDADR (addr: ADDRESS; offset: CARDINAL): ADDRESS; | |
13189 | (* Returns address given by (addr + offset), or may raise | |
13190 | an exception if this address is not valid. | |
13191 | *) | |
13192 | ||
13193 | @findex SUBADR | |
13194 | PROCEDURE SUBADR (addr: ADDRESS; offset: CARDINAL): ADDRESS; | |
13195 | (* Returns address given by (addr - offset), or may raise an | |
13196 | exception if this address is not valid. | |
13197 | *) | |
13198 | ||
13199 | @findex DIFADR | |
13200 | PROCEDURE DIFADR (addr1, addr2: ADDRESS): INTEGER; | |
13201 | (* Returns the difference between addresses (addr1 - addr2), | |
13202 | or may raise an exception if the arguments are invalid | |
13203 | or address space is non-contiguous. | |
13204 | *) | |
13205 | ||
13206 | @findex MAKEADR | |
13207 | PROCEDURE MAKEADR (high: <some type>; ...): ADDRESS; | |
13208 | (* Returns an address constructed from a list of values whose | |
13209 | types are implementation-defined, or may raise an | |
13210 | exception if this address is not valid. | |
13211 | ||
13212 | In GNU Modula-2, MAKEADR can take any number of arguments | |
13213 | which are mapped onto the type ADDRESS. The first parameter | |
13214 | maps onto the high address bits and subsequent parameters map | |
13215 | onto lower address bits. For example: | |
13216 | ||
13217 | a := MAKEADR(BYTE(0FEH), BYTE(0DCH), BYTE(0BAH), BYTE(098H), | |
13218 | BYTE(076H), BYTE(054H), BYTE(032H), BYTE(010H)) ; | |
13219 | ||
13220 | then the value of, a, on a 64 bit machine is: 0FEDCBA9876543210H | |
13221 | ||
13222 | The parameters do not have to be the same type, but constants | |
13223 | _must_ be typed. | |
13224 | *) | |
13225 | ||
13226 | @findex ADR | |
13227 | PROCEDURE ADR (VAR v: <anytype>): ADDRESS; | |
13228 | (* Returns the address of variable v. *) | |
13229 | ||
13230 | @findex ROTATE | |
13231 | PROCEDURE ROTATE (val: <a packedset type>; | |
13232 | num: INTEGER): <type of first parameter>; | |
13233 | (* Returns a bit sequence obtained from val by rotating up/right | |
13234 | or down/right by the absolute value of num. The direction is | |
13235 | down/right if the sign of num is negative, otherwise the direction | |
13236 | is up/left. | |
13237 | *) | |
13238 | ||
13239 | @findex SHIFT | |
13240 | PROCEDURE SHIFT (val: <a packedset type>; | |
13241 | num: INTEGER): <type of first parameter>; | |
13242 | (* Returns a bit sequence obtained from val by shifting up/left | |
13243 | or down/right by the absolute value of num, introducing | |
13244 | zeros as necessary. The direction is down/right if the sign of | |
13245 | num is negative, otherwise the direction is up/left. | |
13246 | *) | |
13247 | ||
13248 | @findex CAST | |
13249 | PROCEDURE CAST (<targettype>; val: <anytype>): <targettype>; | |
13250 | (* CAST is a type transfer function. Given the expression | |
13251 | denoted by val, it returns a value of the type <targettype>. | |
13252 | An invalid value for the target value or a | |
13253 | physical address alignment problem may raise an exception. | |
13254 | *) | |
13255 | ||
13256 | @findex TSIZE | |
13257 | PROCEDURE TSIZE (<type>; ... ): CARDINAL; | |
13258 | (* Returns the number of LOCS used to store a value of the | |
13259 | specified <type>. The extra parameters, if present, | |
13260 | are used to distinguish variants in a variant record. | |
13261 | *) | |
13262 | ||
13263 | @findex THROW | |
13264 | PROCEDURE THROW (i: INTEGER) ; | |
13265 | (* | |
13266 | THROW is a GNU extension and was not part of the PIM or ISO | |
13267 | standards. It throws an exception which will be caught by the | |
13268 | EXCEPT block (assuming it exists). This is a compiler builtin | |
13269 | function which interfaces to the GCC exception handling runtime | |
13270 | system. | |
13271 | GCC uses the term throw, hence the naming distinction between | |
13272 | the GCC builtin and the Modula-2 runtime library procedure Raise. | |
13273 | The later library procedure Raise will call SYSTEM.THROW after | |
13274 | performing various housekeeping activities. | |
13275 | *) | |
13276 | ||
13277 | @findex TBITSIZE | |
13278 | PROCEDURE TBITSIZE (<type>) : CARDINAL ; | |
13279 | (* Returns the minimum number of bits necessary to represent | |
13280 | <type>. This procedure function is only useful for determining | |
13281 | the number of bits used for any type field within a packed RECORD. | |
13282 | It is not particularly useful elsewhere since <type> might be | |
13283 | optimized for speed, for example a BOOLEAN could occupy a WORD. | |
13284 | *) | |
13285 | *) | |
13286 | ||
13287 | ||
13288 | (* The following procedures are invoked by GNU Modula-2 to | |
13289 | shift non word set types. They are not part of ISO Modula-2 | |
13290 | but are used to implement the SHIFT procedure defined above. *) | |
13291 | ||
13292 | (* | |
13293 | ShiftVal - is a runtime procedure whose job is to implement | |
13294 | the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will | |
13295 | inline a SHIFT of a single WORD sized set and will only | |
13296 | call this routine for larger sets. | |
13297 | *) | |
13298 | ||
13299 | @findex ShiftVal | |
13300 | PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET; | |
13301 | SetSizeInBits: CARDINAL; | |
13302 | ShiftCount: INTEGER) ; | |
13303 | ||
13304 | ||
13305 | (* | |
13306 | ShiftLeft - performs the shift left for a multi word set. | |
13307 | This procedure might be called by the back end of | |
13308 | GNU Modula-2 depending whether amount is known at | |
13309 | compile time. | |
13310 | *) | |
13311 | ||
13312 | @findex ShiftLeft | |
13313 | PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET; | |
13314 | SetSizeInBits: CARDINAL; | |
13315 | ShiftCount: CARDINAL) ; | |
13316 | ||
13317 | (* | |
13318 | ShiftRight - performs the shift left for a multi word set. | |
13319 | This procedure might be called by the back end of | |
13320 | GNU Modula-2 depending whether amount is known at | |
13321 | compile time. | |
13322 | *) | |
13323 | ||
13324 | @findex ShiftRight | |
13325 | PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET; | |
13326 | SetSizeInBits: CARDINAL; | |
13327 | ShiftCount: CARDINAL) ; | |
13328 | ||
13329 | ||
13330 | (* | |
13331 | RotateVal - is a runtime procedure whose job is to implement | |
13332 | the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will | |
13333 | inline a ROTATE of a single WORD (or less) | |
13334 | sized set and will only call this routine for larger | |
13335 | sets. | |
13336 | *) | |
13337 | ||
13338 | @findex RotateVal | |
13339 | PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET; | |
13340 | SetSizeInBits: CARDINAL; | |
13341 | RotateCount: INTEGER) ; | |
13342 | ||
13343 | ||
13344 | (* | |
13345 | RotateLeft - performs the rotate left for a multi word set. | |
13346 | This procedure might be called by the back end of | |
13347 | GNU Modula-2 depending whether amount is known at | |
13348 | compile time. | |
13349 | *) | |
13350 | ||
13351 | @findex RotateLeft | |
13352 | PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET; | |
13353 | SetSizeInBits: CARDINAL; | |
13354 | RotateCount: CARDINAL) ; | |
13355 | ||
13356 | ||
13357 | (* | |
13358 | RotateRight - performs the rotate right for a multi word set. | |
13359 | This procedure might be called by the back end of | |
13360 | GNU Modula-2 depending whether amount is known at | |
13361 | compile time. | |
13362 | *) | |
13363 | ||
13364 | @findex RotateRight | |
13365 | PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET; | |
13366 | SetSizeInBits: CARDINAL; | |
13367 | RotateCount: CARDINAL) ; | |
13368 | ||
13369 | ||
13370 | END SYSTEM. | |
13371 | @end example | |
13372 | @page | |
13373 | ||
13374 | @node gm2-libs-iso/Semaphores, gm2-libs-iso/SeqFile, gm2-libs-iso/SYSTEM, M2 ISO Libraries | |
13375 | @subsection gm2-libs-iso/Semaphores | |
13376 | ||
13377 | @example | |
13378 | DEFINITION MODULE Semaphores; | |
13379 | ||
13380 | (* Provides mutual exclusion facilities for use by processes. *) | |
13381 | ||
13382 | TYPE | |
13383 | SEMAPHORE; | |
13384 | ||
13385 | @findex Create | |
13386 | PROCEDURE Create (VAR s: SEMAPHORE; initialCount: CARDINAL ); | |
13387 | (* Creates and returns s as the identity of a new semaphore that | |
13388 | has its associated count initialized to initialCount, and has | |
13389 | no processes yet waiting on it. | |
13390 | *) | |
13391 | ||
13392 | @findex Destroy | |
13393 | PROCEDURE Destroy (VAR s: SEMAPHORE); | |
13394 | (* Recovers the resources used to implement the semaphore s, | |
13395 | provided that no process is waiting for s to become free. | |
13396 | *) | |
13397 | ||
13398 | @findex Claim | |
13399 | PROCEDURE Claim (s: SEMAPHORE); | |
13400 | (* If the count associated with the semaphore s is non-zero, | |
13401 | decrements this count and allows the calling process to | |
13402 | continue; otherwise suspends the calling process until | |
13403 | s is released. | |
13404 | *) | |
13405 | ||
13406 | @findex Release | |
13407 | PROCEDURE Release (s: SEMAPHORE); | |
13408 | (* If there are any processes waiting on the semaphore s, | |
13409 | allows one of them to enter the ready state; otherwise | |
13410 | increments the count associated with s. | |
13411 | *) | |
13412 | ||
13413 | @findex CondClaim | |
13414 | PROCEDURE CondClaim (s: SEMAPHORE): BOOLEAN; | |
13415 | (* Returns FALSE if the call Claim(s) would cause the calling | |
13416 | process to be suspended; in this case the count associated | |
13417 | with s is not changed. Otherwise returns TRUE and the | |
13418 | associated count is decremented. | |
13419 | *) | |
13420 | ||
13421 | END Semaphores. | |
13422 | ||
13423 | @end example | |
13424 | @page | |
13425 | ||
13426 | @node gm2-libs-iso/SeqFile, gm2-libs-iso/ShortComplexMath, gm2-libs-iso/Semaphores, M2 ISO Libraries | |
13427 | @subsection gm2-libs-iso/SeqFile | |
13428 | ||
13429 | @example | |
13430 | DEFINITION MODULE SeqFile; | |
13431 | ||
13432 | (* Rewindable sequential files *) | |
13433 | ||
13434 | IMPORT IOChan, ChanConsts; | |
13435 | ||
13436 | TYPE | |
13437 | @findex ChanId (type) | |
13438 | ChanId = IOChan.ChanId; | |
13439 | @findex FlagSet (type) | |
13440 | FlagSet = ChanConsts.FlagSet; | |
13441 | @findex OpenResults (type) | |
13442 | OpenResults = ChanConsts.OpenResults; | |
13443 | ||
13444 | (* Accepted singleton values of FlagSet *) | |
13445 | ||
13446 | CONST | |
13447 | (* input operations are requested/available *) | |
13448 | @findex read (const) | |
13449 | read = FlagSet@{ChanConsts.readFlag@}; | |
13450 | ||
13451 | (* output operations are requested/available *) | |
13452 | @findex write (const) | |
13453 | write = FlagSet@{ChanConsts.writeFlag@}; | |
13454 | ||
13455 | (* a file may/must/did exist before the channel is opened *) | |
13456 | @findex old (const) | |
13457 | old = FlagSet@{ChanConsts.oldFlag@}; | |
13458 | ||
13459 | (* text operations are requested/available *) | |
13460 | @findex text (const) | |
13461 | text = FlagSet@{ChanConsts.textFlag@}; | |
13462 | ||
13463 | (* raw operations are requested/available *) | |
13464 | @findex raw (const) | |
13465 | raw = FlagSet@{ChanConsts.rawFlag@}; | |
13466 | ||
13467 | @findex OpenWrite | |
13468 | PROCEDURE OpenWrite (VAR cid: ChanId; name: ARRAY OF CHAR; | |
13469 | flags: FlagSet; VAR res: OpenResults); | |
13470 | (* | |
13471 | Attempts to obtain and open a channel connected to a stored | |
13472 | rewindable file of the given name. | |
13473 | The write flag is implied; without the raw flag, text is | |
13474 | implied. If successful, assigns to cid the identity of | |
13475 | the opened channel, assigns the value opened to res, and | |
13476 | selects output mode, with the write position at the start | |
13477 | of the file (i.e. the file is of zero length). | |
13478 | If a channel cannot be opened as required, the value of | |
13479 | res indicates the reason, and cid identifies the invalid | |
13480 | channel. | |
13481 | *) | |
13482 | ||
13483 | @findex OpenAppend | |
13484 | PROCEDURE OpenAppend (VAR cid: ChanId; name: ARRAY OF CHAR; | |
13485 | flags: FlagSet; VAR res: OpenResults); | |
13486 | (* | |
13487 | Attempts to obtain and open a channel connected to a stored | |
13488 | rewindable file of the given name. The write and old flags | |
13489 | are implied; without the raw flag, text is implied. If | |
13490 | successful, assigns to cid the identity of the opened channel, | |
13491 | assigns the value opened to res, and selects output mode, | |
13492 | with the write position corresponding to the length of the | |
13493 | file. If a channel cannot be opened as required, the value | |
13494 | of res indicates the reason, and cid identifies the invalid | |
13495 | channel. | |
13496 | *) | |
13497 | ||
13498 | @findex OpenRead | |
13499 | PROCEDURE OpenRead (VAR cid: ChanId; name: ARRAY OF CHAR; | |
13500 | flags: FlagSet; VAR res: OpenResults); | |
13501 | (* Attempts to obtain and open a channel connected to a stored | |
13502 | rewindable file of the given name. | |
13503 | The read and old flags are implied; without the raw flag, | |
13504 | text is implied. If successful, assigns to cid the | |
13505 | identity of the opened channel, assigns the value opened to | |
13506 | res, and selects input mode, with the read position | |
13507 | corresponding to the start of the file. | |
13508 | If a channel cannot be opened as required, the value of | |
13509 | res indicates the reason, and cid identifies the invalid | |
13510 | channel. | |
13511 | *) | |
13512 | ||
13513 | @findex IsSeqFile | |
13514 | PROCEDURE IsSeqFile (cid: ChanId): BOOLEAN; | |
13515 | (* Tests if the channel identified by cid is open to a | |
13516 | rewindable sequential file. *) | |
13517 | ||
13518 | @findex Reread | |
13519 | PROCEDURE Reread (cid: ChanId); | |
13520 | (* If the channel identified by cid is not open to a rewindable | |
13521 | sequential file, the exception wrongDevice is raised; | |
13522 | otherwise attempts to set the read position to the | |
13523 | start of the file, and to select input mode. | |
13524 | If the operation cannot be performed (perhaps because of | |
13525 | insufficient permissions) neither input mode nor output | |
13526 | mode is selected. | |
13527 | *) | |
13528 | ||
13529 | @findex Rewrite | |
13530 | PROCEDURE Rewrite (cid: ChanId); | |
13531 | (* If the channel identified by cid is not open to a | |
13532 | rewindable sequential file, the exception wrongDevice is | |
13533 | raised; otherwise, attempts to truncate the file to zero | |
13534 | length, and to select output mode. If the operation | |
13535 | cannot be performed (perhaps because of insufficient | |
13536 | permissions) neither input mode nor output mode is selected. | |
13537 | *) | |
13538 | ||
13539 | @findex Close | |
13540 | PROCEDURE Close (VAR cid: ChanId); | |
13541 | (* If the channel identified by cid is not open to a rewindable | |
13542 | sequential file, the exception wrongDevice is raised; | |
13543 | otherwise closes the channel, and assigns the value | |
13544 | identifying the invalid channel to cid. | |
13545 | *) | |
13546 | ||
13547 | END SeqFile. | |
13548 | ||
13549 | @end example | |
13550 | @page | |
13551 | ||
13552 | @node gm2-libs-iso/ShortComplexMath, gm2-libs-iso/ShortIO, gm2-libs-iso/SeqFile, M2 ISO Libraries | |
13553 | @subsection gm2-libs-iso/ShortComplexMath | |
13554 | ||
13555 | @example | |
13556 | DEFINITION MODULE ShortComplexMath; | |
13557 | ||
13558 | (* Mathematical functions for the type SHORTCOMPLEX *) | |
13559 | ||
13560 | CONST | |
13561 | @findex i (const) | |
13562 | i = CMPLX (0.0, 1.0); | |
13563 | @findex one (const) | |
13564 | one = CMPLX (1.0, 0.0); | |
13565 | @findex zero (const) | |
13566 | zero = CMPLX (0.0, 0.0); | |
13567 | ||
13568 | @findex abs | |
13569 | PROCEDURE abs (z: SHORTCOMPLEX): SHORTREAL; | |
13570 | (* Returns the length of z *) | |
13571 | ||
13572 | @findex arg | |
13573 | PROCEDURE arg (z: SHORTCOMPLEX): SHORTREAL; | |
13574 | (* Returns the angle that z subtends to the positive real axis *) | |
13575 | ||
13576 | @findex conj | |
13577 | PROCEDURE conj (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13578 | (* Returns the complex conjugate of z *) | |
13579 | ||
13580 | @findex power | |
13581 | PROCEDURE power (base: SHORTCOMPLEX; exponent: SHORTREAL): SHORTCOMPLEX; | |
13582 | (* Returns the value of the number base raised to the power exponent *) | |
13583 | ||
13584 | @findex sqrt | |
13585 | PROCEDURE sqrt (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13586 | (* Returns the principal square root of z *) | |
13587 | ||
13588 | @findex exp | |
13589 | PROCEDURE exp (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13590 | (* Returns the complex exponential of z *) | |
13591 | ||
13592 | @findex ln | |
13593 | PROCEDURE ln (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13594 | (* Returns the principal value of the natural logarithm of z *) | |
13595 | ||
13596 | @findex sin | |
13597 | PROCEDURE sin (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13598 | (* Returns the sine of z *) | |
13599 | ||
13600 | @findex cos | |
13601 | PROCEDURE cos (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13602 | (* Returns the cosine of z *) | |
13603 | ||
13604 | @findex tan | |
13605 | PROCEDURE tan (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13606 | (* Returns the tangent of z *) | |
13607 | ||
13608 | @findex arcsin | |
13609 | PROCEDURE arcsin (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13610 | (* Returns the arcsine of z *) | |
13611 | ||
13612 | @findex arccos | |
13613 | PROCEDURE arccos (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13614 | (* Returns the arccosine of z *) | |
13615 | ||
13616 | @findex arctan | |
13617 | PROCEDURE arctan (z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13618 | (* Returns the arctangent of z *) | |
13619 | ||
13620 | @findex polarToComplex | |
13621 | PROCEDURE polarToComplex (abs, arg: SHORTREAL): SHORTCOMPLEX; | |
13622 | (* Returns the complex number with the specified polar coordinates *) | |
13623 | ||
13624 | @findex scalarMult | |
13625 | PROCEDURE scalarMult (scalar: SHORTREAL; z: SHORTCOMPLEX): SHORTCOMPLEX; | |
13626 | (* Returns the scalar product of scalar with z *) | |
13627 | ||
13628 | @findex IsCMathException | |
13629 | PROCEDURE IsCMathException (): BOOLEAN; | |
13630 | (* Returns TRUE if the current coroutine is in the exceptional execution state | |
13631 | because of the raising of an exception in a routine from this module; otherwise | |
13632 | returns FALSE. | |
13633 | *) | |
13634 | ||
13635 | END ShortComplexMath. | |
13636 | ||
13637 | @end example | |
13638 | @page | |
13639 | ||
13640 | @node gm2-libs-iso/ShortIO, gm2-libs-iso/ShortWholeIO, gm2-libs-iso/ShortComplexMath, M2 ISO Libraries | |
13641 | @subsection gm2-libs-iso/ShortIO | |
13642 | ||
13643 | @example | |
13644 | DEFINITION MODULE ShortIO; | |
13645 | ||
13646 | (* Input and output of short real numbers in decimal text form | |
13647 | over specified channels. The read result is of the type | |
13648 | IOConsts.ReadResults. | |
13649 | *) | |
13650 | ||
13651 | IMPORT IOChan; | |
13652 | ||
13653 | (* The text form of a signed fixed-point real number is | |
13654 | ["+" | "-"], decimal digit, @{decimal digit@}, [".", | |
13655 | @{decimal digit@}] | |
13656 | ||
13657 | The text form of a signed floating-point real number is | |
13658 | signed fixed-point real number, | |
13659 | "E", ["+" | "-"], decimal digit, @{decimal digit@} | |
13660 | *) | |
13661 | ||
13662 | @findex ReadReal | |
13663 | PROCEDURE ReadReal (cid: IOChan.ChanId; VAR real: SHORTREAL); | |
13664 | (* Skips leading spaces, and removes any remaining characters | |
13665 | from cid that form part of a signed fixed or floating | |
13666 | point number. The value of this number is assigned to real. | |
13667 | The read result is set to the value allRight, outOfRange, | |
13668 | wrongFormat, endOfLine, or endOfInput. | |
13669 | *) | |
13670 | ||
13671 | @findex WriteFloat | |
13672 | PROCEDURE WriteFloat (cid: IOChan.ChanId; real: SHORTREAL; | |
13673 | sigFigs: CARDINAL; width: CARDINAL); | |
13674 | (* Writes the value of real to cid in floating-point text form, | |
13675 | with sigFigs significant figures, in a field of the given | |
13676 | minimum width. | |
13677 | *) | |
13678 | ||
13679 | @findex WriteEng | |
13680 | PROCEDURE WriteEng (cid: IOChan.ChanId; real: SHORTREAL; | |
13681 | sigFigs: CARDINAL; width: CARDINAL); | |
13682 | (* As for WriteFloat, except that the number is scaled with | |
13683 | one to three digits in the whole number part, and with an | |
13684 | exponent that is a multiple of three. | |
13685 | *) | |
13686 | ||
13687 | @findex WriteFixed | |
13688 | PROCEDURE WriteFixed (cid: IOChan.ChanId; real: SHORTREAL; | |
13689 | place: INTEGER; width: CARDINAL); | |
13690 | (* Writes the value of real to cid in fixed-point text form, | |
13691 | rounded to the given place relative to the decimal point, | |
13692 | in a field of the given minimum width. | |
13693 | *) | |
13694 | ||
13695 | @findex WriteReal | |
13696 | PROCEDURE WriteReal (cid: IOChan.ChanId; real: SHORTREAL; | |
13697 | width: CARDINAL); | |
13698 | (* Writes the value of real to cid, as WriteFixed if the | |
13699 | sign and magnitude can be shown in the given width, or | |
13700 | otherwise as WriteFloat. The number of places or | |
13701 | significant digits depends on the given width. | |
13702 | *) | |
13703 | ||
13704 | END ShortIO. | |
13705 | @end example | |
13706 | @page | |
13707 | ||
13708 | @node gm2-libs-iso/ShortWholeIO, gm2-libs-iso/SimpleCipher, gm2-libs-iso/ShortIO, M2 ISO Libraries | |
13709 | @subsection gm2-libs-iso/ShortWholeIO | |
13710 | ||
13711 | @example | |
13712 | DEFINITION MODULE ShortWholeIO; | |
13713 | ||
13714 | (* Input and output of whole numbers in decimal text form | |
13715 | over specified channels. The read result is of the | |
13716 | type IOConsts.ReadResults. | |
13717 | *) | |
13718 | ||
13719 | IMPORT IOChan; | |
13720 | ||
13721 | (* The text form of a signed whole number is | |
13722 | ["+" | "-"], decimal digit, @{decimal digit@} | |
13723 | ||
13724 | The text form of an unsigned whole number is | |
13725 | decimal digit, @{decimal digit@} | |
13726 | *) | |
13727 | ||
13728 | @findex ReadInt | |
13729 | PROCEDURE ReadInt (cid: IOChan.ChanId; VAR int: SHORTINT); | |
13730 | (* Skips leading spaces, and removes any remaining characters | |
13731 | from cid that form part of a signed whole number. The | |
13732 | value of this number is assigned to int. The read result | |
13733 | is set to the value allRight, outOfRange, wrongFormat, | |
13734 | endOfLine, or endOfInput. | |
13735 | *) | |
13736 | ||
13737 | @findex WriteInt | |
13738 | PROCEDURE WriteInt (cid: IOChan.ChanId; int: SHORTINT; | |
13739 | width: CARDINAL); | |
13740 | (* Writes the value of int to cid in text form, in a field of | |
13741 | the given minimum width. *) | |
13742 | ||
13743 | @findex ReadCard | |
13744 | PROCEDURE ReadCard (cid: IOChan.ChanId; VAR card: SHORTCARD); | |
13745 | (* Skips leading spaces, and removes any remaining characters | |
13746 | from cid that form part of an unsigned whole number. The | |
13747 | value of this number is assigned to card. The read result | |
13748 | is set to the value allRight, outOfRange, wrongFormat, | |
13749 | endOfLine, or endOfInput. | |
13750 | *) | |
13751 | ||
13752 | @findex WriteCard | |
13753 | PROCEDURE WriteCard (cid: IOChan.ChanId; card: SHORTCARD; | |
13754 | width: CARDINAL); | |
13755 | (* Writes the value of card to cid in text form, in a field | |
13756 | of the given minimum width. *) | |
13757 | ||
13758 | END ShortWholeIO. | |
13759 | @end example | |
13760 | @page | |
13761 | ||
13762 | @node gm2-libs-iso/SimpleCipher, gm2-libs-iso/StdChans, gm2-libs-iso/ShortWholeIO, M2 ISO Libraries | |
13763 | @subsection gm2-libs-iso/SimpleCipher | |
13764 | ||
13765 | @example | |
13766 | DEFINITION MODULE SimpleCipher ; | |
13767 | ||
13768 | (* | |
13769 | Description: provides a simple Caesar cipher layer which | |
13770 | can be attached to any channel device. This, | |
13771 | pedagogical, module is designed to show how | |
13772 | it is possible to add further layers underneath | |
13773 | the channel devices. | |
13774 | *) | |
13775 | ||
13776 | FROM IOChan IMPORT ChanId ; | |
13777 | ||
13778 | ||
13779 | (* | |
13780 | InsertCipherLayer - inserts a caesar cipher below channel, cid. | |
13781 | The encryption, key, is specified. | |
13782 | *) | |
13783 | ||
13784 | @findex InsertCipherLayer | |
13785 | PROCEDURE InsertCipherLayer (cid: ChanId; key: INTEGER) ; | |
13786 | ||
13787 | ||
13788 | (* | |
13789 | RemoveCipherLayer - removes a Caesar cipher below channel, cid. | |
13790 | *) | |
13791 | ||
13792 | @findex RemoveCipherLayer | |
13793 | PROCEDURE RemoveCipherLayer (cid: ChanId) ; | |
13794 | ||
13795 | ||
13796 | END SimpleCipher. | |
13797 | @end example | |
13798 | @page | |
13799 | ||
13800 | @node gm2-libs-iso/StdChans, gm2-libs-iso/Storage, gm2-libs-iso/SimpleCipher, M2 ISO Libraries | |
13801 | @subsection gm2-libs-iso/StdChans | |
13802 | ||
13803 | @example | |
13804 | DEFINITION MODULE StdChans; | |
13805 | ||
13806 | (* Access to standard and default channels *) | |
13807 | ||
13808 | IMPORT IOChan; | |
13809 | ||
13810 | TYPE | |
13811 | @findex ChanId (type) | |
13812 | ChanId = IOChan.ChanId; | |
13813 | (* Values of this type are used to identify channels *) | |
13814 | ||
13815 | (* The following functions return the standard channel values. | |
13816 | These channels cannot be closed. | |
13817 | *) | |
13818 | ||
13819 | @findex StdInChan | |
13820 | PROCEDURE StdInChan (): ChanId; | |
13821 | (* Returns the identity of the implementation-defined standard source for | |
13822 | program | |
13823 | input. | |
13824 | *) | |
13825 | ||
13826 | @findex StdOutChan | |
13827 | PROCEDURE StdOutChan (): ChanId; | |
13828 | (* Returns the identity of the implementation-defined standard source for program | |
13829 | output. | |
13830 | *) | |
13831 | ||
13832 | @findex StdErrChan | |
13833 | PROCEDURE StdErrChan (): ChanId; | |
13834 | (* Returns the identity of the implementation-defined standard destination for program | |
13835 | error messages. | |
13836 | *) | |
13837 | ||
13838 | @findex NullChan | |
13839 | PROCEDURE NullChan (): ChanId; | |
13840 | (* Returns the identity of a channel open to the null device. *) | |
13841 | ||
13842 | (* The following functions return the default channel values *) | |
13843 | ||
13844 | @findex InChan | |
13845 | PROCEDURE InChan (): ChanId; | |
13846 | (* Returns the identity of the current default input channel. *) | |
13847 | ||
13848 | @findex OutChan | |
13849 | PROCEDURE OutChan (): ChanId; | |
13850 | (* Returns the identity of the current default output channel. *) | |
13851 | ||
13852 | @findex ErrChan | |
13853 | PROCEDURE ErrChan (): ChanId; | |
13854 | (* Returns the identity of the current default error message channel. *) | |
13855 | ||
13856 | (* The following procedures allow for redirection of the default channels *) | |
13857 | ||
13858 | @findex SetInChan | |
13859 | PROCEDURE SetInChan (cid: ChanId); | |
13860 | (* Sets the current default input channel to that identified by cid. *) | |
13861 | ||
13862 | @findex SetOutChan | |
13863 | PROCEDURE SetOutChan (cid: ChanId); | |
13864 | (* Sets the current default output channel to that identified by cid. *) | |
13865 | ||
13866 | @findex SetErrChan | |
13867 | PROCEDURE SetErrChan (cid: ChanId); | |
13868 | (* Sets the current default error channel to that identified by cid. *) | |
13869 | ||
13870 | END StdChans. | |
13871 | @end example | |
13872 | @page | |
13873 | ||
13874 | @node gm2-libs-iso/Storage, gm2-libs-iso/StreamFile, gm2-libs-iso/StdChans, M2 ISO Libraries | |
13875 | @subsection gm2-libs-iso/Storage | |
13876 | ||
13877 | @example | |
13878 | DEFINITION MODULE Storage; | |
13879 | ||
13880 | (* Facilities for dynamically allocating and deallocating storage *) | |
13881 | ||
13882 | IMPORT SYSTEM; | |
13883 | ||
13884 | @findex ALLOCATE | |
13885 | PROCEDURE ALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); | |
13886 | (* Allocates storage for a variable of size amount and assigns | |
13887 | the address of this variable to addr. If there is insufficient | |
13888 | unallocated storage to do this, the value NIL is assigned to addr. | |
13889 | *) | |
13890 | ||
13891 | @findex DEALLOCATE | |
13892 | PROCEDURE DEALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); | |
13893 | (* Deallocates amount locations allocated by ALLOCATE for | |
13894 | the storage of the variable addressed by addr and assigns | |
13895 | the value NIL to addr. | |
13896 | *) | |
13897 | ||
13898 | @findex REALLOCATE | |
13899 | PROCEDURE REALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); | |
13900 | (* Attempts to reallocate, amount of storage. Effectively it | |
13901 | calls ALLOCATE, copies the amount of data pointed to by | |
13902 | addr into the new space and DEALLOCATES the addr. | |
13903 | This procedure is a GNU extension. | |
13904 | *) | |
13905 | ||
13906 | TYPE | |
13907 | @findex StorageExceptions (type) | |
13908 | StorageExceptions = ( | |
13909 | nilDeallocation, (* first argument to DEALLOCATE is NIL *) | |
13910 | pointerToUnallocatedStorage, (* storage to deallocate not allocated by ALLOCATE *) | |
13911 | wrongStorageToUnallocate (* amount to deallocate is not amount allocated *) | |
13912 | ); | |
13913 | ||
13914 | @findex IsStorageException | |
13915 | PROCEDURE IsStorageException (): BOOLEAN; | |
13916 | (* Returns TRUE if the current coroutine is in the exceptional | |
13917 | execution state because of the raising of an exception from | |
13918 | StorageExceptions; otherwise returns FALSE. | |
13919 | *) | |
13920 | ||
13921 | @findex StorageException | |
13922 | PROCEDURE StorageException (): StorageExceptions; | |
13923 | (* If the current coroutine is in the exceptional execution | |
13924 | state because of the raising of an exception from | |
13925 | StorageExceptions, returns the corresponding | |
13926 | enumeration value, and otherwise raises an exception. | |
13927 | *) | |
13928 | ||
13929 | END Storage. | |
13930 | @end example | |
13931 | @page | |
13932 | ||
13933 | @node gm2-libs-iso/StreamFile, gm2-libs-iso/StringChan, gm2-libs-iso/Storage, M2 ISO Libraries | |
13934 | @subsection gm2-libs-iso/StreamFile | |
13935 | ||
13936 | @example | |
13937 | DEFINITION MODULE StreamFile; | |
13938 | ||
13939 | (* Independent sequential data streams *) | |
13940 | ||
13941 | IMPORT IOChan, ChanConsts; | |
13942 | ||
13943 | TYPE | |
13944 | @findex ChanId (type) | |
13945 | ChanId = IOChan.ChanId; | |
13946 | @findex FlagSet (type) | |
13947 | FlagSet = ChanConsts.FlagSet; | |
13948 | @findex OpenResults (type) | |
13949 | OpenResults = ChanConsts.OpenResults; | |
13950 | ||
13951 | (* Accepted singleton values of FlagSet *) | |
13952 | ||
13953 | CONST | |
13954 | @findex read (const) | |
13955 | read = FlagSet@{ChanConsts.readFlag@}; (* input operations are requested/available *) | |
13956 | @findex write (const) | |
13957 | write = FlagSet@{ChanConsts.writeFlag@}; (* output operations are requested/available *) | |
13958 | @findex old (const) | |
13959 | old = FlagSet@{ChanConsts.oldFlag@}; (* a file may/must/did exist before the channel is | |
13960 | opened *) | |
13961 | @findex text (const) | |
13962 | text = FlagSet@{ChanConsts.textFlag@}; (* text operations are requested/available *) | |
13963 | @findex raw (const) | |
13964 | raw = FlagSet@{ChanConsts.rawFlag@}; (* raw operations are requested/available *) | |
13965 | ||
13966 | ||
13967 | @findex Open | |
13968 | PROCEDURE Open (VAR cid: ChanId; name: ARRAY OF CHAR; | |
13969 | flags: FlagSet; VAR res: OpenResults); | |
13970 | (* Attempts to obtain and open a channel connected to a | |
13971 | sequential stream of the given name. | |
13972 | The read flag implies old; without the raw flag, text is | |
13973 | implied. If successful, assigns to cid the identity of | |
13974 | the opened channel, and assigns the value opened to res. | |
13975 | If a channel cannot be opened as required, the value of | |
13976 | res indicates the reason, and cid identifies the invalid | |
13977 | channel. | |
13978 | *) | |
13979 | ||
13980 | @findex IsStreamFile | |
13981 | PROCEDURE IsStreamFile (cid: ChanId): BOOLEAN; | |
13982 | (* Tests if the channel identified by cid is open to a sequential stream. *) | |
13983 | ||
13984 | @findex Close | |
13985 | PROCEDURE Close (VAR cid: ChanId); | |
13986 | (* If the channel identified by cid is not open to a sequential stream, the exception | |
13987 | wrongDevice is raised; otherwise closes the channel, and assigns the value identifying | |
13988 | the invalid channel to cid. | |
13989 | *) | |
13990 | ||
13991 | END StreamFile. | |
13992 | ||
13993 | @end example | |
13994 | @page | |
13995 | ||
13996 | @node gm2-libs-iso/StringChan, gm2-libs-iso/Strings, gm2-libs-iso/StreamFile, M2 ISO Libraries | |
13997 | @subsection gm2-libs-iso/StringChan | |
13998 | ||
13999 | @example | |
14000 | DEFINITION MODULE StringChan ; | |
14001 | ||
14002 | (* | |
14003 | Description: provides a set of Channel and String | |
14004 | input and output procedures. | |
14005 | *) | |
14006 | ||
14007 | FROM DynamicStrings IMPORT String ; | |
14008 | IMPORT IOChan; | |
14009 | ||
14010 | ||
14011 | (* | |
14012 | writeString - writes a string, s, to ChanId, cid. | |
14013 | The string, s, is not destroyed. | |
14014 | *) | |
14015 | ||
14016 | @findex writeString | |
14017 | PROCEDURE writeString (cid: IOChan.ChanId; s: String) ; | |
14018 | ||
14019 | ||
14020 | (* | |
14021 | writeFieldWidth - writes a string, s, to ChanId, cid. | |
14022 | The string, s, is not destroyed and it | |
14023 | is prefixed by spaces so that at least, | |
14024 | width, characters are written. If the | |
14025 | string, s, is longer than width then | |
14026 | no spaces are prefixed to the output | |
14027 | and the entire string is written. | |
14028 | *) | |
14029 | ||
14030 | @findex writeFieldWidth | |
14031 | PROCEDURE writeFieldWidth (cid: IOChan.ChanId; | |
14032 | s: String; width: CARDINAL) ; | |
14033 | ||
14034 | ||
14035 | END StringChan. | |
14036 | @end example | |
14037 | @page | |
14038 | ||
14039 | @node gm2-libs-iso/Strings, gm2-libs-iso/SysClock, gm2-libs-iso/StringChan, M2 ISO Libraries | |
14040 | @subsection gm2-libs-iso/Strings | |
14041 | ||
14042 | @example | |
14043 | DEFINITION MODULE Strings; | |
14044 | ||
14045 | (* Facilities for manipulating strings *) | |
14046 | ||
14047 | TYPE | |
14048 | @findex String1 (type) | |
14049 | String1 = ARRAY [0..0] OF CHAR; | |
14050 | (* String1 is provided for constructing a value of a single-character string type from a | |
14051 | single character value in order to pass CHAR values to ARRAY OF CHAR parameters. | |
14052 | *) | |
14053 | ||
14054 | @findex Length | |
14055 | PROCEDURE Length (stringVal: ARRAY OF CHAR): CARDINAL; | |
14056 | (* Returns the length of stringVal (the same value as would be returned by the | |
14057 | pervasive function LENGTH). | |
14058 | *) | |
14059 | ||
14060 | ||
14061 | (* The following seven procedures construct a string value, and attempt to assign it to a | |
14062 | variable parameter. They all have the property that if the length of the constructed string | |
14063 | value exceeds the capacity of the variable parameter, a truncated value is assigned, while | |
14064 | if the length of the constructed string value is less than the capacity of the variable | |
14065 | parameter, a string terminator is appended before assignment is performed. | |
14066 | *) | |
14067 | ||
14068 | @findex Assign | |
14069 | PROCEDURE Assign (source: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR); | |
14070 | (* Copies source to destination *) | |
14071 | ||
14072 | @findex Extract | |
14073 | PROCEDURE Extract (source: ARRAY OF CHAR; startIndex, numberToExtract: CARDINAL; | |
14074 | VAR destination: ARRAY OF CHAR); | |
14075 | (* Copies at most numberToExtract characters from source to destination, starting at position | |
14076 | startIndex in source. | |
14077 | *) | |
14078 | ||
14079 | @findex Delete | |
14080 | PROCEDURE Delete (VAR stringVar: ARRAY OF CHAR; startIndex, numberToDelete: | |
14081 | CARDINAL); | |
14082 | (* Deletes at most numberToDelete characters from stringVar, starting at position | |
14083 | startIndex. | |
14084 | *) | |
14085 | ||
14086 | @findex Insert | |
14087 | PROCEDURE Insert (source: ARRAY OF CHAR; startIndex: CARDINAL; | |
14088 | VAR destination: ARRAY OF CHAR); | |
14089 | (* Inserts source into destination at position startIndex *) | |
14090 | ||
14091 | @findex Replace | |
14092 | PROCEDURE Replace (source: ARRAY OF CHAR; startIndex: CARDINAL; | |
14093 | VAR destination: ARRAY OF CHAR); | |
14094 | (* Copies source into destination, starting at position startIndex. Copying stops when | |
14095 | all of source has been copied, or when the last character of the string value in | |
14096 | destination has been replaced. | |
14097 | *) | |
14098 | ||
14099 | @findex Append | |
14100 | PROCEDURE Append (source: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR); | |
14101 | (* Appends source to destination. *) | |
14102 | ||
14103 | @findex Concat | |
14104 | PROCEDURE Concat (source1, source2: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR); | |
14105 | (* Concatenates source2 onto source1 and copies the result into destination. *) | |
14106 | ||
14107 | (* The following predicates provide for pre-testing of the operation-completion | |
14108 | conditions for the procedures above. | |
14109 | *) | |
14110 | ||
14111 | @findex CanAssignAll | |
14112 | PROCEDURE CanAssignAll (sourceLength: CARDINAL; VAR destination: ARRAY OF CHAR): BOOLEAN; | |
14113 | (* Returns TRUE if a number of characters, indicated by sourceLength, will fit into | |
14114 | destination; otherwise returns FALSE. | |
14115 | *) | |
14116 | ||
14117 | @findex CanExtractAll | |
14118 | PROCEDURE CanExtractAll (sourceLength, startIndex, numberToExtract: CARDINAL; | |
14119 | VAR destination: ARRAY OF CHAR): BOOLEAN; | |
14120 | (* Returns TRUE if there are numberToExtract characters starting at startIndex and | |
14121 | within the sourceLength of some string, and if the capacity of destination is | |
14122 | sufficient to hold numberToExtract characters; otherwise returns FALSE. | |
14123 | *) | |
14124 | ||
14125 | @findex CanDeleteAll | |
14126 | PROCEDURE CanDeleteAll (stringLength, startIndex, numberToDelete: CARDINAL): BOOLEAN; | |
14127 | (* Returns TRUE if there are numberToDelete characters starting at startIndex and | |
14128 | within the stringLength of some string; otherwise returns FALSE. | |
14129 | *) | |
14130 | ||
14131 | @findex CanInsertAll | |
14132 | PROCEDURE CanInsertAll (sourceLength, startIndex: CARDINAL; | |
14133 | VAR destination: ARRAY OF CHAR): BOOLEAN; | |
14134 | (* Returns TRUE if there is room for the insertion of sourceLength characters from | |
14135 | some string into destination starting at startIndex; otherwise returns FALSE. | |
14136 | *) | |
14137 | ||
14138 | @findex CanReplaceAll | |
14139 | PROCEDURE CanReplaceAll (sourceLength, startIndex: CARDINAL; | |
14140 | VAR destination: ARRAY OF CHAR): BOOLEAN; | |
14141 | (* Returns TRUE if there is room for the replacement of sourceLength characters in | |
14142 | destination starting at startIndex; otherwise returns FALSE. | |
14143 | *) | |
14144 | ||
14145 | @findex CanAppendAll | |
14146 | PROCEDURE CanAppendAll (sourceLength: CARDINAL; VAR destination: ARRAY OF CHAR): BOOLEAN; | |
14147 | (* Returns TRUE if there is sufficient room in destination to append a string of | |
14148 | length sourceLength to the string in destination; otherwise returns FALSE. | |
14149 | *) | |
14150 | ||
14151 | @findex CanConcatAll | |
14152 | PROCEDURE CanConcatAll (source1Length, source2Length: CARDINAL; | |
14153 | VAR destination: ARRAY OF CHAR): BOOLEAN; | |
14154 | (* Returns TRUE if there is sufficient room in destination for a two strings of | |
14155 | lengths source1Length and source2Length; otherwise returns FALSE. | |
14156 | *) | |
14157 | ||
14158 | (* The following type and procedures provide for the comparison of string values, and for the | |
14159 | location of substrings within strings. | |
14160 | *) | |
14161 | ||
14162 | TYPE | |
14163 | @findex CompareResults (type) | |
14164 | CompareResults = (less, equal, greater); | |
14165 | ||
14166 | @findex Compare | |
14167 | PROCEDURE Compare (stringVal1, stringVal2: ARRAY OF CHAR): CompareResults; | |
14168 | (* Returns less, equal, or greater, according as stringVal1 is lexically less than, | |
14169 | equal to, or greater than stringVal2. | |
14170 | *) | |
14171 | ||
14172 | @findex Equal | |
14173 | PROCEDURE Equal (stringVal1, stringVal2: ARRAY OF CHAR): BOOLEAN; | |
14174 | (* Returns Strings.Compare(stringVal1, stringVal2) = Strings.equal *) | |
14175 | ||
14176 | @findex FindNext | |
14177 | PROCEDURE FindNext (pattern, stringToSearch: ARRAY OF CHAR; startIndex: CARDINAL; | |
14178 | VAR patternFound: BOOLEAN; VAR posOfPattern: CARDINAL); | |
14179 | (* Looks forward for next occurrence of pattern in stringToSearch, starting the search at | |
14180 | position startIndex. If startIndex < LENGTH(stringToSearch) and pattern is found, | |
14181 | patternFound is returned as TRUE, and posOfPattern contains the start position in | |
14182 | stringToSearch of pattern. Otherwise patternFound is returned as FALSE, and posOfPattern | |
14183 | is unchanged. | |
14184 | *) | |
14185 | ||
14186 | @findex FindPrev | |
14187 | PROCEDURE FindPrev (pattern, stringToSearch: ARRAY OF CHAR; startIndex: CARDINAL; | |
14188 | VAR patternFound: BOOLEAN; VAR posOfPattern: CARDINAL); | |
14189 | (* Looks backward for the previous occurrence of pattern in stringToSearch and returns the | |
14190 | position of the first character of the pattern if found. The search for the pattern | |
14191 | begins at startIndex. If pattern is found, patternFound is returned as TRUE, and | |
14192 | posOfPattern contains the start position in stringToSearch of pattern in the range | |
14193 | [0..startIndex]. Otherwise patternFound is returned as FALSE, and posOfPattern is unchanged. | |
14194 | *) | |
14195 | ||
14196 | @findex FindDiff | |
14197 | PROCEDURE FindDiff (stringVal1, stringVal2: ARRAY OF CHAR; | |
14198 | VAR differenceFound: BOOLEAN; VAR posOfDifference: CARDINAL); | |
14199 | (* Compares the string values in stringVal1 and stringVal2 for differences. If they | |
14200 | are equal, differenceFound is returned as FALSE, and TRUE otherwise. If | |
14201 | differenceFound is TRUE, posOfDifference is set to the position of the first | |
14202 | difference; otherwise posOfDifference is unchanged. | |
14203 | *) | |
14204 | ||
14205 | @findex Capitalize | |
14206 | PROCEDURE Capitalize (VAR stringVar: ARRAY OF CHAR); | |
14207 | (* Applies the function CAP to each character of the string value in stringVar. *) | |
14208 | ||
14209 | ||
14210 | END Strings. | |
14211 | ||
14212 | @end example | |
14213 | @page | |
14214 | ||
14215 | @node gm2-libs-iso/SysClock, gm2-libs-iso/TERMINATION, gm2-libs-iso/Strings, M2 ISO Libraries | |
14216 | @subsection gm2-libs-iso/SysClock | |
14217 | ||
14218 | @example | |
14219 | DEFINITION MODULE SysClock; | |
14220 | ||
14221 | (* Facilities for accessing a system clock that records the date | |
14222 | and time of day *) | |
14223 | ||
14224 | CONST | |
14225 | @findex maxSecondParts (const) | |
14226 | maxSecondParts = 1000000 ; | |
14227 | ||
14228 | TYPE | |
14229 | @findex Month (type) | |
14230 | Month = [1 .. 12]; | |
14231 | @findex Day (type) | |
14232 | Day = [1 .. 31]; | |
14233 | @findex Hour (type) | |
14234 | Hour = [0 .. 23]; | |
14235 | @findex Min (type) | |
14236 | Min = [0 .. 59]; | |
14237 | @findex Sec (type) | |
14238 | Sec = [0 .. 59]; | |
14239 | @findex Fraction (type) | |
14240 | Fraction = [0 .. maxSecondParts]; | |
14241 | @findex UTCDiff (type) | |
14242 | UTCDiff = [-780 .. 720]; | |
14243 | @findex DateTime (type) | |
14244 | DateTime = | |
14245 | RECORD | |
14246 | year: CARDINAL; | |
14247 | month: Month; | |
14248 | day: Day; | |
14249 | hour: Hour; | |
14250 | minute: Min; | |
14251 | second: Sec; | |
14252 | fractions: Fraction; (* parts of a second *) | |
14253 | zone: UTCDiff; (* Time zone differential | |
14254 | factor which is the number | |
14255 | of minutes to add to local | |
14256 | time to obtain UTC. *) | |
14257 | summerTimeFlag: BOOLEAN; (* Interpretation of flag | |
14258 | depends on local usage. *) | |
14259 | END; | |
14260 | ||
14261 | @findex CanGetClock | |
14262 | PROCEDURE CanGetClock(): BOOLEAN; | |
14263 | (* Tests if the clock can be read *) | |
14264 | ||
14265 | @findex CanSetClock | |
14266 | PROCEDURE CanSetClock(): BOOLEAN; | |
14267 | (* Tests if the clock can be set *) | |
14268 | ||
14269 | @findex IsValidDateTime | |
14270 | PROCEDURE IsValidDateTime(userData: DateTime): BOOLEAN; | |
14271 | (* Tests if the value of userData is a valid *) | |
14272 | ||
14273 | @findex GetClock | |
14274 | PROCEDURE GetClock(VAR userData: DateTime); | |
14275 | (* Assigns local date and time of the day to userData *) | |
14276 | ||
14277 | @findex SetClock | |
14278 | PROCEDURE SetClock(userData: DateTime); | |
14279 | (* Sets the system time clock to the given local date and | |
14280 | time *) | |
14281 | ||
14282 | END SysClock. | |
14283 | @end example | |
14284 | @page | |
14285 | ||
14286 | @node gm2-libs-iso/TERMINATION, gm2-libs-iso/TermFile, gm2-libs-iso/SysClock, M2 ISO Libraries | |
14287 | @subsection gm2-libs-iso/TERMINATION | |
14288 | ||
14289 | @example | |
14290 | DEFINITION MODULE TERMINATION; | |
14291 | ||
14292 | (* Provides facilities for enquiries concerning the occurrence of termination events. *) | |
14293 | ||
14294 | @findex IsTerminating | |
14295 | PROCEDURE IsTerminating (): BOOLEAN ; | |
14296 | (* Returns true if any coroutine has started program termination and false otherwise. *) | |
14297 | ||
14298 | @findex HasHalted | |
14299 | PROCEDURE HasHalted (): BOOLEAN ; | |
14300 | (* Returns true if a call to HALT has been made and false otherwise. *) | |
14301 | ||
14302 | END TERMINATION. | |
14303 | @end example | |
14304 | @page | |
14305 | ||
14306 | @node gm2-libs-iso/TermFile, gm2-libs-iso/TextIO, gm2-libs-iso/TERMINATION, M2 ISO Libraries | |
14307 | @subsection gm2-libs-iso/TermFile | |
14308 | ||
14309 | @example | |
14310 | DEFINITION MODULE TermFile; | |
14311 | ||
14312 | (* Access to the terminal device *) | |
14313 | ||
14314 | (* Channels opened by this module are connected to a single | |
14315 | terminal device; typed characters are distributed between | |
14316 | channels according to the sequence of read requests. | |
14317 | *) | |
14318 | ||
14319 | IMPORT IOChan, ChanConsts; | |
14320 | ||
14321 | TYPE | |
14322 | @findex ChanId (type) | |
14323 | ChanId = IOChan.ChanId; | |
14324 | @findex FlagSet (type) | |
14325 | FlagSet = ChanConsts.FlagSet; | |
14326 | @findex OpenResults (type) | |
14327 | OpenResults = ChanConsts.OpenResults; | |
14328 | ||
14329 | (* Accepted singleton values of FlagSet *) | |
14330 | ||
14331 | CONST | |
14332 | @findex read (const) | |
14333 | read = FlagSet@{ChanConsts.readFlag@}; | |
14334 | (* input operations are requested/available *) | |
14335 | @findex write (const) | |
14336 | write = FlagSet@{ChanConsts.writeFlag@}; | |
14337 | (* output operations are requested/available *) | |
14338 | @findex text (const) | |
14339 | text = FlagSet@{ChanConsts.textFlag@}; | |
14340 | (* text operations are requested/available *) | |
14341 | @findex raw (const) | |
14342 | raw = FlagSet@{ChanConsts.rawFlag@}; | |
14343 | (* raw operations are requested/available *) | |
14344 | @findex echo (const) | |
14345 | echo = FlagSet@{ChanConsts.echoFlag@}; | |
14346 | (* echoing by interactive device on reading of | |
14347 | characters from input stream requested/applies | |
14348 | *) | |
14349 | ||
14350 | @findex Open | |
14351 | PROCEDURE Open (VAR cid: ChanId; flagset: FlagSet; VAR res: OpenResults); | |
14352 | (* Attempts to obtain and open a channel connected to | |
14353 | the terminal. Without the raw flag, text is implied. | |
14354 | Without the echo flag, line mode is requested, | |
14355 | otherwise single character mode is requested. | |
14356 | If successful, assigns to cid the identity of | |
14357 | the opened channel, and assigns the value opened to res. | |
14358 | If a channel cannot be opened as required, the value of | |
14359 | res indicates the reason, and cid identifies the | |
14360 | invalid channel. | |
14361 | *) | |
14362 | ||
14363 | @findex IsTermFile | |
14364 | PROCEDURE IsTermFile (cid: ChanId): BOOLEAN; | |
14365 | (* Tests if the channel identified by cid is open to | |
14366 | the terminal. *) | |
14367 | ||
14368 | @findex Close | |
14369 | PROCEDURE Close (VAR cid: ChanId); | |
14370 | (* If the channel identified by cid is not open to the terminal, | |
14371 | the exception wrongDevice is raised; otherwise closes the | |
14372 | channel and assigns the value identifying the invalid channel | |
14373 | to cid. | |
14374 | *) | |
14375 | ||
14376 | END TermFile. | |
14377 | ||
14378 | @end example | |
14379 | @page | |
14380 | ||
14381 | @node gm2-libs-iso/TextIO, gm2-libs-iso/WholeConv, gm2-libs-iso/TermFile, M2 ISO Libraries | |
14382 | @subsection gm2-libs-iso/TextIO | |
14383 | ||
14384 | @example | |
14385 | DEFINITION MODULE TextIO; | |
14386 | ||
14387 | (* Input and output of character and string types over | |
14388 | specified channels. The read result is of the type | |
14389 | IOConsts.ReadResults. | |
14390 | *) | |
14391 | ||
14392 | IMPORT IOChan; | |
14393 | ||
14394 | (* The following procedures do not read past line marks *) | |
14395 | ||
14396 | @findex ReadChar | |
14397 | PROCEDURE ReadChar (cid: IOChan.ChanId; VAR ch: CHAR); | |
14398 | (* If possible, removes a character from the input stream | |
14399 | cid and assigns the corresponding value to ch. The | |
14400 | read result is set to the value allRight, endOfLine, or | |
14401 | endOfInput. | |
14402 | *) | |
14403 | ||
14404 | @findex ReadRestLine | |
14405 | PROCEDURE ReadRestLine (cid: IOChan.ChanId; VAR s: ARRAY OF CHAR); | |
14406 | (* Removes any remaining characters from the input stream | |
14407 | cid before the next line mark, copying to s as many as | |
14408 | can be accommodated as a string value. The read result is | |
14409 | set to the value allRight, outOfRange, endOfLine, or | |
14410 | endOfInput. | |
14411 | *) | |
14412 | ||
14413 | @findex ReadString | |
14414 | PROCEDURE ReadString (cid: IOChan.ChanId; VAR s: ARRAY OF CHAR); | |
14415 | (* Removes only those characters from the input stream cid | |
14416 | before the next line mark that can be accommodated in s | |
14417 | as a string value, and copies them to s. The read result | |
14418 | is set to the value allRight, endOfLine, or endOfInput. | |
14419 | *) | |
14420 | ||
14421 | @findex ReadToken | |
14422 | PROCEDURE ReadToken (cid: IOChan.ChanId; VAR s: ARRAY OF CHAR); | |
14423 | (* Skips leading spaces, and then removes characters from | |
14424 | the input stream cid before the next space or line mark, | |
14425 | copying to s as many as can be accommodated as a string | |
14426 | value. The read result is set to the value allRight, | |
14427 | outOfRange, endOfLine, or endOfInput. | |
14428 | *) | |
14429 | ||
14430 | (* The following procedure reads past the next line mark *) | |
14431 | ||
14432 | @findex SkipLine | |
14433 | PROCEDURE SkipLine (cid: IOChan.ChanId); | |
14434 | (* Removes successive items from the input stream cid up | |
14435 | to and including the next line mark, or until the end | |
14436 | of input is reached. The read result is set to the | |
14437 | value allRight, or endOfInput. | |
14438 | *) | |
14439 | ||
14440 | (* Output procedures *) | |
14441 | ||
14442 | @findex WriteChar | |
14443 | PROCEDURE WriteChar (cid: IOChan.ChanId; ch: CHAR); | |
14444 | (* Writes the value of ch to the output stream cid. *) | |
14445 | ||
14446 | @findex WriteLn | |
14447 | PROCEDURE WriteLn (cid: IOChan.ChanId); | |
14448 | (* Writes a line mark to the output stream cid. *) | |
14449 | ||
14450 | @findex WriteString | |
14451 | PROCEDURE WriteString (cid: IOChan.ChanId; s: ARRAY OF CHAR); | |
14452 | (* Writes the string value in s to the output stream cid. *) | |
14453 | ||
14454 | END TextIO. | |
14455 | ||
14456 | @end example | |
14457 | @page | |
14458 | ||
14459 | @node gm2-libs-iso/WholeConv, gm2-libs-iso/WholeIO, gm2-libs-iso/TextIO, M2 ISO Libraries | |
14460 | @subsection gm2-libs-iso/WholeConv | |
14461 | ||
14462 | @example | |
14463 | DEFINITION MODULE WholeConv; | |
14464 | ||
14465 | (* Low-level whole-number/string conversions *) | |
14466 | ||
14467 | IMPORT | |
14468 | ConvTypes; | |
14469 | ||
14470 | TYPE | |
14471 | @findex ConvResults (type) | |
14472 | ConvResults = ConvTypes.ConvResults; | |
14473 | (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) | |
14474 | ||
14475 | @findex ScanInt | |
14476 | PROCEDURE ScanInt (inputCh: CHAR; | |
14477 | VAR chClass: ConvTypes.ScanClass; | |
14478 | VAR nextState: ConvTypes.ScanState) ; | |
14479 | (* Represents the start state of a finite state scanner for signed | |
14480 | whole numbers - assigns class of inputCh to chClass and a | |
14481 | procedure representing the next state to nextState. | |
14482 | *) | |
14483 | ||
14484 | @findex FormatInt | |
14485 | PROCEDURE FormatInt (str: ARRAY OF CHAR): ConvResults; | |
14486 | (* Returns the format of the string value for conversion to INTEGER. *) | |
14487 | ||
14488 | @findex ValueInt | |
14489 | PROCEDURE ValueInt (str: ARRAY OF CHAR): INTEGER; | |
14490 | (* Returns the value corresponding to the signed whole number string | |
14491 | value str if str is well-formed; otherwise raises the WholeConv | |
14492 | exception. | |
14493 | *) | |
14494 | ||
14495 | @findex LengthInt | |
14496 | PROCEDURE LengthInt (int: INTEGER): CARDINAL; | |
14497 | (* Returns the number of characters in the string representation of | |
14498 | int. | |
14499 | *) | |
14500 | ||
14501 | @findex ScanCard | |
14502 | PROCEDURE ScanCard (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass; | |
14503 | VAR nextState: ConvTypes.ScanState); | |
14504 | (* Represents the start state of a finite state scanner for unsigned | |
14505 | whole numbers - assigns class of inputCh to chClass and a procedure | |
14506 | representing the next state to nextState. | |
14507 | *) | |
14508 | ||
14509 | @findex FormatCard | |
14510 | PROCEDURE FormatCard (str: ARRAY OF CHAR): ConvResults; | |
14511 | (* Returns the format of the string value for conversion to CARDINAL. | |
14512 | *) | |
14513 | ||
14514 | @findex ValueCard | |
14515 | PROCEDURE ValueCard (str: ARRAY OF CHAR): CARDINAL; | |
14516 | (* Returns the value corresponding to the unsigned whole number string | |
14517 | value str if str is well-formed; otherwise raises the WholeConv | |
14518 | exception. | |
14519 | *) | |
14520 | ||
14521 | @findex LengthCard | |
14522 | PROCEDURE LengthCard (card: CARDINAL): CARDINAL; | |
14523 | (* Returns the number of characters in the string representation of | |
14524 | card. | |
14525 | *) | |
14526 | ||
14527 | @findex IsWholeConvException | |
14528 | PROCEDURE IsWholeConvException (): BOOLEAN; | |
14529 | (* Returns TRUE if the current coroutine is in the exceptional execution | |
14530 | state because of the raising of an exception in a routine from this | |
14531 | module; otherwise returns FALSE. | |
14532 | *) | |
14533 | ||
14534 | END WholeConv. | |
14535 | @end example | |
14536 | @page | |
14537 | ||
14538 | @node gm2-libs-iso/WholeIO, gm2-libs-iso/WholeStr, gm2-libs-iso/WholeConv, M2 ISO Libraries | |
14539 | @subsection gm2-libs-iso/WholeIO | |
14540 | ||
14541 | @example | |
14542 | DEFINITION MODULE WholeIO; | |
14543 | ||
14544 | (* Input and output of whole numbers in decimal text form | |
14545 | over specified channels. The read result is of the | |
14546 | type IOConsts.ReadResults. | |
14547 | *) | |
14548 | ||
14549 | IMPORT IOChan; | |
14550 | ||
14551 | (* The text form of a signed whole number is | |
14552 | ["+" | "-"], decimal digit, @{decimal digit@} | |
14553 | ||
14554 | The text form of an unsigned whole number is | |
14555 | decimal digit, @{decimal digit@} | |
14556 | *) | |
14557 | ||
14558 | @findex ReadInt | |
14559 | PROCEDURE ReadInt (cid: IOChan.ChanId; VAR int: INTEGER); | |
14560 | (* Skips leading spaces, and removes any remaining characters | |
14561 | from cid that form part of a signed whole number. The | |
14562 | value of this number is assigned to int. The read result | |
14563 | is set to the value allRight, outOfRange, wrongFormat, | |
14564 | endOfLine, or endOfInput. | |
14565 | *) | |
14566 | ||
14567 | @findex WriteInt | |
14568 | PROCEDURE WriteInt (cid: IOChan.ChanId; int: INTEGER; | |
14569 | width: CARDINAL); | |
14570 | (* Writes the value of int to cid in text form, in a field of | |
14571 | the given minimum width. *) | |
14572 | ||
14573 | @findex ReadCard | |
14574 | PROCEDURE ReadCard (cid: IOChan.ChanId; VAR card: CARDINAL); | |
14575 | (* Skips leading spaces, and removes any remaining characters | |
14576 | from cid that form part of an unsigned whole number. The | |
14577 | value of this number is assigned to card. The read result | |
14578 | is set to the value allRight, outOfRange, wrongFormat, | |
14579 | endOfLine, or endOfInput. | |
14580 | *) | |
14581 | ||
14582 | @findex WriteCard | |
14583 | PROCEDURE WriteCard (cid: IOChan.ChanId; card: CARDINAL; | |
14584 | width: CARDINAL); | |
14585 | (* Writes the value of card to cid in text form, in a field | |
14586 | of the given minimum width. *) | |
14587 | ||
14588 | END WholeIO. | |
14589 | @end example | |
14590 | @page | |
14591 | ||
14592 | @node gm2-libs-iso/WholeStr, gm2-libs-iso/wrapsock, gm2-libs-iso/WholeIO, M2 ISO Libraries | |
14593 | @subsection gm2-libs-iso/WholeStr | |
14594 | ||
14595 | @example | |
14596 | DEFINITION MODULE WholeStr; | |
14597 | ||
14598 | (* Whole-number/string conversions *) | |
14599 | ||
14600 | IMPORT | |
14601 | ConvTypes; | |
14602 | ||
14603 | TYPE | |
14604 | @findex ConvResults (type) | |
14605 | ConvResults = ConvTypes.ConvResults; | |
14606 | (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) | |
14607 | ||
14608 | (* the string form of a signed whole number is | |
14609 | ["+" | "-"], decimal digit, @{decimal digit@} | |
14610 | *) | |
14611 | ||
14612 | @findex StrToInt | |
14613 | PROCEDURE StrToInt (str: ARRAY OF CHAR; VAR int: INTEGER; | |
14614 | VAR res: ConvResults); | |
14615 | (* Ignores any leading spaces in str. If the subsequent | |
14616 | characters in str are in the format of a signed whole | |
14617 | number, assigns a corresponding value to int. Assigns | |
14618 | a value indicating the format of str to res. | |
14619 | *) | |
14620 | ||
14621 | @findex IntToStr | |
14622 | PROCEDURE IntToStr (int: INTEGER; VAR str: ARRAY OF CHAR); | |
14623 | (* Converts the value of int to string form and copies the | |
14624 | possibly truncated result to str. *) | |
14625 | ||
14626 | (* the string form of an unsigned whole number is | |
14627 | decimal digit, @{decimal digit@} | |
14628 | *) | |
14629 | ||
14630 | @findex StrToCard | |
14631 | PROCEDURE StrToCard (str: ARRAY OF CHAR; | |
14632 | VAR card: CARDINAL; | |
14633 | VAR res: ConvResults); | |
14634 | (* Ignores any leading spaces in str. If the subsequent | |
14635 | characters in str are in the format of an unsigned | |
14636 | whole number, assigns a corresponding value to card. | |
14637 | Assigns a value indicating the format of str to res. | |
14638 | *) | |
14639 | ||
14640 | @findex CardToStr | |
14641 | PROCEDURE CardToStr (card: CARDINAL; VAR str: ARRAY OF CHAR); | |
14642 | (* Converts the value of card to string form and copies the | |
14643 | possibly truncated result to str. *) | |
14644 | ||
14645 | END WholeStr. | |
14646 | @end example | |
14647 | @page | |
14648 | ||
14649 | @node gm2-libs-iso/wrapsock, gm2-libs-iso/wraptime, gm2-libs-iso/WholeStr, M2 ISO Libraries | |
14650 | @subsection gm2-libs-iso/wrapsock | |
14651 | ||
14652 | @example | |
14653 | DEFINITION MODULE wrapsock ; | |
14654 | ||
14655 | (* | |
14656 | Description: provides a set of wrappers to some client side | |
14657 | tcp socket primatives. | |
14658 | *) | |
14659 | ||
14660 | FROM SYSTEM IMPORT ADDRESS ; | |
14661 | FROM ChanConsts IMPORT OpenResults ; | |
14662 | ||
14663 | ||
14664 | TYPE | |
14665 | @findex clientInfo (type) | |
14666 | clientInfo = ADDRESS ; | |
14667 | ||
14668 | ||
14669 | (* | |
14670 | clientOpen - returns an ISO Modula-2 OpenResult. | |
14671 | It attempts to connect to: hostname:portNo. | |
14672 | If successful then the data structure, c, | |
14673 | will have its fields initialized. | |
14674 | *) | |
14675 | ||
14676 | @findex clientOpen | |
14677 | PROCEDURE clientOpen (c: clientInfo; | |
14678 | hostname: ADDRESS; | |
14679 | length: CARDINAL; | |
14680 | portNo: CARDINAL) : OpenResults ; | |
14681 | ||
14682 | ||
14683 | (* | |
14684 | clientOpenIP - returns an ISO Modula-2 OpenResult. | |
14685 | It attempts to connect to: ipaddress:portNo. | |
14686 | If successful then the data structure, c, | |
14687 | will have its fields initialized. | |
14688 | *) | |
14689 | ||
14690 | @findex clientOpenIP | |
14691 | PROCEDURE clientOpenIP (c: clientInfo; | |
14692 | ip: CARDINAL; | |
14693 | portNo: CARDINAL) : OpenResults ; | |
14694 | ||
14695 | ||
14696 | (* | |
14697 | getClientPortNo - returns the portNo from structure, c. | |
14698 | *) | |
14699 | ||
14700 | @findex getClientPortNo | |
14701 | PROCEDURE getClientPortNo (c: clientInfo) : CARDINAL ; | |
14702 | ||
14703 | ||
14704 | (* | |
14705 | getClientHostname - fills in the hostname of the server | |
14706 | the to which the client is connecting. | |
14707 | *) | |
14708 | ||
14709 | @findex getClientHostname | |
14710 | PROCEDURE getClientHostname (c: clientInfo; | |
14711 | hostname: ADDRESS; high: CARDINAL) ; | |
14712 | ||
14713 | ||
14714 | (* | |
14715 | getClientSocketFd - returns the sockFd from structure, c. | |
14716 | *) | |
14717 | ||
14718 | @findex getClientSocketFd | |
14719 | PROCEDURE getClientSocketFd (c: clientInfo) : INTEGER ; | |
14720 | ||
14721 | ||
14722 | (* | |
14723 | getClientIP - returns the sockFd from structure, s. | |
14724 | *) | |
14725 | ||
14726 | @findex getClientIP | |
14727 | PROCEDURE getClientIP (c: clientInfo) : CARDINAL ; | |
14728 | ||
14729 | ||
14730 | (* | |
14731 | getPushBackChar - returns TRUE if a pushed back character | |
14732 | is available. | |
14733 | *) | |
14734 | ||
14735 | @findex getPushBackChar | |
14736 | PROCEDURE getPushBackChar (c: clientInfo; VAR ch: CHAR) : BOOLEAN ; | |
14737 | ||
14738 | ||
14739 | (* | |
14740 | setPushBackChar - returns TRUE if it is able to push back a | |
14741 | character. | |
14742 | *) | |
14743 | ||
14744 | @findex setPushBackChar | |
14745 | PROCEDURE setPushBackChar (c: clientInfo; ch: CHAR) : BOOLEAN ; | |
14746 | ||
14747 | ||
14748 | (* | |
14749 | getSizeOfClientInfo - returns the sizeof (opaque data type). | |
14750 | *) | |
14751 | ||
14752 | @findex getSizeOfClientInfo | |
14753 | PROCEDURE getSizeOfClientInfo () : CARDINAL ; | |
14754 | ||
14755 | ||
14756 | END wrapsock. | |
14757 | @end example | |
14758 | @page | |
14759 | ||
14760 | @node gm2-libs-iso/wraptime, , gm2-libs-iso/wrapsock, M2 ISO Libraries | |
14761 | @subsection gm2-libs-iso/wraptime | |
14762 | ||
14763 | @example | |
14764 | DEFINITION MODULE wraptime ; | |
14765 | ||
14766 | (* | |
14767 | Description: provides an interface to various time related | |
14768 | entities on the underlying host operating system. | |
14769 | It provides access to the glibc/libc functions: | |
14770 | gettimeofday, settimeofday and localtime_r. | |
14771 | *) | |
14772 | ||
14773 | FROM SYSTEM IMPORT ADDRESS ; | |
14774 | ||
14775 | TYPE | |
14776 | @findex timeval (type) | |
14777 | timeval = ADDRESS ; | |
14778 | @findex timezone (type) | |
14779 | timezone = ADDRESS ; | |
14780 | @findex tm (type) | |
14781 | tm = ADDRESS ; | |
14782 | ||
14783 | ||
14784 | (* | |
14785 | InitTimeval - returns a newly created opaque type. | |
14786 | *) | |
14787 | ||
14788 | @findex InitTimeval | |
14789 | PROCEDURE InitTimeval () : timeval ; | |
14790 | ||
14791 | ||
14792 | (* | |
14793 | KillTimeval - deallocates the memory associated with an | |
14794 | opaque type. | |
14795 | *) | |
14796 | ||
14797 | @findex KillTimeval | |
14798 | PROCEDURE KillTimeval (tv: timeval) : timeval ; | |
14799 | ||
14800 | ||
14801 | (* | |
14802 | InitTimezone - returns a newly created opaque type. | |
14803 | *) | |
14804 | ||
14805 | @findex InitTimezone | |
14806 | PROCEDURE InitTimezone () : timezone ; | |
14807 | ||
14808 | ||
14809 | (* | |
14810 | KillTimezone - deallocates the memory associated with an | |
14811 | opaque type. | |
14812 | *) | |
14813 | ||
14814 | @findex KillTimezone | |
14815 | PROCEDURE KillTimezone (tv: timezone) : timezone ; | |
14816 | ||
14817 | ||
14818 | (* | |
14819 | InitTM - returns a newly created opaque type. | |
14820 | *) | |
14821 | ||
14822 | @findex InitTM | |
14823 | PROCEDURE InitTM () : tm ; | |
14824 | ||
14825 | ||
14826 | (* | |
14827 | KillTM - deallocates the memory associated with an | |
14828 | opaque type. | |
14829 | *) | |
14830 | ||
14831 | @findex KillTM | |
14832 | PROCEDURE KillTM (tv: tm) : tm ; | |
14833 | ||
14834 | ||
14835 | (* | |
14836 | gettimeofday - calls gettimeofday(2) with the same parameters, tv, | |
14837 | and, tz. It returns 0 on success. | |
14838 | *) | |
14839 | ||
14840 | @findex gettimeofday | |
14841 | PROCEDURE gettimeofday (tv: timeval; tz: timezone) : INTEGER ; | |
14842 | ||
14843 | ||
14844 | (* | |
14845 | settimeofday - calls settimeofday(2) with the same parameters, tv, | |
14846 | and, tz. It returns 0 on success. | |
14847 | *) | |
14848 | ||
14849 | @findex settimeofday | |
14850 | PROCEDURE settimeofday (tv: timeval; tz: timezone) : INTEGER ; | |
14851 | ||
14852 | ||
14853 | (* | |
14854 | GetFractions - returns the tv_usec field inside the timeval structure | |
14855 | as a CARDINAL. | |
14856 | *) | |
14857 | ||
14858 | @findex GetFractions | |
14859 | PROCEDURE GetFractions (tv: timeval) : CARDINAL ; | |
14860 | ||
14861 | ||
14862 | (* | |
14863 | localtime_r - returns the tm parameter, m, after it has been assigned with | |
14864 | appropriate contents determined by, tv. Notice that | |
14865 | this procedure function expects, timeval, as its first | |
14866 | parameter and not a time_t (as expected by the posix | |
14867 | equivalent). This avoids having to expose a time_t | |
14868 | system dependant definition. | |
14869 | *) | |
14870 | ||
14871 | @findex localtime_r | |
14872 | PROCEDURE localtime_r (tv: timeval; m: tm) : tm ; | |
14873 | ||
14874 | ||
14875 | (* | |
14876 | GetYear - returns the year from the structure, m. | |
14877 | *) | |
14878 | ||
14879 | @findex GetYear | |
14880 | PROCEDURE GetYear (m: tm) : CARDINAL ; | |
14881 | ||
14882 | ||
14883 | (* | |
14884 | GetMonth - returns the month from the structure, m. | |
14885 | *) | |
14886 | ||
14887 | @findex GetMonth | |
14888 | PROCEDURE GetMonth (m: tm) : CARDINAL ; | |
14889 | ||
14890 | ||
14891 | (* | |
14892 | GetDay - returns the day of the month from the structure, m. | |
14893 | *) | |
14894 | ||
14895 | @findex GetDay | |
14896 | PROCEDURE GetDay (m: tm) : CARDINAL ; | |
14897 | ||
14898 | ||
14899 | (* | |
14900 | GetHour - returns the hour of the day from the structure, m. | |
14901 | *) | |
14902 | ||
14903 | @findex GetHour | |
14904 | PROCEDURE GetHour (m: tm) : CARDINAL ; | |
14905 | ||
14906 | ||
14907 | (* | |
14908 | GetMinute - returns the minute within the hour from the structure, m. | |
14909 | *) | |
14910 | ||
14911 | @findex GetMinute | |
14912 | PROCEDURE GetMinute (m: tm) : CARDINAL ; | |
14913 | ||
14914 | ||
14915 | (* | |
14916 | GetSecond - returns the seconds in the minute from the structure, m. | |
14917 | The return value will always be in the range 0..59. | |
14918 | A leap minute of value 60 will be truncated to 59. | |
14919 | *) | |
14920 | ||
14921 | @findex GetSecond | |
14922 | PROCEDURE GetSecond (m: tm) : CARDINAL ; | |
14923 | ||
14924 | ||
14925 | (* | |
14926 | GetSummerTime - returns a boolean indicating whether summer time is | |
14927 | set. | |
14928 | *) | |
14929 | ||
14930 | @findex GetSummerTime | |
14931 | PROCEDURE GetSummerTime (tz: timezone) : BOOLEAN ; | |
14932 | ||
14933 | ||
14934 | (* | |
14935 | GetDST - returns the number of minutes west of GMT. | |
14936 | *) | |
14937 | ||
14938 | @findex GetDST | |
14939 | PROCEDURE GetDST (tz: timezone) : INTEGER ; | |
14940 | ||
14941 | ||
14942 | (* | |
14943 | SetTimeval - sets the fields in timeval, tv, with: | |
14944 | second, minute, hour, day, month, year, fractions. | |
14945 | *) | |
14946 | ||
14947 | @findex SetTimeval | |
14948 | PROCEDURE SetTimeval (tv: timeval; | |
14949 | second, minute, hour, day, | |
14950 | month, year, yday, wday, isdst: CARDINAL) ; | |
14951 | ||
14952 | ||
14953 | (* | |
14954 | SetTimezone - set the timezone field inside timeval, tv. | |
14955 | *) | |
14956 | ||
14957 | @findex SetTimezone | |
14958 | PROCEDURE SetTimezone (tv: timeval; | |
14959 | zone: CARDINAL; minuteswest: INTEGER) ; | |
14960 | ||
14961 | ||
14962 | END wraptime. | |
14963 | @end example | |
14964 | @page | |
14965 | ||
14966 | ||
14967 | @c ------------------------------------------------------------ |