Changeset 56c7e9dd00981d9018a28e7adf1fb6144821c51e

Show
Ignore:
Timestamp:
03/13/09 05:41:58 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1236922918 +0000
git-parent:

[83ae07dae4f92f9cea49d1ab26f4e6a92fbe8db9]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1236922918 +0000
Message:

refs #37... lots of progress here

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/Makefile.in

    r27a81dc r56c7e9d  
    3636NOIT_OBJS=noitd.o noit_listener.o \ 
    3737        noit_console.o noit_console_state.o noit_console_telnet.o \ 
     38        noit_console_complete.o \ 
    3839        noit_check.o noit_check_log.o noit_check_tools.o \ 
    3940        noit_module.o noit_conf.o noit_conf_checks.o noit_tokenizer.o \ 
     
    4243STRATCON_OBJS=stratcond.o noit_listener.o \ 
    4344        noit_console.o noit_console_state.o noit_console_telnet.o \ 
     45        noit_console_complete.o \ 
    4446        noit_conf.o noit_http.o noit_tokenizer.o \ 
    4547        stratcon_realtime_http.o \ 
  • src/noit_check.c

    r84d6f13 r56c7e9d  
    887887 
    888888  noit_console_state_add_cmd(showcmd->dstate, 
    889     NCSCMD("checks", noit_console_show_checks, NULL, NULL)); 
    890 } 
    891  
     889    NCSCMD("checks", noit_console_show_checks, NULL, NULL, NULL)); 
     890} 
     891 
  • src/noit_conf_checks.c

    r057e0c6 r56c7e9d  
    5757      i++) { 
    5858    noit_console_state_add_cmd(state, 
    59       NCSCMD(valid_attrs[i].name, f, 
     59      NCSCMD(valid_attrs[i].name, f, NULL, 
    6060             NULL, &valid_attrs[i])); 
    6161  } 
     
    12881288 
    12891289#define NEW_STATE(a) (a) = noit_console_state_alloc() 
    1290 #define ADD_CMD(a,cmd,func,ss,c) \ 
     1290#define ADD_CMD(a,cmd,func,ac,ss,c) \ 
    12911291  noit_console_state_add_cmd((a), \ 
    1292     NCSCMD(cmd, func, ss, c)) 
    1293 #define DELEGATE_CMD(a,cmd,ss) \ 
     1292    NCSCMD(cmd, func, ac, ss, c)) 
     1293#define DELEGATE_CMD(a,cmd,ac,ss) \ 
    12941294  noit_console_state_add_cmd((a), \ 
    1295     NCSCMD(cmd, noit_console_state_delegate, ss, NULL)) 
     1295    NCSCMD(cmd, noit_console_state_delegate, ac, ss, NULL)) 
    12961296 
    12971297static 
     
    13071307  /* write <terimal|memory|file> */ 
    13081308  NEW_STATE(_write_state); 
    1309   ADD_CMD(_write_state, "terminal", noit_conf_write_terminal, NULL, NULL); 
    1310   ADD_CMD(_write_state, "file", noit_conf_write_file, NULL, NULL); 
     1309  ADD_CMD(_write_state, "terminal", noit_conf_write_terminal, NULL, NULL, NULL); 
     1310  ADD_CMD(_write_state, "file", noit_conf_write_file, NULL, NULL, NULL); 
    13111311  /* write memory?  It's to a file, but I like router syntax */ 
    1312   ADD_CMD(_write_state, "memory", noit_conf_write_file, NULL, NULL); 
     1312  ADD_CMD(_write_state, "memory", noit_conf_write_file, NULL, NULL, NULL); 
    13131313 
    13141314  /* attribute <attrname> <value> */ 
     
    13211321 
    13221322  NEW_STATE(_unset_state); 
    1323   DELEGATE_CMD(_unset_state, "attribute", _uattr_state); 
    1324   ADD_CMD(_unset_state, "section", noit_console_config_section, NULL, (void *)1); 
    1325   ADD_CMD(_unset_state, "config", noit_console_config_unsetconfig, NULL, NULL); 
    1326   ADD_CMD(_unset_state, "check", noit_console_config_nocheck, NULL, NULL); 
     1323  DELEGATE_CMD(_unset_state, "attribute", noit_console_opt_delegate, _uattr_state); 
     1324  ADD_CMD(_unset_state, "section", noit_console_config_section, NULL, NULL, (void *)1); 
     1325  ADD_CMD(_unset_state, "config", noit_console_config_unsetconfig, NULL, NULL, NULL); 
     1326  ADD_CMD(_unset_state, "check", noit_console_config_nocheck, NULL, NULL, NULL); 
    13271327  
    13281328  NEW_STATE(_conf_t_check_state); 
    13291329  _conf_t_check_state->console_prompt_function = conf_t_check_prompt; 
    1330   DELEGATE_CMD(_conf_t_check_state, "attribute", _attr_state); 
    1331   DELEGATE_CMD(_conf_t_check_state, "no", _unset_state); 
    1332   ADD_CMD(_conf_t_check_state, "config", noit_console_config_setconfig, NULL, NULL); 
    1333   ADD_CMD(_conf_t_check_state, "status", noit_console_show_check, NULL, NULL); 
    1334   ADD_CMD(_conf_t_check_state, "exit", noit_console_config_cd, NULL, ".."); 
    1335   ADD_CMD(_conf_t_check_state, "check", noit_console_check, _conf_t_check_state, ".."); 
     1330  DELEGATE_CMD(_conf_t_check_state, "attribute", noit_console_opt_delegate, _attr_state); 
     1331  DELEGATE_CMD(_conf_t_check_state, "no", noit_console_opt_delegate, _unset_state); 
     1332  ADD_CMD(_conf_t_check_state, "config", noit_console_config_setconfig, NULL, NULL, NULL); 
     1333  ADD_CMD(_conf_t_check_state, "status", noit_console_show_check, NULL, NULL, NULL); 
     1334  ADD_CMD(_conf_t_check_state, "exit", noit_console_config_cd, NULL, NULL, ".."); 
     1335  ADD_CMD(_conf_t_check_state, "check", noit_console_check, NULL, _conf_t_check_state, ".."); 
    13361336 
    13371337  NEW_STATE(_conf_t_state);  
    13381338  _conf_t_state->console_prompt_function = conf_t_prompt; 
    13391339  noit_console_state_add_cmd(_conf_t_state, &console_command_exit); 
    1340   ADD_CMD(_conf_t_state, "ls", noit_console_config_show, NULL, NULL); 
    1341   ADD_CMD(_conf_t_state, "cd", noit_console_config_cd, NULL, NULL); 
    1342   ADD_CMD(_conf_t_state, "config", noit_console_config_setconfig, NULL, NULL); 
    1343   ADD_CMD(_conf_t_state, "section", noit_console_config_section, NULL, (void *)0); 
    1344   ADD_CMD(_conf_t_state, "check", noit_console_check, _conf_t_check_state, NULL); 
     1340  ADD_CMD(_conf_t_state, "ls", noit_console_config_show, NULL, NULL, NULL); 
     1341  ADD_CMD(_conf_t_state, "cd", noit_console_config_cd, NULL, NULL, NULL); 
     1342  ADD_CMD(_conf_t_state, "config", noit_console_config_setconfig, NULL, NULL, NULL); 
     1343  ADD_CMD(_conf_t_state, "section", noit_console_config_section, NULL, NULL, (void *)0); 
     1344  ADD_CMD(_conf_t_state, "check", noit_console_check, NULL, _conf_t_check_state, NULL); 
    13451345 
    13461346  showcmd = noit_console_state_get_cmd(tl, "show"); 
    1347   ADD_CMD(showcmd->dstate, "check", noit_console_show_check, NULL, NULL); 
    1348  
    1349   ADD_CMD(tl, "watch", noit_console_watch_check, NULL, (void *)1); 
     1347  ADD_CMD(showcmd->dstate, "check", noit_console_show_check, NULL, NULL, NULL); 
     1348 
     1349  ADD_CMD(tl, "watch", noit_console_watch_check, NULL, NULL, (void *)1); 
    13501350 
    13511351  nocmd = noit_console_state_get_cmd(tl, "no"); 
    1352   ADD_CMD(nocmd->dstate, "watch", noit_console_watch_check, NULL, (void *)0); 
    1353  
    1354   DELEGATE_CMD(_conf_t_state, "write", _write_state); 
    1355   DELEGATE_CMD(_conf_t_state, "attribute", _attr_state); 
    1356   DELEGATE_CMD(_conf_t_state, "no", _unset_state); 
     1352  ADD_CMD(nocmd->dstate, "watch", noit_console_watch_check, NULL, NULL, (void *)0); 
     1353 
     1354  DELEGATE_CMD(_conf_t_state, "write", noit_console_opt_delegate, _write_state); 
     1355  DELEGATE_CMD(_conf_t_state, "attribute", noit_console_opt_delegate, _attr_state); 
     1356  DELEGATE_CMD(_conf_t_state, "no", noit_console_opt_delegate, _unset_state); 
    13571357 
    13581358  NEW_STATE(_conf_state); 
    1359   ADD_CMD(_conf_state, "terminal", noit_console_state_conf_terminal, _conf_t_state, NULL); 
    1360  
    1361   ADD_CMD(tl, "configure", noit_console_state_delegate, _conf_state, NULL); 
    1362   ADD_CMD(tl, "write", noit_console_state_delegate, _write_state, NULL); 
    1363   ADD_CMD(tl, "reload", noit_conf_checks_reload, NULL, NULL); 
    1364 } 
    1365  
     1359  ADD_CMD(_conf_state, "terminal", noit_console_state_conf_terminal, NULL, _conf_t_state, NULL); 
     1360 
     1361  ADD_CMD(tl, "configure", noit_console_state_delegate, noit_console_opt_delegate, _conf_state, NULL); 
     1362  ADD_CMD(tl, "write", noit_console_state_delegate, noit_console_opt_delegate, _write_state, NULL); 
     1363  ADD_CMD(tl, "reload", noit_conf_checks_reload, NULL, NULL, NULL); 
     1364} 
     1365 
  • src/noit_console.c

    r6480ae1 r56c7e9d  
    3636#include "noit_console.h" 
    3737#include "noit_tokenizer.h" 
     38 
     39#include "noitedit/sys.h" 
     40#include "noitedit/el.h" 
     41#include "noitedit/fcns.h" 
     42#include "noitedit/map.h" 
    3843 
    3944static void 
     
    331336    } 
    332337    else { 
     338      int i; 
    333339      const char *line_protocol; 
    334340      HistEvent ev; 
     341 
    335342      ncct->hist = history_init(); 
    336343      history(ncct->hist, &ev, H_SETSIZE, 500); 
     
    345352      if(el_set(ncct->el, EL_HIST, history, ncct->hist)) 
    346353        noitL(noit_error, "Cannot set history on console\n"); 
     354      el_set(ncct->el, EL_ADDFN, "noit_complete", 
     355             "auto completion functions for noit", noit_edit_complete); 
     356      el_set(ncct->el, EL_BIND, "^I", "noit_complete", NULL); 
     357      for(i=EL_NUM_FCNS; i < ncct->el->el_map.nfunc; i++) { 
     358        if(ncct->el->el_map.func[i] == noit_edit_complete) { 
     359          ncct->noit_edit_complete_cmdnum = i; 
     360          break; 
     361        } 
     362      } 
     363 
    347364      if(!noit_hash_retrieve(ac->config, 
    348365                             "line_protocol", strlen("line_protocol"), 
  • src/noit_console.h

    rdb656f3 r56c7e9d  
    1616 
    1717struct _console_state; 
     18struct _console_state_stack; 
    1819struct __noit_console_closure; 
    1920 
     
    2122                                  int, char **, 
    2223                                  struct _console_state *, void *); 
     24typedef char * (*console_opt_func_t)(struct __noit_console_closure *, 
     25                                     struct _console_state_stack *stack, 
     26                                     struct _console_state *state, 
     27                                     int argc, char **argv, 
     28                                     int idx); 
    2329typedef char *(*console_prompt_func_t)(EditLine *); 
    2430typedef void (*state_free_func_t)(struct _console_state *); 
     
    2834  const char            *name; 
    2935  console_cmd_func_t     func; 
     36  console_opt_func_t     autocomplete; 
    3037  struct _console_state *dstate; 
    3138  void                  *closure; 
     
    7784  History *hist; 
    7885  noit_hash_table userdata; 
     86  /* This is console completion magic */ 
     87  int noit_edit_complete_cmdnum; 
     88  int rl_point; 
     89  int rl_end; 
    7990 
    8091  noit_console_state_stack_t *state_stack; 
     
    174185  
    175186API_EXPORT(cmd_info_t *) 
    176   NCSCMD(const char *name, console_cmd_func_t func, 
     187  NCSCMD(const char *name, console_cmd_func_t func, console_opt_func_t ac, 
    177188         noit_console_state_t *dstate, void *closure); 
    178189 
     
    184195 
    185196API_EXPORT(void) 
    186   noit_console_add_help(const char *topic, console_cmd_func_t topic_func); 
     197  noit_console_add_help(const char *topic, console_cmd_func_t topic_func, 
     198                        console_opt_func_t autocomplete); 
     199 
     200API_EXPORT(unsigned char) 
     201  noit_edit_complete(EditLine *el, int invoking_key); 
     202 
     203API_EXPORT(char *) 
     204  noit_console_opt_delegate(noit_console_closure_t ncct, 
     205                            noit_console_state_stack_t *stack, 
     206                            noit_console_state_t *state, 
     207                            int argc, char **argv, 
     208                            int idx); 
    187209 
    188210#endif 
  • src/noit_console_state.c

    rdb656f3 r56c7e9d  
    3030 
    3131cmd_info_t console_command_help = { 
    32   "help", noit_console_help, NULL, NULL 
     32  "help", noit_console_help, noit_console_opt_delegate, NULL, NULL 
    3333}; 
    3434cmd_info_t console_command_exit = { 
    35   "exit", noit_console_state_pop, NULL, NULL 
     35  "exit", noit_console_state_pop, NULL, NULL, NULL 
    3636}; 
    3737cmd_info_t console_command_shutdown = { 
    38   "shutdown", noit_console_shutdown, NULL, NULL 
     38  "shutdown", noit_console_shutdown, NULL, NULL, NULL 
    3939}; 
    4040cmd_info_t console_command_restart = { 
    41   "restart", noit_console_restart, NULL, NULL 
     41  "restart", noit_console_restart, NULL, NULL, NULL 
    4242}; 
    4343 
    4444void 
    45 noit_console_add_help(const char *topic, console_cmd_func_t topic_func) { 
     45noit_console_add_help(const char *topic, console_cmd_func_t topic_func, 
     46                      console_opt_func_t ac) { 
    4647  noit_console_state_t *s = console_command_help.dstate; 
    4748  if(!s) { 
     
    5051    noit_skiplist_set_compare(&s->cmds, cmd_info_compare, cmd_info_comparek); 
    5152  } 
    52   noit_console_state_add_cmd(s, NCSCMD(topic, topic_func, NULL, NULL)); 
     53  noit_console_state_add_cmd(s, NCSCMD(topic, topic_func, ac, NULL, NULL)); 
    5354} 
    5455 
     
    324325  noit_skiplist_set_compare(&s->cmds, cmd_info_compare, cmd_info_comparek); 
    325326  noit_console_state_add_cmd(s, 
    326       NCSCMD("apply", noit_console_generic_apply, NULL, NULL)); 
     327      NCSCMD("apply", noit_console_generic_apply, NULL, NULL, NULL)); 
    327328  noit_console_state_add_cmd(s, &console_command_help); 
    328329  return s; 
     
    358359 
    359360cmd_info_t *NCSCMD(const char *name, console_cmd_func_t func, 
     361                   console_opt_func_t ac, 
    360362                   noit_console_state_t *dstate, void *closure) { 
    361363  cmd_info_t *cmd; 
     
    363365  cmd->name = strdup(name); 
    364366  cmd->func = func; 
     367  cmd->autocomplete = ac; 
    365368  cmd->dstate = dstate; 
    366369  cmd->closure = closure; 
     
    376379    noit_console_state_add_cmd(_top_level_state, &console_command_exit); 
    377380    noit_console_state_add_cmd(_top_level_state, 
    378       NCSCMD("show", noit_console_state_delegate, 
     381      NCSCMD("show", noit_console_state_delegate, noit_console_opt_delegate, 
    379382             noit_console_state_alloc(), NULL)); 
    380383    no_state = noit_console_state_alloc(); 
    381384    noit_console_state_add_cmd(_top_level_state, 
    382       NCSCMD("no", noit_console_state_delegate, 
     385      NCSCMD("no", noit_console_state_delegate, noit_console_opt_delegate, 
    383386             no_state, NULL)); 
    384387 
  • src/noit_module.c

    rdb656f3 r56c7e9d  
    239239} 
    240240 
     241char * 
     242noit_module_options(noit_console_closure_t ncct, 
     243                    noit_console_state_stack_t *stack, 
     244                    noit_console_state_t *state, 
     245                    int argc, char **argv, int idx) { 
     246  if(argc == 1) { 
     247    /* List modules */  
     248    noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     249    const char *name; 
     250    int klen, i = 0; 
     251    noit_image_t *hdr; 
     252 
     253    while(noit_hash_next(&loaders, &iter, (const char **)&name, &klen, 
     254                         (void **)&hdr)) { 
     255      if(!strncmp(hdr->name, argv[0], strlen(argv[0]))) { 
     256        if(idx == i) return strdup(hdr->name); 
     257        i++; 
     258      } 
     259    } 
     260    memset(&iter, 0, sizeof(iter)); 
     261    while(noit_hash_next(&modules, &iter, (const char **)&name, &klen, 
     262                         (void **)&hdr)) { 
     263      if(!strncmp(hdr->name, argv[0], strlen(argv[0]))) { 
     264        if(idx == i) return strdup(hdr->name); 
     265        i++; 
     266      } 
     267    } 
     268    return NULL; 
     269  } 
     270  if(argc == 2) { 
     271    if(!strncmp("examples", argv[1], strlen(argv[1]))) 
     272      if(idx == 0) return strdup("examples"); 
     273  } 
     274  return NULL; 
     275} 
    241276int 
    242277noit_module_help(noit_console_closure_t ncct, 
     
    278313  int i, cnt = 0; 
    279314 
    280   noit_console_add_help("module", noit_module_help); 
     315  noit_console_add_help("module", noit_module_help, noit_module_options); 
    281316 
    282317  /* Load our module loaders */ 
  • src/noitedit/chared.h

    r2c4eb5b r56c7e9d  
    118118#define isword(a)       (isprint(a)) 
    119119 
     120#undef NOP 
    120121#define NOP             0x00 
    121122#undef DELETE