| File: | modules/rxp/ttsxml.cc |
| Location: | line 153, column 5 |
| Description: | Value stored to 'utt' is never read |
| 1 | /*************************************************************************/ |
| 2 | /* */ |
| 3 | /* Centre for Speech Technology Research */ |
| 4 | /* University of Edinburgh, UK */ |
| 5 | /* Copyright (c) 1998 */ |
| 6 | /* All Rights Reserved. */ |
| 7 | /* */ |
| 8 | /* Permission is hereby granted, free of charge, to use and distribute */ |
| 9 | /* this software and its documentation without restriction, including */ |
| 10 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 11 | /* distribute, sublicense, and/or sell copies of this work, and to */ |
| 12 | /* permit persons to whom this work is furnished to do so, subject to */ |
| 13 | /* the following conditions: */ |
| 14 | /* 1. The code must retain the above copyright notice, this list of */ |
| 15 | /* conditions and the following disclaimer. */ |
| 16 | /* 2. Any modifications must be clearly marked as such. */ |
| 17 | /* 3. Original authors' names are not deleted. */ |
| 18 | /* 4. The authors' names are not used to endorse or promote products */ |
| 19 | /* derived from this software without specific prior written */ |
| 20 | /* permission. */ |
| 21 | /* */ |
| 22 | /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */ |
| 23 | /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ |
| 24 | /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ |
| 25 | /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */ |
| 26 | /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ |
| 27 | /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ |
| 28 | /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ |
| 29 | /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ |
| 30 | /* THIS SOFTWARE. */ |
| 31 | /* */ |
| 32 | /*************************************************************************/ |
| 33 | /* */ |
| 34 | /* Author : Alan W Black */ |
| 35 | /* Date : May 1998 */ |
| 36 | /* ------------------------------------------------------------------- */ |
| 37 | /* Interface between festival and the Richard's XML parser */ |
| 38 | /* */ |
| 39 | /* Provides a LISP function to do the analysis so that this directory */ |
| 40 | /* reasonable be optional */ |
| 41 | /* */ |
| 42 | /*************************************************************************/ |
| 43 | |
| 44 | #include "EST_Pathname.h" |
| 45 | #include "festival.h" |
| 46 | #include "text.h" |
| 47 | #include "rxp.h" |
| 48 | |
| 49 | // So we can share the known_ids table. |
| 50 | #include "ling_class/EST_utterance_xml.h" |
| 51 | |
| 52 | using namespace std; |
| 53 | |
| 54 | |
| 55 | static InputSource entity_open(Entity ent, void *arg); |
| 56 | |
| 57 | static LISP tts_file_xml(LISP filename) |
| 58 | { |
| 59 | // Parse the xml file using the LTG's xml parser |
| 60 | EST_String inname = get_c_string(filename); |
| 61 | EST_String line, type, remainder; |
| 62 | Parser p; |
| 63 | Entity ent = 0; |
| 64 | InputSource source = 0; |
| 65 | LISP element_defs; |
| 66 | LISP utt = NIL((struct obj *) 0); // for cummulation of tokens |
| 67 | |
| 68 | if (inname == "-") |
| 69 | source = SourceFromStream("<stdin>",stdinstdin); |
| 70 | else |
| 71 | { |
| 72 | ent = NewExternalEntity("",0,strdup8(inname),0,0)NewExternalEntityN("", "" ? strlen(("")) : 0, 0, strdup8(inname ), 0, 0); |
| 73 | if (ent) |
| 74 | source = EntityOpen(ent); |
| 75 | } |
| 76 | |
| 77 | if (!source) |
| 78 | { |
| 79 | cerr << "xml: unable to open input file \"" << inname << "\"" << endl; |
| 80 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
| 81 | } |
| 82 | element_defs = siod_get_lval("xxml_elements",NULL__null); |
| 83 | p = NewParser(); |
| 84 | ParserSetEntityOpener(p, entity_open); |
| 85 | ParserSetFlag(p, ReturnDefaultedAttributes, 1); |
| 86 | if (ParserPush(p, source) == -1) |
| 87 | { |
| 88 | cerr << "xml: parser error\n" << endl; |
| 89 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
| 90 | } |
| 91 | |
| 92 | while (1) |
| 93 | { |
| 94 | XBit bit = ReadXBit(p); |
| 95 | if (bit->type == XBIT_eof) |
| 96 | break; |
| 97 | else if (bit->type == XBIT_start) |
| 98 | { |
| 99 | Attribute b; |
| 100 | LISP att=NIL((struct obj *) 0); |
| 101 | for (b=bit->attributes; b; b=b->next) |
| 102 | att = cons(cons(rintern(b->definition->name), |
| 103 | cons(cons(rintern(b->value),NIL((struct obj *) 0)),NIL((struct obj *) 0))),att); |
| 104 | utt = xxml_call_element_function( |
| 105 | EST_String("(")+bit->element_definition->name,att, |
| 106 | element_defs,utt); |
| 107 | } |
| 108 | else if (bit->type == XBIT_end) |
| 109 | { |
| 110 | utt = xxml_call_element_function( |
| 111 | EST_String(")")+bit->element_definition->name,NIL((struct obj *) 0), |
| 112 | element_defs,utt); |
| 113 | } |
| 114 | else if (bit->type == XBIT_empty) |
| 115 | { |
| 116 | Attribute b; |
| 117 | LISP att=NIL((struct obj *) 0); |
| 118 | for (b=bit->attributes; b; b=b->next) |
| 119 | att = cons(cons(rintern(b->definition->name), |
| 120 | cons(cons(rintern(b->value),NIL((struct obj *) 0)),NIL((struct obj *) 0))),att); |
| 121 | utt = xxml_call_element_function( |
| 122 | EST_String(bit->element_definition->name),att, |
| 123 | element_defs,utt); |
| 124 | } |
| 125 | else if (bit->type == XBIT_pcdata) |
| 126 | { |
| 127 | utt = xxml_get_tokens(bit->pcdata_charsS1, |
| 128 | siod_get_lval("xxml_word_features",NULL__null), |
| 129 | utt); |
| 130 | } |
| 131 | else if (bit->type == XBIT_cdsect) |
| 132 | { |
| 133 | utt = xxml_get_tokens(bit->cdsect_charsS1, |
| 134 | siod_get_lval("xxml_word_features",NULL__null), |
| 135 | utt); |
| 136 | } |
| 137 | else if (bit->type == XBIT_pi) |
| 138 | { |
| 139 | cerr << "xml: ignoring pi " << bit->pi_charsS2 << endl; |
| 140 | } |
| 141 | else if (bit->type == XBIT_error) |
| 142 | { |
| 143 | ParserPerror(p,bit); |
| 144 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | // ignore it |
| 149 | } |
| 150 | FreeXBit(bit); |
| 151 | } |
| 152 | // Last call (should synthesize trailing tokens) |
| 153 | utt = xxml_call_element_function(" ",NIL((struct obj *) 0),element_defs,utt); |
Value stored to 'utt' is never read | |
| 154 | |
| 155 | FreeDtd(p->dtd); |
| 156 | FreeParser(p); |
| 157 | if (ent) FreeEntity(ent); |
| 158 | return NIL((struct obj *) 0); |
| 159 | } |
| 160 | |
| 161 | static LISP xml_register_id(LISP pattern_l, LISP result_l) |
| 162 | { |
| 163 | EST_String pattern = get_c_string(pattern_l); |
| 164 | EST_String result = get_c_string(result_l); |
| 165 | |
| 166 | utterance_xml_register_id(pattern, result); |
| 167 | return NIL((struct obj *) 0); |
| 168 | } |
| 169 | |
| 170 | static LISP xml_registered_ids() |
| 171 | { |
| 172 | EST_StrList ids; |
| 173 | utterance_xml_registered_ids(ids); |
| 174 | LISP result= NIL((struct obj *) 0); |
| 175 | |
| 176 | EST_Litem *p; |
| 177 | |
| 178 | for(p=ids.head(); p != NULL__null; p=p->next()) |
| 179 | { |
| 180 | EST_String pat = ids(p); |
| 181 | p=p->next(); |
| 182 | EST_String res = ids(p); |
| 183 | result = cons( |
| 184 | cons(strcons(pat.length(), pat), |
| 185 | strcons(res.length(), res)), |
| 186 | result); |
| 187 | } |
| 188 | |
| 189 | return result; |
| 190 | } |
| 191 | |
| 192 | void festival_rxp_init() |
| 193 | { |
| 194 | proclaim_module("rxp"); |
| 195 | |
| 196 | init_subr_1("tts_file_xml",tts_file_xml, |
| 197 | "(tts_file_xml FILE)\n\ |
| 198 | Low level tts processor for XML files. This assumes that element\n\ |
| 199 | instructions are set up in the variable xxml_elements."); |
| 200 | |
| 201 | init_subr_2("xml_register_id", xml_register_id, |
| 202 | "(xml_register_id PATTERN RESULT) \n\ |
| 203 | Add a rule for where to find XML entities such as DTDs.\n\ |
| 204 | The pattern is a regular expression, the result is a string\n\ |
| 205 | with substitutions. If the PATTERN matches the a PUBLIC\n\ |
| 206 | or SYSTEM identifier of an XML entity, the RESULT is expanded\n\ |
| 207 | and then used as a filename."); |
| 208 | |
| 209 | init_subr_0("xml_registered_ids", xml_registered_ids, |
| 210 | "(xml_registered_ids) \n\ |
| 211 | Return the current list of places to look for XML entities."); |
| 212 | } |
| 213 | |
| 214 | static InputSource entity_open(Entity ent, void *arg) |
| 215 | { |
| 216 | (void)arg; |
| 217 | return utterance_xml_try_and_open(ent); |
| 218 | } |