1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)main.c 3.36 (Berkeley) 05/11/89"; 20 #endif /* not lint */ 21 22 #include "defs.h" 23 #include <sys/signal.h> 24 #include <paths.h> 25 #include <stdio.h> 26 #include "string.h" 27 #include "char.h" 28 #include "local.h" 29 30 #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage())) 31 32 /*ARGSUSED*/ 33 main(argc, argv) 34 char **argv; 35 { 36 register char *p; 37 char fflag = 0; 38 char dflag = 0; 39 char xflag = 0; 40 char *cmd = 0; 41 char tflag = 0; 42 43 escapec = ESCAPEC; 44 if (p = rindex(*argv, '/')) 45 p++; 46 else 47 p = *argv; 48 debug = strcmp(p, "a.out") == 0; 49 while (*++argv) { 50 if (**argv == '-') { 51 switch (*++*argv) { 52 case 'f': 53 fflag++; 54 break; 55 case 'c': 56 if (cmd != 0) { 57 (void) fprintf(stderr, 58 "Only one -c allowed.\n"); 59 (void) usage(); 60 } 61 cmd = next(argv); 62 break; 63 case 'e': 64 setescape(next(argv)); 65 break; 66 case 't': 67 tflag++; 68 break; 69 case 'd': 70 dflag++; 71 break; 72 case 'D': 73 debug = !debug; 74 break; 75 case 'x': 76 xflag++; 77 break; 78 default: 79 (void) usage(); 80 } 81 } else 82 (void) usage(); 83 } 84 if ((p = getenv("SHELL")) == 0) 85 p = _PATH_BSHELL; 86 if ((default_shellfile = str_cpy(p)) == 0) 87 nomem(); 88 if (p = rindex(default_shellfile, '/')) 89 p++; 90 else 91 p = default_shellfile; 92 default_shell[0] = p; 93 default_shell[1] = 0; 94 default_nline = NLINE; 95 default_smooth = 1; 96 (void) gettimeofday(&starttime, (struct timezone *)0); 97 if (wwinit() < 0) { 98 (void) fprintf(stderr, "%s.\n", wwerror()); 99 exit(1); 100 } 101 if (debug) 102 wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc; 103 if (xflag) { 104 wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc; 105 wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc; 106 } 107 if (debug || xflag) 108 (void) wwsettty(0, &wwnewtty, &wwoldtty); 109 110 if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol, 111 0, 0, 0)) == 0) { 112 (void) wwflush(); 113 (void) fprintf(stderr, "%s.\r\n", wwerror()); 114 goto bad; 115 } 116 cmdwin->ww_mapnl = 1; 117 cmdwin->ww_nointr = 1; 118 cmdwin->ww_noupdate = 1; 119 cmdwin->ww_unctrl = 1; 120 if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0)) 121 == 0) { 122 (void) wwflush(); 123 (void) fprintf(stderr, "%s.\r\n", wwerror()); 124 goto bad; 125 } 126 wwadd(framewin, &wwhead); 127 if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) { 128 (void) wwflush(); 129 (void) fprintf(stderr, "%s.\r\n", wwerror()); 130 goto bad; 131 } 132 fgwin = framewin; 133 134 wwupdate(); 135 wwflush(); 136 (void) signal(SIGCHLD, wwchild); 137 setvars(); 138 139 setterse(tflag); 140 setcmd(1); 141 if (cmd != 0) 142 (void) dolongcmd(cmd, (struct value *)0, 0); 143 if (!fflag) 144 if (dflag || doconfig() < 0) 145 dodefault(); 146 if (selwin != 0) 147 setcmd(0); 148 149 mloop(); 150 151 bad: 152 wwend(); 153 return 0; 154 } 155 156 usage() 157 { 158 (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n"); 159 exit(1); 160 return 0; /* for lint */ 161 } 162 163 nomem() 164 { 165 (void) fprintf(stderr, "Out of memory.\n"); 166 exit(1); 167 } 168