Commit 72eede0a authored by Hellwig Geisse's avatar Hellwig Geisse

reorganize converters

parent 357fa93a
......@@ -4,7 +4,7 @@
BUILD = ../build
DIRS = convert mkdisk
DIRS = mkdisk oberon2unix unix2oberon
all:
for i in $(DIRS) ; do \
......
#
# Makefile for text conversion tools
#
BUILD = ../../build
DIRS = dos2oberon oberon2dos unix2oberon oberon2unix
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 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[]) {
int c1, c2;
c1 = fgetc(stdin);
if (c1 == EOF) {
return 0;
}
while (1) {
c2 = fgetc(stdin);
if (c2 == EOF) {
fputc(c1, stdout);
return 0;
}
if (c1 == '\r' && c2 == '\n') {
fputc(c1, stdout);
c1 = fgetc(stdin);
if (c1 == EOF) {
return 0;
}
} else {
fputc(c1, stdout);
c1 = c2;
}
}
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[]) {
int c;
while (1) {
c = fgetc(stdin);
if (c == EOF) {
return 0;
}
if (c == '\r') {
fputc(c, stdout);
c = '\n';
fputc(c, stdout);
} else {
fputc(c, stdout);
}
}
return 0;
}
......@@ -2,7 +2,7 @@
# Makefile for Oberon-to-UNIX text converter
#
BUILD = ../../../build
BUILD = ../../build
all: oberon2unix
......
......@@ -7,17 +7,34 @@
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(stdin);
c = fgetc(in);
if (c == EOF) {
return 0;
break;
}
if (c == '\r') {
c = '\n';
}
fputc(c, stdout);
fputc(c, out);
}
fclose(in);
fclose(out);
return 0;
}
......@@ -2,7 +2,7 @@
# Makefile for UNIX-to-Oberon text converter
#
BUILD = ../../../build
BUILD = ../../build
all: unix2oberon
......
......@@ -7,17 +7,34 @@
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(stdin);
c = fgetc(in);
if (c == EOF) {
return 0;
break;
}
if (c == '\n') {
c = '\r';
}
fputc(c, stdout);
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