Added emacs mode support for maxadmin. Accepted command line switches are -e and --emacs and the .maxadmin file looks for a editor=vi|emacs parameter.
This commit is contained in:
@ -63,7 +63,7 @@ static void DoSource(int so, char *cmd);
|
|||||||
static void DoUsage();
|
static void DoUsage();
|
||||||
static int isquit(char *buf);
|
static int isquit(char *buf);
|
||||||
static void PrintVersion(const char *progname);
|
static void PrintVersion(const char *progname);
|
||||||
static void read_inifile(char **hostname, char **port, char **user, char **passwd);
|
static void read_inifile(char **hostname, char **port, char **user, char **passwd,int*);
|
||||||
|
|
||||||
#ifdef HISTORY
|
#ifdef HISTORY
|
||||||
static char *
|
static char *
|
||||||
@ -82,6 +82,7 @@ static struct option long_options[] = {
|
|||||||
{"port", required_argument, 0, 'P'},
|
{"port", required_argument, 0, 'P'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
{"help", no_argument, 0, '?'},
|
{"help", no_argument, 0, '?'},
|
||||||
|
{"emacs", no_argument, 0, 'e'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -94,6 +95,9 @@ static struct option long_options[] = {
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
const char* vi = "vi";
|
||||||
|
const char* emacs = "emacs";
|
||||||
|
|
||||||
int i, num, rv;
|
int i, num, rv;
|
||||||
#ifdef HISTORY
|
#ifdef HISTORY
|
||||||
char *buf;
|
char *buf;
|
||||||
@ -109,13 +113,14 @@ char *hostname = "localhost";
|
|||||||
char *port = "6603";
|
char *port = "6603";
|
||||||
char *user = "admin";
|
char *user = "admin";
|
||||||
char *passwd = NULL;
|
char *passwd = NULL;
|
||||||
|
int use_emacs = 0;
|
||||||
int so;
|
int so;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
read_inifile(&hostname, &port, &user, &passwd);
|
read_inifile(&hostname, &port, &user, &passwd,&use_emacs);
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "h:p:P:u:v?",
|
while ((c = getopt_long(argc, argv, "h:p:P:u:v?e",
|
||||||
long_options, &option_index))
|
long_options, &option_index))
|
||||||
>= 0)
|
>= 0)
|
||||||
{
|
{
|
||||||
@ -135,6 +140,9 @@ char c;
|
|||||||
case 'v':
|
case 'v':
|
||||||
PrintVersion(*argv);
|
PrintVersion(*argv);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
case 'e':
|
||||||
|
use_emacs = 1;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
DoUsage(*argv);
|
DoUsage(*argv);
|
||||||
exit(optopt ? EXIT_FAILURE : EXIT_SUCCESS);
|
exit(optopt ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||||
@ -224,7 +232,10 @@ char c;
|
|||||||
/* Initialize editline */
|
/* Initialize editline */
|
||||||
el = el_init(*argv, stdin, stdout, stderr);
|
el = el_init(*argv, stdin, stdout, stderr);
|
||||||
|
|
||||||
el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
|
if(use_emacs)
|
||||||
|
el_set(el, EL_EDITOR, emacs); /** Editor is emacs */
|
||||||
|
else
|
||||||
|
el_set(el, EL_EDITOR, vi); /* Default editor is vi */
|
||||||
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
|
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
|
||||||
el_set(el, EL_PROMPT, prompt);/* Set the prompt function */
|
el_set(el, EL_PROMPT, prompt);/* Set the prompt function */
|
||||||
|
|
||||||
@ -592,7 +603,7 @@ char *ptr = str + strlen(str);
|
|||||||
* @param passwd Pointer to the password to be updated
|
* @param passwd Pointer to the password to be updated
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
read_inifile(char **hostname, char **port, char **user, char **passwd)
|
read_inifile(char **hostname, char **port, char **user, char **passwd, int* editor)
|
||||||
{
|
{
|
||||||
char pathname[400];
|
char pathname[400];
|
||||||
char *home, *brkt;
|
char *home, *brkt;
|
||||||
@ -624,6 +635,17 @@ char line[400];
|
|||||||
*user = strdup(value);
|
*user = strdup(value);
|
||||||
else if (strcmp(name, "passwd") == 0)
|
else if (strcmp(name, "passwd") == 0)
|
||||||
*passwd = strdup(value);
|
*passwd = strdup(value);
|
||||||
|
else if (strcmp(name, "editor") == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(strcmp(value,"vi") == 0)
|
||||||
|
*editor = 0;
|
||||||
|
else if(strcmp(value,"emacs") == 0)
|
||||||
|
*editor = 1;
|
||||||
|
else
|
||||||
|
fprintf(stderr, "WARNING: Unrecognised "
|
||||||
|
"parameter '%s=%s' in .maxadmin file\n", name, value);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "WARNING: Unrecognised "
|
fprintf(stderr, "WARNING: Unrecognised "
|
||||||
|
Reference in New Issue
Block a user