fix O_STLIM to use library function STLIM
[unix-history] / usr / src / usr.bin / pascal / px / utilities.c
CommitLineData
e0f018be
KM
1/* Copyright (c) 1979 Regents of the University of California */
2
15834a19 3static char sccsid[] = "@(#)utilities.c 1.2 %G%";
e0f018be
KM
4
5#include "vars.h"
6#include "panics.h"
7#include "h02opcs.h"
8
9stats()
10{
11 struct {
12 long usr_time;
13 long sys_time;
14 long child_usr_time;
15 long child_sys_time;
15834a19 16 } tbuf;
e0f018be
KM
17 register double l;
18 register long count;
15834a19
KM
19# ifdef PROFILE
20# define proffile "/vb/grad/mckusick/px/profile/pcnt.out"
21 struct cntrec {
22 double counts[NUMOPS]; /* instruction counts */
23 long runs; /* number of interpreter runs */
24 long startdate; /* date profile started */
25 long usrtime; /* total user time consumed */
26 long systime; /* total system time consumed */
27 double stmts; /* number of pascal stmts executed */
28 } profdata;
29 FILE *datafile;
30# endif PROFILE
e0f018be
KM
31
32 if (_nodump)
33 return(0);
34 times(&tbuf);
15834a19 35# ifdef PROFILE
e0f018be 36 datafile = fopen(proffile,"r");
15834a19
KM
37 if (datafile == NULL)
38 goto skipprof;
39 count = fread(&profdata,1,sizeof(profdata),datafile);
40 if (count != sizeof(profdata))
41 goto skipprof;
42 for (count = 0; count < NUMOPS; count++)
43 profdata.counts[count] += _profcnts[count];
44 profdata.runs += 1;
45 profdata.stmts += _stcnt;
46 profdata.usrtime += tbuf.usr_time;
47 profdata.systime += tbuf.sys_time;
48 datafile = freopen(proffile,"w",datafile);
49 if (datafile == NULL)
50 goto skipprof;
51 count = fwrite(&profdata,1,sizeof(profdata),datafile);
52 if (count != sizeof(profdata))
53 goto skipprof;
54 fclose(datafile);
55skipprof:
56# endif PROFILE
e0f018be
KM
57 l = tbuf.usr_time;
58 l = l / HZ;
59 fprintf(stderr,
60 "\n%1ld statements executed in %04.2f seconds cpu time.\n",
61 _stcnt,l);
62}
63\f
64backtrace(errnum)
65 long errnum;
66{
67 register struct disp *mydp;
68 register struct stack *ap;
69 register char *cp;
70 register long i, linum;
15834a19 71 struct disply disp;
e0f018be
KM
72
73 if (_lino <= 0) {
74 fputs("Program was not executed.\n",stderr);
75 return;
76 }
15834a19 77 disp = _display;
e0f018be
KM
78 if (errnum == PINTR)
79 fputs("\n\tInterrupted in \"",stderr);
80 else if (errnum == PHALT)
81 fputs("\n\tHalted in \"",stderr);
82 else
83 fputs("\n\tError in \"",stderr);
84 mydp = _dp;
85 linum = _lino;
86 for (;;) {
87 ap = mydp->stp;
88 i = linum - (((ap)->entry)->offset & 0177777);
89 fprintf(stderr,"%s\"",(ap->entry)->name);
90 if (_nodump == 0)
91 fprintf(stderr,"+%1d near line %1d.",i,linum);
92 fputc('\n',stderr);
93 *mydp = (ap)->odisp;
15834a19
KM
94 if (mydp <= &_display.frame[1]){
95 _display = disp;
e0f018be
KM
96 psexit(errnum);
97 }
98 mydp = (ap)->dp;
99 linum = (ap)->lino;
100 fputs("\tCalled by \"",stderr);
101 }
102}
103\f
104psexit(code)
105
106 long code;
107{
108 if (_pcpcount != 0)
109 PMFLUSH(_cntrs, _rtns, _pcpcount);
110 if (_mode == PIX) {
111 fputs("Execution terminated",stderr);
112 if (code)
113 fputs(" abnormally",stderr);
114 fputc('.',stderr);
115 fputc('\n',stderr);
116 }
117 stats();
118 exit(code);
119}