📄 commands.c
字号:
} 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 KLUDGELINEMODE
extern int kludgelinemode;
static int
dokludgemode()
{
kludgelinemode = 1;
send_wont(TELOPT_LINEMODE, 1);
send_dont(TELOPT_SGA, 1);
send_dont(TELOPT_ECHO, 1);
}
#endif
static 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(bit, on)
int bit, 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;
}
int
setmode(bit)
{
return dolmmode(bit, 1);
}
int
clearmode(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", setmode, 1, MODE_TRAPSIG },
{ "+isig", 0, setmode, 1, MODE_TRAPSIG },
{ "-isig", "Disable signal trapping", clearmode, 1, MODE_TRAPSIG },
{ "edit", "Enable character editing", setmode, 1, MODE_EDIT },
{ "+edit", 0, setmode, 1, MODE_EDIT },
{ "-edit", "Disable character editing", clearmode, 1, MODE_EDIT },
{ "softtabs", "Enable tab expansion", setmode, 1, MODE_SOFT_TAB },
{ "+softtabs", 0, setmode, 1, MODE_SOFT_TAB },
{ "-softtabs", "Disable character editing", clearmode, 1, MODE_SOFT_TAB },
{ "litecho", "Enable literal character echo", setmode, 1, MODE_LIT_ECHO },
{ "+litecho", 0, setmode, 1, MODE_LIT_ECHO },
{ "-litecho", "Disable literal character echo", clearmode, 1, MODE_LIT_ECHO },
{ "help", 0, 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(argc, argv)
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(argc, argv)
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();
#ifdef ENCRYPTION
EncryptStatus();
#endif /* ENCRYPTION */
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(argc, argv)
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: ");
(void) fgets(buf, sizeof(buf), stdin);
arg = buf;
}
if (arg[0] != '\0')
escape = arg[0];
if (!In3270) {
printf("Escape character is '%s'.\n", control(escape));
}
(void) fflush(stdout);
return 1;
}
/*VARARGS*/
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");
(void) fflush(stdout);
return 1;
}
/*VARARGS*/
int
suspend()
{
#ifdef SIGTSTP
setcommandmode();
{
long oldrows, oldcols, newrows, newcols, err;
err = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;
(void) 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;
}
#if !defined(TN3270)
/*ARGSUSED*/
int
shell(argc, argv)
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;
extern char *strrchr();
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:
(void)wait((int *)0); /* Wait for the shell to complete */
if (TerminalWindowSize(&newrows, &newcols) && connected &&
(err || ((oldrows != newrows) || (oldcols != newcols)))) {
sendnaws();
}
break;
}
return 1;
}
#else /* !defined(TN3270) */
extern int shell();
#endif /* !defined(TN3270) */
/*VARARGS*/
static
bye(argc, argv)
int argc; /* Number of arguments */
char *argv[]; /* arguments */
{
extern int resettermname;
if (connected) {
(void) shutdown(net, 2);
printf("Connection closed.\n");
(void) NetClose(net);
connected = 0;
resettermname = 1;
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
auth_encrypt_connect(connected);
#endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
/* reset options */
tninit();
#if defined(TN3270)
SetIn3270(); /* Get out of 3270 mode */
#endif /* defined(TN3270) */
}
if ((argc != 2) || (strcmp(argv[1], "fromquit") != 0)) {
longjmp(toplevel, 1);
/* NOTREACHED */
}
return 1; /* Keep lint, etc., happy */
}
/*VARARGS*/
quit()
{
(void) call(bye, "bye", "fromquit", 0);
Exit(0);
/*NOTREACHED*/
}
/*VARARGS*/
int
logout()
{
send_do(TELOPT_LOGOUT, 1);
(void) netflush();
return 1;
}
/*
* 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(name)
char *name;
{
return (struct slclist *)
genget(name, (char **) SlcList, sizeof(struct slclist));
}
static
slccmd(argc, argv)
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)",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -