Category : Word Processors
Archive   : ADDCR.ZIP
Filename : ADDCR.C

 
Output of file : ADDCR.C contained in archive : ADDCR.ZIP
/*
* A very simple UNIX->DOS file conversion program. Only adds
* CR characters before the LF character which is already there,
* nothing else.
*
* Works from a file list. If linked with the SETARGV.OBJ file
* from the Microsoft compiler, wildcards in the file list will
* be expanded. There is a test for file names which contain
* '?' or '*'. This happens if there are no files matching the
* wildcard.
*
* The "extra" code for looking at CR characters prevents the
* program from mindlessly adding another CR to the CR/LF pair
* in a file which is already in DOS format. This is useful
* if you use a wildcard which accidently includes both DOS
* files and UNIX files.
*
* This code is placed in the public domain.
*
* Ken Brown
*
*/

#include
#include

main(argc,argv)
int argc;
char *argv[];
{
int counter;
int c;
char *out_file_name = NULL;
FILE *infile,
*outfile;


if(argc < 2) {
printf("syntax: addcr file1 [file2 ...] (wild cards allowed)\n");
exit(1);
}
for(counter = 1; counter < argc; counter++) {
if(strchr(argv[counter],'?') != NULL) {
continue;
}
if(strchr(argv[counter],'*') != NULL) {
continue;
}
out_file_name = "tmXXXXXX";
mktemp(out_file_name);
if((outfile=fopen(out_file_name,"wb")) == NULL) {
printf("can not open %s\n",out_file_name);
continue;
}
if((infile=fopen(argv[counter],"rb"))==NULL) {
printf("can not find %s\n",argv[1]);
continue;
}
if(argc > 2) {
printf("%s\n",argv[counter]);
}
while((c=getc(infile))!=EOF) {
if(c == '\r') {
if((c=getc(infile))==EOF) {
putc('\r',outfile);
break;
}
if(c == '\n') {
putc('\r',outfile);
putc('\n',outfile);
continue;
}
else {
putc('\r',outfile);
putc(c,outfile);
continue;
}
}
if(c=='\n') {
putc('\r',outfile);
putc('\n',outfile);
}
else {
putc(c,outfile);
}
}
fclose(infile);
fclose(outfile);

unlink(argv[counter]);
rename(out_file_name,argv[counter]);
}
}




  3 Responses to “Category : Word Processors
Archive   : ADDCR.ZIP
Filename : ADDCR.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/