home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / window / cmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-18  |  6.1 KB  |  294 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Edward Wang at The University of California, Berkeley.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  */
  36.  
  37. #ifndef lint
  38. static char sccsid[] = "@(#)cmd.c    3.40 (Berkeley) 6/6/90";
  39. #endif /* not lint */
  40.  
  41. #include "defs.h"
  42. #include "char.h"
  43.  
  44. docmd()
  45. {
  46.     register char c;
  47.     register struct ww *w;
  48.     char out = 0;
  49.  
  50.     while (!out && !quit) {
  51.         if ((c = wwgetc()) < 0) {
  52.             if (terse)
  53.                 wwsetcursor(0, 0);
  54.             else {
  55.                 wwputs("Command: ", cmdwin);
  56.                 wwcurtowin(cmdwin);
  57.             }
  58.             do
  59.                 wwiomux();
  60.             while ((c = wwgetc()) < 0);
  61.         }
  62.         if (!terse)
  63.             wwputc('\n', cmdwin);
  64.         switch (c) {
  65.         default:
  66.             if (c != escapec)
  67.                 break;
  68.         case 'h': case 'j': case 'k': case 'l':
  69.         case ctrl('y'):
  70.         case ctrl('e'):
  71.         case ctrl('u'):
  72.         case ctrl('d'):
  73.         case ctrl('b'):
  74.         case ctrl('f'):
  75.         case ctrl('s'):
  76.         case ctrl('q'):
  77.         case ctrl('['):
  78.             if (selwin == 0) {
  79.                 error("No window.");
  80.                 continue;
  81.             }
  82.         }
  83.         switch (c) {
  84.         case '1': case '2': case '3': case '4': case '5':
  85.         case '6': case '7': case '8': case '9':
  86.             if ((w = window[c - '1']) == 0) {
  87.                 error("%c: No such window.", c);
  88.                 break;
  89.             }
  90.             setselwin(w);
  91.             if (checkproc(selwin) >= 0)
  92.                  out = 1;
  93.             break;
  94.         case '%':
  95.             if ((w = getwin()) != 0)
  96.                 setselwin(w);
  97.             break;
  98.         case ctrl('^'):
  99.             if (lastselwin != 0) {
  100.                 setselwin(lastselwin);
  101.                 if (checkproc(selwin) >= 0)
  102.                     out = 1;
  103.             } else
  104.                 error("No previous window.");
  105.             break;
  106.         case 'c':
  107.             if ((w = getwin()) != 0)
  108.                 closewin(w);
  109.             break;
  110.         case 'w':
  111.             c_window();
  112.             break;
  113.         case 'm':
  114.             if ((w = getwin()) != 0)
  115.                 c_move(w);
  116.             break;
  117.         case 'M':
  118.             if ((w = getwin()) != 0)
  119.                 movewin(w, w->ww_alt.t, w->ww_alt.l);
  120.             break;
  121.         case 's':
  122.             if ((w = getwin()) != 0)
  123.                 c_size(w);
  124.             break;
  125.         case 'S':
  126.             if ((w = getwin()) != 0)
  127.                 sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
  128.             break;
  129.         case ':':
  130.             c_colon();
  131.             break;
  132.         case 'h':
  133.             (void) wwwrite(selwin, "\b", 1);
  134.             break;
  135.         case 'j':
  136.             (void) wwwrite(selwin, "\n", 1);
  137.             break;
  138.         case 'k':
  139.             (void) wwwrite(selwin, "\033A", 2);
  140.             break;
  141.         case 'l':
  142.             (void) wwwrite(selwin, "\033C", 2);
  143.             break;
  144.         case ctrl('e'):
  145.             wwscroll(selwin, 1);
  146.             break;
  147.         case ctrl('y'):
  148.             wwscroll(selwin, -1);
  149.             break;
  150.         case ctrl('d'):
  151.             wwscroll(selwin, selwin->ww_w.nr / 2);
  152.             break;
  153.         case ctrl('u'):
  154.             wwscroll(selwin, - selwin->ww_w.nr / 2);
  155.             break;
  156.         case ctrl('f'):
  157.             wwscroll(selwin, selwin->ww_w.nr);
  158.             break;
  159.         case ctrl('b'):
  160.             wwscroll(selwin, - selwin->ww_w.nr);
  161.             break;
  162.         case ctrl('s'):
  163.             stopwin(selwin);
  164.             break;
  165.         case ctrl('q'):
  166.             startwin(selwin);
  167.             break;
  168.         case ctrl('l'):
  169.             wwredraw();
  170.             break;
  171.         case '?':
  172.             c_help();
  173.             break;
  174.         case ctrl('['):
  175.             if (checkproc(selwin) >= 0)
  176.                 out = 1;
  177.             break;
  178.         case ctrl('z'):
  179.             wwsuspend();
  180.             break;
  181.         case 'q':
  182.             c_quit();
  183.             break;
  184.         /* debugging stuff */
  185.         case '&':
  186.             if (debug) {
  187.                 c_debug();
  188.                 break;
  189.             }
  190.         default:
  191.             if (c == escapec) {
  192.                 if (checkproc(selwin) >= 0) {
  193.                     (void) write(selwin->ww_pty,
  194.                         &escapec, 1);
  195.                     out = 1;
  196.                 }
  197.             } else {
  198.                 if (!terse)
  199.                     wwbell();
  200.                 error("Type ? for help.");
  201.             }
  202.         }
  203.     }
  204.     if (!quit)
  205.         setcmd(0);
  206. }
  207.  
  208. struct ww *
  209. getwin()
  210. {
  211.     register int c;
  212.     struct ww *w = 0;
  213.  
  214.     if (!terse)
  215.         wwputs("Which window? ", cmdwin);
  216.     wwcurtowin(cmdwin);
  217.     while ((c = wwgetc()) < 0)
  218.         wwiomux();
  219.     if (debug && c == 'c')
  220.         w = cmdwin;
  221.     else if (debug && c == 'f')
  222.         w = framewin;
  223.     else if (debug && c == 'b')
  224.         w = boxwin;
  225.     else if (c >= '1' && c < NWINDOW + '1')
  226.         w = window[c - '1'];
  227.     else if (c == '+')
  228.         w = selwin;
  229.     else if (c == '-')
  230.         w = lastselwin;
  231.     if (w == 0)
  232.         wwbell();
  233.     if (!terse)
  234.         wwputc('\n', cmdwin);
  235.     return w;
  236. }
  237.  
  238. checkproc(w)
  239. struct ww *w;
  240. {
  241.     if (w->ww_state != WWS_HASPROC) {
  242.         error("No process in window.");
  243.         return -1;
  244.     }
  245.     return 0;
  246. }
  247.  
  248. setcmd(new)
  249. char new;
  250. {
  251.     if (new && !incmd) {
  252.         if (!terse)
  253.             wwadd(cmdwin, &wwhead);
  254.         if (selwin != 0)
  255.             wwcursor(selwin, 1);
  256.         wwcurwin = 0;
  257.     } else if (!new && incmd) {
  258.         if (!terse) {
  259.             wwdelete(cmdwin);
  260.             reframe();
  261.         }
  262.         if (selwin != 0)
  263.             wwcursor(selwin, 0);
  264.         wwcurwin = selwin;
  265.     }
  266.     incmd = new;
  267. }
  268.  
  269. setterse(new)
  270. char new;
  271. {
  272.     if (incmd)
  273.         if (new && !terse) {
  274.             wwdelete(cmdwin);
  275.             reframe();
  276.         } else if (!new && terse)
  277.             wwadd(cmdwin, &wwhead);
  278.     terse = new;
  279. }
  280.  
  281. /*
  282.  * Set the current window.
  283.  */
  284. setselwin(w)
  285. struct ww *w;
  286. {
  287.     if (selwin == w)
  288.         return;
  289.     if (selwin != 0)
  290.         lastselwin = selwin;
  291.     if ((selwin = w) != 0)
  292.         front(selwin, 1);
  293. }
  294.