コード例 #1
0
ファイル: lineedit.cpp プロジェクト: bossjones/burro-engine
void lineedit_start(wchar_t *buf, size_t buflen, const wchar_t *prompt)
{
    memset(&l, 0, sizeof(l));

    /* Populate the linenoise state that we pass to functions implementing
     * specific editing functionalities. */
    l.buf = buf;
    l.buflen = buflen;
    l.prompt = prompt;
    l.plen = wcslen(prompt);
    l.oldpos = l.pos = 0;
    l.len = 0;
    l.cols = CONSOLE_COLS;
    l.maxrows = 0;
    l.history_index = 0;

    /* Buffer starts empty. */
    l.buf[0] = L'\0';
    l.buflen--; /* Make sure there is always space for the nulterm */

    /* The latest history entry is always our current buffer, that
     * initially is just an empty string. */
    linenoiseHistoryAdd(L"");
    refreshLine(&l);
}
コード例 #2
0
ファイル: shell.c プロジェクト: chtombleson/vault
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);
    }
}
コード例 #3
0
ファイル: websh.c プロジェクト: zhemao/websh
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;
}
コード例 #4
0
ファイル: util.c プロジェクト: svn2github/subversion
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;
}
コード例 #5
0
ファイル: repl.cpp プロジェクト: VerKnowSys/phantomjs
// 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();
    }
}
コード例 #6
0
ファイル: picocom.c プロジェクト: JamesLinus/LiteBSD-Ports
void 
add_history (char *fname)
{
	linenoiseHistoryAdd(fname);
	if (history_file_path)
		linenoiseHistorySave(history_file_path);
}
コード例 #7
0
ファイル: srepl.c プロジェクト: deepak1556/sphia-transactions
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;
}
コード例 #8
0
ファイル: redis-cli.c プロジェクト: ngmoco/redis
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);
}
コード例 #9
0
ファイル: main.c プロジェクト: paulkarabilo/lishp
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;
}
コード例 #10
0
ファイル: main.cpp プロジェクト: yl2/riposte
// 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;
}
コード例 #11
0
ファイル: lineedit.cpp プロジェクト: bossjones/burro-engine
void lineedit_stop()
{
    if (l.buflen > 0) {
        linenoiseHistoryAdd(l.buf); /* Add to the history. */
        linenoiseHistorySave("history.txt"); /* Save the history on disk. */
    }
}
コード例 #12
0
ファイル: input.c プロジェクト: saltstar/smartnix
static void addtohistory(const char* entry, size_t length) {
	// TODO(abarth): If whichprompt != 1, we should append this value to an
	// existing history entry. However, linenoise doesn't support editing the
	// history entries, so we'll probably need to refactor the input system to
	// get this behavior right.
#ifdef USE_LINENOISE
	linenoiseHistoryAdd(entry);
#endif
}
コード例 #13
0
ファイル: pers_cli.c プロジェクト: sigmond/mpl
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;
}
コード例 #14
0
ファイル: redislite-cli.c プロジェクト: diorahman/redislite
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);
}
コード例 #15
0
ファイル: lamb.c プロジェクト: sunlaobo/lamb
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;
}
コード例 #16
0
static int l_historyadd(lua_State *L)
{
    const char *line = luaL_checkstring(L, 1);

    if(! linenoiseHistoryAdd(line)) {
        return handle_ln_error(L);
    }

    return handle_ln_ok(L);
}
コード例 #17
0
ファイル: tcpServer.c プロジェクト: barrygu/mifi
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;
}
コード例 #18
0
ファイル: luna.c プロジェクト: arschles/luna
static void
repl() {
  char *line;
  while(line = linenoise("luna> ")) {
    if ('\0' != line[0]) {
      printf("%s\n", line);
      linenoiseHistoryAdd(line);
    }
    free(line);
  }
  exit(0);
}
コード例 #19
0
ファイル: example.c プロジェクト: Archer-sys/luna
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;
}
コード例 #20
0
ファイル: Console.cpp プロジェクト: joegen/oss_core
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;
}
コード例 #21
0
ファイル: sysprimitive.cpp プロジェクト: pgregory/tumbleweed
object sysPrimitive(int number, object* arguments)
{   
  ObjectHandle returnedObject = nilobj;

  /* someday there will be more here */
  switch(number - 150) {
    case 0:     /* do a system() call */
      returnedObject = newInteger(system(
            objectRef(arguments[0]).charPtr()));
      break;

    case 1: /* editline, with history support */
      {
        char* command = linenoise_nb(objectRef(arguments[0]).charPtr());
        returnedObject = newStString(command);
        if(command) 
        {
          linenoiseHistoryAdd(command);
          free(command);
        }
      }
      break;

    case 2: /* get last error */ 
      {
        returnedObject = newStString(gLastError);
      }
      break;

    case 3: /* force garbage collect */
      {
        MemoryManager::Instance()->garbageCollect();
      }
      break;

    case 4:
      {
        returnedObject = newInteger(MemoryManager::Instance()->objectCount());
      }
      break;

    case 5:
      {
        returnedObject = newStString(MemoryManager::Instance()->statsString().c_str());
      }
      break;

    default:
      sysError("unknown primitive","sysPrimitive");
  }
  return(returnedObject);
}
コード例 #22
0
ファイル: ifm.c プロジェクト: maxymania/muserex
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);
	}
}
コード例 #23
0
ファイル: example.c プロジェクト: jmckaskill/linenoise
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;
}
コード例 #24
0
ファイル: qind.c プロジェクト: bradclawsie/code
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);
}
コード例 #25
0
ファイル: linenoise.c プロジェクト: AresDice/BGCC
/* Load the history from the specified file. If the file does not exist
 * zero is returned and no operation is performed.
 *
 * If the file exists and the operation succeeded 0 is returned, otherwise
 * on error -1 is returned. */
int linenoiseHistoryLoad(char *filename) {
    FILE *fp = fopen(filename,"r");
    char buf[LINENOISE_MAX_LINE];
    
    if (fp == NULL) return -1;

    while (fgets(buf,LINENOISE_MAX_LINE,fp) != NULL) {
        char *p;
        
        p = strchr(buf,'\r');
        if (!p) p = strchr(buf,'\n');
        if (p) *p = '\0';
        linenoiseHistoryAdd(buf);
    }
    fclose(fp);
    return 0;
}
コード例 #26
0
ファイル: linenoise_sample.c プロジェクト: royalwang/sundial
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;
}
コード例 #27
0
ファイル: interactive.cpp プロジェクト: mario-campos/clay
    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);
    }
コード例 #28
0
ファイル: redis-cli.c プロジェクト: alexmchale/redis
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);
}
コード例 #29
0
ファイル: lineedit.cpp プロジェクト: bossjones/burro-engine
/* Load the history from the specified file. If the file does not exist
* zero is returned and no operation is performed.
*
* If the file exists and the operation succeeded 0 is returned, otherwise
* on error -1 is returned. */
static int linenoiseHistoryLoad(const char *filename)
{
    FILE *fp = fopen(filename,"r");
    wchar_t buf[LINENOISE_MAX_LINE];
    
    if (fp == NULL)
        return -1;

    while (fgetws(buf,LINENOISE_MAX_LINE,fp) != NULL) {
        //char *p;
        
        //p = strchr(buf,'\r');
        //if (!p) p = strchr(buf,'\n');
        //if (p) *p = '\0';
        linenoiseHistoryAdd(buf);
    }
    fclose(fp);
    return 0;
}
コード例 #30
0
ファイル: command_line.cpp プロジェクト: arn-e/circa
bool circa_get_line(caValue* lineOut)
{
#ifdef CIRCA_USE_LINENOISE
    char* input = linenoise("> ");

    if (input == NULL)
        return false;

    linenoiseHistoryAdd(input);

    set_string(lineOut, input);
    free(input);
    return true;

#else
    internal_error("This tool was built without line reader support");
#endif

    return true;
}