home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
norge.freeshell.org (192.94.73.8)
/
192.94.73.8.tar
/
192.94.73.8
/
pub
/
computers
/
cpm
/
unix2cpm.c
< prev
Wrap
C/C++ Source or Header
|
1995-07-15
|
2KB
|
46 lines
/* UNIX2CPM.COM - A program to convert a UNIX style text file,
using a LF (0AH) for a line delimiter, to one using the CP/M
convention sequence CR/LF (0DH/0AH). */ /* ch: 07/14/95 */
#include "stdio.h"
main(argc, argv) /* requires command line */
int argc;
char *argv[];
{
FILE *fopen(), *fi, *fo;
int c; /* character read and written */
int d; /* temporary stuffed character */
if (argc != 3) { /* if command line is incorrect */
printf("\tCopies infile to outfile and converts\n");
printf("\tLF newline characters (UNIX) to a CR/LF\n");
printf("\tsequence acceptable to CP/M\n\n");
printf("\tSyntax is UNIX2CPM <infile> <outfile>\n");
exit(1);
}
/* try to open files */
if ((fi = fopen(argv[1], "r")) == NULL) {
printf("\tCan't open infile...\n");
exit(1);
}
if ((fo = fopen(argv[2], "w")) == NULL) {
printf("\tCan't open outfile...\n");
exit(1);
}
/* char by char copy */
while ((c = getc(fi)) != EOF) {
c = c & 0x7F; /* strip 8-bit */
if (c == 0x0A) {
c = 0x0D;
putc(c, fo);
c = 0x0A;
putc(c, fo);
}
else putc(c, fo);
}
/* close files and exit */
fclose(fi);
fclose(fo);
exit(0);
}