dat.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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. Qlog,
  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. u64 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. u32 org;
  172. u32 q0;
  173. u32 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. u32 eq0; /* start of typing for ESC */
  183. u32 cq0; /* cache position */
  184. int ncache; /* storage for insert */
  185. int ncachealloc;
  186. Rune *cache;
  187. int nofill;
  188. };
  189. unsigned int textbacknl(Text*, unsigned int, unsigned int);
  190. unsigned int textbsinsert(Text*, unsigned int, Rune*,
  191. unsigned int, int, int*);
  192. int textbswidth(Text*, Rune);
  193. int textclickmatch(Text*, int, int, int, unsigned int*);
  194. void textclose(Text*);
  195. void textcolumnate(Text*, Dirlist**, int);
  196. void textcommit(Text*, int);
  197. void textconstrain(Text*, unsigned int, unsigned int,
  198. unsigned int*, unsigned int*);
  199. void textdelete(Text*, unsigned int, unsigned int, int);
  200. void textdoubleclick(Text*, unsigned int*, unsigned int*);
  201. void textfill(Text*);
  202. void textframescroll(Text*, int);
  203. void textinit(Text*, File*, Rectangle, Reffont*, Image**);
  204. void textinsert(Text*, unsigned int, Rune*, unsigned int,
  205. int);
  206. unsigned int textload(Text*, unsigned int, char*, int);
  207. Rune textreadc(Text*, unsigned int);
  208. void textredraw(Text*, Rectangle, Font*, Image*, int);
  209. void textreset(Text*);
  210. int textresize(Text*, Rectangle);
  211. void textscrdraw(Text*);
  212. void textscroll(Text*, int);
  213. void textselect(Text*);
  214. int textselect2(Text*, unsigned int*, unsigned int*, Text**);
  215. int textselect23(Text*, unsigned int*, unsigned int*, Image*, 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. u8 isdir;
  229. u8 isscratch;
  230. u8 filemenu;
  231. u8 dirty;
  232. u8 autoindent;
  233. int id;
  234. Range addr;
  235. Range limit;
  236. u8 nopen[QMAX];
  237. u8 nomark;
  238. u8 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. u32 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. u8 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. u8 rpart[UTFmax];
  369. int logoff;
  370. };
  371. struct Xfid
  372. {
  373. void *arg; /* args to xfidinit */
  374. Fcall Fcall;
  375. Xfid *next;
  376. Channel *c; /* chan(void(*)(Xfid*)) */
  377. Fid *f;
  378. u8 *buf;
  379. int flushed;
  380. };
  381. void xfidctl(void *);
  382. void xfidflush(Xfid*);
  383. void xfidopen(Xfid*);
  384. void xfidclose(Xfid*);
  385. void xfidread(Xfid*);
  386. void xfidwrite(Xfid*);
  387. void xfidctlwrite(Xfid*, Window*);
  388. void xfideventread(Xfid*, Window*);
  389. void xfideventwrite(Xfid*, Window*);
  390. void xfidindexread(Xfid*);
  391. void xfidutfread(Xfid*, Text*, unsigned int, int);
  392. int xfidruneread(Xfid*, Text*, unsigned int, unsigned int);
  393. void xfidlogopen(Xfid*);
  394. void xfidlogread(Xfid*);
  395. void xfidlogflush(Xfid*);
  396. void xfidlog(Window*, char*);
  397. struct Reffont
  398. {
  399. Ref Ref;
  400. Font *f;
  401. };
  402. Reffont *rfget(int, int, int, char*);
  403. void rfclose(Reffont*);
  404. struct Rangeset
  405. {
  406. Range r[NRange];
  407. };
  408. struct Dirlist
  409. {
  410. Rune *r;
  411. int nr;
  412. int wid;
  413. };
  414. struct Expand
  415. {
  416. unsigned int q0;
  417. unsigned int q1;
  418. Rune *name;
  419. int nname;
  420. char *bname;
  421. int jump;
  422. union{
  423. Text *at;
  424. Rune *ar;
  425. };
  426. int (*agetc)(void*, unsigned int);
  427. int a0;
  428. int a1;
  429. };
  430. enum
  431. {
  432. /* fbufalloc() guarantees room off end of BUFSIZE */
  433. BUFSIZE = Maxblock+IOHDRSZ, /* size from fbufalloc() */
  434. RBUFSIZE = BUFSIZE/sizeof(Rune),
  435. EVENTSIZE = 256,
  436. Scrollwid = 12, /* width of scroll bar */
  437. Scrollgap = 4, /* gap right of scroll bar */
  438. Margin = 4, /* margin around text */
  439. Border = 2, /* line between rows, cols, windows */
  440. };
  441. #define QID(w,q) ((w<<8)|(q))
  442. #define WIN(q) ((((u32)(q).path)>>8) & 0xFFFFFF)
  443. #define FILE(q) ((q).path & 0xFF)
  444. enum
  445. {
  446. FALSE,
  447. TRUE,
  448. XXX,
  449. };
  450. enum
  451. {
  452. Empty = 0,
  453. Null = '-',
  454. Delete = 'd',
  455. Insert = 'i',
  456. Replace = 'r',
  457. Filename = 'f',
  458. };
  459. enum /* editing */
  460. {
  461. Inactive = 0,
  462. Inserting,
  463. Collecting,
  464. };
  465. unsigned int globalincref;
  466. unsigned int seq;
  467. unsigned int maxtab; /* size of a tab, in units of the '0' character */
  468. Display *display;
  469. Image *screen;
  470. Font *font;
  471. Mouse *mouse;
  472. Mousectl *mousectl;
  473. Keyboardctl *keyboardctl;
  474. Reffont reffont;
  475. Image *modbutton;
  476. Image *colbutton;
  477. Image *button;
  478. Image *but2col;
  479. Image *but3col;
  480. Cursor boxcursor;
  481. Row row;
  482. int timerpid;
  483. Disk *disk;
  484. Text *seltext;
  485. Text *argtext;
  486. Text *mousetext; /* global because Text.close needs to clear it */
  487. Text *typetext; /* global because Text.close needs to clear it */
  488. Text *barttext; /* shared between mousetask and keyboardthread */
  489. int bartflag;
  490. Window *activewin;
  491. Column *activecol;
  492. Buffer snarfbuf;
  493. Rectangle nullrect;
  494. int fsyspid;
  495. char *cputype;
  496. char *objtype;
  497. char *home;
  498. char *fontnames[2];
  499. char acmeerrorfile[128];
  500. Image *tagcols[NCOL];
  501. Image *textcols[NCOL];
  502. int plumbsendfd;
  503. int plumbeditfd;
  504. char wdir[512];
  505. int editing;
  506. int messagesize; /* negotiated in 9P version setup */
  507. int globalautoindent;
  508. enum
  509. {
  510. Kscrolloneup = KF|0x20,
  511. Kscrollonedown = KF|0x21,
  512. };
  513. Channel *cplumb; /* chan(Plumbmsg*) */
  514. Channel *cwait; /* chan(Waitmsg) */
  515. Channel *ccommand; /* chan(Command*) */
  516. Channel *ckill; /* chan(Rune*) */
  517. Channel *cxfidalloc; /* chan(Xfid*) */
  518. Channel *cxfidfree; /* chan(Xfid*) */
  519. Channel *cnewwindow; /* chan(Channel*) */
  520. Channel *mouseexit0; /* chan(int) */
  521. Channel *mouseexit1; /* chan(int) */
  522. Channel *cexit; /* chan(int) */
  523. Channel *cerr; /* chan(char*) */
  524. Channel *cedit; /* chan(int) */
  525. Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */
  526. #define STACK 8192