#include <stdint.h>
#include <string.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cmdline_parse_ipaddr.h>
#include <cmdline_parse_num.h>
#include <cmdline_parse_string.h>
+#include <cmdline_parse_file.h>
#include <cmdline_rdline.h>
#include <cmdline.h>
static int get_str(struct cmdline *cl, char *buf, int len)
{
struct rdline rl;
- int ret = 0, n;
- char c;
+ int ret = 0;
+ int c;
char *s;
buf[0] = '\0';
- rdline_init(&rl, cmdline_write_char, NULL, NULL);
+ rdline_init(&rl, cl->s_in, cl->s_out, NULL, NULL, NULL);
rl.opaque = cl;
+
+ /* XXX use rdline() */
rdline_newline(&rl, "edit> ");
- while (ret == 0 || ret == 2) {
- n = read(cl->s_in, &c, 1);
- if (n <= 0)
+ while (ret == RDLINE_RES_SUCCESS) {
+ read(cl->s_in, &c, 1);
+ if (c <= 0)
return -1;
ret = rdline_char_in(&rl, c);
- if (ret == 1) {
+ if (ret == RDLINE_RES_VALIDATED) {
snprintf(buf, len, "%s", rdline_get_buffer(&rl));
s = strchr(buf, '\n');
if (s)
/**********************************************************/
struct cmd_load_result {
- cmdline_fixed_string_t load;
+ cmdline_filename_t load;
cmdline_fixed_string_t file;
};
},
};
-cmdline_parse_token_string_t cmd_load_file =
- TOKEN_STRING_INITIALIZER(struct cmd_load_result, file, NULL);
+cmdline_parse_token_file_t cmd_load_file =
+ TOKEN_FILE_INITIALIZER(struct cmd_load_result, file, 0);
cmdline_parse_inst_t cmd_loadfile = {
.f = cmd_load_parsed, /* function to call */
struct cmd_save_result {
cmdline_fixed_string_t save;
- cmdline_fixed_string_t file;
+ cmdline_filename_t file;
};
static void cmd_save_parsed(void *parsed_result,
},
};
-cmdline_parse_token_string_t cmd_save_file =
- TOKEN_STRING_INITIALIZER(struct cmd_save_result, file, NULL);
+cmdline_parse_token_file_t cmd_save_file =
+ TOKEN_FILE_INITIALIZER(struct cmd_save_result, file,
+ PARSE_FILE_F_CREATE);
cmdline_parse_inst_t cmd_savefile = {
.f = cmd_save_parsed, /* function to call */
/****** CONTEXT (list of instruction) */
/* in progmem */
-cmdline_parse_ctx_t main_ctx[] = {
- (cmdline_parse_inst_t *)&cmd_ls,
- (cmdline_parse_inst_t *)&cmd_ls_node,
- (cmdline_parse_inst_t *)&cmd_pwd,
- (cmdline_parse_inst_t *)&cmd_cd_prev,
- (cmdline_parse_inst_t *)&cmd_cd_root,
- (cmdline_parse_inst_t *)&cmd_cd_node,
- (cmdline_parse_inst_t *)&cmd_set_bool,
- (cmdline_parse_inst_t *)&cmd_set_int,
- (cmdline_parse_inst_t *)&cmd_set_str,
- (cmdline_parse_inst_t *)&cmd_show_node,
- (cmdline_parse_inst_t *)&cmd_show_node_a,
- (cmdline_parse_inst_t *)&cmd_load,
- (cmdline_parse_inst_t *)&cmd_loadfile,
- (cmdline_parse_inst_t *)&cmd_save,
- (cmdline_parse_inst_t *)&cmd_savefile,
- NULL,
+cmdline_parse_ctx_t main_ctx = {
+ .name = "main",
+ .insts = {
+ &cmd_ls,
+ &cmd_ls_node,
+ &cmd_pwd,
+ &cmd_cd_prev,
+ &cmd_cd_root,
+ &cmd_cd_node,
+ &cmd_set_bool,
+ &cmd_set_int,
+ &cmd_set_str,
+ &cmd_show_node,
+ &cmd_show_node_a,
+ &cmd_load,
+ &cmd_loadfile,
+ &cmd_save,
+ &cmd_savefile,
+ NULL,
+ },
};