dat.h 11 KB

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