Revision: 9c148a9ea2b6 Author: John Boyer <john.boyer@xxxxxxxxxxxxxxxxx> Date: Wed Aug 8 18:00:50 2012 Log: Translate text and backtranslate with formatFor utd now work http://code.google.com/p/liblouisutdml/source/detail?r=9c148a9ea2b6 Modified: /liblouisutdml/convert_utd.c /liblouisutdml/liblouisutdml.c /liblouisutdml/louisutdml.h /liblouisutdml/transcriber.c ======================================= --- /liblouisutdml/convert_utd.c Sat Jul 28 21:11:59 2012 +++ /liblouisutdml/convert_utd.c Wed Aug 8 18:00:50 2012 @@ -94,3 +94,50 @@ } return 1; } + +int +pass2_conv () +{ + xmlNode *rootElement = xmlDocGetRootElement (ud->doc); + int haveSemanticFile; + xmlNode *child; + if (rootElement == NULL) + { + lou_logPrint ("Document is empty"); + return 0; + } + clean_semantic_table (); + ud->semantic_files = ud->pass2_conv_sem; + haveSemanticFile = compile_semantic_table (rootElement); + nullPrivate (rootElement); + do_xpath_expr (); + examine_document (rootElement); + if (!haveSemanticFile) + return 0; + ud->format_for = utd; + ud->top = -1; + ud->style_top = -1; + ud->text_length = 0; + ud->translated_length = 0; + child = rootElement->children; + while (child) + { + switch (child->type) + { + case XML_ELEMENT_NODE: + transcribe_paragraph (child, 0); + break; + case XML_TEXT_NODE: + insert_text (child); + break; + case XML_CDATA_SECTION_NODE: + transcribe_cdataSection (child); + break; + default: + break; + } + child = child->next; + } + end_document (); + return 1; +} ======================================= --- /liblouisutdml/liblouisutdml.c Sat Jul 28 21:11:59 2012 +++ /liblouisutdml/liblouisutdml.c Wed Aug 8 18:00:50 2012 @@ -212,9 +212,13 @@ break; if (inbuf[k] != '<') { - transcribe_text_string (); + if (ud->format_for == utd) + k = utd_transcribe_text_string (); + else + k = transcribe_text_string (); *outlen = ud->outlen_so_far; - return 1; + lou_logEnd (); + return k; } if (inbuf[k + 1] == '?') xmlInbuf = (char *) inbuf; @@ -235,9 +239,7 @@ if (xmlInbuf != inbuf) free (xmlInbuf); lou_logEnd (); - if (k == 0) - return 0; - return 1; + return k; } int @@ -268,9 +270,7 @@ if (ud->outFile != stdout) fclose (ud->outFile); lou_logEnd (); - if (k == 0) - return 0; - return 1; + return k; } int @@ -282,6 +282,7 @@ /* Translate the text file in inFileName into braille according to * the specifications in configFileList. If there are errors, print * an error message and return 0.*/ + int k; widechar outbuf[2 * BUFSIZE]; if (!read_configuration_file (configFileList, logFileName, settingsString, mode)) @@ -308,17 +309,20 @@ } else ud->outFile = stdout; - if (!transcribe_text_file ()) + if (ud->format_for == utd) + k = utd_transcribe_text_file (); + else + k = transcribe_text_file (); + if (!k) { freeEverything (); - return 0; } if (ud->inFile != stdin) fclose (ud->inFile); if (ud->outFile != stdout) fclose (ud->outFile); lou_logEnd (); - return 1; + return k; } int EXPORT_CALL @@ -329,6 +333,7 @@ const char *logFileName, const char *settingsString, unsigned int mode) { + int k; if (!read_configuration_file (configFileList, logFileName, settingsString, mode)) return 0; @@ -337,10 +342,13 @@ ud->outbuf = outbuf; ud->outlen = *outlen; ud->inFile = ud->outFile = NULL; - if (!back_translate_braille_string ()) + if (ud->format_for == utd) + k = utd_back_translate_braille_string (); + else + k = back_translate_braille_string (); + if (!k) { freeEverything (); - return 0; } *outlen = ud->outlen_so_far; lou_logEnd (); @@ -357,6 +365,7 @@ * xml file or a text file according to * the specifications in configFileList. If there are errors, print an * error message and return 0.*/ + int k; widechar outbuf[2 * BUFSIZE]; if (!read_configuration_file (configFileList, logFileName, settingsString, mode)) @@ -383,10 +392,13 @@ } else ud->outFile = stdout; - if (!back_translate_file ()) + if (ud->format_for == utd) + k = utd_back_translate_file (); + else + k = back_translate_file (); + if (!k) { freeEverything (); - return 0; } if (ud->inFile != stdin) fclose (ud->inFile); ======================================= --- /liblouisutdml/louisutdml.h Mon Jul 30 07:52:19 2012 +++ /liblouisutdml/louisutdml.h Wed Aug 8 18:00:50 2012 @@ -278,6 +278,7 @@ const char *edit_table_name; const char *semantic_files; const char *converter_sem; + const char *pass2_conv_sem; widechar print_page_number[MAXNUMLEN]; widechar braille_page_string[MAXNUMLEN]; char lineEnd[8]; @@ -393,4 +394,8 @@ int ignore_case_comp (const char *str1, const char *str2, int length); void insert_text_string (xmlNode *node, xmlChar *str); void do_attrtotext (xmlNode *node); +int utd_transcribe_text_file (); +int utd_transcribe_text_string (); +int utd_back_translate_braille_string (); +int utd_back_translate_file (); #endif /*louisutdml_h */ ======================================= --- /liblouisutdml/transcriber.c Mon Jul 30 07:52:19 2012 +++ /liblouisutdml/transcriber.c Wed Aug 8 18:00:50 2012 @@ -120,8 +120,6 @@ static char *makeRomanNumber (int n); static int utd_start (); static int utd_finish (); -static int utd_transcribe_text_string (); -static int utd_transcribe_text_file (); static int utd_insert_translation (const char *table); static void utd_insert_text (xmlNode * node, int length); static int utd_makeBlankLines (int number, int beforeAfter); @@ -307,7 +305,6 @@ if (!start_document ()) return 0; start_style (docStyle, NULL); - ud->outbuf = outbufx; ud->outbuf1_len = outlenx; ud->input_encoding = ud->input_text_encoding; @@ -3552,7 +3549,7 @@ return 1; } -static int +int utd_transcribe_text_string () { xmlNode *addPara = makeDaisyDoc (); @@ -3597,7 +3594,7 @@ return 1; } -static int +int utd_transcribe_text_file () { xmlNode *addPara = makeDaisyDoc (); @@ -3697,7 +3694,7 @@ goodTrans = lou_backTranslate (ud->main_braille_table, ud->text_buffer, &translationLength, backBuf, &translatedLength, NULL, NULL, - backIndices, NULL, NULL, dotsIO); + backIndices, NULL, NULL, 0); if (!goodTrans) { translatedLength = translationLength; For a description of the software, to download it and links to project pages go to http://www.abilitiessoft.com