home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3879 < prev    next >
Encoding:
Text File  |  1991-08-22  |  57.3 KB  |  2,522 lines

  1. Path: wupost!decwrl!amdcad!pyramid!oliveb!olivea!samsung!crackers!m2c!wpi.WPI.EDU!rcarter
  2. From: rcarter@wpi.WPI.EDU (Randolph Carter (nee. Joseph H. Allen))
  3. Newsgroups: alt.sources
  4. Subject: J (Joe's Editor) - Part 3 of 3
  5. Message-ID: <1991Aug22.043527.30804@wpi.WPI.EDU>
  6. Date: 22 Aug 91 04:35:27 GMT
  7. Sender: rcarter@wpi.WPI.EDU (Randolph Carter (nee. Joseph H. Allen))
  8. Organization: Kadath Tours, Inc.
  9. Lines: 2511
  10.  
  11.  
  12. -- Cut here; take text between this line and the last 'cut' line
  13.  fclose(handle);
  14.  }
  15. else
  16.  {
  17.  ldbuf(bt);
  18.  sprintf(sting,"\033[7mError opening file %s\033[m",gfnam1);
  19.  msg(sting);
  20.  }
  21. }
  22.  
  23. delblk()
  24. {
  25. struct buffer *bt=curbuf;
  26. TXTSIZ x=fmnote();
  27. TXTSIZ sz;
  28. if(markbuf)
  29.  {
  30.  stbuf(curbuf);
  31.  ldbuf(markbuf);
  32.  }
  33. if(marke<=markb || marke>fmsize() || !markbuf)
  34.  {
  35.  msg("\033[7mThe block is not marked properly\033[m  Mark it with ^KB & ^KK");
  36.  if(markbuf)
  37.   ldbuf(bt);
  38.  return;
  39.  }
  40. if(bt==markbuf) if(x>=markb && x<marke) x=markb;
  41. sz=marke-markb;
  42. fmpoint(markb);
  43. fmdel(sz);
  44. if(bt==markbuf) if(x>markb) x-=sz;
  45. stbuf(markbuf);
  46. ldbuf(bt);
  47. fmpoint(x);
  48. updall=1;
  49. newy=1;
  50. }
  51.  
  52. moveblk()
  53. {
  54. unsigned char *t;
  55. TXTSIZ sz, x=fmnote();
  56. struct buffer *bt=curbuf;
  57. if(markbuf)
  58.  {
  59.  stbuf(curbuf);
  60.  ldbuf(markbuf);
  61.  }
  62. if(marke<=markb || marke>fmsize() || !markbuf)
  63.  {
  64.  msg("\033[7mThe block is not marked properly\033[m  Mark it with ^KB & ^KK");
  65.  if(markbuf)
  66.   ldbuf(bt);
  67.  return;
  68.  }
  69. if(x>=markb && x<=marke && bt==markbuf)
  70.  {
  71.  x=markb;
  72.  ldbuf(bt);
  73.  return;
  74.  }
  75. sz=marke-markb;
  76. t=(unsigned char *)malloc(sz);
  77. fmpoint(markb);
  78. fmcpy(t,sz);
  79. fmdel(sz);
  80. if(bt==markbuf) if(x>markb) x-=sz, newy=1;
  81. stbuf(markbuf); 
  82. ldbuf(bt);
  83. fmpoint(x);
  84. fminss(t,sz);
  85. free(t);
  86. markb=x;
  87. marke=x+sz;
  88. markbuf=bt;
  89. updall=1;
  90. }
  91.  
  92. cpyblk()
  93. {
  94. unsigned char *t;
  95. TXTSIZ x=fmnote();
  96. struct buffer *bt=curbuf;
  97. TXTSIZ sz;
  98. if(markbuf)
  99.  {
  100.  stbuf(curbuf);
  101.  ldbuf(markbuf);
  102.  }
  103. if(marke<=markb || marke>fmsize() || !markbuf)
  104.  {
  105.  msg("\033[7mThe block is not marked properly\033[m  Mark it with ^KB & ^KK");
  106.  if(markbuf)
  107.   ldbuf(bt);
  108.  return;
  109.  }
  110. sz=marke-markb;
  111. t=(unsigned char *)malloc(sz);
  112. fmpoint(markb);
  113. fmcpy(t,sz);
  114. stbuf(markbuf);
  115. ldbuf(bt); 
  116. fmpoint(x);
  117. fminss(t,sz);
  118. free(t);
  119. marke=x+sz;
  120. markb=x;
  121. markbuf=bt;
  122. updall=1;
  123. }
  124.  
  125. insfil()
  126. {
  127. unsigned char gfnam1[PATHSIZE];
  128. unsigned char sting[PATHSIZE];
  129. gfnam1[0]=0;
  130. if(!getl("File to insert",gfnam1)) return;
  131. fixpath(gfnam1);
  132. handle=fopen(gfnam1,"r");
  133. if(handle)
  134.  {
  135.  if(!fminsfil(handle))
  136.   {
  137.   sprintf(sting,"\033[7mError inserting file %s\033[m",gfnam1);
  138.   msg(sting);
  139.   }
  140.  newy=1;
  141.  fclose(handle);
  142.  }
  143. else
  144.  {
  145.  sprintf(sting,"\033[7mError opening file %s\033[m",gfnam1);
  146.  msg(sting);
  147.  return;
  148.  }
  149. }
  150.  
  151. push()
  152. {
  153. unsigned char *ssh=(unsigned char *)getenv("SHELL");
  154. if(!ssh)
  155.  {
  156.  msg("Couldn't find shell");
  157.  return;
  158.  }
  159. dclose("You are at the command shell.  Type 'exit' to continue editing");
  160. shell(ssh);
  161. rewrite();
  162. }
  163.  
  164. mode()
  165. {
  166. unsigned char s[PATHSIZE];
  167. s[0]=0;
  168. strcat(s,"(R)ght Mrgn ");
  169. if(overwrite) strcat(s,"(I) Overtype ");
  170. else strcat(s,"(I)nsert ");
  171. if(tabmagic) strcat(s,"(T)ab Magic on ");
  172. else strcat(s,"(T)ab Magic off ");
  173. if(wrap) strcat(s,"(W)rap on ");
  174. else strcat(s,"(W)rap off ");
  175. if(autoind) strcat(s,"(A) Indent on ");
  176. else strcat(s,"(A) Indent off ");
  177. if(pic) strcat(s,"(P)ic on: ");
  178. else strcat(s,"(P)ic off: ");
  179. switch(query(s))
  180.  {
  181.  case 'i':
  182.  case 'I':
  183.  case 'o':
  184.  case 'O':
  185.   overwrite= !overwrite;
  186.   break;
  187.  case 'W':
  188.  case 'w':
  189.   wrap= !wrap;
  190.   break;
  191.  case 'a':
  192.  case 'A':
  193.   autoind= !autoind;
  194.   break;
  195.  case 't':
  196.  case 'T':
  197.   tabmagic= !tabmagic;
  198.   break;
  199.  case 'p':
  200.  case 'P':
  201.   pic= !pic;
  202.   break;
  203.  case 'r':
  204.  case 'R':
  205.   {
  206.   char sting[80];
  207.   sprintf(sting,"%d",rmargin);
  208.   if(!getl("Right margin",sting)) return;
  209.   rmargin=atol(sting);
  210.   if(rmargin<2) rmargin=2;
  211.   }
  212.  }
  213. }
  214.  
  215. /* Center the current line */
  216.  
  217. ctrlin()
  218. {
  219. TXTSIZ x;
  220. int tmp=pic;
  221. int y;
  222. unfill();
  223. bol();
  224. while(y=fmrc(), y==' ' || y=='\t') fmdel(1);
  225. eol();
  226. x=fmnote();
  227. bol();
  228. if(x-fmnote()>rmargin) return;
  229. y=(rmargin/2)-(x-fmnote())/2;
  230. while(y--) fminsc(' ');
  231. pic=1;
  232. udnarw();
  233. pic=tmp;
  234. }
  235.  
  236. /* Reformat a paragraph */
  237.  
  238. reformat()
  239. {
  240. TXTSIZ tmp,idt,idt1,b,e;
  241. unsigned char ch;
  242.  
  243. /* First, determine indentation on current or first non-blank line */
  244.  
  245. up:
  246. idt=calcs();
  247. if(fmeof()) return;     /* Not if at end of file */
  248. if(fmrc()==NL)  /* Ignore any blank lines */
  249.  {
  250.  dnarw();
  251.  goto up;
  252.  }
  253. bol();
  254.  
  255. /* Now find beginning of paragraph */
  256. /* It will be indicated by a change of indentation or a blank line or bof */
  257.  
  258. while(fmnote())         /* Beginning is at bof */
  259.  {
  260.  uparw();
  261.  idt1=calcs();
  262.  if(fmrc()==NL) /* Beginning is blank line */
  263.   {
  264.   bol();
  265.   dnarw();
  266.   break;
  267.   }
  268.  bol();
  269.  if(idt1>idt) break;
  270.  if(idt1<idt)
  271.   {
  272.   dnarw();
  273.   break;
  274.   }
  275.  }
  276.  
  277. /* Point is now at beginning of paragraph (hopefully) */
  278. /* Set the mark */
  279.  
  280. b=fmnote();
  281.  
  282. idt=calcs(); bol();    /* Save indentation level of first line of paragraph */
  283.  
  284. /* Now move to after end of paragraph */
  285. while(1)
  286.  {
  287.  tmp=fmnote();
  288.  dnarw();
  289.  if(fmnote()==tmp)      /* Paragraph ends on end of file */
  290.   {
  291.   eol();
  292.   fminsc(NL);        /* Stick in a NL */
  293.   fmgetc();
  294.   extend=0;        /* I don't think I have to do this but... */
  295.   break;
  296.   }
  297.  idt1=calcs();
  298.  if(fmrc()==NL)        /* Paragraph ends on blank line */
  299.   {
  300.   bol();
  301.   break;
  302.   }
  303.  bol();
  304.  if(idt1>idt) break;    /* Paragraph ends when indentation increases */
  305.  }
  306.  
  307. /* Point now after end of paragraph, cut paragraph */
  308. e=fmnote();
  309.  
  310. /* Now reinsert paragraph in a nice way */
  311.  
  312. if(e>b)
  313.  {
  314.  unsigned oldwrap=wrap;
  315.  unsigned oldoverwrite=overwrite;
  316.  unsigned oldauto=autoind;
  317.  unsigned flag=0;
  318.  unsigned char ccc=0;
  319.  TXTSIZ ppp=b; 
  320.  overwrite=0;
  321.  wrap=1;
  322.  while(ppp!=e)
  323.   {
  324.   tmp=fmnote();
  325.   fmpoint(ppp);
  326.   ppp++;
  327.   ch=fmrc();
  328.   fmpoint(tmp);
  329.   if(ch==NL) ch=' ';
  330.   if(ch==' ' || ch==TAB)
  331.    {
  332.    if(flag==0) itype(ch);
  333.    else if(flag==1)
  334.      {
  335.      itype(' ');
  336.      if(!(ccc=='.' || ccc==':' || ccc=='?' || ccc=='!' || ccc=='\"' ||
  337.           ccc==';')) flag=2;
  338.      }
  339.    }
  340.   else
  341.    {
  342.    flag=1;
  343.    itype(ch);
  344.    }
  345.   ccc=ch;
  346.   }
  347.  autoind=0;
  348.  if(flag) itype(NL);
  349.  wrap=oldwrap;
  350.  overwrite=oldoverwrite;
  351.  autoind=oldauto;
  352.  tmp=fmnote();
  353.  fmpoint(b);
  354.  fmdel(e-b);
  355.  fmpoint(tmp-(e-b));
  356.  newy=1;
  357.  }
  358. }
  359.  
  360. killword()
  361. {
  362. unsigned char ch;
  363. ch=fmrc();
  364. if(((ch>='a' && ch<='z') || (ch>='A' && ch <='Z')) && !fmeof())
  365.  do
  366.   {
  367.   delch();
  368.   ch=fmrc();
  369.   } while (((ch>='a' && ch<='z') || (ch>='A' && ch <='Z')) && !fmeof());
  370. else
  371.  if((ch==' ' || ch==TAB || ch==NL) && !fmeof())
  372.   do
  373.    {
  374.    delch();
  375.    ch=fmrc();
  376.    } while (!fmeof() && (ch==' ' || ch==NL || ch==TAB));
  377. else
  378.  if(ch>='0' && ch<='9' && !fmeof())
  379.   do
  380.    {
  381.    delch();
  382.    ch=fmrc();
  383.    } while (!fmeof() && ch>='0' && ch<='9');
  384. else delch();
  385. }
  386.  
  387. backword()
  388. {
  389. unsigned char ch;
  390. if(fmnote())
  391.  {
  392.  fmpoint(fmnote()-1);
  393.  ch=fmgetc();
  394.  if((ch>='a' && ch<='z') || (ch>='A' && ch <='Z'))
  395.   {
  396. up:
  397.   backs();
  398.   if(fmnote())
  399.    {
  400.    fmpoint(fmnote()-1);
  401.    ch=fmrc();
  402.    fmgetc();
  403.    if((ch>='a' && ch<='z') || (ch>='A' && ch <='Z')) goto up;
  404.    }
  405.   }
  406.  else if(ch==' ' || ch==TAB || ch==NL)
  407.    {
  408. up1:
  409.    backs();
  410.    if(fmnote())
  411.     {
  412.     fmpoint(fmnote()-1);
  413.     ch=fmrc();
  414.     fmgetc();
  415.     if(ch==' ' || ch==TAB || ch==NL) goto up1;
  416.     }
  417.    }
  418.  else if(ch>='0' && ch<='9')
  419.    {
  420. up2:
  421.    backs();
  422.    if(fmnote())
  423.     {
  424.     fmpoint(fmnote()-1);
  425.     ch=fmrc();
  426.     fmgetc();
  427.     if(ch>='0' && ch<='9') goto up2;
  428.     }
  429.    }
  430.  else backs();
  431.  }
  432. }
  433.  
  434. word()
  435. {
  436. int c;
  437. if(fmnote()==fmsize()) return 0;
  438. c=fmrc();
  439. if(c>='a' && c<='z') return 1;
  440. if(c>='A' && c<='Z') return 1;
  441. if(c>='0' && c<='9') return 1;
  442. return 0;
  443. }
  444.  
  445. wrdl()
  446. {
  447. extend=0;
  448. newy=1;
  449. if(!fmnote()) return;
  450. fmrgetc();
  451. while(!word())
  452.  {
  453.  if(!fmnote()) return;
  454.  fmrgetc();
  455.  }
  456. while(word())
  457.  {
  458.  if(!fmnote()) return;
  459.  fmrgetc();
  460.  }
  461. fmgetc();
  462. }
  463.  
  464. wrdr()
  465. {
  466. extend=0;
  467. newy=1;
  468. while(!word())
  469.  {
  470.  if(fmnote()==fmsize()) return;
  471.  fmgetc();
  472.  }
  473. while(word())
  474.  {
  475.  if(fmnote()==fmsize()) return;
  476.  fmgetc();
  477.  }
  478. }
  479.  
  480. unsigned char lft[]="{[(<`";
  481. unsigned char rht[]="}])>'";
  482.  
  483. gotomatching()
  484. {
  485. TXTSIZ cur=fmnote(),cnt;
  486. unsigned char c;
  487. int x;
  488. extend=0;
  489. if(fmeof()) return;
  490. c=fmrc();
  491. for(x=0;x!=strlen(lft);++x)
  492.  if(lft[x]==c)
  493.   {
  494.   cnt=0;
  495.   while(!fmeof())
  496.    {
  497.    c=fmgetc();
  498.    if(lft[x]==c) ++cnt;
  499.    if(rht[x]==c)
  500.     if(!--cnt)
  501.      {
  502.      newy=1;
  503.      fmrgetc();
  504.      return;
  505.      }
  506.    }
  507.   fmpoint(cur);
  508.   return;
  509.   }
  510.  else if(rht[x]==c)
  511.   {
  512.   cnt=1;
  513.   while(fmnote())
  514.    {
  515.    c=fmrgetc();
  516.    if(rht[x]==c) ++cnt;
  517.    if(lft[x]==c)
  518.     if(!--cnt)
  519.      {
  520.      newy=1;
  521.      return;
  522.      }
  523.    }
  524.   fmpoint(cur);
  525.   return;
  526.   }
  527. }
  528.  
  529. int setindent()
  530. {
  531. TXTSIZ idt,idt1,cur=fmnote(),tmp;
  532. if(curbuf==markbuf && cur>=markb && cur<marke) return 1;
  533. markbuf=curbuf; markb=0; marke=0;
  534. /* Find beginning */
  535. idt=calcs();
  536. if(fmeof()) goto done;
  537. if(fmrc()==NL) goto done;
  538. while(fmnrnl())
  539.  {
  540.  idt1=calcs();
  541. /* if(fmrc()!=NL) if(idt1<idt) Use this line instead of one below for
  542.    setindent to ignore blank lines */
  543.  if(fmrc()==NL || idt1<idt)
  544.   {
  545.   if(fmfnl()) fmgetc();
  546.   break;
  547.   }
  548.  }
  549. /* Point is now at beginning of block (hopefully) */
  550. /* Set the mark */
  551. markb=fmnote();
  552.  
  553. while(fmfnl())
  554.  {
  555.  fmgetc();
  556.  idt1=calcs();
  557. /* if(fmrc()!=NL) if(idt1<idt) Use this line instead of one below for
  558.    setindent to ignore blank lines */
  559.  if(fmrc()==NL || idt1<idt)
  560.   {
  561.   bol();
  562.   break;
  563.   }
  564.  }
  565. marke=fmnote();
  566. done: fmpoint(cur);
  567. return 0;
  568.  
  569. indentr()
  570. {
  571. TXTSIZ cur=fmnote(),tmp;
  572. if(!setindent()) return;
  573. fmpoint(markb);
  574. while(fmnote()<marke)
  575.  {
  576.  calcs();
  577.  if(fmeof()) break;
  578.  if(fmrc()!=NL)
  579.   {
  580.   if(fmnote()<=cur) ++cur;
  581.   fminsc(' ');
  582.   }
  583.  if(fmfnl()) fmgetc();
  584.  else break;
  585.  }
  586. done: fmpoint(cur);
  587. return;
  588. }
  589.  
  590. indentl()
  591. {
  592. TXTSIZ cur=fmnote(),idt,tmp;
  593. if(!setindent()) return;
  594. fmpoint(markb);
  595. while(fmnote()<marke)
  596.  {
  597.  idt=calcs();
  598.  if(fmeof()) break;
  599.  if(fmrc()!=NL) if(!idt) goto done;
  600.  if(fmfnl()) fmgetc();
  601.  else break;
  602.  }
  603. fmpoint(markb);
  604. while(fmnote()<marke)
  605.  {
  606.  calcs();
  607.  if(fmeof()) break;
  608.  if(fmrc()!=NL)
  609.   {
  610.   if(fmnote()<=cur) --cur;
  611.   fmrgetc();
  612.   fmdel(1);
  613.   }
  614.  if(fmfnl()) fmgetc();
  615.  else break;
  616.  }
  617. done: fmpoint(cur);
  618. return;
  619. }
  620.  
  621. struct window *curwin;
  622. struct buffer *curbuf;
  623. struct window *topwin;
  624.  
  625. ldbuf(zuffer)
  626. struct buffer *zuffer;
  627. {
  628. if(zuffer==curbuf) return;
  629. curbuf=zuffer;
  630. backup=zuffer->backup;
  631. strcpy(gfnam,zuffer->gfnam);
  632. bufsiz=zuffer->bufsiz;
  633. buffer=zuffer->buf;
  634. filend=zuffer->filend;
  635. hole=zuffer->hole;
  636. ehole=zuffer->ehole;
  637. changed=zuffer->changed;
  638. }
  639.  
  640. ldbuf1(zuffer)
  641. struct buffer *zuffer;
  642. {
  643. curbuf=zuffer;
  644. backup=zuffer->backup;
  645. strcpy(gfnam,zuffer->gfnam);
  646. bufsiz=zuffer->bufsiz;
  647. buffer=zuffer->buf;
  648. filend=zuffer->filend;
  649. hole=zuffer->hole;
  650. ehole=zuffer->ehole;
  651. changed=zuffer->changed;
  652. }
  653.  
  654. stbuf(zuffer)
  655. struct buffer *zuffer;
  656. {
  657. zuffer->backup=backup;
  658. strcpy(zuffer->gfnam,gfnam);
  659. zuffer->bufsiz=bufsiz;
  660. zuffer->buf=buffer;
  661. zuffer->filend=filend;
  662. zuffer->hole=hole;
  663. zuffer->ehole=ehole;
  664. zuffer->changed=changed;
  665. }
  666.  
  667. ldwin(window)
  668. struct window *window;
  669. {
  670. saddr=window->saddr;
  671. xoffset=window->xoffset;
  672. pic=window->pic;
  673. autoind=window->autoind;
  674. overwrite=window->overwrite;
  675. wrap=window->wrap;
  676. tabmagic=window->tabmagic;
  677. rmargin=window->rmargin;
  678. extend=window->extend;
  679. ldbuf1(window->buffer);
  680. fmpoint(window->cursor);
  681. }
  682.                                    
  683. stwin(window)
  684. struct window *window;
  685. window->saddr=saddr;
  686. window->xoffset=xoffset;
  687. window->pic=pic;
  688. window->autoind=autoind;
  689. window->overwrite=overwrite;
  690. window->wrap=wrap;
  691. window->tabmagic=tabmagic;
  692. window->rmargin=rmargin;
  693. window->extend=extend;
  694. window->cursor=fmnote();
  695. stbuf(window->buffer);
  696. }
  697.  
  698. wfit()
  699. {
  700. struct window *x;
  701. int total;
  702. updall=1;
  703. newy=1;
  704. up:
  705. total=height-wind;
  706. for(x=topwin;1;x=x->next)
  707.  {
  708.  if(x->height<2) x->height=2;
  709.  if(curwin==x && total>=2) break;
  710.  if(total<2) goto in;
  711.  total-=x->height;
  712.  if(total<0)
  713.   {
  714.   in:
  715.   topwin=topwin->next;
  716.   goto up;
  717.   }
  718.  }
  719. for(x=topwin,total=wind;1;x=x->next)
  720.  {
  721.  x->wind=total;
  722.  if(x->height<2) x->height=2;
  723.  total+=x->height;
  724.  if(total>=height || x->next==topwin)
  725.   {
  726.   total-=x->height;
  727.   x->height=height-total;
  728.   return;
  729.   }
  730.  }
  731. }
  732.  
  733. wnext()
  734. {
  735. stwin(curwin);
  736. curwin=curwin->next;
  737. ldwin(curwin);
  738. wfit();
  739. }
  740.  
  741. wprev()
  742. {
  743. stwin(curwin);
  744. curwin=curwin->prev;
  745. ldwin(curwin);
  746. wfit();
  747. }
  748.  
  749. wexplode()
  750. {
  751. struct window *x;
  752. int y;
  753. if(curwin->height!=height-wind)
  754.  { /* Make curwin only */
  755.  topwin=curwin;
  756.  x=topwin;
  757.  do
  758.   {
  759.   x->height=height-wind;
  760.   x->wind=wind;
  761.   x=x->next;
  762.   }
  763.   while(x!=topwin);
  764.  newy=1;
  765.  }
  766. else
  767.  { /* Show all windows */
  768.  x=topwin; y=0;
  769.  do y++, x=x->next; while(x!=topwin);
  770.  if((height-wind)/y<2) y=2;
  771.  else y=(height-wind)/y;
  772.  x=topwin;
  773.  do x->height=y, x=x->next; while(x!=topwin);
  774.  wfit();
  775.  }
  776. }
  777.  
  778. wgrow()
  779. {
  780. if(curwin->wind+curwin->height==height)
  781.  {
  782.  if(curwin->wind!=wind) if(curwin->prev->height>2)
  783.   curwin->prev->height--, curwin->height++, curwin->wind--, updall=1;
  784.  }
  785. else
  786.  {
  787.  if(curwin->next->height>2)
  788.   curwin->height++, curwin->next->wind++, curwin->next->height--, updall=1;
  789.  }
  790. newy=1;
  791. }
  792.  
  793. wshrink()
  794. {
  795. if(curwin->wind+curwin->height==height)
  796.  {
  797.  if(curwin->wind!=wind) if(curwin->height>2)
  798.  curwin->height--, curwin->prev->height++, curwin->wind++, updall=1;
  799.  }
  800. else
  801.  {
  802.  if(curwin->height>2)
  803.  curwin->height--, curwin->next->wind--, curwin->next->height++, updall=1;
  804.  }
  805. newy=1;
  806. }
  807.  
  808. wsplit()
  809. {
  810. struct window *new;
  811. if(curwin->height<4) return;
  812. new=(struct window *)malloc(sizeof(struct window));
  813. new->buffer=curbuf;
  814. stwin(new);
  815. new->next=curwin->next;
  816. new->prev=curwin;
  817. curwin->next->prev=new;
  818. curwin->next=new;
  819. if(curwin->height&1)
  820.  {
  821.  curwin->height/=2;
  822.  new->height=curwin->height+1;
  823.  }
  824. else
  825.  {
  826.  curwin->height/=2;
  827.  new->height=curwin->height;
  828.  }
  829. if(curwin->hheight&1)
  830.  {
  831.  curwin->hheight/=2;
  832.  new->hheight=curwin->hheight+1;
  833.  }
  834. else
  835.  {
  836.  curwin->hheight/=2;
  837.  new->hheight=curwin->hheight;
  838.  }
  839. new->wind=curwin->wind+curwin->height;
  840. curwin=new;
  841. curbuf->count++;
  842. updall=1;
  843. newy=1;
  844. }
  845.  
  846. wedit()
  847. {
  848. unsigned char gfnam1[PATHSIZE];
  849. unsigned char sting[PATHSIZE];
  850. int c;
  851. struct window *x;
  852. stwin(curwin);
  853. if(curbuf->count==1 && curbuf->changed)
  854.  {
  855.  c=askyn("Do you really want to throw away this file?"); 
  856.  if(c=='N') return;
  857.  if(c== -1) return;
  858.  }
  859. gfnam1[0]=0;
  860. if(!getl("File to edit",gfnam1)) return;
  861. fixpath(gfnam1);
  862. x=topwin;
  863. do
  864.  {
  865.  if(!strcmp(gfnam1,x->buffer->gfnam))
  866.   {
  867.   if(curbuf->count==1)
  868.    {
  869.    free(curbuf->buf), free(curbuf);
  870.    if(curbuf==markbuf) markbuf=0;
  871.    }                           
  872.   else 
  873.    curbuf->count--;
  874.   curwin->buffer=x->buffer;
  875.   curwin->buffer->count++;
  876.   ldbuf(x->buffer);
  877.   bof();
  878.   return;
  879.   }
  880.  x=x->next;
  881.  }
  882.  while(x!=topwin);
  883. handle=fopen(gfnam1,"r");
  884. strcpy(gfnam,gfnam1);
  885. stmode(gfnam);
  886. if(curbuf->count==1) free(curbuf->buf),
  887.                              free(curbuf);
  888. else curbuf->count--;
  889. curwin->buffer=(struct buffer *)malloc(sizeof(struct buffer));
  890. curbuf=curwin->buffer;
  891. curbuf->count=1;
  892. fmopen();
  893. bof();
  894. if(handle)
  895.  {
  896.  if(!fminsfil(handle))
  897.   {
  898.   sprintf(sting,"\033[7mError inserting file %s\033[m",gfnam1);
  899.   msg(sting);
  900.   }
  901.  changed=0;
  902.  newy=1;
  903.  fclose(handle);
  904.  }
  905. else
  906.  {
  907.  newy=1;
  908.  upd=1;
  909.  dupdate();
  910.  if(errno==ENOENT)
  911.   {
  912.   eputs("New File\r");
  913.   backup=1;
  914.   }
  915.  else
  916.   eputs("\033[7mError opening file\033[m\r");
  917.  invalidate(curwin->wind+1);
  918.  dokey(anext());
  919.  return;
  920.  }
  921. }
  922.  
  923. rtn()
  924. {
  925. type(NL);
  926. }
  927.  
  928. stquote()
  929. {
  930. quoteflg=1;
  931. }
  932.  
  933. stquote8th()
  934. {
  935. quote8th=1;
  936. }
  937.  
  938. CMD kkm[54]=
  939. {
  940.  {"uparw",0,uuparw},
  941.  {"rtarw",0,urtarw},
  942.  {"ltarw",0,ultarw},
  943.  {"dnarw",0,udnarw},
  944.  {"eol",0,eol},
  945.  {"pgdn",0,pgdn},
  946.  {"bol",0,bol},
  947.  {"pgup",0,pgup},
  948.  {"ctrlin",0,ctrlin},
  949.  {"setbeg",0,setbeg},
  950.  {"cpyblk",0,cpyblk},
  951.  {"saveit",0,saveit},
  952.  {"wedit",0,wedit},
  953.  {"findfirst",0,findfirst},
  954.  {"findnext",0,findnext},
  955.  {"wgrow",0,wgrow},
  956.  {"thelp",0,thelp},
  957.  {"wexplode",0,wexplode},
  958.  {"reformat",0,reformat},
  959.  {"setend",0,setend},
  960.  {"findline",0,findline},
  961.  {"moveblk",0,moveblk},
  962.  {"wnext",0,wnext},
  963.  {"wprev",0,wprev},
  964.  {"wsplit",0,wsplit},
  965.  {"insfil",0,insfil},
  966.  {"wshrink",0,wshrink},
  967.  {"bof",0,bof},
  968.  {"eof",0,eof},
  969.  {"writeblk",0,writeblk},
  970.  {"exsave",0,exsave},
  971.  {"delblk",0,delblk},
  972.  {"push",0,push},
  973.  {"eexit",0,eexit},
  974.  {"delch",0,delch},
  975.  {"inss",0,inss},
  976.  {"backs",0,backs},
  977.  {"type",0,type},
  978.  {"deleol",0,deleol},
  979.  {"rtn",0,rtn},
  980.  {"backword",0,backword},
  981.  {"rewrite",0,rewrite},
  982.  {"mode",0,mode},
  983.  {"killword",0,killword},
  984.  {"wrdr",0,wrdr},
  985.  {"dellin",0,dellin},
  986.  {"wrdl",0,wrdl},
  987.  {"stquote8th",0,stquote8th},
  988.  {"stquote",0,stquote},
  989.  {"gotomatching",0,gotomatching},
  990.  {"indentl",0,indentl},
  991.  {"indentr",0,indentr},
  992.  {"undo",0,undo},
  993.  {"redo",0,redo}
  994.  };
  995.  
  996. CONTEXT km={0, "main", 0, 54, kkm};
  997.  
  998. /** Key sequence processing functions **/
  999.  
  1000. struct kmap *curmap;
  1001. int quoteflg=0;
  1002. int quote8th=0;
  1003.  
  1004. int dokey(k)
  1005. unsigned char k;
  1006. {
  1007. int above=curmap->len;
  1008. int below=0;
  1009. int new;
  1010. struct kmap *r;
  1011. if(quoteflg)
  1012.  {
  1013.  quoteflg=0;
  1014.  if(k>='@' && k<='_') k-='@';
  1015.  if(k>='a' && k<='z') k-='`';
  1016.  if(k=='?') k=127;
  1017.  type(k);
  1018.  goto abcd;
  1019.  }
  1020. goto in;
  1021. do
  1022.  {
  1023.  new=(above+below)/2;
  1024.  if((curmap->keys[new].k&KEYMASK)==k)
  1025.   if(curmap->keys[new].k&KEYSUB)
  1026.    {
  1027.    curmap=(KMAP *)(curmap->keys[new].n);
  1028.    return Kaccept;
  1029.    }
  1030.   else
  1031.    {
  1032.    r=curmap;
  1033.    curmap=km.kmap;
  1034.    if(km.cmd[r->keys[new].n].func!=redo &&
  1035.       km.cmd[r->keys[new].n].func!=undo) undoptr=0;
  1036.    km.cmd[r->keys[new].n].func(k);
  1037.    abcd:
  1038.    if(!leave)
  1039.     {
  1040.     if(!uuu) upd=1;
  1041.     else uuu=0;
  1042.     dupdate();
  1043.     }
  1044.    return 0;
  1045.    }
  1046.  else if((curmap->keys[new].k&KEYMASK)>k)
  1047.   {
  1048.   above=new;
  1049.   in:
  1050.   if(above==below) break;
  1051.   }
  1052.  else if(below==new) break;
  1053.  else below=new;
  1054.  } while(1);
  1055. curmap=km.kmap;
  1056. return Kbad;
  1057. }
  1058.  
  1059. edit()
  1060. {
  1061. newy=1;
  1062. dupdate();
  1063. imsg();
  1064. dokey(anext());
  1065. if(leave) return;
  1066. upd=1;
  1067. newy=1;
  1068. do
  1069.  dokey(anext());
  1070.  while(!leave);
  1071. }
  1072.  
  1073. struct mpair
  1074.  {
  1075.  struct mpair *next;
  1076.  unsigned char *s;
  1077.  int wrap;
  1078.  int autoind;
  1079.  int pic;
  1080.  int overwrite;
  1081.  int tabmagic;
  1082.  TXTSIZ rmargin;
  1083.  };
  1084.  
  1085. struct mpair *mpairs=0;
  1086.  
  1087. stmode(name)
  1088. unsigned char *name;
  1089. {
  1090. int x=strlen(name);
  1091. struct mpair *mp=mpairs;
  1092. while(mp)
  1093.  if(!strcmp(mp->s,name+x-strlen(mp->s)))
  1094.   {
  1095.   autoind=mp->autoind;
  1096.   wrap=mp->wrap;
  1097.   overwrite=mp->overwrite;
  1098.   pic=mp->pic;
  1099.   tabmagic=mp->tabmagic;
  1100.   break;
  1101.   }
  1102.  else mp=mp->next;
  1103. }
  1104.  
  1105. int process(name,cmds)
  1106. unsigned char *name;
  1107. CONTEXT *cmds;
  1108. {
  1109. CONTEXT *context=0;
  1110. unsigned char buf[PATHSIZE];
  1111. KMAP *kmap;
  1112. FILE *fd=fopen(name,"r");
  1113. int x,y,n,z;
  1114. if(!fd) return -1;
  1115. printf("Processing keymap file %s ...",name);
  1116. fflush(stdout);
  1117. while(fgets(buf,256,fd))
  1118.  {
  1119.  if(buf[0]=='*')
  1120.   {
  1121.   struct mpair *mp=(struct mpair *)calloc(sizeof(struct mpair),1);
  1122.   int c=0;
  1123.   mp->next=mpairs;
  1124.   mpairs=mp;
  1125.   for(x=0;buf[x];x++)
  1126.    if(buf[x]==' ' || buf[x]=='\t' || buf[x]=='\n')
  1127.     {
  1128.     c=buf[x];
  1129.     buf[x]=0;
  1130.     break;
  1131.     }
  1132.   mp->s=strdupp(buf+1);
  1133.   buf[x]=c;
  1134.   while(buf[x])
  1135.    if(buf[x]!=' ' && buf[x]!='\t' && buf[x]!='\n') break;
  1136.    else x++;
  1137.   while(buf[x] && buf[x]!=' ' && buf[x]!='\t' && buf[x]!='\n')
  1138.    {
  1139.    switch(buf[x])
  1140.     {
  1141.    case 'O':
  1142.    case 'o': mp->overwrite=1;
  1143.    break;
  1144.    case 'W':
  1145.    case 'w': mp->wrap=1;
  1146.    break;
  1147.    case 'a':
  1148.    case 'A': mp->autoind=1;
  1149.    break;
  1150.    case 'p':
  1151.    case 'P': mp->pic=1;
  1152.    break;
  1153.    case 't':
  1154.    case 'T': mp->tabmagic=1;
  1155.     }
  1156.    x++;
  1157.    }
  1158.   continue;
  1159.   }
  1160.  if(buf[0]==':' && buf[1]!=' ' && buf[1]!='\t')
  1161.   {
  1162.   for(x=0;buf[x];x++)
  1163.    if(buf[x]==' ' || buf[x]=='\t' || buf[x]=='\n')
  1164.     {
  1165.     buf[x]=0;
  1166.     break;
  1167.     }
  1168.   context=cmds;
  1169.   while(strcmp(buf+1,context->name))
  1170.    {
  1171.    context=context->next;
  1172.    if(!context)
  1173.     {
  1174.     printf("Unknown context name in keyboard file\n");
  1175.     return -1;
  1176.     }
  1177.    }
  1178.   continue;
  1179.   }
  1180.  for(x=0;buf[x];x++) if(buf[x]==' ' || buf[x]=='\t' || buf[x]=='\n') break;
  1181.  if(buf[0]==' ' || buf[0]=='\t' || buf[0]=='\n' || !buf[x]) continue;
  1182.  if(!context)
  1183.   {
  1184.   printf("No context selected for key\n");
  1185.   return -1;
  1186.   }
  1187.  buf[x]=0;
  1188.  for(y=0;y!=context->size;y++)
  1189.    if(!strcmp(context->cmd[y].name,buf)) goto foundit;
  1190.  printf("Key function not found %s\n",buf);
  1191.  continue;
  1192.  foundit:
  1193.  kmap=0;
  1194.  n= -1;
  1195.  for(++x;buf[x];x++) if(buf[x]!=' ' && buf[x]!='\t') break;
  1196.  while(1)
  1197.   {
  1198.   int c;
  1199.   if(buf[x]==' ') x++;
  1200.   if(!buf[x]) break;
  1201.   if(buf[x]=='\n' || buf[x]==' ' || buf[x]=='\t') break;
  1202.   /* Got Next key */
  1203.   x++;
  1204.   if(buf[x-1]=='^')
  1205.    if(buf[x]==' ' || buf[x]=='\t' || buf[x]=='\n' || !buf[x]) c='^';
  1206.    else if(buf[x]=='?') c=127, x++;
  1207.    else c=(buf[x]&0x1f), x++;
  1208.   else if((buf[x-1]&0x5f)=='S' && (buf[x]&0x5f)=='P') c=' ', x++;
  1209.   else c=buf[x-1];
  1210.   /* Add it as if it were a submap */
  1211.   if(!kmap)
  1212.    {
  1213.    if(!(kmap=context->kmap))
  1214.     {
  1215.     kmap=(KMAP *)malloc(sizeof(KMAP));
  1216.     kmap->keys=(KEY *)malloc(4*sizeof(KEY));
  1217.     kmap->size=4;
  1218.     kmap->len=0;
  1219.     context->kmap=kmap;
  1220.     }
  1221.    }
  1222.   else
  1223.    if(kmap->keys[n].k&KEYSUB) kmap=(KMAP *)(kmap->keys[n].n);
  1224.    else
  1225.     {
  1226.     kmap->keys[n].n=(unsigned)malloc(sizeof(KMAP));
  1227.     kmap->keys[n].k|=KEYSUB;
  1228.     kmap=(KMAP *)(kmap->keys[n].n);
  1229.     kmap->keys=(KEY *)malloc(4*sizeof(KEY));
  1230.     kmap->len=0;
  1231.     kmap->size=4;
  1232.     }
  1233.   for(n=0;n!=kmap->len;n++)
  1234.    if((kmap->keys[n].k&KEYMASK)==c) goto sub;
  1235.    else if((kmap->keys[n].k&KEYMASK)>c) break;
  1236.   if(kmap->len==kmap->size)
  1237.    kmap->keys=(KEY *)realloc(kmap->keys,sizeof(KEY)*(kmap->size+=8));
  1238.   for(z=kmap->len;z!=n;z--) kmap->keys[z]=kmap->keys[z-1];
  1239.   kmap->len++;
  1240.   kmap->keys[n].k=c;
  1241.   kmap->keys[n].n=y;
  1242.   sub:;
  1243.   }
  1244.  }
  1245. fclose(fd);
  1246. printf("done\n");
  1247. return 0;
  1248. }
  1249.  
  1250. int main(argc,argv)
  1251. unsigned char *argv[];
  1252. {
  1253. if(process(KEYMAP,&km))
  1254.  {
  1255.  unsigned char *hh=(unsigned char *)getenv("HOME");
  1256.  if(!hh) goto in;
  1257.  strcpy(gfnam,hh);
  1258.  strcat(gfnam,"/");
  1259.  strcat(gfnam,KEYMAP);
  1260.  if(process(gfnam,&km))
  1261.   {
  1262.   in:
  1263.   if(process(KEYDEF,&km))
  1264.    {
  1265.    printf("Couldn't open keymap\n");
  1266.    return 1;
  1267.    }
  1268.   }
  1269.  }
  1270. curmap=km.kmap;
  1271. if(argc>2)
  1272.  {
  1273.  fputs("\nIllegal number of command line arguments",stderr);
  1274.  fputs("\nEditor Command Format:  e [filename]\n",stderr);
  1275.  return 0;
  1276.  }
  1277. termtype();
  1278. curwin=(struct window *)malloc(sizeof(struct window));
  1279. topwin=curwin;
  1280. curwin->next=curwin;
  1281. curwin->prev=curwin;
  1282. markbuf=0;
  1283. curwin->height=height;
  1284. curwin->wind=0;
  1285. curwin->buffer=(struct buffer *)malloc(sizeof(struct buffer));
  1286. curbuf=curwin->buffer;
  1287. curbuf->count=1;
  1288. aopen();
  1289. dopen();
  1290. fmopen();
  1291. bof();
  1292. options=0;
  1293. sstring[0]=0;
  1294. rstring[0]=0;
  1295. leave=0;
  1296.  
  1297. rmargin=width-2;
  1298. tabmagic=0;
  1299. wrap=1;
  1300. autoind=0;
  1301. overwrite=0;
  1302. pic=0;
  1303. stmode("");
  1304.  
  1305. gfnam[0]=0;
  1306.  
  1307. if(argc==2)
  1308.  {
  1309.  strcpy(gfnam,argv[1]);
  1310.  stmode(gfnam);
  1311.  handle=fopen(argv[1],"r");
  1312.  if(handle)
  1313.   {
  1314.   if(!fminsfil(handle))
  1315.    omsg=(unsigned char *)"\033[7mError reading file\033[m";
  1316.   else
  1317.    changed=0;
  1318.   fclose(handle);
  1319.   }
  1320.  else
  1321.   {
  1322.   if(errno==ENOENT)
  1323.    {
  1324.    omsg=(unsigned char *)"New File";
  1325.    backup=1;
  1326.    }
  1327.   else
  1328.    omsg=(unsigned char *)"\033[7mError opening file\033[m";
  1329.   }
  1330.  }
  1331. else omsg=(unsigned char *)"New File";
  1332. edit();
  1333. aclose();
  1334. return 0;
  1335. }
  1336.  
  1337. tsignal(sig)
  1338. {
  1339. handle=fopen(ABORT,"w+");
  1340. fmpoint(0);
  1341. fmsave(handle,fmsize());
  1342. fclose(handle);
  1343. /*
  1344. aclose();
  1345. printf("\rE aborted by signal %d\r\n",sig);
  1346. printf("Last edit file stored in file called aborted.e\r\n");
  1347. */
  1348. _exit(1);
  1349. }
  1350. @EOF
  1351.  
  1352. chmod 600 j.c
  1353.  
  1354. echo x - j.h
  1355. cat >j.h <<'@EOF'
  1356. /* J editor header file
  1357.    Copyright (C) 1991 Joseph H. Allen
  1358.  
  1359. This file is part of J (Joe's Editor)
  1360.  
  1361. J is free software; you can redistribute it and/or modify it under the terms
  1362. of the GNU General Public License as published by the Free Software
  1363. Foundation; either version 1, or (at your option) any later version. 
  1364.  
  1365. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  1366. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  1367. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  1368.  
  1369. You should have received a copy of the GNU General Public License
  1370. along with GNU Emacs; see the file COPYING.  If not, write to
  1371. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1372.  
  1373. /* File characteristics */
  1374.  
  1375. #define NL '\n'            /* End of line character */
  1376. #define TAB '\t'        /* Tab character */
  1377. #define TABWIDTH 8        /* Tab width */
  1378.  
  1379. /* Types used in the file buffer */
  1380.  
  1381. typedef unsigned char * TXTPTR;    /* Pointer to text in the buffer */
  1382. typedef unsigned TXTSIZ;    /* Integer to hold size of file */
  1383. #define TXTFREE(a) free(a)    /* Free a buffer */
  1384. #define TXTMALLOC(a) malloc(a)    /* Allocate a buffer */
  1385. #define TXTREALLOC(a,b) realloc((a),(b))    /* Reallocate a buffer */
  1386.  
  1387. /* File names and characteristics */
  1388.  
  1389. #define PATHSIZE 256        /* Maximum path length */
  1390. #define KEYMAP "keymap.j"    /* Keymap file */
  1391. /* #define KEYDEF "/usr/bin/keymap.j"    Default keymap file */
  1392. #define ABORT "aborted.j"    /* Aborted file */
  1393.  
  1394. /* The current file buffer */
  1395. /* When you change windows, these variables get stored in the 'struct buffer'
  1396.    associated with the old window and are load with the values in the
  1397.    'struct buffer' for the new window */
  1398.  
  1399. extern TXTSIZ bufsiz;        /* Size of malloc block buffer is in */
  1400. extern TXTPTR point;        /* The point (cursor) */
  1401. extern TXTPTR buffer;        /* The buffer */
  1402. extern TXTPTR filend;        /* First char not in buffer */
  1403. extern TXTPTR hole;        /* Address of hole */
  1404. extern TXTPTR ehole;        /* First char not in hole */
  1405. extern int changed;        /* Set if buffer changed */
  1406. extern int backup;        /* Set if backup file has been made */
  1407. extern unsigned char gfnam[PATHSIZE];
  1408.                 /* Current edit file name.  "" for unnamed */
  1409.  
  1410. #define HOLESIZE 1024        /* Amount file buffer grows by */
  1411.  
  1412. /*******************************************************/
  1413. /* Basic file buffer manipulation functions and macros */
  1414. /*******************************************************/
  1415.  
  1416. fminsu();        /* fminsu(size) Adjust pointers by amnt inserted */
  1417. fmdelu();        /* fmdelu(size) Adjust pointers by amount deleted */ 
  1418. /* The pointers the above two functions currently update include:
  1419.     The pointer to start of each window which references the current
  1420.     buffer.
  1421.  
  1422.     The pointer to cursor in each window which reference the current
  1423.     buffer but not the one for the current window.
  1424.  
  1425.     The begin & end pointers to the marked block if they are in the
  1426.     current buffer.
  1427. */
  1428.  
  1429. /* Return size of hole */
  1430.  
  1431. #define fmholesize() (ehole-hole)
  1432.  
  1433. /* Read character at the point */
  1434.  
  1435. #define fmrc() (point==hole?*(point=ehole):*point)
  1436.  
  1437. /* Overtype character at the point */
  1438.  
  1439. #define fmwc(c) (((point==hole)?point=ehole:0),((point==filend)?(fmexpand(1),\
  1440. filend++):0),*point=(c),changed=1)
  1441.  
  1442. /* Read character at point and advance point */
  1443.  
  1444. #define fmgetc() ((point==hole)?(point=ehole+1,*ehole):*(point++))
  1445.  
  1446. /* Overtype character at point and advance point */
  1447.  
  1448. #define fmputc(c) (((point==hole)?point=ehole:0),((point==filend)?(fmexpand(1),\
  1449. filend++):0),*(point++)=(c),changed=1)
  1450.  
  1451. /* Insert character at point */
  1452.  
  1453. #define fminsc(c) ( fminsu(1), \
  1454. (point!=hole?fmhole():0), (hole==ehole?fmbig(1):0),\
  1455. *(hole++)=(c), changed=1)
  1456.  
  1457. /* Return the byte offset from the beginning of the buffer to the point */
  1458.  
  1459. #define fmnote() ((point>=ehole)?(point-buffer)-(ehole-hole):point-buffer)
  1460.  
  1461. /* Return the size of the file in the buffer */
  1462.  
  1463. #define fmsize() ((filend-buffer)-(ehole-hole))
  1464.  
  1465. /* Return true if the point is at the end of the file */
  1466.  
  1467. #define fmeof() ((point==hole)?(ehole==filend):(point==filend))
  1468.  
  1469. /* Position the point to a byte offset from the beginning of the file */
  1470.  
  1471. #define fmpoint(x) (point=buffer+(x), (point>hole)?(point+=ehole-hole):0)
  1472.  
  1473. /* Retreat the point and then read the character that's there */
  1474.  
  1475. #define fmrgetc() (point==ehole?*(point=hole-1):*(--point))
  1476.  
  1477. /* Position the point to the next NL or the end of the file.  If the point
  1478.    is already at a NL, it is set to the next NL. Return 0 if not found, 1
  1479.    if found */
  1480.  
  1481. #define fmnnl() (fmeof()?0:(fmgetc(),fmfnl()))
  1482.  
  1483. /* Set the point to the beginning of the file or the previous NL.  If the
  1484.    point is already at a NL, it is set to the one before it.  Return 0 if
  1485.    not found, 0 if found */
  1486.  
  1487. #define fmnrnl() (fmnote()?(fmrgetc(),fmrnl()):0)
  1488.  
  1489. fmopen();            /* fmopen() Initialize current edit buffer */
  1490. fmexpand();            /* fmexpand(amount) Make buffer bigger */
  1491. fmhole();            /* fmhole() Move hole to point */
  1492. fmbig();            /* fmbig(size) Make hole at least size */
  1493. int fmfnl();            /* Find first NL.  Returns 0 if not found */
  1494.                 /* If at an NL already, point is not moved */
  1495. int fmrnl();            /* Find NL in reverse.  Rtns 0 if not found */
  1496.                 /* If at an NL already, point is not moved */
  1497. fminss();            /* fminss(blk,size) Insert a block at point */
  1498. int fmcmp();            /* fmcmp(blk,size) return 0 if matching */
  1499. int tupp();            /* tupp(c) Convert char to uppercase */
  1500. int fmicmp();            /* Same as fmcmp but ignore case */
  1501. int fmsave();            /* fmsave(FILE,size) Save at point in file */
  1502. int fminsfil();            /* fminsfil(FILE) Insert file at point */
  1503.  
  1504. /******************/
  1505. /* Terminal stuff */
  1506. /******************/
  1507.  
  1508. /* Terminal characteristics (terminal must be vt100ish) */
  1509.  
  1510. extern int width;        /* Screen width */
  1511. extern int height;        /* Screen height */
  1512. extern int scroll;        /* Set if terminal has scrolling regions */
  1513. termtype();            /* termtype() determine above variables */
  1514.  
  1515. /* Terminal state */
  1516.  
  1517. extern int smode;        /* Current character attributes */
  1518. extern int tops;        /* Scroll region top (-1 for unknown) */
  1519. extern int bots;        /* Scroll region bottem */
  1520. extern int oxpos;        /* Cursor position */
  1521. extern int oypos;
  1522. extern int *scrn;        /* Screen buffer
  1523.                     -1 means unknown character
  1524.                     0 - 255 means known character
  1525.                 */
  1526.  
  1527. extern unsigned char *omsg;    /* Opening message */
  1528. dopen();                        /* Open display (clear it, allocate scrn,
  1529.                    etc.) */
  1530. dclose();                       /* dclose(s) Show final message and close
  1531.                    display */
  1532.  
  1533. cposs();            /* cpos(row,col) Set cursor position */
  1534. cpos();                /* cpos(row,col) Set cursor position and
  1535.                    update ox/oypos */
  1536. setregn();            /* setregn(top,bot) Set scroll region */
  1537.  
  1538. attrib();            /* attrib(mask) Set attributes */
  1539. #define INVERSE 1
  1540. #define BLINK 2
  1541. #define UNDERLINE 4
  1542. #define BOLD 8
  1543.  
  1544. int tattrib();            /* tattrib(c) Set attribute depending on char:
  1545.                     0 - 31        Underlined
  1546.                     32 - 126    Normal
  1547.                     127        Underlined
  1548.                     128 - 255     As above but also
  1549.                             inverse
  1550.                 Returns char to show (ctrl chars converted
  1551.                 to normal)
  1552.                 */
  1553.  
  1554. tputcc();            /* tputcc(c) Set attribute and output char */
  1555. tputss();            /* tputss(s) Use tputcc to output a string */
  1556.  
  1557. /*****************/
  1558. /* Screen update */
  1559. /*****************/
  1560.  
  1561. /* Flags which high-level edit functions set to control the screen
  1562.    update.  All three are initialized to 0 before an edit function
  1563.    is executed */
  1564.  
  1565. extern int uuu;            /* Set is no screen update needed */
  1566. extern int cntr;        /* Set to center cursor to middle of
  1567.                    screen if the screen will scroll
  1568.                    (for search/replace) */
  1569. extern int newy;        /* Set if row changed */
  1570. extern int updall;        /* Set to update all windows, not just
  1571.                    the ones with same buffer */
  1572.  
  1573. /* Flags which indicate the current progress of a screen update (I.E., so
  1574.    we can continue if user interrupts screen update) */
  1575.  
  1576. extern int upd;            /* Set if a screen update should be done */
  1577. extern int hupd;        /* Set if a help update should be done */
  1578.  
  1579. extern int helpon;        /* Set if help screen is on */
  1580. extern int wind;        /* Number of help lines */
  1581.  
  1582. extern int xpos;        /* Requested x & y positions (as determined */
  1583. extern int ypos;        /* by scroll calculator: dupdate1 */
  1584.  
  1585. extern TXTSIZ saddr;        /* Byte offset to first char of first screen
  1586.                    line (of current window) */
  1587. extern TXTSIZ xoffset;        /* Cols current window is scrolled to right */
  1588. extern TXTSIZ extend;        /* Column number if past end of line or in
  1589.                    tab stop */
  1590.  
  1591. /* Help text */
  1592.  
  1593. extern unsigned char help[];    /* Help text */
  1594. #define helplines 9
  1595. #define helpwidth 79
  1596.  
  1597. /* Functions for doing screen update */
  1598.  
  1599. clreolchk();        /* clreolchk(lin,col) Clear to end of line if needed */
  1600. int udline();        /* udline(lin) Update a single line.  Return true
  1601.                EOF reached */
  1602. int udscrn();        /* Update screen (returns true if it finished) */
  1603. dupdate1();        /* dupdate1(flg) Recalculate cursor, scroll & update
  1604.                screen (sets cursor position if flg is set) */
  1605. dupdatehelp();        /* Update help */
  1606. dupdate();        /* Update help and screen */
  1607. invalidate();        /* invalidate(lin) Invalidate a line so it gets upd. */
  1608.  
  1609. /****************/
  1610. /* Window Stuff */
  1611. /****************/
  1612.  
  1613. /* Each file that's edited has a 'struct buffer' associated with it.
  1614.    This stores the buffer variables when the buffer is not the current
  1615.    buffer (I.E., when the cursor is in a window for another file).
  1616. */
  1617.  
  1618. struct buffer
  1619.  {
  1620.  int count;        /* Reference count (No. windows into this buffer) */
  1621.  TXTSIZ bufsiz;        /* Size of malloc block buffer is in */
  1622.  TXTPTR buf;        /* The buffer */
  1623.  TXTPTR filend;        /* First char not in buffer */
  1624.  TXTPTR hole;        /* Address of hole */
  1625.  TXTPTR ehole;        /* First char not in hole */
  1626.  int changed;        /* Set if buffer changed */
  1627.  int backup;        /* Set if backup file has been made */
  1628.  unsigned char gfnam[PATHSIZE];    /* Current edit file name.  "" for unnamed */
  1629.  };
  1630.  
  1631. /* Each window has a 'struct window' associated with it */
  1632.  
  1633. struct window
  1634.  {
  1635.  struct window *next;    /* Doubly linked list of windows */
  1636.  struct window *prev;
  1637.  
  1638.  struct buffer *buffer;    /* The buffer this window looks at */
  1639.  
  1640.  /* Screen variables for each window */
  1641.  
  1642.  TXTSIZ saddr;        /* Byte offset to first character of first line in
  1643.                 window */
  1644.  TXTSIZ xoffset;    /* No. columns the screen is scrolled to the right */
  1645.  
  1646.  /* Window size */
  1647.  
  1648.  int wind;         /* Starting screen line */
  1649.             /* wind is not the same as 'wind' the number of
  1650.                help lines */
  1651.  int height;       /* Height of window */
  1652.  int hheight;      /* Height before help turned on */
  1653.  
  1654.  /* Edit modes */
  1655.  
  1656.  int pic;
  1657.  int autoind;
  1658.  int overwrite;
  1659.  int wrap;
  1660.  int tabmagic;
  1661.  TXTSIZ rmargin;
  1662.  
  1663.  /* Cursor position */
  1664.  
  1665.  TXTSIZ extend;        /* Column number if cursor is past end of line or
  1666.                 if it's in a tab stop */
  1667.  TXTSIZ cursor;        /* Byte offset (in buffer) to the cursor */
  1668.  
  1669.  };
  1670.  
  1671. extern struct window *wfirst;    /* Doubly linked list of windows */
  1672. extern struct window *wlast;
  1673.  
  1674. extern struct window *curwin;    /* Current window */
  1675. extern struct buffer *curbuf;    /* Current buffer */
  1676. extern struct window *topwin;    /* First window on the screen */
  1677.  
  1678. /* Keyboard and command table handler */
  1679.  
  1680. typedef struct key KEY;
  1681. struct key
  1682.  {
  1683.  int k;                 /* Key value */
  1684.  int n;                 /* Command number or submap address */
  1685.             /* sizeof(int) had better = sizeof(KMAP *) */
  1686.  };
  1687.  
  1688. typedef struct kmap KMAP;
  1689. struct kmap
  1690.  {
  1691.  int len;          /* Number of KEY entries */
  1692.  int size;         /* Size of malloc block */
  1693.  KEY *keys;             /* KEYs.  Sorted. */
  1694.  };
  1695.  
  1696. /* Masks & bits for k */
  1697.  
  1698. #define KEYMASK 0x7fff
  1699. #define KEYSUB 0x8000    /* Set for submap */
  1700.  
  1701. /* A command entry */
  1702.  
  1703. typedef struct cmd CMD;
  1704. struct cmd
  1705.  {
  1706.  char *name;
  1707.  int flag;
  1708.  int (*func)();
  1709.  };
  1710.  
  1711. /* A context (group of related commands) */
  1712.  
  1713. typedef struct context CONTEXT;
  1714. struct context
  1715.  {
  1716.  CONTEXT *next;        /* List of all contexts */
  1717.  char *name;            /* Name of this context */
  1718.  KMAP *kmap;        /* Top level keymap for this context */
  1719.  int size;        /* Number of entries in this context */
  1720.  CMD *cmd;        /* The entries themselves (sorted) */
  1721.  };
  1722.  
  1723. int dokey();        /* dokey(c) Execute next key */
  1724. extern int quoteflg;    /* Set if next key is quoted */
  1725. extern int quote8th;    /* Set if next key is quoted */
  1726.  
  1727. /* dokey() Return values */
  1728.  
  1729. #define Kaccept -1    /* Key accepted but not executed */
  1730. #define Kbad -2        /* Bad key */
  1731. /* dokey() used to return a function number; now it executes the function
  1732.    itself so the return values are meaningless */
  1733.  
  1734. /* Messages and queries */
  1735.  
  1736. /* These are all hacks because they return/check for exact key values
  1737.    and don't know about the key table.  Someday a key 'context' should
  1738.    be added for these
  1739. */
  1740.  
  1741. int getl();        /* getl(prompt,line) Get a line of input */
  1742.             /* Returns: -1 if user hits ^L
  1743.                      1 if user hits \n or \r
  1744.                      0 if user hits ^C
  1745.                 (yes this is a stupid hack)
  1746.             */
  1747.  
  1748. msg();            /* msg(s) Show a message until user hits a key */
  1749.  
  1750. int askyn();        /* askyn(s) Yes/No question 
  1751.             Returns: 'Y', 'N' or -1 for ^C */
  1752.  
  1753. int query();        /* query(s) Show message, wait for user to hit a key,
  1754.                then return key. */
  1755.  
  1756. int nquery();        /* nquery(s) Same as query but leave cursor on
  1757.                edit screen */
  1758. imsg();                 /* imsg() Show opening message */
  1759.  
  1760. /*******************************************/
  1761. /* High-level edit functions and variables */
  1762. /*******************************************/
  1763.  
  1764. /* Edit modes */
  1765.  
  1766. extern int pic;            /* Set for picture mode */
  1767. extern int autoind;        /* Set for autoindent */
  1768. extern int overwrite;        /* Set for overwrite */
  1769. extern int wrap;        /* Set for autowrap */
  1770. extern int tabmagic;        /* Set for magical tabs */
  1771. extern TXTSIZ rmargin;        /* Current right margin */
  1772.  
  1773. /****************************/
  1774. /* Search and replace stuff */
  1775. /****************************/
  1776.  
  1777. /* Search & replace options */
  1778.  
  1779. #define s_ignore 1        /* Ignore case */
  1780. #define s_backwards 2        /* Search backwards */
  1781. #define s_replace 4        /* Replace */
  1782. #define s_regex 8        /* Regular expression search */
  1783.  
  1784. extern int options;        /* Search options */
  1785. extern unsigned char sstring[PATHSIZE];    /* Search string */
  1786. extern unsigned char rstring[PATHSIZE];    /* Replace string */
  1787. extern int len;            /* Length of search string */
  1788.  
  1789. /**********/
  1790. /* Blocks */
  1791. /**********/
  1792.  
  1793. extern TXTSIZ markb;        /* Begining of block */
  1794. extern TXTSIZ marke;        /* End of block */
  1795. extern struct buffer *markbuf;    /* Buffer block is in or 0 for no block */
  1796.  
  1797. /**************************************/
  1798. /* High level edit function utilities */
  1799. /**************************************/
  1800.  
  1801. extern int leave;        /* Edit function sets this to leave the editor
  1802.                    after the function returns */
  1803.  
  1804. dnarw();            /* Move cursor to next line */
  1805.                 /* Column number is preserved */
  1806. TXTSIZ calcs();            /* Calculate number of whitespace columns
  1807.                    at beginning of line.  Cursor is left
  1808.                    at first non-whitespace character */
  1809. int saveit1();            /* saveit1(s) Save buffer in file & clear
  1810.                    changed */
  1811. itype();
  1812. ltarw();            /* Move cursor left (goes to end of previous
  1813.                    line if at beginning of line) */
  1814. uparw();            /* Move cursor up (preserves column) */
  1815. rtarw();                        /* Move cursor right (goes to beginning of
  1816.                    next line if at end of line) */
  1817.  
  1818. /* Return current column number of cursor */
  1819.  
  1820. #define getcol() (extend?extend:getrcol())
  1821.  
  1822. TXTSIZ getrcol();        /* Get column number of point */
  1823. gocol();            /* gocol(col) Set cursor (point/extend) to
  1824.                    column number */
  1825. unfill();            /* Remove trailing spaces from line */
  1826. fillup();                       /* Fill to extend position (use this only
  1827.                    if extend if past end of line, not for
  1828.                    if extend is in tab stop) */
  1829.  
  1830. int search();            /* Execute a search.  Returns 1 if found,
  1831.                    0 if not */
  1832.  
  1833. /* Window functions */
  1834.  
  1835. ldwin();            /* ldwin(window) load window */
  1836. stwin();            /* stwin(window) save window */
  1837. ldbuf();            /* ldbuf(buf) load buf if it's not already */
  1838. ldbuf1();            /* ldbuf1(buf) load buf always */
  1839. stbuf();            /* stbuf(buf) store buffer */
  1840. wfit();                /* make sure the current window is on screen */
  1841.  
  1842. /* High Level (user) edit functions */
  1843.  
  1844. wnext();            /* goto next window */
  1845. wprev();            /* goto previous window */
  1846. wexplode();            /* show 1 or all windows */
  1847. wgrow();            /* make window bigger */
  1848. wshrink();            /* make window smaller */
  1849. wedit();            /* edit a new file */
  1850. wsplit();            /* Split window into 2 */
  1851.  
  1852. rewrite();            /* Rewrite screen */
  1853. thelp();            /* Toggle help screen */
  1854. bof();                /* Goto beginning of file */
  1855. eof();                /* Goto end of file */
  1856. bol();                /* Goto beginning of line */
  1857. eol();                /* Goto end of line */
  1858. urtarw();            /* Move cursor right (scroll if need to) */
  1859. ultarw();
  1860. uuparw();
  1861. udnarw();
  1862. delch();            /* Delete character */
  1863. type();                /* type(c) type a character */
  1864. inss();                /* insert a space */
  1865. backs();            /* backspace */
  1866. eexit();            /* Exit & abort */
  1867. pgup();                /* 1/2 Page up */
  1868. pgdn();                /* 1/2 Page down */
  1869. deleol();            /* Erase end of line */
  1870. dellin();            /* Erase entire line */
  1871. exsave();            /* Save and exit */
  1872. saveit();            /* Save current file */
  1873. findline();            /* Goto line No. */
  1874. findfirst();            /* Find some text */
  1875. findnext();            /* Find next occurance */
  1876. setbeg();            /* Set beginning of block */
  1877. setend();            /* Set end of block */
  1878. writeblk();            /* Write block to file */
  1879. moveblk();            /* Move block to point */
  1880. cpyblk();            /* Copy block to point */
  1881. delblk();            /* Delete block */
  1882. insfil();            /* Insert a file */
  1883. push();                /* Execute a shell */
  1884. mode();                /* Change edit mode */
  1885. ctrlin();            /* Center current line */
  1886. reformat();            /* Reformat current paragraph */
  1887. killword();            /* Delete word */
  1888. backword();            /* Delete word to the left */
  1889. wrdl();                /* goto previous word */
  1890. wrdr();                /* goto next word */
  1891. edit();                /* Main edit loop */
  1892.  
  1893. extern FILE *handle;        /* File handle used for many various things */
  1894. extern TXTSIZ added;        /* Number of chars autoindent added
  1895.                 (obsolete?) */
  1896.  
  1897. /* Portable strdup() */
  1898.  
  1899. #define strdupp(x) ((unsigned char *)strcpy((unsigned char *)malloc(strlen(x)+1),(x)))
  1900. @EOF
  1901.  
  1902. chmod 600 j.h
  1903.  
  1904. echo x - keymapbsd
  1905. cat >keymapbsd <<'@EOF'
  1906.  
  1907.                               Key map for e editor
  1908.  
  1909.  E looks for this file in:
  1910.         1 - Current directory
  1911.         2 - User's home directory
  1912.         3 - /usr/bin
  1913.  
  1914.  ******************************************************************************
  1915.  * Notes about keymap syntax:                                                 *
  1916.  *                                                                            *
  1917.  * Any line beginning with whitespace is a comment line.  At least 2          *
  1918.  * characters of whitespace past the end of definition line also begin a      *
  1919.  * comment.                                                                   *
  1920.  *                                                                            *
  1921.  * There are two types of lines as follows:                                   *
  1922.  *                                                                            *
  1923.  * :<context>                   This gives the name of a context.  Bindings   *
  1924.  *                              following this line are added into this       *
  1925.  *                              context.                                      *
  1926.  *                                                                            *
  1927.  * <function> <key> <key> ...   This binds a key sequence to a function       *
  1928.  *                                                                            *
  1929.  * <key> is any single character or                                           *
  1930.  * sp    for space or                                                         *
  1931.  * ^     followed by characters in the range @ - _ for control characters or  *
  1932.  * ^?    for del                                                              *
  1933.  *                                                                            *
  1934.  * Any number of whitespace characters may appear between <function> and the  *
  1935.  * first <key>, but there must be single spaces between <key>s.               *
  1936.  *                                                                            *
  1937.  ******************************************************************************
  1938.  
  1939.  File name dependant mode settings
  1940.  
  1941.    a   autoindent (indent)
  1942.    o   overwrite  (insert)
  1943.    p   picture mode (no picture mode)
  1944.    w   word wrap (no word wrap)
  1945.    t   tab magic (no tab magic)
  1946.  
  1947.  Note that when there ambiguities (extensions which begin the same), the last
  1948.  one is chosen.
  1949.  
  1950. *       wt              Default for unknown extensions.  This must be first
  1951. *.c     at              C programs
  1952. *.h     at              C header files
  1953. *.p     at              Pascal programs
  1954. *.f     at              Fortran programs
  1955. *.e     at              This file
  1956.  
  1957.  For the E editor there is currently only one context:
  1958.  
  1959. :main
  1960.  
  1961. backs           ^H              Backspace
  1962. backs        ^?
  1963. backword        ^O              Backspace word
  1964. bof             ^K U            Move cursor to beginning of file
  1965. bof             ^K ^U
  1966. bof             ^K u
  1967. bol             ^A              Move cursor to beginning of line
  1968. bol             ^[ [ H
  1969. bol        ^K ^[ [ H
  1970. bol        ^[ O P
  1971. bol        ^K ^[ O P
  1972. cpyblk          ^K C            Copy previously marked block
  1973. cpyblk          ^K ^C
  1974. cpyblk          ^K c
  1975. ctrlin          ^K A            Center line
  1976. ctrlin          ^K ^A
  1977. ctrlin          ^K a
  1978. delblk          ^K Y            Delete previously marked block
  1979. delblk          ^K ^Y
  1980. delblk          ^K y
  1981. delch           ^D        Delete character
  1982. deleol          ^J              Delete to end of line
  1983. dellin          ^Y              Delete entire line
  1984. dnarw           ^N              Move cursor down
  1985. dnarw           ^[ [ B
  1986. dnarw        ^[ O B
  1987. dnarw        ^K ^[ [ B
  1988. dnarw        ^K ^[ O B
  1989. eexit           ^C              Exit (window/file)
  1990. eexit           ^K Q
  1991. eexit           ^K q
  1992. eof             ^K V            Move cursor to end of file
  1993. eof             ^K ^V
  1994. eof             ^K v
  1995. eol             ^E              Move cursor to end of line
  1996. eol             ^[ [ F
  1997. eol        ^K ^[ [ F
  1998. eol        ^[ O S
  1999. eol        ^K ^[ O S
  2000. exsave          ^K X            Save & exit
  2001. exsave          ^K ^X
  2002. exsave          ^K x
  2003. findfirst       ^K F            Find text
  2004. findfirst       ^K ^F
  2005. findfirst       ^K f
  2006. findnext        ^L              Find next
  2007. findline        ^K L            Goto line number
  2008. findline        ^K ^L
  2009. findline        ^K l
  2010. gotomatching    ^G
  2011. indentl        ^K ,        Indent left
  2012. indentr        ^K .        Indent right
  2013. insfil          ^K R            Insert a file
  2014. insfil          ^K ^R
  2015. insfil          ^K r
  2016.  inss            ^G              Insert a space
  2017. inss            ^[ [ L
  2018. inss        ^K ^[ [ L
  2019. killword        ^W              Delete word under cursor
  2020. ltarw           ^B              Move cursor left
  2021. ltarw           ^[ [ D
  2022. ltarw        ^K ^[ [ D
  2023. ltarw        ^[ O D
  2024. ltarw        ^K ^[ O D
  2025. mode            ^T              Change mode
  2026. moveblk         ^K M            Move previously marked block
  2027. moveblk         ^K ^M
  2028. moveblk         ^K m
  2029. pgdn            ^V              Move cursor 1/2 page down
  2030. pgdn            ^[ [ G
  2031. pgdn        ^K ^[ [ G
  2032. pgdn            ^[ [ 6 ~
  2033. pgdn        ^K ^[ [ 6 ~
  2034. pgup            ^U              Move curosr 1/2 page up
  2035. pgup            ^[ [ I
  2036. pgup        ^K ^[ [ I
  2037. pgup        ^[ [ 5 ~
  2038. pgup        ^K ^[ [ 5 ~
  2039. push            ^K Z            Push to a shell
  2040. push            ^K ^Z
  2041. push            ^K z
  2042. redo        ^K +        Redo
  2043. reformat        ^K J            Reformat paragraph
  2044. reformat        ^K ^J
  2045. reformat        ^K j
  2046. rewrite         ^R              Retype screen
  2047. rtarw           ^F              Move cursor right
  2048. rtarw           ^[ [ C
  2049. rtarw        ^K ^[ [ C
  2050. rtarw        ^[ O C
  2051. rtarw        ^K ^[ O C
  2052. rtn             ^M              The return key
  2053. saveit          ^K D            Save file
  2054. saveit          ^K ^D
  2055. saveit          ^K d
  2056. saveit          ^K S
  2057. saveit          ^K s
  2058. setbeg          ^K B            Set beginning of block
  2059. setbeg          ^K ^B
  2060. setbeg          ^K b
  2061. setend          ^K K            Set end of block
  2062. setend          ^K ^K
  2063. setend          ^K k
  2064. stquote         `               Next character is a control character
  2065. stquote8th      ^\              Next character has 7th bit set
  2066. thelp           ^K H            Toggle help screen on/off
  2067. thelp           ^K ^H
  2068. thelp           ^K h
  2069. thelp           ^[ [ 2 8 ~
  2070. thelp        ^K ^[ [ 2 8 ~
  2071. undo        ^K -        Undelete
  2072. uparw           ^P              Move cursor up
  2073. uparw           ^[ [ A
  2074. uparw        ^K ^[ [ A
  2075. uparw        ^[ O A
  2076. uparw        ^K ^[ O A
  2077. wedit           ^K E            Edit another file
  2078. wedit           ^K ^E
  2079. wedit           ^K e
  2080. wexplode        ^K I            Zoom window
  2081. wexplode        ^K ^I
  2082. wexplode        ^K i
  2083. wgrow           ^K G            Grow window
  2084. wgrow           ^K ^G
  2085. wgrow           ^K g
  2086. wnext           ^K N            Goto next window
  2087. wnext           ^K ^N
  2088. wnext           ^K n
  2089. wprev           ^K P            Goto previous window
  2090. wprev           ^K ^P
  2091. wprev           ^K p
  2092. wrdl            ^Z              Move to previous word
  2093. wrdl        ^[ O Q
  2094. wrdl        ^K ^[ O Q
  2095. wrdr            ^X              Move to next word
  2096. wrdr        ^[ O R
  2097. wrdr        ^K ^[ O R
  2098. writeblk        ^K W            Write previously marked block to a file
  2099. writeblk        ^K ^W
  2100. writeblk        ^K w
  2101. wshrink         ^K T            Shrink window
  2102. wshrink         ^K ^T
  2103. wshrink         ^K t
  2104. wsplit          ^K O            Split window
  2105. wsplit          ^K ^O
  2106. wsplit          ^K o
  2107.  
  2108. type            ^I              Tab
  2109.  
  2110. type            sp              Typable characters
  2111. type            !
  2112. type            "
  2113. type            #       
  2114. type            $
  2115. type            %
  2116. type            &
  2117. type            '
  2118. type            (
  2119. type            )
  2120. type            *
  2121. type            +
  2122. type            ,
  2123. type            -
  2124. type            .
  2125. type            /
  2126. type            0
  2127. type            1
  2128. type            2
  2129. type            3
  2130. type            4
  2131. type            5
  2132. type            6
  2133. type            7
  2134. type            8
  2135. type            9
  2136. type            :
  2137. type            ;
  2138. type            <
  2139. type            =
  2140. type            >
  2141. type            ?
  2142. type            @
  2143. type            A
  2144. type            B
  2145. type            C
  2146. type            D
  2147. type            E
  2148. type            F
  2149. type            G
  2150. type            H
  2151. type            I
  2152. type            J
  2153. type            K
  2154. type            L
  2155. type            M
  2156. type            N
  2157. type            O
  2158. type            P
  2159. type            Q
  2160. type            R
  2161. type            S
  2162. type            T
  2163. type            U
  2164. type            V
  2165. type            W
  2166. type            X
  2167. type            Y
  2168. type            Z
  2169. type            [
  2170. type            \
  2171. type            ]
  2172. type            ^
  2173. type            _
  2174. type            a
  2175. type            b
  2176. type            c
  2177. type            d
  2178. type            e
  2179. type            f
  2180. type            g
  2181. type            h
  2182. type            i
  2183. type            j
  2184. type            k
  2185. type            l
  2186. type            m
  2187. type            n
  2188. type            o
  2189. type            p
  2190. type            q
  2191. type            r
  2192. type            s
  2193. type            t
  2194. type            u
  2195. type            v
  2196. type            w
  2197. type            x
  2198. type            y
  2199. type            z
  2200. type            {
  2201. type            |
  2202. type            }
  2203. type            ~
  2204. @EOF
  2205.  
  2206. chmod 600 keymapbsd
  2207.  
  2208. echo x - keymapxenix
  2209. cat >keymapxenix <<'@EOF'
  2210.  
  2211.                               Key map for e editor
  2212.  
  2213.  E looks for this file in:
  2214.         1 - Current directory
  2215.         2 - User's home directory
  2216.         3 - /usr/bin
  2217.  
  2218.  ******************************************************************************
  2219.  * Notes about keymap syntax:                                                 *
  2220.  *                                                                            *
  2221.  * Any line beginning with whitespace is a comment line.  At least 2          *
  2222.  * characters of whitespace past the end of definition line also begin a      *
  2223.  * comment.                                                                   *
  2224.  *                                                                            *
  2225.  * There are two types of lines as follows:                                   *
  2226.  *                                                                            *
  2227.  * :<context>                   This gives the name of a context.  Bindings   *
  2228.  *                              following this line are added into this       *
  2229.  *                              context.                                      *
  2230.  *                                                                            *
  2231.  * <function> <key> <key> ...   This binds a key sequence to a function       *
  2232.  *                                                                            *
  2233.  * <key> is any single character or                                           *
  2234.  * sp    for space or                                                         *
  2235.  * ^     followed by characters in the range @ - _ for control characters or  *
  2236.  * ^?    for del                                                              *
  2237.  *                                                                            *
  2238.  * Any number of whitespace characters may appear between <function> and the  *
  2239.  * first <key>, but there must be single spaces between <key>s.               *
  2240.  *                                                                            *
  2241.  ******************************************************************************
  2242.  
  2243.  File name dependant mode settings
  2244.  
  2245.    a   autoindent (indent)
  2246.    o   overwrite  (insert)
  2247.    p   picture mode (no picture mode)
  2248.    w   word wrap (no word wrap)
  2249.    t   tab magic (no tab magic)
  2250.  
  2251.  Note that when there ambiguities (extensions which begin the same), the last
  2252.  one is chosen.
  2253.  
  2254. *       wt              Default for unknown extensions.  This must be first
  2255. *.c     at              C programs
  2256. *.h     at              C header files
  2257. *.p     at              Pascal programs
  2258. *.f     at              Fortran programs
  2259. *.e     at              This file
  2260.  
  2261.  For the E editor there is currently only one context:
  2262.  
  2263. :main
  2264.  
  2265. backs           ^H              Backspace
  2266.  backs        ^?        Not on xenix console
  2267. backword        ^O              Backspace word
  2268. bof             ^K U            Move cursor to beginning of file
  2269. bof             ^K ^U
  2270. bof             ^K u
  2271. bol             ^A              Move cursor to beginning of line
  2272. bol             ^[ [ H
  2273. bol        ^K ^[ [ H
  2274. bol        ^[ O P
  2275. bol        ^K ^[ O P
  2276. cpyblk          ^K C            Copy previously marked block
  2277. cpyblk          ^K ^C
  2278. cpyblk          ^K c
  2279. ctrlin          ^K A            Center line
  2280. ctrlin          ^K ^A
  2281. ctrlin          ^K a
  2282. delblk          ^K Y            Delete previously marked block
  2283. delblk          ^K ^Y
  2284. delblk          ^K y
  2285. delch           ^D        Delete character
  2286. delch        ^?        On xenix consol
  2287. deleol          ^J              Delete to end of line
  2288. dellin          ^Y              Delete entire line
  2289. dnarw           ^N              Move cursor down
  2290. dnarw           ^[ [ B
  2291. dnarw        ^[ O B
  2292. dnarw        ^K ^[ [ B
  2293. dnarw        ^K ^[ O B
  2294. eexit           ^C              Exit (window/file)
  2295. eexit           ^K Q
  2296. eexit           ^K q
  2297. eof             ^K V            Move cursor to end of file
  2298. eof             ^K ^V
  2299. eof             ^K v
  2300. eol             ^E              Move cursor to end of line
  2301. eol             ^[ [ F
  2302. eol        ^K ^[ [ F
  2303. eol        ^[ O S
  2304. eol        ^K ^[ O S
  2305. exsave          ^K X            Save & exit
  2306. exsave          ^K ^X
  2307. exsave          ^K x
  2308. findfirst       ^K F            Find text
  2309. findfirst       ^K ^F
  2310. findfirst       ^K f
  2311. findnext        ^L              Find next
  2312. findline        ^K L            Goto line number
  2313. findline        ^K ^L
  2314. findline        ^K l
  2315. gotomatching    ^G
  2316. indentl        ^K ,        Indent left
  2317. indentr        ^K .        Indent right
  2318. insfil          ^K R            Insert a file
  2319. insfil          ^K ^R
  2320. insfil          ^K r
  2321.  inss            ^G              Insert a space
  2322. inss            ^[ [ L
  2323. inss        ^K ^[ [ L
  2324. killword        ^W              Delete word under cursor
  2325. ltarw           ^B              Move cursor left
  2326. ltarw           ^[ [ D
  2327. ltarw        ^K ^[ [ D
  2328. ltarw        ^[ O D
  2329. ltarw        ^K ^[ O D
  2330. mode            ^T              Change mode
  2331. moveblk         ^K M            Move previously marked block
  2332. moveblk         ^K ^M
  2333. moveblk         ^K m
  2334. pgdn            ^V              Move cursor 1/2 page down
  2335. pgdn            ^[ [ G
  2336. pgdn        ^K ^[ [ G
  2337. pgdn            ^[ [ 6 ~
  2338. pgdn        ^K ^[ [ 6 ~
  2339. pgup            ^U              Move curosr 1/2 page up
  2340. pgup            ^[ [ I
  2341. pgup        ^K ^[ [ I
  2342. pgup        ^[ [ 5 ~
  2343. pgup        ^K ^[ [ 5 ~
  2344. push            ^K Z            Push to a shell
  2345. push            ^K ^Z
  2346. push            ^K z
  2347. redo        ^K +        Redo
  2348. reformat        ^K J            Reformat paragraph
  2349. reformat        ^K ^J
  2350. reformat        ^K j
  2351. rewrite         ^R              Retype screen
  2352. rtarw           ^F              Move cursor right
  2353. rtarw           ^[ [ C
  2354. rtarw        ^K ^[ [ C
  2355. rtarw        ^[ O C
  2356. rtarw        ^K ^[ O C
  2357. rtn             ^M              The return key
  2358. saveit          ^K D            Save file
  2359. saveit          ^K ^D
  2360. saveit          ^K d
  2361. saveit          ^K S
  2362. saveit          ^K s
  2363. setbeg          ^K B            Set beginning of block
  2364. setbeg          ^K ^B
  2365. setbeg          ^K b
  2366. setend          ^K K            Set end of block
  2367. setend          ^K ^K
  2368. setend          ^K k
  2369. stquote         `               Next character is a control character
  2370. stquote8th      ^\              Next character has 7th bit set
  2371. thelp           ^K H            Toggle help screen on/off
  2372. thelp           ^K ^H
  2373. thelp           ^K h
  2374. thelp           ^[ [ 2 8 ~
  2375. thelp        ^K ^[ [ 2 8 ~
  2376. undo        ^K -        Undelete
  2377. uparw           ^P              Move cursor up
  2378. uparw           ^[ [ A
  2379. uparw        ^K ^[ [ A
  2380. uparw        ^[ O A
  2381. uparw        ^K ^[ O A
  2382. wedit           ^K E            Edit another file
  2383. wedit           ^K ^E
  2384. wedit           ^K e
  2385. wexplode        ^K I            Zoom window
  2386. wexplode        ^K ^I
  2387. wexplode        ^K i
  2388. wgrow           ^K G            Grow window
  2389. wgrow           ^K ^G
  2390. wgrow           ^K g
  2391. wnext           ^K N            Goto next window
  2392. wnext           ^K ^N
  2393. wnext           ^K n
  2394. wprev           ^K P            Goto previous window
  2395. wprev           ^K ^P
  2396. wprev           ^K p
  2397. wrdl            ^Z              Move to previous word
  2398. wrdl        ^[ O Q
  2399. wrdl        ^K ^[ O Q
  2400. wrdr            ^X              Move to next word
  2401. wrdr        ^[ O R
  2402. wrdr        ^K ^[ O R
  2403. writeblk        ^K W            Write previously marked block to a file
  2404. writeblk        ^K ^W
  2405. writeblk        ^K w
  2406. wshrink         ^K T            Shrink window
  2407. wshrink         ^K ^T
  2408. wshrink         ^K t
  2409. wsplit          ^K O            Split window
  2410. wsplit          ^K ^O
  2411. wsplit          ^K o
  2412.  
  2413. type            ^I              Tab
  2414.  
  2415. type            sp              Typable characters
  2416. type            !
  2417. type            "
  2418. type            #       
  2419. type            $
  2420. type            %
  2421. type            &
  2422. type            '
  2423. type            (
  2424. type            )
  2425. type            *
  2426. type            +
  2427. type            ,
  2428. type            -
  2429. type            .
  2430. type            /
  2431. type            0
  2432. type            1
  2433. type            2
  2434. type            3
  2435. type            4
  2436. type            5
  2437. type            6
  2438. type            7
  2439. type            8
  2440. type            9
  2441. type            :
  2442. type            ;
  2443. type            <
  2444. type            =
  2445. type            >
  2446. type            ?
  2447. type            @
  2448. type            A
  2449. type            B
  2450. type            C
  2451. type            D
  2452. type            E
  2453. type            F
  2454. type            G
  2455. type            H
  2456. type            I
  2457. type            J
  2458. type            K
  2459. type            L
  2460. type            M
  2461. type            N
  2462. type            O
  2463. type            P
  2464. type            Q
  2465. type            R
  2466. type            S
  2467. type            T
  2468. type            U
  2469. type            V
  2470. type            W
  2471. type            X
  2472. type            Y
  2473. type            Z
  2474. type            [
  2475. type            \
  2476. type            ]
  2477. type            ^
  2478. type            _
  2479. type            a
  2480. type            b
  2481. type            c
  2482. type            d
  2483. type            e
  2484. type            f
  2485. type            g
  2486. type            h
  2487. type            i
  2488. type            j
  2489. type            k
  2490. type            l
  2491. type            m
  2492. type            n
  2493. type            o
  2494. type            p
  2495. type            q
  2496. type            r
  2497. type            s
  2498. type            t
  2499. type            u
  2500. type            v
  2501. type            w
  2502. type            x
  2503. type            y
  2504. type            z
  2505. type            {
  2506. type            |
  2507. type            }
  2508. type            ~
  2509. @EOF
  2510.  
  2511. chmod 600 keymapxenix
  2512.  
  2513. exit 0
  2514. -- Cut here
  2515. -- 
  2516. /*  rcarter@wpi.wpi.edu */      /* Amazing */             /* Joseph H. Allen */
  2517. int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
  2518. +r*57)/7,q=q?q-1?q-2?1-p%79?-1:0:p%79-77?1:0:p<1659?79:0:p>158?-79:0,q?!a[p+q*2
  2519. ]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}
  2520.