commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/gnue-common/scripts gnuedtd


From: Jason Cater
Subject: gnue/gnue-common/scripts gnuedtd
Date: Wed, 04 Jul 2001 17:39:28 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/07/04 17:39:28

Modified files:
        gnue-common/scripts: gnuedtd 

Log message:
        Improved gnuedtd; added readable entities

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/scripts/gnuedtd.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue/gnue-common/scripts/gnuedtd
diff -u gnue/gnue-common/scripts/gnuedtd:1.1 
gnue/gnue-common/scripts/gnuedtd:1.2
--- gnue/gnue-common/scripts/gnuedtd:1.1        Mon Jul  2 17:23:03 2001
+++ gnue/gnue-common/scripts/gnuedtd    Wed Jul  4 17:39:28 2001
@@ -1,7 +1,37 @@
-#!env python 
+#!python 
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it 
+# and/or modify it under the terms of the GNU General Public 
+# License as published by the Free Software Foundation; either 
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be 
+# useful, but WITHOUT ANY WARRANTY; without even the implied 
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public 
+# License along with program; see the file COPYING. If not, 
+# write to the Free Software Foundation, Inc., 59 Temple Place 
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2001 Free Software Foundation
+#
+#
+# FILE:
+# gnuedtd
+#
+# DESCRIPTION:
+# This script generates a DTD for the client apps based on 
+# their GParser markup
+#
+# NOTES:
+#
 
 import sys, string, time
-from gnue.common import GParser
+from gnue.common import GParser, GTypecast
 
 class GenerateDTD:
   def __init__ (self, tool, dest=sys.__stdout__): 
@@ -28,8 +58,10 @@
     self.xmlElements = xmlElements
     self.dest = dest
     self.processedTags = {}
+    self.typecasts = {}
 
     for element in xmlElements.keys(): 
+      # Get a mapping of all parent tags
       if xmlElements[element].has_key('ParentTags') and \
          xmlElements[element]['ParentTags'] != None: 
         for parent in xmlElements[element]['ParentTags']: 
@@ -39,6 +71,12 @@
              xmlElements[element].has_key('UsableBySiblings') and \
              xmlElements[element]['UsableBySiblings']
 
+      # Find out what Typecasts are being used
+      if xmlElements[element].has_key('Attributes'): 
+        for att in xmlElements[element]['Attributes'].keys():  
+          self.typecasts[xmlElements[element]['Attributes'][att]['Typecast']] \
+                      = 'CDATA'
+
     dest.write ('<!-- %s DTD (Version %s) -->\n' % (name, version))
 
     dest.write ("""
@@ -68,7 +106,46 @@
 <!ENTITY gt "&#62;">
 <!ENTITY amp "&#38;#38;">
 
+<!-- +---------------------------------------------------+ --> 
+<!-- | Datatype entities to make DTD more human readable | -->
+<!-- +---------------------------------------------------+ -->
+
 """)
+    if self.typecasts.has_key (GTypecast.text):  
+      self.typecasts[GTypecast.text] = '%text;'
+      dest.write('<!ENTITY % text "CDATA">\n\n') 
+
+    if self.typecasts.has_key (GTypecast.boolean):
+      self.typecasts[GTypecast.boolean] = '%boolean;'
+      dest.write('<!ENTITY % boolean "(%true;) #IMPLIED">\n' 
+                 '<!ENTITY % true "">\n\n') 
+
+    if self.typecasts.has_key (GTypecast.number):
+      self.typecasts[GTypecast.number] = '%number;'
+      dest.write('<!ENTITY % number "NMTOKEN">\n' 
+                 '<!-- [-]?[0-9]+([.][0-9]+)? -->\n\n')
+
+    if self.typecasts.has_key (GTypecast.whole):
+      self.typecasts[GTypecast.whole] = '%whole;'
+      dest.write('<!ENTITY % whole "NMTOKEN">\n'
+                 '<!-- [0-9]+ -->\n\n')
+
+    if self.typecasts.has_key (GTypecast.integer):
+      self.typecasts[GTypecast.integer] = '%integer;'
+      dest.write('<!ENTITY % integer "NMTOKEN">\n'
+                 '<!-- [-]?[0-9]+ -->\n\n')
+
+    if self.typecasts.has_key (GTypecast.name):
+      self.typecasts[GTypecast.name] = '%name;'
+      dest.write('<!ENTITY % name "NMTOKEN">\n'
+                 '<!-- [A-Za-z]([A-Z][a-z][0-9][#$_-])* -->\n\n')
+
+    if self.typecasts.has_key (GTypecast.names):
+      self.typecasts[GTypecast.names] = '%names;'
+      dest.write('<!ENTITY & names "CDATA">\n'
+                 '<!-- (%name;)(,[ ]*(%name;))* -->\n\n')
+ 
+    dest.write('\n')
 
     self.elementStack = [['Top level element','form']]
 
@@ -81,23 +158,25 @@
           i = i + 1
 
       if len (self.elementStack[0]) > 1: 
-        self.elementStack[0][1:].sort()
+        elements = self.elementStack[0][1:]
+        elements.sort()
         dest.write('\n<!-- +-' + '-' * (len(self.elementStack[0][0])) + '-+ 
-->\n')
         dest.write('<!-- | %s | -->\n' % self.elementStack[0][0])
         dest.write('<!-- +-' + '-' * (len(self.elementStack[0][0])) + '-+ 
-->\n')
-        for element in self.elementStack[0][1:]: 
+        for element in elements: 
           self.handleElement(element)
         self.elementStack.pop(0)
 
 
-    dest.write ("\n<!-- This DTD is created by gnuedtd\n"
+    dest.write ("\n<!-- This DTD was created by gnuedtd\n"
                   "     Updated: %s   -->\n\n" \
        % ( time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))))
     
 
   #
+  # If a dictionary has a key, return value 
+  # associated w/that key. Otherwise return dflt.
   #
-  #
   def default(self, dict, key, dflt): 
     if dict.has_key(key): 
       return dict[key]
@@ -105,8 +184,8 @@
       return dflt
 
 
-  #
   #
+  # Line wrap a string.  Note, this eliminates redundant spacing
   #
   def wrap(self, indent, text, firstindent=None): 
       if firstindent == None: 
@@ -229,7 +308,7 @@
         if self.default(self.xmlElements[element]['Attributes'][att],
                            'Deprecated',0): 
           self.dest.write(self.wrap(17, 
-            '  <!-- DEPRECATED: Use of the %s attribute (element %s) ' 
+            '  <!-- DEPRECATED: The %s attribute of %s ' 
             'has been deprecated -->' % (att, element),0))
 
 
@@ -239,19 +318,26 @@
           self.dest.write(self.wrap(7, 
             '  <!-- %s -->' % (description), 0))
 
+        datatype = self.default(
+             self.xmlElements[element]['Attributes'][att],
+             'Typecast',GParser.char)
 
+        if datatype == int: 
+          tokentype = "%number;" 
+        else:
+          tokentype = "NMTOKEN"
+
         # handle bool attributes specially
-        if self.default(
-             self.xmlElements[element]['Attributes'][att], 
-             'Typecast',GParser.char) ==  GParser.bool: 
-          self.dest.write(self.wrap(len(attdef),attdef +'NMTOKEN #IMPLIED>',0))
+        if datatype == GParser.bool: 
+          self.dest.write(self.wrap(len(attdef),attdef +'%boolean;>',0))
 
         elif set != None: 
           set = set.keys()
           set.sort()
           if len(set) == 1: 
             indent = len(attdef)
-            attdef = attdef + 'NMTOKEN #FIXED "%s"' % set[0]
+            attdef = attdef + '%s #FIXED "%s">' \
+                % (self.typecasts[datatype], set[0])
           else: 
             attdef = attdef + "("
             indent = len(attdef)
@@ -280,16 +366,24 @@
 
         elif dflt != None: 
           indent = len(attdef)
-          attdef = attdef + ' NMTOKEN #DEFAULT "%s">' % dflt
+          attdef = attdef + ' %s #DEFAULT "%s">' \
+              % (self.typecasts[datatype], dflt) 
           self.dest.write(self.wrap(indent, attdef, 0))
 
         else:
           indent = len(attdef)
-          attdef = attdef + ' CDATA #IMPLIED>'
+          if req: 
+            attdef = attdef + ' %s #REQUIRED>' \
+              % (self.typecasts[datatype]) 
+          else: 
+            attdef = attdef + ' %s #IMPLIED>' \
+              % (self.typecasts[datatype]) 
           self.dest.write(self.wrap(indent, attdef, 0))
           
     
     self.dest.write ("\n")
-
-GenerateDTD(sys.argv[1])
 
+if len(sys.argv) > 1: 
+  GenerateDTD(sys.argv[1])
+else: 
+  GenerateDTD(None)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]