Exemple #1
0
char *
getpass(char *prompt,char *buf,int max, int timeout)
{
	putstr(prompt);
	if (getfullline(buf,max,0,timeout*1000,0,0) == -1)
		putchar('\n');
	return(buf);
}
Exemple #2
0
int
Read(int argc,char *argv[])
{
	int		i, reached_eol, opt, waitfor, noecho;
	char	*prefill, buf[64], *space, *bp;

	prefill = 0;
	waitfor = noecho = 0;
	while((opt=getopt(argc,argv,"fnp:t:T:")) != -1) {
		switch(opt) {
		case 'f':
			flush_console_in();
			return(CMD_SUCCESS);
		case 'n':
			noecho = 1;
			break;
		case 'p':
			prefill = optarg;
			break;
		case 't':
			waitfor = strtol(optarg,(char **)0,0);
			break;
		case 'T':
			waitfor = strtol(optarg,(char **)0,0);
			waitfor = -waitfor;
			break;
		default:
			return(CMD_PARAM_ERROR);
		}
	}

#if INCLUDE_MONCMD
	/* Since this command blocks waiting for user input on the console,
	 * check to see if we are running under the context of MONCMD, and,
	 * if yes, return CMD_FAILURE to avoid a lockup...
	 */
	if (IPMonCmdActive) {
		printf("Invalid under moncmd context.\n");
		return(CMD_FAILURE);
	}
#endif

	/* If -t, then restart the timeout for each character.
	 * If -T, then the timeout accumulates over all characters.
	 * If a timeout does occur, then do nothing to the shell variables
	 * that may be specified as arguments.  This allows the script
	 * writer to distinguish between a timeout, and an empty line...
	 * Timeout has no affect, empty line will NULL out the variable.
	 */
	if (getfullline(buf,sizeof(buf)-1,0,waitfor,prefill,noecho?0:1) == -1)
		return(CMD_SUCCESS);

	/* If there were no args after the option, then there is no need to
	 * consider populating a shell variable, so just return here.
	 */
	if (argc == optind) {
		return(CMD_SUCCESS);
	}

	bp = buf;
	reached_eol = 0;
	for(i=optind;i<argc;i++) {
		space=strpbrk(bp," \t");
		if (space) {
			*space = 0;
			setenv(argv[i],bp);
			bp = space+1;
		}
		else {
			if ((reached_eol) || (*bp == 0)) {
				setenv(argv[i],0);
			}
			else {
				setenv(argv[i],bp);
				reached_eol = 1;
			}
		}
	}
	return(CMD_SUCCESS);
}
Exemple #3
0
int
getline_t(char *buf, int max, int timeout)
{
	return(getfullline(buf,max,0,timeout,0,1));
}
Exemple #4
0
int
getline_p(char *buf, int max, int ledit, char *prefill)
{
	return(getfullline(buf,max,ledit,0,prefill,1));
}
Exemple #5
0
int
getline(char *buf, int max, int ledit)
{
	return(getfullline(buf,max,ledit,0,0,1));
}