/* VTY shell main routine. */
int main (int argc, char **argv, char **env)
{
char *line;
int opt;
int eval_flag = 0;
int boot_flag = 0;
char *eval_line = NULL;
char *config_file = CONFIG_DIR "/" CONFIG_FILE;
if(getenv("VTYSH_CONFIG"))
config_file = getenv("VTYSH_CONFIG");
while (1)
{
opt = getopt_long (argc, argv, "be:c:hv", longopts, 0);
if (opt == EOF)
break;
switch (opt)
{
case 0:
break;
case 'b':
boot_flag = 1;
break;
case 'e':
eval_flag = 1;
eval_line = optarg;
break;
case 'h':
usage (argv[0], 0);
break;
case 'c':
config_file = optarg;
break;
case 'v':
printf("Ver:%s %s\n", __DATE__, __TIME__);
exit(0);
default:
usage (argv[0], 1);
break;
}
}
/* Signal and others. */
signal_init ();
/* Init config. */
config_init();
/* Init the cmd */
cmd_init();
/* Init the vtysh */
vtysh_init_vty ();
/* Install command and node view */
cmd_parse_init();
//TODO load the dynamic so
/* sort the node */
cmd_sort_node();
/* If eval mode */
if (eval_flag)
{
vtysh_execute("enable");
vtysh_execute("config terminal");
exit(vtysh_execute(eval_line));
}
/* Boot startup configuration file. */
if (boot_flag)
exit(vtysh_boot_config (config_file));
in_show_welcome();
host.config = config_file;
vtysh_load_config(config_file);
/* Main command loop. */
while ((line = vtysh_readline()) != NULL)
vtysh_execute (line);
printf ("\n");
exit (0);
}
1