1 enum 2 { 3 Qdir, 4 Qacme, 5 Qcons, 6 Qconsctl, 7 Qdraw, 8 Qeditout, 9 Qindex, 10 Qlabel, 11 Qnew, 12 13 QWaddr, 14 QWbody, 15 QWctl, 16 QWdata, 17 QWeditout, 18 QWerrors, 19 QWevent, 20 QWrdsel, 21 QWwrsel, 22 QWtag, 23 QWxdata, 24 QMAX, 25 }; 26 27 enum 28 { 29 Blockincr = 256, 30 Maxblock = 8*1024, 31 NRange = 10, 32 Infinity = 0x7FFFFFFF, /* huge value for regexp address */ 33 }; 34 35 typedef struct Block Block; 36 typedef struct Buffer Buffer; 37 typedef struct Command Command; 38 typedef struct Column Column; 39 typedef struct Dirlist Dirlist; 40 typedef struct Dirtab Dirtab; 41 typedef struct Disk Disk; 42 typedef struct Expand Expand; 43 typedef struct Fid Fid; 44 typedef struct File File; 45 typedef struct Elog Elog; 46 typedef struct Mntdir Mntdir; 47 typedef struct Range Range; 48 typedef struct Rangeset Rangeset; 49 typedef struct Reffont Reffont; 50 typedef struct Row Row; 51 typedef struct Runestr Runestr; 52 typedef struct Text Text; 53 typedef struct Timer Timer; 54 typedef struct Window Window; 55 typedef struct Xfid Xfid; 56 57 struct Runestr 58 { 59 Rune *r; 60 int nr; 61 }; 62 63 struct Range 64 { 65 int q0; 66 int q1; 67 }; 68 69 struct Block 70 { 71 uint addr; /* disk address in bytes */ 72 union 73 { 74 uint n; /* number of used runes in block */ 75 Block *next; /* pointer to next in free list */ 76 }; 77 }; 78 79 struct Disk 80 { 81 int fd; 82 uint addr; /* length of temp file */ 83 Block *free[Maxblock/Blockincr+1]; 84 }; 85 86 Disk* diskinit(void); 87 Block* disknewblock(Disk*, uint); 88 void diskrelease(Disk*, Block*); 89 void diskread(Disk*, Block*, Rune*, uint); 90 void diskwrite(Disk*, Block**, Rune*, uint); 91 92 struct Buffer 93 { 94 uint nc; 95 Rune *c; /* cache */ 96 uint cnc; /* bytes in cache */ 97 uint cmax; /* size of allocated cache */ 98 uint cq; /* position of cache */ 99 int cdirty; /* cache needs to be written */ 100 uint cbi; /* index of cache Block */ 101 Block **bl; /* array of blocks */ 102 uint nbl; /* number of blocks */ 103 }; 104 void bufinsert(Buffer*, uint, Rune*, uint); 105 void bufdelete(Buffer*, uint, uint); 106 uint bufload(Buffer*, uint, int, int*); 107 void bufread(Buffer*, uint, Rune*, uint); 108 void bufclose(Buffer*); 109 void bufreset(Buffer*); 110 111 struct Elog 112 { 113 short type; /* Delete, Insert, Filename */ 114 uint q0; /* location of change (unused in f) */ 115 uint nd; /* number of deleted characters */ 116 uint nr; /* # runes in string or file name */ 117 Rune *r; 118 }; 119 void elogterm(File*); 120 void elogclose(File*); 121 void eloginsert(File*, int, Rune*, int); 122 void elogdelete(File*, int, int); 123 void elogreplace(File*, int, int, Rune*, int); 124 void elogapply(File*); 125 126 struct File 127 { 128 Buffer; /* the data */ 129 Buffer delta; /* transcript of changes */ 130 Buffer epsilon; /* inversion of delta for redo */ 131 Buffer *elogbuf; /* log of pending editor changes */ 132 Elog elog; /* current pending change */ 133 Rune *name; /* name of associated file */ 134 int nname; /* size of name */ 135 uvlong qidpath; /* of file when read */ 136 uint mtime; /* of file when read */ 137 int dev; /* of file when read */ 138 int unread; /* file has not been read from disk */ 139 int editclean; /* mark clean after edit command */ 140 141 int seq; /* if seq==0, File acts like Buffer */ 142 int mod; 143 Text *curtext; /* most recently used associated text */ 144 Text **text; /* list of associated texts */ 145 int ntext; 146 int dumpid; /* used in dumping zeroxed windows */ 147 }; 148 File* fileaddtext(File*, Text*); 149 void fileclose(File*); 150 void filedelete(File*, uint, uint); 151 void filedeltext(File*, Text*); 152 void fileinsert(File*, uint, Rune*, uint); 153 uint fileload(File*, uint, int, int*); 154 void filemark(File*); 155 void filereset(File*); 156 void filesetname(File*, Rune*, int); 157 void fileundelete(File*, Buffer*, uint, uint); 158 void fileuninsert(File*, Buffer*, uint, uint); 159 void fileunsetname(File*, Buffer*); 160 void fileundo(File*, int, uint*, uint*); 161 uint fileredoseq(File*); 162 163 enum /* Text.what */ 164 { 165 Columntag, 166 Rowtag, 167 Tag, 168 Body, 169 }; 170 171 struct Text 172 { 173 File *file; 174 Frame; 175 Reffont *reffont; 176 uint org; 177 uint q0; 178 uint q1; 179 int what; 180 int tabstop; 181 Window *w; 182 Rectangle scrollr; 183 Rectangle lastsr; 184 Rectangle all; 185 Row *row; 186 Column *col; 187 188 uint eq0; /* start of typing for ESC */ 189 uint cq0; /* cache position */ 190 int ncache; /* storage for insert */ 191 int ncachealloc; 192 Rune *cache; 193 int nofill; 194 }; 195 196 uint textbacknl(Text*, uint, uint); 197 uint textbsinsert(Text*, uint, Rune*, uint, int, int*); 198 int textbswidth(Text*, Rune); 199 int textclickmatch(Text*, int, int, int, uint*); 200 void textclose(Text*); 201 void textcolumnate(Text*, Dirlist**, int); 202 void textcommit(Text*, int); 203 void textconstrain(Text*, uint, uint, uint*, uint*); 204 void textdelete(Text*, uint, uint, int); 205 void textdoubleclick(Text*, uint*, uint*); 206 void textfill(Text*); 207 void textframescroll(Text*, int); 208 void textinit(Text*, File*, Rectangle, Reffont*, Image**); 209 void textinsert(Text*, uint, Rune*, uint, int); 210 uint textload(Text*, uint, char*, int); 211 Rune textreadc(Text*, uint); 212 void textredraw(Text*, Rectangle, Font*, Image*, int); 213 void textreset(Text*); 214 int textresize(Text*, Rectangle); 215 void textscrdraw(Text*); 216 void textscroll(Text*, int); 217 void textselect(Text*); 218 int textselect2(Text*, uint*, uint*, Text**); 219 int textselect23(Text*, uint*, uint*, Image*, int); 220 int textselect3(Text*, uint*, uint*); 221 void textsetorigin(Text*, uint, int); 222 void textsetselect(Text*, uint, uint); 223 void textshow(Text*, uint, uint, int); 224 void texttype(Text*, Rune); 225 226 struct Window 227 { 228 QLock; 229 Ref; 230 Text tag; 231 Text body; 232 Rectangle r; 233 uchar isdir; 234 uchar isscratch; 235 uchar filemenu; 236 uchar dirty; 237 uchar autoindent; 238 int id; 239 Range addr; 240 Range limit; 241 uchar nopen[QMAX]; 242 uchar nomark; 243 uchar noscroll; 244 Range wrselrange; 245 int rdselfd; 246 Column *col; 247 Xfid *eventx; 248 char *events; 249 int nevents; 250 int owner; 251 int maxlines; 252 Dirlist **dlp; 253 int ndl; 254 int putseq; 255 int nincl; 256 Rune **incl; 257 Reffont *reffont; 258 QLock ctllock; 259 uint ctlfid; 260 char *dumpstr; 261 char *dumpdir; 262 int dumpid; 263 int utflastqid; 264 int utflastboff; 265 int utflastq; 266 }; 267 268 void wininit(Window*, Window*, Rectangle); 269 void winlock(Window*, int); 270 void winlock1(Window*, int); 271 void winunlock(Window*); 272 void wintype(Window*, Text*, Rune); 273 void winundo(Window*, int); 274 void winsetname(Window*, Rune*, int); 275 void winsettag(Window*); 276 void winsettag1(Window*); 277 void wincommit(Window*, Text*); 278 int winresize(Window*, Rectangle, int); 279 void winclose(Window*); 280 void windelete(Window*); 281 int winclean(Window*, int); 282 void windirfree(Window*); 283 void winevent(Window*, char*, ...); 284 void winmousebut(Window*); 285 void winaddincl(Window*, Rune*, int); 286 void wincleartag(Window*); 287 char *winctlprint(Window*, char*, int); 288 289 struct Column 290 { 291 Rectangle r; 292 Text tag; 293 Row *row; 294 Window **w; 295 int nw; 296 int safe; 297 }; 298 299 void colinit(Column*, Rectangle); 300 Window* coladd(Column*, Window*, Window*, int); 301 void colclose(Column*, Window*, int); 302 void colcloseall(Column*); 303 void colresize(Column*, Rectangle); 304 Text* colwhich(Column*, Point); 305 void coldragwin(Column*, Window*, int); 306 void colgrow(Column*, Window*, int); 307 int colclean(Column*); 308 void colsort(Column*); 309 void colmousebut(Column*); 310 311 struct Row 312 { 313 QLock; 314 Rectangle r; 315 Text tag; 316 Column **col; 317 int ncol; 318 319 }; 320 321 void rowinit(Row*, Rectangle); 322 Column* rowadd(Row*, Column *c, int); 323 void rowclose(Row*, Column*, int); 324 Text* rowwhich(Row*, Point); 325 Column* rowwhichcol(Row*, Point); 326 void rowresize(Row*, Rectangle); 327 Text* rowtype(Row*, Rune, Point); 328 void rowdragcol(Row*, Column*, int but); 329 int rowclean(Row*); 330 void rowdump(Row*, char*); 331 int rowload(Row*, char*, int); 332 void rowloadfonts(char*); 333 334 struct Timer 335 { 336 int dt; 337 int cancel; 338 Channel *c; /* chan(int) */ 339 Timer *next; 340 }; 341 342 struct Command 343 { 344 int pid; 345 Rune *name; 346 int nname; 347 char *text; 348 char **av; 349 int iseditcmd; 350 Mntdir *md; 351 Command *next; 352 }; 353 354 struct Dirtab 355 { 356 char *name; 357 uchar type; 358 uint qid; 359 uint perm; 360 }; 361 362 struct Mntdir 363 { 364 int id; 365 int ref; 366 Rune *dir; 367 int ndir; 368 Mntdir *next; 369 int nincl; 370 Rune **incl; 371 }; 372 373 struct Fid 374 { 375 int fid; 376 int busy; 377 int open; 378 Qid qid; 379 Window *w; 380 Dirtab *dir; 381 Fid *next; 382 Mntdir *mntdir; 383 int nrpart; 384 uchar rpart[UTFmax]; 385 }; 386 387 388 struct Xfid 389 { 390 void *arg; /* args to xfidinit */ 391 Fcall; 392 Xfid *next; 393 Channel *c; /* chan(void(*)(Xfid*)) */ 394 Fid *f; 395 uchar *buf; 396 int flushed; 397 398 }; 399 400 void xfidctl(void *); 401 void xfidflush(Xfid*); 402 void xfidopen(Xfid*); 403 void xfidclose(Xfid*); 404 void xfidread(Xfid*); 405 void xfidwrite(Xfid*); 406 void xfidctlwrite(Xfid*, Window*); 407 void xfideventread(Xfid*, Window*); 408 void xfideventwrite(Xfid*, Window*); 409 void xfidindexread(Xfid*); 410 void xfidutfread(Xfid*, Text*, uint, int); 411 int xfidruneread(Xfid*, Text*, uint, uint); 412 413 struct Reffont 414 { 415 Ref; 416 Font *f; 417 418 }; 419 Reffont *rfget(int, int, int, char*); 420 void rfclose(Reffont*); 421 422 struct Rangeset 423 { 424 Range r[NRange]; 425 }; 426 427 struct Dirlist 428 { 429 Rune *r; 430 int nr; 431 int wid; 432 }; 433 434 struct Expand 435 { 436 uint q0; 437 uint q1; 438 Rune *name; 439 int nname; 440 char *bname; 441 int jump; 442 union{ 443 Text *at; 444 Rune *ar; 445 }; 446 int (*agetc)(void*, uint); 447 int a0; 448 int a1; 449 }; 450 451 enum 452 { 453 /* fbufalloc() guarantees room off end of BUFSIZE */ 454 BUFSIZE = Maxblock+IOHDRSZ, /* size from fbufalloc() */ 455 RBUFSIZE = BUFSIZE/sizeof(Rune), 456 EVENTSIZE = 256, 457 Scrollwid = 12, /* width of scroll bar */ 458 Scrollgap = 4, /* gap right of scroll bar */ 459 Margin = 4, /* margin around text */ 460 Border = 2, /* line between rows, cols, windows */ 461 }; 462 463 #define QID(w,q) ((w<<8)|(q)) 464 #define WIN(q) ((((ulong)(q).path)>>8) & 0xFFFFFF) 465 #define FILE(q) ((q).path & 0xFF) 466 467 enum 468 { 469 FALSE, 470 TRUE, 471 XXX, 472 }; 473 474 enum 475 { 476 Empty = 0, 477 Null = '-', 478 Delete = 'd', 479 Insert = 'i', 480 Replace = 'r', 481 Filename = 'f', 482 }; 483 484 enum /* editing */ 485 { 486 Inactive = 0, 487 Inserting, 488 Collecting, 489 }; 490 491 uint globalincref; 492 uint seq; 493 uint maxtab; /* size of a tab, in units of the '0' character */ 494 495 Display *display; 496 Image *screen; 497 Font *font; 498 Mouse *mouse; 499 Mousectl *mousectl; 500 Keyboardctl *keyboardctl; 501 Reffont reffont; 502 Image *modbutton; 503 Image *colbutton; 504 Image *button; 505 Image *but2col; 506 Image *but3col; 507 Cursor boxcursor; 508 Row row; 509 int timerpid; 510 Disk *disk; 511 Text *seltext; 512 Text *argtext; 513 Text *mousetext; /* global because Text.close needs to clear it */ 514 Text *typetext; /* global because Text.close needs to clear it */ 515 Text *barttext; /* shared between mousetask and keyboardthread */ 516 int bartflag; 517 Window *activewin; 518 Column *activecol; 519 Buffer snarfbuf; 520 Rectangle nullrect; 521 int fsyspid; 522 char *cputype; 523 char *objtype; 524 char *home; 525 char *fontnames[2]; 526 char acmeerrorfile[128]; 527 Image *tagcols[NCOL]; 528 Image *textcols[NCOL]; 529 int plumbsendfd; 530 int plumbeditfd; 531 char wdir[]; 532 int editing; 533 int messagesize; /* negotiated in 9P version setup */ 534 int globalautoindent; 535 536 enum 537 { 538 Kscrolloneup = KF|0x20, 539 Kscrollonedown = KF|0x21, 540 }; 541 542 Channel *cplumb; /* chan(Plumbmsg*) */ 543 Channel *cwait; /* chan(Waitmsg) */ 544 Channel *ccommand; /* chan(Command*) */ 545 Channel *ckill; /* chan(Rune*) */ 546 Channel *cxfidalloc; /* chan(Xfid*) */ 547 Channel *cxfidfree; /* chan(Xfid*) */ 548 Channel *cnewwindow; /* chan(Channel*) */ 549 Channel *mouseexit0; /* chan(int) */ 550 Channel *mouseexit1; /* chan(int) */ 551 Channel *cexit; /* chan(int) */ 552 Channel *cerr; /* chan(char*) */ 553 Channel *cedit; /* chan(int) */ 554 Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */ 555 556 #define STACK 8192 557