00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifdef COMMENT
00014
00015 The initials "SB" stand for "String Block" or "String Buffer".
00016
00017 SBBUFFER - A SB buffer containing a sbstring opened for editing.
00018 SBFILE - A structure holding file-specific information for all
00019 SDBLKs pointing to that file.
00020 SBSTRING - A SB string; conceptually a single string, but actually
00021 a linked list of SDBLKs. Unless opened by a SBBUFFER,
00022 only a few operations are allowed on SBSTRINGs (creating,
00023 copying, deleting).
00024 SDBLK - One of the linked nodes constituting a sbstring. Each SDBLK
00025 node points to a continuous string either in memory or
00026 on disk, or both.
00027 SBLK - Another name for SDBLK.
00028 SMBLK - An allocated chunk of memory. Also refers to the node structure
00029 maintained by the SBM memory management routines, which
00030 points to the actual chunk of memory.
00031 SBM - Name of the memory management package. SBM routines are used
00032 to allocate memory in general, and are not just for
00033 use by SB routines.
00034
00035 ************ MACHINE DEPENDENT DEFINITIONS **********
00036
00037 The following compile time definitions represent machine
00038 dependent parameters which are intended mainly for use only by SBM and
00039 SBSTR routines. Other programs should use them with caution. Note
00040 that a great deal of code assumes that type "int" corresponds to a basic
00041 machine word (as per C Reference Manual).
00042
00043 The current definitions will only work for machines which have
00044 1, 2, 4, or 8 "char" bytes in a machine word. Any other size will
00045 require some changes to the definitions and possibly to some places
00046 using them.
00047
00048 WORD - integer-type definition corresponding to machine word.
00049 WDSIZE - # addressable char bytes in a machine word. (1, 2, 4, 8)
00050 WDBITS - # low order bits in an address, ie log2(WDSIZE). (0, 1, 2, 3)
00051 WDMASK - Mask for low order bits of address (0, 1, 3, 7)
00052 CHAR_MASK - If defined, machine does sign-extension on chars, and
00053 they must be masked with this value.
00054
00055 Note that the macro for WDBITS has no mathematical significance
00056 other than being an expression which happens to evaluate into the right
00057 constant for the 4 allowed values of WDSIZE, and in fact it is this
00058 crock which restricts WDSIZE! If C had a base 2 logarithm expression
00059 then any power of 2 could be used.
00060
00061 Values for machines
00062 WORD WDSIZE WDBITS WDMASK
00063 PDP11, Z8000, I8086 int 2 1 01
00064 VAX11, M68000, PDP10 int 4 2 03
00065
00066 #endif
00067
00068
00069
00070 #include "eesite.h"
00071 #ifdef __STDC__
00072 #include <limits.h>
00073 #define _SBMUCHAR 1
00074 #define _SBMCHARSIGN (CHAR_MIN < 0)
00075 #define CHAR_MASK (UCHAR_MAX)
00076
00077 #else
00078 #ifndef _SBMUCHAR
00079 #define _SBMUCHAR 0
00080 #endif
00081 #ifndef _SBMCHARSIGN
00082 #define _SBMCHARSIGN 1
00083 #endif
00084 #ifndef CHAR_MASK
00085 #define CHAR_MASK 0377
00086 #endif
00087 #endif
00088
00089
00090
00091
00092 #if (_SBMUCHAR || (_SBMCHARSIGN==0))
00093 #define sb_uchartoint(a) (a)
00094 #else
00095 #define sb_uchartoint(a) ((a)&CHAR_MASK)
00096 #endif
00097
00098
00099
00100
00101
00102
00103
00104 #define WORD int
00105 #define WDSIZE ((int)(sizeof(WORD)))
00106 #define WDMASK (WDSIZE-1)
00107 #define WDBITS ((WDSIZE>>2)+(1&WDMASK))
00108
00109 #define rnddiv(a) ((a)>>WDBITS)
00110 #define rndrem(a) ((a)&WDMASK)
00111 #define rnddwn(a) ((a)&~WDMASK)
00112 #define rndup(a) rnddwn((a)+WDSIZE-1)
00113
00114 #ifdef COMMENT
00115 #define rnddiv(a) ((a)/WDSIZE)
00116 #define rndrem(a) ((a)%WDSIZE)
00117 #define rnddwn(a) ((a)-rndrem(a))
00118 #define rndup(a) rnddwn((a)+WDSIZE-1)
00119 #undef WDMASK
00120 #undef WDBITS
00121 #endif
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 typedef long chroff;
00132 typedef unsigned int SBMO;
00133 typedef
00134 #if _SBMUCHAR
00135 unsigned
00136 #endif
00137 char *SBMA;
00138
00139
00140
00141
00142
00143
00144 #define SB_NFILES 32
00145
00146 #define SB_BUFSIZ 512
00147 #define SB_SLOP (16*WDSIZE)
00148
00149 #define SMNODES (20)
00150 #define SMCHUNKSIZ (16*512)
00151 #define MAXSBMO ((SBMO)-1)
00152
00153
00154 #define EOF (-1)
00155 #define SBFILE struct sbfile
00156 #define SBBUF struct sbbuffer
00157 #define SBSTR struct sdblk
00158
00159 struct sbfile {
00160 int sfflags;
00161 int sffd;
00162 struct sdblk *sfptr1;
00163 chroff sflen;
00164 };
00165
00166
00167 struct sbbuffer {
00168 SBMA sbiop;
00169 int sbrleft;
00170 int sbwleft;
00171 int sbflags;
00172 chroff sbdot;
00173 chroff sboff;
00174 struct sdblk *sbcur;
00175 };
00176
00177 #define SB_OVW 01
00178 #define SB_WRIT 02
00179
00180
00181
00182
00183
00184
00185
00186 struct sdblk {
00187 struct sdblk *slforw;
00188 struct sdblk *slback;
00189 int sdflags;
00190 struct sdblk *sdforw;
00191 struct sdblk *sdback;
00192 struct smblk *sdmem;
00193 SBFILE *sdfile;
00194 chroff sdlen;
00195 chroff sdaddr;
00196 };
00197
00198 #define SD_LOCK 0100000
00199 #define SD_LCK2 0040000
00200 #define SD_MOD 0020000
00201 #define SD_NID 0323
00202 #define SD_LOCKS (SD_LOCK|SD_LCK2)
00203
00204
00205
00206
00207
00208
00209
00210
00211 struct smblk {
00212 struct smblk *smforw;
00213 struct smblk *smback;
00214 int smflags;
00215 SBMA smaddr;
00216 SBMO smlen;
00217 SBMO smuse;
00218 };
00219
00220 #define SM_USE 0100000
00221 #define SM_NXM 040000
00222 #define SM_EXT 020000
00223 #define SM_MNODS 010000
00224 #define SM_DNODS 04000
00225 #define SM_NID 0315
00226
00227
00228 #define SBMERR 0
00229 #define SBXERR 1
00230 #define SBFERR 2
00231
00232
00233
00234
00235
00236
00237 #define sbm_nfre sbmnfre
00238 #define sbm_nfor sbmnfor
00239 #define sbm_nmov sbmnmov
00240 #define sbm_ngc sbmngc
00241 #define sbx_ndget sbxndg
00242 #define sbx_ndel sbxnde
00243 #define sbx_ndfre sbxndf
00244 #define sbx_sdcpy sbxsdc
00245 #define sbx_sdgc sbxsdg
00246 #define sbe_sdlist sbesls
00247 #define sbe_sdtab sbestb
00248 #define sbe_sds sbesds
00249 #define sbe_sbvfy sbesbv
00250 #define sbe_sbs sbesbs
00251
00252
00253 extern SBMA sbm_lowaddr;
00254
00255 extern SBFILE sbv_tf;
00256 extern int (*sbv_debug)();
00257 extern off_t lseek();
00258 extern char *mktemp();
00259 extern char *malloc();
00260 extern char *calloc();
00261 extern SBBUF *sb_open();
00262 extern SBSTR *sb_close(), *sb_fduse(), *sbs_cpy(), *sbs_app(), *sb_cpyn(),
00263 *sb_killn();
00264 extern struct sdblk *sbx_ready();
00265 extern chroff sb_tell(), sb_ztell(), sbs_len();
00266
00267
00268
00269 #define sb_putc(s,c) (--((s)->sbwleft) >= 0 ? \
00270 (*(s)->sbiop++ = c) : sb_sputc(s,c))
00271 #define sb_getc(s) (--((s)->sbrleft) >= 0 ? \
00272 sb_uchartoint(*(s)->sbiop++) : sb_sgetc(s))
00273 #define sb_peekc(s) ((s)->sbrleft > 0 ? \
00274 sb_uchartoint(*(s)->sbiop) : sb_speekc(s))
00275
00276
00277
00278
00279 #define sb_backc(s) (++(s->sbrleft), --(s->sbiop))
00280
00281 #include "sbproto.h"