2016-04-30 4 views
1

Есть ли способ для libedit (editline) выполнить закрытие вкладки, если я использую editline для небольшой оболочки? Кажется, что rl_parse_and_bind не доступен, если я включил histedit.h - почему он не работает?Завершена ли работа надстрочной вкладкой editline?

int main(int argc, char *argv[]) { 
    struct sigaction sh; 
    /* char *shell_prompt[100];*/ 
    sh.sa_handler = handler; 
    sigemptyset(&sh.sa_mask); 
    sh.sa_flags = 0; 
    sigaction(SIGINT, &sh, NULL); 
    int index = 0; 
    int i; 
    EditLine *el = el_init(argv[0], stdin, stdout, stderr); 
    el_set(el, EL_PROMPT_ESC, &prompt, '\1'); 
    el_set(el, EL_EDITOR, "emacs"); 
    rl_parse_and_bind("bind ^I rl_complete"); 
    HistEvent ev; 
    History *myhistory; 
    while (1) { 
     index = 0; 
     i = getopt_long(argc, argv, "p:vh", 
         options, &index); 
     if (i == -1) 
      break; 
     switch (i) { 
      case 'p': { 
       /* store_parameter(optarg); */ 
       break; 
      } 
      case 'v': { 
       printf("OpenShell version 0.1(a)\n"); 
       printf("Version: %s\n", VERSION); 
       exit(EXIT_SUCCESS); 

      } 
      case 'h': { 
       printf("Usage: ./shell\n"); 
       /*print_help();*/ 
       exit(EXIT_SUCCESS); 

      } 
      default: { 
       /* fprintf(stderr, "Error (%s): unrecognized option.\n", __FUNCTION__);*/ 
       /* print_help();*/ 
       return 1;/*RETURN_FAILURE;*/ 

      } 
     } 
    } 
    getPath(); 
    myhistory = history_init(); 
    if (myhistory == 0) { 
     fprintf(stderr, "history could not be initialized\n"); 
     return 1; 
    } 
    /* Set the size of the history */ 
    history(myhistory, &ev, H_SETSIZE, 800); 

    /* This sets up the call back functions for history functionality */ 
    el_set(el, EL_HIST, history, myhistory); 

    while (1) { 
     int count; 
     char const *line = el_gets(el, &count); 
     char *pos; 
     if (line && (pos = strchr(line, '\n')) != NULL) 
      *pos = '\0'; 
     if (line && count > 0) 
      command(line); 
     /* In order to use our history we have to explicitly add commands 
    to the history */ 
     if (count > 0) { 
      history(myhistory, &ev, H_ENTER, line); 
     } 
    } 
    el_end(el); 
    return 0; 
} 

Теперь это как мои соответствующие заголовки выглядят и, кажется, работает как с OpenBSD и Ubuntu:

#include <histedit.h> 
#ifdef linux 
#include <editline/readline.h> 
#endif 
#ifdef __OpenBSD__ 
#include <readline/readline.h> 
#endif 
+1

Обязательно должен работать, чтобы использовать 'rl_parse_and_bind' include' readline.h', почему бы не задать конкретный вопрос? – fluter

+0

@fluter Это сработало для меня, потому что я смешиваю «editline» и «readline». Если я включаю только 'histedit.h', то' rs_parse_and_bind' недоступен и 'readline.h' я включаю как' #include 'это правильно? Я не уверен, что включает в себя, если я хочу, чтобы код работал и компилировался как с OpenBSD, так и с Ubuntu. –

+1

Чтобы использовать его, вы должны '#include '. – fluter

ответ

1

Проблема была в зависимости от системы, некоторые заголовки не доступны, поэтому необходимо проверка включает в себя условные обозначения.

#if defined(__linux__) // can also use Linux here 
#include <editline/readline.h> 
#elif defined(__OpenBSD__) 
#include <readline/readline.h> 
#endif 

 Смежные вопросы

  • Нет связанных вопросов^_^