home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_01 / txt2mcr.c < prev    next >
Text File  |  1990-09-06  |  2KB  |  89 lines

  1. static char helptext[] = {
  2. "TXT2MCR - this program converts an ascii file to a macro file\n"
  3. "          the  .txt file can be created with any text editor.\n"
  4. "          PARAMETERS: filename ( leave out the .txt extension )\n"
  5. "                      filename.txt will be converted to filename.mcr\n"
  6.     };
  7.  
  8. /*  to compile this program under TurboC:
  9.  *        tcc -mt -lt -Z -d txt2mcr.c
  10.  */
  11.  
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. #define MOUSE     128
  17.  
  18. main ( int argc, char **argv )
  19.     {
  20.  
  21.     int            n;
  22.     unsigned char      c;
  23.  
  24.     int nchar =0;
  25.  
  26.     char in_name[13], out_name[13];
  27.     FILE *inf, *outf;
  28.  
  29.     if ( argc == 1  || *argv[1] == '?' || (strlen (argv[1]) > 8) )
  30.         {
  31.         puts (helptext);
  32.         exit (1);
  33.         }
  34.  
  35.     strcpy (in_name,  argv[1] );
  36.     strcpy (out_name, in_name);
  37.     strcat (in_name,  ".txt" );
  38.     strcat (out_name, ".mcr" );
  39.  
  40.     if ( NULL == ( inf=fopen (in_name, "rb") ) )
  41.         {
  42.         printf ("FILE NOT FOUND %s\n\n%s\n",in_name,helptext);
  43.         exit (1);
  44.         }
  45.  
  46.     if ( NULL == ( outf=fopen (out_name, "wb") ) )
  47.         {
  48.         printf ("CANNOT OPEN  %s\n\n%s\n",out_name,helptext);
  49.         exit (1);
  50.         }
  51.  
  52.  
  53.     while ( ! feof (inf) )
  54.         {
  55.         if ( 1 == fread ( &c, sizeof (c), 1, inf) )
  56.             {
  57.             ++nchar;
  58.             n = c;
  59.             if ( n == MOUSE )
  60.                 {
  61.                 puts ("Input file contains MOUSE character\n"
  62.                       "Illegal character 0x80 = 128\n"
  63.                       "TERMINATING\n");
  64.                 exit (10);
  65.                 }
  66.  
  67.             if ( 1 != fwrite ( &n, sizeof(n), 1, outf ) )
  68.                 {
  69.                 puts ("ERROR DURING OUTPUT...TERMINATING");
  70.                 exit (10);
  71.                 }
  72.             }
  73.  
  74.         }
  75.  
  76.     fclose (inf);
  77.     fclose (outf);
  78.  
  79.  
  80.     printf (
  81.     "MACRO FILE %s successfully created, %i characters transferred\n",
  82.     out_name, nchar);
  83.  
  84.  
  85.  
  86.  
  87.  
  88.     return     (0);    /* main */
  89.     }