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