Debian fixes
[jelmer/ptabtools.git] / ptbdict.c
1 /*
2         (c) 2005: Jelmer Vernooij <jelmer@samba.org>
3
4         This program is free software; you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation; either version 2 of the License, or
7         (at your option) any later version.
8
9         This program is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <stdio.h>
20 #include <errno.h>
21 #include <popt.h>
22 #include "dlinklist.h"
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #ifdef HAVE_STDINT_H
29 #  include <stdint.h>
30 #endif
31
32 #include <string.h>
33
34 #include "ptb.h"
35
36 static void print_tuning(struct ptb_tuning *t, void *userdata)
37 {
38         int j;
39         printf("%s: ", t->name);
40         for (j = 0; j < t->nr_strings; j++) {
41                 printf("%s ", ptb_tuning_get_note(t->strings[j]));
42         }
43         printf("\n");
44 }
45
46 static void del_tuning(struct ptb_tuning *t, void *userdata)
47 {
48         struct ptb_tuning_dict *d = userdata;
49         
50         d->nr_tunings--;
51         
52         /* FIXME: Swap current and last item */
53 }
54
55 static void traverse_tunings(struct ptb_tuning_dict *ret, const char *name, void (*fn) (struct ptb_tuning *, void *userdata), void *userdata)
56 {
57         int i;
58         for (i = 0; i < ret->nr_tunings; i++) {
59                 if (name && strcmp(name, ret->tunings[i].name)) continue;
60
61                 fn (&ret->tunings[i], userdata);
62         }
63 }
64
65 int main(int argc, const char **argv) 
66 {
67         struct ptb_tuning_dict *ret;
68         int c, version = 0;
69         int del = 0, add =0;
70         const char *tun;
71         poptContext pc;
72         struct poptOption options[] = {
73                 POPT_AUTOHELP
74                 {"version", 'v', POPT_ARG_NONE, &version, 'v', "Show version information" },
75                 {"add", 'a', POPT_ARG_NONE, &add, 'a', "Add entry" },
76                 {"del", 'd', POPT_ARG_NONE, &del, 'd', "Delete entry" },
77                 POPT_TABLEEND
78         };
79
80         pc = poptGetContext(argv[0], argc, argv, options, 0);
81         poptSetOtherOptionHelp(pc, "tunings.dat [tuning-name]");
82         while((c = poptGetNextOpt(pc)) >= 0) {
83                 switch(c) {
84                 case 'v':
85                         printf("ptbdict Version "PACKAGE_VERSION"\n");
86                         printf("(C) 2005 Jelmer Vernooij <jelmer@samba.org>\n");
87                         exit(0);
88                         break;
89                 }
90         }
91                         
92         if(!poptPeekArg(pc)) {
93                 poptPrintUsage(pc, stderr, 0);
94                 return -1;
95         }
96
97         ret = ptb_read_tuning_dict(poptGetArg(pc));
98
99         if(!ret) {
100                 perror("Read error: ");
101                 return -1;
102         } 
103
104         tun = poptGetArg(pc);
105
106         if (add) {
107                 /* FIXME */
108         } else {
109                 traverse_tunings(ret, tun, del?del_tuning:print_tuning, NULL);
110         }
111
112         return 0;
113 }