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.38 (Berkeley) 10/13/89"; 20 #endif /* not lint */ 21 22 #include "defs.h" 23 #include <paths.h> 24 #include <stdio.h> 25 #include "string.h" 26 #include "char.h" 27 #include "local.h" 28 29 #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage())) 30 31 /*ARGSUSED*/ 32 main(argc, argv) 33 char **argv; 34 { 35 register char *p; 36 char fflag = 0; 37 char dflag = 0; 38 char xflag = 0; 39 char *cmd = 0; 40 char tflag = 0; 41 42 escapec = ESCAPEC; 43 if (p = rindex(*argv, '/')) 44 p++; 45 else 46 p = *argv; 47 debug = strcmp(p, "a.out") == 0; 48 while (*++argv) { 49 if (**argv == '-') { 50 switch (*++*argv) { 51 case 'f': 52 fflag++; 53 break; 54 case 'c': 55 if (cmd != 0) { 56 (void) fprintf(stderr, 57 "Only one -c allowed.\n"); 58 (void) usage(); 59 } 60 cmd = next(argv); 61 break; 62 case 'e': 63 setescape(next(argv)); 64 break; 65 case 't': 66 tflag++; 67 break; 68 case 'd': 69 dflag++; 70 break; 71 case 'D': 72 debug = !debug; 73 break; 74 case 'x': 75 xflag++; 76 break; 77 default: 78 (void) usage(); 79 } 80 } else 81 (void) usage(); 82 } 83 if ((p = getenv("SHELL")) == 0) 84 p = _PATH_BSHELL; 85 if ((default_shellfile = str_cpy(p)) == 0) { 86 (void) fprintf(stderr, "Out of memory.\n"); 87 exit(1); 88 } 89 if (p = rindex(default_shellfile, '/')) 90 p++; 91 else 92 p = default_shellfile; 93 default_shell[0] = p; 94 default_shell[1] = 0; 95 default_nline = NLINE; 96 default_smooth = 1; 97 (void) gettimeofday(&starttime, (struct timezone *)0); 98 if (wwinit() < 0) { 99 (void) fprintf(stderr, "%s.\n", wwerror()); 100 exit(1); 101 } 102 if (debug) 103 wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc; 104 if (xflag) { 105 wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc; 106 wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc; 107 } 108 if (debug || xflag) 109 (void) wwsettty(0, &wwnewtty, &wwoldtty); 110 111 if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol, 112 0, 0, 0)) == 0) { 113 wwflush(); 114 (void) fprintf(stderr, "%s.\r\n", wwerror()); 115 goto bad; 116 } 117 cmdwin->ww_mapnl = 1; 118 cmdwin->ww_nointr = 1; 119 cmdwin->ww_noupdate = 1; 120 cmdwin->ww_unctrl = 1; 121 if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0)) 122 == 0) { 123 wwflush(); 124 (void) fprintf(stderr, "%s.\r\n", wwerror()); 125 goto bad; 126 } 127 wwadd(framewin, &wwhead); 128 if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) { 129 wwflush(); 130 (void) fprintf(stderr, "%s.\r\n", wwerror()); 131 goto bad; 132 } 133 fgwin = framewin; 134 135 wwupdate(); 136 wwflush(); 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