home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / reactivekbd / part04 / functions.c
Encoding:
C/C++ Source or Header  |  1989-10-16  |  35.0 KB  |  1,646 lines

  1. #include "file+rk.h"
  2. #include "rk_button.h"
  3. #include <sys/ioctl.h>
  4. #include <stdio.h>
  5.  
  6. extern char *cursor_left, *cursor_right;
  7. extern char *enter_insert_mode, *exit_insert_mode;
  8. extern char *pre_insert_char, *post_insert_char;
  9. extern char *enter_delete_mode, *exit_delete_mode, *delete_a_char;
  10. extern char *clear_screen;
  11. extern char *enter_standout_mode, *exit_standout_mode;    /* JJD 9-86 */
  12. extern int  current_key_map;
  13. extern char meta_prefixes[MAXEXTENSIONS][MAXEXTENSIONS];
  14. extern int  meta_map[MAXEXTENSIONS][MAXEXTENSIONS];
  15.  
  16. extern pred_number;
  17. extern pty_master;
  18. extern char output_string[],temp_str[];
  19. extern output_string_length;
  20. extern char pred_mode,pred_on_display,lisp_mode,nl_truncate_mode,eol_only_mode,eol_longer_mode,add_space_mode,show_eol_mode;
  21. extern char pred_buff[];
  22. extern (*keymap[128][MAXEXTENSIONS]) ();
  23. extern char trace_mode;
  24. extern struct sgttyb   new_stdin, old_stdin;
  25. extern int maxk;
  26. extern int maxprime;
  27. extern max_freq;
  28. extern max_nodes;
  29.  
  30. append_to_output_string(c)
  31.     char            c;
  32. {
  33.     output_string[output_string_length++] = c;
  34. }
  35.  
  36. int 
  37. accept_forward_word(e)
  38.     ED_STRUCT      *e;
  39. {                /* JJD 9-86 */
  40.     char           *ch;
  41.     int             how_many, num_to_advance;
  42.  
  43.     if (!pred_mode)
  44.         return forward_word(e);
  45.     how_many = e->universal_argument;
  46.     num_to_advance = 0;
  47.     /* truncate prediction to after first NL */
  48.     if (ch = index(pred_buff, '\n'))
  49.         *(++ch) = '\0';
  50.     ch = &pred_buff[0];    /* changed from editor data */
  51.  
  52.     while (how_many--) {
  53.         if ((!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  54.             while (*ch && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  55.                 num_to_advance++, ch++;
  56.  
  57.         while (*ch && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  58.             num_to_advance++, ch++;
  59.         if(isspace(*ch)&&add_space_mode&&(*ch!='\n'))
  60.             num_to_advance++, ch++;
  61.         if (*ch == '\0')
  62.             how_many = 0;
  63.     }
  64.  
  65.     e->universal_argument = num_to_advance;
  66.     return accept_forward_char(e);    
  67. }
  68.  
  69. int BOGUS(e)
  70.     ED_STRUCT      *e;
  71. {
  72.         e->universal_argument = 1;
  73.         write (1, "\07", 1);
  74.         return(OK);
  75. }
  76.  
  77. int 
  78. forward_word(e)
  79.     ED_STRUCT      *e;
  80. {
  81.  
  82.     char           *ch;
  83.     int             how_many, num_to_advance;
  84.  
  85.     how_many = e->universal_argument;
  86.     num_to_advance = 0;
  87.     ch = e->dot;
  88.  
  89.     while (how_many--) {
  90.         if ((!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  91.             while (*ch && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  92.                 num_to_advance++, ch++;
  93.  
  94.         while (*ch && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  95.             num_to_advance++, ch++;
  96.  
  97.         if (*ch == '\0')
  98.             how_many = 0;
  99.     }
  100.  
  101.     e->universal_argument = num_to_advance;
  102.     return forward_char(e);
  103. }
  104.  
  105.  
  106. int 
  107. backward_word(e)
  108.     ED_STRUCT      *e;
  109. {
  110.  
  111.     char           *ch, *cb;
  112.     int             num_to_go, how_many;
  113.  
  114.     cb = e->current_buffer;
  115.     ch = e->dot;
  116.     num_to_go = 0;
  117.     how_many = e->universal_argument;
  118.  
  119.     if (ch-- == cb)
  120.         return OK;
  121.  
  122.     while (how_many--) {
  123.         while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  124.             num_to_go++, ch--;
  125.  
  126.         while ((ch >= cb) &&
  127.                (isalnum(*ch) ||
  128.             (*ch == '-') ||
  129.             (*ch == '_')))
  130.             num_to_go++, ch--;
  131.  
  132.         if (ch < e->current_buffer)
  133.             how_many = 0;
  134.     }
  135.  
  136.     e->universal_argument = num_to_go;
  137.     return backward_char(e);
  138. }
  139.  
  140.  
  141. int 
  142. delete_word(e)
  143.     ED_STRUCT      *e;
  144. {
  145.  
  146.     char           *ch;
  147.     int             how_many, num_to_advance;
  148.  
  149.     how_many = e->universal_argument;
  150.     num_to_advance = 0;
  151.     ch = e->dot;
  152.  
  153.     while (how_many--) {
  154.         if ((!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  155.             while (*ch && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  156.                 num_to_advance++, ch++;
  157.  
  158.         while (*ch && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  159.             num_to_advance++, ch++;
  160.  
  161.         if (*ch == '\0')
  162.             how_many = 0;
  163.     }
  164.  
  165.     e->universal_argument = num_to_advance;
  166.     return delete_char(e);
  167. }
  168.  
  169.  
  170. int 
  171. backspace_word(e)
  172.     ED_STRUCT      *e;
  173. {
  174.  
  175.     char           *ch, *cb;
  176.     int             num_to_go, how_many;
  177.  
  178.     cb = e->current_buffer;
  179.     ch = e->dot;
  180.     num_to_go = 0;
  181.     how_many = e->universal_argument;
  182.  
  183.     if (ch-- == cb)
  184.         return OK;
  185.  
  186.     while (how_many--) {
  187.         while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  188.             num_to_go++, ch--;
  189.  
  190.         while ((ch >= cb) &&
  191.                (isalnum(*ch) ||
  192.             (*ch == '-') ||
  193.             (*ch == '_')))
  194.             num_to_go++, ch--;
  195.  
  196.         if (ch < e->current_buffer)
  197.             how_many = 0;
  198.     }
  199.  
  200.     e->universal_argument = num_to_go;
  201.     return backspace_char(e);
  202. }
  203.  
  204.  
  205. int 
  206. forward_paren(e)
  207.     ED_STRUCT      *e;
  208. {
  209.  
  210.     char           *ch = e->dot - 1;    /* pretend to go back one */
  211.     int             paren_count = 1;
  212.     int             num_to_advance = 0;
  213.  
  214.     while (*++ch && paren_count) {
  215.         num_to_advance++;
  216.         if (*ch == ')')
  217.             paren_count--;    /* a ')' with no intervening ()'s */
  218.         else if (*ch == '(')    /* search for ) matching this ( */
  219.             while (*++ch && paren_count) {
  220.                 num_to_advance++;
  221.                 if (*ch == ')')
  222.                     paren_count--;
  223.                 else if (*ch == '(')
  224.                     paren_count++;
  225.             }
  226.     }
  227.  
  228.     e->universal_argument = num_to_advance;
  229.     return forward_char(e);
  230. }
  231.  
  232.  
  233. int 
  234. backward_paren(e)
  235.     ED_STRUCT      *e;
  236. {
  237.  
  238.     char           *ch, *cb;
  239.     int             paren_count = 1;
  240.     int             num_to_go = 0;
  241.  
  242.     ch = e->dot;
  243.     cb = e->current_buffer;
  244.  
  245.     if (ch != cb)        /* not already at the beginning */
  246.         while ((--ch >= cb) && paren_count) {
  247.             num_to_go++;
  248.             if (*ch == '(')
  249.                 paren_count--;    /* a '(' with no intervening
  250.                          * ()'s */
  251.             else if (*ch == ')')    /* search for ( matching this
  252.                          * ) */
  253.                 while ((--ch >= cb) && paren_count) {
  254.                     num_to_go++;
  255.                     if (*ch == '(')
  256.                         paren_count--;
  257.                     else if (*ch == ')')
  258.                         paren_count++;
  259.                 }
  260.         }
  261.  
  262.     e->universal_argument = num_to_go;
  263.     return backward_char(e);
  264. }
  265.  
  266. int 
  267. toggle_lisp_mode(e)
  268.     ED_STRUCT      *e;
  269. {
  270.     lisp_mode = !lisp_mode;
  271.     return OK;
  272. }
  273.  
  274. int 
  275. toggle_add_space_mode(e)
  276.     ED_STRUCT      *e;
  277. {
  278.     add_space_mode = !add_space_mode;
  279.     return OK;
  280. }
  281.  
  282. int 
  283. toggle_show_eol_mode(e)
  284.     ED_STRUCT      *e;
  285. {
  286.     show_eol_mode = !show_eol_mode;
  287.     if (pred_on_display)
  288.         erase_pred_buffer(e);
  289.     if (pred_mode)
  290.         make_a_prediction(pred_buff);
  291.     return OK;
  292. }
  293.  
  294. int 
  295. toggle_nl_truncate_mode(e)
  296.     ED_STRUCT      *e;
  297. {                /* JJD 9-86 */
  298.     nl_truncate_mode = !nl_truncate_mode;
  299.     if (pred_on_display)
  300.         erase_pred_buffer(e);
  301.     if (pred_mode)
  302.         make_a_prediction(pred_buff);
  303.     return OK;
  304. }
  305.  
  306. int 
  307. toggle_eol_only_mode(e)
  308.     ED_STRUCT      *e;
  309. {                /* JJD 9-86 */
  310.     eol_only_mode = !eol_only_mode;
  311.     if (pred_on_display)
  312.         erase_pred_buffer(e);
  313.     if (pred_mode)
  314.         make_a_prediction(pred_buff);
  315.     return OK;
  316. }
  317.  
  318. int 
  319. toggle_eol_longer_mode(e)
  320.     ED_STRUCT      *e;
  321. {                /* JJD 9-86 */
  322.     eol_longer_mode = !eol_longer_mode;
  323.     if (pred_on_display)
  324.         erase_pred_buffer(e);
  325.     if (pred_mode)
  326.         make_a_prediction(pred_buff);
  327.     return OK;
  328. }
  329.  
  330. int 
  331. toggle_pred_mode(e)
  332.     ED_STRUCT      *e;
  333. {                /* JJD 9-86 */
  334.     pred_mode = !pred_mode;
  335.     if (pred_on_display)
  336.         erase_pred_buffer(e);
  337.     if (pred_mode)
  338.         make_a_prediction(pred_buff);
  339.     return OK;
  340. }
  341.  
  342. int 
  343. show_free_nodes(e)
  344.     ED_STRUCT      *e;
  345. {                /* JJD 1-87, revised 3-89 */
  346.     extern int      next_free;
  347.     char            tbuf[128];    /* extern in rk_button */
  348.     extern long     psize;
  349.     sprintf(tbuf, "\015\nK=%d, COUNT=%d, NODES=%d, PRIME=%d; psize=%d, nodes=%d\015\n",
  350.         maxk, max_freq, max_nodes, maxprime, psize, next_free);
  351.     write(1, tbuf, strlen(tbuf));
  352.     write(1, "Continue: ", 10);    /* JJD 3-89 added */
  353.     draw_current_edit_line(e);    /* JJD 3-89 added */
  354.     return OK;
  355. }
  356.  
  357. int 
  358. show_version(e)
  359.     ED_STRUCT      *e;
  360. {                /* JJD 3-89 added */
  361.     char            tbuf[128];
  362.     sprintf(tbuf, "\015\nRK_Button Version: %s", RK_VERSION);
  363.     strcat(tbuf, ", with file_completion (^C).\015\n");
  364.     write(1, tbuf, strlen(tbuf));
  365.     write(1, "Continue: ", 10);
  366.     draw_current_edit_line(e);
  367.     return OK;
  368. }
  369.  
  370. int 
  371. prime_from_file(e)
  372.     ED_STRUCT      *e;
  373. {                /* JJD 9-86 */
  374.     char            filename[256];
  375.     FILE           *from;
  376.     int             i;
  377.     char            c;
  378.     extern Buffer   Buf;    /* externs in rk_button */
  379.     extern char     context[MAX_CMD_LINE_LENGTH];
  380.  
  381.     erase_current_edit_line(e);
  382.     e->dot = e->current_buffer;
  383.     e->mark = e->current_buffer;
  384.     *(e->dot) = '\0';
  385.  
  386.     ioctl(0, TIOCGETP, &new_stdin);
  387.     ioctl(0, TIOCSETP, &old_stdin);
  388.     strcpy(filename, "");
  389.     printf("File to prime from ([RETURN] to cancel): ");
  390.     fflush(stdout);
  391.     gets(filename);
  392.     if (filename[0] == '\0') {
  393.         printf("Command cancelled.\r\n");
  394.         fflush(stdout);
  395.     } else {
  396.         if ((from = fopen(filename, "r")) == NULL) {
  397.             printf("cannot open: %s\r\n", filename);
  398.             fflush(stdout);
  399.         } else {
  400.             while (((int) (c = getc(from))) != EOF)
  401.                 for (i = maxk; i > 0; i--)
  402.                     Buf[i] = move_up(Buf[i - 1], c);
  403.             fclose(from);
  404.             show_free_nodes(e);
  405.         }
  406.     }
  407.     ioctl(0, TIOCSETP, &new_stdin);
  408.  
  409.     return OK;
  410. }
  411.  
  412.  
  413. int 
  414. close_paren(e)
  415.     ED_STRUCT      *e;
  416. {
  417.  
  418.     char           *old_dot;
  419.  
  420.     if (!lisp_mode)
  421.         return self_insert(e);
  422.  
  423.     old_dot = e->dot;
  424.     if (*old_dot != ')')    /* if not on a ')', insert one */
  425.         self_insert(e);
  426.  
  427.     forward_char(e);    /* skip past ')' so bkd-prn works */
  428.     backward_paren(e);    /* flash back to matching '(' */
  429.     sleep(1);
  430.  
  431.     e->universal_argument = 1 + old_dot - e->dot;
  432.     return forward_char(e);    /* skip ahead to old dot + 1 */
  433. }
  434.  
  435.  
  436. int 
  437. open_paren(e)
  438.     ED_STRUCT      *e;
  439. {
  440.  
  441.     char           *old_dot;
  442.  
  443.     self_insert(e);        /* stick in an open_paren */
  444.     if (!lisp_mode)
  445.         return OK;
  446.  
  447.     old_dot = e->dot;
  448.     if ((*old_dot == ')') || (*old_dot == 0)) {
  449.         e->current_input_char = ')';    /* if on a ')' or at the end */
  450.         self_insert(e);    /* then insert matching ')' */
  451.         backward_char(e);    /* and go back inside () */
  452.     }
  453.     return OK;
  454. }
  455.  
  456.  
  457. int 
  458. increment_universal_argument(e)
  459.     ED_STRUCT      *e;
  460. {
  461.  
  462.     if (e->universal_argument > UNIVERSAL_ARGUMENT_MAXIMUM)
  463.         write(1, "\07", 1);
  464.     else
  465.         e->universal_argument *= 4;
  466.  
  467.     return OK;
  468. }
  469.  
  470.  
  471. int 
  472. clear_display(e)
  473.     ED_STRUCT      *e;
  474. {
  475.  
  476.     e->universal_argument = 1;
  477.     output_string_length = 0;
  478.     if (clear_screen) {
  479.         tputs(clear_screen, ONE_LINE, append_to_output_string);
  480.         write(1, output_string, output_string_length);
  481.     } else
  482.         write(1, "\r\n\r\n", 2);
  483.     draw_current_edit_line(e);
  484.  
  485.     return OK;
  486. }
  487.  
  488.  
  489.  
  490. int 
  491. previous_line(e)
  492.     ED_STRUCT      *e;
  493. {
  494.  
  495.     int             how_many;
  496.  
  497.     how_many = e->universal_argument;
  498.     e->current_ed_buff_ptr->dot = e->dot;
  499.     e->current_ed_buff_ptr->mark = e->mark;
  500.     erase_current_edit_line(e);
  501.     for (; how_many; --how_many)
  502.         e->current_ed_buff_ptr = e->current_ed_buff_ptr->prev_ptr;
  503.     e->current_buffer = e->current_ed_buff_ptr->string;
  504.     e->dot = e->current_ed_buff_ptr->dot;
  505.     e->mark = e->current_ed_buff_ptr->mark;
  506.     draw_current_edit_line(e);
  507.     e->universal_argument = 1;
  508.     return OK;
  509. }
  510.  
  511.  
  512. int 
  513. previous_pred(e)
  514.     ED_STRUCT      *e;
  515. {                /* JJD 9-86 */
  516.  
  517.     if (pred_number)
  518.         pred_number--;
  519.     return OK;
  520. }
  521.  
  522. int 
  523. next_pred(e)
  524.     ED_STRUCT      *e;
  525. {                /* JJD 9-86 */
  526.  
  527.     if (++pred_number > 127)
  528.         pred_number = 127;
  529.     return OK;
  530. }
  531.  
  532. int 
  533. next_line(e)
  534.     ED_STRUCT      *e;
  535. {
  536.  
  537.     int             how_many;
  538.  
  539.     how_many = e->universal_argument;
  540.     e->current_ed_buff_ptr->dot = e->dot;
  541.  
  542.     e->current_ed_buff_ptr->mark = e->mark;
  543.  
  544.     erase_current_edit_line(e);
  545.     for (; how_many; --how_many)
  546.         e->current_ed_buff_ptr = e->current_ed_buff_ptr->next_ptr;
  547.     e->current_buffer = e->current_ed_buff_ptr->string;
  548.     e->dot = e->current_ed_buff_ptr->dot;
  549.  
  550.     e->mark = e->current_ed_buff_ptr->mark;
  551.  
  552.     draw_current_edit_line(e);
  553.     e->universal_argument = 1;
  554.     return OK;
  555. }
  556.  
  557.  
  558. int 
  559. discard_current_edit_line(e)
  560.     ED_STRUCT      *e;
  561. {
  562.  
  563.     strcpy(e->kill_buffer, e->current_buffer);
  564.     erase_current_edit_line(e);
  565.     e->dot = e->current_buffer;
  566.  
  567.     e->mark = e->current_buffer;
  568.  
  569.     *e->dot = '\0';
  570.  
  571.     return OK;
  572. }
  573.  
  574.  
  575. int 
  576. discard_rest_of_line(e)
  577.     ED_STRUCT      *e;
  578. {
  579.  
  580.     strcpy(e->kill_buffer, e->dot);
  581.     e->universal_argument = strlen(e->dot);
  582.  
  583.     if (e->universal_argument == 0) {
  584.         e->universal_argument = 1;
  585.         return OK;
  586.     } else
  587.  
  588.     {
  589.         if (e->mark > e->dot)
  590.             e->mark = e->dot;
  591.         return delete_char(e);
  592.     }
  593.  
  594. }
  595.  
  596.  
  597. int 
  598. yank_from_kill_buffer(e)
  599.     ED_STRUCT      *e;
  600. {
  601.  
  602.     int             count;
  603.  
  604.     output_string_length = 0;
  605.     strcpy(temp_str, e->dot);
  606.     strcpy(e->dot, e->kill_buffer);
  607.  
  608.     if (e->mark > e->dot)
  609.         e->mark += strlen(e->kill_buffer);
  610.  
  611.     e->dot = e->dot + strlen(e->kill_buffer);
  612.     strcpy(e->dot, temp_str);
  613.     display_string_into_output_string(e->kill_buffer);
  614.     count = display_string_into_output_string(temp_str);
  615.     for (; count; --count)
  616.         tputs(cursor_left, ONE_LINE, append_to_output_string);
  617.     write(1, output_string, output_string_length);
  618.  
  619.     return OK;
  620. }
  621.  
  622.  
  623.  
  624. int 
  625. display_pred_buffer(e)
  626.     ED_STRUCT      *e;
  627. {                /* JJD 9-86 ???? */
  628.  
  629.     int             count;
  630.  
  631.     output_string[0] = '\0';
  632.     output_string_length = 0;
  633.  
  634.     if (enter_standout_mode)
  635.         tputs(enter_standout_mode, ONE_LINE, append_to_output_string);
  636.     count = display_string_into_output_string(pred_buff);
  637.     if (enter_standout_mode)
  638.         tputs(exit_standout_mode, ONE_LINE, append_to_output_string);
  639.     count += display_string_into_output_string(e->dot);
  640.  
  641.     for (; count; --count)
  642.         tputs(cursor_left, ONE_LINE, append_to_output_string);
  643.     write(1, output_string, output_string_length);
  644.     pred_on_display = 1;
  645.  
  646.     return OK;
  647. }
  648.  
  649.  
  650. int 
  651. erase_pred_buffer(e)
  652.     ED_STRUCT      *e;
  653. {                /* JJD 9-86 */
  654.  
  655.     int             num_to_erase, count;
  656.  
  657.     output_string[0] = '\0';
  658.     output_string_length = 0;
  659.  
  660.     if (enter_standout_mode)
  661.         tputs(exit_standout_mode, ONE_LINE, append_to_output_string);
  662.     display_string_into_output_string(e->dot);
  663.  
  664.     num_to_erase = get_display_length(pred_buff);
  665.     for (count = num_to_erase; count; --count)
  666.         output_string[output_string_length++] = ' ';
  667.     num_to_erase += get_display_length(e->dot);
  668.     for (count = num_to_erase; count; --count)
  669.         tputs(cursor_left, ONE_LINE, append_to_output_string);
  670.     write(1, output_string, output_string_length);
  671.     pred_on_display = 0;
  672.  
  673.     return OK;
  674. }
  675.  
  676. int 
  677. insert_interrupt_char(e)
  678.     ED_STRUCT      *e;
  679. {
  680.  
  681.     struct tchars   pty_tchars;
  682.  
  683.     ioctl(pty_master, TIOCGETC, &pty_tchars);
  684.  
  685.     erase_current_edit_line(e);
  686.     e->dot = e->current_buffer;
  687.  
  688.     e->mark = e->current_buffer;
  689.  
  690.     *(e->dot++) = pty_tchars.t_intrc;
  691.     *(e->dot) = '\0';
  692.     return FINISHED_BUT_DONT_ADD_CTRL_M;
  693. }
  694.  
  695. int 
  696. insert_quit_char(e)
  697.     ED_STRUCT      *e;
  698. {
  699.  
  700.     struct tchars   pty_tchars;
  701.  
  702.     ioctl(pty_master, TIOCGETC, &pty_tchars);
  703.  
  704.     erase_current_edit_line(e);
  705.     e->dot = e->current_buffer;
  706.     e->mark = e->current_buffer;
  707.     *(e->dot++) = pty_tchars.t_quitc;
  708.     *(e->dot) = '\0';
  709.     return FINISHED_BUT_DONT_ADD_CTRL_M;
  710. }
  711.  
  712. int 
  713. insert_stop_char(e)
  714.     ED_STRUCT      *e;
  715. {                /* JJD 9-86 */
  716.  
  717.     struct tchars   pty_tchars;
  718.  
  719.     ioctl(pty_master, TIOCGETC, &pty_tchars);
  720.  
  721.     erase_current_edit_line(e);
  722.     e->dot = e->current_buffer;
  723.     e->mark = e->current_buffer;
  724.     *(e->dot++) = pty_tchars.t_stopc;
  725.     *(e->dot) = '\0';
  726.     return FINISHED_BUT_DONT_ADD_CTRL_M;
  727. }
  728.  
  729. int 
  730. insert_start_char(e)
  731.     ED_STRUCT      *e;
  732. {                /* JJD 9-86 */
  733.  
  734.     struct tchars   pty_tchars;
  735.  
  736.     ioctl(pty_master, TIOCGETC, &pty_tchars);
  737.  
  738.     erase_current_edit_line(e);
  739.     e->dot = e->current_buffer;
  740.     e->mark = e->current_buffer;
  741.     *(e->dot++) = pty_tchars.t_startc;
  742.     *(e->dot) = '\0';
  743.     return FINISHED_BUT_DONT_ADD_CTRL_M;
  744. }
  745.  
  746. int 
  747. insert_eof_char(e)
  748.     ED_STRUCT      *e;
  749. {                /* JJD 9-86 */
  750.  
  751.     struct tchars   pty_tchars;
  752.  
  753.     ioctl(pty_master, TIOCGETC, &pty_tchars);
  754.  
  755.     erase_current_edit_line(e);
  756.     e->dot = e->current_buffer;
  757.     e->mark = e->current_buffer;
  758.     *(e->dot++) = pty_tchars.t_eofc;
  759.     *(e->dot) = '\0';
  760.     return FINISHED_BUT_DONT_ADD_CTRL_M;
  761. }
  762.  
  763. int 
  764. insert_suspend_char(e)
  765.     ED_STRUCT      *e;
  766. {
  767.  
  768.     struct ltchars  pty_ltchars;
  769.  
  770.     ioctl(pty_master, TIOCGLTC, &pty_ltchars);
  771.  
  772.     erase_current_edit_line(e);
  773.     e->dot = e->current_buffer;
  774.     e->mark = e->current_buffer;
  775.     *(e->dot++) = pty_ltchars.t_suspc;
  776.     *(e->dot) = '\0';
  777.     return FINISHED_BUT_DONT_ADD_CTRL_M;
  778. }
  779.  
  780.  
  781.  
  782. int 
  783. twiddle_chars(e)
  784.     ED_STRUCT      *e;
  785. {
  786.  
  787.     char            temp_char;
  788.     int             num_to_back_up, count;
  789.  
  790.     output_string_length = 0;
  791.  
  792.     if (strlen(e->current_buffer) == 0) {
  793.         *e->dot++ = '\024';
  794.         *e->dot = '\0';
  795.         return FINISHED_BUT_DONT_ADD_CTRL_M;
  796.     } else if ((e->dot - e->current_buffer) < 2)
  797.         write(1, "\07", 1);
  798.     else {
  799.         temp_char = *(e->dot - 1);
  800.         *(e->dot - 1) = *(e->dot - 2);
  801.         *(e->dot - 2) = temp_char;
  802.         num_to_back_up = get_char_display_length(*(e->dot - 2));
  803.         num_to_back_up += get_char_display_length(*(e->dot - 1));
  804.         for (count = num_to_back_up; count; --count)
  805.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  806.         display_char_into_output_string(*(e->dot - 2));
  807.         display_char_into_output_string(*(e->dot - 1));
  808.         write(1, output_string, output_string_length);
  809.     }
  810.  
  811.     e->universal_argument = 1;
  812.  
  813.     return OK;
  814. }
  815.  
  816. int 
  817. beginning_of_line(e)
  818.     ED_STRUCT      *e;
  819. {
  820.  
  821.     e->universal_argument = 1;
  822.     output_string[0] = '\0';
  823.     output_string_length = 0;
  824.     while (e->dot != e->current_buffer) {
  825.         e->dot--;
  826.         if ((*(e->dot) < 32) || (*(e->dot) == 127)) {
  827.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  828.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  829.         } else
  830.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  831.     }
  832.  
  833.     write(1, output_string, output_string_length);
  834.  
  835.     return OK;
  836. }
  837.  
  838. int 
  839. end_of_line(e)
  840.     ED_STRUCT      *e;
  841. {
  842.  
  843.     e->universal_argument = 1;
  844.     output_string[0] = '\0';
  845.     output_string_length = 0;
  846.     display_string_into_output_string(e->dot);
  847.     e->dot = &(e->current_buffer[strlen(e->current_buffer)]);
  848.  
  849.     write(1, output_string, output_string_length);
  850.  
  851.     return OK;
  852. }
  853.  
  854. int 
  855. quote_char(e)
  856.     ED_STRUCT      *e;
  857. {
  858.  
  859.     char            quoted_char;
  860.  
  861.     READ(0, "ed_char, 1);
  862.     quoted_char &= 127;
  863.     if (quoted_char == '\0') {
  864.         write(1, "\07", 1);
  865.         return OK;
  866.     } else {
  867.         e->current_input_char = quoted_char;
  868.         return self_insert(e);
  869.     }
  870. }
  871.  
  872. meta_prefix(e)
  873.     ED_STRUCT      *e;
  874. {
  875.     char            metad_char;
  876.     int        i=0;
  877.     int        status;
  878.  
  879.     if(e==0)
  880.         abortit("meta_prefix passed a nil pointer, aborting...\n",-1);
  881.  
  882.     while((i<MAXEXTENSIONS) && (meta_prefixes[i][current_key_map]) &&
  883.           (e->current_input_char!=meta_prefixes[i][current_key_map]))
  884.         i++;
  885.     if(i==MAXEXTENSIONS)
  886.         return(BOGUS(e));
  887.     current_key_map=meta_map[i][current_key_map];
  888.  
  889.     if (pred_mode && pred_buff[0] && !pred_on_display)
  890.         display_pred_buffer(e);    /* JJD 9-86 */
  891.     READ(0, &metad_char, 1);
  892.     if (pred_on_display) erase_pred_buffer (e);    /* JJD 3-89 added */
  893.     metad_char &= 127;    /* clear high bit */
  894.     e->current_input_char = metad_char;
  895.     status  = (keymap[(int) metad_char][current_key_map])(e);
  896.     current_key_map=0;
  897.     return(status);
  898. }
  899.  
  900.  
  901.     
  902.  
  903.  
  904. int 
  905. backward_char(e)
  906.     ED_STRUCT      *e;
  907. {
  908.  
  909.     int             num_to_go, count, needs_beep;
  910.  
  911.     output_string[0] = '\0';
  912.     output_string_length = 0;
  913.  
  914.     if ((e->dot - e->universal_argument) < e->current_buffer)
  915.         num_to_go = e->dot - e->current_buffer, needs_beep = 1;
  916.     else
  917.         num_to_go = e->universal_argument, needs_beep = 0;
  918.  
  919.     count = num_to_go;
  920.     while (count-- > 0) {
  921.         e->dot--;
  922.         tputs(cursor_left, ONE_LINE, append_to_output_string);
  923.         if ((*(e->dot) < 32) || (*(e->dot) == 127))
  924.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  925.     }
  926.  
  927.     if (needs_beep)
  928.         output_string[output_string_length++] = '\07';
  929.  
  930.     write(1, output_string, output_string_length);
  931.  
  932.     e->universal_argument = 1;
  933.  
  934.     return OK;
  935. }
  936.  
  937. int 
  938. accept_to_end_of_line(e)
  939.     ED_STRUCT      *e;
  940. {                /* JJD 9-86 */
  941.  
  942.     char           *ptr;
  943.  
  944.     if (!pred_mode)
  945.         return end_of_line(e);
  946.     /* truncate prediction to after first NL */
  947.     if (ptr = index(pred_buff, '\n')){
  948.         *(++ptr) = '\0';
  949.     }
  950.     /* only go to end of prediction */
  951.     e->universal_argument = strlen(pred_buff);
  952.     return accept_forward_char(e);
  953. }
  954.  
  955. int 
  956. accept_forward_char(e)
  957.     ED_STRUCT      *e;
  958. {                /* JJD 9-86 */
  959.  
  960.     int             num_to_go, count, needs_beep, finished = 0;
  961.  
  962.     if (!pred_mode)
  963.         return forward_char(e);
  964.     if (pred_buff[0] == '\n')
  965.         return finish_editing_line(e);
  966.     output_string[0] = '\0';
  967.     output_string_length = 0;
  968.  
  969.     num_to_go = strlen(pred_buff);
  970.     if (e->universal_argument > num_to_go)    /* to end of prediction */
  971.         needs_beep = 1;
  972.     else
  973.         num_to_go = e->universal_argument, needs_beep = 0;
  974.  
  975.     /* there is at most 1 NL at the end of the prediction */
  976.     if (pred_buff[num_to_go - 1] == '\n') {
  977.         num_to_go--;
  978.         finished = 1;
  979.     }
  980.     pred_buff[num_to_go] = '\0';
  981.     display_string_into_output_string(pred_buff);
  982.     strcat(pred_buff, e->dot);
  983.     strcpy(e->dot, pred_buff);
  984.     if (e->mark > e->dot)
  985.         e->mark += num_to_go;
  986.     e->dot += num_to_go;
  987.     count = display_string_into_output_string(e->dot);
  988.     for (; count; --count)
  989.         tputs(cursor_left, ONE_LINE, append_to_output_string);
  990.  
  991.     if (needs_beep)
  992.         output_string[output_string_length++] = '\07';
  993.     write(1, output_string, output_string_length);
  994.     e->universal_argument = 1;
  995.  
  996.     if (finished)
  997.         return finish_editing_line(e);
  998.     else
  999.         return OK;
  1000. }
  1001.  
  1002. int 
  1003. forward_char(e)
  1004.     ED_STRUCT      *e;
  1005. {
  1006.  
  1007.     int             num_to_go, count, needs_beep;
  1008.  
  1009.     output_string[0] = '\0';
  1010.     output_string_length = 0;
  1011.  
  1012.     if (e->universal_argument > strlen(e->dot))
  1013.         num_to_go = strlen(e->dot), needs_beep = 1;
  1014.     else
  1015.         num_to_go = e->universal_argument, needs_beep = 0;
  1016.  
  1017.     count = num_to_go;
  1018.     while (count-- > 0)
  1019.         display_char_into_output_string(*(e->dot++));
  1020.  
  1021.     if (needs_beep)
  1022.         output_string[output_string_length++] = '\07';
  1023.  
  1024.     write(1, output_string, output_string_length);
  1025.  
  1026.     e->universal_argument = 1;
  1027.  
  1028.     return OK;
  1029. }
  1030.  
  1031.  
  1032. int 
  1033. backspace_char(e)
  1034.     ED_STRUCT      *e;
  1035. {
  1036.  
  1037.     int             rest_of_line_display_length, count;
  1038.     int             num_to_delete;
  1039.     char           *c, *new_dot;
  1040.     char           *old_dot = e->dot;    /* JJD 3-89 added */
  1041.  
  1042.     output_string[0] = '\0';
  1043.     output_string_length = 0;
  1044.  
  1045.     if ((e->dot - e->current_buffer) < e->universal_argument)
  1046.         new_dot = e->current_buffer;
  1047.     else
  1048.         new_dot = e->dot - e->universal_argument;
  1049.  
  1050.     num_to_delete = 0;
  1051.     for (c = e->dot - 1; c >= new_dot; --c)
  1052.         if ((*c < 32) || (*c == 127))
  1053.             num_to_delete += 2;
  1054.         else
  1055.             num_to_delete++;
  1056.  
  1057.     if (delete_a_char) {
  1058.         for (count = num_to_delete; count; --count)
  1059.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  1060.  
  1061.         if (enter_delete_mode)
  1062.             tputs(enter_delete_mode, ONE_LINE, append_to_output_string);
  1063.  
  1064.         for (count = num_to_delete; count; --count)
  1065.             tputs(delete_a_char, ONE_LINE, append_to_output_string);
  1066.  
  1067.         if (enter_delete_mode)
  1068.             tputs(exit_delete_mode, ONE_LINE, append_to_output_string);
  1069.     } else {
  1070.         for (count = num_to_delete; count; --count)
  1071.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  1072.  
  1073.         rest_of_line_display_length =
  1074.             display_string_into_output_string(e->dot);
  1075.  
  1076.         for (count = num_to_delete; count; --count)
  1077.             output_string[output_string_length++] = ' ';
  1078.  
  1079.         for (count = num_to_delete + rest_of_line_display_length; count; --count)
  1080.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  1081.     }
  1082.  
  1083.     if (e->dot - e->universal_argument < e->current_buffer)
  1084.         output_string[output_string_length++] = '\07';
  1085.  
  1086.     strcpy(temp_str, e->dot);
  1087.     strcpy(new_dot, temp_str);
  1088.     e->dot = new_dot;
  1089.     if (e->mark >= new_dot)
  1090.         e->mark -= (old_dot - new_dot);
  1091.     e->universal_argument = 1;
  1092.     write(1, output_string, output_string_length);
  1093.  
  1094.     return OK;
  1095. }
  1096.  
  1097. int 
  1098. delete_char(e)
  1099.     ED_STRUCT      *e;
  1100. {
  1101.  
  1102.     int             count;
  1103.     int             num_to_delete, num_to_back_up;
  1104.     char           *c, *new_dot;
  1105.     char           *old_dot = e->dot;    /* JJD 3-89 added */
  1106.  
  1107.     if (*(e->dot) == '\0') {
  1108.         struct tchars   pty_tchars;
  1109.         ioctl(pty_master, TIOCGETC, &pty_tchars);
  1110.         erase_pred_buffer(e);
  1111.         erase_current_edit_line(e);
  1112.         *(e->dot++) = pty_tchars.t_eofc;
  1113.         *(e->dot) = '\0';
  1114.         return FINISHED_BUT_DONT_ADD_CTRL_M;
  1115.     }
  1116.     output_string[0] = '\0';
  1117.     output_string_length = 0;
  1118.  
  1119.     if (e->universal_argument > strlen(e->dot))
  1120.         new_dot = e->dot + strlen(e->dot);
  1121.     else
  1122.         new_dot = e->dot + e->universal_argument;
  1123.  
  1124.     num_to_delete = 0;
  1125.     for (c = e->dot; c < new_dot; ++c)
  1126.         if ((*c < 32) || (*c == 127))
  1127.             num_to_delete += 2;
  1128.         else
  1129.             num_to_delete++;
  1130.  
  1131.     if (delete_a_char) {
  1132.         if (enter_delete_mode)
  1133.             tputs(enter_delete_mode, ONE_LINE, append_to_output_string);
  1134.  
  1135.         for (count = num_to_delete; count; --count)
  1136.             tputs(delete_a_char, ONE_LINE, append_to_output_string);
  1137.  
  1138.         if (enter_delete_mode)
  1139.             tputs(exit_delete_mode, ONE_LINE, append_to_output_string);
  1140.     } else {
  1141.         num_to_back_up = display_string_into_output_string(new_dot);
  1142.         for (count = num_to_delete; count; --count)
  1143.             output_string[output_string_length++] = ' ';
  1144.         for (count = num_to_back_up + num_to_delete; count; --count)
  1145.             tputs(cursor_left, ONE_LINE, append_to_output_string);
  1146.     }
  1147.  
  1148.     if (e->universal_argument > strlen(e->dot))
  1149.         output_string[output_string_length++] = '\07';
  1150.  
  1151.     strcpy(temp_str, new_dot);
  1152.     strcpy(e->dot, temp_str);
  1153.     e->universal_argument = 1;
  1154.     if (e->mark >= new_dot)
  1155.         e->mark += (old_dot - new_dot);
  1156.     write(1, output_string, output_string_length);
  1157.  
  1158.     return OK;
  1159. }
  1160.  
  1161.  
  1162. int 
  1163. finish_editing_line(e)
  1164.     ED_STRUCT      *e;
  1165. {
  1166.  
  1167.     char           *old_dot;
  1168.  
  1169.     e->universal_argument = 1;
  1170.     old_dot = e->dot;
  1171.     beginning_of_line(e);
  1172.     e->dot = old_dot;    /* necessary to preserve cursor position
  1173.                  * accross newlines                      */
  1174.     return FINISHED_EDITING;
  1175. }
  1176.  
  1177.  
  1178. int 
  1179. self_insert(e)
  1180.     ED_STRUCT      *e;
  1181. {
  1182.  
  1183.     int             num_to_back_up, count;
  1184.     char           *old_dot = e->dot;    /* JJD 3-89 added */
  1185.  
  1186.     strcpy(output_string, "");
  1187.     output_string_length = 0;
  1188.  
  1189.     if (*(e->dot) == '\0') {
  1190.         for (count = e->universal_argument; count; --count)
  1191.             display_char_into_output_string(e->current_input_char);
  1192.     } else {
  1193.         if (enter_insert_mode || pre_insert_char) {
  1194.             if (enter_insert_mode)
  1195.                 tputs(enter_insert_mode, ONE_LINE, append_to_output_string);
  1196.  
  1197.             for (count = e->universal_argument; count; --count) {
  1198.                 if (pre_insert_char)
  1199.                     tputs(pre_insert_char, ONE_LINE, append_to_output_string);
  1200.                 if ((e->current_input_char < 32)) {
  1201.                     output_string[output_string_length++] = '^';
  1202.                     if (post_insert_char)
  1203.                         tputs(post_insert_char, ONE_LINE,
  1204.                            append_to_output_string);
  1205.                     if (pre_insert_char)
  1206.                         tputs(pre_insert_char, ONE_LINE,
  1207.                            append_to_output_string);
  1208.                     output_string[output_string_length++] =
  1209.                         e->current_input_char + '@';
  1210.                 } else if (e->current_input_char == 127) {
  1211.                     output_string[output_string_length++] = '^';
  1212.                     if (post_insert_char)
  1213.                         tputs(post_insert_char, ONE_LINE,
  1214.                            append_to_output_string);
  1215.                     if (pre_insert_char)
  1216.                         tputs(pre_insert_char, ONE_LINE,
  1217.                            append_to_output_string);
  1218.                     output_string[output_string_length++] = '?';
  1219.                 } else
  1220.                     output_string[output_string_length++] =
  1221.                         e->current_input_char;
  1222.  
  1223.                 if (post_insert_char)
  1224.                     tputs(post_insert_char, ONE_LINE, append_to_output_string);
  1225.             }
  1226.  
  1227.             if (enter_insert_mode)
  1228.                 tputs(exit_insert_mode, ONE_LINE, append_to_output_string);
  1229.         } else {
  1230.             for (count = e->universal_argument; count; --count)
  1231.                 display_char_into_output_string(e->current_input_char);
  1232.             num_to_back_up =
  1233.                 display_string_into_output_string(e->dot);
  1234.             for (count = num_to_back_up; count; --count)
  1235.                 tputs(cursor_left, ONE_LINE, append_to_output_string);
  1236.         }
  1237.     }
  1238.  
  1239.     strcpy(temp_str, e->dot);
  1240.     for (count = e->universal_argument; count; --count)
  1241.         *(e->dot++) = e->current_input_char;
  1242.     strcpy(e->dot, temp_str);
  1243.     if (e->mark > old_dot)
  1244.         e->mark += (e->dot - old_dot);
  1245.     write(1, output_string, output_string_length);
  1246.  
  1247.     e->universal_argument = 1;
  1248.     return OK;
  1249. }
  1250.  
  1251.  
  1252. run_program_connected_to_standard_tty(cmd)
  1253.     char           *cmd;
  1254. {
  1255.  
  1256.     int             status;
  1257.     void        (*sig)();
  1258.  
  1259.     ioctl(0, TIOCGETP, &new_stdin);
  1260.     ioctl(0, TIOCSETP, &old_stdin);
  1261.     printf("Now running \"%s\"\r\n", cmd);
  1262.     sig=signal(SIGCHLD,SIG_DFL); 
  1263.     status = system(cmd);
  1264.     signal(SIGCHLD,sig); 
  1265.     printf("Finished running \"%s\"\r\n", cmd);
  1266.     ioctl(0, TIOCSETP, &new_stdin);
  1267.     write(1, "Continue: ", 10);
  1268.     return status;
  1269. }
  1270.  
  1271.  
  1272. quietly_run_program_connected_to_standard_tty(cmd)
  1273.     char           *cmd;
  1274. {
  1275.  
  1276.     int             status;
  1277.     void        (*sig)();
  1278.     
  1279.     ioctl(0, TIOCGETP, &new_stdin);
  1280.     ioctl(0, TIOCSETP, &old_stdin);
  1281.     sig=signal(SIGCHLD,SIG_DFL); 
  1282.     status = system(cmd);
  1283.     signal(SIGCHLD,sig); 
  1284.     ioctl(0, TIOCSETP, &new_stdin);
  1285.     return status;
  1286. }
  1287.  
  1288.  
  1289.  
  1290. int 
  1291. uppercase_word(e)
  1292.     ED_STRUCT      *e;
  1293. {
  1294.  
  1295.     char           *ch, *cb;
  1296.  
  1297.     cb = e->current_buffer;
  1298.     ch = e->dot;
  1299.  
  1300.     if (ch != cb)        /* not at beginning of buffer */
  1301.         while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1302.             ch--;    /* search backwards until in a word */
  1303.  
  1304.     while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1305.         ch--;        /* find first letter in word */
  1306.  
  1307.     while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1308.         if ((*ch >= 'a') && (*ch <= 'z'))
  1309.             *ch -= 32;    /* uppercase all lowers */
  1310.  
  1311.     erase_current_edit_line(e);
  1312.     draw_current_edit_line(e);
  1313.     return OK;
  1314. }
  1315.  
  1316. int 
  1317. lowercase_word(e)
  1318.     ED_STRUCT      *e;
  1319. {
  1320.  
  1321.     char           *ch, *cb;
  1322.  
  1323.     cb = e->current_buffer;
  1324.     ch = e->dot;
  1325.  
  1326.     if (ch != cb)        /* not at beginning of buffer */
  1327.         while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1328.             ch--;    /* search backwards until in a word */
  1329.  
  1330.     while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1331.         ch--;        /* find first letter in word */
  1332.  
  1333.     while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1334.         if ((*ch >= 'A') && (*ch <= 'Z'))
  1335.             *ch += 32;    /* lowercase all uppers */
  1336.  
  1337.     erase_current_edit_line(e);
  1338.     draw_current_edit_line(e);
  1339.     return OK;
  1340. }
  1341.  
  1342.  
  1343. int 
  1344. capitalize_word(e)
  1345.     ED_STRUCT      *e;
  1346. {
  1347.  
  1348.     char           *ch, *cb;
  1349.     int             subword_flag = 0;
  1350.  
  1351.     cb = e->current_buffer;
  1352.     ch = e->dot;
  1353.  
  1354.     if (ch != cb)        /* not at beginning of buffer */
  1355.         while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1356.             ch--;    /* search backwards until in a word */
  1357.  
  1358.     while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1359.         ch--;        /* find first letter in word */
  1360.  
  1361.     if ((*++ch >= 'a') && (*ch <= 'z'))
  1362.         *ch -= 32;    /* uppercase first letter */
  1363.  
  1364.     while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1365.         if (!isalnum(*ch))
  1366.             subword_flag = 1;    /* next char starts subword */
  1367.         else if (subword_flag) {
  1368.             subword_flag = 0;
  1369.             if ((*ch >= 'a') && (*ch <= 'z'))
  1370.                 *ch -= 32;    /* uppercase first letter */
  1371.         } else if ((*ch >= 'A') && (*ch <= 'Z'))
  1372.             *ch += 32;    /* lowercase subsequent letters */
  1373.  
  1374.     erase_current_edit_line(e);
  1375.     draw_current_edit_line(e);
  1376.     return OK;
  1377. }
  1378.  
  1379. int 
  1380. ul_to_dash_word(e)
  1381.     ED_STRUCT      *e;
  1382. {
  1383.  
  1384.     char           *ch, *cb;
  1385.  
  1386.     cb = e->current_buffer;
  1387.     ch = e->dot;
  1388.  
  1389.     if (ch != cb)        /* not at beginning of buffer */
  1390.         while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1391.             ch--;    /* search backwards until in a word */
  1392.  
  1393.     while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1394.         ch--;        /* find first letter in word */
  1395.  
  1396.     while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1397.         if (*ch == '_')    /* replace underscores with hyphens */
  1398.             *ch = '-';
  1399.  
  1400.     erase_current_edit_line(e);
  1401.     draw_current_edit_line(e);
  1402.     return OK;
  1403. }
  1404.  
  1405. int 
  1406. dash_to_ul_word(e)
  1407.     ED_STRUCT      *e;
  1408. {
  1409.  
  1410.     char           *ch, *cb;
  1411.  
  1412.     cb = e->current_buffer;
  1413.     ch = e->dot;
  1414.  
  1415.     if (ch != cb)        /* not at beginning of buffer */
  1416.         while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1417.             ch--;    /* search backwards until in a word */
  1418.  
  1419.     while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1420.         ch--;        /* find first letter in word */
  1421.  
  1422.     while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1423.         if (*ch == '-')    /* replace hyphens with underscores */
  1424.             *ch = '_';
  1425.  
  1426.     erase_current_edit_line(e);
  1427.     draw_current_edit_line(e);
  1428.     return OK;
  1429. }
  1430.  
  1431.  
  1432. /*
  1433. int 
  1434. describe_bindings(e)
  1435.     ED_STRUCT      *e;
  1436. {
  1437.  
  1438.     char            cmd[256];
  1439.  
  1440.     erase_current_edit_line(e);
  1441.     write(1, "One moment. . .", 15);
  1442.     strcpy(cmd, "/usr/ucb/more ");
  1443.     strcat(cmd, getenv("HOME"));
  1444.     strcat(cmd, ".rk.key_map");
  1445.     quietly_run_program_connected_to_standard_tty(cmd);
  1446.     write(1, "Continue: ", 10);
  1447.     draw_current_edit_line(e);
  1448.     return OK;
  1449. }
  1450. */
  1451.  
  1452.         
  1453.  
  1454. run_tty_program(e)
  1455.     ED_STRUCT      *e;
  1456. {
  1457.  
  1458.     char            cmd[512];
  1459.  
  1460.     erase_current_edit_line(e);
  1461.     e->dot = e->current_buffer;
  1462.     e->mark = e->current_buffer;
  1463.     *(e->dot) = '\0';
  1464.  
  1465.     ioctl(0, TIOCGETP, &new_stdin);
  1466.     ioctl(0, TIOCSETP, &old_stdin);
  1467.     strcpy(cmd, "");
  1468.     printf("Command to run ([RETURN] to cancel): ");
  1469.     fflush(stdout);
  1470.     gets(cmd);
  1471.     if (cmd[0] == '\0') {
  1472.         printf("Command cancelled.\r\n");
  1473.         ioctl(0, TIOCSETP, &new_stdin);
  1474.     } else {
  1475.         ioctl(0, TIOCSETP, &new_stdin);
  1476.         run_program_connected_to_standard_tty(cmd);
  1477.     }
  1478.  
  1479.     return OK;
  1480. }
  1481.  
  1482. run_talk(e)
  1483.     ED_STRUCT      *e;
  1484. {
  1485.  
  1486.     char            cmd[256], *who_to;
  1487.  
  1488.     erase_current_edit_line(e);
  1489.     e->dot = e->current_buffer;
  1490.     e->mark = e->current_buffer;
  1491.     *(e->dot) = '\0';
  1492.  
  1493.     ioctl(0, TIOCGETP, &new_stdin);
  1494.     ioctl(0, TIOCSETP, &old_stdin);
  1495.     strcpy(cmd, "talk ");
  1496.     who_to = &cmd[5];
  1497.     printf("Talk to whom ([RETURN] to cancel): ");
  1498.     fflush(stdout);
  1499.     gets(who_to);
  1500.     if (who_to[0] == '\0') {
  1501.         printf("Talk cancelled.\r\n");
  1502.         ioctl(0, TIOCSETP, &new_stdin);
  1503.     } else {
  1504.         ioctl(0, TIOCSETP, &new_stdin);
  1505.         run_program_connected_to_standard_tty(cmd);
  1506.     }
  1507.  
  1508.     return OK;
  1509. }
  1510.  
  1511. run_write(e)
  1512.     ED_STRUCT      *e;
  1513. {
  1514.  
  1515.     char            cmd[256], *who_to;
  1516.  
  1517.     erase_current_edit_line(e);
  1518.     e->dot = e->current_buffer;
  1519.     e->mark = e->current_buffer;
  1520.     *(e->dot) = '\0';
  1521.  
  1522.     ioctl(0, TIOCGETP, &new_stdin);
  1523.     ioctl(0, TIOCSETP, &old_stdin);
  1524.     strcpy(cmd, "write ");
  1525.     who_to = &cmd[6];
  1526.     printf("write to whom ([RETURN] to cancel): ");
  1527.     fflush(stdout);
  1528.     gets(who_to);
  1529.     if (who_to[0] == '\0') {
  1530.         printf("Write cancelled.\r\n");
  1531.         ioctl(0, TIOCSETP, &new_stdin);
  1532.     } else {
  1533.         ioctl(0, TIOCSETP, &new_stdin);
  1534.         run_program_connected_to_standard_tty(cmd);
  1535.     }
  1536.  
  1537.     return OK;
  1538. }
  1539.  
  1540. run_pp(e)
  1541.     ED_STRUCT      *e;
  1542. {                /* JJD 9-86 */
  1543.  
  1544.     char            cmd[256], *who_to;
  1545.  
  1546.     erase_current_edit_line(e);
  1547.     e->dot = e->current_buffer;
  1548.     e->mark = e->current_buffer;
  1549.     *(e->dot) = '\0';
  1550.  
  1551.     ioctl(0, TIOCGETP, &new_stdin);
  1552.     ioctl(0, TIOCSETP, &old_stdin);
  1553.     strcpy(cmd, "pp ");
  1554.     who_to = &cmd[3];
  1555.     printf("pp what file ([RETURN] to cancel): ");
  1556.     fflush(stdout);
  1557.     gets(who_to);
  1558.     if (who_to[0] == '\0') {
  1559.         printf("pp cancelled.\r\n");
  1560.         ioctl(0, TIOCSETP, &new_stdin);
  1561.     } else {
  1562.         ioctl(0, TIOCSETP, &new_stdin);
  1563.         run_program_connected_to_standard_tty(cmd);
  1564.     }
  1565.  
  1566.     return OK;
  1567. }
  1568.  
  1569. run_mesg(e)
  1570.     ED_STRUCT      *e;
  1571. {
  1572.  
  1573.     char            cmd[256], *on_or_off;
  1574.  
  1575.     erase_current_edit_line(e);
  1576.     e->dot = e->current_buffer;
  1577.     e->mark = e->current_buffer;
  1578.     *(e->dot) = '\0';
  1579.  
  1580.     ioctl(0, TIOCGETP, &new_stdin);
  1581.     ioctl(0, TIOCSETP, &old_stdin);
  1582.     strcpy(cmd, "mesg ");
  1583.     on_or_off = &cmd[5];
  1584.     printf("Do you want \"mesg y\" or \"mesg n\" ");
  1585.     printf("(type y or n and press [RETURN]): ");
  1586.     fflush(stdout);
  1587.     gets(on_or_off);
  1588.     if (!strncmp(on_or_off, "on", 2))
  1589.         strcpy(on_or_off, "y");
  1590.     else if (!strncmp(on_or_off, "off", 3))
  1591.         strcpy(on_or_off, "n");
  1592.     else if (*on_or_off == 'y' || *on_or_off == 'n')
  1593.         on_or_off[1] = '\0';
  1594.     else if (on_or_off[0] == '\0') {
  1595.         printf("Mesg cancelled.\r\n");
  1596.         ioctl(0, TIOCSETP, &new_stdin);
  1597.         return OK;
  1598.     } else {
  1599.         printf("Mesg cancelled because you didn't respond with y or n.\r\n");
  1600.         ioctl(0, TIOCSETP, &new_stdin);
  1601.         return OK;
  1602.     }
  1603.  
  1604.     ioctl(0, TIOCSETP, &new_stdin);
  1605.     run_program_connected_to_standard_tty(cmd);
  1606.     return OK;
  1607. }
  1608.  
  1609. int describe_arguments(e)
  1610.     ED_STRUCT      *e;
  1611. {
  1612.     extern num_buffers;
  1613.     extern  char silent;
  1614.     extern  char login;
  1615.     extern    max_len;
  1616.     extern    max_eol;
  1617.     extern char *zero_freq_file;
  1618.     extern char *prime_file;
  1619.     extern char *key_file;
  1620.  
  1621.  
  1622.     printf("\r\nCurrent Command Line Argument Values:\r\n");
  1623.     printf("    -b (Number of buffers)  = %d\r\n", num_buffers);
  1624.     printf("    -e (End of Line length)    = %d\r\n",max_eol);
  1625.     printf("    -f (Maximum Frequency)    = %d\r\n",max_freq);
  1626.     printf("    -i (Inline Length)    = %d\r\n",max_len);
  1627.     printf("    -k (Key Bindings File)    = \"%s\"\r\n",key_file);
  1628.     printf("    -n (Nodes to allocate)    = %d\r\n",max_nodes);
  1629.     printf("    -o (Order of model)    = %d\r\n",maxk);
  1630.     printf("    -p (Prime File)        = \"%s\"\r\n",prime_file);
  1631.     printf("    -s (Maximum to prime)    = %d\r\n",maxprime);
  1632.     printf("    -z (Zero Frequency File)= \"%s\"\r\n",zero_freq_file);
  1633.     printf("    -A (add_space_mode)    = %s\r\n",add_space_mode?"TRUE":"FALSE");
  1634.     printf("    -E (eol_only_mode)    = %s\r\n",eol_only_mode?"TRUE":"FALSE");
  1635.     printf("    -L (eol_longer_mode)    = %s\r\n",eol_longer_mode?"TRUE":"FALSE");
  1636.     printf("    -N (nl_truncate_mode)    = %s\r\n",nl_truncate_mode?"TRUE":"FALSE");
  1637.     printf("    -P (pred_mode)        = %s\r\n",pred_mode?"TRUE":"FALSE");
  1638.     printf("    -S (show_eol_mode)    = %s\r\n",show_eol_mode?"TRUE":"FALSE");
  1639.     printf("    -g (login shell)    = %s\r\n",login?"TRUE":"FALSE");
  1640.     printf("    -l (lisp_mode)        = %s\r\n",lisp_mode?"TRUE":"FALSE");
  1641.     printf("    -m (silent startup)    = %s\r\n",silent?"TRUE":"FALSE");
  1642.     write(1, "Continue: ", 10);
  1643.     draw_current_edit_line(e);
  1644.     return OK;
  1645. }
  1646.