home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 61.dms / 61.adf / source.files / ilbmdump.c < prev    next >
C/C++ Source or Header  |  1986-03-21  |  4KB  |  131 lines

  1. /*--------------------------------------------------------------*/
  2. /*                                */
  3. /* ILBMDump.c: reads in ILBM, prints out ascii representation,     */
  4. /*  for including in C files.                     */
  5. /*                                                              */
  6. /* By Jerry Morrison and Steve Shaw, Electronic Arts.           */
  7. /* This software is in the public domain.                       */
  8. /*                                                              */
  9. /* This version for the Commodore-Amiga computer.               */
  10. /*                                                              */
  11. /*  Callable from CLI ONLY                    */
  12. /*  Jan 31, 1986                        */
  13. /*--------------------------------------------------------------*/
  14.  
  15.  
  16.  
  17. #include "iff/intuall.h"
  18. #include "libraries/dos.h"
  19. #include "libraries/dosextens.h"
  20. #include "iff/ilbm.h"
  21. #include "iff/readpict.h"
  22. #include "iff/remalloc.h"
  23.  
  24. #undef NULL
  25. #include "lattice/stdio.h"
  26. /*----------------------------------------------------------------------*/
  27. /*    Iff error messages                        */
  28. /*----------------------------------------------------------------------*/
  29.  
  30. char MsgOkay[] = { "----- (IFF_OKAY) A good IFF file." };
  31. char MsgEndMark[] = {"----- (END_MARK) How did you get this message??" };
  32. char MsgDone[] = { "----- (IFF_DONE) How did you get this message??" };
  33. char MsgDos[] = { "----- (DOS_ERROR) The DOS gave back an error." };
  34. char MsgNot[] = { "----- (NOT_IFF) not an IFF file." };
  35. char MsgNoFile[] = { "----- (NO_FILE) no such file found." };
  36. char MsgClientError[] = {"----- (CLIENT_ERROR) IFF Checker bug."};
  37. char MsgForm[] = { "----- (BAD_FORM) How did you get this message??" };
  38. char MsgShort[] = { "----- (SHORT_CHUNK) How did you get this message??" };
  39. char MsgBad[] = { "----- (BAD_IFF) a mangled IFF file." };
  40.  
  41. /* MUST GET THESE IN RIGHT ORDER!!*/
  42. char *IFFPMessages[-LAST_ERROR+1] = {
  43.     /*IFF_OKAY*/  MsgOkay,
  44.     /*END_MARK*/  MsgEndMark,
  45.     /*IFF_DONE*/  MsgDone,
  46.     /*DOS_ERROR*/ MsgDos,
  47.     /*NOT_IFF*/   MsgNot,
  48.     /*NO_FILE*/   MsgNoFile,
  49.     /*CLIENT_ERROR*/ MsgClientError,
  50.     /*BAD_FORM*/  MsgForm,
  51.     /*SHORT_CHUNK*/  MsgShort,
  52.     /*BAD_IFF*/   MsgBad
  53.     };
  54.  
  55. /* this returns a string containing characters after the
  56.      last '/' or ':' */
  57. GetSuffix(to, fr) UBYTE *to, *fr; {
  58.     int i;
  59.     UBYTE c,*s = fr;
  60.     for (i=0; ;i++) {
  61.     c = *s++;
  62.     if (c == 0) break;
  63.     if (c == '/') fr = s;
  64.     else if (c == ':') fr = s;
  65.     }
  66.     strcpy(to,fr);
  67.     }
  68.  
  69. LONG GfxBase;
  70. struct BitMap bitmap = {0};
  71.  
  72. ILBMFrame ilbmFrame;    /* Top level "client frame".*/
  73.  
  74. /** main() ******************************************************************/
  75.  
  76. UBYTE defSwitch[] = "b";
  77.  
  78. void main(argc, argv)  int argc;  char **argv;  {
  79.     UBYTE *sw;
  80.     FILE *fp;
  81.     LONG iffp,file;
  82.     UBYTE name[40], fname[40];
  83.     GfxBase = (LONG)OpenLibrary("graphics.library",0);
  84.     if (GfxBase==NULL) exit(0);
  85.     
  86.     if (argc) {
  87.     /* Invoked via CLI.  Make a lock for current directory. */
  88.     if (argc < 2) {
  89.         printf("Usage from CLI: 'ILBMDump filename switch-string'\n");
  90.         printf(" where switch-string = \n");
  91.         printf("  <nothing> : Bob format (default)\n");
  92.         printf("  s         : Sprite format (with header and trailer words)\n");
  93.         printf("  sn        : Sprite format (No header and trailer words)\n");
  94.         printf("  a         : Attached sprite (with header and trailer)\n");
  95.         printf("  an        : Attached sprite (No header and trailer)\n");
  96.         printf(" Add 'c' to switch list to output CR's with LF's   \n");
  97.         }
  98.     else {
  99.         sw = (argc>2)? argv[2]: defSwitch;
  100.         
  101.         file = Open(argv[1], MODE_OLDFILE);
  102.         
  103.         if (file) {
  104.         iffp = ReadPicture(file, &bitmap, &ilbmFrame, ChipAlloc);
  105.         Close(file);
  106.         if (iffp != IFF_DONE) {
  107.             printf(" Couldn't read file %s \n", argv[1]);
  108.             printf("%s\n",IFFPMessages[-iffp]);
  109.             }
  110.         else {
  111.             printf(" Creating file %s.c \n",argv[1]);
  112.             GetSuffix(name,argv[1]);
  113.             strcpy(fname,argv[1]);
  114.             strcat(fname,".c");
  115.             fp = fopen(fname,"w");
  116.             BMPrintCRep(&bitmap,fp,name,sw);
  117.             fclose(fp);
  118.             }
  119.         }
  120.         else printf(" Couldn't open file: %s. \n", argv[1]);
  121.  
  122.         if (bitmap.Planes[0])  RemFree(bitmap.Planes[0]);
  123.  
  124.         printf("\n");
  125.         }
  126.     }
  127.     CloseLibrary(GfxBase);
  128.     exit(0);
  129.     }
  130.  
  131.