summaryrefslogtreecommitdiffstats
path: root/nest
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1999-11-17 13:14:44 +0100
committerMartin Mares <mj@ucw.cz>1999-11-17 13:14:44 +0100
commit62a463954815748d0d82da0e30651e6eea7bc9cf (patch)
tree4df691d34dc346791f56cd04e71dacc9979d5cd0 /nest
parent30770df2ab33ffbfd75a9478265ac5e1a1db98d9 (diff)
downloadbird-62a463954815748d0d82da0e30651e6eea7bc9cf.tar
bird-62a463954815748d0d82da0e30651e6eea7bc9cf.zip
Added some temporary examples of how to define CLI commands (search for CF_CLI).
To define a new command, just add a new rule to the gramar: CF_CLI(COMMAND NAME, arguments, help-args, help-text) { what-should-the-command-do } ; where <arguments> are appended to the RHS of the rule, <help-args> is the argument list as shown in the help and <help-text> is description of the command for the help. <what-should-the-command-do> is a C code snippet to be executed. It should not take too much time to execute. If you want to print out a lot of information, you can schedule a routine to be called after the current buffer is flushed by making cli->cont point to the routine (see the TEST LONG command definition for an example); if the connection is closed in the meantime, cli->cleanup gets called. You can access `struct cli' belonging to the connection you're currently servicing as this_cli, but only during parse time, not from routines scheduled for deferred execution. Functions to call inside command handlers: cli_printf(cli, code, printf-args) -- print text to CLI connection, <code> is message code as assigned in doc/reply_codes or a negative one if it's a continuation line. cli_msg(code, printf-args) -- the same for this_cli. Use 'sock -x bird.ctl' for connecting to the CLI until a client is written.
Diffstat (limited to 'nest')
-rw-r--r--nest/config.Y24
1 files changed, 22 insertions, 2 deletions
diff --git a/nest/config.Y b/nest/config.Y
index 6a630b2..4000b6d 100644
--- a/nest/config.Y
+++ b/nest/config.Y
@@ -187,9 +187,29 @@ password_list:
/* Core commands */
-CF_CLI(TEST LEDS, <N>, [[Flashes each LED <N> times]]) NUM { cli_msg(0, "%d", $3); } ;
-CF_CLI(TEST, 1, 2) { cli_msg(0, "OK"); }
+/* FIXME: These are examples. Remove them soon. */
+CF_CLI_HELP(TEST, <subsystem>, [[Tests different subsystems]])
+CF_CLI(TEST LEDS, NUM, <N>, [[Flashes each LED <N> times]]) { cli_msg(0, "%d", $3); } ;
+CF_CLI(TEST MEMORY,,, [[Replace all useful information by testing patterns]]) { cli_msg(0, "DONE"); } ;
+CF_CLI(TEST LONG,,, [[Test long replies]]) {
+ static void test_command(struct cli *);
+ this_cli->cont = test_command;
+ this_cli->rover = (void *) 1;
+ cli_msg(-2, "Start");
+} ;
CF_CODE
+static void test_command(struct cli *c)
+{
+ int i = (int) c->rover;
+ if (i < 10) {
+ cli_printf(c, -3, "%d", i);
+ c->rover = (void *) ++i;
+ } else {
+ c->cont = NULL;
+ cli_printf(c, 4, "DONE");
+ }
+}
+
CF_END