home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1990 / USERJL90.MSA / LISTINGS.ARC / BITSTRIP.C next >
C/C++ Source or Header  |  1990-05-16  |  2KB  |  96 lines

  1. /* ===================================================================== */
  2.  
  3. /*             Command line 'Bit7' clear textfile utility                */             
  4.  
  5. /* --------------------------------------------------------------------- */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <fcntl.h>
  9.  
  10. #define FILE_END_OK         1
  11. #define PARAM_FAULT         2
  12. #define SOURCE_MISSING      3
  13. #define FILE_TOO_BIG        4
  14. #define NO_NEW_FILE         5
  15. #define ERROR_ON_WRITING    6
  16.  
  17. #define BUFF_SIZE           5000
  18. #define S_MODE              O_RDONLY|O_BINARY
  19. #define D_MODE              O_CREAT|O_TRUNC|O_WRONLY|O_BINARY
  20.  
  21. static int *text_string[] = {
  22.    "ST Bit7 Stripper Utility by Paul Overaa) \n",
  23.    "New file is now available",
  24.    "Usage... <SourceFile> <DestinationFile>",
  25.    "Sorry... cannot find source file",
  26.    "Sorry... source file>5000 bytes maximum",
  27.    "Sorry... couldn't open destination file",
  28.    "Write-error - are you out of disk space ?",
  29.    " - ANY KEY to exit\n" 
  30.    };  
  31.  
  32. /* --------------------------------------------------------------------- */
  33.  
  34. main(argc, argv)
  35.     
  36. int argc; char *argv[];
  37.  
  38. {
  39.  
  40. int source_fh, dest_fh, source_count, dest_count, state_flag=FILE_END_OK;
  41. register int i; char buffer[BUFF_SIZE+1];
  42.  
  43.  
  44.  
  45.  
  46. printf("%s",text_string[0]); 
  47.  
  48. if(argc!=4) {state_flag=PARAM_FAULT;}
  49.         
  50. else { 
  51.       
  52.       if ((source_fh=open(argv[1],S_MODE))==EOF) {state_flag=SOURCE_MISSING;}
  53.    
  54.        else {
  55.             
  56.             if((dest_fh=open(argv[2],D_MODE))==EOF) {state_flag=NO_NEW_FILE;}
  57.       
  58.              else {
  59.  
  60.                   source_count=read(source_fh,buffer,BUFF_SIZE);   
  61.   
  62.                   if (source_count<BUFF_SIZE)
  63.                      
  64.                      {
  65.  
  66.                       for (i=0;i<source_count;i++) buffer[i]=buffer[i]&0x7F;
  67.                     
  68.                       } else {state_flag=FILE_TOO_BIG;}
  69.  
  70.                   dest_count=write(dest_fh,buffer,source_count);
  71.  
  72.                   close(dest_fh);
  73.  
  74.                   if (source_count!=dest_count) state_flag=ERROR_ON_WRITING;                   
  75.  
  76.                   }
  77.        
  78.             close(source_fh);       
  79.    
  80.             }
  81.      
  82.     }
  83.  
  84. if (state_flag!=1) unlink(argv[2]);
  85.  
  86. printf("%s%s",text_string[state_flag],text_string[7]);
  87. getchar(); 
  88.  
  89.  
  90. /* ====================================================================== */
  91.  
  92.  
  93.  
  94.  
  95.