1 /* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. 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 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 06/06/93"; 13 #endif /* not lint */ 14 15 #include "defs.h" 16 #include <paths.h> 17 #include <stdio.h> 18 #include "string.h" 19 #include "char.h" 20 #include "local.h" 21 22 #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage())) 23 24 /*ARGSUSED*/ 25 main(argc, argv) 26 char **argv; 27 { 28 register char *p; 29 char fflag = 0; 30 char dflag = 0; 31 char xflag = 0; 32 char *cmd = 0; 33 char tflag = 0; 34 35 escapec = ESCAPEC; 36 if (p = rindex(*argv, '/')) 37 p++; 38 else 39 p = *argv; 40 debug = strcmp(p, "a.out") == 0; 41 while (*++argv) { 42 if (**argv == '-') { 43 switch (*++*argv) { 44 case 'f': 45 fflag++; 46 break; 47 case 'c': 48 if (cmd != 0) { 49 (void) fprintf(stderr, 50 "Only one -c allowed.\n"); 51 (void) usage(); 52 } 53 cmd = next(argv); 54 break; 55 case 'e': 56 setescape(next(argv)); 57 break; 58 case 't': 59 tflag++; 60 break; 61 case 'd': 62 dflag++; 63 break; 64 case 'D': 65 debug = !debug; 66 break; 67 case 'x': 68 xflag++; 69 break; 70 default: 71 (void) usage(); 72 } 73 } else 74 (void) usage(); 75 } 76 if ((p = getenv("SHELL")) == 0) 77 p = _PATH_BSHELL; 78 if ((default_shellfile = str_cpy(p)) == 0) { 79 (void) fprintf(stderr, "Out of memory.\n"); 80 exit(1); 81 } 82 if (p = rindex(default_shellfile, '/')) 83 p++; 84 else 85 p = default_shellfile; 86 default_shell[0] = p; 87 default_shell[1] = 0; 88 default_nline = NLINE; 89 default_smooth = 1; 90 (void) gettimeofday(&starttime, (struct timezone *)0); 91 if (wwinit() < 0) { 92 (void) fprintf(stderr, "%s.\n", wwerror()); 93 exit(1); 94 } 95 96 #ifdef OLD_TTY 97 if (debug) 98 wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc; 99 if (xflag) { 100 wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc; 101 wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc; 102 } 103 #else 104 if (debug) { 105 wwnewtty.ww_termios.c_cc[VQUIT] = 106 wwoldtty.ww_termios.c_cc[VQUIT]; 107 wwnewtty.ww_termios.c_lflag |= ISIG; 108 } 109 if (xflag) { 110 wwnewtty.ww_termios.c_cc[VSTOP] = 111 wwoldtty.ww_termios.c_cc[VSTOP]; 112 wwnewtty.ww_termios.c_cc[VSTART] = 113 wwoldtty.ww_termios.c_cc[VSTART]; 114 wwnewtty.ww_termios.c_iflag |= IXON; 115 } 116 #endif 117 if (debug || xflag) 118 (void) wwsettty(0, &wwnewtty); 119 120 if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol, 121 0, 0, 0)) == 0) { 122 wwflush(); 123 (void) fprintf(stderr, "%s.\r\n", wwerror()); 124 goto bad; 125 } 126 cmdwin->ww_mapnl = 1; 127 cmdwin->ww_nointr = 1; 128 cmdwin->ww_noupdate = 1; 129 cmdwin->ww_unctrl = 1; 130 if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0)) 131 == 0) { 132 wwflush(); 133 (void) fprintf(stderr, "%s.\r\n", wwerror()); 134 goto bad; 135 } 136 wwadd(framewin, &wwhead); 137 if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) { 138 wwflush(); 139 (void) fprintf(stderr, "%s.\r\n", wwerror()); 140 goto bad; 141 } 142 fgwin = framewin; 143 144 wwupdate(); 145 wwflush(); 146 setvars(); 147 148 setterse(tflag); 149 setcmd(1); 150 if (cmd != 0) 151 (void) dolongcmd(cmd, (struct value *)0, 0); 152 if (!fflag) 153 if (dflag || doconfig() < 0) 154 dodefault(); 155 if (selwin != 0) 156 setcmd(0); 157 158 mloop(); 159 160 bad: 161 wwend(1); 162 return 0; 163 } 164 165 usage() 166 { 167 (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n"); 168 exit(1); 169 return 0; /* for lint */ 170 } 171