/* * Use globals: * * - char *histfile_name (also sets this) * - char *last_in_history (allocates it) */ static int linphonec_initialize_readline() { /*rl_bind_key('\t', rl_insert);*/ /* Allow conditional parsing of ~/.inputrc */ rl_readline_name = "linphonec"; /* Call idle_call() every second */ rl_set_keyboard_input_timeout(LPC_READLINE_TIMEOUT); rl_event_hook=linphonec_idle_call; /* Set history file and read it */ histfile_name = ms_strdup_printf ("%s/.linphonec_history", getenv("HOME")); read_history(histfile_name); /* Initialized last_in_history cache*/ last_in_history[0] = '\0'; /* Register a completion function */ rl_attempted_completion_function = linephonec_readline_completion; /* printf("Readline initialized.\n"); */ setlinebuf(stdout); return 0; }
int main (int argc, char *argv[]) { ArgsInfo args_info = { &nm_cli, argc, argv }; /* Set up unix signal handling */ if (!setup_signals ()) exit (NMC_RESULT_ERROR_UNKNOWN); /* Set locale to use environment variables */ setlocale (LC_ALL, ""); #ifdef GETTEXT_PACKAGE /* Set i18n stuff */ bindtextdomain (GETTEXT_PACKAGE, NMCLI_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif nm_g_type_init (); /* Save terminal settings */ tcgetattr (STDIN_FILENO, &termios_orig); /* readline init */ rl_event_hook = event_hook_for_readline; /* Set 0.01s timeout to mitigate slowness in readline when a broken version is used. * See https://bugzilla.redhat.com/show_bug.cgi?id=1109946 */ rl_set_keyboard_input_timeout (10000); nmc_value_transforms_register (); nmc_init (&nm_cli); g_idle_add (start, &args_info); loop = g_main_loop_new (NULL, FALSE); /* create main loop */ g_main_loop_run (loop); /* run main loop */ if (nm_cli.complete) nm_cli.return_value = NMC_RESULT_SUCCESS; /* Print result descripting text */ if (nm_cli.return_value != NMC_RESULT_SUCCESS) { g_printerr ("%s\n", nm_cli.return_text->str); } g_main_loop_unref (loop); nmc_cleanup (&nm_cli); return nm_cli.return_value; }
int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) { char *ptr, *pbuf, **ap, *__argv[EXEC_ARG_SIZE]; int __argc, rc=0; rl_readline_name = "ipmitool"; /* this essentially disables command completion * until its implemented right, otherwise we get * the current directory contents... */ rl_bind_key('\t', rl_insert); if (intf->keepalive) { /* hook to keep lan sessions active */ shell_intf = intf; rl_event_hook = rl_event_keepalive; #if defined(RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0402 /* There is a bug in readline 4.2 and later (at least on FreeBSD and NetBSD): * timeout equal or greater than 1 second causes an infinite loop. */ rl_set_keyboard_input_timeout(1000 * 1000 - 1); #endif } while ((pbuf = (char *)readline(RL_PROMPT)) != NULL) { if (strlen(pbuf) == 0) { free(pbuf); continue; } if (strncmp(pbuf, "quit", 4) == 0 || strncmp(pbuf, "exit", 4) == 0) { free(pbuf); return 0; } if (strncmp(pbuf, "help", 4) == 0 || strncmp(pbuf, "?", 1) == 0) { ipmi_cmd_print(intf->cmdlist); free(pbuf); continue; } /* for the all-important up arrow :) */ add_history(pbuf); /* change "" and '' with spaces in the middle to ~ */ ptr = pbuf; while (*ptr != '\0') { if (*ptr == '"') { ptr++; while (*ptr != '"') { if (isspace((int)*ptr)) *ptr = '~'; ptr++; } } if (*ptr == '\'') { ptr++; while (*ptr != '\'') { if (isspace((int)*ptr)) *ptr = '~'; ptr++; } } ptr++; } __argc = 0; ap = __argv; for (*ap = strtok(pbuf, " \t"); *ap != NULL; *ap = strtok(NULL, " \t")) { __argc++; ptr = *ap; if (*ptr == '\'') { memmove(ptr, ptr+1, strlen(ptr)); while (*ptr != '\'') { if (*ptr == '~') *ptr = ' '; ptr++; } *ptr = '\0'; } if (*ptr == '"') { memmove(ptr, ptr+1, strlen(ptr)); while (*ptr != '"') { if (*ptr == '~') *ptr = ' '; ptr++; } *ptr = '\0'; } if (**ap != '\0') { if (++ap >= &__argv[EXEC_ARG_SIZE]) break; } } if (__argc && __argv[0]) rc = ipmi_cmd_run(intf, __argv[0], __argc-1, &(__argv[1])); free(pbuf); } printf("\n"); return rc; }