source: buchla-68k/orig/GEMDOS/SECDUMP.C@ c93e44d

Last change on this file since c93e44d was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 5.5 KB
Line 
1/*
2 =============================================================================
3 secdump.c -- sector dump for the Atari ST
4 Version 1 -- 1988-01-27 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define PROGID "secdump"
9
10#include "stddefs.h"
11#include "osbind.h"
12#include "stdio.h"
13#include "ctype.h"
14
15#define PERLINE 16
16#define SECLEN 512
17
18short spp;
19short secnum;
20short sec_bgn;
21short sec_end;
22short drive;
23
24char ebuf[128];
25char secbuf[SECLEN];
26
27/*
28
29*/
30
31/*
32 =============================================================================
33 pipc() -- print if printable characters
34 =============================================================================
35*/
36
37static
38pipc(chars, length)
39char chars[];
40int length;
41{
42 int i;
43
44 for (i = 0; i < length; i++)
45 if (isascii(0x00FF & chars[i]) AND (isprint(0x00FF & chars[i])))
46 printf("%c", chars[i]);
47 else
48 printf(".");
49}
50
51/*
52
53*/
54
55/*
56 =============================================================================
57 mdump() -- dump a memory area in hexadecimal
58 =============================================================================
59*/
60
61mdump(begin, end, start)
62char *begin, *end;
63long start;
64{
65 long i, ii;
66 int j, jj, k;
67 char c, chars[PERLINE];
68
69 i = 0L;
70 ii = start;
71 j = 0;
72
73 if (begin GT end)
74 return;
75
76 while (begin LE end) {
77
78 c = *begin++;
79
80 if (! (i % PERLINE)) {
81
82 if (i) {
83
84 j=0;
85 printf(" ");
86 pipc(chars, PERLINE);
87 }
88
89 printf("\n%08lx:", ii);
90 }
91
92 ii++;
93 i++;
94
95 printf(" %02.2x", (c & 0x00FF));
96 chars[j++] = c;
97 }
98
99 if (k = (i % PERLINE)) {
100
101 k = PERLINE - k;
102
103 for (jj = 0; jj < (3 * k); ++jj)
104 printf(" ");
105 }
106
107 printf(" ");
108 pipc(chars, PERLINE);
109 printf("\n");
110}
111
112/*
113
114*/
115
116/*
117 =============================================================================
118 errmsg() -- print an error message on stderr
119 =============================================================================
120*/
121
122errmsg(s)
123char *s;
124{
125 fprintf(stderr, "%s: ERROR - %s\n", PROGID, s);
126}
127
128/*
129 =============================================================================
130 usage() -- print a usage message on stdout
131 =============================================================================
132*/
133
134usage()
135{
136 printf("usage: %s drive first [last]\n", PROGID);
137}
138
139/*
140
141*/
142
143/*
144 =============================================================================
145 getsnum() -- get a sector number into secnum
146 =============================================================================
147*/
148
149short
150getsnum(from)
151char *from;
152{
153 short c;
154 long n;
155
156 n = 0;
157
158 while (c = *from++) {
159
160 if (isascii(c)) {
161
162 if (isdigit(c)) {
163
164 n = (n * 10) + (c - '0');
165
166 } else {
167
168 return(FAILURE);
169 }
170
171 } else {
172
173 return(FAILURE);
174 }
175 }
176
177 if (n < 32767L) {
178
179 secnum = (short)n;
180 return(SUCCESS);
181
182 }
183
184 return(FAILURE);
185}
186
187/*
188
189*/
190
191/*
192 =============================================================================
193 getdrv() -- get and check a drive specifier
194 =============================================================================
195*/
196
197short
198getdrv(from)
199char *from;
200{
201 short c;
202 long dmap;
203
204 dmap = Drvmap();
205
206 c = *from & 0x00FF;
207
208 if (isascii(c))
209 if (isalpha(c)) {
210
211 drive = _toupper(c) - 'A';
212
213 if (dmap & (1L << drive))
214 return(SUCCESS);
215 }
216
217 return(FAILURE);
218}
219
220/*
221
222*/
223
224/*
225 =============================================================================
226 prtsec() -- print a sector in hex and ASCII
227 =============================================================================
228*/
229
230prtsec(sn)
231short sn;
232{
233 if (Rwabs(2, secbuf, 1, sn, drive)) {
234
235 sprintf(ebuf, "Sector %d is unreadable", sn);
236 errmsg(ebuf);
237 exit(1);
238 }
239
240 if (NOT spp) {
241
242 spp = TRUE;
243 printf("\f");
244 }
245
246 printf("\n\nDrive %c: -- Sector %d\n\n", drive + 'A', sn);
247 mdump(secbuf, &secbuf[SECLEN - 1], 0L);
248}
249
250/*
251
252*/
253
254/*
255 =============================================================================
256 main() -- main driver for secdump.c
257 =============================================================================
258*/
259
260main(argc, argv)
261int argc;
262char *argv[];
263{
264 short isec;
265
266 /* decode the command line */
267
268 switch (argc) {
269
270 case 1: /* no arguments -- just give usage message */
271
272 usage();
273 exit(0);
274
275 case 3: /* 2 arguments -- expect drive and first sector */
276
277 if (getdrv(argv[1])) {
278
279 errmsg("Invalid drive specifier");
280 exit(1);
281 }
282
283 if (getsnum(argv[2])) {
284
285 errmsg("Invalid first sector");
286 exit(1);
287 }
288
289 sec_bgn = secnum;
290 sec_end = sec_bgn;
291 break;
292
293 case 4: /* 3 arguments -- expect drive and sector range */
294
295 if (getdrv(argv[1])) {
296
297 errmsg("Invalid drive specifier");
298 exit(1);
299 }
300
301 if (getsnum(argv[2])) {
302
303 errmsg("Invalid first sector");
304 exit(1);
305 }
306
307 sec_bgn = secnum;
308
309 if (getsnum(argv[3])) {
310
311 errmsg("Invalid last sector");
312 exit(1);
313 }
314
315 sec_end = secnum;
316
317 if (sec_end < sec_bgn) {
318
319 errmsg("Last sector preceeds first sector");
320 exit(1);
321 }
322
323 break;
324
325 default: /* wrong argument count -- give an error message */
326
327 errmsg("Wrong number of arguments");
328 usage();
329 exit(1);
330 }
331
332 spp = FALSE;
333
334 /* get the sectors, and print them */
335
336 for (isec = sec_bgn; isec LE sec_end; isec++)
337 prtsec(isec);
338
339 exit(0);
340}
Note: See TracBrowser for help on using the repository browser.