home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / pine / pico / bind.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  16.0 KB  |  352 lines

  1. #if    !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: bind.c,v 4.2 1993/04/15 00:20:08 mikes Exp $";
  3. #endif
  4. /*
  5.  * Program:    Key binding routines
  6.  *
  7.  *
  8.  * Michael Seibel
  9.  * Networks and Distributed Computing
  10.  * Computing and Communications
  11.  * University of Washington
  12.  * Administration Builiding, AG-44
  13.  * Seattle, Washington, 98195, USA
  14.  * Internet: mikes@cac.washington.edu
  15.  *
  16.  * Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  17.  *
  18.  * Copyright 1991-1993  University of Washington
  19.  *
  20.  *  Permission to use, copy, modify, and distribute this software and its
  21.  * documentation for any purpose and without fee to the University of
  22.  * Washington is hereby granted, provided that the above copyright notice
  23.  * appears in all copies and that both the above copyright notice and this
  24.  * permission notice appear in supporting documentation, and that the name
  25.  * of the University of Washington not be used in advertising or publicity
  26.  * pertaining to distribution of the software without specific, written
  27.  * prior permission.  This software is made available "as is", and
  28.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  29.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  30.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  31.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  32.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  33.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  34.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  35.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  36.  *
  37.  * Pine and Pico are trademarks of the University of Washington.
  38.  * No commercial use of these trademarks may be made without prior
  39.  * written permission of the University of Washington.
  40.  *
  41.  */
  42. /*    This file is for functions having to do with key bindings,
  43.     descriptions, help commands, and command line execution.
  44.  
  45.     written 11-feb-86 by Daniel Lawrence
  46.                                 */
  47.  
  48. #include    <stdio.h>
  49. #include    "estruct.h"
  50. #include    "edef.h"
  51. #include    "pico.h"
  52. #ifdef HEBREW
  53. #include "hebrew.h"
  54. #endif
  55.  
  56. #ifdef    ANSI
  57.     int arraylen(char **);
  58. #else
  59.     int arraylen();
  60. #endif
  61.  
  62. /* 
  63.  * help - help function for pico (UW pared down version of uemacs).
  64.  *      this function will intentionally garbage with helpful 
  65.  *      tips and then wait for a ' ' to be hit to then update the 
  66.  *        screen.
  67.  */
  68.  
  69.  
  70. static char *helptext[] = {
  71.     "\tPico Help Text",
  72.     " ",
  73.     "\tPico is designed to be a simple, easy-to-use text editor with a",
  74.     "\tlayout very similar to the pine mailer.  The status line at the",
  75.     "\ttop of the display shows pico's version, the current file being",
  76.     "\tedited and whether or not there are outstanding modifications",
  77.     "\tthat have not been saved.  The third line from the bottom is used",
  78.     "\tto report informational messages and for additional command input.",
  79.     "\tThe bottom two lines list the available editing commands.",
  80.     " ",
  81.     "\tEach character typed is automatically inserted into the buffer",
  82.     "\tat the current cursor position.  Editing commands and cursor",
  83.     "\tmovement (besides arrow keys) are given to pico by typing",
  84.     "\tspecial control-key sequences.  A caret, '^', is used to denote",
  85.     "~\tthe control key, sometimes marked \"CTRL\", so the ~C~T~R~L~-~q key",
  86.     "~\tcombination is written as ~^~Q.",
  87.     " ",
  88.     "\tThe following functions are available in pico (where applicable,",
  89.     "\tcorresponding function key commands are in parentheses).",
  90.     " ",
  91.     "~\t~^~G (~F~1)   Display this help text.",
  92.     " ",
  93.     "~\t~^~F        move Forward a character.",
  94.     "~\t~^~B        move Backward a character.",
  95.     "~\t~^~P        move to the Previous line.",
  96.     "~\t~^~N        move to the Next line.",
  97.     "~\t~^~A        move to the beginning of the current line.",
  98.     "~\t~^~E        move to the End of the current line.",
  99.     "~\t~^~V (~F~8)   move forward a page of text.",
  100.     "~\t~^~Y (~F~7)   move backward a page of text.",
  101.     " ",
  102.     "~\t~^~W (~F~6)   Search for (where is) text, neglecting case.",
  103.     "~\t~^~L        Refresh the display.",
  104.     " ",
  105.     "~\t~^~D        Delete the character at the cursor position.",
  106.     "~\t~^~^        Mark cursor position as beginning of selected text.",
  107.     "\t\t  Note: Setting mark when already set unselects text.",
  108.     "~\t~^~K (~F~9)   Cut selected text (displayed in inverse characters).",
  109.     "\t\t  Note: The selected text's boundary on the cursor side",
  110.     "\t\t        ends at the left edge of the cursor.  So, with ",
  111.     "\t\t        selected text to the left of the cursor, the ",
  112.     "\t\t        character under the cursor is not selected.",
  113.     "~\t~^~U (~F~1~0)  Uncut (paste) last cut text inserting it at the",
  114.     "\t\t  current cursor position.",
  115.     "~\t~^~I        Insert a tab at the current cursor position.",
  116.     " ",
  117.     "~\t~^~J (~F~4)   Format (justify) the current paragraph.",
  118.     "\t\t  Note: paragraphs delimited by blank lines or indentation.",
  119.     "~\t~^~T (~F~1~2)  To invoke the spelling checker",
  120.     "~\t~^~C (~F~1~1)  Report current cursor position",
  121.     " ",
  122.     "~\t~^~R (~F~5)   Insert an external file at the current cursor position.",
  123.     "~\t~^~O (~F~3)   Output the current buffer to a file, saving it.",
  124.     "~\t~^~X (~F~2)   Exit pico, saving buffer.",
  125.     "    ",
  126.     "\tPine and Pico are trademarks of the University of Washington.",
  127.     "\tNo commercial use of these trademarks may be made without prior",
  128.     "\twritten permission of the University of Washington.",
  129.     "    ",
  130.     "    End of Help.",
  131.     " ",
  132.     NULL
  133. };
  134.  
  135.  
  136. /*
  137.  * arraylen - return the number of bytes in an array of char
  138.  */
  139. arraylen(array)
  140. char **array;
  141. {
  142.     register int i=0;
  143.  
  144.     while(array[i++] != NULL) ;
  145.     return(i);
  146. }
  147.  
  148.  
  149. /*
  150.  * whelp - display help text for the composer and pico
  151.  */
  152. whelp(f, n)
  153. {
  154.     if(Pmaster){
  155.     (*Pmaster->helper)(Pmaster->composer_help, "Help on the Pine Composer", 1);
  156.     curwp->w_flag |= WFMODE;
  157.     }
  158.     else
  159.       pico_help(helptext);
  160.  
  161.         sgarbf = TRUE;
  162. }
  163.  
  164.  
  165.  
  166. #define    OVERLAP    2        /* displayed page overlap */
  167.  
  168. /*
  169.  * scrollw - takes beginning row and ending row to diplay an array
  170.  *           of text lines.  returns either 0 if scrolling terminated
  171.  *           normally or the value of a ctrl character typed to end it.
  172.  *
  173.  * updates - 
  174.  *     01/11/89 - added stripe call if 1st char is tilde - '~'
  175.  *
  176.  */
  177. wscrollw(begrow, endrow, textp, textlen)
  178. int    begrow, endrow;
  179. char    *textp[];
  180. int    textlen;
  181. {
  182.     register int    loffset = 0; 
  183.     register int    prevoffset = -1; 
  184.     register int    dlines;
  185.     register int    i;
  186.     register int    cont;
  187.     register int    done = 0;
  188.     register char    *buf;
  189.     int     c;
  190.      
  191.     dlines = endrow - begrow - 1;
  192.     while(!done) {
  193.         /*
  194.          * diplay a page loop ...
  195.          */
  196.     if(prevoffset != loffset){
  197.                for(i = 0; i < dlines; i++){
  198.                 movecursor(i + begrow, 0);
  199.                 peeol();
  200.                 if((loffset+i) < textlen){
  201.             buf = &(textp[loffset+i][0]);
  202.             if(*buf == '~'){
  203.             buf++;
  204.             wstripe(begrow+i, 0, buf, '~');
  205.             }
  206.             else{
  207.             pputs(buf, 0);
  208.             }
  209.                 }
  210.             }
  211.         /*
  212.          * put up the options prompt
  213.          */
  214.             movecursor(begrow + dlines, 0);
  215.             cont = (loffset+dlines < textlen);
  216.             if(cont){                               /* continue ? */
  217.         if(loffset == 0)
  218.             wkeyhelp("000000X00V00","Exit Help,Next Pg");
  219.         else
  220.             wkeyhelp("000Y00X00V00","Prev Pg,Exit Help,Next Pg");
  221.             }
  222.             else{
  223.         if(loffset == 0)
  224.           wkeyhelp("000000X00000","Exit Help");
  225.         else
  226.           wkeyhelp("000Y00X00000","Prev Pg,Exit Help");
  227.             }
  228.     }
  229.  
  230.     (*term.t_flush)();
  231.  
  232. #ifdef HEBREW
  233.     message_mode=1;
  234. #endif
  235.         c = GetKey();
  236. #ifdef HEBREW
  237.     message_mode=0;
  238. #endif
  239.  
  240.     prevoffset = loffset;
  241.     switch(c){
  242.         case  (CTRL|'X') :        /* quit */
  243.          case  F2  :
  244.         done = 1;
  245.         break;
  246.         case  (CTRL|'Y') :        /* prev page */
  247.         case  F7  :            /* prev page */
  248.         if((loffset-dlines-OVERLAP) > 0){
  249.                        loffset -= (dlines-OVERLAP);
  250.         }
  251.             else{
  252.             if(loffset != 0){
  253.             prevoffset = -1;
  254.             }
  255.             else{
  256.                 (*term.t_beep)();
  257.             }
  258.             loffset = 0;
  259.             }
  260.         break;
  261.         case  (CTRL|'V') :            /* next page */
  262.          case  F8  :
  263.         if(cont){
  264.                       loffset += (dlines-OVERLAP);
  265.         }
  266.         else{
  267.            (*term.t_beep)();
  268.         }
  269.         break;
  270.         case  '\016' :        /* prev-line */
  271.         case  (CTRL|'N') :
  272.           if(cont)
  273.         loffset++;
  274.           else
  275.         (*term.t_beep)();
  276.           break;
  277.         case  '\020' :        /* prev-line */
  278.         case  (CTRL|'P') :
  279.           if(loffset > 0)
  280.         loffset--;
  281.           else
  282.         (*term.t_beep)();
  283.           break;
  284.         case  '\014' :        /* refresh */
  285.         case  (CTRL|'L') :        /* refresh */
  286.             modeline(curwp);
  287.         update();
  288.         prevoffset = -1;
  289.         break;
  290.         case  NODATA :
  291.             break;
  292.         default :
  293.         emlwrite("Unknown Command.");
  294.         (*term.t_beep)();
  295.         break;
  296.     }
  297.     }
  298.     return(TRUE);
  299. }
  300.  
  301.  
  302. /*
  303.  * normal - given a char and list of function key to command key mappings, 
  304.  *          return, depending on gmode, the right command.  The list is
  305.  *          an array of (Fkey, command-key) pairs.  sc is the index in the
  306.  *          array that means to ignore fkey vs. command key mapping
  307.  *
  308.  *          rules:  1. if c not in table (either fkey or command), let it thru
  309.  *                  2. if c matches, but in other mode, punt it
  310.  */
  311. normal(c, list, sc)
  312. int c, sc;
  313. int list[][2];
  314. {
  315.     register int i;
  316.  
  317.     for(i=0; i < 12; i++){
  318.     if(c == list[i][(FUNC&c) ? 0 : 1]){    /* in table? */
  319.         if(i == sc)                /* SPECIAL CASE! */
  320.           return(list[i][1]);
  321.  
  322.         if(list[i][1] == NODATA)        /* no mapping ! */
  323.           return(c);
  324.  
  325.         if(((FUNC&c) == FUNC) ^ ((gmode&MDFKEY) == MDFKEY))
  326.           return(BADESC);            /* keystroke not allowed! */
  327.         else
  328.           return(list[i][1]);        /* never return func keys */
  329.     }
  330.     }
  331.  
  332.     return(c);
  333. }
  334.  
  335.  
  336. /*
  337.  * rebind - replace the first function with the second
  338.  */
  339. rebindfunc(a, b)
  340. int (*a)(), (*b)();
  341. {
  342.     KEYTAB *kp;
  343.  
  344.     kp = (Pmaster) ? &keytab[0] : &pkeytab[0];
  345.  
  346.     while(kp->k_fp != NULL){        /* go thru whole list, and */
  347.     if(kp->k_fp == a)
  348.       kp->k_fp = b;            /* replace all occurances */
  349.     kp++;
  350.     }
  351. }