summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-08 03:48:57 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-08-08 03:48:57 (GMT)
commit9e46fe5e6d90cad53889e2c92a6ee8811508f670 (patch)
tree07e9309c0572469e96e14e54702da57f1ffa9450
parente390259c0dba344a3d51c6a706f03daee498df53 (diff)
downloadabcdisk-9e46fe5e6d90cad53889e2c92a6ee8811508f670.zip
abcdisk-9e46fe5e6d90cad53889e2c92a6ee8811508f670.tar.gz
abcdisk-9e46fe5e6d90cad53889e2c92a6ee8811508f670.tar.bz2
abcdisk-9e46fe5e6d90cad53889e2c92a6ee8811508f670.tar.xz
Require format; common command line; support format listingabcdisk-1.0
We now require a format specifier. Use a consistent "format from to" command line format, and print help text if missing - including listing all the supported formats.
-rw-r--r--abcread.c30
-rw-r--r--abcwrite.c30
-rw-r--r--formats.c39
-rw-r--r--util.c2
-rw-r--r--util.h3
5 files changed, 55 insertions, 49 deletions
diff --git a/abcread.c b/abcread.c
index 302670a..b8bba5e 100644
--- a/abcread.c
+++ b/abcread.c
@@ -138,8 +138,6 @@ int main(int argc, char *argv[])
{
struct disk *disk;
const struct diskfmt *fmt;
- const char *fmt_name;
- char * const *argp;
FILE *f;
int i;
@@ -147,36 +145,22 @@ int main(int argc, char *argv[])
program = argv[0];
- if (argc > 1 && argv[1][0] == '-') {
- fmt_name = argv[1]+1;
- argp = argv + 2;
- argc -= 2;
- } else {
- fmt_name = "";
- argp = argv + 1;
- argc--;
- }
-
- fmt = get_format(fmt_name);
- if (!fmt) {
- fprintf(stderr, "%s: unknown format: %s\n", program, fmt_name);
- exit(1);
- }
-
- if (argc < 2) {
- fprintf(stderr, "Usage: %s [-format] file outdir\n", program);
+ if (argc != 4 || !(fmt = get_format(argv[1]))) {
+ fprintf(stderr, "Usage: %s format file outdir\n", program);
+ show_formats(stderr);
exit(1);
}
disk = allocate_disk(fmt);
- f = fopen(argp[0], "rb");
+ f = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "rb");
fread(disk->image, 1, fmt->sectors << 8, f);
- fclose(f);
+ if (f != stdin)
+ fclose(f);
/* Extract files */
for (i = 0; i < 16; i++)
- extract_dir_sector(disk, argp[1], i+16);
+ extract_dir_sector(disk, argv[3], i+16);
return 0;
}
diff --git a/abcwrite.c b/abcwrite.c
index afb6316..98e5b60 100644
--- a/abcwrite.c
+++ b/abcwrite.c
@@ -392,34 +392,32 @@ int main(int argc, char *argv[])
{
struct disk *disk;
const struct diskfmt *fmt;
- const char *fmt_name;
- char * const *argp;
+ FILE *f;
setlocale(LC_ALL, "");
program = argv[0];
- if (argc > 1 && argv[1][0] == '-') {
- fmt_name = argv[1]+1;
- argp = argv + 2;
- } else {
- fmt_name = "";
- argp = argv + 1;
- }
-
- fmt = get_format(fmt_name);
- if (!fmt) {
- fprintf(stderr, "%s: unknown format: %s\n", program, fmt_name);
- exit(1);
+ if (argc != 4 || !(fmt = get_format(argv[1]))) {
+ fprintf(stderr, "Usage: %s format indir outfile\n", argv[0]);
+ show_formats(stderr);
+ return 1;
}
disk = allocate_disk(fmt);
/* Install files */
- get_files(&disk->mfd, *argp);
+ get_files(&disk->mfd, argv[2]);
/* Finally, write out image */
- fwrite(disk->image, 1, fmt->sectors << 8, stdout);
+ f = !strcmp(argv[3], "-") ? stdout : fopen(argv[3], "wb");
+ if (!f) {
+ perror(argv[3]);
+ return 1;
+ }
+ fwrite(disk->image, 1, fmt->sectors << 8, f);
+ if (f != stdout)
+ fclose(f);
return 0;
}
diff --git a/formats.c b/formats.c
index 96a3abc..d5aa241 100644
--- a/formats.c
+++ b/formats.c
@@ -3,17 +3,22 @@
#include <string.h>
#include "util.h"
+#define F(c,h,s) (c),(h),(s),((c)*(h)*(s))
+
static const struct diskfmt formats[] =
{
- { "fd2", 40*1* 8, 0, 6, 8 },
- { "abc830", 40*1*16, 0, 6, 8 },
- { "abc830-ufd", 40*1*16, 0, 14, 16 },
- { "abc832", 80*2*16, 2, 14, 16 },
- { "abc834", 80*2*16, 2, 14, 16 },
- { "abc838", 77*2*26, 2, 14, 16 },
- { "hd", 238*8*32, 5, 14, 16 },
- { "", 238*8*32, 5, 14, 16 },
- { NULL, 0, 0, 0 }
+ { "fd2", F( 40,1, 8), 0, 6, 8 },
+ { "dd80", F( 40,1, 8), 0, 6, 8 },
+ { "fd2d", F( 40,1,16), 0, 6, 8 },
+ { "dd82", F( 40,1,16), 0, 6, 8 },
+ { "abc830", F( 40,1,16), 0, 6, 8 },
+ { "abc830-ufd", F( 40,1,16), 0, 14, 16 },
+ { "abc832", F( 80,2,16), 2, 14, 16 },
+ { "abc832", F( 80,2,16), 2, 14, 16 },
+ { "abc834", F( 80,2,16), 2, 14, 16 },
+ { "abc838", F( 77,2,26), 2, 14, 16 },
+ { "hd", F(238,8,32), 5, 14, 16 },
+ { NULL, F(0,0,0), 0, 0, 0 }
};
const struct diskfmt *get_format(const char *name)
@@ -27,3 +32,19 @@ const struct diskfmt *get_format(const char *name)
return NULL;
}
+
+void show_formats(FILE *f)
+{
+ const struct diskfmt *fmt;
+
+ fprintf(f, "Format Tracks Sides Sec/trk Cluster Sectors Total System\n");
+
+ for (fmt = formats; fmt->name; fmt++) {
+ fprintf(f, "%-13s %4d %6d %7d %9d %9d %6dK %5d\n",
+ fmt->name, fmt->c, fmt->h, fmt->s,
+ 1 << fmt->cluster_shift,
+ fmt->sectors, fmt->sectors >> 2, fmt->syssec);
+ }
+}
+
+
diff --git a/util.c b/util.c
index 81906cb..cc265b1 100644
--- a/util.c
+++ b/util.c
@@ -55,7 +55,7 @@ struct disk *allocate_disk(const struct diskfmt *fmt)
/* Create MFD directory sectors */
for (i = 0; i < fmt->dirsecs; i++) {
- unsigned char *p = disk->image + ((i + fmt->syssec) << 8);
+ unsigned char *p = disk->mfd.dirsec + ((i + fmt->syssec) << 8);
memset(p, 0x00, 16);
memset(p+16, 0xFF, 240);
}
diff --git a/util.h b/util.h
index 94d6806..a8d2d95 100644
--- a/util.h
+++ b/util.h
@@ -2,9 +2,11 @@
#define UTIL_H
#include <stdlib.h>
+#include <stdio.h>
struct diskfmt {
const char *name;
+ unsigned char c, h, s;
int sectors; /* Total sectors (max 1911 clusters) */
unsigned int cluster_shift; /* Size of a cluster, log2 */
int syssec; /* First system sector (bitmap) */
@@ -28,6 +30,7 @@ struct disk {
};
const struct diskfmt *get_format(const char *);
+void show_formats(FILE *);
struct disk *allocate_disk(const struct diskfmt *fmt);
extern const char *program;