home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / utilities / viewer / source / showiffchunks.rx < prev    next >
Encoding:
Text File  |  1994-07-14  |  3.4 KB  |  117 lines

  1. /*
  2.    This ARexx-script is Public Domain.
  3.    It's enclosed to the FreeWare program Viewer.
  4.    It's meant to show off all chunks of ANY IFF-file,
  5.    so that easily Viewer can be extended to view ascii-texts
  6.    out off ANY IFF-file that contains plain character datas.
  7.  
  8.    THE IDEA FOR THIS APPLICATION INSPIRATED THROUGH SIFT WRITTEN BY LEO L. SCHWAB.
  9.  
  10.    This script written in 1994 by:
  11.      Joerg van de Loo
  12.      Hoevel 15
  13.      47559 Kranenburg
  14.      Germany   
  15. */
  16.  
  17. ARG FileName
  18.  
  19. IF FileName == '' THEN DO
  20.   SAY 'ShowIFFChunks: Need file name as parameter!'
  21.   EXIT 20
  22.   END
  23.  
  24. IF ~EXISTS(FileName) THEN DO
  25.   SAY 'Couldn''t find the file - file does not exists, respectively!'
  26.   EXIT 10
  27.   END
  28.  
  29. Open('File', FileName, 'R')   /* First, we have to open the file */
  30.  
  31. String = READCH('File', 4)    /* Read in first 4 bytes of file */
  32. IF String ~= 'FORM' THEN DO   /* Must be labelled as "FORM" ! */
  33.   SAY 'File does own right fromat!'
  34.   EXIT 5
  35.   END
  36.  
  37. SEEK('File', 4, 'C')       /* Overread length of FORM-Chunk */
  38. String = READCH('File', 4) /* Get ID (group) of file */
  39. SAY 'Type of file:' String
  40.  
  41. DO FOREVER           /* Never ending */
  42. true = EOF('File')   /* End of file ? */
  43. IF true == 1 THEN    /* In case it's 1 then yes... */
  44.   BREAK
  45.   ELSE
  46.  
  47.   String = READCH('File', 4)      /* Name of Chunk */
  48.  
  49.   IF String == 'ILBM' THEN DO     /* In case it's the ILBM-Chunk no length will follow */
  50.      SAY 'Name of Chunk: ILBM.'   /* but the BMHD, this one owns one */
  51.      String = READCH('File', 4)   /* New Chunk-name! */
  52.      END
  53.  
  54.   Length = READCH('File', 4)      /* Length of Chunk */
  55.  
  56.   IF String == "" THEN  /* No name? */
  57.      BREAK              /* If so, no output and end! */
  58.      ELSE               /* Esle, output and continue! */
  59.  
  60.   SAY 'Name of Chunk:' String', Length:' C2D(Length) 'Bytes.'
  61.  
  62.   IF String == 'NAME' THEN DO
  63.      PrintStr( C2D(Length))
  64.      END
  65.   IF String == '(c) ' THEN DO
  66.      PrintStr( C2D(Length))
  67.      END
  68.   IF String == 'AUTH' THEN DO
  69.      PrintStr( C2D(Length))
  70.      END
  71.   IF String == 'ANNO' THEN DO
  72.      PrintStr( C2D(Length))
  73.      END
  74.   IF String == 'CHRS' THEN DO
  75.      PrintStr( C2D(Length))
  76.      END
  77.  
  78. /*
  79. The FORM-Chunk represents in an ANIM-file the length of one! Frame.
  80. This length includes all other Chunks, e.g. ANHD und DLTA; because
  81. we want to see those Chunks too, we only have to ignore the length setting -
  82. this can be easily done via "Seek" and an offset to current by zero.
  83. */
  84.   IF String == 'FORM' THEN Length = D2C(0) /* If FORM-Chunk, ignore length! */
  85.  
  86. /*
  87. Now we have to check for not by two divisible lengths.
  88. Because a Chunk can own a un-even length, we have to check
  89. and! correct this, too. Otherwise the file cursor points
  90. not to a Chunk anymore, since the offset for a Chunk within
  91. a file is ever even!
  92. */
  93.   IF BITTST(C2D(Length), 0) == 1 THEN DO  /* Odd or not... */
  94.      SAY '  »» Warning: Chunk-Length odd, going to extent it...'
  95.      Ext = C2D(Length)   /* Odd length to Ext */
  96.      Ext = Ext+1         /* Length + 1 */
  97.      Length = D2C(Ext)   /* Set corrected length */
  98.      END
  99.  
  100.   SEEK('File', C2D(Length), 'C')   /* Overread last Chunk */
  101.  
  102.   END
  103.  
  104. EXIT           /* If we reach this point,
  105.                we'll quit the program */
  106.  
  107. /*----------------------------------------------*/
  108. PrintStr: PROCEDURE
  109.      ARG len
  110.  
  111.      NewString = READCH('File', len)
  112.      Say '     Text contents: "'NewString'"'
  113.      len = len - (len * 2)
  114.      SEEK('File', len, 'C')
  115.      RETURN 0
  116. /*----------------------------------------------*/
  117.