Beispiel #1
0
int
read_baud (void)
{
	char *baudstr, *ep;
	int baud = -1;

	do {
		fd_printf(STO, "\r\n");
		baudstr = linenoise("*** baud: ");
		fd_printf(STO, "\r");
		if ( baudstr == NULL )
			break;
		baud = strtol(baudstr, &ep, 0);
		if ( ! ep || *ep != '\0' || ! term_baud_ok(baud) || baud == 0 ) {
			fd_printf(STO, "*** Invalid baudrate!");
			baud = -1;
		}
		free(baudstr);
	} while (baud < 0);

	if (baudstr != NULL)
		add_history(baudstr);

	return baud;
}
Beispiel #2
0
// interactive line entry using linenoise
static bool terminal(State& state, std::istream & in, std::ostream & out, Value& code)
{ 
    std::string input;
    code = Value::Nil();

    int status = 0;
    while(status == 0)
    {
        char* line = linenoise( input.size() == 0 ? "> " : "+ " );

        if(line == 0)
            return true;

        input += line;

        if(line[0] != '\0') {
            linenoiseHistoryAdd(line);
            linenoiseHistorySave((char*)".riposte_history");
        }

        free(line);
        
        input += "\n";   /* add the discarded newline back in */
        
        if(input.size() > 0) {
            Parser parser(state);
            status = parser.execute(input.c_str(), input.size(), true, code);    
        }
    }

    if (status == -1)
        code = Value::Nil();

    return false;
}
Beispiel #3
0
// private slots:
void REPL::startLoop()
{
    char* userInput;

    // Load REPL history
    linenoiseHistoryLoad(m_historyFilepath.data());         //< requires "char *"
    while (m_looping && (userInput = linenoise(PROMPT)) != NULL) {
        if (userInput[0] != '\0') {
            // Send the user input to the main Phantom frame for evaluation
            m_webframe->evaluateJavaScript(
                QString(JS_EVAL_USER_INPUT).arg(
                    QString(userInput).replace('"', "\\\"")));

            // Save command in the REPL history
            linenoiseHistoryAdd(userInput);
            linenoiseHistorySave(m_historyFilepath.data()); //< requires "char *"
        }
        free(userInput);
    }

    // If still "looping", close Phantom (usually caused by "CTRL+C" / "CTRL+D")
    if (m_looping) {
        m_parentPhantom->exit();
    }
}
Beispiel #4
0
int main(int argc, char *argv[]) {
	char *line, *url;
	if(argc < 2){
		fprintf(stderr, "Usage: %s url\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	
	headers = create_map();
	
	url = argv[1];
	char prompt[strlen(url)+3];
	sprintf(prompt, "%s> ", url);
	
	linenoiseSetCompletionCallback(completionCallback);

	while((line = linenoise(prompt)) != NULL) {
		if(strcmp(line, "exit")==0)
			break;
		if (line[0] != '\0') {
			linenoiseHistoryAdd(line);
			handle_input(url, line);
		}
		
		free(line);
	}
	
	return 0;
}
Beispiel #5
0
int main(int argc, char **argv) {
    mpc_parser_t *plisp = plisp_set_grammar();
    puts("PLisp v.0.0.0.1."); //Pablo Lisp lol
    puts("Press Ctrl-C to exit.");
    global = new_lenv(128);
    lenv_add_builtins(global);
    while ((input = linenoise("mylsp> ")) != NULL) {
        if (input[0] != '\0') {
        	mpc_result_t r;
			linenoiseHistoryAdd(input);
			if ((mpc_parse("<stdin>", input, plisp, &r))) {
				lval *val = lval_eval(global, lval_read(r.output));
				lval_println(val);
				lval_del(val);
				mpc_ast_delete(r.output);
			} else {
				mpc_err_print(r.error);
				mpc_err_delete(r.error);
			}
        }
        free(input);
    }

    lenv_del(global);
    plisp_cleanup_grammar();
    return 0;
}
Beispiel #6
0
void shell_run() {
    shell_running = 1;

    printf("Vault version %s\n", VAULT_VERSION);
    printf("Enter \"help\" for list of commands\n");

    char *line;

    while(shell_running) {
        while ((line = linenoise("vault> ")) != 0) {
            if (line[0] != '\0') {
                printf("%s", line);
                linenoiseHistoryAdd(line);

                if (line == SHELL_ACTION_HELP) {

                }

                if (line == SHELL_ACTION_EXIT) {
                    shell_close();
                }
            }
        }

        free(line);
    }
}
Beispiel #7
0
static void repl() {
    int argc, j;
    char *line, **argv;

    while((line = linenoise("redis> ")) != NULL) {
        if (line[0] != '\0') {
            argv = splitArguments(line,&argc);
            linenoiseHistoryAdd(line);
            if (argc > 0) {
                if (strcasecmp(argv[0],"quit") == 0 ||
                    strcasecmp(argv[0],"exit") == 0)
                        exit(0);
                else
                    cliSendCommand(argc, argv, 1);
            }
            /* Free the argument vector */
            for (j = 0; j < argc; j++)
                sdsfree(argv[j]);
            zfree(argv);
        }
        /* linenoise() returns malloc-ed lines like readline() */
        free(line);
    }
    exit(0);
}
Beispiel #8
0
int
srepl_init (sphia_t *sphia, cmd_t *cmds, opt_t *opts) {
  int rc = 0;
  char *line;

  linenoiseSetCompletionCallback(completion);
  
  linenoiseHistoryLoad("history.txt");

  while((line = linenoise("sphia> ")) != NULL) {
    for(size_t i = 0; i < sizeof(*cmds) / sizeof(cmds[0]); i++) {
      if(0 == strcmp(cmds[i].name, line) || 
        (NULL != cmds[i].alt && 0 == strcmp(cmds[i].alt, line))) {
       if(0 == strcmp(cmds[i].name, "set")) {
           parse_args(line, opts);
       }

       if(NULL != cmds[i].func) {
         if(0 == (rc = cmds[i].func(sphia, opts))) {
           linenoiseHistoryAdd(line);
           linenoiseHistorySave("History.txt");
         }else {
        
         }
       }
     }
   }
      
    free(line);
  }
  
  return rc;
}
Beispiel #9
0
svn_error_t *
svnmover_prompt_user(const char **result,
                     const char *prompt_str,
                     apr_pool_t *pool)
{
#ifdef HAVE_LINENOISE
  char *input;

  input = linenoise(prompt_str);
  if (! input)
    {
      return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
    }
  /* add the line to the recallable history (if non-empty) */
  if (input && *input)
    {
      linenoiseHistoryAdd(input);
    }
  *result = apr_pstrdup(pool, input);
  free(input);
#else
  SVN_ERR(svn_cmdline_prompt_user2(result, prompt_str, NULL, pool));
#endif
  return SVN_NO_ERROR;
}
Beispiel #10
0
char * prepare_post(CURL * curl){
	char * data;
	curl_easy_setopt(curl, CURLOPT_POST, 1);
	data = linenoise("...");
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
	return data;
}
Beispiel #11
0
static int readlines(void) {
    char *line;
    mpl_list_t *reqMsg = NULL;
    int quit = 0;
    mpl_list_t *tmp;

    completionStrings = calloc(maxStrings, sizeof(char *));

    while((line = linenoise("PERS> ")) != NULL) {
        if (line[0] != '\0') {
            if (strcmp(line,"quit") && strncmp(line, "help ", 5)) {
                char *req;
                int ret = -1;
                req = formatCmdLine(line, "Req");
                reqMsg = mpl_param_list_unpack_param_set(req, PERSONNEL_PARAM_SET_ID);
                if (!reqMsg) {
                    printf("Protocol error\n");
                    ret = -1;
                }
                else if (checkCommand(reqMsg) == 0) {
                    ret = pack_and_send(reqMsg);
                }
                mpl_param_list_destroy(&reqMsg);
                free(req);
                if (ret == 0) {
                    fgets(buf, 1024, fi);
                    printf("%s\n", buf);
                }
            }
            else if (!strncmp(line, "help ", 5)) {
                char *helptext;
                persfile_get_command_help(line, &helptext);
                if (helptext != NULL) {
                    printf("%s", helptext);
                    free(helptext);
                }
                else
                    printf("No help\n");
            }
            else {
                quit = 1;
            }
            linenoiseHistoryAdd(line);
            linenoiseHistorySave("history.txt"); /* Save every new entry */
            free(line);
            while ((tmp = mpl_list_remove(&completionCallstack, NULL)) != NULL) {
                completion_callstack_entry_t *e;
                e = MPL_LIST_CONTAINER(tmp, completion_callstack_entry_t, list_entry);
                free(e);
            }
        }
        if (quit)
            break;
    }
    free(completionStrings);
    return 0;
}
Beispiel #12
0
static void repl()
{
	int argc, j;
	char *line;
	sds *argv;

	config.interactive = 1;
	linenoiseSetCompletionCallback(completionCallback);

	while((line = linenoise(db ? "redislite> " : "not connected> ")) != NULL) {
		if (line[0] != '\0') {
			argv = sdssplitargs(line, &argc);
			linenoiseHistoryAdd(line);
			if (config.historyfile) {
				linenoiseHistorySave(config.historyfile);
			}
			if (argv == NULL) {
				printf("Invalid argument(s)\n");
				continue;
			}
			else if (argc > 0) {
				if (strcasecmp(argv[0], "quit") == 0 ||
				        strcasecmp(argv[0], "exit") == 0) {
					exit(0);
				}
				else if (argc == 1 && !strcasecmp(argv[0], "clear")) {
					linenoiseClearScreen();
				}
				else {
					long long start_time = mstime(), elapsed;

					if (cliSendCommand(argc, argv, 1) != REDISLITE_OK) {
						cliConnect(1);

						/* If we still cannot send the command,
						 * print error and abort. */
						if (cliSendCommand(argc, argv, 1) != REDISLITE_OK) {
							cliPrintContextErrorAndExit();
						}
					}
					elapsed = mstime() - start_time;
					if (elapsed >= 500) {
						printf("(%.2fs)\n", (double)elapsed / 1000);
					}
				}
			}
			/* Free the argument vector */
			for (j = 0; j < argc; j++) {
				sdsfree(argv[j]);
			}
			redislite_free(argv);
		}
		/* linenoise() returns malloc-ed lines like readline() */
		free(line);
	}
	exit(0);
}
Beispiel #13
0
void run_cmdline_loop(repl_t *repl, JSContextRef ctx) {
    while (true) {
        char *input_line = NULL;

        if (config.dumb_terminal) {
            display_prompt(repl->current_prompt);
            input_line = get_input();
            if (input_line == NULL) { // Ctrl-D pressed
                printf("\n");
                break;
            }
        } else {
            // Handle prints while processing linenoise input
            if (cljs_engine_ready) {
                cljs_set_print_sender(ctx, &linenoisePrintNow);
            }

            // If *print-newline* is off, we need to emit a newline now, otherwise
            // the linenoise prompt and line editing will overwrite any printed
            // output on the current line.
            if (cljs_engine_ready && !cljs_print_newline(ctx)) {
                fprintf(stdout, "\n");
            }

            char *line = linenoise(repl->current_prompt, prompt_ansi_code_for_theme(config.theme),
                                   repl->indent_space_count);

            // Reset printing handler back
            if (cljs_engine_ready) {
                cljs_set_print_sender(ctx, NULL);
            }

            repl->indent_space_count = 0;
            if (line == NULL) {
                if (errno == EAGAIN) { // Ctrl-C
                    errno = 0;
                    repl->input = NULL;
                    empty_previous_lines(repl);
                    repl->current_prompt = form_prompt(repl->current_ns, false);
                    printf("\n");
                    continue;
                } else { // Ctrl-D
                    exit_value = EXIT_SUCCESS_INTERNAL;
                    break;
                }
            }

            input_line = line;
        }

        bool break_out = process_line(repl, ctx, input_line);
        if (break_out) {
            break;
        }
    }
}
Beispiel #14
0
int main(void) {
    char *line;
    config_t config = loadConfiguration("./conf/config");
    
    while((line = linenoise("nosh: ")) != NULL) {
        parms = parse(line, config);
        exec(parms, config);
    }
    free(line);
}
Beispiel #15
0
int main(int UNUSED(argc), char *argv[]) 
{
//	int i;
    const int num_threads = 2;
	pthread_t tid[num_threads];
//	void *status;
	struct listen_param lis_para;
	struct send_param send_para;
    char *line;

    //mtrace();
    que_msg = CreateQueue(100);
    sem_init(&sem_msg, 0, 0);

	memset(&dev_map, 0, sizeof(dev_map));

	lis_para.port = SERVER_PORT;
	lis_para.receive_thread = receive_thread;
	pthread_create(&tid[0], NULL, listen_thread, &lis_para);
	
	send_para.que_msg = que_msg;
	send_para.mutex_msg = &mutex_msg;
	send_para.sem_msg = &sem_msg;
    pthread_create(&tid[1], NULL, send_thread, &send_para);

    linenoiseHistoryLoad("hist-srv.txt"); /* Load the history at startup */
    while((line = linenoise("srv> ")) != NULL) {
        /* Do something with the string. */
        if (line[0] != '\0' && line[0] != '/') {
            //printf("echo: '%s'\n", line);
            linenoiseHistoryAdd(line); /* Add to the history. */
            linenoiseHistorySave("hist-srv.txt"); /* Save the history on disk. */
            cmd_handle(0, line);
        } else if (!strncmp(line,"/q",2)) {
        	free(line);
        	break;
        } else if (!strncmp(line,"/historylen",11)) {
            /* The "/historylen" command will change the history len. */
            int len = atoi(line+11);
            linenoiseHistorySetMaxLen(len);
        } else if (line[0] == '/') {
            printf("Unreconized command: %s\n", line);
        } else {
        	printf("\n");
        }
        free(line);
    }

//	for (i = 0; i < num_threads; i++)
//		pthread_join(tid[i],&status); 
		
	return 0;
}
Beispiel #16
0
std::string Console::prompt(const std::string& message)
{
  std::string ret;
  char* line = linenoise(message.c_str());
  if (line)
  {
    ret = line;
    linenoiseHistoryAdd(line);
  }
  free(line);
  return ret;
}
Beispiel #17
0
static int line_noise_run(int argc, char **argv) {
	char buf[BUF_SIZE];
	struct hist h;
	linenoise_history_init(&h);
	linenoise_history_add("history1", &h);
	linenoise_history_add("history2", &h);
	linenoise("enter string> ", buf, BUF_SIZE, &h, (compl_callback_t) compl);

	printf("You've entered %s.\n", buf);

	return ENOERR;
}
Beispiel #18
0
int main(int argc, char *argv[]) {
    char *line;
#ifdef HAVE_MULTILINE
    /* Note: multiline support has not yet been integrated */
    char *prgname = argv[0];

    /* Parse options, with --multiline we enable multi line editing. */
    while(argc > 1) {
        argc--;
        argv++;
        if (!strcmp(*argv,"--multiline")) {
            linenoiseSetMultiLine(1);
            printf("Multi-line mode enabled.\n");
        } else {
            fprintf(stderr, "Usage: %s [--multiline]\n", prgname);
            exit(1);
        }
    }
#endif

#ifndef NO_COMPLETION
    /* Set the completion callback. This will be called every time the
     * user uses the <tab> key. */
    linenoiseSetCompletionCallback(completion);
#endif

    /* Load history from file. The history file is just a plain text file
     * where entries are separated by newlines. */
    linenoiseHistoryLoad("history.txt"); /* Load the history at startup */

    /* Now this is the main loop of the typical linenoise-based application.
     * The call to linenoise() will block as long as the user types something
     * and presses enter.
     *
     * The typed string is returned as a malloc() allocated string by
     * linenoise, so the user needs to free() it. */
    while((line = linenoise("hello> ")) != NULL) {
        /* Do something with the string. */
        if (line[0] != '\0' && line[0] != '/') {
            printf("echo: '%s'\n", line);
            linenoiseHistoryAdd(line); /* Add to the history. */
            linenoiseHistorySave("history.txt"); /* Save the history on disk. */
        } else if (!strncmp(line,"/historylen",11)) {
            /* The "/historylen" command will change the history len. */
            int len = atoi(line+11);
            linenoiseHistorySetMaxLen(len);
        } else if (line[0] == '/') {
            printf("Unreconized command: %s\n", line);
        }
        free(line);
    }
    return 0;
}
Beispiel #19
0
static void
repl() {
  char *line;
  while(line = linenoise("luna> ")) {
    if ('\0' != line[0]) {
      printf("%s\n", line);
      linenoiseHistoryAdd(line);
    }
    free(line);
  }
  exit(0);
}
Beispiel #20
0
char *
read_filename (void)
{
	char *fname;
	linenoiseSetCompletionCallback(file_completion_cb);
	fd_printf(STO, "\r\n");
	fname = linenoise("*** file: ");
	fd_printf(STO, "\r");
	linenoiseSetCompletionCallback(NULL);
	if (fname != NULL)
		add_history(fname);
	return fname;
}
Beispiel #21
0
char * prepare_put(CURL * curl, upload_buffer * upbuf){
	char * data;
	
	curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
	data = linenoise("...");
	upbuf->data = data;
	upbuf->index = 0;
	upbuf->length = strlen(data);
	curl_easy_setopt(curl, CURLOPT_READDATA, upbuf);
	curl_easy_setopt(curl, CURLOPT_READFUNCTION, handle_upload);
	
	return data;
}
Beispiel #22
0
int main(int argc,const string_t* argv){
	sh_prompt_update();
	//linenoiseHistorySetMaxLen(10);
	sh_initAutoComplete();
	string_t line;
	sds prcdLn;
	while((line = linenoise(sh_prompt())) != NULL) {
		linenoiseHistoryAdd(line);
		//prcdLn = sh_expand_string(line);
		sh_system(line);
		free(cPTR line);
		//sh_system(prcdLn);
		//sdsfree(prcdLn);
	}
}
Beispiel #23
0
int main(void) {
    char buf[1024];
    int retval;

    while(1) {
        retval = linenoise(buf,1024,"hello> ");
        if (retval > 0) {
            printf("echo: '%s'\n", buf);
            linenoiseHistoryAdd(buf);
        } else if (retval == -1) {
            exit(1);
        }
    }
    return 0;
}
Beispiel #24
0
int main(void) {

    setlocale(LC_ALL, "");

    signal(SIGINT,  sig);
    signal(SIGQUIT, sig);
    signal(SIGHUP,  sig);
    signal(SIGTERM, sig);

    linenoiseSetCompletionCallback(completion);

    char *home_dir = getenv("HOME");
    assert(home_dir != NULL);

    char *histfile_path = get_hist_path(home_dir);
    if (NULL == histfile_path) {
        fprintf(stderr,"cannot determine history file path\n");
        exit(EXIT_FAILURE);
    }
    printf("history file: %s\n",histfile_path); 

    linenoiseHistoryLoad(histfile_path); 

    char *line;
    cmd_request *cr;
    while((line = linenoise("qind> ")) != NULL) {
        if (strncmp(line,"",MAX_CMD_LEN) == 0) {
            continue;
        }
        cr = new_cmd_request(line);
        if (NULL == cr) {
            fprintf(stderr,"could not make cmd_request\n");
            exit(EXIT_FAILURE);
        } 
        dump_cmd_request(cr);
        if (strncmp(QUIT_CMD,line,MAX_CMD_LEN) == 0) {
            printf("<quitting>\n");
            break;
        }
        linenoiseHistoryAdd(cr->request);
        destroy_cmd_request(cr);
        free(line);
    }

    linenoiseHistorySave(histfile_path); 
    free(histfile_path);
    exit(EXIT_SUCCESS);
}
static int l_linenoise(lua_State *L)
{
    const char *prompt = luaL_checkstring(L, 1);
    const char *line;

    completion_state = L;
    line = linenoise(prompt);
    completion_state = NULL;

    if(! line) {
        return handle_ln_error(L);
    }
    lua_pushstring(L, line);
    free(line);
    return 1;
}
/**
 * Returns an allocated line, or NULL if EOF.
 */
char *Jim_HistoryGetline(const char *prompt)
{
#ifdef USE_LINENOISE
    return linenoise(prompt);
#else
    char *line = malloc(MAX_LINE_LEN);

    fputs(prompt, stdout);
    fflush(stdout);

    if (fgets(line, MAX_LINE_LEN, stdin) == NULL) {
        free(line);
        return NULL;
    }
    return line;
#endif
}
Beispiel #27
0
int 
main(int argc, char *argv[]) 
{
    char *line;

    linenoiseSetCompletionCallback(completion);
    linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
    while((line = linenoise("hello> ")) != NULL) {
        if (line[0] != '\0') {
            printf("echo: '%s'\n", line);
            linenoiseHistoryAdd(line);
            linenoiseHistorySave("history.txt"); /* Save every new entry */
        }
        free(line);
    }
    return 0;
}
Beispiel #28
0
int main(int argc, char *argv[]) {
    int err;
    char *host = "127.0.0.1";
    int port = 1276;
    char *prompt = "lamb";

    /* Signal event processing */
    lamb_signal_processing();
    
    /* Start main event thread */
    int sock;
    err = lamb_sock_connect(&sock, host, port);
    if (err) {
        fprintf(stderr, "Can't connect to %s server\n", host);
        return -1;
    }

    char *line;
    char *prgname = argv[0];

    linenoiseSetCompletionCallback(completion);
    linenoiseSetHintsCallback(hints);
    linenoiseHistoryLoad(".lamb_history");
    linenoiseHistorySetMaxLen(1000);
    
    while((line = linenoise("lamb> ")) != NULL) {
        /* Do something with the string. */
        if (line[0] != '\0') {
            printf("echo: %s\n", line);
            linenoiseHistoryAdd(line);
            linenoiseHistorySave(".lamb_history");
        } else if (line[0] != '\0' && !strncmp(line, "show client", 11)) {
            int id = atoi(line + 11);
            lamb_show_client(sock, id);
            linenoiseHistoryAdd(line);
            linenoiseHistorySave(".lamb_history");
        } else if (line[0] != '\0') {
            printf("Unknown Command: '%s'\n", line);
        }
        free(line);
    }

    return 0;
}
Beispiel #29
0
    static void interactiveLoop()
    {
        setjmp(recovery);
        linenoiseSetMultiLine(1);
        linenoiseHistorySetMaxLen(100);

        char *buf;
        while ((buf = linenoise("clay> ")) != NULL) {
            linenoiseHistoryAdd(buf);
            string line = stripSpaces(buf);
            if (line[0] == ':') {
                replCommand(line.substr(1, line.size() - 1));
            } else {
                eval(line);
            }
            free(buf);
        }
        engine->runStaticConstructorsDestructors(true);
    }
Beispiel #30
0
static void repl() {
    int argc, j;
    char *line;
    sds *argv;

    config.interactive = 1;
    while((line = linenoise("redis> ")) != NULL) {
        if (line[0] != '\0') {
            argv = sdssplitargs(line,&argc);
            linenoiseHistoryAdd(line);
            if (config.historyfile) linenoiseHistorySave(config.historyfile);
            if (argv == NULL) {
                printf("Invalid argument(s)\n");
                continue;
            } else if (argc > 0) {
                if (strcasecmp(argv[0],"quit") == 0 ||
                    strcasecmp(argv[0],"exit") == 0)
                {
                    exit(0);
                } else {
                    int err;

                    if ((err = cliSendCommand(argc, argv, 1)) != 0) {
                        if (err == ECONNRESET) {
                            printf("Reconnecting... ");
                            fflush(stdout);
                            if (cliConnect(1) == -1) exit(1);
                            printf("OK\n");
                            cliSendCommand(argc,argv,1);
                        }
                    }
                }
            }
            /* Free the argument vector */
            for (j = 0; j < argc; j++)
                sdsfree(argv[j]);
            zfree(argv);
        }
        /* linenoise() returns malloc-ed lines like readline() */
        free(line);
    }
    exit(0);
}