-
Notifications
You must be signed in to change notification settings - Fork 13
/
acct.c
372 lines (312 loc) · 6.94 KB
/
acct.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/* Copyright (C) 2022 Lars Brinkhoff <lars@nocrew.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*
1975 format:
tab4: xwd j,jppn ;first entry is ppn of loser
xwd 0,k ;job number. negative means forced out
;by a reload
xwd j,jlogin ;login date/time
xwd 0,ntime ;current time
xwd j,jlin ;line number
xwd j,jtime ;ttime of job
xwd j,jkcj ;kcj of job
1978 format:
tab4: ntime ;time
tmplog ;login date/time
xwd j,jppn ;ppn of loser
tmpcpu ;incremental ttime of job
tmpkcj ;incremental kcj of job
xwd j,jldck ;load measure
tmpdsk ;incremental disk
xwd j,jname ;job name
400000,,20 ;mark the buffer
440000,,2 ;LOAD RELOAD CODE INTO B
500000,,11 ;logout header
510000,,11 ;a crash record?
540000,,11 ;a check point?
600000,,4 ;program check flag
640000,,3 ;header word for load
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "dis.h"
static const char *started = "initiated";
static void
print_timestamp (FILE *f, word_t date, word_t minutes)
{
print_dec_timestamp (f, date);
fprintf (f, " %02lld:%02lld", minutes / 60, minutes % 60);
}
static void
print_octal (word_t word)
{
if (word == -1)
{
printf (" ");
return;
}
printf (" %06llo,,%06llo", word >> 18, word & 0777777LL);
}
static void
print_sixbit (word_t word)
{
char string[7];
if (word == -1)
{
printf (" ");
return;
}
sixbit_to_ascii (word, string);
printf (" %s", string);
}
static void
print_ppn (word_t word)
{
char prj[7];
char prg[4];
sixbit_to_ascii (word, prj);
strncpy (prg, prj+3, 3);
prj[3] = 0;
prg[3] = 0;
printf ("%s,%s", prj, prg);
}
static void
print_ascii (word_t word)
{
int i;
if (word == -1)
return;
for (i = 0; i < 5; i++)
{
char c = (word >> 29) & 0177;
if (c < 32 || c == 0177)
c = '.';
putchar (c);
word <<= 7;
}
}
static void
print_header (FILE *f, word_t first)
{
word_t date, minutes;
word_t word;
int i = 1;
printf ("Accounting %s: ", started);
started = "restarted";
word = get_word (f);
i++;
date = word >> 18;
minutes = word & 07777;
print_timestamp (stdout, date, minutes);
fputs (" ", stdout);
do
{
word = get_word (f);
i++;
print_ascii (word);
}
while (word & 0376);
putchar ('\n');
printf (" PRJ,PRG Job Login Logout Line Runtime Kcticks\n");
if ((first >> 18) == 0400000)
{
for (; i < (first & 0777777); i++)
word = get_word (f);
}
}
//sys.act/12.dat/.149
//1975-05-12 00:00 Stanford 7.01/E 04-30-75.
//sys.act/30.dat/.326
//1978-05-30 00:00 SU-AI WAITS 8.70/Z Assembled 05-27-78..
//sys.act/1.dat/.327
//1978-06-01 00:03 SU-AI WAITS 8.71 Assembled 05-31-78..
//jun 1 1978
//may.txt 325
//[B,AVH] 1 2:32 0:47 1218
static void
print_trailer (FILE *f)
{
word_t date, minutes;
word_t word;
printf ("Accounting stopped: ");
word = get_word (f);
date = word >> 18;
minutes = word & 07777;
print_timestamp (stdout, date, minutes);
putchar ('\n');
}
static void
print_old_record (FILE *f, word_t word)
{
word_t date, minutes;
word_t word2;
fputs (" ", stdout);
print_ppn (word);
word2 = get_word (f);
if (word2 & 0400000000000)
printf (" %3llo ", 01000000000000LL - (word2 & WORDMASK));
else
printf (" %3llo ", word2);
word = get_word (f);
date = word >> 18;
minutes = word & 07777;
print_timestamp (stdout, date, minutes);
fputs (" ", stdout);
word = get_word (f);
date = word >> 18;
minutes = word & 07777;
print_timestamp (stdout, date, minutes);
fputs (" ", stdout);
word = get_word (f);
if (word == 0777777777777LL)
fputs ("DET ", stdout);
else
printf ("%3llo ", word & 0777777);
word = get_word (f);
printf ("%8lld ", word);
word = get_word (f);
printf ("%8lld ", word);
if ((word2 & 0400000000000) == 0)
{
putchar ('\n');
return;
}
word = get_word (f);
word = get_word (f);
print_sixbit (word);
putchar ('\n');
}
static void
print_new_record (FILE *f, word_t first)
{
word_t date, minutes;
word_t word, time, login;
time = get_word (f);
login = get_word (f);
fputs (" ", stdout);
word = get_word (f);
print_ppn (word);
printf (" %3llo ", (first >> 18) & 0777);
date = login >> 18;
minutes = login & 07777;
print_timestamp (stdout, date, minutes);
fputs (" ", stdout);
date = time >> 18;
minutes = time & 07777;
print_timestamp (stdout, date, minutes);
printf (" %3llo ", (first >> 9) & 0777);
word = get_word (f);
printf ("%8lld ", word);
word = get_word (f);
printf ("%8lld ", word);
word = get_word (f);
//printf ("%012llo ", word);
word = get_word (f);
//printf ("%012llo ", word);
word = get_word (f);
print_sixbit (word);
putchar ('\n');
}
static void
usage (const char *x)
{
fprintf (stderr, "Usage: %s [-Wformat] < file\n", x);
usage_word_format ();
exit (1);
}
static void
parse_old_format (FILE *f, word_t word)
{
for (;;)
{
if (word != -1)
word &= WORDMASK;
switch (word)
{
case -1:
exit (0);
case 0777777777777LL:
print_header (f, word);
break;
case 0777777777776LL:
print_trailer (f);
break;
default:
print_old_record (f, word);
break;
}
word = get_word (f);
}
}
static void
parse_new_format (FILE *f, word_t word)
{
int length;
for (;;)
{
if (word == -1)
exit (0);
length = word & 0777;
switch ((word >> 27) & 0777)
{
case 0400:
print_header (f, word);
break;
//case 0500: //logout
case 0440: //reload
case 0450: //reload
case 0510: //crash
case 0600: //program check
case 0610:
case 0640: //load
while (--length)
word = get_word (f);
break;
case 0500:
case 0540:
print_new_record (f, word);
break;
default:
printf ("Unknown: %03llo\n", (word >> 27) & 0777);
break;
}
word = get_word (f);
}
}
int
main (int argc, char **argv)
{
word_t word;
int opt;
while ((opt = getopt (argc, argv, "W:")) != -1)
{
switch (opt)
{
case 'W':
if (parse_input_word_format (optarg))
usage (argv[0]);
break;
default:
usage (argv[0]);
}
}
word = get_word (stdin);
word &= WORDMASK;
if (word == 0777777777777LL)
parse_old_format (stdin, word);
else if (word == 0400000000020LL)
parse_new_format (stdin, word);
else
;
return 0;
}