home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume24 / mced / part01 / vi_edit.c < prev   
C/C++ Source or Header  |  1991-10-26  |  15KB  |  741 lines

  1. /*
  2.  * This software is Copyright (c) 1991 by Andy Knight
  3.  *
  4.  * Permission is hereby granted to copy, distribute or otherwise
  5.  * use any part of this package as long as you do not try to make
  6.  * money from it or pretend that you wrote it.  This copyright
  7.  * notice must be maintained in any copy made.
  8.  *
  9.  * Use of this software constitutes acceptance for use in an AS IS
  10.  * condition. There are NO warranties with regard to this software.
  11.  * In no event shall the author be liable for any damages whatsoever
  12.  * arising out of or in connection with the use or performance of this
  13.  * software.  Any use of this software is at the user's own risk.
  14.  *
  15.  * If you make modifications to this software that you feel
  16.  * increases it usefulness for the rest of the community, please
  17.  * email the changes, enhancements, bug fixes as well as any and
  18.  * all ideas to me. This software is going to be maintained and
  19.  * enhanced as deemed necessary by the community.
  20.  * 
  21.  * " ... Freely you have recieved, freely give"  <Matthew 10:8> 
  22.  *
  23.  *        Andy Knight
  24.  *        aknight@ourgang.prime.com
  25.  */
  26.  
  27. #include "config.h"
  28.  
  29.  
  30. extern char    *hist[], cstr[];
  31. extern int      xbeg, cur_cmd, last_hline, pwolfe_getch();
  32. extern int      edit_mode, x_pos, savex_pos, xend;
  33.  
  34. extern void     my_wmove(), add_hline(), cmd_to_win(), win_to_cmd();
  35. extern void     my_winsch(), my_waddstr(), case_upper();
  36. extern void     my_wdelch(), case_lower(), eat_white();
  37. extern SIGTYPE  die_curses(), die_normal();
  38. extern WINDOW  *win;
  39.  
  40. #ifdef SYSVcurses
  41. extern struct termio tio, tin;
  42. #else
  43. extern struct tchars tco, tcn;
  44. #endif
  45.  
  46.  
  47. edit_cmd()
  48. {
  49.     int             stop_it, p_init, xins_strt, edch, i, j, tmp_cmd;
  50.     int             dot_mode, dot_iterations, n_iterations, n_times, indx;
  51.     char            tch, dot_cmd;
  52.     char            save_ins[MAX_W_SAVED + 1], save_del[MAX_W_SAVED + 1];
  53.     fprintf(stdout, "\n");
  54.     if (initscr() == ERR)
  55.     {
  56.     fprintf(stderr, "Curses won't initialize - help!\n");
  57.     die_normal();
  58.     }
  59.     signal(SIGINT, die_curses);    /* die cleanly */
  60.     CBREAKF();
  61.     noecho();
  62. #ifdef SYSVcurses
  63.     win = newwin(2, COLS, 0, 0);
  64. #else
  65.     clearok(curscr, FALSE);    /* SYSV curses clears it anyway ;-( */
  66.     win = newwin(2, COLS, LINES - 2, 0);
  67. #endif
  68.  
  69.     cmd_to_win();
  70.     my_wmove(--x_pos);
  71.     wrefresh(win);
  72.     savex_pos = x_pos;
  73.  
  74. #ifdef SYSVcurses        /* disable STOP/START (CTRL-S) */
  75.     if (ioctl(0, TCGETA, &tio) != 0)
  76.     perror("ioctl");
  77.     tin = tio;
  78.     tin.c_iflag &= ~IXON;
  79.     if (ioctl(0, TCSETA, &tin) != 0)
  80.     perror("ioctl");
  81. #else
  82.     if (ioctl(0, TIOCGETC, &tco) != 0)
  83.     perror("ioctl");
  84.     tcn = tco;
  85.     tcn.t_stopc = -1;
  86.     if (ioctl(0, TIOCSETC, &tcn) != 0)
  87.     perror("ioctl");
  88. #endif
  89.     edit_mode = VI_NINS_MODE;
  90.     dot_iterations = 1;
  91.     dot_cmd = NO;
  92.     n_times = indx = 0;
  93.     p_init = NO;
  94.     for (; (edch = pwolfe_getch(win)) != '\n';)
  95.     {
  96.     if ((edch == 'u' || edch == 'U') && edit_mode == VI_NINS_MODE)
  97.     {
  98.         cmd_to_win();
  99.         x_pos = savex_pos;
  100.         my_wmove(x_pos);
  101.         wrefresh(win);
  102.         continue;
  103.     }
  104.     if (edit_mode == VI_NINS_MODE && (edch == 'a' || edch == 'A'
  105.          || edch == 'i' || edch == 'I' || edch == 'p' || edch == 'P'
  106.          || edch == '.' || edch == 'x' || edch == 'd' || edch == 'D'
  107.          || edch == 'c' || edch == 'C' || edch == 'r' || edch == 'R'
  108.          || edch == '\~' || edch == 'X' || edch == ControlW 
  109.          || edch == Sun_R1))
  110.     {
  111.         savex_pos = x_pos;
  112.         win_to_cmd();    /* for undo function */
  113.         my_wmove(x_pos);
  114.     }
  115.     if (edit_mode == VI_NINS_MODE)
  116.     {
  117.         if (edch == 'c')
  118.         {
  119.         indx = 0;
  120.         xins_strt = x_pos;
  121.         edit_mode = VI_c_MODE;
  122.         continue;
  123.         }
  124.         else if (edch == 'd')
  125.         {
  126.         edit_mode = VI_d_MODE;
  127.         continue;
  128.         }
  129.         else if (edch == 'r')
  130.         {
  131.         edit_mode = VI_r_MODE;
  132.         continue;
  133.         }
  134.         else if (edch == 'R')
  135.         {
  136.         indx = 0;
  137.         xins_strt = x_pos;
  138.         dot_mode = VI_NINS_MODE;
  139.         dot_cmd = 'R';
  140.         edit_mode = VI_R_MODE;
  141.         continue;
  142.         }
  143.     }
  144.  
  145.     if (isdigit(edch) && edit_mode == VI_NINS_MODE)
  146.     {
  147.         if (n_times != 0)
  148.         n_times *= 10;
  149.         n_times += edch - '0';
  150.         continue;
  151.     }
  152.  
  153.     if (n_times != 0)
  154.     {
  155.         n_iterations = n_times;
  156.         n_times = 0;
  157.     }
  158.     else
  159.         n_iterations = 1;
  160.  
  161.     if (edch == '\.' && edit_mode == VI_NINS_MODE)
  162.     {
  163.         if (dot_cmd != NO)
  164.         {
  165.         edch = dot_cmd;
  166.         edit_mode = dot_mode;
  167.         n_iterations = dot_iterations;
  168.         if (edch == 'i' || edch == 'a')
  169.         {
  170.             if (edch == 'a')
  171.             my_wmove(++x_pos);
  172.             my_waddstr(save_ins);
  173.             my_wmove(--x_pos);
  174.             n_iterations = 0;
  175.         }
  176.         else if (edch == 'R')
  177.         {
  178.             for (i = 0; i < indx && x_pos >= xbeg && x_pos < xend; i++)
  179.             my_wdelch();
  180.             my_waddstr(save_ins);
  181.             my_wmove(--x_pos);
  182.             n_iterations = 0;
  183.         }
  184.         else if (edit_mode == VI_c_MODE)
  185.         {
  186.             my_waddstr(save_ins);
  187.             n_iterations = 1;
  188.             edit_mode = VI_c_MODE;
  189.             dot_mode = NO_BEG_INS;
  190.         }
  191.         }
  192.         else
  193.         beep();
  194.     }
  195.  
  196.     if (edit_mode == VI_INS_MODE)
  197.     {
  198.         if (edch == ControlU)
  199.         {
  200.         wclear(win);
  201.         wrefresh(win);
  202.         die_curses();
  203.         }
  204.         else if (edch == Escape)
  205.         {
  206.         edit_mode = VI_NINS_MODE;
  207.         if (x_pos > xbeg)
  208.             my_wmove(--x_pos);
  209.         }
  210.         else if (edch == ControlW || edch == Sun_R1)
  211.         {
  212.         if (x_pos > xbeg)
  213.         {
  214.             my_wmove(--x_pos);
  215.             eat_white(-1, YES);
  216.             for (; !(isspace(winch(win))) && (x_pos >= xins_strt);)
  217.             {
  218.             my_wdelch();
  219.             if (x_pos == xbeg)
  220.                 break;
  221.             else
  222.                 my_wmove(--x_pos);
  223.             }
  224.             if (x_pos > xbeg && x_pos < xend - 1)
  225.             my_wmove(++x_pos);
  226.         }
  227.         else
  228.             beep();
  229.         }
  230.         else if (edch == Delete)
  231.         {
  232.         if (x_pos > xbeg && x_pos > xins_strt)
  233.         {
  234.             my_wmove(--x_pos);
  235.             my_wdelch();
  236.         }
  237.         else
  238.             beep();
  239.         }
  240.         else if (isprint(edch))
  241.         {
  242.         my_winsch(edch);
  243.         if (indx < MAX_W_SAVED)
  244.         {
  245.             save_ins[indx] = edch;
  246.             save_ins[++indx] = '\0';
  247.         }
  248.         }
  249.         else
  250.         beep();
  251.     }
  252.     else if (edit_mode == VI_R_MODE)
  253.     {
  254.         if (edch == Escape)
  255.         {
  256.         if (x_pos > xbeg)
  257.             my_wmove(--x_pos);
  258.         if (x_pos > xend - 1)
  259.             xend = x_pos + 1;
  260.         edit_mode = VI_NINS_MODE;
  261.         }
  262.         else if (edch == ControlU)
  263.         {
  264.         wclear(win);
  265.         wrefresh(win);
  266.         die_curses();
  267.         }
  268.         else if (edch == Delete)
  269.         {
  270.         if (x_pos > xbeg && x_pos > xins_strt)
  271.         {
  272.             my_winsch(' ');
  273.             x_pos -= 2;
  274.             my_wmove(x_pos);
  275.             my_wdelch();
  276.             save_ins[--indx] = ' ';
  277.         }
  278.         else
  279.             beep();
  280.         }
  281.         else if (isprint(edch))
  282.         {
  283.         my_wdelch();
  284.         my_winsch(edch);
  285.         if (indx < MAX_W_SAVED)
  286.         {
  287.             save_ins[indx] = edch;
  288.             save_ins[++indx] = '\0';
  289.         }
  290.         }
  291.         else
  292.         beep();
  293.     }
  294.     else
  295.     {
  296.         stop_it = NO;
  297.         for (j = 0; j < n_iterations && edch != Escape; j++)
  298.         {
  299.         if (edit_mode == VI_d_MODE || edit_mode == VI_c_MODE)
  300.         {
  301.             if (edch == 'w' || edch == 'W')    /* delete or change word */
  302.             {
  303.             if (x_pos < xend)
  304.             {
  305.                 if (!(isalnum(winch(win))) && winch(win) != '_'
  306.                 && edch == 'w')
  307.                 {
  308.                 if (x_pos < xend)
  309.                 {
  310.                     p_init = YES;
  311.                     if (MAX_W_SAVED > 1)
  312.                     {
  313.                     save_del[0] = winch(win);
  314.                     save_del[1] = '\0';
  315.                     }
  316.                     my_wdelch();
  317.                     i = 1;
  318.                 }
  319.                 }
  320.                 else
  321.                 {
  322.                 for (i = 0; (( edch == 'w' && (isalnum(winch(win))) 
  323.                     || edch == 'W') 
  324.                     && !(isspace(winch(win))) 
  325.                     || winch(win) == '_') 
  326.                     && (x_pos < xend);)
  327.                 {
  328.                     if (i < MAX_W_SAVED)
  329.                     save_del[i] = winch(win);
  330.                     my_wdelch();
  331.                     ++i;
  332.                 }
  333.                 save_del[MIN(i, MAX_W_SAVED)] = '\0';
  334.                 p_init = YES;
  335.                 }
  336.                 if (winch(win) == ' ' && x_pos <= xend - 1
  337.                 && edit_mode != VI_c_MODE)
  338.                 {
  339.                 my_wdelch();
  340.                 if (i < MAX_W_SAVED)
  341.                 {
  342.                     save_del[i] = ' ';
  343.                     save_del[MIN((i + 1), MAX_W_SAVED)] = '\0';
  344.                 }
  345.                 }
  346.             }
  347.             else
  348.                 beep();
  349.             if (x_pos == xend && edit_mode != VI_c_MODE)
  350.                 my_wmove(--x_pos);
  351.             if (edit_mode == VI_d_MODE)
  352.             {
  353.                 dot_cmd = edch;
  354.                 dot_iterations = n_iterations;
  355.                 dot_mode = VI_d_MODE;
  356.             }
  357.             if (edit_mode == VI_c_MODE)
  358.             {
  359.                 if (dot_mode != NO_BEG_INS)
  360.                 edit_mode = VI_INS_MODE;
  361.                 else
  362.                 {
  363.                 edit_mode = VI_NINS_MODE;
  364.                 my_wmove(--x_pos);
  365.                 }
  366.                 dot_cmd = edch;
  367.                 dot_iterations = 1;
  368.                 dot_mode = VI_c_MODE;
  369.             }
  370.             else if (j >= n_iterations - 1)
  371.                 edit_mode = VI_NINS_MODE;
  372.             }
  373.             else if (edch == 'd' && edit_mode != VI_c_MODE)
  374.             {
  375.             wclear(win);
  376.             wrefresh(win);
  377.             die_curses();
  378.             break;
  379.             }
  380.             else
  381.             {
  382.             edit_mode = VI_NINS_MODE;
  383.             beep();
  384.             }
  385.  
  386.         }
  387.         else if (edit_mode == VI_r_MODE)
  388.         {
  389.             if (isprint(edch))
  390.             {
  391.             dot_mode = VI_r_MODE;
  392.             dot_cmd = edch;
  393.             my_wdelch();
  394.             my_winsch(edch);
  395.             my_wmove(--x_pos);
  396.             }
  397.             else
  398.             beep();
  399.             edit_mode = VI_NINS_MODE;
  400.         }
  401.         else
  402.         {
  403.             switch (edch)
  404.             {
  405.             case 'I':
  406.             dot_cmd = NO;
  407.             x_pos = xbeg;
  408.             xins_strt = x_pos;
  409.             my_wmove(x_pos);
  410.             edit_mode = VI_INS_MODE;
  411.             break;
  412.             case 'i':
  413.             indx = 0;
  414.             dot_cmd = 'i';
  415.             dot_iterations = 1;
  416.             dot_mode = VI_NINS_MODE;
  417.             xins_strt = x_pos;
  418.             edit_mode = VI_INS_MODE;
  419.             break;
  420.             case 'A':
  421.             dot_cmd = NO;
  422.             if (x_pos < xend)
  423.             {
  424.                 x_pos = xend;
  425.                 xins_strt = x_pos;
  426.                 my_wmove(x_pos);
  427.             }
  428.             edit_mode = VI_INS_MODE;
  429.             break;
  430.             case 'a':
  431.             indx = 0;
  432.             dot_cmd = 'a';
  433.             dot_iterations = 1;
  434.             dot_mode = VI_NINS_MODE;
  435.             if (x_pos < xend)
  436.                 my_wmove(++x_pos);
  437.             xins_strt = x_pos;
  438.             edit_mode = VI_INS_MODE;
  439.             break;
  440.             case ControlU:
  441.             case Sun_R3:
  442.             wclear(win);
  443.             wrefresh(win);
  444.             die_curses();
  445.             break;
  446.             case ControlW:    /* Delete backwards to next space */
  447.             case Sun_R1:
  448.             dot_cmd = ControlW;
  449.             dot_iterations = n_iterations;
  450.             dot_mode = VI_NINS_MODE;
  451.             if (x_pos > xbeg)
  452.             {
  453.                 if (x_pos != xend - 1)
  454.                 my_wmove(--x_pos);
  455.                 eat_white(-1, YES);
  456.                 for (; !(isspace(winch(win))) && (x_pos >= xbeg);)
  457.                 {
  458.                 my_wdelch();
  459.                 if (x_pos == xbeg)
  460.                     break;
  461.                 else
  462.                     my_wmove(--x_pos);
  463.                 }
  464.                 if (x_pos > xbeg && x_pos < xend - 1)
  465.                 my_wmove(++x_pos);
  466.             }
  467.             else
  468.                 beep();
  469.             break;
  470.             case 'b':    /* move back to beginning of previous word */
  471.             case 'B':
  472.             case Sun_R4:
  473.             if (x_pos > xbeg)
  474.             {
  475.                 my_wmove(--x_pos);
  476.                 eat_white(-1, NO);
  477.                 for (; !(isspace(winch(win))) && (x_pos > xbeg);)
  478.                 {
  479.                 my_wmove(--x_pos);
  480.                 }
  481.                 if (x_pos > xbeg)
  482.                 my_wmove(++x_pos);
  483.             }
  484.             else
  485.                 beep();
  486.             break;
  487.             case 'w':    /* move forward to beginning of next word */
  488.             case 'W':
  489.             case Sun_R6:
  490.             if (x_pos < xend - 1)
  491.             {
  492.                 eat_white(1, NO);
  493.                 for (; !(isspace(winch(win))) && (x_pos < xend - 1);)
  494.                 {
  495.                 my_wmove(++x_pos);
  496.                 }
  497.                 if (x_pos < xend - 1)
  498.                 my_wmove(++x_pos);
  499.             }
  500.             else
  501.                 beep();
  502.             break;
  503.             case ControlL:    /* redraw win */
  504.             savex_pos = x_pos;
  505.             win_to_cmd();
  506.             wclear(win);
  507.             wrefresh(win);
  508.             cmd_to_win();
  509.             x_pos = savex_pos;
  510.             my_wmove(x_pos);
  511.             break;
  512.             case BackSpace:
  513.             case KEY_LEFT:
  514.             case KEY_BACKSPACE:
  515.             case 'h':
  516.             case Sun_R10:
  517.             if (x_pos > xbeg)
  518.                 my_wmove(--x_pos);
  519.             else
  520.                 beep();
  521.             break;
  522.             case EscapeM:    /* move cursor to middle */
  523.             case Sun_R11:
  524.             x_pos = xbeg + (xend - xbeg) / 2;
  525.             my_wmove(x_pos);
  526.             break;
  527.             case KEY_RIGHT:
  528.             case 'l':
  529.             case ' ':
  530.             case Sun_R12:
  531.             if (x_pos < xend - 1)
  532.                 my_wmove(++x_pos);
  533.             else
  534.                 beep();
  535.             break;
  536.             case KEY_UP:    /* move upward in history list */
  537.             case 'k':
  538.             case Sun_R8:
  539.             if (cur_cmd > 0)
  540.             {
  541.                 --cur_cmd;
  542.                 strcpy(cstr, hist[cur_cmd]);
  543.                 wclear(win);
  544.                 cmd_to_win();
  545.                 my_wmove(--x_pos);
  546.             }
  547.             else
  548.                 beep();
  549.             break;
  550.             case KEY_DOWN:    /* move downward in history list */
  551.             case 'j':
  552.             case Sun_R14:
  553.             if (cur_cmd < last_hline)
  554.             {
  555.                 ++cur_cmd;
  556.                 strcpy(cstr, hist[cur_cmd]);
  557.                 wclear(win);
  558.                 cmd_to_win();
  559.                 my_wmove(--x_pos);
  560.             }
  561.             else
  562.                 beep();
  563.             break;
  564.             case 'n':    /* search history list backwards */
  565.             if ((tmp_cmd = index_cmd(cur_cmd - 1, -1)) != cur_cmd)
  566.             {
  567.                 cur_cmd = tmp_cmd;
  568.                 strcpy(cstr, hist[cur_cmd]);
  569.                 wclear(win);
  570.                 cmd_to_win();
  571.                 my_wmove(--x_pos);
  572.             }
  573.             else
  574.                 beep();
  575.             break;
  576.             case '\^':
  577.             case Sun_R7:
  578.             my_wmove(xbeg);
  579.             x_pos = xbeg;
  580.             break;
  581.             case '\$':
  582.             case Sun_R13:
  583.             case Sun_R9:
  584.             x_pos = xend - 1;
  585.             my_wmove(x_pos);
  586.             break;
  587.             case 'D':    /* delete to end of line */
  588.             if (x_pos < xend)
  589.             {
  590.                 p_init = YES;
  591.                 dot_cmd = NO;
  592.                 for (i = 0; (xend - x_pos) > 0; i++)
  593.                 {
  594.                 if (i < MAX_W_SAVED)
  595.                 {
  596.                     save_del[i] = winch(win);
  597.                     save_del[MIN((i + 1), MAX_W_SAVED)] = '\0';
  598.                 }
  599.                 my_wdelch();
  600.                 }
  601.                 if (x_pos == xend)
  602.                 my_wmove(--x_pos);
  603.             }
  604.             else
  605.                 beep();
  606.             break;
  607.             case 'C':    /* delete to end of line and insert */
  608.             if (x_pos < xend)
  609.             {
  610.                 dot_cmd = NO;
  611.                 xins_strt = x_pos;
  612.                 for (i = xend; i > x_pos; i--)
  613.                 {
  614.                 my_wdelch();
  615.                 }
  616.                 edit_mode = VI_INS_MODE;
  617.             }
  618.             else
  619.                 beep();
  620.             break;
  621.             case 'J':
  622.             x_pos = xend;
  623.             my_wmove(x_pos);
  624.             my_winsch(' ');
  625.             add_hline();
  626.             break;
  627.             case 'p':
  628.             case 'P':
  629.             if (p_init == YES)
  630.             {
  631.                 if (edch == 'p')
  632.                 my_wmove(++x_pos);
  633.                 my_waddstr(save_del);
  634.                 my_wmove(--x_pos);
  635.             }
  636.             else
  637.                 beep();
  638.             break;
  639.             case 'x':    /* delete current character */
  640.             dot_cmd = 'x';
  641.             dot_iterations = n_iterations;
  642.             dot_mode = VI_NINS_MODE;
  643.             p_init = YES;
  644.             if (j < MAX_W_SAVED)
  645.             {
  646.                 save_del[j] = winch(win);
  647.                 save_del[MIN((j + 1), MAX_W_SAVED)] = '\0';
  648.             }
  649.             if (x_pos == xend - 1 && stop_it == NO)
  650.             {
  651.                 if (j <= n_iterations - 1)
  652.                 stop_it = YES;
  653.                 my_wdelch();
  654.                 my_wmove(--x_pos);
  655.             }
  656.             else if (x_pos != xend - 1)
  657.             {
  658.                 if (x_pos >= xbeg)
  659.                 {
  660.                 my_wdelch();
  661.                 }
  662.                 else
  663.                 beep();
  664.             }
  665.             break;
  666.             case 'X':    /* delete character before cursor */
  667.             dot_cmd = 'X';
  668.             dot_iterations = n_iterations;
  669.             dot_mode = VI_NINS_MODE;
  670.             if (x_pos > xbeg)
  671.             {
  672.                 my_wmove(--x_pos);
  673.                 p_init = YES;
  674.                 if ((n_iterations - j - 1) < MAX_W_SAVED)
  675.                 {
  676.                 save_del[n_iterations - j - 1] = winch(win);
  677.                 save_del[MIN(n_iterations, MAX_W_SAVED)] = '\0';
  678.                 }
  679.                 my_wdelch();
  680.             }
  681.             else
  682.                 beep();
  683.             break;
  684.             case EscapeL:    /* lower case whole command */
  685.             case Sun_R2:
  686.             savex_pos = x_pos;
  687.             win_to_cmd();
  688.             case_lower();
  689.             cmd_to_win();
  690.             x_pos = savex_pos;
  691.             my_wmove(x_pos);
  692.             break;
  693.             case EscapeU:    /* upper case whole command */
  694.             savex_pos = x_pos;
  695.             win_to_cmd();
  696.             case_upper();
  697.             cmd_to_win();
  698.             x_pos = savex_pos;
  699.             my_wmove(x_pos);
  700.             break;
  701.             case '\~':    /* toggle case of current character */
  702.             case Sun_R5:
  703.             tch = winch(win);
  704.             if (isupper(tch))
  705.             {
  706.                 wdelch(win);
  707.                 winsch(win, tolower(tch));
  708.             }
  709.             else if (islower(tch))
  710.             {
  711.                 wdelch(win);
  712.                 winsch(win, toupper(tch));
  713.             }
  714.             if (x_pos < xend - 1)
  715.                 my_wmove(++x_pos);
  716.             break;
  717.             default:
  718.             beep();
  719.             break;
  720.             }
  721.         }
  722.         }
  723.     }
  724.     wrefresh(win);
  725.     if (xend <= xbeg)
  726.         die_curses();
  727.     }
  728.     win_to_cmd();
  729. #ifdef SYSVcurses        /* reset tty */
  730.     if (ioctl(0, TCSETA, &tio) != 0)
  731.     perror("ioctl");
  732. #else
  733.     if (ioctl(0, TIOCSETC, &tco) != 0)
  734.     perror("ioctl");
  735. #endif
  736.     NOCBREAKF();
  737.     echo();
  738.     endwin();
  739.     return;            /* finished, execute command */
  740. }
  741.