Commit 2a6b3869 authored by Hellwig Geisse's avatar Hellwig Geisse
Browse files

add a few important tools

parent 1fee6d1c
#
# Makefile for tools
#
BUILD = ../build
#DIRS = mkdisk dos2oberon oberon2dos oberon2unix unix2oberon mem2bin cmpx \
# showobj showsym bin2boot
DIRS = mkdisk dos2oberon oberon2dos unix2oberon oberon2unix cmpx
all:
for i in $(DIRS) ; do \
$(MAKE) -C $$i all ; \
done
install:
for i in $(DIRS) ; do \
$(MAKE) -C $$i install ; \
done
clean:
for i in $(DIRS) ; do \
$(MAKE) -C $$i clean ; \
done
rm -f *~
#
# Makefile for file comparison tool
#
BUILD = ../../build
all: cmpx
install: cmpx
mkdir -p $(BUILD)/bin
cp cmpx $(BUILD)/bin
cmpx: cmpx.c
gcc -g -Wall -o cmpx cmpx.c
clean:
rm -f *~ cmpx
/*
* cmpx.c -- file comparison with hex output
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
FILE *f1, *f2;
int b1, b2;
int n;
int diff;
if (argc != 3) {
printf("usage: %s <file1> <file2>\n", argv[0]);
return 1;
}
f1 = fopen(argv[1], "r");
if (f1 == NULL) {
printf("error: cannot open '%s'\n", argv[1]);
return 1;
}
f2 = fopen(argv[2], "r");
if (f2 == NULL) {
printf("error: cannot open '%s'\n", argv[2]);
return 1;
}
diff = 0;
n = 0;
while (1) {
b1 = fgetc(f1);
b2 = fgetc(f2);
if (b1 == EOF || b2 == EOF) {
break;
}
if (b1 != b2) {
printf("0x%08X 0x%02X 0x%02X\n", n, b1, b2);
diff = 1;
}
n++;
}
if (b1 != EOF || b2 != EOF) {
printf("files have different lengths\n");
diff = 1;
}
fclose(f1);
fclose(f2);
return diff;
}
#
# Makefile for DOS-to-Oberon text converter
#
BUILD = ../../build
all: dos2oberon
install: dos2oberon
mkdir -p $(BUILD)/bin
cp dos2oberon $(BUILD)/bin
dos2oberon: dos2oberon.c
gcc -g -Wall -o dos2oberon dos2oberon.c
clean:
rm -f *~ dos2oberon
/*
* dos2oberon.c -- convert DOS line endings to Oberon line endings
*/
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *in, *out;
int c;
if (argc != 3) {
printf("usage: %s <input file> <output file>\n", argv[0]);
return 1;
}
in = fopen(argv[1], "r");
if (in == NULL) {
printf("error: cannot open input file '%s'\n", argv[1]);
return 1;
}
out = fopen(argv[2], "w");
if (out == NULL) {
printf("error: cannot open output file '%s'\n", argv[2]);
return 1;
}
while (1) {
c = fgetc(in);
if (c == EOF) {
break;
}
if (c == '\r') {
c = fgetc(in);
if (c != EOF && c != '\n') {
ungetc(c, in);
}
c = '\r';
}
fputc(c, out);
}
fclose(in);
fclose(out);
return 0;
}
#
# Makefile for disk creator
#
BUILD = ../../build
CC = gcc
CFLAGS = -g -Wall
LDFLAGS = -g -Wall
LDLIBS = -lm
SRCS = mkdisk.c
OBJS = $(patsubst %.c,%.o,$(SRCS))
BIN = mkdisk
all: $(BIN)
install: $(BIN)
mkdir -p $(BUILD)/bin
cp $(BIN) $(BUILD)/bin
$(BIN): $(OBJS)
$(CC) $(LDFLAGS) -o $(BIN) $(OBJS) $(LDLIBS)
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
clean:
rm -f *~ $(OBJS) $(BIN)
/*
* mkdisk.c -- make an empty physical disk
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#define SECTOR_SIZE 512
#define MIN_NUMBER_SECTORS 100
#define SECTORS_PER_MB ((1 << 20) / SECTOR_SIZE)
#define DATA_BYTE 0xE5
void error(char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "Error: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(1);
}
void usage(void) {
fprintf(stderr, "Usage: mkdisk <file name> <n>[M]\n");
fprintf(stderr, " <n>: decimal number of sectors\n");
fprintf(stderr, " if 'M' appended: megabytes instead of sectors\n");
fprintf(stderr, " (sector size is always %d bytes)\n", SECTOR_SIZE);
exit(1);
}
int main(int argc, char *argv[]) {
FILE *dskFile;
int numSectors;
unsigned char sectorBuffer[SECTOR_SIZE];
int i;
if (argc != 3) {
usage();
}
numSectors = atoi(argv[2]);
i = strlen(argv[2]) - 1;
if (argv[2][i] == 'M') {
numSectors *= SECTORS_PER_MB;
}
if (numSectors < MIN_NUMBER_SECTORS) {
error("this disk is too small to be useful (minimum size is %d sectors)",
MIN_NUMBER_SECTORS);
}
dskFile = fopen(argv[1], "wb");
if (dskFile == NULL) {
error("cannot open file '%s' for write", argv[1]);
}
fprintf(stdout,
"Creating disk '%s' with %d sectors (around %d MB)...\n",
argv[1], numSectors,
(numSectors + SECTORS_PER_MB / 2) / SECTORS_PER_MB);
for (i = 0; i < SECTOR_SIZE; i++) {
sectorBuffer[i] = DATA_BYTE;
}
for (i = 0; i < numSectors; i++) {
if (fwrite(sectorBuffer, SECTOR_SIZE, 1, dskFile) != 1) {
error("write error on file '%s', sector %d", argv[1], i);
}
}
fclose(dskFile);
return 0;
}
#
# Makefile for Oberon-to-DOS text converter
#
BUILD = ../../build
all: oberon2dos
install: oberon2dos
mkdir -p $(BUILD)/bin
cp oberon2dos $(BUILD)/bin
oberon2dos: oberon2dos.c
gcc -g -Wall -o oberon2dos oberon2dos.c
clean:
rm -f *~ oberon2dos
/*
* oberon2dos.c -- convert Oberon line endings to DOS line endings
*/
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *in, *out;
int c;
if (argc != 3) {
printf("usage: %s <input file> <output file>\n", argv[0]);
return 1;
}
in = fopen(argv[1], "r");
if (in == NULL) {
printf("error: cannot open input file '%s'\n", argv[1]);
return 1;
}
out = fopen(argv[2], "w");
if (out == NULL) {
printf("error: cannot open output file '%s'\n", argv[2]);
return 1;
}
while (1) {
c = fgetc(in);
if (c == EOF) {
break;
}
if (c == '\r') {
fputc(c, out);
c = '\n';
}
fputc(c, out);
}
fclose(in);
fclose(out);
return 0;
}
#
# Makefile for Oberon-to-UNIX text converter
#
BUILD = ../../build
all: oberon2unix
install: oberon2unix
mkdir -p $(BUILD)/bin
cp oberon2unix $(BUILD)/bin
oberon2unix: oberon2unix.c
gcc -g -Wall -o oberon2unix oberon2unix.c
clean:
rm -f *~ oberon2unix
/*
* oberon2unix.c -- convert Oberon line endings to UNIX line endings
*/
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *in, *out;
int c;
if (argc != 3) {
printf("usage: %s <input file> <output file>\n", argv[0]);
return 1;
}
in = fopen(argv[1], "r");
if (in == NULL) {
printf("error: cannot open input file '%s'\n", argv[1]);
return 1;
}
out = fopen(argv[2], "w");
if (out == NULL) {
printf("error: cannot open output file '%s'\n", argv[2]);
return 1;
}
while (1) {
c = fgetc(in);
if (c == EOF) {
break;
}
if (c == '\r') {
c = '\n';
}
fputc(c, out);
}
fclose(in);
fclose(out);
return 0;
}
#
# Makefile for UNIX-to-Oberon text converter
#
BUILD = ../../build
all: unix2oberon
install: unix2oberon
mkdir -p $(BUILD)/bin
cp unix2oberon $(BUILD)/bin
unix2oberon: unix2oberon.c
gcc -g -Wall -o unix2oberon unix2oberon.c
clean:
rm -f *~ unix2oberon
/*
* unix2oberon.c -- convert UNIX line endings to Oberon line endings
*/
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *in, *out;
int c;
if (argc != 3) {
printf("usage: %s <input file> <output file>\n", argv[0]);
return 1;
}
in = fopen(argv[1], "r");
if (in == NULL) {
printf("error: cannot open input file '%s'\n", argv[1]);
return 1;
}
out = fopen(argv[2], "w");
if (out == NULL) {
printf("error: cannot open output file '%s'\n", argv[2]);
return 1;
}
while (1) {
c = fgetc(in);
if (c == EOF) {
break;
}
if (c == '\n') {
c = '\r';
}
fputc(c, out);
}
fclose(in);
fclose(out);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment