home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / fep / part02 < prev    next >
Text File  |  1988-11-09  |  31KB  |  1,772 lines

  1. Subject:  v16i062:  Front end editor program, Part02/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Kazumasa Utashiro <kddlab!sra.junet!utashiro>
  7. Posting-number: Volume 16, Issue 62
  8. Archive-name: fep/part02
  9.  
  10. #!/bin/sh
  11. # to extract, remove the header and type "sh filename"
  12. if `test ! -s ./fep_hist.c`
  13. then
  14. echo "writing ./fep_hist.c"
  15. cat > ./fep_hist.c << '\End\Of\File\'
  16. /*    Copyright (c) 1987, 1988 by Software Research Associates, Inc.    */
  17.  
  18. #ifndef lint
  19. static char rcsid[]=
  20. "$Header: fep_hist.c,v 4.0 88/08/05 20:22:14 utashiro Rel $ (SRA)";
  21. #endif lint
  22.  
  23. #include <stdio.h>
  24. #include <ctype.h>
  25. #include "fep_defs.h"
  26. #include "fep_glob.h"
  27. #include "fep_funcs.h"
  28.  
  29. char    **HistoryTable;
  30. int    TopOfHist;
  31. int    TailOfHist;
  32. int    CurrentHist;
  33. int    HistorySize;
  34.  
  35. int    uniqline = 1;
  36.  
  37. char    *getOldestHistory();
  38. char    *getYoungestHistory();
  39.  
  40. char *argv[MAXARGS];
  41. int argc;
  42.  
  43. init_hist(size)
  44.     int size;
  45. {
  46.     char *itoa();
  47.  
  48.     TopOfHist = 0;
  49.     TailOfHist = 0;
  50.     CurrentHist = 0;
  51.     HistorySize = size;
  52.  
  53.     /*
  54.      * "set_var" will call "changeHistorySize" function for initilize
  55.      * history table.
  56.      */
  57.     set_var ("history", itoa (HistorySize));
  58. }
  59.  
  60. char *
  61. itoa (i)
  62.     int i;
  63. {
  64.     static char buf[64];
  65.  
  66.     sprintf (buf, "%d", i);
  67.     return (buf);
  68. }
  69.  
  70. addHistory(string)
  71.     char *string;
  72. {
  73.     char *allocAndCopyThere();
  74.     char *prev;
  75.  
  76.     if (HistorySize <= 0)
  77.     return;
  78.  
  79.     CurrentHist = TailOfHist;
  80.     prev = getYoungestHistory ();
  81.     if (look_var ("ignore-same-line") && prev && !strcmp (string, prev))
  82.         return;
  83.  
  84.     if (TailOfHist-HistorySize >= TopOfHist) {
  85.     if (HistoryTable[TopOfHist % HistorySize])
  86.         free(HistoryTable[TopOfHist % HistorySize]);
  87.         TopOfHist++;
  88.     }
  89.     HistoryTable[(TailOfHist++)%HistorySize] = allocAndCopyThere(string);
  90.     CurrentHist = TailOfHist;
  91. }
  92.  
  93. void
  94. resetCurrentHistory()
  95. {
  96.     CurrentHist = TailOfHist;
  97. }
  98.  
  99. char *
  100. getPreviousHistory()
  101. {
  102.     if (HistorySize <= 0)
  103.     return (0);
  104.  
  105.     if (TailOfHist == 0) {
  106.         return((char *)0);
  107.     }
  108.     if (CurrentHist == TopOfHist)
  109.     CurrentHist = TailOfHist - 1;
  110.     else
  111.     CurrentHist--;
  112.     return (HistoryTable[CurrentHist % HistorySize]);
  113. }
  114.  
  115. char *
  116. getNextHistory()
  117. {
  118.     
  119.     if (HistorySize <= 0)
  120.     return (0);
  121.  
  122.     if (CurrentHist == TailOfHist || CurrentHist == TailOfHist-1)
  123.     CurrentHist = TopOfHist;
  124.     else
  125.         CurrentHist++;
  126.     return (HistoryTable[CurrentHist % HistorySize]);
  127. }
  128.  
  129. char *
  130. getHistory(num)
  131.     int num;
  132. {
  133.  
  134.     if (HistorySize <= 0)
  135.     return (0);
  136.  
  137.     if (num < TopOfHist || TailOfHist <= num) {
  138.         return ((char *)0);
  139.     }
  140.     else {
  141.         return (HistoryTable[num % HistorySize]);
  142.     }
  143. }
  144.  
  145. getOldestHistNum()
  146. {
  147.  
  148.     return (TopOfHist);
  149. }
  150.  
  151. getYoungestHistNum()
  152. {
  153.  
  154.     return (TailOfHist-1);
  155. }
  156.  
  157. char *
  158. getOldestHistory()
  159. {
  160.     register char *cp;
  161.  
  162.     if (TailOfHist == 0)
  163.         return("");
  164.  
  165.     cp = HistoryTable[TopOfHist];
  166.     return (cp ? cp : "");
  167. }
  168.  
  169. char *
  170. getYoungestHistory()
  171. {
  172.     register char *cp;
  173.  
  174.     if (TailOfHist == 0)
  175.         return("");
  176.  
  177.     cp = getHistory (getYoungestHistNum());
  178.     return (cp ? cp : "");
  179. }
  180.  
  181. getCurrentHistNum()
  182. {
  183.     return (CurrentHist);
  184. }
  185.  
  186. char *
  187. allocAndCopyThere(string)
  188.     char *string;
  189. {
  190.     register char *cp;
  191.     
  192.     cp = (char *)malloc(strlen(string)+1);
  193.  
  194.     if (cp == (char *)0)
  195.     return ((char *)0);
  196.  
  197.     strcpy(cp, string);
  198.     return(cp);
  199. }
  200.  
  201. char *
  202. historyExtract(string)
  203.     char *string;
  204. {
  205.     char *search_reverse_history();
  206.  
  207.     if (HistorySize <= 0)
  208.     return (0);
  209.  
  210.     switch (*++string) {
  211.     case '0': 
  212.     case '1': 
  213.     case '2': 
  214.     case '3': 
  215.     case '4': 
  216.     case '5': 
  217.     case '6': 
  218.     case '7': 
  219.     case '8': 
  220.     case '9': 
  221.         {
  222.         register int    histNum;
  223.  
  224.         histNum = (atoi (string)) - 1;
  225.         if (TopOfHist <= histNum && histNum < TailOfHist) {
  226.             CurrentHist = histNum;
  227.             return (HistoryTable[histNum % HistorySize]);
  228.         }
  229.         else {
  230.             return ((char *) 0);
  231.         }
  232.         }
  233.         break;
  234.  
  235.     case '-':
  236.         {
  237.         register int    histNum;
  238.  
  239.         if (! isdigit(*++string))
  240.             return ((char *) 0);
  241.  
  242.         histNum = TailOfHist - (atoi (string));
  243.         if (TopOfHist <= histNum && histNum < TailOfHist) {
  244.             CurrentHist = histNum;
  245.             return (HistoryTable[histNum % HistorySize]);
  246.         }
  247.         else {
  248.             return ((char *) 0);
  249.         }
  250.         }
  251.         break;
  252.  
  253.     case '!': 
  254.         if (TailOfHist != 0) {
  255.         CurrentHist = TailOfHist - 1;
  256.         return (HistoryTable[(TailOfHist - 1) % HistorySize]);
  257.         }
  258.         break;
  259.  
  260.     case '?':
  261.         return (search_reverse_history (++string));
  262.  
  263.     default:
  264.         {
  265.         char *buf[64];
  266.  
  267.         strcpy (buf, "^");
  268.         strncat (buf, string, 64);
  269.         return (search_reverse_history (buf));
  270.         }
  271.     }
  272.     return ((char *) 0);
  273. }
  274.  
  275. char *
  276. search_reverse_history (string)
  277. {
  278.     register int i;
  279.     char *re_comp();
  280.  
  281.     if (string != NULL) {
  282.     set_var ("search-string", string);
  283.     if (re_comp(string) != (char *)0)
  284.         return ((char *) 0);
  285.     i = TailOfHist - 1;
  286.     }
  287.     else
  288.     i = CurrentHist - 1;
  289.  
  290.     for (; i >= TopOfHist; i--) {
  291.     if (re_exec(HistoryTable[i % HistorySize]) == 1) {
  292.         CurrentHist = i;
  293.         return(HistoryTable[i % HistorySize]);
  294.     }
  295.     }
  296.     return ((char *) 0);
  297. }
  298.  
  299. char *
  300. search_forward_history (string)
  301. {
  302.     register int i;
  303.     char *re_comp();
  304.  
  305.     if (string != NULL) {
  306.     if (re_comp(string) != (char *)0)
  307.         return ((char *) 0);
  308.     i = TopOfHist;
  309.     }
  310.     else
  311.     i = CurrentHist + 1;
  312.  
  313.     for (; i <= TailOfHist; i++) {
  314.     if (re_exec(HistoryTable[i % HistorySize]) == 1) {
  315.         CurrentHist = i;
  316.         return(HistoryTable[i % HistorySize]);
  317.     }
  318.     }
  319.     return ((char *) 0);
  320. }
  321.  
  322. /*
  323.  * Change history table size.
  324.  */
  325. changeHistorySize(newsize)
  326.     int newsize;
  327. {
  328.     char **newHistTable;
  329.     register int newTop, i;
  330.  
  331.     if (newsize > 0)
  332.     newHistTable = (char **)calloc(sizeof(char *), newsize);
  333.  
  334.     newTop = (TailOfHist - newsize < TopOfHist)
  335.         ? TopOfHist : TailOfHist - newsize;
  336.  
  337.     /*
  338.      * This function can be called for initializing history table
  339.      */
  340.     if (HistoryTable) {
  341.     for (i = TailOfHist-1; i >= TopOfHist && i >= newTop; i--) {
  342.         newHistTable[i%newsize] = HistoryTable[i%HistorySize];
  343.     }
  344.  
  345.     for (i = TopOfHist; i < newTop; i++) {
  346.         if (HistoryTable[i%HistorySize]) {
  347.         free(HistoryTable[i%HistorySize]);
  348.         }
  349.     }
  350.     free(HistoryTable);
  351.     }
  352.  
  353.     if (newsize <= 0)
  354.     HistoryTable = (char **) 0;
  355.  
  356.     TopOfHist = newTop;
  357.     HistorySize = newsize;
  358.     HistoryTable = newHistTable;
  359.  
  360.     if (look_var ("debug")) {
  361.     printf ("history: top=%d, tail=%d, size=%d\n",
  362.         TopOfHist, TailOfHist, HistorySize);
  363.     }
  364. }
  365.  
  366. /*
  367.  * Built-in function "fep-history"
  368.  */
  369. fep_history (comline)
  370.     char *comline;
  371. {
  372.     int num;
  373.  
  374.     argc = mkargv (comline, argv, MAXARGS);
  375.  
  376.     if (argc == 2)
  377.     num = atoi (argv[1]);
  378.     else
  379.     num = 0;
  380.  
  381.     hist_showHistory (num);
  382. }
  383.  
  384. hist_showHistory (num)
  385.     int num;
  386. {
  387.     register int from, to, i;
  388.     char *cp;
  389.  
  390.     if (num <= 0)
  391.     num = HistorySize;
  392.  
  393.     from = getOldestHistNum ();
  394.     to = getYoungestHistNum ();
  395.  
  396.     from = max (from, to - num + 1);
  397.  
  398.     if (CurrentHist < from) {
  399.     from = max (getOldestHistNum(), CurrentHist - num/2);
  400.     to = min (getYoungestHistNum(), from + num - 1);
  401.     }
  402.  
  403.     for (i = from; i <= to; i++) {
  404.     if (cp = getHistory(i)) {
  405.         printf("%c%4d ", (i == CurrentHist) ? '>' : ' ', i+1);
  406.         ctlprint(cp);
  407.     }
  408.     }
  409. }
  410.  
  411. char *
  412. mk_home_relative (cp)
  413.     char *cp;
  414. {
  415.     char buf[256];
  416.  
  417.     /*
  418.      * If variable "history-file" is not absolute path name,
  419.      * change it to relative path name from home directory.
  420.      */
  421.     if (*cp != '/' && !(*cp == '.' && *(cp+1) == '/')) {
  422.     strcpy (buf, getenv ("HOME"));
  423.     strcat (buf, "/");
  424.     strcat (buf, cp);
  425.     }
  426.     else
  427.     strcpy (buf, cp);
  428.  
  429.     return (buf);
  430. }
  431.  
  432. fep_save_history (comline)
  433.     char *comline;
  434. {
  435.     char *file;
  436.     char **argp;
  437.     FILE *fp;
  438.     int num = 0;
  439.  
  440.     argc = mkargv (comline, argv, MAXARGS);
  441.  
  442.     argp = argv;
  443.     ++argp;
  444.  
  445.     if (isdigit (**argp))
  446.     num = atoi (*argp++);
  447.  
  448.     if (*argp == NULL) {
  449.     char *cp;
  450.  
  451.     if ((cp = look_var ("history-file")) == NULL) {
  452.         clear_edit_line ();
  453.         printf (
  454.         "%s: Argument or \"history-file\" variables is required\n",
  455.         argv[0]
  456.         );
  457.         recover_edit_line ();
  458.         return;
  459.     }
  460.     file = mk_home_relative (cp);
  461.     }
  462.     else
  463.     file = *argp;
  464.  
  465.     save_history (file, num);
  466. }
  467.  
  468. #define MAXSAVEHIST 512
  469.  
  470. save_history (file, num)
  471.     char *file;
  472.     int num;
  473. {
  474.     int old, new;
  475.     FILE *fp, *fopen();
  476.     char *cp;
  477.  
  478.     old = getOldestHistNum ();
  479.     new = getYoungestHistNum ();
  480.  
  481.     if (num <= 0)
  482.     num = MAXSAVEHIST;
  483.  
  484.     if (new - num + 1 > old)
  485.     old = new - num + 1;
  486.  
  487.     if (look_var ("debug")) {
  488.     printf ("save history from %d to %d\n", old, new);
  489.     }
  490.  
  491.     if ((fp = fopen (file, "w")) == NULL) {
  492.     clear_edit_line ();
  493.     perror (file);
  494.     recover_edit_line ();
  495.     return;
  496.     }
  497.  
  498.     while (old <= new) {
  499.     cp = getHistory (old++);
  500.     fprintf (fp, "%s\n", cp);
  501.     }
  502.  
  503.     fclose (fp);
  504.     return;
  505. }
  506.  
  507. fep_read_history (comline)
  508.     char *comline;
  509. {
  510.     char *file;
  511.     char **argp;
  512.     FILE *fp;
  513.  
  514.     argc = mkargv (comline, argv, MAXARGS);
  515.  
  516.     argp = argv;
  517.     ++argp;
  518.  
  519.     if (*argp == NULL) {
  520.     char *cp;
  521.     
  522.     if ((cp = look_var ("history-file")) == NULL) {
  523.         clear_edit_line ();
  524.         printf (
  525.         "%s: Argument or \"history-file\" variables is required\n",
  526.         argv[0]
  527.         );
  528.         recover_edit_line ();
  529.         return;
  530.     }
  531.     file = mk_home_relative (cp);
  532.     }
  533.     else
  534.     file = *argp;
  535.  
  536.     read_history (file);
  537. }
  538.  
  539. read_history (file)
  540.     char *file;
  541. {
  542.     FILE *fp;
  543.     char line [MAXCOMLEN];
  544.     register int i;
  545.  
  546.     if ((fp = fopen (file, "r")) == NULL) {
  547.     clear_edit_line ();
  548.     perror (file);
  549.     recover_edit_line ();
  550.     return;
  551.     }
  552.  
  553.     while (fgets (line, MAXCOMLEN, fp)) {
  554.     i = strlen (line) - 1;
  555.     if (line [i] == '\n')
  556.         line [i] = '\0';
  557.     addHistory (line);
  558.     }
  559.     return;
  560. }
  561. \End\Of\File\
  562. else
  563.   echo "will not over write ./fep_hist.c"
  564. fi
  565. if `test ! -s ./fep_com.c`
  566. then
  567. echo "writing ./fep_com.c"
  568. cat > ./fep_com.c << '\End\Of\File\'
  569. /*    Copyright (c) 1987, 1988 by Software Research Associates, Inc.    */
  570.  
  571. #ifndef lint
  572. static char rcsid[]=
  573. "$Header: fep_com.c,v 4.0 88/08/05 20:22:02 utashiro Rel $ (SRA)";
  574. #endif lint
  575.  
  576. #include <stdio.h>
  577. #include <sgtty.h>
  578. #include <ctype.h>
  579. #include <sys/param.h>
  580. #include <sys/file.h>
  581. #include <sys/stat.h>
  582. #include <sys/ioctl.h>
  583. #include "fep_defs.h"
  584. #include "fep_glob.h"
  585. #include "fep_funcs.h"
  586.  
  587. int    tty_fix_bell = OFF;    /* ring bell if the tty mode is changed */
  588.  
  589. /*
  590.  * Check command line if it call built-in function or not and execute it
  591.  */
  592. executeBuiltInFunction (line)
  593.     char *line;
  594. {
  595.     register FunctionTableEnt *ftp;
  596.     int argc;
  597.  
  598.     /*
  599.      * Skip white space.
  600.      */
  601.     while (isspace (*line))
  602.     line++;
  603.     /*
  604.      * Skip comment and blank line
  605.      */
  606.     if (*line == '#' || *line == '\0')
  607.     return (IGNORED);
  608.  
  609.     /*
  610.      * All built-in command should be prefixed by 'fep-'
  611.      */
  612.     if (strncmp (line, "fep-", 4) != 0)
  613.     return (NOT_PROCESSED);
  614.  
  615.     for (ftp = BuiltinFuncTable; ftp->name; ftp++) {
  616.     if (is_same_command (line, ftp->name)) {
  617.         if (debug)
  618.         showArgs (line);
  619.         if (
  620.         condition()
  621.         /* control structure should be processed on any condition */
  622.         || strncmp (line + 4, "if", 2) == 0
  623.         || strncmp (line + 4, "endif", 5) == 0
  624.         || strncmp (line + 4, "elseif", 6) == 0
  625.         || strncmp (line + 4, "else", 4) == 0
  626.         )
  627.         (*ftp->func)(line);
  628.         return (PROCESSED);
  629.     }
  630.     }
  631.     return (NOT_PROCESSED);
  632. }
  633.  
  634. is_same_command (a, b)
  635.     register char *a, *b;
  636. {
  637.  
  638.     while (*a && *b && *a == *b)
  639.     ++a, ++b;
  640.     if ((*a == NULL || isspace (*a)) && (*b == NULL || isspace (*b)))
  641.     return 1;
  642.     else
  643.     return 0;
  644. }
  645.  
  646. /*
  647.  * Process 'fep-if' and 'fep-elseif'
  648.  */
  649. fep_if (comline)
  650.     char *comline;
  651. {
  652.     char *argv[MAXARGS];
  653.     int argc;
  654.     char *err;
  655.     int cond;
  656.     int i;
  657.  
  658.     argc = mkargv (comline, argv, MAXARGS);
  659.  
  660.     if (argc != 2 && argc != 4) {
  661.     printf ("%s: Illegal number of arguments\n", argv[0]);
  662.     return;
  663.     }
  664.  
  665.     /*
  666.      * In case of only one argument,
  667.      * treat as true if the variable is set.
  668.      */
  669.     if (argc == 2) {
  670.     char *cp;
  671.  
  672.     if (argv[1][0] == '$')
  673.         cp = &argv[1][1];
  674.     else
  675.         cp = &argv[1][0];
  676.  
  677.     cond = look_var (cp) ? 1 : 0;
  678.     }
  679.     else {
  680.     int value;
  681.  
  682.     /*
  683.      * Substitute variable prefixed by '$' mark.
  684.      */
  685.     for (i = 0; i < argc; i++) {
  686.         if (argv[i][0] == '$') {
  687.         char *v;
  688.  
  689.         if (v = look_var (&argv[i][1]))
  690.             argv[i] = v;
  691.         else
  692.             argv[i] = "";
  693.         }
  694.     }
  695.  
  696.     if (debug) {
  697.         int i;
  698.         char **argp;
  699.  
  700.         for (i = 0, argp = argv; *argp; argp++, i++)
  701.         printf ("argv[%d] = \"%s\"\n", i, *argp);
  702.     }
  703.  
  704.         /*
  705.      * Check operator.
  706.      */
  707.     if (eq (argv[2], "==") || eq (argv[2], "="))
  708.         value = 1;
  709.     else if (eq (argv[2], "!="))
  710.         value = 0;
  711.     else {
  712.         printf ("%s: Unknown opperator \"%s\"", argv[0], argv[2]);
  713.         return;
  714.     }
  715.  
  716.     if (eq (argv[1], argv[3]))
  717.         cond = value;
  718.     else
  719.         cond = !value;
  720.     }
  721.  
  722.     if (eq (argv[0], "fep-elseif"))
  723.     err = change_condition (cond);
  724.     else
  725.     err = push_condition (cond);
  726.  
  727.     if (err)
  728.     printf ("%s: %s", argv[0], err);
  729.     else if (debug)
  730.     printf ("%s: %s\n", comline, cond ? "TRUE" : "FALSE");
  731.  
  732.     return;
  733. }
  734.  
  735. fep_else ()
  736. {
  737.     char *err;
  738.  
  739.     if (err = change_condition (1))
  740.     printf ("fep-else: %s", err);
  741.  
  742.     return;
  743. }
  744.  
  745. fep_endif ()
  746. {
  747.     char *err;
  748.  
  749.     if (err = pop_condition ())
  750.     printf ("fep-endif: %s", err);
  751.  
  752.     return;
  753. }
  754.  
  755. bind_to_key (comline)
  756.     char *comline;
  757. {
  758.     register FunctionTableEnt *fnte;
  759.     char *argv[MAXARGS];
  760.     int argc;
  761.  
  762.     argc = mkargv (comline, argv, MAXARGS);
  763.  
  764.     /*
  765.      * Something error occured. Print message and return
  766.      */
  767.     if (argc < 0) {
  768.     printf ("%s\n", argv[0]);
  769.     return;
  770.     }
  771.  
  772.     /*
  773.      * Number of arguments should be three.
  774.      */
  775.     if (argc != 3) {
  776.     printf ("Invalid number of arguments\n");
  777.     return;
  778.     }
  779.  
  780.     /*
  781.      * Find the function name from function name table.
  782.      */
  783.     for (fnte = FunctionNameTable; fnte->func; fnte++) {
  784.     if (strcmp (fnte->name, argv[1]) == 0) {
  785.         bind_key (curFuncTab, fnte->func, argv[2], abort);
  786.         break;
  787.     }
  788.     }
  789.  
  790.     /*
  791.      * Couldn't find such a function
  792.      */
  793.     if (fnte->func == NULL)
  794.     printf ("%s: no such built-in command\n", argv[1]);
  795. }
  796.  
  797. alias(comline)
  798.     char *comline;
  799. {
  800.     char *argv[MAXARGS];
  801.     int argc;
  802.  
  803.     argc = mkargv (comline, argv, MAXARGS);
  804.  
  805.     switch (argc) {
  806.     case 1:
  807.         show_aliaslist (NULL);
  808.         break;
  809.  
  810.     case 2:
  811.         show_aliaslist (argv[1]);
  812.         break;
  813.  
  814.     case 3:
  815.         set_alias (argv[1], argv[2]);
  816.         break;
  817.  
  818.     default:
  819.         printf ("%s: Illegal number of arguments.\n", argv[0]);
  820.     }
  821.     return;
  822. }
  823.  
  824. unalias (comline)
  825.     char *comline;
  826. {
  827.     char *argv[MAXARGS];
  828.     int argc;
  829.     int i;
  830.  
  831.     argc = mkargv (comline, argv, MAXARGS);
  832.  
  833.     for (i=1; i<argc; i++)
  834.     unset_alias (argv[i]);
  835.  
  836.     return;
  837. }
  838.  
  839. set (comline)
  840.     char *comline;
  841. {
  842.     char line[MAXCOMLEN];
  843.     char *cp, *index();
  844.     char *argv[MAXARGS];
  845.     int argc;
  846.  
  847.     /*
  848.      * If there is '=' character in command line, change it to space.
  849.      */
  850.     strcpy (line, comline);
  851.     if (cp = index (line, '='))
  852.     *cp = ' ';
  853.  
  854.     argc = mkargv (line, argv, MAXARGS);
  855.  
  856.     switch (argc) {
  857.  
  858.     /* set */
  859.     case 1:
  860.         show_varlist ();
  861.         return;
  862.     
  863.     /* set var */
  864.     case 2:
  865.         set_var (argv[1], "");
  866.         return;
  867.  
  868.     /* set var = val */
  869.     case 3:
  870.         set_var (argv[1], argv[2]);
  871.         break;
  872.  
  873.     default:
  874.         printf ("Invalid number of arguments\n");
  875.         return;
  876.     }
  877. }
  878.  
  879. unset(comline)
  880.     char *comline;
  881. {
  882.     char **vp;
  883.     char *argv[MAXARGS];
  884.     int argc;
  885.  
  886.     argc = mkargv (comline, argv, MAXARGS);
  887.  
  888.     if (argc < 2) {
  889.     printf ("Invalid number of arguments\n");
  890.     return;
  891.     }
  892.  
  893.     for (vp = &argv[1]; *vp; vp++)
  894.     unset_var (*vp);
  895. }
  896.  
  897. extern    int Transparency;
  898. extern    struct sgttyb slave_ttymode;
  899. extern    struct sgttyb master_ttymode;
  900. extern    int master, slave;
  901. extern    char slave_tty[];
  902.  
  903. /*
  904.  * Toggle transparency switch.
  905.  * If variable Transparency is ON, fep doesn't care about input.
  906.  * If OFF, line editing will be done by fep.
  907.  * But this Transparency is set automaticaly by getcharacter() routine,
  908.  * if the variable auto-tty-fix is ON.
  909.  */
  910. toggle_transparency()
  911. {
  912.     int r;
  913.     int slave_fd;
  914.     struct sgttyb s;
  915.  
  916.     if (Transparency == OFF) {
  917.  
  918.     slave_fd = open (slave_tty, O_WRONLY);
  919.     if (slave_fd < 0) {
  920.         perror (slave_tty);
  921.         return;
  922.     }
  923.  
  924.     r = ioctl (slave_fd, TIOCGETP, (char *) &s);
  925.     if (r < 0) {
  926.         perror (slave_tty);
  927.         (void) close (slave_fd);
  928.         return;
  929.     }
  930.  
  931.     s.sg_flags |= CBREAK;
  932.     r = ioctl (0, TIOCSETN, (char *) & s);
  933.     if (r < 0) {
  934.         perror (slave_tty);
  935.         (void) close (slave_fd);
  936.     }
  937.     (void) close (slave_fd);
  938.     }
  939.     else
  940.     r = ioctl (0, TIOCSETN, (char *) & master_ttymode);
  941.  
  942.     if (r < 0) {
  943.     printf ("Can't change pty mode.\n");
  944.     return;
  945.     }
  946.  
  947.     Transparency = !Transparency;
  948. }
  949.  
  950. /*
  951.  * Check tty mode of slave tty and fix stdout tty mode
  952.  */
  953. fix_transparency()
  954. {
  955.     int r;
  956.     struct sgttyb s;
  957.  
  958.     if (slave < 0)
  959.     return;
  960.  
  961.     r = ioctl (slave, TIOCGETP, (char *) &s);
  962.     /*
  963.      * slave CRMOD is off, but master should be.
  964.      */
  965.     s.sg_flags |= CRMOD;
  966.     if (r < 0) {
  967.     perror (slave_tty);
  968.     return;
  969.     }
  970.  
  971.     /*
  972.      * If find slave tty mode is cbreak or raw, fix tty mode of stdout to
  973.      * same mode as slave and set Transparency ON.
  974.      */
  975.     if (s.sg_flags & (CBREAK|RAW)) {
  976.     if (Transparency == OFF) {
  977.         r = ioctl (0, TIOCSETN, (char *) & s);
  978.         if (r < 0) {
  979.         perror ("stdout");
  980.         return;
  981.         }
  982.         if (tty_fix_bell) errorBell ();
  983.         Transparency = ON;
  984.     }
  985.     }
  986.     else {
  987.     if (Transparency == ON) {
  988.         r = ioctl (0, TIOCSETN, (char *) &master_ttymode);
  989.         if (r < 0) {
  990.         perror ("stdout");
  991.         return;
  992.         }
  993.         if (tty_fix_bell) errorBell ();
  994.         Transparency = OFF;
  995.     }
  996.     }
  997.  
  998.     if (r < 0) {
  999.     printf ("Can't change pty mode.\n");
  1000.     return;
  1001.     }
  1002. }
  1003.  
  1004. int crt, sline;
  1005.  
  1006. show_bindings ()
  1007. {
  1008.     crt = lookd_var ("crt");
  1009.     if (crt < 0)
  1010.     crt = 0;
  1011.     sline = 0;
  1012.  
  1013.     clear_edit_line ();
  1014.     (void) showBindingTbl (curFuncTab, "");
  1015.     recover_edit_line ();
  1016. }
  1017.  
  1018. showBindingTbl (ft, prefix)
  1019.     FUNC ft[];
  1020.     char *prefix;
  1021. {
  1022.     register FunctionTableEnt *fnte;
  1023.     register int i;
  1024.  
  1025.     for (i = 0; i < 128; i++) {
  1026.     if (ft[i] == self_insert || ft[i] == abort)
  1027.         continue;
  1028.  
  1029.     /*
  1030.      * If the pointer to function has indirect flag print "indirect".
  1031.      */
  1032.     if (isIndirect(ft[i])) {
  1033.         char pf[64];
  1034.  
  1035.         sprintf (pf, "%s%s%c-",
  1036.         prefix, (i == 0 || isctlchar(i)) ? "^" : "", unctl(i));
  1037.         if (showBindingTbl (maskIndirect(ft[i]), pf) == 0)
  1038.         break;
  1039.         continue;
  1040.     }
  1041.  
  1042.     /*
  1043.      * Search function name table
  1044.      */
  1045.     for (fnte = FunctionNameTable; fnte->func; fnte++) {
  1046.         if (ft[i] == fnte->func) {
  1047.  
  1048.         if (!check_more())
  1049.             return (0);
  1050.  
  1051.         /*
  1052.          * Show binding
  1053.          */
  1054.         printf ("%s%s%c\t%s\n",
  1055.             prefix,
  1056.             i == 0 || isctlchar(i) ? "^" : "",
  1057.             unctl(i),
  1058.             fnte->name
  1059.             );
  1060.         break;
  1061.         }
  1062.     }
  1063.  
  1064.     /*
  1065.      * Can't find such a function
  1066.      */
  1067.     if (fnte->func == NULL)
  1068.         printf (
  1069.         "%s%c\tunknown function (0x%x)\n",
  1070.         i == 0 || isctlchar(i) ? "^" : "",
  1071.         unctl(i),
  1072.         ft[i]
  1073.         );
  1074.     }
  1075.     return (1);
  1076. }
  1077.  
  1078. show_help ()
  1079. {
  1080.     crt = lines;
  1081.     (crt < 0) && (crt = 0);
  1082.     sline = 0;
  1083.  
  1084.     clear_edit_line ();
  1085.  
  1086.     check_more()            &&
  1087.     (printf ("Functions:\n") || 1)    &&
  1088.     showTable (FunctionNameTable)    &&
  1089.     check_more()            &&
  1090.     (printf ("Commands:\n") || 1)    &&
  1091.     showTable (BuiltinFuncTable)    &&
  1092.     check_more()            &&
  1093.     (printf ("Variables:\n") || 1)    &&
  1094.     showVariables ();
  1095.  
  1096.     recover_edit_line ();
  1097. }
  1098.  
  1099. showTable (fnte)
  1100.     FunctionTableEnt *fnte;
  1101. {
  1102.     int i;
  1103.  
  1104.     /*
  1105.      * Search function name table
  1106.      */
  1107.     for (; fnte->func; fnte++) {
  1108.     if (!check_more())
  1109.         return (0);
  1110.     printf ("\t%-30s %s\n", fnte->name, fnte->help);
  1111.     }
  1112.  
  1113.     return (1);
  1114. }
  1115.  
  1116. showVariables ()
  1117. {
  1118.     extern VAR default_set_vars[], default_unset_vars[];
  1119.     VAR *vp;
  1120.  
  1121.     for (vp = default_set_vars; vp->v_name; ++vp) {
  1122.     if (!vp->v_help)
  1123.         continue;
  1124.     if (!check_more())
  1125.         return (0);
  1126.     printf ("\t%-30s %s\n", vp->v_name, vp->v_help);
  1127.     }
  1128.  
  1129.     for (vp = default_unset_vars; vp->v_name; ++vp) {
  1130.     if (!vp->v_help)
  1131.         continue;
  1132.     if (!check_more())
  1133.         return (0);
  1134.     printf ("\t%-30s %s\n", vp->v_name, vp->v_help);
  1135.     }
  1136.     return (1);
  1137. }
  1138.  
  1139. putch (c)
  1140.     int c;
  1141. {
  1142.     putchar (c);
  1143. }
  1144.  
  1145. check_more()
  1146. {
  1147.  
  1148.     if (sline == 0 && look_var ("clear-repaint") && term_clear)
  1149.     tputs (term_clear, 1, putch);
  1150.  
  1151.     /*
  1152.      * Print more message
  1153.      */
  1154. #   define PUTMORE    printf (  "--More--");
  1155. #   define DELMORE    printf ("\r        \r");
  1156.     if (crt && ++sline >= crt) {
  1157.     
  1158.     PUTMORE;
  1159.     fflush (stdout);
  1160.     
  1161.     switch (getcharacter()) {
  1162.     case '\n': case '\r': case 'j':
  1163.         --sline;
  1164.         break;
  1165.  
  1166.     case 'd': case CTRL(D):
  1167.         sline /= 2;
  1168.         break;
  1169.  
  1170.     case 'q': case 'Q': case CTRL(C):
  1171.         DELMORE;
  1172.         return (0);
  1173.  
  1174.     default:
  1175.         sline = 0;
  1176.         break;
  1177.     }
  1178.     DELMORE;
  1179.     }
  1180.     return (1);
  1181. }
  1182.  
  1183. /*
  1184.  * Change directory
  1185.  */
  1186. fep_chdir (line)
  1187. char *line;
  1188. {
  1189.     char *argv[MAXARGS];
  1190.     int argc;
  1191.  
  1192.     switch (mkargv (line, argv, MAXARGS)) {
  1193.  
  1194.     /*
  1195.      * Change directory with no arguments cause to chdir to home directory
  1196.      */
  1197.         case 1: {
  1198.         char *home, *getenv();
  1199.  
  1200.         if (home = getenv ("HOME"))
  1201.         argv[1] = home;
  1202.         else {
  1203.         printf ("Where is your home directory?\n");
  1204.         return;
  1205.         }
  1206.         break;
  1207.     }
  1208.  
  1209.     /*
  1210.      * Change directory command with argument
  1211.      */
  1212.     case 2:
  1213.         break;
  1214.  
  1215.     /*
  1216.      * Something error occured in mkargv.
  1217.      */
  1218.     case -1:
  1219.         printf ("%s\n", argv[0]);
  1220.         return;
  1221.  
  1222.     default:
  1223.         printf ("fep-chdir: Invalid number of arguments.\n");
  1224.         return;
  1225.     }
  1226.  
  1227.     /*
  1228.      * Chane directory.
  1229.      * Keep in mind that end process still in old directory
  1230.      */
  1231.     if (chdir (argv[1]) < 0) {
  1232.     perror (argv[1]);
  1233.     return;
  1234.     }
  1235.     printf ("Working directory has been changed to \"%s\"\n", argv[1]);
  1236. }
  1237.  
  1238. fep_pwd (line)
  1239.     char *line;
  1240. {
  1241.     char cwd[MAXPATHLEN], *getwd();
  1242.  
  1243.     (void) getwd (cwd);
  1244.     printf ("%s\n", cwd);
  1245. }
  1246.  
  1247. fep_echo (comline)
  1248.     char *comline;
  1249. {
  1250.     char *argv[MAXARGS];
  1251.     int argc;
  1252.     char **argp;
  1253.     int putnewline = 1, first;
  1254.  
  1255.     argc = mkargv (comline, argv, MAXARGS);
  1256.     
  1257.     argp = &argv[1];
  1258.     if (*argp && strcmp (*argp, "-n") == NULL) {
  1259.     putnewline = 0;
  1260.     ++argp;
  1261.     }
  1262.  
  1263.     for (first = 1; *argp; argp++) {
  1264.     char *cp;
  1265.  
  1266.     /*
  1267.      * Put space
  1268.      */
  1269.     if (! first)
  1270.         printf ("%s", " ");
  1271.  
  1272.     /*
  1273.      * Print argument
  1274.      */
  1275.     if (**argp == '$' && (cp = look_var (*argp + 1)))
  1276.         printf ("%s", cp);
  1277.     else
  1278.         printf ("%s", *argp);
  1279.  
  1280.     first = 0;
  1281.     }
  1282.  
  1283.     if (putnewline)
  1284.     printf ("%c", '\n');
  1285. }
  1286.  
  1287. fep_command (comline)
  1288.     char *comline;
  1289. {
  1290.     char *argv[MAXARGS];
  1291.     int argc;
  1292.     int i;
  1293.     char **argp;
  1294.     char *buf[256];
  1295.  
  1296.     argc = mkargv (comline, argv, MAXARGS);
  1297.  
  1298.     if (argc == 1) {
  1299.     printf ("Invalid number of arguments.\n");
  1300.     return;
  1301.     }
  1302.  
  1303.     strcpy (buf, "");
  1304.     for (i=1; i<argc; i++) {
  1305.     strcat (buf, argv[i]);
  1306.     strcat (buf, " ");
  1307.     }
  1308.  
  1309.     invoke_command (buf);
  1310. }
  1311.  
  1312. fep_source (comline)
  1313.     char *comline;
  1314. {
  1315.     FILE *fp;
  1316.     static char *argv[MAXARGS];
  1317.     char file [MAXPATHLEN];
  1318.     int argc;
  1319.  
  1320.     argc = mkargv (comline, argv, MAXARGS);
  1321.  
  1322.     if (argc != 2) {
  1323.     printf ("Invalid number of arguments.\n");
  1324.     return;
  1325.     }
  1326.  
  1327.     strcpy (file, argv[1]);
  1328.     source_file (file);
  1329.  
  1330.     return;
  1331. }
  1332.  
  1333. sourceRcFile ()
  1334. {
  1335.     char *home, filename[64], *getenv();
  1336.     char line[256];
  1337.     struct stat stb_home, stb_cur;
  1338.  
  1339.     if (!(home = getenv ("HOME")))
  1340.     return;
  1341.  
  1342.     strcpy (filename, home);
  1343.     strcat (filename, "/.feprc");
  1344.  
  1345.     /*
  1346.      * Source .feprc in home directory.
  1347.      */
  1348.     stb_home.st_ino = 0;
  1349.     if (stat (filename, &stb_home) >= 0 && (stb_home.st_mode&S_IREAD))
  1350.     source_file (filename);
  1351.  
  1352.     /*
  1353.      * Source .feprc in current directory.
  1354.      */
  1355.     if ((stat (".feprc", &stb_cur) >= 0 && stb_cur.st_ino != stb_home.st_ino))
  1356.     source_file (".feprc");
  1357.  
  1358.     return;
  1359. }
  1360.  
  1361. source_file (file)
  1362.     char *file;
  1363. {
  1364.     FILE *fp;
  1365.     char line[512], line2[512];
  1366.     int i = 0;
  1367.  
  1368.     if ((fp = fopen (file, "r")) == NULL) {
  1369.     perror (file);
  1370.     return;
  1371.     }
  1372.  
  1373.     while (fgets (line, 256, fp)) {
  1374.     i++;
  1375.     if (executeBuiltInFunction (line) == NOT_PROCESSED) {
  1376.         char *cp = line;
  1377.  
  1378.         while (isspace (*cp))
  1379.         cp++;
  1380.         strcpy (line2, "fep-");
  1381.         strcat (line2, cp);
  1382.         if (executeBuiltInFunction (line2) == NOT_PROCESSED) {
  1383.         printf ("\"%s\", line %d: cannot be executed\n", file, i);
  1384.         printf (">>> %s", line);
  1385.         }
  1386.     }
  1387.     }
  1388.     
  1389.     fclose (fp);
  1390.     return;
  1391.     
  1392. }
  1393.  
  1394. #define MAX_IF_NEST 10
  1395.  
  1396. #define CONDITION_MASK    0x00ff
  1397. #define HAS_BEEN_TRUE    0x0100
  1398.  
  1399. int condition_stack [MAX_IF_NEST] = {1};
  1400. int current_if_stack = 0;
  1401.  
  1402. condition ()
  1403. {
  1404.     int cond = 1, i;
  1405.  
  1406.     if (current_if_stack == 0)
  1407.     return (1);
  1408.  
  1409.     for (i = 1; i <= current_if_stack; i++)
  1410.     cond &= condition_stack [i];
  1411.  
  1412.     return (cond & CONDITION_MASK);
  1413. }
  1414.  
  1415. char *
  1416. change_condition (cond)
  1417.     int cond;
  1418. {
  1419.     if (debug)
  1420.     printf ("old=0x%x, new=0x%x\n",
  1421.         condition_stack [current_if_stack],    cond);
  1422.     if (current_if_stack > 0) {
  1423.     if (condition_stack [current_if_stack] & HAS_BEEN_TRUE)
  1424.         cond = 0;
  1425.     else if (cond != 0)
  1426.         condition_stack [current_if_stack] |= HAS_BEEN_TRUE;
  1427.  
  1428.     condition_stack [current_if_stack] &= ~CONDITION_MASK;
  1429.     condition_stack [current_if_stack] |= cond;
  1430.     return ((char *)0);
  1431.     }
  1432.     else
  1433.     return ("Not in if close\n");
  1434. }
  1435.  
  1436. char *
  1437. push_condition (cond)
  1438.     int cond;
  1439. {
  1440.     if (current_if_stack < MAX_IF_NEST){
  1441.     ++current_if_stack;
  1442.     condition_stack [current_if_stack] = cond;
  1443.     if (cond == 1)
  1444.         condition_stack [current_if_stack] |= HAS_BEEN_TRUE;
  1445.     return ((char*)0);
  1446.     }
  1447.     else
  1448.     return ("If stack over flow\n");
  1449. }
  1450.  
  1451. char *
  1452. pop_condition ()
  1453. {
  1454.  
  1455.     if (current_if_stack > 0) {
  1456.     --current_if_stack;
  1457.     return ((char*)0);
  1458.     }
  1459.     else
  1460.     return ("No more if stack\n");
  1461. }
  1462.  
  1463. invoke_shell ()
  1464. {
  1465.     char *shell = "/bin/sh";
  1466.  
  1467.     if (look_var ("shell"))
  1468.     shell = look_var ("shell");
  1469.  
  1470.     invoke_command (shell);
  1471. }
  1472.  
  1473. invoke_command (cmd)
  1474.     char *cmd;
  1475. {
  1476.     int catchsig();
  1477.     int (*func)();
  1478.  
  1479.     clear_edit_line ();
  1480.     if (look_var ("verbose"))
  1481.     printf ("Invoke %s\n", cmd);
  1482.     fflush (stdout);
  1483.     recover_tty();
  1484.     recover_signal ();
  1485.     system (cmd);
  1486.     fix_signal ();
  1487.     fix_tty();
  1488.     if (look_var ("verbose"))
  1489.     printf ("Return to fep\n");
  1490.     recover_edit_line ();
  1491. }
  1492.  
  1493. FILE *redirect_fp = NULL;
  1494. int redirect_line = 0;
  1495.  
  1496. fep_read_from_file (comline)
  1497.     char *comline;
  1498. {
  1499.     FILE *fp;
  1500.     static char *argv[MAXARGS];
  1501.     char file [MAXPATHLEN];
  1502.     int argc;
  1503.  
  1504.     argc = mkargv (comline, argv, MAXARGS);
  1505.  
  1506.     if (argc != 2) {
  1507.     printf ("Invalid number of arguments.\n");
  1508.     return;
  1509.     }
  1510.  
  1511.     if (redirect_fp) {
  1512.     fclose (redirect_fp);
  1513.     redirect_fp = NULL;
  1514.     }
  1515.  
  1516.     redirect_fp = fopen (argv[1], "r");
  1517.  
  1518.     if (redirect_fp = fopen (argv[1], "r")) {
  1519.     if (look_var ("verbose"))
  1520.         printf ("Input redirected from %s\n", argv[1]);
  1521.     errorBell ();
  1522.     redirect_line = 0;
  1523.     }
  1524.     else
  1525.     perror (argv[0]);
  1526.  
  1527.     return;
  1528. }
  1529.  
  1530. /*
  1531.  * Process ID of the process redirecting from.
  1532.  */
  1533. int redirect_pid = 0;
  1534.  
  1535. fep_read_from_command (comline)
  1536.     char *comline;
  1537. {
  1538.     static char *argv[MAXARGS];
  1539.     char buf[256];
  1540.     int argc;
  1541.     int i;
  1542.     FILE *popen();
  1543.  
  1544.     argc = mkargv (comline, argv, MAXARGS);
  1545.  
  1546.     if (argc == 1) {
  1547.     printf ("Invalid number of arguments.\n");
  1548.     return;
  1549.     }
  1550.  
  1551.     if (redirect_fp) {
  1552.     fclose (redirect_fp);
  1553.     redirect_fp = NULL;
  1554.     }
  1555.  
  1556.     strcpy (buf, "");
  1557.     for (i=1; i<argc; i++) {
  1558.     strcat (buf, argv[i]);
  1559.     strcat (buf, " ");
  1560.     }
  1561.  
  1562.     if (redirect_fp = popen (buf, "r")) {
  1563.     if (look_var ("verbose"))
  1564.         printf ("Input redirected from %s\n", argv[1]);
  1565.     errorBell ();
  1566.     redirect_line = 0;
  1567.     }
  1568.     else
  1569.     perror (argv[0]);
  1570.  
  1571.     return;
  1572. }
  1573.  
  1574. char script_file[128];
  1575.  
  1576. fep_start_script (comline)
  1577.     char *comline;
  1578. {
  1579.     char *name;
  1580.  
  1581.     /*
  1582.      * Caution!! If editstatus is EDITING, comline argument is never passed.
  1583.      */
  1584.     if (editstatus == NOTEDITING) {
  1585.     int argc;
  1586.     static char *argv[MAXARGS];
  1587.     char buf[256];
  1588.  
  1589.     argc = mkargv (comline, argv, MAXARGS);
  1590.     switch (argc) {
  1591.  
  1592.         case 1:
  1593.         name = look_var ("script-file");
  1594.         break;
  1595.  
  1596.         case 2:
  1597.         name = argv[1];
  1598.         break;
  1599.  
  1600.         default:
  1601.         printf ("%s: Illegal number of arguments.\n", argv[0]);
  1602.     }
  1603.     }
  1604.     else
  1605.     name = look_var ("script-file");
  1606.  
  1607.     /*
  1608.      * If script is running alread, reatun.
  1609.      */
  1610.     if (script_fp) {
  1611.     clear_edit_line ();
  1612.     errorBell ();
  1613.     printf ("script is already running.\n");
  1614.     recover_edit_line ();
  1615.     return;
  1616.     }
  1617.  
  1618.     if (!name) {
  1619.     clear_edit_line ();
  1620.     printf ("script-file is not set.\n");
  1621.     recover_edit_line ();
  1622.     return;
  1623.     }
  1624.  
  1625.     if ((script_fp = fopen (name, "a")) == NULL) {
  1626.     clear_edit_line ();
  1627.     perror (name);
  1628.     recover_edit_line ();
  1629.     return;
  1630.     }
  1631.  
  1632.     strncpy (script_file, name, sizeof (script_file));
  1633.  
  1634.     clear_edit_line ();
  1635.     printf ("script start (file=\"%s\").\n", script_file);
  1636.     recover_edit_line ();
  1637. }
  1638.  
  1639. fep_end_script ()
  1640. {
  1641.     if (!script_fp) {
  1642.     clear_edit_line ();
  1643.     errorBell ();
  1644.     printf ("script is not started.\n");
  1645.     return;
  1646.     }
  1647.  
  1648.     fclose (script_fp);
  1649.     script_fp = NULL;
  1650.  
  1651.     clear_edit_line ();
  1652.     printf ("script end (file=\"%s\").\n", script_file);
  1653.     recover_edit_line ();
  1654.  
  1655.     return;
  1656. }
  1657.  
  1658. fep_repaint(comline)
  1659.     char *comline;
  1660. {
  1661.     int i;
  1662.     int line;
  1663.     CHAR ch;
  1664.     char *crt_hight;
  1665.     char *save_prompt;
  1666.     BUFFER *bp = output_buffer;
  1667.  
  1668.     /*
  1669.      * Caution!! If editstatus is EDITING, comline argument is never passed.
  1670.      */
  1671.     if (editstatus == NOTEDITING && comline) {
  1672.     int argc;
  1673.     static char *argv[MAXARGS];
  1674.     char buf[256];
  1675.  
  1676.     argc = mkargv (comline, argv, MAXARGS);
  1677.     switch (argc) {
  1678.  
  1679.         case 1:
  1680.         crt_hight = look_var ("crt");
  1681.         break;
  1682.  
  1683.         case 2:
  1684.         crt_hight = argv[1];
  1685.         break;
  1686.  
  1687.         default:
  1688.         printf ("%s: Illegal number of arguments.\n", argv[0]);
  1689.     }
  1690.     }
  1691.     else
  1692.     crt_hight = look_var ("crt");
  1693.  
  1694.     line = atoi (crt_hight);
  1695.  
  1696.     clear_edit_line ();
  1697.     
  1698.     ch = buf_char (bp, -1);
  1699.     for (i = -1; ; --i) {
  1700.     if ((ch = buf_char(bp, i)) == '\n')
  1701.         --line;
  1702.     if (ch == (CHAR)-1 || line <= 0)
  1703.         break;
  1704.     }
  1705.     i += 1;
  1706.  
  1707.     if (look_var("clear-repaint") && term_clear)
  1708.     tputs (term_clear, 1, putch);
  1709.  
  1710.     for (; i < 0; i++) {
  1711.     char cd;
  1712.     cd = buf_char (bp, i);
  1713.     putchar (buf_char(bp, i));
  1714.     }
  1715.  
  1716.     /*
  1717.      * In this case, prompt should not be printed.
  1718.      * Saving prompt is ugly solution, but...
  1719.      */
  1720.     save_prompt = prompt;
  1721.     prompt = 0;
  1722.     recover_edit_line ();
  1723.     prompt = save_prompt;
  1724.     fflush (stdout);
  1725. }
  1726.  
  1727. #ifdef STAT
  1728.  
  1729. #include "fep_stat.h"
  1730.  
  1731. long stat_obyte = 0;
  1732. long stat_ibyte = 0;
  1733. long stat_rerror = 0;
  1734. long stat_werror = 0;
  1735. long stat_nselect = 0;
  1736.  
  1737. struct statistics stat_info[] = {
  1738.     "Command Output",    &stat_obyte,
  1739.     "Command Input ",    &stat_ibyte,
  1740.     "Read error    ",    &stat_rerror,
  1741.     "Write error   ",    &stat_werror,
  1742.     "Select count  ",    &stat_nselect,
  1743.     NULL, NULL
  1744. };
  1745.  
  1746. fep_showstat ()
  1747. {
  1748.     struct statistics *sp = stat_info;
  1749.     BUFFER *bp = output_buffer;
  1750.  
  1751.     printf ("I/O and system calls:\n");
  1752.     for (sp = stat_info; sp->info_name; sp++) {
  1753.     printf ("\t%s: %d\n", sp->info_name, *(sp->info_valp));
  1754.     }
  1755.  
  1756.     printf ("\nI/O Buffer:\n");
  1757.     printf ("\tMax  : %d\n", bp->b_max);
  1758.     printf ("\tHiWtr: %d\n", bp->hiwater);
  1759.     printf ("\tCount: %d\n", bp->count);
  1760.     printf ("\tNext : %d\n", bp->next);
  1761.     printf ("\tStart: %d\n", bp->start);
  1762.  
  1763. }
  1764. #endif
  1765. \End\Of\File\
  1766. else
  1767.   echo "will not over write ./fep_com.c"
  1768. fi
  1769. echo "Finished archive 2 of 5"
  1770. exit
  1771.  
  1772.