home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_300
/
376_01
/
os2tool.000
/
DOS2UNIX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-23
|
2KB
|
106 lines
/*
* DOS2UNIX.C - Translates files between DOS/OS/2 and UNIX.
*
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 24.11.1991
*/
static char *VERSION = "Version 1.0, Copyright(c) Martti Ylikoski, 1991" ;
/*
*/
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <errno.h>
#include <param.h>
#include <paramstd.h>
static char *progname ;
extern unsigned long pflags ;
ParamEntry pentry[12] = {
"P", &ParamSetPause, 0,
"F", &ParamSetFold, 0,
"V", &ParamSetVerbose, 0,
"R", &ParamSetReport, 0,
"S", &ParamSetSubDirs, 0,
"?", &ParamSetHelp, 1,
"H", &ParamSetHelp, 1,
"NOD", &ParamSetNoDefault, 0,
"TEST", &ParamSetTest, 0,
"Y", &ParamSetYes, 0,
"N", &ParamSetTest, 0,
"\0", NULL, 0
} ;
ParamBlock params = {
"/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
pentry
} ;
main(int argc, char *argv[])
{
FILE *fpin, *fpout ;
char buf[1024] ;
progname = argv[0] ;
ParamHandle(¶ms, &argc, argv) ;
if (pflags & PA_HELP)
{
printf("%s - Translates files between DOS/OS/2 and UNIX.\n", progname) ;
puts(VERSION) ;
puts("Usage: UNIX2DOS [file1 [file2]] [/? | /H]") ;
puts("Where,") ;
puts(" /H,/? = Help") ;
puts("If file1 is missing, DOS2UNIX reads from the standard input") ;
puts("if file2 is missing, DOS2UNIX writes to the standard output") ;
return( 0 ) ;
}
if (argc == 1)
fpin = stdin ;
else
{
if ((fpin = fopen(argv[1], "rt")) == NULL)
{
fprintf(stderr, "%s unable to open input file %s\n", progname, argv[1]) ;
return( 1 ) ;
}
}
if (argc < 3)
{
setmode(1, O_BINARY) ;
fpout = stdout ;
}
else
{
if ((fpout = fopen(argv[2], "wb")) == NULL)
{
fprintf(stderr, "%s unable to open output file %s\n", progname, argv[2]) ;
fclose(fpin) ;
return( 1 ) ;
}
}
while(fgets(buf, sizeof(buf), fpin) != NULL)
{
fputs(buf, fpout) ;
if (ferror(fpin) || ferror(fpout))
{
fprintf(stderr, "%s: error in processing\nFiles may be only partially converted\n", progname) ;
fclose(fpin) ;
fclose (fpout) ;
return( 1 ) ;
}
}
fclose(fpin) ;
fclose(fpout) ;
return( 0 ) ;
}