/* * Copyright (C) 1995-1997 Christopher D. Granz * * This header may not be removed. * * Refer to the file "License" included in this package for further * information and before using any of the following. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <unistd.h> /* * Functions */ int main( int iArgC, char *pArgV[] ) { FILE *pInFile; FILE *pOutFile; char cBuf[1024]; char c; int i; int iType; if ( iArgC < 2 ) { usage: fprintf( stderr, "\nUsage: %s [-u|d] <text file>\n", pArgV[0] ); return ( 0 ); } iType = 0; sprintf( cBuf, "%ld.tmp", (long) getpid( ) ); if ( iArgC > 2 ) { i = 2; if ( pArgV[1][0] != '-' ) goto usage; switch ( pArgV[1][1] ) { case 'u': break; case 'd': iType = 1; break; default : goto usage; } if ( pArgV[1][2] != '\0' ) goto usage; } else i = 1; if ( ( pInFile = fopen( pArgV[i], "r" ) ) == NULL ) { fprintf( stderr, "\n%s: %s: %s.\n", pArgV[0], pArgV[i], strerror( errno ) ); return ( 1 ); } if ( ( pOutFile = fopen( cBuf, "w" ) ) == NULL ) { fprintf( stderr, "\n%s: %s: %s.\n", pArgV[0], cBuf, strerror( errno ) ); return ( 1 ); } if ( iType == 1 ) { for ( ; ; ) { c = getc( pInFile ); if ( c == EOF ) break; switch ( c ) { case '\n': putc( '\r', pOutFile ); putc( '\n', pOutFile ); break; case '\r': break; default : putc( c, pOutFile ); break; } } } else { for ( ; ; ) { c = getc( pInFile ); if ( c == EOF ) break; switch ( c ) { case '\r': break; default : putc( c, pOutFile ); break; } } } fclose( pInFile ); fclose( pOutFile ); unlink( pArgV[i] ); rename( cBuf, pArgV[i] ); return ( 0 ); } /* * End of main.c */