home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / window / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-18  |  5.0 KB  |  197 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[] = "@(#)main.c    3.42 (Berkeley) 8/12/90";
  39. #endif /* not lint */
  40.  
  41. #include "defs.h"
  42. #include <paths.h>
  43. #include <stdio.h>
  44. #include "string.h"
  45. #include "char.h"
  46. #include "local.h"
  47.  
  48. #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
  49.  
  50. /*ARGSUSED*/
  51. main(argc, argv)
  52. char **argv;
  53. {
  54.     register char *p;
  55.     char fflag = 0;
  56.     char dflag = 0;
  57.     char xflag = 0;
  58.     char *cmd = 0;
  59.     char tflag = 0;
  60.  
  61.     escapec = ESCAPEC;    
  62.     if (p = rindex(*argv, '/'))
  63.         p++;
  64.     else
  65.         p = *argv;
  66.     debug = strcmp(p, "a.out") == 0;
  67.     while (*++argv) {
  68.         if (**argv == '-') {
  69.             switch (*++*argv) {
  70.             case 'f':
  71.                 fflag++;
  72.                 break;
  73.             case 'c':
  74.                 if (cmd != 0) {
  75.                     (void) fprintf(stderr,
  76.                         "Only one -c allowed.\n");
  77.                     (void) usage();
  78.                 }
  79.                 cmd = next(argv);
  80.                 break;
  81.             case 'e':
  82.                 setescape(next(argv));
  83.                 break;
  84.             case 't':
  85.                 tflag++;
  86.                 break;
  87.             case 'd':
  88.                 dflag++;
  89.                 break;
  90.             case 'D':
  91.                 debug = !debug;
  92.                 break;
  93.             case 'x':
  94.                 xflag++;
  95.                 break;
  96.             default:
  97.                 (void) usage();
  98.             }
  99.         } else
  100.             (void) usage();
  101.     }
  102.     if ((p = getenv("SHELL")) == 0)
  103.         p = _PATH_BSHELL;
  104.     if ((default_shellfile = str_cpy(p)) == 0) {
  105.         (void) fprintf(stderr, "Out of memory.\n");
  106.         exit(1);
  107.     }
  108.     if (p = rindex(default_shellfile, '/'))
  109.         p++;
  110.     else
  111.         p = default_shellfile;
  112.     default_shell[0] = p;
  113.     default_shell[1] = 0;
  114.     default_nline = NLINE;
  115.     default_smooth = 1;
  116.     (void) gettimeofday(&starttime, (struct timezone *)0);
  117.     if (wwinit() < 0) {
  118.         (void) fprintf(stderr, "%s.\n", wwerror());
  119.         exit(1);
  120.     }
  121.  
  122. #ifdef OLD_TTY
  123.     if (debug)
  124.         wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
  125.     if (xflag) {
  126.         wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
  127.         wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
  128.     }
  129. #else
  130.     if (debug) {
  131.         wwnewtty.ww_termios.c_cc[VQUIT] =
  132.             wwoldtty.ww_termios.c_cc[VQUIT];
  133.         wwnewtty.ww_termios.c_lflag |= ISIG;
  134.     }
  135.     if (xflag) {
  136.         wwnewtty.ww_termios.c_cc[VSTOP] =
  137.             wwoldtty.ww_termios.c_cc[VSTOP];
  138.         wwnewtty.ww_termios.c_cc[VSTART] =
  139.             wwoldtty.ww_termios.c_cc[VSTART];
  140.         wwnewtty.ww_termios.c_iflag |= IXON;
  141.     }
  142. #endif
  143.     if (debug || xflag)
  144.         (void) wwsettty(0, &wwnewtty);
  145.  
  146.     if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol,
  147.                  0, 0, 0)) == 0) {
  148.         wwflush();
  149.         (void) fprintf(stderr, "%s.\r\n", wwerror());
  150.         goto bad;
  151.     }
  152.     cmdwin->ww_mapnl = 1;
  153.     cmdwin->ww_nointr = 1;
  154.     cmdwin->ww_noupdate = 1;
  155.     cmdwin->ww_unctrl = 1;
  156.     if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0))
  157.         == 0) {
  158.         wwflush();
  159.         (void) fprintf(stderr, "%s.\r\n", wwerror());
  160.         goto bad;
  161.     }
  162.     wwadd(framewin, &wwhead);
  163.     if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) {
  164.         wwflush();
  165.         (void) fprintf(stderr, "%s.\r\n", wwerror());
  166.         goto bad;
  167.     }
  168.     fgwin = framewin;
  169.  
  170.     wwupdate();
  171.     wwflush();
  172.     setvars();
  173.  
  174.     setterse(tflag);
  175.     setcmd(1);
  176.     if (cmd != 0)
  177.         (void) dolongcmd(cmd, (struct value *)0, 0);
  178.     if (!fflag)
  179.         if (dflag || doconfig() < 0)
  180.             dodefault();
  181.     if (selwin != 0)
  182.         setcmd(0);
  183.  
  184.     mloop();
  185.  
  186. bad:
  187.     wwend();
  188.     return 0;
  189. }
  190.  
  191. usage()
  192. {
  193.     (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n");
  194.     exit(1);
  195.     return 0;            /* for lint */
  196. }
  197.