Debian Codegraph @

utils/m-tx/mtx-src/libp2c/p2clib.c

raw
1
2 /* Run-time library for use with "p2c", the Pascal to C translator */
3
4 /* "p2c" Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation.
5 * By Dave Gillespie, [email protected]. Version --VERSION--.
6 * This file may be copied, modified, etc. in any way. It is not restricted
7 * by the licence agreement accompanying p2c itself.
8 */
9
10
11
12 #include "p2c.h"
13
14
15 #ifndef NO_TIME
16 # include <time.h>
17 #endif
18
19
20 #define Isspace(c) isspace(c) /* or "((c) == ' ')" if preferred */
21
22
23
24
25 int P_argc;
26 char **P_argv;
27
28 short P_escapecode;
29 int P_ioresult;
30
31 long EXCP_LINE; /* Used by Pascal workstation system */
32
33 Anyptr __MallocTemp__;
34
35 __p2c_jmp_buf *__top_jb;
36
37
38
39
40 void PASCAL_MAIN(argc, argv)
41 int argc;
42 char **argv;
43 {
44 P_argc = argc;
45 P_argv = argv;
46 __top_jb = NULL;
47
48 #ifdef LOCAL_INIT
49 LOCAL_INIT();
50 #endif
51 }
52
53
54
55
56
57 /* In case your system lacks these... */
58
59 long my_labs(x)
60 long x;
61 {
62 return((x > 0) ? x : -x);
63 }
64
65
66 #ifdef __STDC__
67 Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n)
68 #else
69 Anyptr my_memmove(d, s, n)
70 Anyptr d, s;
71 register int n;
72 #endif
73 {
74 register char *dd = (char *)d, *ss = (char *)s;
75 if (dd < ss || dd - ss >= n) {
76 #if defined(bcopy) && defined(memcpy)
77 Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n);
78 #else
79 memcpy(dd, ss, n);
80 #endif
81 } else if (n > 0) {
82 dd += n;
83 ss += n;
84 while (n-- > 0)
85 *--dd = *--ss;
86 }
87 return d;
88 }
89
90 #ifdef __STDC__
91 Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n)
92 #else
93 Anyptr my_memcpy(d, s, n)
94 Anyptr d, s;
95 register int n;
96 #endif
97 {
98 register char *ss = (char *)s, *dd = (char *)d;
99 while (n-- > 0)
100 *dd++ = *ss++;
101 return d;
102 }
103
104
105 #ifdef __STDC__
106 int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n)
107 #else
108 int my_memcmp(s1, s2, n)
109 Anyptr s1, s2;
110 register int n;
111 #endif
112 {
113 register char *a = (char *)s1, *b = (char *)s2;
114 register int i;
115 while (n-- > 0)
116 if ((i = (*a++) - (*b++)) != 0)
117 return i;
118 return 0;
119 }
120
121 #ifdef __STDC__
122 Anyptr my_memset(Anyptr d, int c, size_t n)
123 #else
124 Anyptr my_memset(d, c, n)
125 Anyptr d;
126 register int c;
127 register int n;
128 #endif
129 {
130 register char *dd = (char *)d;
131 while (n-- > 0)
132 *dd++ = c;
133 return d;
134 }
135
136
137 int my_toupper(c)
138 int c;
139 {
140 if (islower(c))
141 return _toupper(c);
142 else
143 return c;
144 }
145
146
147 int my_tolower(c)
148 int c;
149 {
150 if (isupper(c))
151 return _tolower(c);
152 else
153 return c;
154 }
155
156
157
158
159 long ipow(a, b)
160 long a, b;
161 {
162 long v;
163
164 if (a == 0 || a == 1)
165 return a;
166 if (a == -1)
167 return (b & 1) ? -1 : 1;
168 if (b < 0)
169 return 0;
170 if (a == 2)
171 return 1L << b;
172 v = (b & 1) ? a : 1;
173 while ((b >>= 1) > 0) {
174 a *= a;
175 if (b & 1)
176 v *= a;
177 }
178 return v;
179 }
180
181
182 long P_imax(a, b)
183 long a, b;
184 {
185 if (a > b)
186 return a;
187 else
188 return b;
189 }
190
191 long P_imin(a, b)
192 long a, b;
193 {
194 if (a < b)
195 return a;
196 else
197 return b;
198 }
199
200
201 double P_rmax(a, b)
202 double a, b;
203 {
204 if (a > b)
205 return a;
206 else
207 return b;
208 }
209
210 double P_rmin(a, b)
211 double a, b;
212 {
213 if (a < b)
214 return a;
215 else
216 return b;
217 }
218
219
220
221
222 /* Common string functions: */
223
224 /* Store in "ret" the substring of length "len" starting from "pos" (1-based).
225 Store a shorter or null string if out-of-range. Return "ret". */
226
227 char *strsub(ret, s, pos, len)
228 register char *ret, *s;
229 register int pos, len;
230 {
231 register char *s2;
232
233 if (--pos < 0 || len <= 0) {
234 *ret = 0;
235 return ret;
236 }
237 while (pos > 0) {
238 if (!*s++) {
239 *ret = 0;
240 return ret;
241 }
242 pos--;
243 }
244 s2 = ret;
245 while (--len >= 0) {
246 if (!(*s2++ = *s++))
247 return ret;
248 }
249 *s2 = 0;
250 return ret;
251 }
252
253
254 /* Return the index of the first occurrence of "pat" as a substring of "s",
255 starting at index "pos" (1-based). Result is 1-based, 0 if not found. */
256
257 int strpos2(s, pat, pos)
258 char *s;
259 register char *pat;
260 register int pos;
261 {
262 register char *cp, ch;
263 register int slen;
264
265 if (--pos < 0)
266 return 0;
267 slen = strlen(s) - pos;
268 cp = s + pos;
269 if (!(ch = *pat++))
270 return 0;
271 pos = strlen(pat);
272 slen -= pos;
273 while (--slen >= 0) {
274 if (*cp++ == ch && !strncmp(cp, pat, pos))
275 return cp - s;
276 }
277 return 0;
278 }
279
280
281 /* Case-insensitive version of strcmp. */
282
283 int strcicmp(s1, s2)
284 register char *s1, *s2;
285 {
286 register unsigned char c1, c2;
287
288 while (*s1) {
289 if (*s1++ != *s2++) {
290 if (!s2[-1])
291 return 1;
292 c1 = toupper(s1[-1]);
293 c2 = toupper(s2[-1]);
294 if (c1 != c2)
295 return c1 - c2;
296 }
297 }
298 if (*s2)
299 return -1;
300 return 0;
301 }
302
303
304
305
306 /* HP and Turbo Pascal string functions: */
307
308 /* Trim blanks at left end of string. */
309
310 char *strltrim(s)
311 register char *s;
312 {
313 while (Isspace(*s++)) ;
314 return s - 1;
315 }
316
317
318 /* Trim blanks at right end of string. */
319
320 char *strrtrim(s)
321 register char *s;
322 {
323 register char *s2 = s;
324
325 if (!*s)
326 return s;
327 while (*++s2) ;
328 while (s2 > s && Isspace(*--s2))
329 *s2 = 0;
330 return s;
331 }
332
333
334 /* Store in "ret" "num" copies of string "s". Return "ret". */
335
336 char *strrpt(ret, s, num)
337 char *ret;
338 register char *s;
339 register int num;
340 {
341 register char *s2 = ret;
342 register char *s1;
343
344 while (--num >= 0) {
345 s1 = s;
346 while ((*s2++ = *s1++)) ;
347 s2--;
348 }
349 return ret;
350 }
351
352
353 /* Store in "ret" string "s" with enough pad chars added to reach "size". */
354
355 char *strpad(ret, s, padchar, num)
356 char *ret;
357 register char *s;
358 register int padchar, num;
359 {
360 register char *d = ret;
361
362 if (s == d) {
363 while (*d++) ;
364 } else {
365 while ((*d++ = *s++)) ;
366 }
367 num -= (--d - ret);
368 while (--num >= 0)
369 *d++ = padchar;
370 *d = 0;
371 return ret;
372 }
373
374
375 /* Copy the substring of length "len" from index "spos" of "s" (1-based)
376 to index "dpos" of "d", lengthening "d" if necessary. Length and
377 indices must be in-range. */
378
379 void strmove(len, s, spos, d, dpos)
380 register char *s, *d;
381 register int len, spos, dpos;
382 {
383 s += spos - 1;
384 d += dpos - 1;
385 while (*d && --len >= 0)
386 *d++ = *s++;
387 if (len > 0) {
388 while (--len >= 0)
389 *d++ = *s++;
390 *d = 0;
391 }
392 }
393
394
395 /* Delete the substring of length "len" at index "pos" from "s".
396 Delete less if out-of-range. */
397
398 void strdelete(s, pos, len)
399 register char *s;
400 register int pos, len;
401 {
402 register int slen;
403
404 if (--pos < 0)
405 return;
406 slen = strlen(s) - pos;
407 if (slen <= 0)
408 return;
409 s += pos;
410 if (slen <= len) {
411 *s = 0;
412 return;
413 }
414 while ((*s = s[len])) s++;
415 }
416
417
418 /* Insert string "src" at index "pos" of "dst". */
419
420 void strinsert(src, dst, pos)
421 register char *src, *dst;
422 register int pos;
423 {
424 register int slen, dlen;
425
426 if (--pos < 0)
427 return;
428 dlen = strlen(dst);
429 dst += dlen;
430 dlen -= pos;
431 if (dlen <= 0) {
432 strcpy(dst, src);
433 return;
434 }
435 slen = strlen(src);
436 do {
437 dst[slen] = *dst;
438 --dst;
439 } while (--dlen >= 0);
440 dst++;
441 while (--slen >= 0)
442 *dst++ = *src++;
443 }
444
445
446
447
448 /* File functions */
449
450 /* Peek at next character of input stream; return EOF at end-of-file. */
451
452 int P_peek(f)
453 FILE *f;
454 {
455 int ch;
456
457 ch = getc(f);
458 if (ch == EOF)
459 return EOF;
460 ungetc(ch, f);
461 return (ch == '\n') ? ' ' : ch;
462 }
463
464
465 /* Check if at end of file, using Pascal "eof" semantics. End-of-file for
466 stdin is broken; remove the special case for it to be broken in a
467 different way. */
468
469 int P_eof(f)
470 FILE *f;
471 {
472 register int ch;
473
474 if (feof(f))
475 return 1;
476 #ifdef HAVE_ISATTY
477 if (isatty(fileno(f)))
478 #else
479 if (f == stdin)
480 #endif
481 return 0; /* not safe to look-ahead on the keyboard! */
482 ch = getc(f);
483 if (ch == EOF)
484 return 1;
485 ungetc(ch, f);
486 return 0;
487 }
488
489
490 /* Check if at end of line (or end of entire file). */
491
492 int P_eoln(f)
493 FILE *f;
494 {
495 register int ch;
496
497 ch = getc(f);
498 if (ch == EOF)
499 return 1;
500 ungetc(ch, f);
501 return (ch == '\n');
502 }
503
504
505 /* Skip whitespace (including newlines) in a file. */
506
507 FILE *_skipnlspaces(f)
508 FILE *f;
509 {
510 register int ch;
511
512 do {
513 ch = getc(f);
514 } while (ch == ' ' || ch == '\t' || ch == '\n');
515 if (ch != EOF)
516 ungetc(ch, f);
517 return f;
518 }
519
520
521 /* Skip whitespace (not including newlines) in a file. */
522
523 FILE *_skipspaces(f)
524 FILE *f;
525 {
526 register int ch;
527
528 do {
529 ch = getc(f);
530 } while (ch == ' ' || ch == '\t');
531 if (ch != EOF)
532 ungetc(ch, f);
533 return f;
534 }
535
536
537 /* Read a packed array of characters from a file. */
538
539 Void P_readpaoc(f, s, len)
540 FILE *f;
541 char *s;
542 int len;
543 {
544 int ch;
545
546 for (;;) {
547 if (len <= 0)
548 return;
549 ch = getc(f);
550 if (ch == EOF || ch == '\n')
551 break;
552 *s++ = ch;
553 --len;
554 }
555 while (--len >= 0)
556 *s++ = ' ';
557 if (ch != EOF)
558 ungetc(ch, f);
559 }
560
561 Void P_readlnpaoc(f, s, len)
562 FILE *f;
563 char *s;
564 int len;
565 {
566 int ch;
567
568 for (;;) {
569 ch = getc(f);
570 if (ch == EOF || ch == '\n')
571 break;
572 if (len > 0) {
573 *s++ = ch;
574 --len;
575 }
576 }
577 while (--len >= 0)
578 *s++ = ' ';
579 }
580
581
582 /* Compute maximum legal "seek" index in file (0-based). */
583
584 long P_maxpos(f)
585 FILE *f;
586 {
587 long savepos = ftell(f);
588 long val;
589
590 if (fseek(f, 0L, SEEK_END))
591 return -1;
592 val = ftell(f);
593 if (fseek(f, savepos, SEEK_SET))
594 return -1;
595 return val;
596 }
597
598
599 /* Use packed array of char for a file name. */
600
601 Char *P_trimname(fn, len)
602 register Char *fn;
603 register int len;
604 {
605 static Char fnbuf[256];
606 register Char *cp = fnbuf;
607
608 while (--len >= 0 && *fn && !isspace(*fn))
609 *cp++ = *fn++;
610 *cp = 0;
611 return fnbuf;
612 }
613
614
615
616
617 /* Pascal's "memavail" doesn't make much sense in Unix with virtual memory.
618 We fix memory size as 10Meg as a reasonable compromise. */
619
620 long memavail()
621 {
622 return 10000000; /* worry about this later! */
623 }
624
625 long maxavail()
626 {
627 return memavail();
628 }
629
630
631
632
633 /* Sets are stored as an array of longs. S[0] is the size of the set;
634 S[N] is the N'th 32-bit chunk of the set. S[0] equals the maximum
635 I such that S[I] is nonzero. S[0] is zero for an empty set. Within
636 each long, bits are packed from lsb to msb. The first bit of the
637 set is the element with ordinal value 0. (Thus, for a "set of 5..99",
638 the lowest five bits of the first long are unused and always zero.) */
639
640 /* (Sets with 32 or fewer elements are normally stored as plain longs.) */
641
642 long *P_setunion(d, s1, s2) /* d := s1 + s2 */
643 register long *d, *s1, *s2;
644 {
645 long *dbase = d++;
646 register int sz1 = *s1++, sz2 = *s2++;
647 while (sz1 > 0 && sz2 > 0) {
648 *d++ = *s1++ | *s2++;
649 sz1--, sz2--;
650 }
651 while (--sz1 >= 0)
652 *d++ = *s1++;
653 while (--sz2 >= 0)
654 *d++ = *s2++;
655 *dbase = d - dbase - 1;
656 return dbase;
657 }
658
659
660 long *P_setint(d, s1, s2) /* d := s1 * s2 */
661 register long *d, *s1, *s2;
662 {
663 long *dbase = d++;
664 register int sz1 = *s1++, sz2 = *s2++;
665 while (--sz1 >= 0 && --sz2 >= 0)
666 *d++ = *s1++ & *s2++;
667 while (--d > dbase && !*d) ;
668 *dbase = d - dbase;
669 return dbase;
670 }
671
672
673 long *P_setdiff(d, s1, s2) /* d := s1 - s2 */
674 register long *d, *s1, *s2;
675 {
676 long *dbase = d++;
677 register int sz1 = *s1++, sz2 = *s2++;
678 while (--sz1 >= 0 && --sz2 >= 0)
679 *d++ = *s1++ & ~*s2++;
680 if (sz1 >= 0) {
681 while (sz1-- >= 0)
682 *d++ = *s1++;
683 }
684 while (--d > dbase && !*d) ;
685 *dbase = d - dbase;
686 return dbase;
687 }
688
689
690 long *P_setxor(d, s1, s2) /* d := s1 / s2 */
691 register long *d, *s1, *s2;
692 {
693 long *dbase = d++;
694 register int sz1 = *s1++, sz2 = *s2++;
695 while (sz1 > 0 && sz2 > 0) {
696 *d++ = *s1++ ^ *s2++;
697 sz1--, sz2--;
698 }
699 while (--sz1 >= 0)
700 *d++ = *s1++;
701 while (--sz2 >= 0)
702 *d++ = *s2++;
703 while (--d > dbase && !*d) ;
704 *dbase = d - dbase;
705 return dbase;
706 }
707
708
709 int P_inset(val, s) /* val IN s */
710 register unsigned val;
711 register long *s;
712 {
713 register int bit;
714 bit = val % SETBITS;
715 val /= SETBITS;
716 if (val < *s++ && ((1L<<bit) & s[val]))
717 return 1;
718 return 0;
719 }
720
721
722 long *P_addset(s, val) /* s := s + [val] */
723 register long *s;
724 register unsigned val;
725 {
726 register long *sbase = s;
727 register int bit, size;
728 bit = val % SETBITS;
729 val /= SETBITS;
730 size = *s;
731 if (++val > size) {
732 s += size;
733 while (val > size)
734 *++s = 0, size++;
735 *sbase = size;
736 } else
737 s += val;
738 *s |= 1L<<bit;
739 return sbase;
740 }
741
742
743 long *P_addsetr(s, v1, v2) /* s := s + [v1..v2] */
744 register long *s;
745 register unsigned v1, v2;
746 {
747 register long *sbase = s;
748 register int b1, b2, size;
749 if ((int)v1 > (int)v2)
750 return sbase;
751 b1 = v1 % SETBITS;
752 v1 /= SETBITS;
753 b2 = v2 % SETBITS;
754 v2 /= SETBITS;
755 size = *s;
756 v1++;
757 if (++v2 > size) {
758 while (v2 > size)
759 s[++size] = 0;
760 s[v2] = 0;
761 *s = v2;
762 }
763 s += v1;
764 if (v1 == v2) {
765 *s |= (~((-2L)<<(b2-b1))) << b1;
766 } else {
767 *s++ |= (-1L) << b1;
768 while (++v1 < v2)
769 *s++ = -1;
770 *s |= ~((-2L) << b2);
771 }
772 return sbase;
773 }
774
775
776 long *P_remset(s, val) /* s := s - [val] */
777 register long *s;
778 register unsigned val;
779 {
780 register int bit;
781 bit = val % SETBITS;
782 val /= SETBITS;
783 if (++val <= *s) {
784 if (!(s[val] &= ~(1L<<bit)))
785 while (*s && !s[*s])
786 (*s)--;
787 }
788 return s;
789 }
790
791
792 int P_setequal(s1, s2) /* s1 = s2 */
793 register long *s1, *s2;
794 {
795 register int size = *s1++;
796 if (*s2++ != size)
797 return 0;
798 while (--size >= 0) {
799 if (*s1++ != *s2++)
800 return 0;
801 }
802 return 1;
803 }
804
805
806 int P_subset(s1, s2) /* s1 <= s2 */
807 register long *s1, *s2;
808 {
809 register int sz1 = *s1++, sz2 = *s2++;
810 if (sz1 > sz2)
811 return 0;
812 while (--sz1 >= 0) {
813 if (*s1++ & ~*s2++)
814 return 0;
815 }
816 return 1;
817 }
818
819
820 long *P_setcpy(d, s) /* d := s */
821 register long *d, *s;
822 {
823 register long *save_d = d;
824
825 #ifdef SETCPY_MEMCPY
826 memcpy(d, s, (*s + 1) * sizeof(long));
827 #else
828 register int i = *s + 1;
829 while (--i >= 0)
830 *d++ = *s++;
831 #endif
832 return save_d;
833 }
834
835
836 /* s is a "smallset", i.e., a 32-bit or less set stored
837 directly in a long. */
838
839 long *P_expset(d, s) /* d := s */
840 register long *d;
841 register long s;
842 {
843 if (s) {
844 d[1] = s;
845 *d = 1;
846 } else
847 *d = 0;
848 return d;
849 }
850
851
852 long P_packset(s) /* convert s to a small-set */
853 register long *s;
854 {
855 if (*s++)
856 return *s;
857 else
858 return 0;
859 }
860
861
862
863
864
865 /* Oregon Software Pascal extensions, courtesy of William Bader */
866
867 int P_getcmdline(l, h, line)
868 int l, h;
869 Char *line;
870 {
871 int i, len;
872 char *s;
873
874 h = h - l + 1;
875 len = 0;
876 for(i = 1; i < P_argc; i++) {
877 s = P_argv[i];
878 while (*s) {
879 if (len >= h) return len;
880 line[len++] = *s++;
881 }
882 if (len >= h) return len;
883 line[len++] = ' ';
884 }
885 return len;
886 }
887
888 Void TimeStamp(Day, Month, Year, Hour, Min, Sec)
889 int *Day, *Month, *Year, *Hour, *Min, *Sec;
890 {
891 #ifndef NO_TIME
892 struct tm *tm;
893 long clock;
894
895 time(&clock);
896 tm = localtime(&clock);
897 *Day = tm->tm_mday;
898 *Month = tm->tm_mon + 1; /* Jan = 0 */
899 *Year = tm->tm_year;
900 if (*Year < 1900)
901 *Year += 1900; /* year since 1900 */
902 *Hour = tm->tm_hour;
903 *Min = tm->tm_min;
904 *Sec = tm->tm_sec;
905 #endif
906 }
907
908 Void VAXdate(s)
909 char *s;
910 {
911 long clock;
912 char *c;
913 int i;
914 static int where[] = {8, 9, 0, 4, 5, 6, 0, 20, 21, 22, 23};
915
916 time(&clock);
917 c = ctime(&clock);
918 for (i = 0; i < 11; i++)
919 s[i] = my_toupper(c[where[i]]);
920 s[2] = '-';
921 s[6] = '-';
922 }
923
924 Void VAXtime(s)
925 char *s;
926 {
927 long clock;
928 char *c;
929 int i;
930
931 time(&clock);
932 c = ctime(&clock);
933 for (i = 0; i < 8; i++)
934 s[i] = c[i+11];
935 s[8] = '.';
936 s[9] = '0';
937 s[10] = '0';
938 }
939
940
941
942
943 /* SUN Berkeley Pascal extensions */
944
945 Void P_sun_argv(s, len, n)
946 register char *s;
947 register int len, n;
948 {
949 register char *cp;
950
951 if ((unsigned)n < P_argc)
952 cp = P_argv[n];
953 else
954 cp = "";
955 while (*cp && --len >= 0)
956 *s++ = *cp++;
957 while (--len >= 0)
958 *s++ = ' ';
959 }
960
961
962
963
964 int _OutMem()
965 {
966 return _Escape(-2);
967 }
968
969 int _CaseCheck()
970 {
971 return _Escape(-9);
972 }
973
974 int _NilCheck()
975 {
976 return _Escape(-3);
977 }
978
979
980
981
982
983 /* The following is suitable for the HP Pascal operating system.
984 It might want to be revised when emulating another system. */
985
986 char *_ShowEscape(buf, code, ior, prefix)
987 char *buf, *prefix;
988 int code, ior;
989 {
990 char *bufp;
991
992 if (prefix && *prefix) {
993 strcpy(buf, prefix);
994 strcat(buf, ": ");
995 bufp = buf + strlen(buf);
996 } else {
997 bufp = buf;
998 }
999 if (code == -10) {
1000 sprintf(bufp, "Pascal system I/O error %d", ior);
1001 switch (ior) {
1002 case 3:
1003 strcat(buf, " (illegal I/O request)");
1004 break;
1005 case 7:
1006 strcat(buf, " (bad file name)");
1007 break;
1008 case FileNotFound: /*10*/
1009 strcat(buf, " (file not found)");
1010 break;
1011 case FileNotOpen: /*13*/
1012 strcat(buf, " (file not open)");
1013 break;
1014 case BadInputFormat: /*14*/
1015 strcat(buf, " (bad input format)");
1016 break;
1017 case 24:
1018 strcat(buf, " (not open for reading)");
1019 break;
1020 case 25:
1021 strcat(buf, " (not open for writing)");
1022 break;
1023 case 26:
1024 strcat(buf, " (not open for direct access)");
1025 break;
1026 case 28:
1027 strcat(buf, " (string subscript out of range)");
1028 break;
1029 case EndOfFile: /*30*/
1030 strcat(buf, " (end-of-file)");
1031 break;
1032 case FileWriteError: /*38*/
1033 strcat(buf, " (file write error)");
1034 break;
1035 }
1036 } else {
1037 sprintf(bufp, "Pascal system error %d", code);
1038 switch (code) {
1039 case -2:
1040 strcat(buf, " (out of memory)");
1041 break;
1042 case -3:
1043 strcat(buf, " (reference to NIL pointer)");
1044 break;
1045 case -4:
1046 strcat(buf, " (integer overflow)");
1047 break;
1048 case -5:
1049 strcat(buf, " (divide by zero)");
1050 break;
1051 case -6:
1052 strcat(buf, " (real math overflow)");
1053 break;
1054 case -8:
1055 strcat(buf, " (value range error)");
1056 break;
1057 case -9:
1058 strcat(buf, " (CASE value range error)");
1059 break;
1060 case -12:
1061 strcat(buf, " (bus error)");
1062 break;
1063 case -20:
1064 strcat(buf, " (stopped by user)");
1065 break;
1066 }
1067 }
1068 return buf;
1069 }
1070
1071
1072 int _Escape(code)
1073 int code;
1074 {
1075 char buf[100];
1076
1077 P_escapecode = code;
1078 if (__top_jb) {
1079 __p2c_jmp_buf *jb = __top_jb;
1080 __top_jb = jb->next;
1081 longjmp(jb->jbuf, 1);
1082 }
1083 if (code == 0)
1084 exit(EXIT_SUCCESS);
1085 if (code == -1)
1086 exit(EXIT_FAILURE);
1087 fprintf(stderr, "%s\n", _ShowEscape(buf, P_escapecode, P_ioresult, ""));
1088 exit(EXIT_FAILURE);
1089 }
1090
1091 int _EscIO(code)
1092 int code;
1093 {
1094 P_ioresult = code;
1095 return _Escape(-10);
1096 }
1097
1098 int _EscIO2(code, name)
1099 int code;
1100 char *name;
1101 {
1102 P_ioresult = code;
1103 if (!__top_jb && name && *name) {
1104 char buf[100];
1105 fprintf(stderr, "%s: %s\n",
1106 name, _ShowEscape(buf, P_escapecode, P_ioresult, ""));
1107 exit(EXIT_FAILURE);
1108 }
1109 return _Escape(-10);
1110 }
1111
1112
1113
1114 /* End. */
1115
1116
1117