Author: bdonlan
Date: 2005-06-01 14:15:18 -0400 (Wed, 01 Jun 2005)
New Revision: 745

Added:
   trunk/clients/havercurs/cmdline.m
Removed:
   trunk/clients/havercurs/cmdline.c
Modified:
   trunk/
   trunk/clients/havercurs/cmdline.h
   trunk/clients/havercurs/display.c
   trunk/clients/havercurs/display.h
   trunk/clients/havercurs/entry.c
   trunk/clients/havercurs/entry.h
   trunk/clients/havercurs/event.c
   trunk/clients/havercurs/event.h
   trunk/clients/havercurs/lineio.c
   trunk/clients/havercurs/lineio.h
   trunk/clients/havercurs/main.c
   trunk/clients/havercurs/mymalloc.c
   trunk/clients/havercurs/mymalloc.h
   trunk/clients/havercurs/net.c
   trunk/clients/havercurs/net.h
   trunk/clients/havercurs/trie.c
   trunk/clients/havercurs/trie.h
Log:
 [EMAIL PROTECTED]:  bdonlan | 2005-05-07 15:08:53 -0400
 Fix modeline



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/havercurs-objc:40764
1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:11166
1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk-merge-10131:11178
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
e9404bb1-7af0-0310-a7ff-e22194cd388b:/haver/local:1040
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
   + 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/havercurs-objc:40765
1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:11166
1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk-merge-10131:11178
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
e9404bb1-7af0-0310-a7ff-e22194cd388b:/haver/local:1040
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238

Deleted: trunk/clients/havercurs/cmdline.c
===================================================================
--- trunk/clients/havercurs/cmdline.c   2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/cmdline.c   2005-06-01 18:15:18 UTC (rev 745)
@@ -1,236 +0,0 @@
-/* vim: ft=objc 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
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This module is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this module; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include "cmdline.h"
-#include "mymalloc.h"
-#include "trie.h"
-
-static trie *root;
-
-typedef struct cmdentry {
-    cmdline_handler *handler;
-    void *baton;
-} cmdentry;
-
-/** cmdline_init()
- *
- * Initializes the module. Must be called before any other functions in this 
header.
- */
-void cmdline_init(void) {
-    root = trie_create();
-}
-
-/** cmdline_free()
- *
- * De-initializes the module. cmdline_init() must be called again after 
calling this,
- * before any other functions from this header are called
- */
-void cmdline_free(void) {
-    trie_free(root);
-    root = NULL;
-}
-
-/** cmdline_register()
- *
- * Registers a command handler.
- *
- * Arguments:
- * const char *command - name of the command
- * 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_handler *cmdline_register(
-               const char *command,
-               cmdline_handler *cb,
-               void *baton
-               )
-{
-    cmdline_handler *old;
-    struct cmdentry *e = trie_get(root, command);
-    if (e) {
-        old = e->handler;
-    } else {
-        e = mymalloc(sizeof *e);
-        old = NULL;
-    }
-    e->handler = cb;
-    e->baton = baton;
-    return old;
-}
-
-/** cmdline_unregister()
- *
- * Unregisters a command handler
- *
- * Arguments:
- * const char *command - name of the command
- *
- * Return value:
- * Previous handler or NULL if none
- */
-cmdline_handler *cmdline_unregister(const char *command) {
-    cmdentry *old = trie_delete(root, command);
-    if (old)
-        return old->handler;
-    return NULL;
-}
-
-struct process_baton {
-    void *baton;
-    cmdline_handler *handler;
-};
-
-/** cmdline_lookup()
- *
- * Obtains the handler for a given command
- *
- * Arguments:
- * const char *command - name of the command
- * void **baton - pointer to location to place the baton value, or NULL
- *                               to discard
- *
- * Return value:
- * Handler callback, or NULL if none or ambiguous
- */
-cmdline_handler *cmdline_lookup(
-               const char *command,
-               void **baton
-               )
-{
-    struct process_baton lb;
-    struct cmdentry *e = trie_get(root, command);
-    if (e) {
-        if (baton)
-            *baton = e->baton;
-        return e->handler;
-    }
-    return NULL;
-}
-
-/** process_cb()
- *
- * Callback used by cmdline_process() with trie_enum()
- */
-static int process_cb(
-        void *baton,
-        const char *key,
-        void *value
-        )
-{
-    struct cmdentry *e = value;
-    struct process_baton *lb = baton;
-    lb->baton = e->baton;
-    lb->handler = e->handler;
-    return 0;
-}
-
-
-/** cmdline_process()
- *
- * Dispatches a command to its handler, if any.
- *
- * Arguments:
- * const char *cmdline - full command line to process
- * int partial         - 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, int partial) {
-    char *cmdstr;
-    const char *endcmd = cmdline;
-    int ret;
-
-    while (*endcmd && strchr(trie_chars, *endcmd))
-        endcmd++;
-    cmdstr = mymalloc(endcmd - cmdline + 1);
-    memcpy(cmdstr, cmdline, endcmd - cmdline);
-    cmdstr[endcmd - cmdline] = '\0';
-
-    if (partial) {
-        struct process_baton lb;
-        size_t r;
-        r = trie_enum(root, cmdstr, process_cb, &lb);
-        if (r == 1) {
-            lb.handler(lb.baton, cmdline);
-            ret = 2;
-        } else if (r == 0) {
-            ret = 0;
-        } else {
-            ret = -1;
-        }
-    } else {
-        void *baton;
-        cmdline_handler *h;
-        h = cmdline_lookup(cmdstr, &baton);
-        h(baton, cmdline);
-        ret = 1;
-    }
-    free(cmdstr);
-    return ret;
-}
-
-struct cmdline_enum_baton {
-    void *baton;
-    cmdline_enum_callback *cb;
-};
-
-static int cmdline_enum_cb(
-        void *baton,
-        const char *key,
-        void *value
-        )
-{
-    struct cmdline_enum_baton *b = baton;
-    cmdentry *e = value;
-    return b->cb(b->baton, key, e->handler, e->baton);
-}
-
-/** 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
-        )
-{
-    struct cmdline_enum_baton b;
-    b.cb = cb;
-    b.baton = baton;
-    return trie_enum(root, prefix, cmdline_enum_cb, &b);
-}

Modified: trunk/clients/havercurs/cmdline.h
===================================================================
--- trunk/clients/havercurs/cmdline.h   2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/cmdline.h   2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  * cmdline.h - Functions for processing and dispatching commands
  * 
  * Copyright (C) 2004 Bryan Donlan

Added: trunk/clients/havercurs/cmdline.m
===================================================================
--- trunk/clients/havercurs/cmdline.m   2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/cmdline.m   2005-06-01 18:15:18 UTC (rev 745)
@@ -0,0 +1,236 @@
+/* vim: set ft=objc 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
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "cmdline.h"
+#include "mymalloc.h"
+#include "trie.h"
+
+static trie *root;
+
+typedef struct cmdentry {
+    cmdline_handler *handler;
+    void *baton;
+} cmdentry;
+
+/** cmdline_init()
+ *
+ * Initializes the module. Must be called before any other functions in this 
header.
+ */
+void cmdline_init(void) {
+    root = trie_create();
+}
+
+/** cmdline_free()
+ *
+ * De-initializes the module. cmdline_init() must be called again after 
calling this,
+ * before any other functions from this header are called
+ */
+void cmdline_free(void) {
+    trie_free(root);
+    root = NULL;
+}
+
+/** cmdline_register()
+ *
+ * Registers a command handler.
+ *
+ * Arguments:
+ * const char *command - name of the command
+ * 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_handler *cmdline_register(
+               const char *command,
+               cmdline_handler *cb,
+               void *baton
+               )
+{
+    cmdline_handler *old;
+    struct cmdentry *e = trie_get(root, command);
+    if (e) {
+        old = e->handler;
+    } else {
+        e = mymalloc(sizeof *e);
+        old = NULL;
+    }
+    e->handler = cb;
+    e->baton = baton;
+    return old;
+}
+
+/** cmdline_unregister()
+ *
+ * Unregisters a command handler
+ *
+ * Arguments:
+ * const char *command - name of the command
+ *
+ * Return value:
+ * Previous handler or NULL if none
+ */
+cmdline_handler *cmdline_unregister(const char *command) {
+    cmdentry *old = trie_delete(root, command);
+    if (old)
+        return old->handler;
+    return NULL;
+}
+
+struct process_baton {
+    void *baton;
+    cmdline_handler *handler;
+};
+
+/** cmdline_lookup()
+ *
+ * Obtains the handler for a given command
+ *
+ * Arguments:
+ * const char *command - name of the command
+ * void **baton - pointer to location to place the baton value, or NULL
+ *                               to discard
+ *
+ * Return value:
+ * Handler callback, or NULL if none or ambiguous
+ */
+cmdline_handler *cmdline_lookup(
+               const char *command,
+               void **baton
+               )
+{
+    struct process_baton lb;
+    struct cmdentry *e = trie_get(root, command);
+    if (e) {
+        if (baton)
+            *baton = e->baton;
+        return e->handler;
+    }
+    return NULL;
+}
+
+/** process_cb()
+ *
+ * Callback used by cmdline_process() with trie_enum()
+ */
+static int process_cb(
+        void *baton,
+        const char *key,
+        void *value
+        )
+{
+    struct cmdentry *e = value;
+    struct process_baton *lb = baton;
+    lb->baton = e->baton;
+    lb->handler = e->handler;
+    return 0;
+}
+
+
+/** cmdline_process()
+ *
+ * Dispatches a command to its handler, if any.
+ *
+ * Arguments:
+ * const char *cmdline - full command line to process
+ * int partial         - 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, int partial) {
+    char *cmdstr;
+    const char *endcmd = cmdline;
+    int ret;
+
+    while (*endcmd && strchr(trie_chars, *endcmd))
+        endcmd++;
+    cmdstr = mymalloc(endcmd - cmdline + 1);
+    memcpy(cmdstr, cmdline, endcmd - cmdline);
+    cmdstr[endcmd - cmdline] = '\0';
+
+    if (partial) {
+        struct process_baton lb;
+        size_t r;
+        r = trie_enum(root, cmdstr, process_cb, &lb);
+        if (r == 1) {
+            lb.handler(lb.baton, cmdline);
+            ret = 2;
+        } else if (r == 0) {
+            ret = 0;
+        } else {
+            ret = -1;
+        }
+    } else {
+        void *baton;
+        cmdline_handler *h;
+        h = cmdline_lookup(cmdstr, &baton);
+        h(baton, cmdline);
+        ret = 1;
+    }
+    free(cmdstr);
+    return ret;
+}
+
+struct cmdline_enum_baton {
+    void *baton;
+    cmdline_enum_callback *cb;
+};
+
+static int cmdline_enum_cb(
+        void *baton,
+        const char *key,
+        void *value
+        )
+{
+    struct cmdline_enum_baton *b = baton;
+    cmdentry *e = value;
+    return b->cb(b->baton, key, e->handler, e->baton);
+}
+
+/** 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
+        )
+{
+    struct cmdline_enum_baton b;
+    b.cb = cb;
+    b.baton = baton;
+    return trie_enum(root, prefix, cmdline_enum_cb, &b);
+}


Property changes on: trunk/clients/havercurs/cmdline.m
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/clients/havercurs/display.c
===================================================================
--- trunk/clients/havercurs/display.c   2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/display.c   2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/display.h
===================================================================
--- trunk/clients/havercurs/display.h   2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/display.h   2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/entry.c
===================================================================
--- trunk/clients/havercurs/entry.c     2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/entry.c     2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/entry.h
===================================================================
--- trunk/clients/havercurs/entry.h     2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/entry.h     2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/event.c
===================================================================
--- trunk/clients/havercurs/event.c     2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/event.c     2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/event.h
===================================================================
--- trunk/clients/havercurs/event.h     2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/event.h     2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/lineio.c
===================================================================
--- trunk/clients/havercurs/lineio.c    2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/lineio.c    2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/lineio.h
===================================================================
--- trunk/clients/havercurs/lineio.h    2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/lineio.h    2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/main.c
===================================================================
--- trunk/clients/havercurs/main.c      2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/main.c      2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/mymalloc.c
===================================================================
--- trunk/clients/havercurs/mymalloc.c  2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/mymalloc.c  2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/mymalloc.h
===================================================================
--- trunk/clients/havercurs/mymalloc.h  2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/mymalloc.h  2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/net.c
===================================================================
--- trunk/clients/havercurs/net.c       2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/net.c       2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/net.h
===================================================================
--- trunk/clients/havercurs/net.h       2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/net.h       2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  *
  * Copyright (C) 2004 Bryan Donlan
  * 

Modified: trunk/clients/havercurs/trie.c
===================================================================
--- trunk/clients/havercurs/trie.c      2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/trie.c      2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  * trie.c - Functions for manipulating tries
  * 
  * Copyright (C) 2004 Bryan Donlan

Modified: trunk/clients/havercurs/trie.h
===================================================================
--- trunk/clients/havercurs/trie.h      2005-06-01 18:15:07 UTC (rev 744)
+++ trunk/clients/havercurs/trie.h      2005-06-01 18:15:18 UTC (rev 745)
@@ -1,4 +1,4 @@
-/* vim: ft=objc set ts=4 sw=4 expandtab si ai sta tw=104:
+/* vim: set ft=objc ts=4 sw=4 expandtab si ai sta tw=104:
  * trie.h - Functions for manipulating tries
  * 
  * Copyright (C) 2004 Bryan Donlan


Reply via email to