Bayonne 3 - API
 All Classes Namespaces Files Functions Variables Typedefs Macros
utils/phrasebook.cpp
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2011 David Sugar, Tycho Softworks.
3 //
4 // This file is part of GNU ccAudio2.
5 //
6 // GNU ccAudio2 is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU ccAuydio2 is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU ccAudio2. If not, see <http://www.gnu.org/licenses/>.
18 
19 #include <bayonne.h>
20 #include <config.h>
21 
22 using namespace BAYONNE_NAMESPACE;
23 using namespace UCOMMON_NAMESPACE;
24 
25 static shell::flagopt helpflag('h',"--help", _TEXT("display this list"));
26 static shell::flagopt althelp('?', NULL, NULL);
27 static shell::stringopt lang('L', "--lang", _TEXT("specify language"), "language", "C");
28 static shell::stringopt prefix('P', "--prefix", _TEXT("specify alternate prefix path"), "path", NULL);
29 static shell::stringopt suffix('S', "--suffix", _TEXT("audio extension"), ".ext", ".au");
30 static shell::stringopt voice('V', "--voice", _TEXT("specify voice library"), "name", "default");
31 static shell::stringopt phrasebook('B', "--phrasebook", _TEXT("specify phrasebook directory"), "path", NULL);
32 static Env::pathinfo_t ruleset;
33 static bool showpath = false;
34 
35 static void display(char **args)
36 {
37  union {
38  Phrasebook::rule_t rule;
39  char buf[1024];
40  } state;
41 
42  while(*args) {
43  Phrasebook::init(&state.rule, sizeof(state));
44  const char **out = &state.rule.list[0];
45  const char *arg = *(args++);
46 
47  if(eq(arg, "@number/", 8))
48  ruleset->number(arg + 8, &state.rule);
49  else if(eq(arg, "@number")) {
50  arg = *(args++);
51  if(!arg)
52  shell::errexit(4, "*** phrasebook: @number: %s\n", _TEXT("argument missing"));
53  ruleset->number(arg, &state.rule);
54  }
55  else if(eq(arg, "@time/", 6))
56  ruleset->time(arg + 6, &state.rule);
57  else if(eq(arg, "@time")) {
58  arg = *(args++);
59  if(!arg)
60  shell::errexit(4, "*** phrasebook: @time: %s\n", _TEXT("argument missing"));
61  ruleset->time(arg, &state.rule);
62  }
63  else if(eq(arg, "@date/", 6))
64  ruleset->date(arg + 6, &state.rule);
65  else if(eq(arg, "@date")) {
66  arg = *(args++);
67  if(!arg)
68  shell::errexit(4, "*** phrasebook: @date: %s\n", _TEXT("argument missing"));
69  ruleset->date(arg, &state.rule);
70  }
71  else if(eq(arg, "@weekday/", 9))
72  ruleset->weekday(arg + 9, &state.rule);
73  else if(eq(arg, "@weekday")) {
74  arg = *(args++);
75  if(!arg)
76  shell::errexit(4, "*** phrasebook: @fulldate: %s\n", _TEXT("argument missing"));
77  ruleset->weekday(arg, &state.rule);
78  }
79  else if(eq(arg, "@fulldate/", 10))
80  ruleset->fulldate(arg + 10, &state.rule);
81  else if(eq(arg, "@fulldate")) {
82  arg = *(args++);
83  if(!arg)
84  shell::errexit(4, "*** phrasebook: @fulldate: %s\n", _TEXT("argument missing"));
85  ruleset->fulldate(arg, &state.rule);
86  }
87  else if(eq(arg, "@spell/", 7))
88  ruleset->spell(arg + 7, &state.rule);
89  else if(eq(arg, "@spell")) {
90  arg = *(args++);
91  if(!arg)
92  shell::errexit(4, "*** phrasebook: @spell: %s\n", _TEXT("argument missing"));
93  ruleset->spell(arg, &state.rule);
94  }
95  else if(eq(arg, "@order/", 7))
96  ruleset->order(arg + 7, &state.rule);
97  else if(eq(arg, "@order")) {
98  arg = *(args++);
99  if(!arg)
100  shell::errexit(4, "*** phrasebook: @order: %s\n", _TEXT("argument missing"));
101  ruleset->order(arg, &state.rule);
102  }
103 
104  else
105  ruleset->literal(arg, &state.rule);
106 
107  ruleset.voices = *voice;
108 
109  if(*out == NULL) {
110  printf("*** %s: failed", arg);
111  if(showpath)
112  printf("\n");
113  }
114  else while(*out) {
115  if(showpath) {
116  char buffer[512];
117  const char *file = Env::path(ruleset, *out, buffer, sizeof(buffer), true);
118  if(!file)
119  printf("*** %s: invalid\n", *out);
120  else
121  printf("%s\n", file);
122  ++out;
123  }
124  else
125  printf("%s ", *(out++));
126  }
127  if(!showpath)
128  printf("\n");
129  }
130 }
131 
132 PROGRAM_MAIN(argc, argv)
133 {
134  shell::bind("phrasebook");
135  shell args(argc, argv);
136 
137  Env::tool(&args);
138 
139  if(is(prefix))
140  Env::set("prefix", *prefix);
141 
142  if(is(phrasebook))
143  Env::set("voices", *phrasebook);
144 
145  if(is(suffix))
146  Env::set("extension", *suffix);
147 
148  if(is(helpflag) || is(althelp)) {
149  printf("%s\n", _TEXT("Usage: phrasebook [options] command arguments..."));
150  printf("%s\n\n", _TEXT("Phrasebook operations"));
151  printf("%s\n", _TEXT("Options:"));
152  shell::help();
153  printf("\n%s\n", _TEXT("Report bugs to dyfet@gnu.org"));
154  PROGRAM_EXIT(0);
155  }
156 
157  if(!args())
158  shell::errexit(1, "*** phrasebook: %s\n",
159  _TEXT("no command specified"));
160 
161  const char *cmd = args[0];
162 
163  argv = args.argv();
164  ++argv;
165 
166  if(is(lang))
167  ruleset.book = Phrasebook::find(*lang);
168  else
169  ruleset.book = Phrasebook::find(NULL);
170 
171  if(!ruleset.book)
172  shell::errexit(3, "*** phrasebook: %s: %s\n",
173  *lang, _TEXT("language not found"));
174 
175  if(case_eq(cmd, "display"))
176  display(argv);
177  else if(case_eq(cmd, "paths")) {
178  showpath = true;
179  display(argv);
180  }
181  else
182  shell::errexit(2, "*** phrasebook: %s: %s\n",
183  cmd, _TEXT("unknown command"));
184 
185  PROGRAM_EXIT(0);
186 }
187 
#define BAYONNE_NAMESPACE
Definition: bayonne.h:25
GNU Bayonne library namespace.
PROGRAM_MAIN(argc, argv)