home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
ux_dos.zip
/
UNIX_DOS.C
next >
Wrap
C/C++ Source or Header
|
1996-01-08
|
2KB
|
63 lines
/*unix_dos -[u|d][input]
* -u changes \n\r into \n
* -d changes \n into \n\r
*/
/*Last modified by boris@innonyc.com
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
void main(int argc, char ** argv)
{
FILE *in, *out; int cur_arg=1; char dest[256]; char buf[80];
struct find_t ffblk; int c,ii,unix_to_dos, done=1;char file_name[256]="";
if(((argc>1)&&strcmp(argv[1],"-u")&&strcmp(argv[1],"-d"))||(argc==1)) {
printf("Program converts text files from DOS to UNIX and reverse\n\
To use type %s -[u|d] <file names>\n\
-u indicates input text files are UNIX type, -d DOS (\\n\\r)\n\
Wild card are SUPPORTED\n"
,argv[0]);
exit(1);
}
unix_to_dos=strcmp(argv[1],"-d");argc--;argv++;
if(argc==1)exit(0);
do{
/* optional input arg */
if(done){/*first attempt to decode the argument*/
done =_dos_findfirst(argv[cur_arg],_A_NORMAL|_A_HIDDEN|
_A_RDONLY|_A_SYSTEM|_A_ARCH,&ffblk); ii=strlen(argv[cur_arg]);
while((ii>=0)&&(argv[cur_arg][ii]!='\\'))ii--;
ii++;
}
strncpy(file_name,argv[cur_arg],ii);file_name[ii]=0;
strcat(file_name,ffblk.name);
if ((in = fopen(file_name, "rb")) == NULL) {
perror(file_name);
exit(1);
}
out = fopen("t023489d.tmp", "wb");
if (out == NULL) {
perror("t023489d.tmp");
exit(1);
}
/* search for header line */
while((c=fgetc(in))!=EOF){
if((c!='\n')&&(c!='\r')){fputc(c,out);continue;}
if(c=='\r')continue; fputc(c,out);
if(unix_to_dos) {fputc('\r',out);continue;}
}
fclose(out); fclose(in);
remove(file_name);
rename("t023489d.tmp",file_name);
done = _dos_findnext(&ffblk);
if (done!=0){cur_arg++;}
}while(cur_arg<argc);
}