8 int cmd_do_testopchar(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
12 opchar=cmd_opchar_check(cmd_io,des,param);
13 if(opchar<0) return opchar;
16 "cmd_do_testopchar called\n"
22 param[0], param[1], param[2], param[3], opchar);
27 int cmd_do_spacesep(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
29 if (des->mode & CDESM_OPCHR) {
31 opchar=cmd_opchar_check(cmd_io,des,param);
32 if(opchar<0) return opchar;
36 for (i = 0; param[i] || (des->mode & CDESM_OPCHR && i == 1); i++)
37 printf("param[%d]=%s\n", i, param[i]);
42 int cmd_do_testparam(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
45 "cmd_do_testparam called\n"
49 param[0], param[1], param[1] == NULL ? "!!unset!!" : param[2]);
54 int cmd_do_testerror(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
59 int cmd_do_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
61 printf("This is the simplest command\n");
65 int cmd_do_testcmdio(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
67 cmd_io_puts(cmd_io, "The first line of text\n");
68 cmd_io_puts(cmd_io, "The second line of text\n");
69 /* Only ED_LINE_CHARS character can be sent. */
73 cmd_des_t const **cmd_list;
75 cmd_des_t const cmd_des_help={
77 "help","prints help for commands",
78 cmd_do_help,{(char*)&cmd_list}};
81 cmd_des_t const cmd_des_val={
82 0, CDESM_OPCHR|CDESM_RW,
83 "val","use ':' or '?' to store/read value of an integer variable",
84 cmd_do_rw_int, {(char*)&val}};
86 cmd_des_t const cmd_des_valro={
87 0, CDESM_OPCHR|CDESM_RD,
88 "valro","read only access to an integer variable",
89 cmd_do_rw_int, {(char*)&val}};
91 cmd_des_t const cmd_des_valwo={
92 0, CDESM_OPCHR|CDESM_WR,
93 "valwo","write only access to an integer variable",
94 cmd_do_rw_int, {(char*)&val}};
96 cmd_des_t const cmd_des_opchar_test={
97 0, CDESM_OPCHR|CDESM_RW,
98 "opchar","opchar test (use ':' or '?' as suffix)",
101 cmd_des_t const cmd_des_opchar_testro={
102 0, CDESM_OPCHR|CDESM_RD,
103 "opcharro","opchar test (only '?' is allowed)",
106 cmd_des_t const cmd_des_test={
108 "test","the simplest command",
111 cmd_des_t const cmd_des_testio={
113 "testio","test of cmd_io inside functions (universal way to print results)",
116 cmd_des_t const cmd_des_param={
118 "param","test of parameters",
121 cmd_des_t const cmd_des_prefix={
123 "prefix*","suffix of the command is supplied as a parametr",
126 cmd_des_t const cmd_des_num={
128 "num##","suffix of the command (two digits) is supplied as a parametr",
131 cmd_des_t const cmd_des_char={
133 "char?","suffix of the command (one character) is supplied as a parametr",
136 cmd_des_t const cmd_des_charmid={
138 "char?mid","middle character of the command is supplied as a parametr",
141 cmd_des_t const cmd_des_hiddedn={
143 "hidden","should not be available",
146 cmd_des_t const cmd_des_error={
148 "testerror","should produce an error",
151 cmd_des_t const cmd_des_spacesep={
153 "spacesep","Test for space separated parameters",
156 cmd_des_t const cmd_des_spacesepop={
157 0, CDESM_SPACE_SEP|CDESM_OPCHR|CDESM_RW,
158 "spacesepop","Test for space separated parameters and an opchar",
161 cmd_des_t const cmd_des_spacesepwild={
163 "spacesep#","Test for space separated parameters and a wildcard",
168 cmd_des_t const *cmd_list_1[]={
172 &cmd_des_opchar_test,
173 &cmd_des_opchar_testro,
177 cmd_des_t const *cmd_list_2[]={
187 &cmd_des_spacesepwild,
191 cmd_des_t const *cmd_list_main[]={
194 CMD_DES_INCLUDE_SUBLIST(cmd_list_1),
195 CMD_DES_CONTINUE_AT(cmd_list_2),
200 cmd_des_t const **cmd_list = cmd_list_main;
202 cmd_io_t cmd_io_std_line;
204 struct termios tcbackup;
208 tcsetattr(0, TCSAFLUSH, &tcbackup);
217 tc.c_lflag &= ~(ICANON|ECHO);
220 tc.c_cc[VERASE] = '\b';
221 tcsetattr(0, TCSAFLUSH, &tc);
222 signal(SIGINT, sigint);
225 cmd_processor_run(&cmd_io_std_line, cmd_list_main);