dat.h (11770B)
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 = 32*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 int reverse; 458 union{ 459 Text *at; 460 Rune *ar; 461 } u; 462 int (*agetc)(void*, uint); 463 int a0; 464 int a1; 465 }; 466 467 enum 468 { 469 /* fbufalloc() guarantees room off end of BUFSIZE */ 470 BUFSIZE = Maxblock+IOHDRSZ, /* size from fbufalloc() */ 471 RBUFSIZE = BUFSIZE/sizeof(Rune), 472 EVENTSIZE = 256, 473 }; 474 475 #define Scrollwid scalesize(display, 12) 476 #define Scrollgap scalesize(display, 4) 477 #define Margin scalesize(display, 4) 478 #define Border scalesize(display, 2) 479 #define ButtonBorder scalesize(display, 2) 480 481 #define QID(w,q) ((w<<8)|(q)) 482 #define WIN(q) ((((ulong)(q).path)>>8) & 0xFFFFFF) 483 #define FILE(q) ((q).path & 0xFF) 484 485 #undef FALSE 486 #undef TRUE 487 488 enum 489 { 490 FALSE, 491 TRUE, 492 XXX 493 }; 494 495 enum 496 { 497 Empty = 0, 498 Null = '-', 499 Delete = 'd', 500 Insert = 'i', 501 Replace = 'r', 502 Filename = 'f' 503 }; 504 505 enum /* editing */ 506 { 507 Inactive = 0, 508 Inserting, 509 Collecting 510 }; 511 512 uint globalincref; 513 uint seq; 514 uint maxtab; /* size of a tab, in units of the '0' character */ 515 516 Display *display; 517 Image *screen; 518 Font *font; 519 Mouse *mouse; 520 Mousectl *mousectl; 521 Keyboardctl *keyboardctl; 522 Reffont reffont; 523 Image *modbutton; 524 Image *colbutton; 525 Image *button; 526 Image *but2col; 527 Image *but3col; 528 Cursor boxcursor; 529 Cursor2 boxcursor2; 530 Row row; 531 int timerpid; 532 Disk *disk; 533 Text *seltext; 534 Text *argtext; 535 Text *mousetext; /* global because Text.close needs to clear it */ 536 Text *typetext; /* global because Text.close needs to clear it */ 537 Text *barttext; /* shared between mousetask and keyboardthread */ 538 int bartflag; 539 int swapscrollbuttons; 540 Window *activewin; 541 Column *activecol; 542 Buffer snarfbuf; 543 Rectangle nullrect; 544 int fsyspid; 545 char *cputype; 546 char *objtype; 547 char *home; 548 char *acmeshell; 549 char *fontnames[2]; 550 Image *tagcols[NCOL]; 551 Image *textcols[NCOL]; 552 extern char wdir[]; /* must use extern because no dimension given */ 553 int editing; 554 int erroutfd; 555 int messagesize; /* negotiated in 9P version setup */ 556 int globalautoindent; 557 int dodollarsigns; 558 char* mtpt; 559 560 enum 561 { 562 Kscrolloneup = KF|0x20, 563 Kscrollonedown = KF|0x21 564 }; 565 566 Channel *cplumb; /* chan(Plumbmsg*) */ 567 Channel *cwait; /* chan(Waitmsg) */ 568 Channel *ccommand; /* chan(Command*) */ 569 Channel *ckill; /* chan(Rune*) */ 570 Channel *cxfidalloc; /* chan(Xfid*) */ 571 Channel *cxfidfree; /* chan(Xfid*) */ 572 Channel *cnewwindow; /* chan(Channel*) */ 573 Channel *mouseexit0; /* chan(int) */ 574 Channel *mouseexit1; /* chan(int) */ 575 Channel *cexit; /* chan(int) */ 576 Channel *cerr; /* chan(char*) */ 577 Channel *cedit; /* chan(int) */ 578 Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */ 579 580 QLock editoutlk; 581 582 #define STACK 65536