/* librock/vsil.h - - - - - - - - - - - - Copyright Notice - - - - - - - - - - - - Copyright 1998 Forrest J. Cavalier III See http://www.mibsoftware.com/librock/ for documentation and original copies of this software. This software shall be distributed with the implementation source code according to the librock license terms therein. License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */ /* VSIL - Variable size indexed list. All items in the list are a variable size. A pointer and a size of an item is obtained using an integer index. Items can be inserted, deleted, or replaced in the list. (Modifying an item in place is only possible if the size will remain the same.) A librock_VSIL_s is implemented in separate blocks of allocated memory, each holding a number of items. This allows adding items without copying the entire list. For convenience, a '\0' separates each item. Sequential items may not be adjacent in memory. C++ wrapper: CVsil */ #ifndef librock_INCLUDE_VSIL_H #define librock_INCLUDE_VSIL_H #ifdef __cplusplus class librock_IRWStream; extern "C" { #endif struct librock_VSIL_s { /* VSIL segments. */ struct librock_VSIL_s librock_PTR *next; long baseindex; /* First item has this index. */ int numitems; /* This is size of offlist */ int maxitems; /* Number of items available before expansion required */ int segmentsize; /* Bytes until end. */ int flags; /* 8-4-95: */ #define librock_VSIL_0 1 /* Bit 0: append a zero */ }; struct librock_VSIL_s librock_PTR *librock_VSIL_alloc(); struct librock_VSIL_s librock_PTR *librock_VSIL_alloc0(); void librock_VSIL_free(struct librock_VSIL_s librock_PTR *m); int librock_VSIL_cbAll(struct librock_VSIL_s librock_PTR *m,long librock_PTR *items,long librock_PTR *storage); int librock_VSIL_cbItem(struct librock_VSIL_s librock_PTR *m,long index); int librock_VSIL_copy(struct librock_VSIL_s librock_PTR *m,long index,char librock_PTR *buffer); const char librock_PTR *librock_VSIL_point(struct librock_VSIL_s librock_PTR *m,long index); int librock_VSIL_put(struct librock_VSIL_s librock_PTR *m,long index,const char librock_PTR *buffer,int newsize); int librock_VSIL_delete(struct librock_VSIL_s librock_PTR *m,long index); int librock_VSIL_insert(struct librock_VSIL_s librock_PTR *m,long index,const char librock_PTR *buffer,int newsize); int librock_VSIL_insertNTS(struct librock_VSIL_s librock_PTR *m,long index,const char librock_PTR *buffer); int librock_VSIL_LoadText(struct librock_VSIL_s librock_PTR *fbuf,librock_FILE *f); /* Splits at EOL, strips EOL */ void librock_VSIL_WriteText(struct librock_VSIL_s librock_PTR *fbuf,librock_FILE *f); /* Inserts \n */ int librock_ITERwordsinVSIL(struct librock_VSIL_s librock_PTR *src,long librock_PTR *pLine,int librock_PTR *pOffset); #ifdef __cplusplus }; #endif #ifdef __cplusplus const char *librock_VSILstorebin(struct librock_VSIL_s librock_PTR *vsilSrc,const char librock_PTR *lpszTag,librock_IRWStream *dest); const char *VSILload1bin(const char librock_PTR *lpszTag,librock_IRWStream *src,void librock_PTR * librock_PTR *lplpRet,short librock_PTR *lpcbRet); /* CVsil A Class wrapped around the VSIL data type. Features added above struct VSIL features: Edit buffer Range operations Character acceptance at a position Clipboard I/O LoadText and WriteText functions. (DEBUG: shouldn't these be separate? Search for text (DEBUG: currently untested) */ class librock_PTR librock_CVsil /* Was _far */ { /* As of 1/24/96 not derived from CObject: we don't use any of that functionality anyway (Can't use CArchive to save, no dumping, no diagnostics, no dynamic creation. ) */ public: librock_CVsil(void); librock_CVsil(struct librock_VSIL_s librock_PTR *v) { /* 6/3/96 */ m_image = v; m_numlines = -1; /* Unknown 10/4/96 */ }; struct librock_VSIL_s librock_PTR *Detach() { /* 6/3/96 */ struct librock_VSIL_s librock_PTR *i; i = m_image; m_image = 0; return i; }; public: virtual ~librock_CVsil(); protected: struct librock_VSIL_s librock_PTR *m_image; /* public access through vsil() */ long m_numlines; /* public access through VSILlinecount() This is set to -1 if unknown. Should not be used, even in implementation: call VSILlinecount() instead. */ protected: /* Operations to contents */ public: /* Primitive operations:Status/Reading */ virtual long VSILlinecount(void); virtual int VSILlinesize(long y); virtual const char librock_PTR *VSILlinepoint(long y); virtual void copy(long y,char librock_PTR *block); /* Primitive operations:Editing/Writing entire lines */ virtual void VSILlinedelete(long y); virtual void VSILlineinsert(long y,const char librock_PTR *block,int len); virtual void VSILlineput(long y,const char librock_PTR *block,int len); virtual void VSILlineappend(const char librock_PTR *block,int len); /* Appends at EOF */ void Clear(); /* Operations: Other */ struct librock_VSIL_s librock_PTR *vsil(void) { m_numlines = -1; /* Show unknown 10/4/96 */ return m_image; }; /* 5-20-96 */ }; #endif /* __cplusplus */ #endif /* librock_INCLUDE_VSIL_H */ /* $Log: vsil.h,v $ Revision 1.1 2002/03/17 06:04:45 forrest@mibsoftware.com rights=#1 Initial rights#1 Copyright (c) Forrest J Cavalier III d-b-a Mib Software rights#1 License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */