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

📄 commands.c

📁 socket5 代理服务代码 socket5 代理服务代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	    } else if (Ambiguous(c)) {		fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n", name);		return 0;	    }	    if (c->variable) {		*c->variable = 0;		if (c->actionexplanation) {		    printf("%s %s.\n", *c->variable? "Will" : "Won't", c->actionexplanation);		}	    }	    if (c->handler) (*c->handler)(0);	} else if (Ambiguous(ct)) {	    fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n", name);	    return 0;	} else if (ct->handler) {	    (*ct->handler)(0);	    printf("%s reset to \"%s\".\n", ct->name, (char *)ct->charp);	} else {	    *(ct->charp) = _POSIX_VDISABLE;	    printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));	}    }    return 1;}/* The following are the data structures and routines for the 'mode'         *//* command.                                                                  */#ifdef	KLUDGELINEMODEextern int kludgelinemode;static int dokludgemode() {    kludgelinemode = 1;    send_wont(TELOPT_LINEMODE, 1);    send_dont(TELOPT_SGA, 1);    send_dont(TELOPT_ECHO, 1);    return 1;}#endifstatic int dolinemode() {#ifdef	KLUDGELINEMODE    if (kludgelinemode) send_dont(TELOPT_SGA, 1);#endif    send_will(TELOPT_LINEMODE, 1);    send_dont(TELOPT_ECHO, 1);    return 1;}static int docharmode() {#ifdef	KLUDGELINEMODE    if (kludgelinemode) send_do(TELOPT_SGA, 1);    else#endif    send_wont(TELOPT_LINEMODE, 1);    send_do(TELOPT_ECHO, 1);    return 1;}static int dolmmode(int bit, int on) {    unsigned char c;    extern int linemode;    if (my_want_state_is_wont(TELOPT_LINEMODE)) {	printf("?Need to have LINEMODE option enabled first.\n");	printf("'mode ?' for help.\n");	return 0;    }    if (on) c = (linemode | bit);    else    c = (linemode & ~bit);    lm_mode(&c, 1, 1);    return 1;}static int tn_setmode(int bit) {    return dolmmode(bit, 1);}static int clearmode(int bit) {    return dolmmode(bit, 0);}struct modelist {    char *name;		/* command name */    char *help;		/* help string */    int	(*handler)();	/* routine which executes command */    int	needconnect;	/* Do we need to be connected to execute? */    int arg1;};extern int modehelp();static struct modelist ModeList[] = {    { "character", "Disable LINEMODE option",	     docharmode, 1 },#ifdef	KLUDGELINEMODE    { "",	   "(or disable obsolete line-by-line mode)", 0 },#endif    { "line",	   "Enable LINEMODE option",	     dolinemode, 1 },#ifdef	KLUDGELINEMODE    { "",	"(or enable obsolete line-by-line mode)", 0 },#endif    { "", "", 0 },    { "",	   "These require the LINEMODE option to be enabled", 0 },    { "isig",	   "Enable signal trapping",	     tn_setmode, 1, MODE_TRAPSIG },    { "+isig",	   NULL,			     tn_setmode, 1, MODE_TRAPSIG },    { "-isig",	   "Disable signal trapping",	     clearmode,  1, MODE_TRAPSIG },    { "edit",	   "Enable character editing",	     tn_setmode, 1, MODE_EDIT },    { "+edit",	   NULL,			     tn_setmode, 1, MODE_EDIT },    { "-edit",	   "Disable character editing",	     clearmode,  1, MODE_EDIT },    { "softtabs",  "Enable tab expansion",	     tn_setmode, 1, MODE_SOFT_TAB },    { "+softtabs", NULL,			     tn_setmode, 1, MODE_SOFT_TAB },    { "-softtabs", "Disable character editing",      clearmode,  1, MODE_SOFT_TAB },    { "litecho",   "Enable literal character echo",  tn_setmode, 1, MODE_LIT_ECHO },    { "+litecho",  NULL,			     tn_setmode, 1, MODE_LIT_ECHO },    { "-litecho",  "Disable literal character echo", clearmode,  1, MODE_LIT_ECHO },    { "help",	   NULL,			     modehelp,   0 },#ifdef	KLUDGELINEMODE    { "kludgeline", 0,				     dokludgemode, 1 },#endif    { "", "", 0 },    { "?",	    "Print help information",	     modehelp, 0 },    { 0 },};int modehelp() {    struct modelist *mt;    printf("format is:  'mode Mode', where 'Mode' is one of:\n\n");    for (mt = ModeList; mt->name; mt++) {	if (mt->help) {	    if (*mt->help) printf("%-15s %s\n", mt->name, mt->help);	    else printf("\n");	}    }    return 0;}#define	GETMODECMD(name) (struct modelist *) genget(name, (char **) ModeList, sizeof(struct modelist))static int modecmd(int argc, char *argv[]) {    struct modelist *mt;    if (argc != 2) {	printf("'mode' command requires an argument\n");	printf("'mode ?' for help.\n");    } else if ((mt = GETMODECMD(argv[1])) == 0) {	fprintf(stderr, "Unknown mode '%s' ('mode ?' for help).\n", argv[1]);    } else if (Ambiguous(mt)) {	fprintf(stderr, "Ambiguous mode '%s' ('mode ?' for help).\n", argv[1]);    } else if (mt->needconnect && !connected) {	printf("?Need to be connected first.\n");	printf("'mode ?' for help.\n");    } else if (mt->handler) {	return (*mt->handler)(mt->arg1);    }    return 0;}/* The following data structures and routines implement the "display"        *//* command.                                                                  */static int display(int argc, char *argv[]) {    struct togglelist *tl;    struct setlist *sl;#define	dotog(tl)	if (tl->variable && tl->actionexplanation) { \			    if (*tl->variable) { \				printf("will"); \			    } else { \				printf("won't"); \			    } \			    printf(" %s.\n", tl->actionexplanation); \			}#define	doset(sl)   if (sl->name && *sl->name != ' ') { \			if (sl->handler == 0) \			    printf("%-15s [%s]\n", sl->name, control(*sl->charp)); \			else \			    printf("%-15s \"%s\"\n", sl->name, (char *)sl->charp); \		    }    if (argc == 1) {	for (tl = Togglelist; tl->name; tl++) {	    dotog(tl);	}	printf("\n");	for (sl = Setlist; sl->name; sl++) {	    doset(sl);	}    } else {	int i;	for (i = 1; i < argc; i++) {	    sl = getset(argv[i]);	    tl = GETTOGGLE(argv[i]);	    if (Ambiguous(sl) || Ambiguous(tl)) {		printf("?Ambiguous argument '%s'.\n", argv[i]);		return 0;	    } else if (!sl && !tl) {		printf("?Unknown argument '%s'.\n", argv[i]);		return 0;	    } else {		if (tl) {		    dotog(tl);		}		if (sl) {		    doset(sl);		}	    }	}    }    /*@*/optionstatus();    return 1;#undef	doset#undef	dotog}/* The following are the data structures, and many of the routines, relating *//* to command processing.                                                    *//*                                                                           *//* Set the escape character.                                                 */static int setescape(int argc, char *argv[]) {    register char *arg;    char buf[50];        printf("Deprecated usage - please use 'set escape%s%s' in the future.\n",	   (argc > 2)? " ":"", (argc > 2)? argv[1]: "");    if (argc > 2) arg = argv[1];    else {	printf("new escape character: ");	fgets(buf, sizeof(buf), stdin);	arg = buf;    }    if (arg[0] != '\0') escape = arg[0];    if (!In3270) {	printf("Escape character is '%s'.\n", control(escape));    }    fflush(stdout);    return 1;}static int togcrmod() {    crmod = !crmod;    printf("Deprecated usage - please use 'toggle crmod' in the future.\n");    printf("%s map carriage return on output.\n", crmod ? "Will" : "Won't");    fflush(stdout);    return 1;}int suspend() {#ifdef	SIGTSTP    long oldrows, oldcols, newrows, newcols, err;    setcommandmode();    err = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;    kill(0, SIGTSTP);    /* If we didn't get the window size before the SUSPEND, but we can get   */    /* them now (?), then send the NAWS to make sure that we are set up for  */    /* the right window size. 	                                                                     */    if (TerminalWindowSize(&newrows, &newcols) && connected &&	(err || ((oldrows != newrows) || (oldcols != newcols)))) {	sendnaws();    }    /* reget parameters in case they were changed */    TerminalSaveState();    setconnmode(0);#else    printf("Suspend is not supported.  Try the '!' command instead\n");#endif    return 1;}#ifndef TN3270int shell(int argc, char *argv[]) {    long oldrows, oldcols, newrows, newcols, err;    setcommandmode();    err = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;    switch(vfork()) {    case -1:	perror("Fork failed\n");	break;    case 0:	{	    /* Fire up the shell in the child. */	    register char *shellp, *shellname;	    shellp = getenv("SHELL");	    if (shellp == NULL) shellp = "/bin/sh";	    if ((shellname = strrchr(shellp, '/')) == 0) shellname = shellp;	    else shellname++;	    if (argc > 1) execl(shellp, shellname, "-c", &saveline[1], 0);	    else execl(shellp, shellname, 0);	    perror("Execl");	    _exit(1);	}    default:	wait(NULL);	/* Wait for the shell to complete */	if (TerminalWindowSize(&newrows, &newcols) && connected &&	    (err || ((oldrows != newrows) || (oldcols != newcols)))) {	    sendnaws();	}	break;    }    return 1;}#elseextern int shell();#endif/* The SLC command.                                                          */struct slclist {	char	*name;	char	*help;	void	(*handler)();	int	arg;};static void slc_help();struct slclist SlcList[] = {    { "export",	"Use local special character definitions",     slc_mode_export,	0 },    { "import",	"Use remote special character definitions",    slc_mode_import,	1 },    { "check",	"Verify remote special character definitions", slc_mode_import,	0 },    { "help",	0,				               slc_help,	0 },    { "?",	"Print help information",	               slc_help,	0 },    { 0 },};static void slc_help() {    struct slclist *c;    for (c = SlcList; c->name; c++) {	if (c->help) {	    if (*c->help) printf("%-15s %s\n", c->name, c->help);	    else printf("\n");	}    }}static struct slclist *getslc(char *name) {    return (struct slclist *) genget(name, (char **) SlcList, sizeof(struct slclist));}static int slccmd(int argc, char *argv[]) {    struct slclist *c;    if (argc != 2) {	fprintf(stderr, "Need an argument to 'slc' command.  'slc ?' for help.\n");	return 0;    }        c = getslc(argv[1]);    if (c == 0) {	fprintf(stderr, "'%s': unknown argument ('slc ?' for help).\n", argv[1]);	return 0;    }        if (Ambiguous(c)) {	fprintf(stderr, "'%s': ambiguous argument ('slc ?' for help).\n", argv[1]);	return 0;    }        (*c->handler)(c->arg);    slcstate();    return 1;}/* The ENVIRON command. */struct envlist {	char	*name;	char	*help;	void	(*handler)();	int	narg;};extern struct env_lst *	env_define P((unsigned char *, unsigned char *));extern void	env_undefine P((unsigned char *)),	env_export P((unsigned char *)),	env_unexport P((unsigned char *)),	env_send P((unsigned char *)),#if defined(OLD_ENVIRON) && defined(ENV_HACK)	env_varval P((unsigned char *)),#endif	env_list P((void));static void	env_help P((void));struct envlist EnvList[] = {    { "define",	"Define an environment variable",						(void (*)())env_define,	2 },    { "undefine", "Undefine an environment variable",						env_undefine,	1 },    { "export",	"Mark an environment variable for automatic export",						env_export,	1 },    { "unexport", "Don't mark an environment variable for automatic export",						env_unexport,	1 },    { "send",	"Send an environment variable", env_send,	1 },    { "list",	"List the current environment variables",						env_list,	0 },#if defined(OLD_ENVIRON) && defined(ENV_HACK)    { "varval", "Reverse VAR and VALUE (auto, right, wrong, status)",						env_varval,    1 },#endif    { "help",	0,				env_help,		0 },    { "?",	"Print help information",	env_help,		0 },    { 0 },};static void env_help() {    struct envlist *c;    for (c = EnvList; c->name; c++) {	if (c->help) {	    if (*c->help) printf("%-15s %s\n", c->name, c->help);	    else printf("\n");	}    }}static struct envlist *getenvcmd(char *name) {    return (struct envlist *)genget(name, (char **) EnvList, sizeof(struct envlist));}int env_cmd(int argc, char *argv[]) {    struct envlist *c;    if (argc < 2) {	fprintf(stderr, "Need an argument to 'environ' command.  'environ ?' for help.\n");	return 0;    }    c = getenvcmd(argv[1]);    if (c == 0) {	fprintf(stderr, "'%s': unknown argument ('environ ?' for help).\n", argv[1]);	return 0;    }    if (Ambiguous(c)) {	fprintf(stderr, "'%s': ambiguous argument ('environ ?' for help).\n", argv[1]);	return 0;    }        if (c->narg + 2 != argc) {	fprintf(stderr, "Need %s%d argument%s to 'environ %s' command.  'environ ?' for help.\n",		c->narg < argc + 2 ? "only " : "", c->narg, c->narg == 1 ? "" : "s", c->name);	return 0;    }    (*c->handler)(argv[2], argv[3]);    return 1;}struct env_lst {	struct env_lst *next;	/* pointer to next structure */	struct env_lst *prev;	/* pointer to previous structure */	unsigned char *var;	/* pointer to variable name */	unsigned char *value;	/* pointer to variable value */	int export;		/* 1 -> export with default list of variables */	int welldefined;	/* A well defined variable */};struct env_lst envlisthead;struct env_lst *env_find(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);    }

⌨️ 快捷键说明

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