1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3 * Copyright (c) 2007 Carnegie Mellon University. All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * This work was supported in part by funding from the Defense Advanced
19 * Research Projects Agency and the National Science Foundation of the
20 * United States of America, and the CMU Sphinx Speech Consortium.
22 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * ====================================================================
40 #include <sphinxbase/hash_table.h>
41 #include <sphinxbase/fsg_model.h>
42 #include <sphinxbase/jsgf.h>
43 #include <sphinxbase/err.h>
44 #include <sphinxbase/strfuncs.h>
47 get_fsg(jsgf_t *grammar, const char *name)
49 jsgf_rule_iter_t *itor;
50 logmath_t *lmath = logmath_init(1.0001, 0, 0);
51 fsg_model_t *fsg = NULL;
53 for (itor = jsgf_rule_iter(grammar); itor;
54 itor = jsgf_rule_iter_next(itor)) {
55 jsgf_rule_t *rule = jsgf_rule_iter_rule(itor);
56 char const *rule_name = jsgf_rule_name(rule);
58 if ((name == NULL && jsgf_rule_public(rule))
59 || (name && strlen(rule_name)-2 == strlen(name) &&
60 0 == strncmp(rule_name + 1, name, strlen(rule_name) - 2))) {
61 fsg = jsgf_build_fsg_raw(grammar, rule, logmath_retain(lmath), 1.0);
62 jsgf_rule_iter_free(itor);
72 main(int argc, char *argv[])
80 if (argc > 1 && 0 == strcmp(argv[1], "-fsm")) {
85 jsgf = jsgf_parse_file(argc > 1 ? argv[1] : NULL, NULL);
89 fsg = get_fsg(jsgf, argc > 2 ? argv[2] : NULL);
98 fsg_model_writefile_fsm(fsg, outfile);
100 fsg_model_write_fsm(fsg, stdout);
102 fsg_model_writefile_symtab(fsg, symfile);
106 fsg_model_writefile(fsg, outfile);
108 fsg_model_write(fsg, stdout);
111 jsgf_grammar_free(jsgf);
117 /** Silvio Moioli: Windows CE/Mobile entry point added. */
118 #if defined(_WIN32_WCE)
119 #pragma comment(linker,"/entry:mainWCRTStartup")
122 //Windows Mobile has the Unicode main only
123 int wmain(int32 argc, wchar_t *wargv[]) {
129 argv = malloc(argc*sizeof(char*));
130 for (i=0; i<argc; i++){
131 wlen = lstrlenW(wargv[i]);
132 len = wcstombs(NULL, wargv[i], wlen);
133 argv[i] = malloc(len+1);
134 wcstombs(argv[i], wargv[i], wlen);
137 //assuming ASCII parameters
138 return main(argc, argv);