-
Notifications
You must be signed in to change notification settings - Fork 13
/
od10.c
154 lines (130 loc) · 2.81 KB
/
od10.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
/* Copyright (C) 2021 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/>. */
#include <stdio.h>
#include <unistd.h>
#include "dis.h"
unsigned int address = 0;
int offset = -1;
static void
print_octal (word_t word)
{
if (word == -1)
{
printf (" ");
return;
}
printf (" %06llo,,%06llo", word >> 18, word & 0777777LL);
address++;
if (offset != -1)
offset++;
}
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_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_double (word_t even, word_t odd)
{
printf ("%010o", address);
if (offset != -1)
printf ("/%06o", offset);
printf (": ");
print_octal (even);
print_octal (odd);
putchar (' ');
print_sixbit (even);
print_sixbit (odd);
printf (" ");
print_ascii (even);
print_ascii (odd);
putchar ('\n');
}
static void
od (FILE *f)
{
word_t even, odd;
for (;;)
{
even = get_word (f);
if (even == -1)
exit (0);
record:
if (even & START_TAPE)
printf ("Logical end of tape.\n");
else if (even & START_FILE)
printf ("Start of file.\n");
else if (even & START_RECORD)
printf ("Start of record.\n");
if (even & (START_TAPE|START_FILE|START_RECORD))
offset = 0;
even &= WORDMASK;
odd = get_word (f);
if (odd != -1 && odd & (START_TAPE|START_FILE|START_RECORD))
{
print_double (even, -1);
even = odd;
goto record;
}
print_double (even, odd);
if (odd == -1)
exit (0);
}
}
static void
usage (const char *x)
{
fprintf (stderr, "Usage: %s [-Wformat] < file\n", x);
usage_word_format ();
exit (1);
}
int
main (int argc, char **argv)
{
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]);
}
}
od (stdin);
return 0;
}