7 #define waitfor samwaitfor
13 #define class samclass
16 * BLOCKSIZE is relatively small to keep memory consumption down.
19 #define BLOCKSIZE 2048
20 #define RUNESIZE sizeof(Rune)
22 #define NBUFFILES 3+2*NDISC /* plan 9+undo+snarf+NDISC*(transcript+buf) */
28 #undef INFINITY /* Darwin declares this as HUGE_VAL */
29 #define INFINITY 0x7FFFFFFFL
31 #define STRSIZE (2*BLOCKSIZE)
33 typedef long Posn; /* file position or address */
34 typedef ushort Mod; /* modification number */
36 typedef struct Address Address;
37 typedef struct Block Block;
38 typedef struct Buffer Buffer;
39 typedef struct Disk Disk;
40 typedef struct File File;
41 typedef struct List List;
42 typedef struct Range Range;
43 typedef struct Rangeset Rangeset;
44 typedef struct String String;
76 struct List /* code depends on a long being able to hold a pointer */
78 int type; /* 'p' for pointer, 'P' for Posn */
90 #define listptr g.listp
91 #define voidpptr g.voidp
92 #define posnptr g.posnp
93 #define stringpptr g.stringp
94 #define filepptr g.filep
101 BUFSIZE = Maxblock, /* size from fbufalloc() */
102 RBUFSIZE = BUFSIZE/sizeof(Rune)
118 vlong addr; /* disk address in bytes */
120 uint n; /* number of used runes in block */
121 Block *next; /* pointer to next in free list */
128 vlong addr; /* length of temp file */
129 Block *free[Maxblock/Blockincr+1];
132 Disk* diskinit(void);
133 Block* disknewblock(Disk*, uint);
134 void diskrelease(Disk*, Block*);
135 void diskread(Disk*, Block*, Rune*, uint);
136 void diskwrite(Disk*, Block**, Rune*, uint);
142 uint cnc; /* bytes in cache */
143 uint cmax; /* size of allocated cache */
144 uint cq; /* position of cache */
145 int cdirty; /* cache needs to be written */
146 uint cbi; /* index of cache Block */
147 Block **bl; /* array of blocks */
148 uint nbl; /* number of blocks */
150 void bufinsert(Buffer*, uint, Rune*, uint);
151 void bufdelete(Buffer*, uint, uint);
152 uint bufload(Buffer*, uint, int, int*);
153 void bufread(Buffer*, uint, Rune*, uint);
154 void bufclose(Buffer*);
155 void bufreset(Buffer*);
159 Buffer b; /* the data */
160 Buffer delta; /* transcript of changes */
161 Buffer epsilon; /* inversion of delta for redo */
162 String name; /* name of associated file */
163 uvlong qidpath; /* of file when read */
164 uint mtime; /* of file when read */
165 ulong dev; /* of file when read */
166 int unread; /* file has not been read from disk */
168 long seq; /* if seq==0, File acts like Buffer */
169 long cleanseq; /* f->seq at last read/write of file */
170 int mod; /* file appears modified in menu */
171 char rescuing; /* sam exiting; this file unusable */
174 // Text *curtext; /* most recently used associated text */
175 // Text **text; /* list of associated texts */
177 // int dumpid; /* used in dumping zeroxed windows */
180 Posn hiposn; /* highest address touched this Mod */
181 Address dot; /* current position */
182 Address ndot; /* new current position after update */
183 Range tdot; /* what terminal thinks is current range */
184 Range mark; /* tagged spot in text (don't confuse with Mark) */
185 List *rasp; /* map of what terminal's got */
186 short tag; /* for communicating with terminal */
187 char closeok; /* ok to close file? */
188 char deleted; /* delete at completion of command */
189 Range prevdot; /* state before start of change */
194 /*File* fileaddtext(File*, Text*); */
195 void fileclose(File*);
196 void filedelete(File*, uint, uint);
197 /*void filedeltext(File*, Text*); */
198 void fileinsert(File*, uint, Rune*, uint);
199 uint fileload(File*, uint, int, int*);
200 void filemark(File*);
201 void filereset(File*);
202 void filesetname(File*, String*);
203 void fileundelete(File*, Buffer*, uint, uint);
204 void fileuninsert(File*, Buffer*, uint, uint);
205 void fileunsetname(File*, Buffer*);
206 void fileundo(File*, int, int, uint*, uint*, int);
207 int fileupdate(File*, int, int);
209 int filereadc(File*, uint);
210 File *fileopen(void);
211 void loginsert(File*, uint, Rune*, uint);
212 void logdelete(File*, uint, uint);
213 void logsetname(File*, String*);
214 int fileisdirty(File*);
215 long undoseq(File*, int);
216 long prevseq(Buffer*);
218 void raspload(File*);
219 void raspstart(File*);
220 void raspdelete(File*, uint, uint, int);
221 void raspinsert(File*, uint, Rune*, uint, int);
222 void raspdone(File*, int);
223 void raspflush(File*);
228 void* fbufalloc(void);
229 void fbuffree(void*);
230 uint min(uint, uint);
231 void cvttorunes(char*, int, Rune*, int*, int*, int*);
233 #define runemalloc(a) (Rune*)emalloc((a)*sizeof(Rune))
234 #define runerealloc(a, b) (Rune*)realloc((a), (b)*sizeof(Rune))
235 #define runemove(a, b, c) memmove((a), (b), (c)*sizeof(Rune))
238 int Read(int, void*, int);
239 void Seek(int, long, int);
240 int plan9(File*, int, String*, int);
241 int Write(int, void*, int);
243 int bexecute(File*, Posn);
245 void closefiles(File*, String*);
248 void cmdupdate(void);
249 void compile(String*);
250 void copy(File*, Address);
251 File *current(File*);
254 void dellist(List*, int);
255 void doubleclick(File*, Posn);
256 void dprint(char*, ...);
257 void edit(File*, int);
258 void *emalloc(ulong);
259 void *erealloc(void*, ulong);
261 void error_c(Err, int);
262 void error_r(Err, char*);
263 void error_s(Err, char*);
264 int execute(File*, Posn, Posn);
265 int filematch(File*, String*);
266 void filename(File*);
267 void fixname(String*);
268 void fullname(String*);
270 File *getfile(String*);
271 int getname(File*, String*, int);
273 void hiccough(char*);
274 void inslist(List*, int, ...);
275 Address lineaddr(Posn, Address, int);
276 List *listalloc(int);
277 void listfree(List*);
279 File *lookfile(String*);
280 void lookorigin(File*, Posn, Posn);
282 void move(File*, Address);
283 void moveto(File*, Range);
285 void nextmatch(File*, String*, Posn, int);
287 void notifyf(void*, char*);
289 void printposn(File*, int);
290 void print_ss(char*, String*, String*);
291 void print_s(char*, String*);
293 Range rdata(List*, Posn, Posn);
294 Posn readio(File*, int*, int, int);
299 void rgrow(List*, Posn, Posn);
301 void settempfile(void);
303 void snarf(File*, Posn, Posn, Buffer*, int);
304 void sortname(File*);
305 void startup(char*, int, char**, char**);
306 void state(File*, int);
307 int statfd(int, ulong*, uvlong*, long*, long*, long*);
308 int statfile(char*, ulong*, uvlong*, long*, long*, long*);
309 void Straddc(String*, int);
310 void Strclose(String*);
311 int Strcmp(String*, String*);
312 void Strdelete(String*, Posn, Posn);
313 void Strdupl(String*, Rune*);
314 void Strduplstr(String*, String*);
315 void Strinit(String*);
316 void Strinit0(String*);
317 void Strinsert(String*, String*, Posn);
318 void Strinsure(String*, ulong);
319 int Strispre(String*, String*);
320 void Strzero(String*);
322 char *Strtoc(String*);
323 void syserror(char*);
326 String *tmpcstr(char*);
327 String *tmprstr(Rune*, int);
328 void freetmpstr(String*);
329 void termcommand(void);
330 void termwrite(char*);
331 File *tofile(String*);
332 void trytoclose(File*);
333 void trytoquit(void);
338 void warn_s(Warn, char*);
339 void warn_SS(Warn, String*, String*);
340 void warn_S(Warn, String*);
341 int whichmenu(File*);
345 extern Rune samname[]; /* compiler dependent */
347 extern Rune *right[];
349 extern char RSAM[]; /* system dependent */
350 extern char SAMTERM[];
352 extern char TMPDIR[];
354 extern char SHPATH[];
356 extern char RXPATH[];
364 extern char *rsamname; /* globals */
365 extern char *samterm;
366 extern Rune genbuf[];
372 extern Buffer snarfbuf;
373 extern Buffer plan9buf;
375 extern List tempfile;
377 extern File *curfile;
378 extern File *lastfile;
381 extern Posn cmdptadv;
384 extern String cmdstr;
385 extern String genstr;
386 extern String lastpat;
387 extern String lastregexp;
388 extern String plan9cmd;
389 extern int downloaded;
392 extern int panicking;
394 extern int termlocked;
395 extern int outbuffered;
399 void outTs(Hmesg, int);
401 void outTl(Hmesg, long);
402 void outTslS(Hmesg, int, long, String*);
403 void outTS(Hmesg, String*);
404 void outTsS(Hmesg, int, String*);
405 void outTsllS(Hmesg, int, long, long, String*);
406 void outTsll(Hmesg, int, long, long);
407 void outTsl(Hmesg, int, long);
408 void outTsv(Hmesg, int, vlong);
410 int needoutflush(void);