⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commands.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
	int welldefined;	/* A well defined variable */};struct env_lst envlisthead;	struct env_lst *env_find(var)	unsigned char *var;{	register struct env_lst *ep;	for (ep = envlisthead.next; ep; ep = ep->next) {		if (strcmp((char *)ep->var, (char *)var) == 0)			return(ep);	}	return(NULL);}	voidenv_init(){	extern char **environ;	register char **epp, *cp;	register struct env_lst *ep;	extern char *index();	for (epp = environ; *epp; epp++) {		if (cp = index(*epp, '=')) {			*cp = '\0';			ep = env_define((unsigned char *)*epp,					(unsigned char *)cp+1);			ep->export = 0;			*cp = '=';		}	}	/*	 * Special case for DISPLAY variable.  If it is ":0.0" or	 * "unix:0.0", we have to get rid of "unix" and insert our	 * hostname.	 */	if ((ep = env_find("DISPLAY"))	    && ((*ep->value == ':')	        || (strncmp((char *)ep->value, "unix:", 5) == 0))) {		char hbuf[256+1];		char *cp2 = index((char *)ep->value, ':');		gethostname(hbuf, 256);		hbuf[256] = '\0';		cp = (char *)malloc(strlen(hbuf) + strlen(cp2) + 1);		sprintf((char *)cp, "%s%s", hbuf, cp2);		free(ep->value);		ep->value = (unsigned char *)cp;	}	/*	 * If USER is not defined, but LOGNAME is, then add	 * USER with the value from LOGNAME.  By default, we	 * don't export the USER variable.	 */	if ((env_find("USER") == NULL) && (ep = env_find("LOGNAME"))) {		env_define((unsigned char *)"USER", ep->value);		env_unexport((unsigned char *)"USER");	}	env_export((unsigned char *)"DISPLAY");	env_export((unsigned char *)"PRINTER");}	struct env_lst *env_define(var, value)	unsigned char *var, *value;{	register struct env_lst *ep;	if (ep = env_find(var)) {		if (ep->var)			free(ep->var);		if (ep->value)			free(ep->value);	} else {		ep = (struct env_lst *)malloc(sizeof(struct env_lst));		ep->next = envlisthead.next;		envlisthead.next = ep;		ep->prev = &envlisthead;		if (ep->next)			ep->next->prev = ep;	}	ep->welldefined = opt_welldefined(var);	ep->export = 1;	ep->var = (unsigned char *)strdup((char *)var);	ep->value = (unsigned char *)strdup((char *)value);	return(ep);}	voidenv_undefine(var)	unsigned char *var;{	register struct env_lst *ep;	if (ep = env_find(var)) {		ep->prev->next = ep->next;		if (ep->next)			ep->next->prev = ep->prev;		if (ep->var)			free(ep->var);		if (ep->value)			free(ep->value);		free(ep);	}}	voidenv_export(var)	unsigned char *var;{	register struct env_lst *ep;	if (ep = env_find(var))		ep->export = 1;}	voidenv_unexport(var)	unsigned char *var;{	register struct env_lst *ep;	if (ep = env_find(var))		ep->export = 0;}	voidenv_send(var)	unsigned char *var;{	register struct env_lst *ep;        if (my_state_is_wont(TELOPT_NEW_ENVIRON)#ifdef	OLD_ENVIRON	    && my_state_is_wont(TELOPT_OLD_ENVIRON)#endif		) {		fprintf(stderr,		    "Cannot send '%s': Telnet ENVIRON option not enabled\n",									var);		return;	}	ep = env_find(var);	if (ep == 0) {		fprintf(stderr, "Cannot send '%s': variable not defined\n",									var);		return;	}	env_opt_start_info();	env_opt_add(ep->var);	env_opt_end(0);}	voidenv_list(){	register struct env_lst *ep;	for (ep = envlisthead.next; ep; ep = ep->next) {		printf("%c %-20s %s\n", ep->export ? '*' : ' ',					ep->var, ep->value);	}}	unsigned char *env_default(init, welldefined)	int init;{	static struct env_lst *nep = NULL;	if (init) {		nep = &envlisthead;		return;	}	if (nep) {		while (nep = nep->next) {			if (nep->export && (nep->welldefined == welldefined))				return(nep->var);		}	}	return(NULL);}	unsigned char *env_getvalue(var)	unsigned char *var;{	register struct env_lst *ep;	if (ep = env_find(var))		return(ep->value);	return(NULL);}#if defined(OLD_ENVIRON) && defined(ENV_HACK)	voidenv_varval(what)	unsigned char *what;{	extern int old_env_var, old_env_value, env_auto;	int len = strlen((char *)what);	if (len == 0)		goto unknown;	if (strncasecmp((char *)what, "status", len) == 0) {		if (env_auto)			printf("%s%s", "VAR and VALUE are/will be ",					"determined automatically\n");		if (old_env_var == OLD_ENV_VAR)			printf("VAR and VALUE set to correct definitions\n");		else			printf("VAR and VALUE definitions are reversed\n");	} else if (strncasecmp((char *)what, "auto", len) == 0) {		env_auto = 1;		old_env_var = OLD_ENV_VALUE;		old_env_value = OLD_ENV_VAR;	} else if (strncasecmp((char *)what, "right", len) == 0) {		env_auto = 0;		old_env_var = OLD_ENV_VAR;		old_env_value = OLD_ENV_VALUE;	} else if (strncasecmp((char *)what, "wrong", len) == 0) {		env_auto = 0;		old_env_var = OLD_ENV_VALUE;		old_env_value = OLD_ENV_VAR;	} else {unknown:		printf("Unknown \"varval\" command. (\"auto\", \"right\", \"wrong\", \"status\")\n");	}}#endif#if	defined(AUTHENTICATION)/* * The AUTHENTICATE command. */struct authlist {	char	*name;	char	*help;	int	(*handler)();	int	narg;};extern int	auth_enable P((int)),	auth_disable P((int)),	auth_status P((void));static int	auth_help P((void));struct authlist AuthList[] = {    { "status",	"Display current status of authentication information",						auth_status,	0 },    { "disable", "Disable an authentication type ('auth disable ?' for more)",						auth_disable,	1 },    { "enable", "Enable an authentication type ('auth enable ?' for more)",						auth_enable,	1 },    { "help",	0,				auth_help,		0 },    { "?",	"Print help information",	auth_help,		0 },    { 0 },};    static intauth_help(){    struct authlist *c;    for (c = AuthList; c->name; c++) {	if (c->help) {	    if (*c->help)		printf("%-15s %s\n", c->name, c->help);	    else		printf("\n");	}    }    return 0;}auth_cmd(argc, argv)    int  argc;    char *argv[];{    struct authlist *c;    c = (struct authlist *)		genget(argv[1], (char **) AuthList, sizeof(struct authlist));    if (c == 0) {        fprintf(stderr, "'%s': unknown argument ('auth ?' for help).\n",    				argv[1]);        return 0;    }    if (Ambiguous(c)) {        fprintf(stderr, "'%s': ambiguous argument ('auth ?' for help).\n",    				argv[1]);        return 0;    }    if (c->narg + 2 != argc) {	fprintf(stderr,	    "Need %s%d argument%s to 'auth %s' command.  'auth ?' for help.\n",		c->narg < argc + 2 ? "only " : "",		c->narg, c->narg == 1 ? "" : "s", c->name);	return 0;    }    return((*c->handler)(argv[2], argv[3]));}#endif#ifdef	ENCRYPTION/* * The ENCRYPT command. */struct encryptlist {	char	*name;	char	*help;	int	(*handler)();	int	needconnect;	int	minarg;	int	maxarg;};extern int	EncryptEnable P((char *, char *)),	EncryptDisable P((char *, char *)),	EncryptType P((char *, char *)),	EncryptStart P((char *)),	EncryptStartInput P((void)),	EncryptStartOutput P((void)),	EncryptStop P((char *)),	EncryptStopInput P((void)),	EncryptStopOutput P((void)),	EncryptStatus P((void));static int	EncryptHelp P((void));struct encryptlist EncryptList[] = {    { "enable", "Enable encryption. ('encrypt enable ?' for more)",						EncryptEnable, 1, 1, 2 },    { "disable", "Disable encryption. ('encrypt enable ?' for more)",						EncryptDisable, 0, 1, 2 },    { "type", "Set encryptiong type. ('encrypt type ?' for more)",						EncryptType, 0, 1, 1 },    { "start", "Start encryption. ('encrypt start ?' for more)",						EncryptStart, 1, 0, 1 },    { "stop", "Stop encryption. ('encrypt stop ?' for more)",						EncryptStop, 1, 0, 1 },    { "input", "Start encrypting the input stream",						EncryptStartInput, 1, 0, 0 },    { "-input", "Stop encrypting the input stream",						EncryptStopInput, 1, 0, 0 },    { "output", "Start encrypting the output stream",						EncryptStartOutput, 1, 0, 0 },    { "-output", "Stop encrypting the output stream",						EncryptStopOutput, 1, 0, 0 },    { "status",	"Display current status of authentication information",						EncryptStatus,	0, 0, 0 },    { "help",	0,				EncryptHelp,	0, 0, 0 },    { "?",	"Print help information",	EncryptHelp,	0, 0, 0 },    { 0 },};    static intEncryptHelp(){    struct encryptlist *c;    for (c = EncryptList; c->name; c++) {	if (c->help) {	    if (*c->help)		printf("%-15s %s\n", c->name, c->help);	    else		printf("\n");	}    }    return 0;}encrypt_cmd(argc, argv)    int  argc;    char *argv[];{    struct encryptlist *c;    c = (struct encryptlist *)		genget(argv[1], (char **) EncryptList, sizeof(struct encryptlist));    if (c == 0) {        fprintf(stderr, "'%s': unknown argument ('encrypt ?' for help).\n",    				argv[1]);        return 0;    }    if (Ambiguous(c)) {        fprintf(stderr, "'%s': ambiguous argument ('encrypt ?' for help).\n",    				argv[1]);        return 0;    }    argc -= 2;    if (argc < c->minarg || argc > c->maxarg) {	if (c->minarg == c->maxarg) {	    fprintf(stderr, "Need %s%d argument%s ",		c->minarg < argc ? "only " : "", c->minarg,		c->minarg == 1 ? "" : "s");	} else {	    fprintf(stderr, "Need %s%d-%d arguments ",		c->maxarg < argc ? "only " : "", c->minarg, c->maxarg);	}	fprintf(stderr, "to 'encrypt %s' command.  'encrypt ?' for help.\n",		c->name);	return 0;    }    if (c->needconnect && !connected) {	if (!(argc && (isprefix(argv[2], "help") || isprefix(argv[2], "?")))) {	    printf("?Need to be connected first.\n");	    return 0;	}    }    return ((*c->handler)(argc > 0 ? argv[2] : 0,			argc > 1 ? argv[3] : 0,			argc > 2 ? argv[4] : 0));}#endif	/* ENCRYPTION */#if	defined(unix) && defined(TN3270)    static voidfilestuff(fd)    int fd;{    int res;#ifdef	F_GETOWN    setconnmode(0);    res = fcntl(fd, F_GETOWN, 0);    setcommandmode();    if (res == -1) {	perror("fcntl");	return;    }    printf("\tOwner is %d.\n", res);#endif    setconnmode(0);    res = fcntl(fd, F_GETFL, 0);    setcommandmode();    if (res == -1) {	perror("fcntl");	return;    }#ifdef notdef    printf("\tFlags are 0x%x: %s\n", res, decodeflags(res));#endif}#endif /* defined(unix) && defined(TN3270) *//* * Print status about the connection. */    /*ARGSUSED*/    staticstatus(argc, argv)    int	 argc;    char *argv[];{    if (connected) {	printf("Connected to %s.\n", hostname);	if ((argc < 2) || strcmp(argv[1], "notmuch")) {	    int mode = getconnmode();	    if (my_want_state_is_will(TELOPT_LINEMODE)) {		printf("Operating with LINEMODE option\n");		printf("%s line editing\n", (mode&MODE_EDIT) ? "Local" : "No");		printf("%s catching of signals\n",					(mode&MODE_TRAPSIG) ? "Local" : "No");		slcstate();#ifdef	KLUDGELINEMODE	    } else if (kludgelinemode && my_want_state_is_dont(TELOPT_SGA)) {		printf("Operating in obsolete linemode\n");#endif	    } else {		printf("Operating in single character mode\n");		if (localchars)		    printf("Catching signals locally\n");	    }	    printf("%s character echo\n", (mode&MODE_ECHO) ? "Local" : "Remote");	    if (my_want_state_is_will(TELOPT_LFLOW))		printf("%s flow control\n", (mode&MODE_FLOW) ? "Local" : "No");#ifdef	ENCRYPTION	    encrypt_display();#endif	/* ENCRYPTION */	}    } else {	printf("No connection.\n");    }#   if !defined(TN3270)    printf("Escape character is '%s'.\n", control(escape));    (void) fflush(stdout);#   else /* !defined(TN3270) */    if ((!In3270) && ((argc < 2) || strcmp(argv[1], "notmuch"))) {	printf("Escape character is '%s'.\n", control(escape));    }#   if defined(unix)    if ((argc >= 2) && !strcmp(argv[1], "everything")) {	printf("SIGIO received %d time%s.\n",				sigiocount, (sigiocount == 1)? "":"s");	if (In3270) {	    printf("Process ID %d, process group %d.\n",					    getpid(), getpgrp(getpid()));	    printf("Terminal input:\n");	    filestuff(tin);	    printf("Terminal output:\n");	    filestuff(tout);	    printf("Network socket:\n");	    filestuff(net);	}    }    if (In3270 && transcom) {       printf("Transparent mode command is '%s'.\n", transcom);    }#   endif /* defined(unix) */    (void) fflush(stdout);    if (In3270) {	return 0;    }#   endif /* defined(TN3270) */    return 1;}#ifdef	SIGINFO/* * Function that gets called when SIGINFO is received. */ayt_status(){    (void) call(status, "status", "notmuch", 0);}#endifunsigned long inet_addr();    inttn(argc, argv)    int argc;    char *argv[];{    register struct hostent *host = 0;    struct sockaddr_in sin;    struct servent *sp = 0;    unsigned long temp;    extern char *inet_ntoa();#if	defined(IP_OPTIONS) && defined(IPPROTO_IP)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -