add togglevar for options.

This commit is contained in:
Kelvin Sherlock 2012-09-08 16:59:25 -04:00
parent be00396c26
commit b5dc0fa710

View File

@ -46,6 +46,26 @@ extern char reply_string[];
char *mname;
jmp_buf jabort;
/*
* Toggle a variable
*/
int togglevar(int argc, char ** argv, int *var, const char *mesg)
{
if (argc < 2) {
*var = !*var;
} else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
*var = 1;
} else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
*var = 0;
} else {
printf("usage: %s [ on | off ]\n", argv[0]);
return (-1);
}
if (mesg)
printf("%s %s.\n", mesg, onoff(*var));
return (*var);
}
/*
* `Another' gets another argument, and stores the new argc and argv.
* It reverts to the top level (via main.c's intr()) on EOF/error.
@ -830,9 +850,7 @@ int i;
/*VARARGS*/
void setbell (int argc, char **argv)
{
bell = !bell;
printf("Bell mode %s.\n", onoff(bell));
code = bell;
code = togglevar(argc, argv, &bell, "Bell mode");
}
/*
@ -841,9 +859,7 @@ void setbell (int argc, char **argv)
/*VARARGS*/
void settrace (int argc, char **argv)
{
trace = !trace;
printf("Packet tracing %s.\n", onoff(trace));
code = trace;
code = togglevar(argc, argv, &trace, "Packet tracing");
}
/*
@ -866,9 +882,7 @@ void sethash (int argc, char **argv)
/*VARARGS*/
void setverbose (int argc, char **argv)
{
verbose = !verbose;
printf("Verbose mode %s.\n", onoff(verbose));
code = verbose;
code = togglevar(argc, argv, &verbose, "Verbose mode");
}
/*
@ -877,9 +891,7 @@ void setverbose (int argc, char **argv)
/*VARARGS*/
void setport (int argc, char **argv)
{
sendport = !sendport;
printf("Use of PORT cmds %s.\n", onoff(sendport));
code = sendport;
code = togglevar(argc, argv, &sendport, "Use of PORT cmds");
}
/*
@ -889,9 +901,7 @@ void setport (int argc, char **argv)
/*VARARGS*/
void setprompt (int argc, char **argv)
{
interactive = !interactive;
printf("Interactive mode %s.\n", onoff(interactive));
code = interactive;
code = togglevar(argc, argv, &interactive, "Interactive mode");
}
/*
@ -901,9 +911,7 @@ void setprompt (int argc, char **argv)
/*VARARGS*/
void setglob (int argc, char **argv)
{
doglob = !doglob;
printf("Globbing %s.\n", onoff(doglob));
code = doglob;
code = togglevar(argc, argv, &doglob, "Globbing");
}
/*
@ -1846,16 +1854,12 @@ LOOP:
void setsunique (int argc, char **argv)
{
sunique = !sunique;
printf("Store unique %s.\n", onoff(sunique));
code = sunique;
code = togglevar(argc, argv, &sunique, "Store unique");
}
void setrunique (int argc, char **argv)
{
runique = !runique;
printf("Receive unique %s.\n", onoff(runique));
code = runique;
code = togglevar(argc, argv, &runique, "Receive unique");
}
/* change directory to perent directory */