i965/vs: Allocate register set once at context creation.
[mesa.git] / src / mesa / drivers / dri / common / xmlpool / gen_xmlpool.py
index 11e24b1332e041798fd6676239cc12919ff1bd01..acfdcf48a194a30cf93b3b451a5d5258ed0f42e0 100644 (file)
@@ -1,30 +1,47 @@
 #!/usr/bin/python
 
+#
+# Usage:
+#     gen_xmlpool.py /path/to/t_option.h localedir lang lang lang ...
+#
+# For each given language, this script expects to find a .mo file at
+# `{localedir}/{language}/LC_MESSAGES/options.mo`.
+#
+
 import sys
 import gettext
 import re
 
+# Path to t_options.h
+template_header_path = sys.argv[1]
+
+localedir = sys.argv[2]
+
 # List of supported languages
-languages = sys.argv[1:]
+languages = sys.argv[3:]
 
 # Escape special characters in C strings
 def escapeCString (s):
     escapeSeqs = {'\a' : '\\a', '\b' : '\\b', '\f' : '\\f', '\n' : '\\n',
-                  '\r' : '\\r', '\t' : '\\t', '\v' : '\\v',
-                  '"' : "''", '\\' : '\\\\'}
+                  '\r' : '\\r', '\t' : '\\t', '\v' : '\\v', '\\' : '\\\\'}
     # " -> '' is a hack. Quotes (") aren't possible in XML attributes.
     # Better use Unicode characters for typographic quotes in option
     # descriptions and translations.
     i = 0
     r = ''
     while i < len(s):
-        if escapeSeqs.has_key(s[i]):
-            if s[i] == '"':
-                sys.stderr.write (
-                    "Warning: Double quotes don't work in XML attributes. "
-                    "Escaping with ''.\n"
-                    "Consider using typographic quotes (\\u201c-\\u201f) "
-                    "instead.\n%s\n" % repr(s))
+        # Special case: escape double quote with \u201c or \u201d, depending
+        # on whether it's an open or close quote. This is needed because plain
+        # double quotes are not possible in XML attributes.
+        if s[i] == '"':
+            if i == len(s)-1 or s[i+1].isspace():
+                # close quote
+                q = u'\u201c'
+            else:
+                # open quote
+                q = u'\u201d'
+            r = r + q
+        elif escapeSeqs.has_key(s[i]):
             r = r + escapeSeqs[s[i]]
         else:
             r = r + s[i]
@@ -130,7 +147,7 @@ def expandMatches (matches, translations, end=None):
 translations = [("en", gettext.NullTranslations())]
 for lang in languages:
     try:
-        trans = gettext.translation ("options", ".", [lang])
+        trans = gettext.translation ("options", localedir, [lang])
     except IOError:
         sys.stderr.write ("Warning: language '%s' not found.\n" % lang)
         continue
@@ -151,7 +168,7 @@ print \
 
 # Process the options template and generate options.h with all
 # translations.
-template = file ("t_options.h", "r")
+template = file (template_header_path, "r")
 descMatches = []
 for line in template:
     if len(descMatches) > 0: