Revision: 76782a6f060a Author: John Boyer <john.boyer@xxxxxxxxxxxxxxxxx> Date: Mon Apr 30 16:55:10 2012 Log: latest changes http://code.google.com/p/liblouisutdml/source/detail?r=76782a6f060a Modified: /java/src/org/liblouis/liblouisutdml.java /liblouisutdml/semantics.c ======================================= --- /java/src/org/liblouis/liblouisutdml.java Tue Dec 13 09:42:49 2011 +++ /java/src/org/liblouis/liblouisutdml.java Mon Apr 30 16:55:10 2012 @@ -123,7 +123,7 @@ byte[]inbuf, byte[]outbuf, int[]outlen, String logFilename, - String settingsSrting, int mode); + String settingsString, int mode); /** the brf characters in inbuf are translated to print characters in outbuf according to the settings in the configuration files and @@ -135,7 +135,7 @@ byte[]outbuf, int[]outlen, String logFilename, - String settingsSrting, + String settingsString, int mode); /** The xml document in inputFile is translated into braille and the ======================================= --- /liblouisutdml/semantics.c Sun Apr 22 21:11:39 2012 +++ /liblouisutdml/semantics.c Mon Apr 30 16:55:10 2012 @@ -482,6 +482,8 @@ memcpy (insertsPtr, &inserts, insertsSize); return insertsPtr; } + +static int insertFromMacro (int which); int insert_code (xmlNode * node, int which) @@ -498,6 +500,11 @@ nodeEntry = (HashEntry *) node->_private; if (nodeEntry == NULL) return 0; + if (nodeEntry->macro) + { + insertFromMacro (which); + return 1; + } if (nodeEntry->inserts == NULL) return 1; inserts = nodeEntry->inserts; @@ -1220,16 +1227,6 @@ else return NULL; } - -char * -is_macro (xmlNode * node) -{ - HashEntry *nodeEntry = (HashEntry *) node->_private; - if (nodeEntry != NULL) - return nodeEntry->macro; - else - return NULL; -} xmlChar * get_attr_value (xmlNode * node) @@ -1407,22 +1404,6 @@ style->first_line_indent = -100; return style; } - -#define MACROSUF " orcam" -xmlChar * -new_macro (xmlChar * name, xmlChar * body) -{ - char *storedBody = alloc_string (body); - char key[MAXNAMELEN]; - if (!semanticTable) - semanticTable = hashNew (); - strcpy (key, name); - strcat (key, MACROSUF); - if (hashLookup (semanticTable, key) != notFound) - return NULL; - hashInsert (semanticTable, key, macroEntry, 0, NULL, NULL, storedBody); - return storedBody; -} StyleType * lookup_style (xmlChar * name) @@ -1434,17 +1415,6 @@ return latestEntry->style; return NULL; } - -unsigned char * -lookup_macro (xmlChar * name) -{ - char key[MAXNAMELEN]; - strcpy (key, name); - strcat (key, MACROSUF); - if (hashLookup (semanticTable, key) != notFound) - return latestEntry->macro; - return NULL; -} StyleType * action_to_style (sem_act action) @@ -1457,7 +1427,7 @@ /* Beginning of macro processing */ /* Hold macro state */ -static char *macro; +static char *macro = NULL; static int macroLength; static int posInMacro;; static xmlNode *macroNode; @@ -1467,8 +1437,8 @@ static void macroError (char *format, ...) { - char buffer[MAXNAMELEN]; char key[40]; + char buffer[MAXNAMELEN]; va_list arguments; va_start (arguments, format); #ifdef WIN32 @@ -1479,7 +1449,50 @@ va_end (arguments); strncpy (key, isMacroEntry->key, strlen (isMacroEntry->key) - 5); lou_logPrint ("Macro %s: %s", key, buffer); - errorCount++; +} + +char * +is_macro (xmlNode * node) +{ + HashEntry *nodeEntry = (HashEntry *) node->_private; + if (nodeEntry != NULL) + return nodeEntry->macro; + else + return NULL; +} + +#define MACROSUF " orcam" + +unsigned char * +lookup_macro (xmlChar * name) +{ + char key[MAXNAMELEN]; + strcpy (key, name); + strcat (key, MACROSUF); + if (hashLookup (semanticTable, key) != notFound) + return latestEntry->macro; + return NULL; +} + +xmlChar * +new_macro (xmlChar * name, xmlChar * body) +{ + char *storedBody = alloc_string (body); + char key[MAXNAMELEN]; + if (!semanticTable) + semanticTable = hashNew (); + strcpy (key, name); + strcat (key, MACROSUF); + if (hashLookup (semanticTable, key) != notFound) + return NULL; + hashInsert (semanticTable, key, macroEntry, 0, NULL, NULL, storedBody); + return storedBody; +} + +static int +insertFromMacro (int which) +{ + return 1; } static int @@ -1593,7 +1606,57 @@ int pos = 0; while (unPos < macroLength) { - } + if (isalpha (macro[unPos])) + { + int namePos = unPos; + char name[40]; + int k = 0; + StyleType *style; + for (; isalnum (macro[namePos]) && namePos < macroLength; namePos++) + name[k++] = macro[namePos]; + name[k] = 0; + if ((style = lookup_style (name)) != NULL) + { + if (macroHasStyle) + { + macroError ("only one style can be specified"); + compiledMacro[0] = '!'; + } + else + { + macroHasStyle = 1; + compiledMacro[pos++] = '~'; + isMacroEntry->style = style; + } + } + else + { + if ((k = find_semantic_number (name)) != notFound) + { + k = sprintf (name, "%s", k); + strcpy (&compiledMacro[pos], name); + pos += k; + if (macro[posInMacro] == '(') + { + k = find_group_length ("()", ¯o[unPos]); + strncpy (&compiledMacro[pos], ¯o[unPos], k); + pos += k; + unPos += k; + } + } + else + { + macroError ("'%s' is neither a style or semantic action", + name); + compiledMacro[0] = '!'; + } + unPos += namePos; + } + if (macro[unPos] == ',') + compiledMacro[pos++] = macro[unPos++]; + } + } + compiledMacro[pos] = 0; strcpy (macro, compiledMacro); return 1; } @@ -1661,8 +1724,8 @@ int end_macro () { - if (macro == NULL) - return 0; + if (macro == NULL) + return 0; executeMacro (); return 1; } For a description of the software, to download it and links to project pages go to http://www.abilitiessoft.com