dat.h 12 KB

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