home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / www / afc / afc-dir / iffparser_examples.lha / Examples / IFFParser_Example.e < prev    next >
Text File  |  1997-09-09  |  3KB  |  86 lines

  1. /*
  2. ** IFFParser_oo Example 1
  3. **
  4. ** Here you will see how to
  5. ** write some chunks and then read them again!
  6. **
  7. ** This code is meant for demostration only.
  8. **
  9. ** Feel free of examine, modify or rip it!
  10. **
  11. ** (C)Copyright 1997 Amiga Foundation Classes.
  12. **
  13. ** PD Source Code.
  14. **
  15. */
  16.  
  17. MODULE 'afc/IFFParser',     -> Our MAGIC MODULE!
  18.        'afc/explain_exception'
  19.  
  20. PROC main() HANDLE              -> NOTE: Exception handling!
  21.   DEF iff:PTR TO iffparser      -> OBJECT instance
  22.   DEF buf[128]:STRING           -> a STRING ;)
  23.   DEF s:PTR TO CHAR
  24.  
  25.   NEW iff.iffparser()           -> Let's create it!
  26.  
  27.   iff.save('Ram:Test.IFF')      -> First Of ALL let's save an ugly IFF file
  28.   iff.createchunk("DEMO","FORM") -> This is the FORM chunk!
  29.  
  30.   iff.createchunk("DEMO","FTXT") -> This is a FTXT (not exactly 8) chunk!
  31.   StrCopy(buf, 'DO you like my object?')  -> Here we fill our STRING...
  32.   iff.writechunk(buf, StrLen(buf)+1)    -> AND write it into the chunk!
  33.   iff.closechunk()                 -> AND THEN we close the chunk...
  34.  
  35.   iff.createchunk("DEMO","FTXT") -> Another chunk!
  36.   StrCopy(buf, 'Is not that easy TO create IFF files with this object?')
  37.   iff.writechunk(buf, StrLen(buf)+1)
  38.   iff.closechunk()
  39.  
  40.   iff.createchunk("DEMO","FTXT")  -> AND the last FTXT chunk!
  41.   StrCopy(buf, 'What a kind of magic!')
  42.   iff.writechunk(buf, StrLen(buf)+1)
  43.   iff.closechunk()
  44.  
  45.   iff.createchunk("DEMO","INFO") -> Whaaaat?!?! a nek kind of chunk!
  46.   StrCopy(buf, 'Hello ALL, I\qm the INFO chunk!')
  47.   iff.writechunk(buf, StrLen(buf)+1)
  48.   iff.closechunk()
  49.  
  50.   iff.closechunk()               -> Here we close DEMO FORM chunk!
  51.   iff.close()                    -> AND here we close IFF save file session.
  52.  
  53.   iff.getheader(buf,'Ram:Test.IFF') -> What kind of file we created?
  54.   WriteF('\s\n', buf)
  55.  
  56.  
  57.   iff.load('Ram:Test.IFF')
  58.   iff.setscan("DEMO","FTXT")  -> Let's load ALL FTXT chunks!
  59.   iff.setscan("DEMO","INFO")  -> Let's load ALL INFO chunks also!
  60.   iff.exit("DEMO","FORM")     -> We will stop when FORM ends!
  61.  
  62.   iff.scan()                  -> Here comes the sun!
  63.  
  64.   IF (s:=iff.first("DEMO","INFO"))   -> Here we pos TO the first INFO chunk
  65.     REPEAT
  66.       WriteF('INFO txt:\s\n', s)     -> We WriteF() it
  67.     UNTIL (s:=iff.succ()) = FALSE    -> AND get the next one
  68.   ENDIF
  69.  
  70.   IF (s:=iff.first("DEMO","FTXT"))   -> Here we pos TO the first FTXT chunk
  71.     REPEAT
  72.       WriteF('FTXT txt:\s\n', s)     -> We WriteF() it
  73.     UNTIL (s:=iff.succ()) = FALSE    -> AND get the next one
  74.   ENDIF
  75.  
  76.   iff.close()                        -> Here we close ALL resources
  77.  
  78.  
  79. EXCEPT DO
  80.   WriteF('Here we die!\n')
  81.   explain_exception()
  82.   END iff                            -> ALWAYS END the OBJECT before exiting!!!!
  83.   CleanUp(0)
  84. ENDPROC
  85.  
  86.