dat.h 11 KB

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