home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / examples / add / normal / editfile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  2.6 KB  |  157 lines

  1. /*-- Rev Header - do NOT edit!
  2.  *
  3.  *  Filename : editfile.h
  4.  *  Purpose  : Eine Klasse, die das Bearbeiten von Files erleichtert
  5.  *
  6.  *  Program  : -
  7.  *  Author   : Gerhard Müller
  8.  *  Copyright: (c) by Gerhard Müller
  9.  *  Creation : Tue Sep  7 02:26:39 1993
  10.  *
  11.  *  compile  :
  12.  *
  13.  *  Compile version  : 0.1
  14.  *  Ext. Version     : 0.1
  15.  *
  16.  *  REVISION HISTORY
  17.  *
  18.  *  Date                     Comment
  19.  *  ------------------------ -------------------------------------------------
  20.  *  Fri Sep 17 00:45:42 1993 Took from CED_Help, seems to work quite well
  21.  *
  22.  *-- REV_END --
  23.  */
  24.  
  25. #ifndef ADD_EDITFILE_H
  26. #define ADD_EDITFILE_H
  27.  
  28.     /*
  29.      * C-Includes, C-Definitionen
  30.      *
  31.      */
  32.  
  33. #define class _class
  34. #define template _template
  35.  
  36. extern "C" {
  37. #include <exec/types.h>
  38. #include <exec/execbase.h>
  39. #include <exec/memory.h>
  40. #include <clib/alib_protos.h>
  41. #include <clib/alib_stdio_protos.h>
  42. #include <utility/tagitem.h>
  43. #include <inline/stubs.h>
  44. #include <dos/dos.h>
  45. #include <dos/dosextens.h>
  46. #ifdef __OPTIMIZE__
  47. #include <inline/exec.h>
  48. #include <inline/dos.h>
  49. #else
  50. #include <clib/exec_protos.h>
  51. #include <clib/dos_protos.h>
  52. #endif
  53. }
  54.  
  55. #undef template
  56. #undef class
  57.  
  58.  
  59.     /*
  60.      * C++-Includes, C++-Definitionen
  61.      *
  62.      */
  63.  
  64. #include "add.h"        // we call GetFileSize()
  65. #include "OwnError.h"
  66.  
  67. class editfile {
  68.  
  69. private:
  70.     ULONG    size;    // Länge des Files
  71.     char    *mem;    // Zeiger auf Speicher im RAM
  72.     BOOL    goodflag; // Öffnen erfolgreich ? Ja=TRUE
  73.  
  74.     void _intern_editfile(BPTR fh);
  75.  
  76. public:
  77.  
  78.     char    **index;    // Zeiger auf Array von Char-Pointern (0-terminitert)
  79.  
  80. /*
  81.  
  82.        ---> |----|
  83.             |    | --> "String 1"
  84.             |----|
  85.             |    | --> "String 2"
  86.             |----|
  87.                .
  88.                .
  89.                .
  90.             |----|
  91.             |    | --> "String n"
  92.             |----|
  93.             |    | --> 0
  94.             |----|
  95.  
  96. */
  97.  
  98.     ULONG    strings;    // Anzahl Strings in Tabelle
  99.  
  100.     inline editfile(BPTR fh);
  101.     inline editfile(char *filename);
  102.  
  103.     ~editfile()
  104.     {
  105.         if(index) FreeVec(index);
  106.         if(mem) FreeVec(mem);
  107.     }
  108.  
  109.     inline BOOL editfile::good();
  110.     inline BOOL editfile::bad();
  111.  
  112. };
  113.  
  114.  
  115. inline editfile::editfile(char *filename)
  116. {
  117.     BPTR    fh;                // filehandle
  118.  
  119.     err.Clear();            // clear out all previous errors
  120.  
  121.     index=0;                // clear all private variables
  122.     mem=0;
  123.  
  124.     if(fh=Open((unsigned char *)filename,MODE_OLDFILE))
  125.     {
  126.         _intern_editfile((BPTR) fh);
  127.  
  128.         Close(fh);
  129.     }
  130.     else
  131.     {
  132.         // kein File
  133.  
  134.         err.DosError(IoErr());
  135.     }
  136. }
  137.  
  138. inline editfile::editfile(BPTR fh)
  139. {
  140.     err.Clear();            // clear out all previous errors
  141.     _intern_editfile((BPTR) fh);
  142. }
  143.  
  144.  
  145.  
  146. inline BOOL editfile::good()
  147. {
  148.     return goodflag;
  149. }
  150.  
  151. inline BOOL editfile::bad()
  152. {
  153.     return !goodflag;
  154. }
  155.  
  156. #endif
  157.