home *** CD-ROM | disk | FTP | other *** search
/ MACD 7 / MACD7.iso / datatypes / akjfif-datatype / stripaol / stripaol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-12  |  2.8 KB  |  144 lines

  1. /*
  2. **      $VER: StripAOL.c 1.00 (3.1.98)
  3. **
  4. **      Strips proprietary AOL email JPEG header from file
  5. **
  6. **      (C) Copyright 1998 Andreas R. Kleinert
  7. **      Freeware. All Rights Reserved.
  8. */
  9.  
  10. #define __USE_SYSBASE
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14.  
  15. #include <proto/exec.h>
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21.  
  22. #ifndef N
  23. #define N (NULL)
  24. #endif /* N */
  25.  
  26.  
  27. char ver_text [] = "\0$VER: StripAOL 1.00 (3.1.98)";
  28.  
  29.  
  30. /* *************************************************** */
  31. /* *                                                 * */
  32. /* * Additional Base Declarations                    * */
  33. /* *                                                 * */
  34. /* *************************************************** */
  35.  
  36. extern struct ExecBase *SysBase;
  37.  
  38.  
  39. /* *************************************************** */
  40. /* *                                                 * */
  41. /* * MAIN                                            * */
  42. /* *                                                 * */
  43. /* *************************************************** */
  44.  
  45. void __regargs __chkabort(void) { }
  46. void __regargs _CXBRK(void)     { }
  47.  
  48.  
  49. void main(long argc, char **argv)
  50. {
  51.  ULONG error = 0;
  52.  
  53.  if(argc == 3)
  54.   {
  55.    FILE *in, *out;
  56.  
  57.    in = fopen(argv[1], "rb");
  58.    if(in)
  59.     {
  60.      ULONG i, found = FALSE;
  61.      char *inbuf;
  62.      UBYTE chk[256];
  63.  
  64.      inbuf = malloc(16384);
  65.      if(inbuf) setbuf(in, inbuf);
  66.  
  67.      fread(&chk[0], 256, 1, in);
  68.  
  69.      for(i=0; i<248; i++)
  70.       {
  71.        if(!strncmp(&chk[i], "JPEG8BIM", 8))
  72.         {
  73.          found = TRUE;
  74.          break;
  75.         }
  76.       }
  77.  
  78.      if(found)
  79.       {
  80.        found = FALSE;
  81.  
  82.        for( ; i<252; i++)
  83.         {
  84.          if(chk[i] == 0xFF)
  85.            if(chk[i+1] == 0xD8)
  86.              if(chk[i+2] == 0xFF)
  87.                if(chk[i+3] == 0xE0) { found = TRUE; break; }
  88.         }
  89.  
  90.        if(found)
  91.         {
  92.          out = fopen(argv[2], "wb");
  93.          if(out)
  94.           {
  95.            int c;
  96.            char *outbuf;
  97.  
  98.            outbuf = malloc(16384);
  99.            if(outbuf) setbuf(out, outbuf);
  100.  
  101.            fwrite(&chk[i], 256-i, 1, out);
  102.  
  103.            while( (c = fgetc(in)) != EOF) fputc(c, out);
  104.  
  105.            fclose(out);
  106.  
  107.            if(outbuf) free(outbuf);
  108.  
  109.           }else
  110.           {
  111.            printf("\n ERROR: Can't open outfile\n");
  112.            error = 20;
  113.           }
  114.         }else
  115.         {
  116.          printf("\n ERROR: Unsupported kind of AOL JPEG\n");
  117.          error = 20;
  118.         }
  119.       }else
  120.       {
  121.        printf("\n ERROR: Is not an AOL JPEG\n");
  122.        error = 20;
  123.       }
  124.  
  125.      fclose(in);
  126.  
  127.      if(inbuf) free(inbuf);
  128.  
  129.     }else
  130.     {
  131.      printf("\n ERROR: Can't open infile\n");
  132.      error = 20;
  133.     }
  134.  
  135.   }else
  136.   {
  137.    printf("\n Strips proprietary AOL email JPEG header.");
  138.    printf("\n Written 1998 by Andreas R. Kleinert <Andreas_Kleinert@t-online.de>");
  139.    printf("\n Usage: INFILE OUTFILE\n\n");
  140.   }
  141.  
  142.  exit(error);
  143. }
  144.