home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2591 < prev    next >
Encoding:
Text File  |  1992-11-20  |  53.9 KB  |  2,313 lines

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!world!jhallen
  3. From: jhallen@world.std.com (Joseph H Allen)
  4. Subject: JOE 1.0.5 Part 4 of 10
  5. Message-ID: <By2MIq.KwF@world.std.com>
  6. Organization: The World Public Access UNIX, Brookline, MA
  7. Date: Sat, 21 Nov 1992 14:49:38 GMT
  8. Lines: 2303
  9.  
  10. Submitted-by: jhallen@world.std.com
  11. Archive-name: joe1.0.5part4
  12.  
  13. fi
  14. # ============= help.c ==============
  15. if test -f 'help.c' -a X"$1" != X"-c"; then
  16.     echo 'x - skipping help.c (File already exists)'
  17. else
  18. echo 'x - extracting help.c (Text)'
  19. sed 's/^X//' << 'SHAR_EOF' > 'help.c' &&
  20. /* Help system
  21. X   Copyright (C) 1992 Joseph H. Allen
  22. X
  23. This file is part of JOE (Joe's Own Editor)
  24. X
  25. JOE is free software; you can redistribute it and/or modify it under the 
  26. terms of the GNU General Public License as published by the Free Software 
  27. Foundation; either version 1, or (at your option) any later version.  
  28. X
  29. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  30. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  31. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  32. details.  
  33. X
  34. You should have received a copy of the GNU General Public License along with 
  35. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  36. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  37. X
  38. #include "config.h"
  39. #include "tty.h"
  40. #include "toomany.h"
  41. #include "b.h"
  42. #include "termcap.h"
  43. #include "kbd.h"
  44. #include "scrn.h"
  45. #include "w.h"
  46. #include "menu.h"
  47. #include "help.h"
  48. X
  49. /* The loaded help screen */
  50. X
  51. char *hlptxt=0;
  52. int hlpsiz=0;
  53. int hlpbsz=0;
  54. int hlplns=0;
  55. X
  56. static int uphelp=0;
  57. X
  58. /* Display help text */
  59. X
  60. void dsphlp(t)
  61. SCREEN *t;
  62. {
  63. char *str=hlptxt;
  64. int y,x,c;
  65. int atr=0;
  66. for(y=0;y!=t->wind;++y)
  67. X {
  68. X if(t->t->updtab[y])
  69. X  {
  70. X  for(x=0;x!=t->w-1;++x)
  71. X   if(*str=='\n' || !*str)
  72. X    if(eraeol(t->t,x,y)) return;
  73. X    else break;
  74. X   else
  75. X    {
  76. X    if(*str=='\\')
  77. X     if(str[1]=='i' || str[1]=='u' || str[1]=='I' || str[1]=='U')
  78. X      {
  79. X      if(str[1]=='i' || str[1]=='I') atr^=INVERSE;
  80. X      else atr^=UNDERLINE;
  81. X      str+=2;
  82. X      --x; continue;
  83. X      }
  84. X     else if(str[1]=='\\') c='\\'+atr, str+=2;
  85. X     else { ++str; --x; continue; }
  86. X    else c= (unsigned char)*str++ +atr;
  87. X    if(t->t->scrn[x+y*t->w]!=c)
  88. X     {
  89. X     if(have) return;
  90. X     t->t->scrn[x+y*t->w]=c;
  91. X     outatr(t->t,x,y,c);
  92. X     }
  93. X    }
  94. X  atr=0; t->t->updtab[y]=0;
  95. X  }
  96. X while(*str && *str!='\n') ++str;
  97. X if(*str=='\n') ++str;
  98. X }
  99. }
  100. X
  101. /* Create the help window */
  102. X
  103. void helpon(t)
  104. SCREEN *t;
  105. {
  106. if(!hlptxt) return;
  107. t->wind=hlplns;
  108. if(t->h-t->wind<FITHEIGHT) t->wind=t->h-FITHEIGHT;
  109. if(t->wind<0)
  110. X {
  111. X t->wind=0;
  112. X return;
  113. X }
  114. chsize(t,t->h-t->wind,t->h);
  115. msetI(t->t->updtab,1,t->wind);
  116. }
  117. X
  118. /* Eliminate the help window */
  119. X
  120. void helpoff(t)
  121. SCREEN *t;
  122. {
  123. int z=t->wind;
  124. t->wind=0;
  125. chsize(t,t->h,t->h-z);
  126. }
  127. X
  128. /* Toggle help on/off */
  129. X
  130. void uhelp(w)
  131. W *w;
  132. {
  133. struct help *h;
  134. if(w->huh) if(h=get_help(w->huh))
  135. X {
  136. X if(w->t->wind) helpoff(w->t);
  137. X hlptxt=h->hlptxt;
  138. X hlpsiz=h->hlpsiz;
  139. X hlpbsz=h->hlpbsz;
  140. X hlplns=h->hlplns;
  141. X helpon(w->t);
  142. X return;
  143. X }
  144. uhelpme(w);
  145. }
  146. X
  147. /* Help selection menu */
  148. X
  149. void uheol(w) W *w; { MENU *m=(MENU *)w->object; meol(m); }
  150. void uhbol(w) W *w; { MENU *m=(MENU *)w->object; mbol(m); }
  151. void uheof(w) W *w; { MENU *m=(MENU *)w->object; meof(m); }
  152. void uhbof(w) W *w; { MENU *m=(MENU *)w->object; mbof(m); }
  153. void uhdnarw(w) W *w; { MENU *m=(MENU *)w->object; mdnarw(m); }
  154. void uhuparw(w) W *w; { MENU *m=(MENU *)w->object; muparw(m); }
  155. void uhltarw(w) W *w; { MENU *m=(MENU *)w->object; mltarw(m); }
  156. void uhrtarw(w) W *w; { MENU *m=(MENU *)w->object; mrtarw(m); }
  157. void hdumb() {}
  158. void movehelp(w,x,y) W *w; { MENU *m=(MENU *)w->object; menumove(m,x,y); }
  159. void resizehelp(w,x,y) W *w; { MENU *m=(MENU *)w->object; menuresz(m,x,y); }
  160. void disphelp(w) W *w;
  161. X {
  162. X MENU *m=(MENU *)w->object;
  163. X menugen(m);
  164. X w->cury=0;
  165. X w->curx=(m->cursor-m->top)*(m->width+1);
  166. X }
  167. void followhelp(w) W *w; { MENU *m=(MENU *)w->object; menufllw(m); }
  168. void wkillhelp(w) W *w; { MENU *m=(MENU *)w->object; if(m) menurm(m); }
  169. X
  170. int prevcursor=0;
  171. X
  172. void uhrtn(w)
  173. W *w;
  174. {
  175. MENU *m=(MENU *)w->object;
  176. hlptxt=help_structs[m->cursor]->hlptxt;
  177. hlpsiz=help_structs[m->cursor]->hlpsiz;
  178. hlpbsz=help_structs[m->cursor]->hlpbsz;
  179. hlplns=help_structs[m->cursor]->hlplns;
  180. prevcursor=m->cursor;
  181. wabort(w);
  182. helpon(w->t);
  183. }
  184. X
  185. void uhabort(w)
  186. W *w;
  187. {
  188. MENU *m=(MENU *)w->object;
  189. prevcursor=m->cursor;
  190. wabort(w);
  191. }
  192. X
  193. CONTEXT cthelp= {"help",0};
  194. X
  195. static WATOM watomhelp=
  196. {
  197. &cthelp,
  198. disphelp,
  199. followhelp,
  200. wkillhelp,
  201. resizehelp,
  202. movehelp,
  203. hdumb,
  204. hdumb,
  205. TYPEHELP
  206. };
  207. X
  208. void uhelpme(w)
  209. W *w;
  210. {
  211. W *new;
  212. MENU *m;
  213. if(w->t->wind)
  214. X {
  215. X helpoff(w->t);
  216. X return;
  217. X }
  218. if(!help_names[0]) return;
  219. if(!help_names[1])
  220. X {
  221. X helpon(w->t);
  222. X return;
  223. X }
  224. if(!(new=wcreate(w->t,&watomhelp,w,w,w->main,1,NULL))) return;
  225. new->object=(void *)(m=mkmenu(new->t,help_names,new->x,new->y,new->w,new->h));
  226. m->cursor=prevcursor;
  227. w->t->curwin=new;
  228. }
  229. SHAR_EOF
  230. chmod 0600 help.c ||
  231. echo 'restore of help.c failed'
  232. Wc_c="`wc -c < 'help.c'`"
  233. test 4291 -eq "$Wc_c" ||
  234.     echo 'help.c: original size 4291, current size' "$Wc_c"
  235. fi
  236. # ============= help.h ==============
  237. if test -f 'help.h' -a X"$1" != X"-c"; then
  238.     echo 'x - skipping help.h (File already exists)'
  239. else
  240. echo 'x - extracting help.h (Text)'
  241. sed 's/^X//' << 'SHAR_EOF' > 'help.h' &&
  242. /* Help system
  243. X   Copyright (C) 1992 Joseph H. Allen
  244. X
  245. This file is part of JOE (Joe's Own Editor)
  246. X
  247. JOE is free software; you can redistribute it and/or modify it under the 
  248. terms of the GNU General Public License as published by the Free Software 
  249. Foundation; either version 1, or (at your option) any later version.  
  250. X
  251. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  252. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  253. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  254. details.  
  255. X
  256. You should have received a copy of the GNU General Public License along with 
  257. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  258. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  259. X
  260. #ifndef _Ihelp
  261. #define _Ihelp 1
  262. X
  263. #include "config.h"
  264. #include "kbd.h"
  265. X
  266. extern char *hlptxt;
  267. extern int hlpsiz, hlpbsz, hlplns;
  268. void dsphlp();
  269. X
  270. void uhelp();
  271. X
  272. struct help
  273. X {
  274. X  char *hlptxt;
  275. X  int hlpsiz;
  276. X  int hlpbsz;
  277. X  int hlplns;
  278. X  char *name;
  279. X  struct help *next;
  280. X };
  281. X
  282. #define TYPEHELP 0x800
  283. void uhelpme();
  284. void uhabort();
  285. void uhrtn();
  286. X
  287. void uhrtarw();
  288. void uhltarw();
  289. void uhuparw();
  290. void uhdnarw();
  291. void uhbof();
  292. void uheof();
  293. void uhbol();
  294. void uheol();
  295. X
  296. extern CONTEXT cthelp;
  297. X
  298. extern char **help_names;
  299. extern struct help **help_structs;
  300. X
  301. #endif
  302. SHAR_EOF
  303. chmod 0600 help.h ||
  304. echo 'restore of help.h failed'
  305. Wc_c="`wc -c < 'help.h'`"
  306. test 1306 -eq "$Wc_c" ||
  307.     echo 'help.h: original size 1306, current size' "$Wc_c"
  308. fi
  309. # ============= joerc ==============
  310. if test -f 'joerc' -a X"$1" != X"-c"; then
  311.     echo 'x - skipping joerc (File already exists)'
  312. else
  313. echo 'x - extracting joerc (Text)'
  314. sed 's/^X//' << 'SHAR_EOF' > 'joerc' &&
  315. X                         Initialization file for JOE
  316. X
  317. X JOE looks for this file in:
  318. X    1 - .joerc
  319. X    2 - $HOME/.joerc
  320. X    3 - /usr/local/lib/joerc
  321. X
  322. X FIRST SECTION: Default global options:
  323. X
  324. X Put each option you want set in the first column:
  325. X
  326. X -mid        Cursor is recentered when scrolling is necessary
  327. X -asis        Characters 160 - 254 shown as-is
  328. X -stacol    Column number in status line
  329. X -starow    Row number in status line
  330. X -force        Force final newline when files are saved
  331. X -help        Start with help on
  332. X -pg nnn    No. lines to keep for PgUp/PgDn
  333. X -gtab nnn    Default tab width for prompt windows
  334. X
  335. X SECOND SECTION: File name dependant local option settings:
  336. X
  337. X Each line with '*' in the first column indicates the modes which should be
  338. X files which match the regular expression.  If more than one regular
  339. X expression matches the file name, than the last matching one is chosen.
  340. X
  341. X Here is a list of modes which can be set:
  342. X
  343. X    -wordwrap        Wordwrap
  344. X    -autoindent        Auto indent
  345. X    -overwrite        Overtype mode
  346. X    -lmargin nnn        Left margin
  347. X    -rmargin nnn        Right margin
  348. X    -tab nnn        Tab width
  349. X    -indentc nnn        Indentation character (32 for space, 9 for tab)
  350. X    -istep nnn        Number of indentation columns
  351. *
  352. -wordwrap
  353. X
  354. *.c
  355. -autoindent
  356. X
  357. *.h
  358. -autoindent
  359. X
  360. *akefile
  361. *AKEFILE
  362. *joerc
  363. X
  364. *.p
  365. -autoindent
  366. X
  367. X THIRD SECTION: Named help screens:
  368. X
  369. X Use \i to turn on/off inverse video
  370. X Use \u to turn on/off underline
  371. X
  372. {Basic
  373. \i   Help Screen    turn off with ^KH                                            \i
  374. \i \i\uCURSOR\u           \uGO TO\u            \uBLOCK\u      \uDELETE\u   \uMISC\u         \uEXIT\u      \i \i
  375. \i \i^B left ^F right ^U  prev. screen ^KB begin  ^D char. ^KJ reformat ^KX save  \i \i
  376. \i \i^P up   ^N down  ^V  next screen  ^KK end    ^Y line  ^TT overtype ^C  abort \i \i
  377. \i \i^Z previous word ^A  beg. of line ^KM move   ^W >word `   Ctrl-    ^KZ shell \i \i
  378. \i \i^X next word     ^E  end of line  ^KC copy   ^O word< ^\\  Meta-    \uFILE\u      \i \i
  379. \i \i\uSEARCH\u           ^KU top of file  ^KW file   ^J >line ^R  retype   ^KE new   \i \i
  380. \i \i^KF find text    ^KV end of file  ^KY delete ^_ undo  ^@  insert   ^KR insert\i \i
  381. \i \i^L  find next    ^KL to line No.  ^K/ filter ^^ redo               ^KD save  \i \i
  382. }
  383. X
  384. {Windows
  385. \i   Help Screen    turn off with ^KH                                            \i
  386. \i \i^KO Split the window into two.  You can then use ^KE to load a file into the \i \i
  387. \i \i    new window.                                                              \i \i
  388. \i \i^KG Make current window bigger         ^KT Make current window smaller       \i \i
  389. \i \i^KN Go to the window below             ^KP Go to the window above            \i \i
  390. \i \i^C  Eliminate the current window       ^KI Show all windows / Show one window\i \i
  391. }
  392. X
  393. {Advanced
  394. \i   Help Screen    turn off with ^KH                                            \i
  395. \i \i ESC nn   repeat next command nn times     ^G   goto matching ( [ {          \i \i
  396. \i \i ^K SPACE show position status             ^K-  goto prevous place in        \i \i
  397. \i \i ^K [ 0-9 begin recording macro n               position history             \i \i
  398. \i \i ^K ]     stop recording                   ^K=  goto next place              \i \i
  399. \i \i ^K 0-9   play macro n                     ^K,  indent marked block less     \i \i
  400. \i \i ^K A     center line                      ^K.  indent marked block more     \i \i
  401. \i \i ^T X     rectangle mode                   ^K;  tag search                   \i \i
  402. }
  403. X
  404. {Options
  405. \i   Help Screen    turn off with ^KH                                            \i
  406. \i \i                                Mode Settings                                \i \i
  407. \i \i                                                                             \i \i
  408. \i \i ^TT Insert/Overtype             ^TM Recenter cursor when it goes off window \i \i
  409. \i \i ^TA Autoindent on/off           ^TF Force final NL when files are written   \i \i
  410. \i \i ^TW Wordwrap on/off             ^TH Display characters above 127 as-is      \i \i
  411. \i \i ^TL Left margin                 ^TN Show line number on status line         \i \i
  412. \i \i ^TR Right margin                ^TC Show column number on status line       \i \i
  413. \i \i ^TP No. PgUp/PgDn Lines         ^TD Tab width                               \i \i
  414. \i \i ^TK Indent character            ^TI Indent step column width                \i \i
  415. \i \i ^TX Rectangle mode                                                          \i \i
  416. }
  417. X
  418. {Search
  419. \i   Help Screen    turn off with ^KH                                            \i
  420. \i \iSpecial search sequences:                                                    \i \i
  421. \i \i    \\^     matches beginning of line     \\$     matches end of line          \i \i
  422. \i \i    \\<     matches beginning of word     \\>     matches end of word          \i \i
  423. \i \i    \\?     matches any single character  \\*     matches 0 or more characters \i \i
  424. \i \i    \\c     matches balanced C expression \\\\     matches a \\                  \i \i
  425. \i \i    \\[..]  matches one of a set          \\n     matches a newline            \i \i
  426. \i \i    \\+     matches 0 or more of the character which follows the \\+           \i \i
  427. \i \iSpecial replace sequences:                                                   \i \i
  428. \i \i    \\&     replaced with text which matched search string                    \i \i
  429. \i \i    \\0 - 9 replaced with text which matched Nth \\*, \\?, \\c, \\+, or \\[..]     \i \i
  430. \i \i    \\\\     replaced with \\               \\n     replaced with newline        \i \i
  431. }
  432. X
  433. {Names
  434. \i   Help Screen    turn off with ^KH                                            \i
  435. \i \i Hit TAB at file name prompts to generate menu of file names                 \i \i
  436. \i \i Or use up/down keys to access history of previously entered names           \i \i
  437. \i \i Special file names:                                                         \i \i
  438. \i \i      !command                 Pipe in/out of a shell command                \i \i
  439. \i \i      >>filename               Append to a file                              \i \i
  440. \i \i      -                        Read/Write to/from standard I/O               \i \i
  441. \i \i      filename,START,SIZE      Read/Write a part of a file/device            \i \i
  442. \i \i          Give START/SIZE in decimal (255), octal (0377) or hex (0xFF)       \i \i
  443. }
  444. X
  445. {Joe
  446. \i   Help Screen    turn off with ^KH                                            \i
  447. \i \i Joe Allen's email address:  'jhallen@world.std.com' or                      \i \i
  448. \i \i 'rcarter' on the VWIS Linux BBS (508)793-9568                               \i \i
  449. }
  450. X
  451. X FOURTH SECTION: Key bindings:
  452. X
  453. X :main are the main editing bindings
  454. X :fprompt are file name prompt bindings
  455. X :prompt are other prompt bindings
  456. X :tab are file menu bindings
  457. X :help are help menu bindings
  458. X
  459. X Use ^@ through ^_ and ^? for Ctrl chars
  460. X Use SP for space
  461. X Use a TO b to generate a range of characters
  462. X Use UP DOWN RIGHT LEFT HOME END INS DEL PGUP PGDN
  463. X     F1 F2 F3 F4 F5 F6 F7 F8 F9 F0
  464. X     for the corresponding termcap key sequence definitions
  465. X
  466. X Simple macros can be made by comma seperating 2 or more command names.  For
  467. X example:
  468. X
  469. X bof,bol    ^T Z        Goto beginning of last line
  470. X
  471. X Also quoted matter is typed in literally:
  472. X
  473. X bol,">",dnarw    F1        Quote news article line
  474. X
  475. :main
  476. X
  477. type        ^I        Tab
  478. quote8        ^\        Quote Meta chars
  479. type        SP TO ~        Typeable characters
  480. quote        `        Quote Ctrl chars
  481. X
  482. abort        ^C        Abort window
  483. arg        ^[ 1 TO 9    Repeat count
  484. backs        ^?        Backspace
  485. backs        ^H
  486. backw        ^O        Backspace word
  487. blkcpy        ^K C        Copy marked block
  488. blkcpy        ^K ^C
  489. blkcpy        ^K c
  490. blkdel        ^K Y        Delete marked block
  491. blkdel        ^K ^Y
  492. blkdel        ^K y
  493. blkmove        ^K M        Move marked block
  494. blkmove        ^K ^M
  495. blkmove        ^K m
  496. blksave        ^K W        Save marked block
  497. blksave        ^K ^W
  498. blksave        ^K w
  499. bof        ^K U        Goto beginning of file
  500. bof        ^K ^U
  501. bof        ^K u
  502. bol        HOME        Goto beginning of line
  503. bol        ^A
  504. center        ^K A        Center line
  505. center        ^K ^A
  506. center        ^K a
  507. delch        DEL        Delete character
  508. delch        ^D
  509. deleol        ^J        Delete to end of line
  510. dellin        ^Y        Delete entire line
  511. delw        ^W        Delete word to right
  512. dnarw        DOWN        Go down
  513. dnarw        ^N
  514. dnarw        ^[ O B
  515. dnarw        ^[ [ B
  516. edit        ^K E        Edit a file
  517. edit        ^K ^E
  518. edit        ^K e
  519. eof        ^K V        Go to end of file
  520. eof        ^K ^V
  521. eof        ^K v
  522. eol        END        Go to end of line
  523. eol        ^E
  524. explode        ^K I        Show one window / Show all windows
  525. explode        ^K ^I
  526. explode        ^K i
  527. exsave        ^K X        Save and exit
  528. exsave        ^K ^X
  529. exsave        ^K x
  530. ffirst        ^K F        Find first
  531. ffirst        ^K ^F
  532. ffirst        ^K f
  533. filt        ^K /        Filter block
  534. fnext        ^L        Find next
  535. format        ^K J        Format paragraph
  536. format        ^K ^J
  537. format        ^K j
  538. groww        ^K G        Grow window
  539. groww        ^K ^G
  540. groww        ^K g
  541. help        ^K H        Help
  542. help        ^K ^H
  543. help        ^K h
  544. iasis        ^T H        Characters 160-254 shown as-is
  545. iasis        ^T ^H
  546. iasis        ^T h
  547. iforce        ^T F        Force final newline
  548. iforce        ^T ^F
  549. iforce        ^T f
  550. iindent        ^T A        Autoindent on/off
  551. iindent        ^T ^A
  552. iindent        ^T a
  553. iindentc    ^T k
  554. iindentc    ^T K
  555. iindentc    ^T ^K
  556. ilmargin    ^T L        Set left margin
  557. ilmargin    ^T ^L
  558. ilmargin    ^T l
  559. imid        ^T M        Center cursor when scrolling
  560. imid        ^T ^M
  561. imid        ^T m
  562. insc        INS        Insert a space
  563. insc        ^@
  564. insf        ^K R        Insert a file
  565. insf        ^K ^R
  566. insf        ^K r
  567. ipgamnt        ^T P        No. lines to keep for PGUP/PGDN
  568. ipgamnt        ^T ^P
  569. ipgamnt        ^T p
  570. irmargin    ^T R        Set right margin
  571. irmargin    ^T ^R
  572. irmargin    ^T r
  573. istacol        ^T C        Column number on status line
  574. istacol        ^T ^C
  575. istacol        ^T c
  576. istarow        ^T N        Row number on status line
  577. istarow        ^T ^N
  578. istarow        ^T n
  579. iistep        ^T i
  580. iistep        ^T I
  581. iistep        ^T ^I
  582. isquare        ^T x
  583. isquare        ^T X
  584. isquare        ^T ^X
  585. itab        ^T D
  586. itab        ^T ^D
  587. itab        ^T d
  588. itype        ^T T        Insert/Overtype
  589. itype        ^T ^T
  590. itype        ^T t
  591. iwrap        ^T W        Word wrap
  592. iwrap        ^T ^W
  593. iwrap        ^T w
  594. lindent        ^K ,        Indent to left
  595. line        ^K L        Goto line no.
  596. line        ^K ^L
  597. line        ^K l
  598. ltarw        LEFT        Go left
  599. ltarw        ^B
  600. ltarw        ^[ O D
  601. ltarw        ^[ [ D
  602. markb        ^K B        Set beginning of marked block
  603. markb        ^K ^B
  604. markb        ^K b
  605. markk        ^K K        Set end of marked block
  606. markk        ^K ^K
  607. markk        ^K k
  608. nextpos        ^K =        Goto next position in position history
  609. nextw        ^K N        Goto window below
  610. nextw        ^K ^N
  611. nextw        ^K n
  612. nextword    ^X        Goto next word
  613. open        ^]        Split line
  614. pgdn        PGDN        Screen down
  615. pgdn        ^V
  616. pgup        PGUP        Screen up
  617. pgup        ^U
  618. play        ^K 0 TO 9    Execute macro
  619. prevpos        ^K -
  620. prevw        ^K P        Window above
  621. prevw        ^K ^P
  622. prevw        ^K p
  623. prevword    ^Z        Previous word
  624. record        ^K [        Record macro
  625. redo        ^^        Redo changes
  626. retype        ^R        Refresh screen
  627. rindent        ^K .        Indent to right
  628. rtarw        RIGHT        Go right
  629. rtarw        ^F
  630. rtarw        ^[ O C
  631. rtarw        ^[ [ C
  632. rtn        ^M        Return
  633. save        ^K D        Save file
  634. save        ^K S
  635. save        ^K ^D
  636. save        ^K ^S
  637. save        ^K d
  638. save        ^K s
  639. shell        ^K Z        Shell escape/Suspend
  640. shell        ^K ^Z
  641. shell        ^K z
  642. shrinkw        ^K T        Shrink window
  643. shrinkw        ^K ^T
  644. shrinkw        ^K t
  645. splitw        ^K O        Split window
  646. splitw        ^K ^O
  647. splitw        ^K o
  648. stat        ^K SP        Show status
  649. stop        ^K ]        Stop recording macro
  650. tag        ^K ;
  651. tomatch        ^G        Goto matching parenthasis
  652. undo        ^_        Undo changes
  653. uparw        UP        Go up
  654. uparw        ^P
  655. uparw        ^[ O A
  656. uparw        ^[ [ A
  657. X
  658. :prompt
  659. X
  660. type        ^I        Tab
  661. quote8        ^\        Quote Meta chars
  662. type        SP TO ~        Typeable characters
  663. quote        `        Quote Ctrl chars
  664. X
  665. abortpw        ^C        Abort window
  666. arg        ^[ 1 TO 9    Repeat count
  667. backs        ^?        Backspace
  668. backs        ^H
  669. backw        ^O        Backspace word
  670. blkcpy        ^K C        Copy marked block
  671. blkcpy        ^K ^C
  672. blkcpy        ^K c
  673. blkdel        ^K Y        Delete marked block
  674. blkdel        ^K ^Y
  675. blkdel        ^K y
  676. blkmove        ^K M        Move marked block
  677. blkmove        ^K ^M
  678. blkmove        ^K m
  679. blksave        ^K W        Save marked block
  680. blksave        ^K ^W
  681. blksave        ^K w
  682. bof        ^K U        Goto beginning of file
  683. bof        ^K ^U
  684. bof        ^K u
  685. bol        HOME        Goto beginning of line
  686. bol        ^A
  687. center        ^K A        Center line
  688. center        ^K ^A
  689. center        ^K a
  690. delch        DEL        Delete character
  691. delch        ^D
  692. deleol        ^J        Delete to end of line
  693. dellin        ^Y        Delete entire line
  694. delw        ^W        Delete word to right
  695. dnarw        DOWN        Go down
  696. dnarw        ^N
  697. dnarw        ^[ O B
  698. dnarw        ^[ [ B
  699. edit        ^K E        Edit a file
  700. edit        ^K ^E
  701. edit        ^K e
  702. eof        ^K V        Go to end of file
  703. eof        ^K ^V
  704. eof        ^K v
  705. eol        END        Go to end of line
  706. eol        ^E
  707. explode        ^K I        Show one window / Show all windows
  708. explode        ^K ^I
  709. explode        ^K i
  710. exsave        ^K X        Save and exit
  711. exsave        ^K ^X
  712. exsave        ^K x
  713. ffirst        ^K F        Find first
  714. ffirst        ^K ^F
  715. ffirst        ^K f
  716. filt        ^K /        Filter block
  717. fnext        ^L        Find next
  718. format        ^K J        Format paragraph
  719. format        ^K ^J
  720. format        ^K j
  721. groww        ^K G        Grow window
  722. groww        ^K ^G
  723. groww        ^K g
  724. help        ^K H        Help
  725. help        ^K ^H
  726. help        ^K h
  727. iasis        ^T H        Characters 160-254 shown as-is
  728. iasis        ^T ^H
  729. iasis        ^T h
  730. iforce        ^T F        Force final newline
  731. iforce        ^T ^F
  732. iforce        ^T f
  733. iindent        ^T A        Autoindent on/off
  734. iindent        ^T ^A
  735. iindent        ^T a
  736. iindentc    ^T k
  737. iindentc    ^T K
  738. iindentc    ^T ^K
  739. ilmargin    ^T L        Set left margin
  740. ilmargin    ^T ^L
  741. ilmargin    ^T l
  742. imid        ^T M        Center cursor when scrolling
  743. imid        ^T ^M
  744. imid        ^T m
  745. insc        INS        Insert a space
  746. insc        ^@
  747. insf        ^K R        Insert a file
  748. insf        ^K ^R
  749. insf        ^K r
  750. ipgamnt        ^T P        No. lines to keep for PGUP/PGDN
  751. ipgamnt        ^T ^P
  752. ipgamnt        ^T p
  753. irmargin    ^T R        Set right margin
  754. irmargin    ^T ^R
  755. irmargin    ^T r
  756. istacol        ^T C        Column number on status line
  757. istacol        ^T ^C
  758. istacol        ^T c
  759. istarow        ^T N        Row number on status line
  760. istarow        ^T ^N
  761. istarow        ^T n
  762. iistep        ^T i
  763. iistep        ^T I
  764. iistep        ^T ^I
  765. isquare        ^T x
  766. isquare        ^T X
  767. isquare        ^T ^X
  768. itab        ^T D
  769. itab        ^T ^D
  770. itab        ^T d
  771. itype        ^T T        Insert/Overtype
  772. itype        ^T ^T
  773. itype        ^T t
  774. iwrap        ^T W        Word wrap
  775. iwrap        ^T ^W
  776. iwrap        ^T w
  777. lindent        ^K ,        Indent to left
  778. line        ^K L        Goto line no.
  779. line        ^K ^L
  780. line        ^K l
  781. ltarw        LEFT        Go left
  782. ltarw        ^B
  783. ltarw        ^[ O D
  784. ltarw        ^[ [ D
  785. markb        ^K B        Set beginning of marked block
  786. markb        ^K ^B
  787. markb        ^K b
  788. markk        ^K K        Set end of marked block
  789. markk        ^K ^K
  790. markk        ^K k
  791. nextpos        ^K =        Goto next position in position history
  792. nextw        ^K N        Goto window below
  793. nextw        ^K ^N
  794. nextw        ^K n
  795. nextword    ^X        Goto next word
  796. open        ^]        Split line
  797. pgdn        PGDN        Screen down
  798. pgdn        ^V
  799. pgup        PGUP        Screen up
  800. pgup        ^U
  801. play        ^K 0 TO 9    Execute macro
  802. prevpos        ^K -
  803. prevw        ^K P        Window above
  804. prevw        ^K ^P
  805. prevw        ^K p
  806. prevword    ^Z        Previous word
  807. record        ^K [        Record macro
  808. redo        ^^        Redo changes
  809. retype        ^R        Refresh screen
  810. rindent        ^K .        Indent to right
  811. rtarw        RIGHT        Go right
  812. rtarw        ^F
  813. rtarw        ^[ O C
  814. rtarw        ^[ [ C
  815. rtnpw        ^M        Return
  816. save        ^K D        Save file
  817. save        ^K S
  818. save        ^K ^D
  819. save        ^K ^S
  820. save        ^K d
  821. save        ^K s
  822. shell        ^K Z        Shell escape/Suspend
  823. shell        ^K ^Z
  824. shell        ^K z
  825. shrinkw        ^K T        Shrink window
  826. shrinkw        ^K ^T
  827. shrinkw        ^K t
  828. splitw        ^K O        Split window
  829. splitw        ^K ^O
  830. splitw        ^K o
  831. stat        ^K SP        Show status
  832. stop        ^K ]        Stop recording macro
  833. tag        ^K ;
  834. tomatch        ^G        Goto matching parenthasis
  835. undo        ^_        Undo changes
  836. uparw        UP        Go up
  837. uparw        ^P
  838. uparw        ^[ O A
  839. uparw        ^[ [ A
  840. X
  841. :fprompt
  842. X
  843. complete    ^I        Complete file name
  844. quote8        ^\        Quote Meta chars
  845. type        SP TO ~        Typeable characters
  846. quote        `        Quote Ctrl chars
  847. X
  848. abortpw        ^C        Abort window
  849. arg        ^[ 1 TO 9    Repeat count
  850. backs        ^?        Backspace
  851. backs        ^H
  852. backw        ^O        Backspace word
  853. blkcpy        ^K C        Copy marked block
  854. blkcpy        ^K ^C
  855. blkcpy        ^K c
  856. blkdel        ^K Y        Delete marked block
  857. blkdel        ^K ^Y
  858. blkdel        ^K y
  859. blkmove        ^K M        Move marked block
  860. blkmove        ^K ^M
  861. blkmove        ^K m
  862. blksave        ^K W        Save marked block
  863. blksave        ^K ^W
  864. blksave        ^K w
  865. bof        ^K U        Goto beginning of file
  866. bof        ^K ^U
  867. bof        ^K u
  868. bol        HOME        Goto beginning of line
  869. bol        ^A
  870. center        ^K A        Center line
  871. center        ^K ^A
  872. center        ^K a
  873. delch        DEL        Delete character
  874. delch        ^D
  875. deleol        ^J        Delete to end of line
  876. dellin        ^Y        Delete entire line
  877. delw        ^W        Delete word to right
  878. dnarw        DOWN        Go down
  879. dnarw        ^N
  880. dnarw        ^[ O B
  881. dnarw        ^[ [ B
  882. edit        ^K E        Edit a file
  883. edit        ^K ^E
  884. edit        ^K e
  885. eof        ^K V        Go to end of file
  886. eof        ^K ^V
  887. eof        ^K v
  888. eol        END        Go to end of line
  889. eol        ^E
  890. explode        ^K I        Show one window / Show all windows
  891. explode        ^K ^I
  892. explode        ^K i
  893. exsave        ^K X        Save and exit
  894. exsave        ^K ^X
  895. exsave        ^K x
  896. ffirst        ^K F        Find first
  897. ffirst        ^K ^F
  898. ffirst        ^K f
  899. filt        ^K /        Filter block
  900. fnext        ^L        Find next
  901. format        ^K J        Format paragraph
  902. format        ^K ^J
  903. format        ^K j
  904. groww        ^K G        Grow window
  905. groww        ^K ^G
  906. groww        ^K g
  907. help        ^K H        Help
  908. help        ^K ^H
  909. help        ^K h
  910. iasis        ^T H        Characters 160-254 shown as-is
  911. iasis        ^T ^H
  912. iasis        ^T h
  913. iforce        ^T F        Force final newline
  914. iforce        ^T ^F
  915. iforce        ^T f
  916. iindent        ^T A        Autoindent on/off
  917. iindent        ^T ^A
  918. iindent        ^T a
  919. iindentc    ^T k
  920. iindentc    ^T K
  921. iindentc    ^T ^K
  922. ilmargin    ^T L        Set left margin
  923. ilmargin    ^T ^L
  924. ilmargin    ^T l
  925. imid        ^T M        Center cursor when scrolling
  926. imid        ^T ^M
  927. imid        ^T m
  928. insc        INS        Insert a space
  929. insc        ^@
  930. insf        ^K R        Insert a file
  931. insf        ^K ^R
  932. insf        ^K r
  933. ipgamnt        ^T P        No. lines to keep for PGUP/PGDN
  934. ipgamnt        ^T ^P
  935. ipgamnt        ^T p
  936. irmargin    ^T R        Set right margin
  937. irmargin    ^T ^R
  938. irmargin    ^T r
  939. istacol        ^T C        Column number on status line
  940. istacol        ^T ^C
  941. istacol        ^T c
  942. istarow        ^T N        Row number on status line
  943. istarow        ^T ^N
  944. istarow        ^T n
  945. iistep        ^T i
  946. iistep        ^T I
  947. iistep        ^T ^I
  948. isquare        ^T x
  949. isquare        ^T X
  950. isquare        ^T ^X
  951. itab        ^T D
  952. itab        ^T ^D
  953. itab        ^T d
  954. itype        ^T T        Insert/Overtype
  955. itype        ^T ^T
  956. itype        ^T t
  957. iwrap        ^T W        Word wrap
  958. iwrap        ^T ^W
  959. iwrap        ^T w
  960. lindent        ^K ,        Indent to left
  961. line        ^K L        Goto line no.
  962. line        ^K ^L
  963. line        ^K l
  964. ltarw        LEFT        Go left
  965. ltarw        ^B
  966. ltarw        ^[ O D
  967. ltarw        ^[ [ D
  968. markb        ^K B        Set beginning of marked block
  969. markb        ^K ^B
  970. markb        ^K b
  971. markk        ^K K        Set end of marked block
  972. markk        ^K ^K
  973. markk        ^K k
  974. nextpos        ^K =        Goto next position in position history
  975. nextw        ^K N        Goto window below
  976. nextw        ^K ^N
  977. nextw        ^K n
  978. nextword    ^X        Goto next word
  979. open        ^]        Split line
  980. pgdn        PGDN        Screen down
  981. pgdn        ^V
  982. pgup        PGUP        Screen up
  983. pgup        ^U
  984. play        ^K 0 TO 9    Execute macro
  985. prevpos        ^K -
  986. prevw        ^K P        Window above
  987. prevw        ^K ^P
  988. prevw        ^K p
  989. prevword    ^Z        Previous word
  990. record        ^K [        Record macro
  991. redo        ^^        Redo changes
  992. retype        ^R        Refresh screen
  993. rindent        ^K .        Indent to right
  994. rtarw        RIGHT        Go right
  995. rtarw        ^F
  996. rtarw        ^[ O C
  997. rtarw        ^[ [ C
  998. rtnpw        ^M        Return
  999. save        ^K D        Save file
  1000. save        ^K S
  1001. save        ^K ^D
  1002. save        ^K ^S
  1003. save        ^K d
  1004. save        ^K s
  1005. shell        ^K Z        Shell escape/Suspend
  1006. shell        ^K ^Z
  1007. shell        ^K z
  1008. shrinkw        ^K T        Shrink window
  1009. shrinkw        ^K ^T
  1010. shrinkw        ^K t
  1011. splitw        ^K O        Split window
  1012. splitw        ^K ^O
  1013. splitw        ^K o
  1014. stat        ^K SP        Show status
  1015. stop        ^K ]        Stop recording macro
  1016. tag        ^K ;
  1017. tomatch        ^G        Goto matching parenthasis
  1018. undo        ^_        Undo changes
  1019. uparw        UP        Go up
  1020. uparw        ^P
  1021. uparw        ^[ O A
  1022. uparw        ^[ [ A
  1023. X
  1024. :tab
  1025. X
  1026. aborttab    ^C
  1027. arg        ^[ 1 TO 9
  1028. backstab    ^?
  1029. backstab    ^H
  1030. boftab        ^K U
  1031. boftab        ^K ^U
  1032. boftab        ^K u
  1033. boltab        HOME
  1034. boltab        ^A
  1035. dnarwtab    DOWN
  1036. dnarwtab    ^N
  1037. dnarwtab    ^[ [ B
  1038. dnarwtab    ^[ O B
  1039. eoftab        ^K V
  1040. eoftab        ^K ^V
  1041. eoftab        ^K v
  1042. eoltab        END
  1043. eoltab        ^E
  1044. explode        ^K I
  1045. explode        ^K ^I
  1046. explode        ^K i
  1047. help        ^K H
  1048. help        ^K ^H
  1049. help        ^K h
  1050. ltarwtab    LEFT
  1051. ltarwtab    ^B
  1052. ltarwtab    ^[ [ D
  1053. ltarwtab    ^[ O D
  1054. nextw        ^K N
  1055. nextw        ^K ^N
  1056. nextw        ^K n
  1057. play        ^K 0 TO 9
  1058. prevw        ^K P
  1059. prevw        ^K ^P
  1060. prevw        ^K p
  1061. record        ^K [
  1062. retype        ^R
  1063. rtarwtab    RIGHT
  1064. rtarwtab    ^F
  1065. rtarwtab    ^[ [ C
  1066. rtarwtab    ^[ O C
  1067. rtntab        SP
  1068. rtntab        ^M
  1069. shell        ^K Z
  1070. shell        ^K ^Z
  1071. shell        ^K z
  1072. stop        ^K ]
  1073. uparwtab    UP
  1074. uparwtab    ^P
  1075. uparwtab    ^[ [ A
  1076. uparwtab    ^[ O A
  1077. X
  1078. :help
  1079. X
  1080. aborthelp    ^C
  1081. arg        ^[ 1 TO 9
  1082. bofhelp        ^K U
  1083. bofhelp        ^K ^U
  1084. bofhelp        ^K u
  1085. bolhelp        HOME
  1086. bolhelp        ^A
  1087. dnarwhelp    DOWN
  1088. dnarwhelp    ^N
  1089. dnarwhelp    ^[ [ B
  1090. dnarwhelp    ^[ O B
  1091. eofhelp        ^K V
  1092. eofhelp        ^K ^V
  1093. eofhelp        ^K v
  1094. eolhelp        END
  1095. eolhelp        ^E
  1096. explode        ^K I
  1097. explode        ^K ^I
  1098. explode        ^K i
  1099. ltarwhelp    LEFT
  1100. ltarwhelp    ^B
  1101. ltarwhelp    ^[ [ D
  1102. ltarwhelp    ^[ O D
  1103. nextw        ^K N
  1104. nextw        ^K ^N
  1105. nextw        ^K n
  1106. play        ^K 0 TO 9
  1107. prevw        ^K P
  1108. prevw        ^K ^P
  1109. prevw        ^K p
  1110. record        ^K [
  1111. retype        ^R
  1112. rtarwhelp    RIGHT
  1113. rtarwhelp    ^F
  1114. rtarwhelp    ^[ [ C
  1115. rtarwhelp    ^[ O C
  1116. rtnhelp        SP
  1117. rtnhelp        ^M
  1118. rtnhelp        ^K H
  1119. rtnhelp        ^K ^H
  1120. rtnhelp        ^K h
  1121. shell        ^K Z
  1122. shell        ^K ^Z
  1123. shell        ^K z
  1124. stop        ^K ]
  1125. uparwhelp    UP
  1126. uparwhelp    ^P
  1127. uparwhelp    ^[ [ A
  1128. uparwhelp    ^[ O A
  1129. SHAR_EOF
  1130. chmod 0600 joerc ||
  1131. echo 'restore of joerc failed'
  1132. Wc_c="`wc -c < 'joerc'`"
  1133. test 19130 -eq "$Wc_c" ||
  1134.     echo 'joerc: original size 19130, current size' "$Wc_c"
  1135. fi
  1136. # ============= kbd.c ==============
  1137. if test -f 'kbd.c' -a X"$1" != X"-c"; then
  1138.     echo 'x - skipping kbd.c (File already exists)'
  1139. else
  1140. echo 'x - extracting kbd.c (Text)'
  1141. sed 's/^X//' << 'SHAR_EOF' > 'kbd.c' &&
  1142. /* Keyboard handler
  1143. X   Copyright (C) 1992 Joseph H. Allen
  1144. X
  1145. This file is part of JOE (Joe's Own Editor)
  1146. X
  1147. JOE is free software; you can redistribute it and/or modify it under the 
  1148. terms of the GNU General Public License as published by the Free Software 
  1149. Foundation; either version 1, or (at your option) any later version.  
  1150. X
  1151. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  1152. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  1153. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  1154. details.  
  1155. X
  1156. You should have received a copy of the GNU General Public License along with 
  1157. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  1158. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  1159. X
  1160. #include <stdio.h>
  1161. #include "config.h"
  1162. #include "heap.h"
  1163. #include "zstr.h"
  1164. #include "va.h"
  1165. X
  1166. /* For help text loading in init. file */
  1167. #include "help.h"
  1168. X
  1169. /* For special key sequence table */
  1170. #include "scrn.h"
  1171. X
  1172. /* For option settings */
  1173. #include "bw.h"
  1174. X
  1175. #include "macro.h"
  1176. #include "kbd.h"
  1177. X
  1178. char **help_names;
  1179. struct help **help_structs;
  1180. struct help *first_help;
  1181. X
  1182. /* Create a KBD */
  1183. X
  1184. KBD *mkkbd(context)
  1185. CONTEXT *context;
  1186. {
  1187. KBD *kbd=(KBD *)malloc(sizeof(KBD));
  1188. kbd->topmap=context->kmap;
  1189. kbd->curmap=context->kmap;
  1190. return kbd;
  1191. }
  1192. X
  1193. /* Eliminate a KBD */
  1194. X
  1195. void rmkbd(k)
  1196. KBD *k;
  1197. {
  1198. free(k);
  1199. }
  1200. X
  1201. /* Lookup key in keyboard table */
  1202. X
  1203. static int findkey(kmap,c)
  1204. KMAP *kmap;
  1205. {
  1206. int x,y,z;
  1207. x=0; y=kmap->len; z= -1;
  1208. if(y)
  1209. X while(z!=(x+y)/2)
  1210. X  {
  1211. X  z=(x+y)/2;
  1212. X  if((kmap->keys[z].k&KEYMASK)==c) return z;
  1213. X  else if((kmap->keys[z].k&KEYMASK)>c) y=z;
  1214. X  else x=z;
  1215. X  }
  1216. return y;
  1217. }
  1218. X
  1219. /* Process next key for KBD */
  1220. X
  1221. MACRO *dokey(kbd,k)
  1222. KBD *kbd;
  1223. {
  1224. int n=findkey(kbd->curmap,k);
  1225. if(n==kbd->curmap->len || (kbd->curmap->keys[n].k&KEYMASK)!=k)
  1226. X kbd->curmap=kbd->topmap;
  1227. else if(kbd->curmap->keys[n].k&KEYSUB)
  1228. X kbd->curmap=kbd->curmap->keys[n].value.submap;
  1229. else
  1230. X {
  1231. X MACRO *macro=kbd->curmap->keys[n].value.macro;
  1232. X kbd->curmap=kbd->topmap;
  1233. X return macro;
  1234. X }
  1235. return 0;
  1236. }
  1237. X
  1238. /* Return command table index for given command name */
  1239. X
  1240. int findcmd(cmdtab,s)
  1241. CMDTAB *cmdtab;
  1242. char *s;
  1243. {
  1244. int x,y,z;
  1245. x=0; y=cmdtab->len; z= -1;
  1246. while(z!=(x+y)/2)
  1247. X {
  1248. X z=(x+y)/2;
  1249. X switch(zcmp(s,cmdtab->cmd[z].name))
  1250. X  {
  1251. X case  1: x=z; break;
  1252. X case -1: y=z; break;
  1253. X case  0: return z;
  1254. X  }
  1255. X }
  1256. return -1;
  1257. }
  1258. X
  1259. /* Return key code for key name */
  1260. X
  1261. static int keyval(s)
  1262. char *s;
  1263. {
  1264. int z1;
  1265. for(z1=0;z1!=NKEYS;++z1) if(!zcmp(s,seqs[z1].name))
  1266. X return seqs[z1].code;
  1267. if(s[0]=='^')
  1268. X if(s[1]=='?') return 127;
  1269. X else return s[1]&0x1f;
  1270. else if(!zcmp(s,"SP")) return ' ';
  1271. else return s[0];
  1272. }
  1273. X
  1274. /* Add a key to a keymap */
  1275. X
  1276. static void addkey(kmap,n,k,v)
  1277. KMAP *kmap;
  1278. MACRO *v;
  1279. {
  1280. if(kmap->len==kmap->size)
  1281. X kmap->keys=(KEY *)realloc(kmap->keys,sizeof(KEY)*(kmap->size+=64));
  1282. mbkwd(kmap->keys+n+1,kmap->keys+n,(kmap->len++-n)*sizeof(KEY));
  1283. kmap->keys[n].k=k;
  1284. kmap->keys[n].value.macro=v;
  1285. }
  1286. X
  1287. /* Eliminate a keymap */
  1288. X
  1289. static void rmkmap(kmap)
  1290. KMAP *kmap;
  1291. {
  1292. int x;
  1293. if(!kmap) return;
  1294. for(x=0;x!=kmap->len;++x)
  1295. X if(kmap->keys[x].k&KEYSUB) rmkmap(kmap->keys[x].value.submap);
  1296. X else rmmacro(kmap->keys[x].value.macro);
  1297. free(kmap->keys);
  1298. free(kmap);
  1299. }
  1300. X
  1301. OPTIONS *options=0;
  1302. extern int mid, dspasis, dspctrl, force, help, pgamnt, starow, stacol,
  1303. X           tabwidth;
  1304. X
  1305. void setoptions(bw,name)
  1306. BW *bw;
  1307. char *name;
  1308. {
  1309. OPTIONS *o;
  1310. for(o=options;o;o=o->next)
  1311. X if(rmatch(o->name,name))
  1312. X  {
  1313. X  bw->overtype=o->overtype;
  1314. X  bw->lmargin=o->lmargin;
  1315. X  bw->rmargin=o->rmargin;
  1316. X  bw->autoindent=o->autoindent;
  1317. X  bw->wordwrap=o->wordwrap;
  1318. X  bw->istep=o->istep;
  1319. X  bw->indentc=o->indentc;
  1320. X  bw->b->tab=o->tab;
  1321. X  break;
  1322. X  }
  1323. }
  1324. X
  1325. /* Process initialization file */
  1326. X
  1327. int prokbd(name,cntxts)
  1328. char *name;
  1329. CONTEXT **cntxts;
  1330. {
  1331. CONTEXT *context=0;        /* Current context */
  1332. KMAP *kmap;            /* Current keymap */
  1333. char buf[256];            /* Input buffer */
  1334. FILE *fd=fopen(name,"r");    /* File */
  1335. MACRO *macro=0;
  1336. struct help *tmp;
  1337. int nhelp=0;
  1338. int line=0;            /* Line number */
  1339. int err=0;            /* Set if there was any errors */
  1340. int x,y,n,z,c,d;
  1341. X
  1342. first_help=NULL;
  1343. help_names=vatrunc(NULL,0);
  1344. X
  1345. if(!fd) return -1;
  1346. X
  1347. fprintf(stderr,"Processing keymap file \'%s\'...",name); fflush(stdout);
  1348. X
  1349. while(++line, fgets(buf,256,fd))
  1350. X {
  1351. X /* Set file-dependant options */
  1352. X if(buf[0]=='*')
  1353. X  {
  1354. X  OPTIONS *n=(OPTIONS *)malloc(sizeof(OPTIONS));
  1355. X  for(x=0;buf[x] && buf[x]!='\n' && buf[x]!=' ' && buf[x]!='\t';++x);
  1356. X  buf[x]=0;
  1357. X  n->lmargin=0;
  1358. X  n->rmargin=76;
  1359. X  n->overtype=0;
  1360. X  n->autoindent=0;
  1361. X  n->wordwrap=0;
  1362. X  n->tab=tabwidth;
  1363. X  n->indentc=' ';
  1364. X  n->istep=1;
  1365. X  n->next=options;
  1366. X  options=n;
  1367. X  n->name=zdup(buf);
  1368. X  continue;
  1369. X  }
  1370. X if(buf[0]=='-')
  1371. X  {
  1372. X  int v;
  1373. X  for(x=0;buf[x] && buf[x]!='\n' && buf[x]!=' ' && buf[x]!='\t';++x);
  1374. X  c=buf[x]; buf[x]=0;
  1375. X  if(!zcmp(buf+1,"mid")) mid=1;
  1376. X  else if(!zcmp(buf+1,"asis")) dspasis=1;
  1377. X  else if(!zcmp(buf+1,"stacol")) stacol=1;
  1378. X  else if(!zcmp(buf+1,"starow")) starow=1;
  1379. X  else if(!zcmp(buf+1,"force")) force=1;
  1380. X  else if(!zcmp(buf+1,"help")) help=1;
  1381. X  else if(!zcmp(buf+1,"pg") && c) sscanf(buf+x+1,"%d",&pgamnt);
  1382. X  else if(!zcmp(buf+1,"gtab") && c) sscanf(buf+x+1,"%d",&tabwidth);
  1383. X  else
  1384. X   if(options)
  1385. X    if(!zcmp(buf+1,"wordwrap")) options->wordwrap=1;
  1386. X    else if(!zcmp(buf+1,"autoindent")) options->autoindent=1;
  1387. X    else if(!zcmp(buf+1,"overwrite")) options->overtype=1;
  1388. X    else if(!zcmp(buf+1,"lmargin") && c) sscanf(buf+x+1,"%ld",&options->lmargin);
  1389. X    else if(!zcmp(buf+1,"rmargin") && c) sscanf(buf+x+1,"%ld",&options->rmargin);
  1390. X    else if(!zcmp(buf+1,"istep") && c) sscanf(buf+x+1,"%ld",&options->istep);
  1391. X    else if(!zcmp(buf+1,"tab") && c) sscanf(buf+x+1,"%d",&options->tab);
  1392. X    else if(!zcmp(buf+1,"indentc") && c) sscanf(buf+x+1,"%d",&options->indentc);
  1393. X    else fprintf(stderr,"\n%s %d: Unknown option",name,line);
  1394. X   else fprintf(stderr,"\n%s %d: No pattern selected for option",name,line);
  1395. X  continue;
  1396. X  }
  1397. X
  1398. X /* Process help text */
  1399. X if(buf[0]=='{')
  1400. X  {
  1401. X  int bfl;
  1402. X  tmp=(struct help *) malloc(sizeof(struct help));
  1403. X  nhelp++;
  1404. X  tmp->next=first_help;
  1405. X  first_help=tmp;
  1406. X  tmp->name=vsncpy(NULL,0,sz(buf+1)-1);
  1407. X  help_names=vaadd(help_names,tmp->name);
  1408. X  tmp->hlptxt=0;
  1409. X  tmp->hlpsiz=0;
  1410. X  tmp->hlpbsz=0;
  1411. X  tmp->hlplns=0;
  1412. X  up:
  1413. X  if(++line, !fgets(buf,256,fd))
  1414. X   {
  1415. X   err=1;
  1416. X   fprintf(stderr,
  1417. X           "\n%s %d: End of keymap file occured before end of help text",
  1418. X           name,line);
  1419. X   break;
  1420. X   }
  1421. X  if(buf[0]=='}')
  1422. X   {
  1423. X   if(!hlptxt)
  1424. X    hlptxt=tmp->hlptxt,
  1425. X    hlpsiz=tmp->hlpsiz,
  1426. X    hlpbsz=tmp->hlpbsz,
  1427. X    hlplns=tmp->hlplns;
  1428. X   continue;
  1429. X   }
  1430. X  bfl=zlen(buf);
  1431. X  if(tmp->hlpsiz+bfl>tmp->hlpbsz)
  1432. X   {
  1433. X   if(tmp->hlptxt) tmp->hlptxt=(char *)realloc(tmp->hlptxt,tmp->hlpbsz+bfl+1024);
  1434. X   else tmp->hlptxt=(char *)malloc(bfl+1024), tmp->hlptxt[0]=0;
  1435. X   tmp->hlpbsz+=bfl+1024;
  1436. X   }
  1437. X  zcpy(tmp->hlptxt+tmp->hlpsiz,buf);
  1438. X  tmp->hlpsiz+=bfl;
  1439. X  ++tmp->hlplns;
  1440. X  goto up;
  1441. X  }
  1442. X /* Get context name */
  1443. X if(buf[0]==':')
  1444. X  {
  1445. X  for(x=1;buf[x] && buf[x]!=' ' && buf[x]!='\t' && buf[x]!='\n';++x);
  1446. X  buf[x]=0;
  1447. X  if(x==1) continue;
  1448. X  for(x=0,context=0;cntxts[x];++x)
  1449. X   if(!zcmp(buf+1,cntxts[x]->name))
  1450. X    {
  1451. X    context=cntxts[x];
  1452. X    break;
  1453. X    }
  1454. X  if(!context) fprintf(stderr,"\n%s %d: Unknown context",name,line), err=1;
  1455. X  continue;
  1456. X  }
  1457. X /* Process Macro */
  1458. X x=0;
  1459. X macro=0;
  1460. X macroloop:
  1461. X if(buf[x]=='\"')
  1462. X  {
  1463. X  ++x;
  1464. X  while(buf[x] && buf[x]!='\"')
  1465. X   {
  1466. X   if(buf[x]=='\\' && buf[x+1])
  1467. X    {
  1468. X    ++x;
  1469. X    switch(buf[x])
  1470. X     {
  1471. X    case 'n': buf[x]=10; break;
  1472. X    case 'r': buf[x]=13; break;
  1473. X    case 'b': buf[x]=8; break;
  1474. X    case 'f': buf[x]=12; break;
  1475. X    case 'a': buf[x]=7; break;
  1476. X    case 't': buf[x]=9; break;
  1477. X    case 'x':
  1478. X     c=0;
  1479. X     if(buf[x+1]>='0' && buf[x+1]<='9') c=c*16+buf[++x]-'0';
  1480. X     else if(buf[x+1]>='a' && buf[x+1]<='f' ||
  1481. X             buf[x+1]>='A' && buf[x+1]<='F') c=c*16+(buf[++x]&0xF)+9;
  1482. X     if(buf[x+1]>='0' && buf[x+1]<='9') c=c*16+buf[++x]-'0';
  1483. X     else if(buf[x+1]>='a' && buf[x+1]<='f' ||
  1484. X             buf[x+1]>='A' && buf[x+1]<='F') c=c*16+(buf[++x]&0xF)+9;
  1485. X     buf[x]=c;
  1486. X     break;
  1487. X    case '0': case '1': case '2': case '3':
  1488. X    case '4': case '5': case '6': case '7':
  1489. X    case '8': case '9':
  1490. X     c=buf[x]-'0';
  1491. X     if(buf[x+1]>='0' && buf[x+1]<='7') c=c*8+buf[++x]-'0';
  1492. X     if(buf[x+1]>='0' && buf[x+1]<='7') c=c*8+buf[++x]-'0';
  1493. X     buf[x]=c;
  1494. X     break;
  1495. X     }
  1496. X    }
  1497. X   if(macro)
  1498. X    {
  1499. X    if(!macro->steps)
  1500. X     {
  1501. X     MACRO *m=macro;
  1502. X     macro=mkmacro(0,1,0);
  1503. X     addmacro(macro,m);
  1504. X     }
  1505. X    addmacro(macro,mkmacro(buf[x],1,findcmd(&cmdtab,"type")));
  1506. X    }
  1507. X   else macro=mkmacro(buf[x],1,findcmd(&cmdtab,"type"));
  1508. X   ++x;
  1509. X   }
  1510. X  if(buf[x]=='\"') ++x;
  1511. X  }
  1512. X else
  1513. X  {
  1514. X  for(y=x;
  1515. X      buf[y] && buf[y]!=',' && buf[y]!=' ' && buf[y]!='\t' && buf[y]!='\n';
  1516. X      ++y);
  1517. X  if(y!=x)
  1518. X   {
  1519. X   z=buf[y]; buf[y]=0;
  1520. X   n=findcmd(&cmdtab,buf+x);
  1521. X   if(n== -1)
  1522. X    {
  1523. X    fprintf(stderr,"\n%s %d: Key function \'%s\' not found",name,line,buf);
  1524. X    err=1;
  1525. X    continue;
  1526. X    }
  1527. X   else if(macro)
  1528. X    {
  1529. X    if(!macro->steps)
  1530. X     {
  1531. X     MACRO *m=macro;
  1532. X     macro=mkmacro(0,1,0);
  1533. X     addmacro(macro,m);
  1534. X     }
  1535. X    addmacro(macro,mkmacro(-1,1,n));
  1536. X    }
  1537. X   else macro=mkmacro(-1,1,n);
  1538. X   buf[x=y]=z;
  1539. X   }
  1540. X  }
  1541. X if(buf[x]==',')
  1542. X  {
  1543. X  ++x;
  1544. X  goto macroloop;
  1545. X  }
  1546. X
  1547. X if(!macro) continue;
  1548. X
  1549. X if(!context)
  1550. X  {
  1551. X  err=1;
  1552. X  fprintf(stderr,"\n%s %d: No context selected for key",name,line);
  1553. X  continue;
  1554. X  }
  1555. X
  1556. X /* Process key sequence */
  1557. X kmap=0;
  1558. X n= -1;
  1559. X while(buf[x]==' ' || buf[x]=='\t') ++x;
  1560. X while(1)
  1561. X  {
  1562. X  int qw,zz;
  1563. X  if(buf[x]==' ') ++x;
  1564. X  if(!buf[x] || buf[x]=='\n' || buf[x]==' ' || buf[x]=='\t') break;
  1565. X  /* Got Next key */
  1566. X  for(zz=x;buf[zz]!=' ' && buf[zz] && buf[zz]!='\t' && buf[zz]!='\n';++zz);
  1567. X  qw=buf[zz]; buf[zz]=0;
  1568. X  d=c=keyval(buf+x);
  1569. X  buf[zz]=qw; x=zz;
  1570. X
  1571. X  if(buf[x]==' ') ++x;
  1572. X  if(buf[x]=='T' && buf[x+1]=='O')
  1573. X   {
  1574. X   x+=2;
  1575. X   if(buf[x]==' ') ++x;
  1576. X   if(buf[x] && buf[x]!='\n' && buf[x]!=' ' && buf[x]!='\t')
  1577. X    {
  1578. X    for(zz=x;buf[zz]!=' ' && buf[zz] && buf[zz]!='\t' && buf[zz]!='\n';++zz);
  1579. X    qw=buf[zz]; buf[zz]=0;
  1580. X    d=keyval(buf+x);
  1581. X    buf[zz]=qw; x=zz;
  1582. X    }
  1583. X   }
  1584. X  if(d<c) d=c;
  1585. X
  1586. X  /* Add it as if it were a submap */
  1587. X  if(!kmap)
  1588. X   {
  1589. X   if(!(kmap=context->kmap))
  1590. X    {
  1591. X    kmap=(KMAP *)malloc(sizeof(KMAP));
  1592. X    kmap->keys=(KEY *)malloc((kmap->size=128)*sizeof(KEY));
  1593. X    kmap->len=0;
  1594. X    context->kmap=kmap;
  1595. X    }
  1596. X   }
  1597. X  else
  1598. X   if(kmap->keys[n].k&KEYSUB) kmap=kmap->keys[n].value.submap;
  1599. X   else
  1600. X    {
  1601. X    kmap->keys[n].value.submap=(KMAP *)malloc(sizeof(KMAP));
  1602. X    kmap->keys[n].k|=KEYSUB;
  1603. X    kmap=kmap->keys[n].value.submap;
  1604. X    kmap->keys=(KEY *)malloc((kmap->size=128)*sizeof(KEY));
  1605. X    kmap->len=0;
  1606. X    }
  1607. X  n=findkey(kmap,c);
  1608. X  if(n==kmap->len || (kmap->keys[n].k&KEYMASK)!=c) addkey(kmap,n,c,NULL);
  1609. X  }
  1610. X while(c<=d)
  1611. X  {
  1612. X  n=findkey(kmap,c);
  1613. X  if(n==kmap->len || (kmap->keys[n].k&KEYMASK)!=c)
  1614. X   addkey(kmap,n,c,c==d?macstk(macro,c):dupmacro(macstk(macro,c)));
  1615. X  else
  1616. X   {
  1617. X   if(kmap->keys[n].k&KEYSUB)
  1618. X    rmkmap(kmap->keys[n].value.submap),
  1619. X    kmap->keys[n].k&=~KEYSUB;
  1620. X   else
  1621. X    rmmacro(kmap->keys[n].value.macro);
  1622. X   kmap->keys[n].value.macro=(c==d?macstk(macro,c):dupmacro(macstk(macro,c)));
  1623. X   }
  1624. X  ++c;
  1625. X  }
  1626. X }
  1627. fclose(fd);
  1628. if(err) fprintf(stderr,"\ndone\n");
  1629. else fprintf(stderr,"done\n");
  1630. if (nhelp)
  1631. X {
  1632. X  help_structs=(struct help **) malloc(sizeof(struct help *)*nhelp);
  1633. X  tmp=first_help;
  1634. X  while(nhelp--)
  1635. X   {
  1636. X    help_structs[nhelp]=tmp;
  1637. X    tmp=tmp->next;
  1638. X   }
  1639. X }
  1640. return 0;
  1641. }
  1642. X
  1643. struct help *get_help(name)
  1644. X char *name;
  1645. X {
  1646. X  struct help *tmp;
  1647. X  for(tmp=first_help;tmp && zcmp(tmp->name,name);tmp=tmp->next);
  1648. X  return tmp;
  1649. X }
  1650. SHAR_EOF
  1651. chmod 0600 kbd.c ||
  1652. echo 'restore of kbd.c failed'
  1653. Wc_c="`wc -c < 'kbd.c'`"
  1654. test 11368 -eq "$Wc_c" ||
  1655.     echo 'kbd.c: original size 11368, current size' "$Wc_c"
  1656. fi
  1657. # ============= kbd.h ==============
  1658. if test -f 'kbd.h' -a X"$1" != X"-c"; then
  1659.     echo 'x - skipping kbd.h (File already exists)'
  1660. else
  1661. echo 'x - extracting kbd.h (Text)'
  1662. sed 's/^X//' << 'SHAR_EOF' > 'kbd.h' &&
  1663. /* Keyboard handler
  1664. X   Copyright (C) 1992 Joseph H. Allen
  1665. X
  1666. This file is part of JOE (Joe's Own Editor)
  1667. X
  1668. JOE is free software; you can redistribute it and/or modify it under the 
  1669. terms of the GNU General Public License as published by the Free Software 
  1670. Foundation; either version 1, or (at your option) any later version.  
  1671. X
  1672. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  1673. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  1674. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  1675. details.  
  1676. X
  1677. You should have received a copy of the GNU General Public License along with 
  1678. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  1679. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  1680. X
  1681. #ifndef _Ikbd
  1682. #define _Ikbd 1
  1683. X
  1684. #include "config.h"
  1685. #include "macro.h"
  1686. X
  1687. typedef struct key KEY;
  1688. typedef struct kmap KMAP;
  1689. typedef struct cmd CMD;
  1690. typedef struct context CONTEXT;
  1691. typedef struct cmdtab CMDTAB;
  1692. typedef struct kbd KBD;
  1693. X
  1694. /* The command table */
  1695. X
  1696. extern CMDTAB cmdtab;
  1697. X
  1698. typedef struct options OPTIONS;
  1699. struct options
  1700. X {
  1701. X OPTIONS *next;
  1702. X char *name;
  1703. X int overtype;
  1704. X long lmargin;
  1705. X long rmargin;
  1706. X int autoindent;
  1707. X int wordwrap;
  1708. X int tab;
  1709. X int indentc;
  1710. X long istep;
  1711. X };
  1712. X
  1713. void setoptions();
  1714. X
  1715. /* A key to macro binding in a keymap */
  1716. X
  1717. struct key
  1718. X {
  1719. X int k;            /* Key value */
  1720. X union
  1721. X  {
  1722. X  MACRO *macro;        /* Macro or */
  1723. X  KMAP *submap;        /* Submap address (for prefix keys) */
  1724. X  } value;
  1725. X };
  1726. X
  1727. /* A map of keycode to command/sub-map bindings */
  1728. X
  1729. struct kmap
  1730. X {
  1731. X int len;        /* Number of KEY entries */
  1732. X int size;        /* Malloc size of block */
  1733. X KEY *keys;        /* KEYs.  Sorted. */
  1734. X };
  1735. X
  1736. /* Masks & bits for 'k' entry in KEY */
  1737. X
  1738. #define KEYMASK 0x7fff    /* Mask to get key value */
  1739. #define KEYSUB 0x8000    /* Bit set for prefix key */
  1740. X
  1741. /* Command entry */
  1742. X
  1743. struct cmd
  1744. X {
  1745. X char *name;        /* Command name */
  1746. X int flag;        /* Execution flags */
  1747. X void (*func)();    /* Function bound to name */
  1748. X };
  1749. X
  1750. /* A Context (a set of bindings) */
  1751. X
  1752. struct context
  1753. X {
  1754. X char *name;        /* Name of this context */
  1755. X KMAP *kmap;        /* Keymap for this context */
  1756. X };
  1757. X
  1758. /* Command table */
  1759. X
  1760. struct cmdtab
  1761. X {
  1762. X CMD *cmd;        /* The entries themselves (sorted by name) */
  1763. X int len;        /* Number of entries */
  1764. X };
  1765. X
  1766. /* A keyboard handler */
  1767. X
  1768. struct kbd
  1769. X {
  1770. X KMAP *curmap;        /* Current keymap */
  1771. X KMAP *topmap;        /* Top-level keymap */
  1772. X };
  1773. X
  1774. /* KBD *mkkbd(CONTEXT *context);
  1775. X   Create a keyboard handler for the given context.
  1776. */
  1777. KBD *mkkbd();
  1778. X
  1779. /* void rmkbd(KBD *);
  1780. X *
  1781. X * Eliminate a keyboard handler
  1782. X */
  1783. void rmkbd();
  1784. X
  1785. /* MACRO *dokey(KBD *kbd,char k);
  1786. X   Handle a key for a KBD:
  1787. X
  1788. X     Returns 0 for invalid or prefix keys
  1789. X
  1790. X     Returns a macro address for completed key-sequences
  1791. */
  1792. MACRO *dokey();
  1793. X
  1794. /* int prokbd(char *name,CONTEXT **cmds);  Process a keymap set-up file into
  1795. X   the list of contexts.  Returns 0 for success or -1 for error
  1796. */
  1797. int prokbd();
  1798. X
  1799. /* int findcmd(CMDTAB *cmdtab,char *s);
  1800. X * Return command table index for the named command
  1801. X */
  1802. int findcmd();
  1803. X
  1804. struct help *get_help();
  1805. X
  1806. #endif
  1807. SHAR_EOF
  1808. chmod 0600 kbd.h ||
  1809. echo 'restore of kbd.h failed'
  1810. Wc_c="`wc -c < 'kbd.h'`"
  1811. test 2999 -eq "$Wc_c" ||
  1812.     echo 'kbd.h: original size 2999, current size' "$Wc_c"
  1813. fi
  1814. # ============= macro.c ==============
  1815. if test -f 'macro.c' -a X"$1" != X"-c"; then
  1816.     echo 'x - skipping macro.c (File already exists)'
  1817. else
  1818. echo 'x - extracting macro.c (Text)'
  1819. sed 's/^X//' << 'SHAR_EOF' > 'macro.c' &&
  1820. /* Keyboard macros
  1821. X   Copyright (C) 1992 Joseph H. Allen
  1822. X
  1823. This file is part of JOE (Joe's Own Editor)
  1824. X
  1825. JOE is free software; you can redistribute it and/or modify it under the 
  1826. terms of the GNU General Public License as published by the Free Software 
  1827. Foundation; either version 1, or (at your option) any later version.  
  1828. X
  1829. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  1830. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  1831. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  1832. details.  
  1833. X
  1834. You should have received a copy of the GNU General Public License along with 
  1835. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  1836. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  1837. X
  1838. #include "main.h"
  1839. #include "macro.h"
  1840. X
  1841. /* Create a macro */
  1842. X
  1843. MACRO *mkmacro(k,arg,n)
  1844. {
  1845. MACRO *macro=(MACRO *)malloc(sizeof(MACRO));
  1846. macro->steps=0;
  1847. macro->size=0;
  1848. macro->arg=arg;
  1849. macro->n=n;
  1850. macro->k=k;
  1851. return macro;
  1852. }
  1853. X
  1854. /* Eliminate a macro */
  1855. X
  1856. void rmmacro(macro)
  1857. MACRO *macro;
  1858. {
  1859. if(macro)
  1860. X {
  1861. X if(macro->steps)
  1862. X  {
  1863. X  int x;
  1864. X  for(x=0;x!=macro->n;++x) rmmacro(macro->steps[x]);
  1865. X  free(macro->steps);
  1866. X  }
  1867. X free(macro);
  1868. X }
  1869. }
  1870. X
  1871. /* Add a step to block macro */
  1872. X
  1873. void addmacro(macro,m)
  1874. MACRO *macro, *m;
  1875. {
  1876. if(macro->n==macro->size)
  1877. X macro->steps=(MACRO **)realloc(macro->steps,(macro->size+=5)*sizeof(MACRO *));
  1878. macro->steps[macro->n++]=m;
  1879. }
  1880. X
  1881. /* Duplicate a macro */
  1882. X
  1883. MACRO *dupmacro(mac)
  1884. MACRO *mac;
  1885. {
  1886. MACRO *m=(MACRO *)malloc(sizeof(MACRO));
  1887. int x;
  1888. m->k=mac->k;
  1889. m->n=mac->n;
  1890. m->arg=mac->arg;
  1891. if(mac->steps)
  1892. X {
  1893. X int x;
  1894. X m->steps=(MACRO **)malloc((m->size=mac->n)*sizeof(MACRO *));
  1895. X for(x=0;x!=m->n;++x) m->steps[x]=dupmacro(mac->steps[x]);
  1896. X }
  1897. else m->steps=0, m->size=0;
  1898. return m;
  1899. }
  1900. X
  1901. MACRO *macstk(m,k)
  1902. MACRO *m;
  1903. {
  1904. m->k=k;
  1905. return m;
  1906. }
  1907. X
  1908. MACRO *macsta(m,a)
  1909. MACRO *m;
  1910. {
  1911. m->arg=a;
  1912. return m;
  1913. }
  1914. X
  1915. /* Keyboard macro recorder */
  1916. X
  1917. MACRO *kbdmacro[10];
  1918. int playmode[10];
  1919. X
  1920. struct recmac *recmac=0;
  1921. X
  1922. void unmac()
  1923. {
  1924. if(recmac) rmmacro(recmac->m->steps[--recmac->m->n]);
  1925. }
  1926. X
  1927. void record(m)
  1928. MACRO *m;
  1929. {
  1930. if(recmac) addmacro(recmac->m,dupmacro(m));
  1931. }
  1932. X
  1933. void urecord(w)
  1934. W *w;
  1935. {
  1936. int c;
  1937. int n;
  1938. struct recmac *r;
  1939. n=query(w,"Macro to record (0-9 or ^C to abort): ");
  1940. if(n>'9' || n<'0') return;
  1941. unmac(); unmac();
  1942. r=(struct recmac *)malloc(sizeof(struct recmac));
  1943. r->m=mkmacro(0,1,0);
  1944. r->next=recmac;
  1945. r->n=n-'0';
  1946. recmac=r;
  1947. }
  1948. X
  1949. void ustop()
  1950. {
  1951. unmac();
  1952. if(recmac)
  1953. X {
  1954. X struct recmac *r=recmac;
  1955. X MACRO *m;
  1956. X recmac=r->next;
  1957. X if(kbdmacro[r->n]) rmmacro(kbdmacro[r->n]);
  1958. X kbdmacro[r->n]=r->m;
  1959. X if(recmac) record(m=mkmacro(r->n+'0',1,findcmd(&cmdtab,"play"))), rmmacro(m);
  1960. X free(r);
  1961. X }
  1962. }
  1963. X
  1964. void uplay(w,c)
  1965. W *w;
  1966. {
  1967. if(c>'9' || c<'0') return;
  1968. c-='0';
  1969. if(playmode[c] || !kbdmacro[c]) return;
  1970. playmode[c]=1;
  1971. exmacro(kbdmacro[c]);
  1972. playmode[c]=0;
  1973. }
  1974. SHAR_EOF
  1975. chmod 0600 macro.c ||
  1976. echo 'restore of macro.c failed'
  1977. Wc_c="`wc -c < 'macro.c'`"
  1978. test 2755 -eq "$Wc_c" ||
  1979.     echo 'macro.c: original size 2755, current size' "$Wc_c"
  1980. fi
  1981. # ============= macro.h ==============
  1982. if test -f 'macro.h' -a X"$1" != X"-c"; then
  1983.     echo 'x - skipping macro.h (File already exists)'
  1984. else
  1985. echo 'x - extracting macro.h (Text)'
  1986. sed 's/^X//' << 'SHAR_EOF' > 'macro.h' &&
  1987. /* Keyboard macros
  1988. X   Copyright (C) 1992 Joseph H. Allen
  1989. X
  1990. This file is part of JOE (Joe's Own Editor)
  1991. X
  1992. JOE is free software; you can redistribute it and/or modify it under the 
  1993. terms of the GNU General Public License as published by the Free Software 
  1994. Foundation; either version 1, or (at your option) any later version.  
  1995. X
  1996. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  1997. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  1998. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  1999. details.  
  2000. X
  2001. You should have received a copy of the GNU General Public License along with 
  2002. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  2003. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  2004. X
  2005. #ifndef _Imacro
  2006. #define _Imacro 1
  2007. X
  2008. #include "config.h"
  2009. X
  2010. typedef struct macro MACRO;
  2011. X
  2012. struct macro
  2013. X {
  2014. X int k;        /* Keycode */
  2015. X int arg;    /* Repeat argument */
  2016. X int n;        /* Command number or number of steps */
  2017. X int size;    /* Malloc size of steps */
  2018. X MACRO **steps;    /* Block */
  2019. X };
  2020. X
  2021. struct recmac
  2022. X {
  2023. X struct recmac *next;
  2024. X int n;
  2025. X MACRO *m;
  2026. X };
  2027. X
  2028. extern struct recmac *recmac;    /* Set when macro is recording */
  2029. X
  2030. MACRO *mkmacro();
  2031. void addmacro();
  2032. MACRO *dupmacro();
  2033. void rmmacro();
  2034. MACRO *macstk();
  2035. MACRO *macsta();
  2036. void uplay();
  2037. void ustop();
  2038. void urecord();
  2039. void record();
  2040. void unmac();
  2041. X
  2042. #endif
  2043. SHAR_EOF
  2044. chmod 0600 macro.h ||
  2045. echo 'restore of macro.h failed'
  2046. Wc_c="`wc -c < 'macro.h'`"
  2047. test 1344 -eq "$Wc_c" ||
  2048.     echo 'macro.h: original size 1344, current size' "$Wc_c"
  2049. fi
  2050. # ============= main.c ==============
  2051. if test -f 'main.c' -a X"$1" != X"-c"; then
  2052.     echo 'x - skipping main.c (File already exists)'
  2053. else
  2054. echo 'x - extracting main.c (Text)'
  2055. sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&
  2056. /* Editor startup and main edit loop
  2057. X   Copyright (C) 1992 Joseph H. Allen
  2058. X
  2059. This file is part of JOE (Joe's Own Editor)
  2060. X
  2061. JOE is free software; you can redistribute it and/or modify it under the 
  2062. terms of the GNU General Public License as published by the Free Software 
  2063. Foundation; either version 1, or (at your option) any later version.  
  2064. X
  2065. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  2066. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  2067. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  2068. details.  
  2069. X
  2070. You should have received a copy of the GNU General Public License along with 
  2071. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  2072. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  2073. X
  2074. #include <stdio.h>
  2075. #include "config.h"
  2076. #include "vfile.h"
  2077. #include "blocks.h"
  2078. #include "tty.h"
  2079. #include "toomany.h"
  2080. #include "termcap.h"
  2081. #include "scrn.h"
  2082. #include "b.h"
  2083. #include "bw.h"
  2084. #include "tw.h"
  2085. #include "w.h"
  2086. #include "kbd.h"
  2087. #include "zstr.h"
  2088. #include "macro.h"
  2089. #include "tab.h"
  2090. #include "pw.h"
  2091. #include "edfuncs.h"
  2092. #include "poshist.h"
  2093. #include "pattern.h"
  2094. #include "help.h"
  2095. #include "vs.h"
  2096. #include "main.h"
  2097. X
  2098. /* Message to display when exiting the editor */
  2099. X
  2100. int help=0;
  2101. X
  2102. char *exmsg=0;
  2103. X
  2104. /* Main screen */
  2105. X
  2106. SCREEN *maint;
  2107. X
  2108. /* Command table */
  2109. X
  2110. #define EMID 1
  2111. #define ECHKXCOL 2
  2112. #define EFIXXCOL 4
  2113. #define EMINOR 8
  2114. #define EPOS 16
  2115. #define EMOVE 32
  2116. X
  2117. int typen;
  2118. X
  2119. static CMD cmds[]=
  2120. {
  2121. X  { "abort", TYPETW, uaborttw },
  2122. X  { "aborthelp", TYPEHELP, uhabort },
  2123. X  { "abortpw", TYPEPW, uabortpw },
  2124. X  { "aborttab", TYPETAB, tuabort },
  2125. X  { "arg", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uarg },
  2126. X  { "backs", TYPETW+TYPEPW+ECHKXCOL+EFIXXCOL+EMINOR, ubacks },
  2127. X  { "backstab", TYPETAB, tbacks },
  2128. X  { "backw", TYPETW+TYPEPW+ECHKXCOL+EFIXXCOL, ubackw },
  2129. X  { "blkcpy", TYPETW+TYPEPW+0, ublkcpy },
  2130. X  { "blkdel", TYPETW+TYPEPW+EFIXXCOL, ublkdel },
  2131. X  { "blkmove", TYPETW+TYPEPW+EFIXXCOL, ublkmove },
  2132. X  { "blksave", TYPETW+TYPEPW+0, ublksave },
  2133. X  { "bof", TYPETW+TYPEPW+EMOVE+EFIXXCOL, ubof },
  2134. X  { "bofhelp", TYPEHELP, uhbof },
  2135. X  { "boftab", TYPETAB, tbof },
  2136. X  { "bol", TYPETW+TYPEPW+EFIXXCOL, ubol },
  2137. X  { "bolhelp", TYPEHELP, uhbol },
  2138. X  { "boltab", TYPETAB, tbol },
  2139. X  { "center", TYPETW+TYPEPW+EFIXXCOL, ucenter },
  2140. X  { "check", TYPETW+TYPEPW+0, ucheck },
  2141. X  { "checkp", TYPETW+TYPEPW+0, ucheckp },
  2142. X  { "complete", TYPETW+TYPEPW, ucmplt },
  2143. X  { "delbol", TYPETW+TYPEPW+EFIXXCOL, udelbl },
  2144. X  { "delch", TYPETW+TYPEPW+ECHKXCOL+EFIXXCOL+EMINOR, udelch },
  2145. X  { "deleol", TYPETW+TYPEPW+0, udelel },
  2146. X  { "dellin", TYPETW+TYPEPW+EFIXXCOL, udelln },
  2147. X  { "delw", TYPETW+TYPEPW+EFIXXCOL+ECHKXCOL, udelw },
  2148. X  { "dnarw", TYPETW+TYPEPW+EMOVE, udnarw },
  2149. X  { "dnarwhelp", TYPEHELP, uhdnarw },
  2150. X  { "dnarwtab", TYPETAB, tdnarw },
  2151. X  { "dnslide", TYPETW+EMOVE, udnslide },
  2152. X  { "edit", TYPETW+TYPEPW, uedit },
  2153. X  { "eof", TYPETW+TYPEPW+EFIXXCOL+EMOVE, ueof },
  2154. X  { "eofhelp", TYPEHELP, uheof },
  2155. X  { "eoftab", TYPETAB, teof },
  2156. X  { "eol", TYPETW+TYPEPW+EFIXXCOL, ueol },
  2157. X  { "eolhelp", TYPEHELP, uheol },
  2158. X  { "eoltab", TYPETAB, teol },
  2159. X  { "explode", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uexpld },
  2160. X  { "exsave", TYPETW+TYPEPW, uexsve },
  2161. X  { "ffirst", TYPETW+TYPEPW+EMOVE, pffirst },
  2162. X  { "filt", TYPETW+TYPEPW+0, ufilt },
  2163. X  { "fnext", TYPETW+TYPEPW+EFIXXCOL+EMID+EMOVE, pfnext },
  2164. X  { "format", TYPETW+TYPEPW+EFIXXCOL, uformat },
  2165. X  { "groww", TYPETW, ugroww },
  2166. X  { "help", TYPETW+TYPEPW+TYPETAB, uhelp },
  2167. X  { "iasis", TYPETW+TYPEPW+TYPETAB+TYPEHELP+EFIXXCOL, uiasis },
  2168. X  { "iforce", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uiforce },
  2169. X  { "iindent", TYPETW+TYPEPW, uiindent },
  2170. X  { "iindentc", TYPETW+TYPEPW, uicindent },
  2171. X  { "iistep", TYPETW+TYPEPW, uiistep },
  2172. X  { "ilmargin", TYPETW+TYPEPW, uilmargin },
  2173. X  { "imid", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uimid },
  2174. X  { "insc", TYPETW+TYPEPW+EFIXXCOL, uinsc },
  2175. X  { "insf", TYPETW+TYPEPW+0, uinsf },
  2176. X  { "ipgamnt", TYPETW+TYPEPW, uipgamnt },
  2177. X  { "irmargin", TYPETW+TYPEPW+TYPETAB, uirmargin },
  2178. X  { "isquare", TYPETW+TYPEPW, uisquare },
  2179. X  { "istacol", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uistacol },
  2180. X  { "istarow", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uistarow },
  2181. X  { "itab", TYPETW+TYPEPW, uitab },
  2182. X  { "itype", TYPETW+TYPEPW, uitype },
  2183. X  { "iwrap", TYPETW+TYPEPW, uiwrap },
  2184. X  { "lindent", TYPETW+TYPEPW+0, ulindent },
  2185. X  { "line", TYPETW+TYPEPW+EMOVE, uline },
  2186. X  { "ltarw", TYPETW+TYPEPW+EFIXXCOL+ECHKXCOL, ultarw },
  2187. X  { "ltarwhelp", TYPEHELP, uhltarw },
  2188. X  { "ltarwtab", TYPETAB, tltarw },
  2189. X  { "markb", TYPETW+TYPEPW+0, umarkb },
  2190. X  { "markk", TYPETW+TYPEPW+0, umarkk },
  2191. X  { "nedge", TYPETW+TYPEPW+EFIXXCOL, unedge },
  2192. X  { "nextpos", TYPETW+TYPEPW+EFIXXCOL+EMID+EPOS, unextpos },
  2193. X  { "nextw", TYPETW+TYPEPW+TYPETAB+TYPEHELP, unextw },
  2194. X  { "nextword", TYPETW+TYPEPW+EFIXXCOL, unxtwrd },
  2195. X  { "open", TYPETW+TYPEPW+EFIXXCOL, uopen },
  2196. X  { "pedge", TYPETW+TYPEPW+EFIXXCOL, upedge },
  2197. X  { "pgdn", TYPETW+EMOVE, upgdn },
  2198. X  { "pgup", TYPETW+EMOVE, upgup },
  2199. X  { "play", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uplay },
  2200. X  { "prevpos", TYPETW+TYPEPW+EPOS+EMID+EFIXXCOL, uprevpos },
  2201. X  { "prevw", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uprevw },
  2202. X  { "prevword", TYPETW+TYPEPW+EFIXXCOL+ECHKXCOL, uprvwrd },
  2203. X  { "quote", TYPETW+TYPEPW+EFIXXCOL, uquote },
  2204. X  { "quote8", TYPETW+TYPEPW+EFIXXCOL, uquote8 },
  2205. X  { "record", TYPETW+TYPEPW+TYPETAB+TYPEHELP, urecord },
  2206. X  { "redo", TYPETW+TYPEPW+EFIXXCOL, uredo },
  2207. X  { "retype", TYPETW+TYPEPW+TYPETAB+TYPEHELP, uretyp },
  2208. X  { "rindent", TYPETW+TYPEPW+0, urindent },
  2209. X  { "rtarw", TYPETW+TYPEPW+EFIXXCOL, urtarw },
  2210. X  { "rtarwhelp", TYPEHELP, uhrtarw },
  2211. X  { "rtarwtab", TYPETAB, trtarw },
  2212. X  { "rtn", TYPETW+TYPEPW+EFIXXCOL, urtn },
  2213. X  { "rtnhelp", TYPEHELP, uhrtn },
  2214. X  { "rtnpw", TYPEPW+EMID, upromptrtn },
  2215. X  { "rtntab", TYPETAB, trtn },
  2216. X  { "save", TYPETW+TYPEPW, usave },
  2217. X  { "shell", TYPETW+TYPEPW+TYPETAB+TYPEHELP, ushell },
  2218. X  { "shrinkw", TYPETW, ushrnk },
  2219. X  { "splitw", TYPETW, usplitw },
  2220. X  { "stat", TYPETW+TYPEPW, ustat },
  2221. X  { "stop", TYPETW+TYPEPW+TYPETAB+TYPEHELP, ustop },
  2222. X  { "tag", TYPETW+TYPEPW, utag },
  2223. X  { "tomatch", TYPETW+TYPEPW+ECHKXCOL+EFIXXCOL, utomatch },
  2224. X  { "type", TYPETW+TYPEPW+EFIXXCOL+EMINOR, utype },
  2225. X  { "undo", TYPETW+TYPEPW+EFIXXCOL, uundo },
  2226. X  { "uparw", TYPETW+TYPEPW+EMOVE, uuparw },
  2227. X  { "uparwhelp", TYPEHELP, uhuparw },
  2228. X  { "uparwtab", TYPETAB, tuparw },
  2229. X  { "upslide", TYPETW+EMOVE, uupslide }
  2230. };
  2231. X
  2232. CMDTAB cmdtab={cmds,sizeof(cmds)/sizeof(CMD)};
  2233. X
  2234. void dofollows()
  2235. {
  2236. W *w=maint->curwin; do
  2237. X {
  2238. X if(w->y!= -1) w->watom->follow(w);
  2239. X w=(W *)(w->link.next);
  2240. X }
  2241. X while(w!=maint->curwin);
  2242. }
  2243. X
  2244. /* Execute a command */
  2245. X
  2246. void execmd(n,k)
  2247. {
  2248. BW *bw=(BW *)maint->curwin->object;
  2249. if((cmdtab.cmd[n].flag&ECHKXCOL) && bw->cursor->xcol!=bw->cursor->col)
  2250. X goto skip;
  2251. if(!(cmdtab.cmd[n].flag&maint->curwin->watom->what)) goto skip;
  2252. cmdtab.cmd[n].func(maint->curwin,k);
  2253. if(leave) return;
  2254. bw=(BW *)maint->curwin->object;
  2255. X
  2256. if(!(cmdtab.cmd[n].flag&EPOS) &&
  2257. X   (maint->curwin->watom->what&(TYPETW|TYPEPW)))
  2258. X afterpos(maint->curwin,bw->cursor);
  2259. if(!(cmdtab.cmd[n].flag&(EMOVE|EPOS)) &&
  2260. X   (maint->curwin->watom->what&(TYPETW|TYPEPW)))
  2261. X aftermove(maint->curwin,bw->cursor);
  2262. X
  2263. skip:
  2264. if(cmdtab.cmd[n].flag&EFIXXCOL) bw->cursor->xcol=bw->cursor->col;
  2265. if(cmdtab.cmd[n].flag&EMID)
  2266. X {
  2267. X int omid=mid; mid=1;
  2268. X dofollows();
  2269. X mid=omid;
  2270. X }
  2271. }
  2272. X
  2273. MACRO *curmacro=0;
  2274. int macroptr;
  2275. X
  2276. void exmacro(m)
  2277. MACRO *m;
  2278. {
  2279. int arg=maint->arg;
  2280. int flg=0;
  2281. maint->arg=0;
  2282. X
  2283. if(!arg) arg=1;
  2284. X
  2285. if( m->steps ||
  2286. X    arg!=1 ||
  2287. X    !(cmdtab.cmd[m->n].flag&EMINOR)
  2288. X  ) flg=1;
  2289. X
  2290. if(flg) umclear();
  2291. while(arg-- && !leave)
  2292. X if(m->steps)
  2293. X  {
  2294. X  MACRO *tmpmac=curmacro;
  2295. X  int tmpptr=macroptr;
  2296. X  int x=0;
  2297. X  while(m && x!=m->n && !leave)
  2298. X   {
  2299. X   MACRO *d;
  2300. X   d=m->steps[x++];
  2301. X   curmacro=m;
  2302. X   macroptr=x;
  2303. X   exmacro(d);
  2304. X   m=curmacro;
  2305. X   x=macroptr;
  2306. X   }
  2307. X  curmacro=tmpmac;
  2308. X  macroptr=tmpptr;
  2309.