dat.h 12 KB

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