Revision: e5b9ddfd37b9 Author: John Boyer <john.boyer@xxxxxxxxxxxxxxxxx> Date: Sun Apr 22 21:11:39 2012 Log: Removed kill_safely function and improved error handling. http://code.google.com/p/liblouisutdml/source/detail?r=e5b9ddfd37b9 Deleted: /liblouisutdml/macro.x Modified: /liblouisutdml/liblouisutdml.c /liblouisutdml/louisutdml.h /liblouisutdml/readconfig.c /liblouisutdml/semantics.c /liblouisutdml/transcribe_document.c /liblouisutdml/transcribe_paragraph.c /liblouisutdml/transcriber.c ======================================= --- /liblouisutdml/macro.x Wed Mar 14 19:07:44 2012 +++ /dev/null @@ -1,159 +0,0 @@ -/* Beginning of macro processing */ - -static int -doSemanticActions (xmlNode * node, int *posx) -{ - int pos = *posx; - HashEntry *nodeEntry = (HashEntry *) node->_private; - char *macro = nodeEntry->macro; - int length = strlen (macro); - char *paramStart = NULL; - int retVal = 1; - int semNum = atoi (macro[pos]); - for (; isdigit (macro[pos]) && pos < length; pos++); - if (macro[pos] == '(') - paramStart = macro[++pos]; - paramLength = find_group_length ("()", paramStart - 1); - switch (semNum) - { - case no: - if (ud->text_length > 0 && ud->text_length < MAX_LENGTH - && ud->text_buffer[ud->text_length - 1] > 32) - ud->text_buffer[ud->text_length++] = 32; - break; - case skip: - retVal = -1; - case markhead: - ud->head_node = node; - break; - case configtweak: -{ - int k; - int kk = 0; - xmlChar configString[2 * MAXNAMELEN]; - configString[kk++] = ud->string_escape; - for (k = 0; k < paramLength; k++) - { - if (paramStart[k] == '=') - configString[kk++] = ' '; - else if (paramStart[k] == ';') - configString[kk++] = '\n'; - else - configString[kk++] = (xmlChar) paramStart[k]; - } - configString[kk++] = '\n'; - configString[kk] = 0; - if (!config_compileSettings ((char *) configString)) - return 0; -} - ud->main_braille_table = ud->contracted_table_name; - if (!lou_getTable (ud->main_braille_table)) - { - lou_logPrint ("Cannot open main table %s", ud->main_braille_table); - kill_safely (); - } - break; - case htmllink: - if (ud->format_for != browser) - break; - insert_linkOrTarget (node, 0); - break; - case htmltarget: - if (ud->format_for != browser) - break; - insert_linkOrTarget (node, 1); - break; - case boxline: - do_boxline (node); - break; - case blankline: - do_blankline (); - break; - case linespacing: - do_linespacing (node); - break; - case softreturn: - do_softreturn (); - break; - case righthandpage: - do_righthandpage (); - break; - case code: - transcribe_computerCode (node, 0); - break; - case math: - transcribe_math (node, 0); - break; - case graphic: - transcribe_graphic (node, 0); - break; - case chemistry: - transcribe_chemistry (node, 0); - break; - case music: - transcribe_music (node, 0); - break; - case changetable: - change_table (node); - break; - case pagenum: - do_pagenum (); - break; - default: - retVal = 0; - } - *posx = pos; - return retVal; -} - -static int -compileMacro (HashEntry * nodeEntry) -{ - xmlChar *uncompiledMacro = nodeEntry->macro; - xmlChar compiledMacro[4 * MAXNAMELEN]; - int unPos = 0; - int pos = 0; - while (unPos < strlen (uncompiledMacro)) - { - } - strcpy (uncompiledMacro, compiledMacro); - return 1; -} - -int -start_macro (xmlNode * node) -{ - HashEntry *nodeEntry = (HashEntry *) node->_private; - xmlChar *macro; - int pos = 0; - int hasStyle = 0; - if (nodeEntry == NULL || nodeEntry->macro == NULL) - return 0; - /*compile macro the first time it is used. */ - if (isalpha (nodeEntry->macro[0])) - compileMacro (nodeEntry); - macro = nodeEntry->macro; - if (macro[0] == '!') - /* Contains errors */ - return -1; - while (pos < strlen (macro)) - { - if (isdigit (macro[pos])) - doSemanticActions (node, &pos); - if (mcro[pos] == ',') - pos++; - if (macro[pos] == '~') - { - start_style (nodeEntry->style, node); - hasStyle = `; - pos++; - } - } - return hasStyle; -} - -end_macro () -{ -} - -/* End of macro processing */ ======================================= --- /liblouisutdml/liblouisutdml.c Sun Apr 15 13:04:06 2012 +++ /liblouisutdml/liblouisutdml.c Sun Apr 22 21:11:39 2012 @@ -64,6 +64,8 @@ static xmlParserCtxt *ctxt; static int libxml2_initialized = 0; +static void freeEverything (); + static int processXmlDocument (const char *inputDoc, int length) { @@ -105,14 +107,16 @@ if (ud->doc == NULL) { lou_logPrint ("Document could not be processed"); - kill_safely (); + freeEverything (); + return 0; } if (ud->format_for >= utd && strcmp (ud->doc->encoding, "UTF-8") != 0) { lou_logPrint ( "This format requires UTF-8 encoding, not '%s'", ud->doc->encoding); - kill_safely (); + freeEverything (); + return 0; } rootElement = xmlDocGetRootElement (ud->doc); if (rootElement == NULL) @@ -139,20 +143,18 @@ return 1; } -void -kill_safely () -{ - lou_logPrint ("liblouisutdml is terminating."); +static void +freeEverything () +{ lou_logEnd (); if (ud->doc != NULL) xmlFreeDoc (ud->doc); lbu_free (); if (!libxml2_initialized) - exit (1); + return; xmlCleanupParser (); initGenericErrorDefaultFunc (NULL); xmlFreeParserCtxt (ctxt); - exit (1); } void *EXPORT_CALL ======================================= --- /liblouisutdml/louisutdml.h Sat Apr 21 16:32:06 2012 +++ /liblouisutdml/louisutdml.h Sun Apr 22 21:11:39 2012 @@ -382,7 +382,6 @@ int utd2transinxml (xmlNode * node); int utd2volumes (xmlNode * node); int hasAttrValue (xmlNode *node, char *attrName, char *value); -void kill_safely (); xmlChar * new_macro (xmlChar * name, xmlChar *body); unsigned char * lookup_macro (xmlChar * name); char *is_macro (xmlNode *node); ======================================= --- /liblouisutdml/readconfig.c Sun Apr 22 11:28:04 2012 +++ /liblouisutdml/readconfig.c Sun Apr 22 21:11:39 2012 @@ -1249,7 +1249,7 @@ if (!(ud = malloc (sizeof (UserData)))) { lou_logPrint ("liblouisutdml: not enough memory for buffers"); - kill_safely (); + return 0; } } memset (ud, 0, sizeof (UserData)); ======================================= --- /liblouisutdml/semantics.c Sun Apr 22 11:28:04 2012 +++ /liblouisutdml/semantics.c Sun Apr 22 21:11:39 2012 @@ -1530,7 +1530,7 @@ if (!lou_getTable (ud->main_braille_table)) { lou_logPrint ("Cannot open main table %s", ud->main_braille_table); - kill_safely (); + return 0; } break; case htmllink: ======================================= --- /liblouisutdml/transcribe_document.c Fri Feb 17 07:19:45 2012 +++ /liblouisutdml/transcribe_document.c Sun Apr 22 21:11:39 2012 @@ -43,7 +43,8 @@ ud->style_top = -1; ud->text_length = 0; ud->translated_length = 0; - start_document (); + if (!start_document ()) + return 0; push_sem_stack (node); if ((style = is_style (node)) != NULL) start_style (style, node); ======================================= --- /liblouisutdml/transcribe_paragraph.c Tue Apr 17 08:55:37 2012 +++ /liblouisutdml/transcribe_paragraph.c Sun Apr 22 21:11:39 2012 @@ -201,7 +201,7 @@ if (!lou_getTable (ud->main_braille_table)) { lou_logPrint ("Cannot open main table %s", ud->main_braille_table); - kill_safely (); + return 0; } if (action != 0) pop_sem_stack (); ======================================= --- /liblouisutdml/transcriber.c Tue Apr 17 08:55:37 2012 +++ /liblouisutdml/transcriber.c Sun Apr 22 21:11:39 2012 @@ -150,7 +150,7 @@ if (!(firstTableHeader = lou_getTable (ud->main_braille_table))) { lou_logPrint ("Cannot open main table %s", ud->main_braille_table); - kill_safely (); + return 0; } if (ud->has_contentsheader) ud->braille_page_number = 1; @@ -249,7 +249,7 @@ StyleType *docStyle = lookup_style ("document"); StyleType *paraStyle = lookup_style ("para"); if (!start_document ()) - kill_safely (); + return 0; ud->input_encoding = ud->input_text_encoding; start_style (docStyle, NULL); while (1) @@ -305,7 +305,7 @@ StyleType *docStyle = lookup_style ("document"); StyleType *paraStyle = lookup_style ("para"); if (!start_document ()) - kill_safely (); + return 0; start_style (docStyle, NULL); ud->outbuf = outbufx; ud->outbuf1_len = outlenx; @@ -686,7 +686,7 @@ if (!k) { lou_logPrint ("Cannot find table %s", table); - kill_safely (); + return 0; } if ((ud->translated_length + translatedLength) < MAX_TRANS_LENGTH) ud->translated_length += translatedLength; For a description of the software, to download it and links to project pages go to http://www.abilitiessoft.com