Author: bdonlan
Date: 2004-12-31 21:18:11 -0500 (Fri, 31 Dec 2004)
New Revision: 495
Modified:
trunk/
trunk/clients/havercurs/cmdline.h
Log:
[EMAIL PROTECTED]: bdonlan | 2005-01-01T02:17:58.935112Z
Add enumerator fucntion for prefix matching. Rename cmdline_callback to
cmdline_handler. Minor formatting changes.
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:10256
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
+ 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:10259
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
Modified: trunk/clients/havercurs/cmdline.h
===================================================================
--- trunk/clients/havercurs/cmdline.h 2005-01-01 01:53:38 UTC (rev 494)
+++ trunk/clients/havercurs/cmdline.h 2005-01-01 02:18:11 UTC (rev 495)
@@ -1,5 +1,6 @@
/* vim: set ts=4 sw=4 expandtab si ai sta tw=104:
- *
+ * cmdline.h - Functions for processing and dispatching commands
+ *
* Copyright (C) 2004 Bryan Donlan
*
* This module is free software; you can redistribute it and/or modify
@@ -17,15 +18,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
#ifndef CMDLINE_H
#define CMDLINE_H 1
-/* cmdline.h
- * Functions for processing and dispatching commands.
- */
+#include <stdlib.h>
-/** cmdline_callback
+/** cmdline_handler
*
* Function type for command line dispatching.
*
@@ -33,8 +31,29 @@
* void *baton - external value passed to cmdline_register()
* const char *cmdline - pointer to full command line
*/
-typedef void cmdline_callback(void *baton, const char *cmdline);
+typedef void cmdline_handler(void *baton, const char *cmdline);
+/** cmdline_enum_callback
+ *
+ * Callback for cmdline_enum().
+ *
+ * Arguments:
+ * void *baton - baton passed to cmdline_enum()
+ * const char *command - full command name found
+ * cmdline_handler *handler - handler found
+ * void *h_baton - baton for the handler found
+ *
+ * Return value:
+ * 0 to terminate search
+ * Any other value to continue
+ */
+typedef int cmdline_enum_callback(
+ void *baton,
+ const char *command,
+ cmdline_handler *handler,
+ void *h_baton
+ );
+
/** cmdline_init()
*
* Initializes the module. Must be called before any other functions in this
header.
@@ -54,15 +73,15 @@
*
* Arguments:
* const char *command - name of the command
- * cmdline_callback *cb - callback to call when command is invoked
+ * cmdline_handler *cb - callback to call when command is invoked
* void *baton - value to pass to the callback's baton argument
*
* Return value:
* Previous handler or NULL if none
*/
-cmdline_callback *cmdline_register(
+cmdline_handler *cmdline_register(
const char *command,
- cmdline_callback *cb,
+ cmdline_handler *cb,
void *baton
);
@@ -76,7 +95,7 @@
* Return value:
* Previous handler or NULL if none
*/
-cmdline_callback *cmdline_unregister(const char *command);
+cmdline_handler *cmdline_unregister(const char *command);
/** cmdline_lookup()
*
@@ -86,13 +105,15 @@
* const char *command - name of the command
* void **baton - pointer to location to place the baton value, or NULL
* to discard
+ * int partial - 1 if partial matching should be attempted
*
* Return value:
* Handler callback, or NULL if none
*/
-cmdline_callback *cmdline_lookup(
+cmdline_handler *cmdline_lookup(
const char *command,
- void **baton
+ void **baton,
+ int partial
);
/** cmdline_process()
@@ -101,11 +122,32 @@
*
* Arguments:
* const char *cmdline - full command line to process
+ * int particl - 1 if partial matching should be attempted
*
* Return value:
+ * 2 if command was processed with a partial match
* 1 if command was successfully processed
* 0 if no handler was found
+ * -1 if multiple partial matches were found; no action will be taken
*/
int cmdline_process(const char *cmdline);
+/** cmdline_enum()
+ *
+ * Obtain a complete listing of partial matches for a command prefix
+ *
+ * Arguments:
+ * const char *prefix - the prefix to search for
+ * cmdline_enum_callback *cb - callback to call on each match
+ * void *baton - baton to pass to callback
+ *
+ * Return value:
+ * Total number of matches (regardless of whether cb() returns 0)
+ */
+size_t cmdline_enum(
+ const char *prefix,
+ cmdline_enum_callback *cb,
+ void *baton
+ );
+
#endif