/* * Figure out what kind of terminal we're dealing with, and then read in * its termcap entry. */ const char * get_termcap_entry(char *userarg, char **tcapbufp) { struct ttyent *t; int rval; char *p, *ttypath; const char *ttype; if (userarg) { ttype = userarg; goto found; } /* Try the environment. */ if ((ttype = getenv("TERM"))) goto map; /* Try ttyname(3); check for dialup or other mapping. */ if ((ttypath = ttyname(STDERR_FILENO))) { if ((p = strrchr(ttypath, '/'))) ++p; else p = ttypath; if ((t = getttynam(p))) { ttype = t->ty_type; goto map; } } /* If still undefined, use "unknown". */ ttype = "unknown"; map: ttype = mapped(ttype); /* * If not a path, remove TERMCAP from the environment so we get a * real entry from /etc/termcap. This prevents us from being fooled * by out of date stuff in the environment. */ found: if ((p = getenv("TERMCAP")) != NULL && *p != '/') unsetenv("TERMCAP"); /* * ttype now contains a pointer to the type of the terminal. * If the first character is '?', ask the user. */ if (ttype[0] == '?') { if (ttype[1] != '\0') ttype = askuser(ttype + 1); else ttype = askuser(NULL); } /* Find the termcap entry. If it doesn't exist, ask the user. */ while ((rval = tgetent(tbuf, ttype)) == 0) { warnx("terminal type %s is unknown", ttype); ttype = askuser(NULL); } if (rval == -1) errx(1, "termcap: %s", strerror(errno ? errno : ENOENT)); *tcapbufp = tbuf; return (ttype); }
/*** fDoReplace - called by fScan as file is scanned. * * Purpose: * * Input: * * Output: * Returns ..... * * Exceptions: * * Notes: * *************************************************************************/ flagType fDoReplace ( void ) { int c; char *p = pLog (scanreal, flScan.col, TRUE); if (fRplRePrev) { int rem; flagType fAgain = TRUE; do { switch (rem = REMatch (patBuf, scanreal, p, REStack, MaxREStack, TRUE)) { case REM_NOMATCH: flScan.col = scanlen; return FALSE; case REM_STKOVR: MaxREStack += 128; REStack = (RE_OPCODE **)ZEROREALLOC ((char *)REStack, MaxREStack * sizeof(*REStack)); break; default: printerror ("Internal Error: RE error %d, line %ld", rem, flScan.lin); case REM_MATCH: fAgain = FALSE; break; } } while (fAgain); c = colPhys (scanreal, REStart (patBuf)); srchlen = RELength (patBuf, 0); if (c + srchlen - 1 > scanlen) { return FALSE; } flScan.col = c; } else { if ( (*(fSrchCasePrev ? strncmp : _strnicmp)) (srcbuf, p, srchlen)) { return FALSE; } if (flScan.col + srchlen - 1 > scanlen) { return FALSE; } } if (fQrpl) { ClearHiLite (pFileHead, TRUE); Display(); cursorfl (flScan); HighLight (flScan.col, flScan.lin, flScan.col+srchlen-1, flScan.lin); Display (); c = askuser ('n', 'a', "Replace this occurrence? (Yes/No/All/Quit): ", NULL); ClearHiLite (pFileHead, TRUE); redraw (pFileHead, flScan.lin, flScan.lin); RSETFLAG (fDisplay, RHIGH); switch (c) { case -1: case 'q': fCtrlc = TRUE; return TRUE; case 'n': return FALSE; case 'a': dispmsg(0); /* clear dialog line */ fQrpl = FALSE; break; } } if (fRplRePrev) { patRpl (); } else { simpleRpl (p); } return FALSE; }
/* * Figure out what kind of terminal we're dealing with, and then read in * its termcap entry. */ static const char * get_termcap_entry(char *userarg) { int errret; char *p; const char *ttype; #if HAVE_GETTTYNAM struct ttyent *t; #else FILE *fp; #endif char *ttypath; if (userarg) { ttype = userarg; goto found; } /* Try the environment. */ if ((ttype = getenv("TERM")) != 0) goto map; if ((ttypath = ttyname(STDERR_FILENO)) != 0) { p = _nc_basename(ttypath); #if HAVE_GETTTYNAM /* * We have the 4.3BSD library call getttynam(3); that means * there's an /etc/ttys to look up device-to-type mappings in. * Try ttyname(3); check for dialup or other mapping. */ if ((t = getttynam(p))) { ttype = t->ty_type; goto map; } #else if ((fp = fopen("/etc/ttytype", "r")) != 0 || (fp = fopen("/etc/ttys", "r")) != 0) { char buffer[BUFSIZ]; char *s, *t, *d; while (fgets(buffer, sizeof(buffer), fp) != NULL) { for (s = buffer, t = d = 0; *s; s++) { if (isspace(UChar(*s))) *s = '\0'; else if (t == 0) t = s; else if (d == 0 && s != buffer && s[-1] == '\0') d = s; } if (t != 0 && d != 0 && !strcmp(d, p)) { ttype = strdup(t); fclose(fp); goto map; } } fclose(fp); } #endif /* HAVE_GETTTYNAM */ } /* If still undefined, use "unknown". */ ttype = "unknown"; map:ttype = mapped(ttype); /* * If not a path, remove TERMCAP from the environment so we get a * real entry from /etc/termcap. This prevents us from being fooled * by out of date stuff in the environment. */ found:if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) { /* 'unsetenv("TERMCAP")' is not portable. * The 'environ' array is better. */ int n; for (n = 0; environ[n] != 0; n++) { if (!strncmp("TERMCAP=", environ[n], 8)) { while ((environ[n] = environ[n + 1]) != 0) { n++; } break; } } } /* * ttype now contains a pointer to the type of the terminal. * If the first character is '?', ask the user. */ if (ttype[0] == '?') { if (ttype[1] != '\0') ttype = askuser(ttype + 1); else ttype = askuser(0); } /* Find the terminfo entry. If it doesn't exist, ask the user. */ while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret) != OK) { if (errret == 0) { (void) fprintf(stderr, "%s: unknown terminal type %s\n", _nc_progname, ttype); ttype = 0; } else { (void) fprintf(stderr, "%s: can't initialize terminal type %s (error %d)\n", _nc_progname, ttype, errret); ttype = 0; } ttype = askuser(ttype); } #if BROKEN_LINKER tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */ #endif return (ttype); }
int Cast(int argc,char *argv[]) { long flags; int opt, tfd, index; char *structtype, *structfile, *tablename, *linkname, *name; flags = 0; name = (char *)0; linkname = (char *)0; tablename = (char *)0; while((opt=getopt(argc,argv,"apl:n:t:")) != -1) { switch(opt) { case 'a': flags |= STRUCT_SHOWADD; break; case 'l': linkname = optarg; break; case 'n': name = optarg; break; case 'p': flags |= STRUCT_SHOWPAD; break; case 't': tablename = optarg; break; default: return(CMD_PARAM_ERROR); } } if (argc != optind + 2) return(CMD_PARAM_ERROR); structtype = argv[optind]; memAddr = strtoul(argv[optind+1],0,0); /* Start by detecting the presence of a structure definition file... */ structfile = getenv("STRUCTFILE"); if (!structfile) structfile = STRUCTFILE; tfd = tfsopen(structfile,TFS_RDONLY,0); if (tfd < 0) { printf("Structure definition file '%s' not found\n",structfile); return(CMD_FAILURE); } index = 0; do { castDepth = 0; showStruct(tfd,flags,structtype,name,linkname); index++; if (linkname) printf("Link #%d = 0x%lx\n",index,memAddr); if (tablename || linkname) { if (askuser("next?")) { if (tablename) printf("%s[%d]:\n",tablename,index); } else tablename = linkname = (char *)0; } } while(tablename || linkname); tfsclose(tfd,0); return(CMD_SUCCESS); }
void main(int argc, char **argv) { int i, trysecstore; char err[ERRMAX], *s; Dir d; Proto *p; char *secstorepw; trysecstore = 1; secstorepw = nil; ARGBEGIN{ case 'D': chatty9p++; break; case 'S': /* server: read nvram, no prompting for keys */ askforkeys = 0; trysecstore = 0; sflag = 1; break; case 'a': authaddr = EARGF(usage()); break; case 'd': debug = 1; doprivate = 0; break; case 'g': /* get: prompt for key for name and domain */ gflag = 1; break; case 'k': /* reinitialize nvram */ kflag = 1; break; case 'm': /* set default mount point */ mtpt = EARGF(usage()); break; case 'n': trysecstore = 0; break; case 'p': doprivate = 0; break; case 's': /* set service name */ service = EARGF(usage()); break; case 'u': /* user: set hostowner */ uflag = 1; break; default: usage(); }ARGEND if(argc != 0 && !gflag) usage(); if(doprivate) private(); initcap(); quotefmtinstall(); fmtinstall('A', _attrfmt); fmtinstall('N', attrnamefmt); fmtinstall('H', encodefmt); ring = emalloc(sizeof(*ring)); notify(notifyf); if(gflag){ if(argc != 1) usage(); askuser(argv[0]); exits(nil); } for(i=0; prototab[i]; i++){ p = prototab[i]; if(p->name == nil) sysfatal("protocol %d has no name", i); if(p->init == nil) sysfatal("protocol %s has no init", p->name); if(p->write == nil) sysfatal("protocol %s has no write", p->name); if(p->read == nil) sysfatal("protocol %s has no read", p->name); if(p->close == nil) sysfatal("protocol %s has no close", p->name); if(p->keyprompt == nil) p->keyprompt = ""; } if(sflag){ s = getnvramkey(kflag ? NVwrite : NVwriteonerr, &secstorepw); if(s == nil) fprint(2, "factotum warning: cannot read nvram: %r\n"); else if(ctlwrite(s, 0) < 0) fprint(2, "factotum warning: cannot add nvram key: %r\n"); if(secstorepw != nil) trysecstore = 1; if (s != nil) { memset(s, 0, strlen(s)); free(s); } } else if(uflag) promptforhostowner(); owner = getuser(); if(trysecstore){ if(havesecstore() == 1){ while(secstorefetch(secstorepw) < 0){ rerrstr(err, sizeof err); if(strcmp(err, "cancel") == 0) break; fprint(2, "factotum: secstorefetch: %r\n"); fprint(2, "Enter an empty password to quit.\n"); free(secstorepw); secstorepw = nil; /* just try nvram pw once */ } }else{ /* rerrstr(err, sizeof err); if(*err) fprint(2, "factotum: havesecstore: %r\n"); */ } } postmountsrv(&fs, service, mtpt, MBEFORE); if(service){ nulldir(&d); d.mode = 0666; s = emalloc(10+strlen(service)); strcpy(s, "/srv/"); strcat(s, service); if(dirwstat(s, &d) < 0) fprint(2, "factotum warning: cannot chmod 666 %s: %r\n", s); free(s); } exits(nil); }
int hitakey(void) { return(askuser((char *)"hit any key to continue...")); }
int More(void) { return(askuser((char *)"more?")); }