7 * BLOCKSIZE is relatively small to keep memory consumption down.
10 #define BLOCKSIZE 2048
11 #define RUNESIZE sizeof(Rune)
13 #define NBUFFILES 3+2*NDISC /* plan 9+undo+snarf+NDISC*(transcript+buf) */
19 #define INFINITY 0x7FFFFFFFL
21 #define STRSIZE (2*BLOCKSIZE)
23 typedef long Posn; /* file position or address */
24 typedef ushort Mod; /* modification number */
26 typedef struct Address Address;
27 typedef struct Block Block;
28 typedef struct Buffer Buffer;
29 typedef struct Disk Disk;
30 typedef struct Discdesc Discdesc;
31 typedef struct File File;
32 typedef struct List List;
33 typedef struct Range Range;
34 typedef struct Rangeset Rangeset;
35 typedef struct String String;
67 struct List /* code depends on a long being able to hold a pointer */
82 #define listptr g.listp
84 #define longptr g.longp
85 #define ucharpptr g.ucharp
86 #define stringpptr g.stringp
87 #define filepptr g.filep
88 #define listval g.listv
95 BUFSIZE = Maxblock, /* size from fbufalloc() */
96 RBUFSIZE = BUFSIZE/sizeof(Rune),
112 uint addr; /* disk address in bytes */
115 uint n; /* number of used runes in block */
116 Block *next; /* pointer to next in free list */
123 uint addr; /* length of temp file */
124 Block *free[Maxblock/Blockincr+1];
127 Disk* diskinit(void);
128 Block* disknewblock(Disk*, uint);
129 void diskrelease(Disk*, Block*);
130 void diskread(Disk*, Block*, Rune*, uint);
131 void diskwrite(Disk*, Block**, Rune*, uint);
137 uint cnc; /* bytes in cache */
138 uint cmax; /* size of allocated cache */
139 uint cq; /* position of cache */
140 int cdirty; /* cache needs to be written */
141 uint cbi; /* index of cache Block */
142 Block **bl; /* array of blocks */
143 uint nbl; /* number of blocks */
145 void bufinsert(Buffer*, uint, Rune*, uint);
146 void bufdelete(Buffer*, uint, uint);
147 uint bufload(Buffer*, uint, int, int*);
148 void bufread(Buffer*, uint, Rune*, uint);
149 void bufclose(Buffer*);
150 void bufreset(Buffer*);
154 Buffer _; /* the data */
155 Buffer delta; /* transcript of changes */
156 Buffer epsilon; /* inversion of delta for redo */
157 String name; /* name of associated file */
158 uvlong qidpath; /* of file when read */
159 uint mtime; /* of file when read */
160 int dev; /* of file when read */
161 int unread; /* file has not been read from disk */
163 long seq; /* if seq==0, File acts like Buffer */
164 long cleanseq; /* f->seq at last read/write of file */
165 int mod; /* file appears modified in menu */
166 char rescuing; /* sam exiting; this file unusable */
168 // Text *curtext; /* most recently used associated text */
169 // Text **text; /* list of associated texts */
171 // int dumpid; /* used in dumping zeroxed windows */
173 Posn hiposn; /* highest address touched this Mod */
174 Address dot; /* current position */
175 Address ndot; /* new current position after update */
176 Range tdot; /* what terminal thinks is current range */
177 Range mark; /* tagged spot in text (don't confuse with Mark) */
178 List *rasp; /* map of what terminal's got */
179 short tag; /* for communicating with terminal */
180 char closeok; /* ok to close file? */
181 char deleted; /* delete at completion of command */
182 Range prevdot; /* state before start of change */
187 //File* fileaddtext(File*, Text*);
188 void fileclose(File*);
189 void filedelete(File*, uint, uint);
190 //void filedeltext(File*, Text*);
191 void fileinsert(File*, uint, Rune*, uint);
192 uint fileload(File*, uint, int, int*);
193 void filemark(File*);
194 void filereset(File*);
195 void filesetname(File*, String*);
196 void fileundelete(File*, Buffer*, uint, uint);
197 void fileuninsert(File*, Buffer*, uint, uint);
198 void fileunsetname(File*, Buffer*);
199 void fileundo(File*, int, int, uint*, uint*, int);
200 int fileupdate(File*, int, int);
202 int filereadc(File*, uint);
203 File *fileopen(void);
204 void loginsert(File*, uint, Rune*, uint);
205 void logdelete(File*, uint, uint);
206 void logsetname(File*, String*);
207 int fileisdirty(File*);
208 long undoseq(File*, int);
209 long prevseq(Buffer*);
211 void raspload(File*);
212 void raspstart(File*);
213 void raspdelete(File*, uint, uint, int);
214 void raspinsert(File*, uint, Rune*, uint, int);
215 void raspdone(File*, int);
220 void* fbufalloc(void);
221 void fbuffree(void*);
222 uint min(uint, uint);
223 void cvttorunes(char*, int, Rune*, int*, int*, int*);
225 #define runemalloc(a) (Rune*)emalloc((a)*sizeof(Rune))
226 #define runerealloc(a, b) (Rune*)realloc((a), (b)*sizeof(Rune))
227 #define runemove(a, b, c) memmove((a), (b), (c)*sizeof(Rune))
230 int Read(int, void*, int);
231 void Seek(int, long, int);
232 int plan9(File*, int, String*, int);
233 int Write(int, void*, int);
234 int bexecute(File*, Posn);
236 void closefiles(File*, String*);
239 void cmdupdate(void);
240 void compile(String*);
241 void copy(File*, Address);
242 File *current(File*);
245 void dellist(List*, int);
246 void doubleclick(File*, Posn);
247 void dprint(char*, ...);
248 void edit(File*, int);
249 void *emalloc(ulong);
250 void *erealloc(void*, ulong);
252 void error_c(Err, int);
253 void error_r(Err, char*);
254 void error_s(Err, char*);
255 int execute(File*, Posn, Posn);
256 int filematch(File*, String*);
257 void filename(File*);
258 void fixname(String*);
259 void fullname(String*);
261 File *getfile(String*);
262 int getname(File*, String*, int);
264 void hiccough(char*);
265 void inslist(List*, int, long);
266 Address lineaddr(Posn, Address, int);
267 void listfree(List*);
269 File *lookfile(String*);
270 void lookorigin(File*, Posn, Posn);
272 void move(File*, Address);
273 void moveto(File*, Range);
275 void nextmatch(File*, String*, Posn, int);
277 void notifyf(void*, char*);
279 void printposn(File*, int);
280 void print_ss(char*, String*, String*);
281 void print_s(char*, String*);
283 Range rdata(List*, Posn, Posn);
284 Posn readio(File*, int*, int, int);
289 void rgrow(List*, Posn, Posn);
291 void settempfile(void);
293 void snarf(File*, Posn, Posn, Buffer*, int);
294 void sortname(File*);
295 void startup(char*, int, char**, char**);
296 void state(File*, int);
297 int statfd(int, ulong*, uvlong*, long*, long*, long*);
298 int statfile(char*, ulong*, uvlong*, long*, long*, long*);
299 void Straddc(String*, int);
300 void Strclose(String*);
301 int Strcmp(String*, String*);
302 void Strdelete(String*, Posn, Posn);
303 void Strdupl(String*, Rune*);
304 void Strduplstr(String*, String*);
305 void Strinit(String*);
306 void Strinit0(String*);
307 void Strinsert(String*, String*, Posn);
308 void Strinsure(String*, ulong);
309 int Strispre(String*, String*);
310 void Strzero(String*);
312 char *Strtoc(String*);
313 void syserror(char*);
316 String *tmpcstr(char*);
317 String *tmprstr(Rune*, int);
318 void freetmpstr(String*);
319 void termcommand(void);
320 void termwrite(char*);
321 File *tofile(String*);
322 void trytoclose(File*);
323 void trytoquit(void);
328 void warn_s(Warn, char*);
329 void warn_SS(Warn, String*, String*);
330 void warn_S(Warn, String*);
331 int whichmenu(File*);
334 Discdesc *Dstart(void);
336 extern Rune samname[]; /* compiler dependent */
338 extern Rune *right[];
340 extern char RSAM[]; /* system dependent */
341 extern char SAMTERM[];
343 extern char TMPDIR[];
345 extern char SHPATH[];
347 extern char RXPATH[];
348 extern char SAMSAVECMD[];
356 extern char *rsamname; /* globals */
357 extern char *samterm;
358 extern Rune genbuf[];
364 extern Buffer snarfbuf;
365 extern Buffer plan9buf;
367 extern List tempfile;
369 extern File *curfile;
370 extern File *lastfile;
373 extern Posn cmdptadv;
376 extern String cmdstr;
377 extern String genstr;
378 extern String lastpat;
379 extern String lastregexp;
380 extern String plan9cmd;
381 extern int downloaded;
384 extern int panicking;
386 extern int termlocked;
391 void outTs(Hmesg, int);
393 void outTl(Hmesg, long);
394 void outTslS(Hmesg, int, long, String*);
395 void outTS(Hmesg, String*);
396 void outTsS(Hmesg, int, String*);
397 void outTsllS(Hmesg, int, long, long, String*);
398 void outTsll(Hmesg, int, long, long);
399 void outTsl(Hmesg, int, long);
400 void outTsv(Hmesg, int, long);
401 void outstart(Hmesg);
402 void outcopy(int, void*);
405 void outvlong(void*);