Couple of fixes, tool works now.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 7 Mar 2005 07:08:14 +0000 (08:08 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 7 Mar 2005 07:08:14 +0000 (08:08 +0100)
ptbdict.c

index 2141a0cad2eef05eb4fcb1e3e3c15eae8b563afe..a398f8a3925b2d89687fa59de8c397efc60637ed 100644 (file)
--- a/ptbdict.c
+++ b/ptbdict.c
 #  include <stdint.h>
 #endif
 
+#include <string.h>
+
 #include "ptb.h"
 
+static void print_tuning(struct ptb_tuning *t, void *userdata)
+{
+       int j;
+       printf("%s: ", t->name);
+       for (j = 0; j < t->nr_strings; j++) {
+               printf("%d ", t->strings[j]);
+       }
+       printf("\n");
+}
+
+static void del_tuning(struct ptb_tuning *t, void *userdata)
+{
+       struct ptb_tuning_dict *d = userdata;
+       
+       d->nr_tunings--;
+       
+       /* FIXME: Swap current and last item */
+}
+
+static void traverse_tunings(struct ptb_tuning_dict *ret, const char *name, void (*fn) (struct ptb_tuning *, void *userdata), void *userdata)
+{
+       int i;
+       for (i = 0; i < ret->nr_tunings; i++) {
+               if (name && strcmp(name, ret->tunings[i].name)) continue;
+
+               fn (&ret->tunings[i], userdata);
+       }
+}
+
 int main(int argc, const char **argv) 
 {
        struct ptb_tuning_dict *ret;
-       int i;
-       int c;
-       int version = 0;
+       int c, version = 0;
+       int del = 0, add =0;
+       const char *tun;
        poptContext pc;
        struct poptOption options[] = {
                POPT_AUTOHELP
                {"version", 'v', POPT_ARG_NONE, &version, 'v', "Show version information" },
+               {"add", 'a', POPT_ARG_NONE, &add, 'a', "Add entry" },
+               {"del", 'd', POPT_ARG_NONE, &del, 'd', "Delete entry" },
                POPT_TABLEEND
        };
 
        pc = poptGetContext(argv[0], argc, argv, options, 0);
-       poptSetOtherOptionHelp(pc, "file.ptb");
+       poptSetOtherOptionHelp(pc, "tunings.dat [tuning-name]");
        while((c = poptGetNextOpt(pc)) >= 0) {
                switch(c) {
                case 'v':
@@ -62,19 +95,18 @@ int main(int argc, const char **argv)
        }
 
        ret = ptb_read_tuning_dict(poptGetArg(pc));
-       
+
        if(!ret) {
                perror("Read error: ");
                return -1;
        } 
 
-       for (i = 0; i < ret->nr_tunings; i++) {
-               int j;
-               printf("%s: ", ret->tunings[i].name);
-               for (j = 0; j < ret->tunings[i].nr_strings; j++) {
-                       printf("%d ", ret->tunings[i].strings[j]);
-               }
-               printf("\n");
+       tun = poptGetArg(pc);
+
+       if (add) {
+               /* FIXME */
+       } else {
+               traverse_tunings(ret, tun, del?del_tuning:print_tuning, NULL);
        }
 
        return 0;