home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / v2600 / source.lha / source / bin2c26.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  1.4 KB  |  65 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <getopt.h>
  5. #include "c26def.h"
  6.  
  7. /* Supports a subset of version 2 */
  8.  
  9. int
  10. main (int argc, char **argv)
  11. {
  12.   FILE *infile, *outfile;
  13.   char outname[80];
  14.   char inbuf[16384];
  15.   char *writer = "bin2c26 Version 1.0";
  16.   int i, namelen;
  17.   struct c26_tag tag;
  18.  
  19.   for (i = 1; i < argc; i++)
  20.     {
  21.       infile = fopen (argv[i], "rb");
  22.       if (!infile)
  23.     {
  24.       fprintf (stderr, "Can't find %s\n", argv[i]);
  25.       exit - 1;
  26.     }
  27.  
  28.       /* Build the output name */
  29.       namelen = strlen (argv[i]);
  30.       strncpy (outname, argv[i], namelen - 3);
  31.       outname[namelen] = 0;
  32.       strncpy (&outname[namelen - 3], "c26", 3);
  33.  
  34.       /* Open output file */
  35.       outfile = fopen (outname, "wb");
  36.       if (!outfile)
  37.     {
  38.       fprintf (stderr, "Can't create %s\n", outname);
  39.       exit - 1;
  40.     }
  41.  
  42.       tag.type = C26MAGIC;
  43.       fwrite (&(tag.type), sizeof (tag.type), 1, outfile);
  44.       fwrite (".c26", sizeof (unsigned char), 4, outfile);
  45.  
  46.       tag.type = VERSION;
  47.       tag.len = 2;
  48.       fwrite (&tag, sizeof (tag), 1, outfile);
  49.  
  50.       tag.type = WRITER;
  51.       tag.len = strlen (writer) + 1;
  52.       fwrite (&tag, sizeof (tag), 1, outfile);
  53.       fwrite (writer, 1, tag.len, outfile);
  54.  
  55.       tag.type = DATA;
  56.       tag.len = 4096;
  57.       fwrite (&tag, sizeof (tag), 1, outfile);
  58.       fread (&inbuf, 1, 4096, infile);
  59.       fwrite (&inbuf, 1, 4096, outfile);
  60.  
  61.       fclose (outfile);
  62.       fclose (infile);
  63.     }
  64. }
  65.