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

  1. /*-- Rev Header - do NOT edit!
  2.  *
  3.  *  Filename : editfile.cc
  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.     /*
  26.      * C++-Includes, C++-Definitionen
  27.      *
  28.      */
  29.  
  30. #include "editfile.h"
  31.  
  32.  
  33. void editfile::_intern_editfile(BPTR fh)
  34. {
  35.     index=0;
  36.     mem=0;
  37.     strings=0;
  38.  
  39.     goodflag=FALSE;        /* not successful */
  40.  
  41.     if(size=GetFileSize(fh))
  42.     {
  43.         if(mem=(char *)AllocVec(size+1,MEMF_ANY))
  44.         {
  45.             LONG temp_len = Read(fh, mem,size);
  46.  
  47.             if(temp_len == size)
  48.             {
  49.                 char *t=mem;
  50.  
  51.                 *(t+size)=0;    // Buffer Null-Terminieren
  52.  
  53.                 // Alle 0x0a durch 0x00 ersetzen und dabei Anzahl merken
  54.  
  55.                 for(strings=0 ; t< (mem+size); t++)
  56.                 {
  57.  
  58.                     // im File war schon eine 0...
  59.  
  60.                     if(!*t) { strings++; }
  61.  
  62.  
  63.                     // aus \n 0 machen...
  64.  
  65.                     if(*t=='\n') { *t=0; strings++; }
  66.  
  67.                 }
  68.  
  69.  
  70.                 // Speicher für Tabelle holen
  71.  
  72.                 if(index=(char **)AllocVec((strings+1)*4,MEMF_ANY))
  73.                 {
  74.  
  75.                     // Indextabelle erstellen...
  76.  
  77.                     ULONG x;
  78.  
  79.                     char *start=mem;
  80.  
  81.                     for(x=0, t=mem; t < (mem+size); t++)
  82.                     {
  83.                         if(! (*t))
  84.                         {
  85.                             index[x]=start;
  86.                             start=t+1;
  87.                             x++;
  88.                         }
  89.                     }
  90.  
  91.                     index[x]=0;
  92.  
  93.                     goodflag=TRUE;
  94.  
  95.                     // FreeVec in destructor
  96.                 }
  97.                 else
  98.                 {
  99.                     // out of memory
  100.  
  101.                     err.DosError(ERROR_NO_FREE_STORE);
  102.                 }
  103.  
  104.             }
  105.             else
  106.             {
  107.                 // Read-Error
  108.  
  109.                 err.NotifyError("read error occurred !");
  110.             }
  111.  
  112.             // FreeVec in destructor
  113.         }
  114.         else
  115.         {
  116.             // no mem
  117.  
  118.             err.DosError(ERROR_NO_FREE_STORE);
  119.         }
  120.     }
  121.     else
  122.     {
  123.         // no file-length
  124.  
  125.         err.DosError(ERROR_OBJECT_WRONG_TYPE);
  126.     }
  127. }
  128.  
  129.  
  130.