home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd1.bin / zkuste / delphi / kolekce / d567 / FLEXCEL.ZIP / XLSAdapter / KOLE2Import.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-09-26  |  5.6 KB  |  180 lines

  1. unit KOLE2Import;
  2. {$A8}{$Z4}
  3.  
  4. interface
  5. uses Libc;
  6. const
  7.   libgnomeole2 = 'libgnomeole2.so.0';
  8.   //Comment former line and uncomment following 2 lines for static link
  9.   //{$L 'libgnomeole2.o'}
  10.   //libgnomeole2='';
  11.  
  12. type
  13.   mode_t = Longword;
  14.   ssize_t = size_t;
  15.   off_t = Longint;
  16.   caddr_t = Longint;
  17.  
  18.   PPPChar= ^PPChar;
  19.  
  20.   gboolean= LongBool;
  21.   gint32= Longint;
  22.   guint32= LongWord;
  23.   guint8 = byte;
  24.   pguint8 = ^guint8;
  25.   gint = integer;
  26.   pgint = ^gint;
  27.  
  28.   TMsOleErr = (
  29.     MS_OLE_ERR_OK,
  30.     MS_OLE_ERR_EXIST,
  31.     MS_OLE_ERR_INVALID,
  32.     MS_OLE_ERR_FORMAT,
  33.     MS_OLE_ERR_PERM,
  34.     MS_OLE_ERR_MEM,
  35.     MS_OLE_ERR_SPACE,
  36.     MS_OLE_ERR_NOTEMPTY,
  37.     MS_OLE_ERR_BADARG
  38.   );
  39.  
  40.   TMsOleSeek = (
  41.     MsOleSeekSet,
  42.     MsOleSeekCur,
  43.     MsOleSeekEnd
  44.   );
  45.  
  46.   TMsOleType = (
  47.     MsOleStorageT = 1,
  48.     MsOleStreamT  = 2,
  49.     MsOleRootT    = 5
  50.   );
  51.  
  52.   TMsOlePos = guint32;
  53.   TMsOleSPos = gint32;
  54.  
  55.   _MsOleSysWrappers = record
  56. {    int     (*open2)    (const char *pathname, int flags);
  57.     int     (*open3)    (const char *pathname, int flags, mode_t mode);
  58.     ssize_t (*read)        (int fd, void *buf, size_t count);
  59.     int     (*close)    (int fd);
  60.     ssize_t (*write)    (int fd, const void *buf, size_t count);
  61.     off_t   (*lseek)    (int fd, off_t offset, int whence);
  62.     int     (*isregfile)    (int fd);
  63.     int     (*getfilesize)    (int fd, guint32 *size);
  64.  
  65.     /* Optionaly implementable */
  66.     void   *(*mmap)         (void *start, size_t length, int prot,
  67.                  int flags, int fd, off_t offset);
  68.     int     (*munmap)       (void *start, size_t length);
  69. }  end;
  70.  
  71.   TMsOleSysWrappers = _MsOleSysWrappers;
  72.   PMsOleSysWrappers = ^TMsOleSysWrappers;
  73.  
  74. // **
  75. // * Structure describing an OLE file
  76. // **
  77.   PGArray= pointer;
  78.  
  79.   _MsOle = record
  80.     ref_count: Longint;
  81.     ole_mmap: gboolean;
  82.     mem: ^guint8;
  83.     length: guint32;
  84.     syswrap: PMsOleSysWrappers;
  85.  
  86.     mode: char;
  87.     file_des: integer;
  88.     dirty: integer;
  89.     bb: PGArray;      { Big  blocks status  }
  90.     sb: PGArray;      { Small block status  }
  91.     sbf: PGArray;     { The small block file }
  92.     num_pps: guint32;  { Count of number of property sets }
  93.     pps: pointer;     { Property Storage -> struct _PPS, always 1 valid entry or NULL }
  94.     // if memory mapped
  95.     bbattr: pointer;  { Pointers to block structures }
  96.     // end if memory mapped
  97.   end;
  98.  
  99.  
  100.   _MsOleStat = record
  101.     oleType: TMsOleType;
  102.     size: TMsOlePos;
  103.   end;
  104.  
  105.   TMsOle            = _MsOle;
  106.   PMsOle           = ^TMsOle;
  107.   PPMsOle          = ^PMsOle;
  108.   TMsOleStat        = _MsOleStat;
  109.   PMsOleStat       = ^TMsOleStat;
  110.  
  111. /////////////////////////////////////////////////// Methods ////////////////////
  112.   function ms_ole_open (fs: PPMsOle; const path: PChar): TMsOleErr;
  113.   function ms_ole_open_vfs (fs: PPMsOle; const path: PChar; try_mmap: gboolean; wrappers: PMsOleSysWrappers): TMsOleErr; cdecl; external libgnomeole2;
  114.  
  115.   function ms_ole_create (fs: PPMsOle; const path: PChar): TMsOleErr;
  116.   function ms_ole_create_vfs (fs: PPMsOle; const path: PChar; try_mmap: gboolean; wrappers: PMsOleSysWrappers): TMsOleErr; cdecl; external libgnomeole2;
  117.  
  118.   procedure ms_ole_destroy (fs: PPMsOle); cdecl; external libgnomeole2;
  119.  
  120.   function ms_ole_unlink (fs: PMsOle; const path: PChar): TMsOleErr; cdecl; external libgnomeole2;
  121.   function ms_ole_directory (names: PPPChar; fs: PMsOle; const dirpath: PChar): TMsOleErr; cdecl; external libgnomeole2;
  122.   function ms_ole_stat (stat: PMsOleStat;fs: PMsOle; const dirpath: PChar; const name: PChar): TMsOleErr; cdecl; external libgnomeole2;
  123.  
  124.  
  125. //////////////////////////////////////////////////// Streams ///////////////////
  126. type
  127.    P1MsOleStream = pointer; //until a better way...
  128.  
  129.    TRead_Copy = function (stream: P1MsOleStream; ptr:  Pguint8; length: TMsOlePos): gint; cdecl;
  130.    TRead_Ptr  = function (stream: P1MsOleStream; length: TMsOlePos):guint8; cdecl;
  131.    TLSeek     = function (stream: P1MsOleStream; bytes: TMsOleSPos; oleType: TMsOleSeek): TMsOleSPos; cdecl;
  132.    TTell      = function (stream: P1MsOleStream): TMsOlePos; cdecl;
  133.    TWrite     = function (stream: P1MsOleStream; ptr:  Pguint8; length: TMsOlePos): TMsOlePos; cdecl;
  134.  
  135.   _MsOleStream = record
  136.     size: TMsOlePos;
  137.     read_copy: TRead_Copy;
  138.     read_ptr : TRead_Ptr;
  139.     lseek    : TLSeek;
  140.     tell     : TTell;
  141.     write    : TWrite;
  142.  
  143.     // Private.
  144.      _type: byte;
  145.     afile: PMsOle;
  146.     pps: pointer;        // Straight PPS
  147.     blocks: pointer;        // A list of the blocks in the file
  148.                     // if NULL: no file
  149.     position: TMsOlePos;    // Current offset into file.
  150.                 // Points to the next byte to read
  151.   end;
  152.  
  153.   TMsOleStream = _MsOleStream;
  154.   PMsOleStream = ^TMsOleStream;
  155.   PPMsOleStream =^PMsOleStream;
  156.  
  157.   function ms_ole_stream_open  (const stream: PPMsOleStream;fs: PMsOle; const dirpath: PChar; const name: PChar; mode: char): TMsOleErr; cdecl; external libgnomeole2;
  158.   function ms_ole_stream_close (const stream: PPMsOleStream): TMsOleErr; cdecl; external libgnomeole2;
  159.   function ms_ole_stream_duplicate (const stream_copy: PPMsOleStream; const stream: PMsOleStream): TMsOleErr; cdecl; external libgnomeole2;
  160.  
  161.   procedure ms_ole_dump (const ptr: Pguint8; len: guint32); cdecl; external libgnomeole2;
  162.   procedure ms_ole_ref (fs: PMsOle); cdecl; external libgnomeole2;
  163.   procedure ms_ole_unref (fs: PMsOle); cdecl; external libgnomeole2;
  164.   procedure ms_ole_debug (fs: PMsOle); cdecl; external libgnomeole2;
  165.  
  166.  
  167. implementation
  168.  
  169. function ms_ole_open (fs: PPMsOle; const path: PChar): TMsOleErr;
  170. begin
  171.   Result:=ms_ole_open_vfs (fs, path, True, Nil);
  172. end;
  173.  
  174. function ms_ole_create (fs: PPMsOle; const path: PChar): TMsOleErr;
  175. begin
  176.   Result:=ms_ole_create_vfs (fs, path, True, Nil);
  177. end;
  178.  
  179. end.
  180.