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