dat.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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*, int);
  215. int textselect3(Text*, unsigned int*, unsigned int*);
  216. void textsetorigin(Text*, unsigned int, int);
  217. void textsetselect(Text*, unsigned int, unsigned int);
  218. void textshow(Text*, unsigned int, unsigned int, int);
  219. void texttype(Text*, Rune);
  220. struct Window
  221. {
  222. QLock QLock;
  223. Ref Ref;
  224. Text tag;
  225. Text body;
  226. Rectangle r;
  227. uint8_t isdir;
  228. uint8_t isscratch;
  229. uint8_t filemenu;
  230. uint8_t dirty;
  231. uint8_t autoindent;
  232. int id;
  233. Range addr;
  234. Range limit;
  235. uint8_t nopen[QMAX];
  236. uint8_t nomark;
  237. uint8_t noscroll;
  238. Range wrselrange;
  239. int rdselfd;
  240. Column *col;
  241. Xfid *eventx;
  242. char *events;
  243. int nevents;
  244. int owner;
  245. int maxlines;
  246. Dirlist **dlp;
  247. int ndl;
  248. int putseq;
  249. int nincl;
  250. Rune **incl;
  251. Reffont *reffont;
  252. QLock ctllock;
  253. uint ctlfid;
  254. char *dumpstr;
  255. char *dumpdir;
  256. int dumpid;
  257. int utflastqid;
  258. int utflastboff;
  259. int utflastq;
  260. };
  261. void wininit(Window*, Window*, Rectangle);
  262. void winlock(Window*, int);
  263. void winlock1(Window*, int);
  264. void winunlock(Window*);
  265. void wintype(Window*, Text*, Rune);
  266. void winundo(Window*, int);
  267. void winsetname(Window*, Rune*, int);
  268. void winsettag(Window*);
  269. void winsettag1(Window*);
  270. void wincommit(Window*, Text*);
  271. int winresize(Window*, Rectangle, int);
  272. void winclose(Window*);
  273. void windelete(Window*);
  274. int winclean(Window*, int);
  275. void windirfree(Window*);
  276. void winevent(Window*, char*, ...);
  277. void winmousebut(Window*);
  278. void winaddincl(Window*, Rune*, int);
  279. void wincleartag(Window*);
  280. char *winctlprint(Window*, char*, int);
  281. struct Column
  282. {
  283. Rectangle r;
  284. Text tag;
  285. Row *row;
  286. Window **w;
  287. int nw;
  288. int safe;
  289. };
  290. void colinit(Column*, Rectangle);
  291. Window* coladd(Column*, Window*, Window*, int);
  292. void colclose(Column*, Window*, int);
  293. void colcloseall(Column*);
  294. void colresize(Column*, Rectangle);
  295. Text* colwhich(Column*, Point);
  296. void coldragwin(Column*, Window*, int);
  297. void colgrow(Column*, Window*, int);
  298. int colclean(Column*);
  299. void colsort(Column*);
  300. void colmousebut(Column*);
  301. struct Row
  302. {
  303. QLock QLock;
  304. Rectangle r;
  305. Text tag;
  306. Column **col;
  307. int ncol;
  308. };
  309. void rowinit(Row*, Rectangle);
  310. Column* rowadd(Row*, Column *c, int);
  311. void rowclose(Row*, Column*, int);
  312. Text* rowwhich(Row*, Point);
  313. Column* rowwhichcol(Row*, Point);
  314. void rowresize(Row*, Rectangle);
  315. Text* rowtype(Row*, Rune, Point);
  316. void rowdragcol(Row*, Column*, int but);
  317. int rowclean(Row*);
  318. void rowdump(Row*, char*);
  319. int rowload(Row*, char*, int);
  320. void rowloadfonts(char*);
  321. struct Timer
  322. {
  323. int dt;
  324. int cancel;
  325. Channel *c; /* chan(int) */
  326. Timer *next;
  327. };
  328. struct Command
  329. {
  330. int pid;
  331. Rune *name;
  332. int nname;
  333. char *text;
  334. char **av;
  335. int iseditcmd;
  336. Mntdir *md;
  337. Command *next;
  338. };
  339. struct Dirtab
  340. {
  341. char *name;
  342. uint8_t type;
  343. unsigned int qid;
  344. unsigned int perm;
  345. };
  346. struct Mntdir
  347. {
  348. int id;
  349. int ref;
  350. Rune *dir;
  351. int ndir;
  352. Mntdir *next;
  353. int nincl;
  354. Rune **incl;
  355. };
  356. struct Fid
  357. {
  358. int fid;
  359. int busy;
  360. int open;
  361. Qid qid;
  362. Window *w;
  363. Dirtab *dir;
  364. Fid *next;
  365. Mntdir *mntdir;
  366. int nrpart;
  367. uint8_t rpart[UTFmax];
  368. };
  369. struct Xfid
  370. {
  371. void *arg; /* args to xfidinit */
  372. Fcall Fcall;
  373. Xfid *next;
  374. Channel *c; /* chan(void(*)(Xfid*)) */
  375. Fid *f;
  376. uint8_t *buf;
  377. int flushed;
  378. };
  379. void xfidctl(void *);
  380. void xfidflush(Xfid*);
  381. void xfidopen(Xfid*);
  382. void xfidclose(Xfid*);
  383. void xfidread(Xfid*);
  384. void xfidwrite(Xfid*);
  385. void xfidctlwrite(Xfid*, Window*);
  386. void xfideventread(Xfid*, Window*);
  387. void xfideventwrite(Xfid*, Window*);
  388. void xfidindexread(Xfid*);
  389. void xfidutfread(Xfid*, Text*, unsigned int, int);
  390. int xfidruneread(Xfid*, Text*, unsigned int, unsigned int);
  391. struct Reffont
  392. {
  393. Ref Ref;
  394. Font *f;
  395. };
  396. Reffont *rfget(int, int, int, char*);
  397. void rfclose(Reffont*);
  398. struct Rangeset
  399. {
  400. Range r[NRange];
  401. };
  402. struct Dirlist
  403. {
  404. Rune *r;
  405. int nr;
  406. int wid;
  407. };
  408. struct Expand
  409. {
  410. unsigned int q0;
  411. unsigned int q1;
  412. Rune *name;
  413. int nname;
  414. char *bname;
  415. int jump;
  416. union{
  417. Text *at;
  418. Rune *ar;
  419. };
  420. int (*agetc)(void*, unsigned int);
  421. int a0;
  422. int a1;
  423. };
  424. enum
  425. {
  426. /* fbufalloc() guarantees room off end of BUFSIZE */
  427. BUFSIZE = Maxblock+IOHDRSZ, /* size from fbufalloc() */
  428. RBUFSIZE = BUFSIZE/sizeof(Rune),
  429. EVENTSIZE = 256,
  430. Scrollwid = 12, /* width of scroll bar */
  431. Scrollgap = 4, /* gap right of scroll bar */
  432. Margin = 4, /* margin around text */
  433. Border = 2, /* line between rows, cols, windows */
  434. };
  435. #define QID(w,q) ((w<<8)|(q))
  436. #define WIN(q) ((((uint32_t)(q).path)>>8) & 0xFFFFFF)
  437. #define FILE(q) ((q).path & 0xFF)
  438. enum
  439. {
  440. FALSE,
  441. TRUE,
  442. XXX,
  443. };
  444. enum
  445. {
  446. Empty = 0,
  447. Null = '-',
  448. Delete = 'd',
  449. Insert = 'i',
  450. Replace = 'r',
  451. Filename = 'f',
  452. };
  453. enum /* editing */
  454. {
  455. Inactive = 0,
  456. Inserting,
  457. Collecting,
  458. };
  459. unsigned int globalincref;
  460. unsigned int seq;
  461. unsigned int maxtab; /* size of a tab, in units of the '0' character */
  462. Display *display;
  463. Image *screen;
  464. Font *font;
  465. Mouse *mouse;
  466. Mousectl *mousectl;
  467. Keyboardctl *keyboardctl;
  468. Reffont reffont;
  469. Image *modbutton;
  470. Image *colbutton;
  471. Image *button;
  472. Image *but2col;
  473. Image *but3col;
  474. Cursor boxcursor;
  475. Row row;
  476. int timerpid;
  477. Disk *disk;
  478. Text *seltext;
  479. Text *argtext;
  480. Text *mousetext; /* global because Text.close needs to clear it */
  481. Text *typetext; /* global because Text.close needs to clear it */
  482. Text *barttext; /* shared between mousetask and keyboardthread */
  483. int bartflag;
  484. Window *activewin;
  485. Column *activecol;
  486. Buffer snarfbuf;
  487. Rectangle nullrect;
  488. int fsyspid;
  489. char *cputype;
  490. char *objtype;
  491. char *home;
  492. char *fontnames[2];
  493. char acmeerrorfile[128];
  494. Image *tagcols[NCOL];
  495. Image *textcols[NCOL];
  496. int plumbsendfd;
  497. int plumbeditfd;
  498. char wdir[512];
  499. int editing;
  500. int messagesize; /* negotiated in 9P version setup */
  501. int globalautoindent;
  502. enum
  503. {
  504. Kscrolloneup = KF|0x20,
  505. Kscrollonedown = KF|0x21,
  506. };
  507. Channel *cplumb; /* chan(Plumbmsg*) */
  508. Channel *cwait; /* chan(Waitmsg) */
  509. Channel *ccommand; /* chan(Command*) */
  510. Channel *ckill; /* chan(Rune*) */
  511. Channel *cxfidalloc; /* chan(Xfid*) */
  512. Channel *cxfidfree; /* chan(Xfid*) */
  513. Channel *cnewwindow; /* chan(Channel*) */
  514. Channel *mouseexit0; /* chan(int) */
  515. Channel *mouseexit1; /* chan(int) */
  516. Channel *cexit; /* chan(int) */
  517. Channel *cerr; /* chan(char*) */
  518. Channel *cedit; /* chan(int) */
  519. Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */
  520. #define STACK 8192