mirror of
				https://gitlab.gnome.org/GNOME/libxml2.git
				synced 2025-10-24 13:33:01 +03:00 
			
		
		
		
	Converting apibuild.py to python3
not finished ....
This commit is contained in:
		
							
								
								
									
										376
									
								
								doc/apibuild.py
									
									
									
									
									
								
							
							
						
						
									
										376
									
								
								doc/apibuild.py
									
									
									
									
									
								
							| @@ -84,18 +84,18 @@ ignored_words = { | ||||
| } | ||||
|  | ||||
| def escape(raw): | ||||
|     raw = string.replace(raw, '&', '&') | ||||
|     raw = string.replace(raw, '<', '<') | ||||
|     raw = string.replace(raw, '>', '>') | ||||
|     raw = string.replace(raw, "'", ''') | ||||
|     raw = string.replace(raw, '"', '"') | ||||
|     raw = raw.replace('&', '&') | ||||
|     raw = raw.replace('<', '<') | ||||
|     raw = raw.replace('>', '>') | ||||
|     raw = raw.replace("'", ''') | ||||
|     raw = raw.replace('"', '"') | ||||
|     return raw | ||||
|  | ||||
| def uniq(items): | ||||
|     d = {} | ||||
|     for item in items: | ||||
|         d[item]=1 | ||||
|     return d.keys() | ||||
|     return list(d.keys()) | ||||
|  | ||||
| class identifier: | ||||
|     def __init__(self, name, header=None, module=None, type=None, lineno = 0, | ||||
| @@ -113,8 +113,8 @@ class identifier: | ||||
|         else: | ||||
|             self.conditionals = conditionals[:] | ||||
|         if self.name == debugsym: | ||||
| 	    print "=> define %s : %s" % (debugsym, (module, type, info, | ||||
| 	                                 extra, conditionals)) | ||||
|             print("=> define %s : %s" % (debugsym, (module, type, info, | ||||
|                                          extra, conditionals))) | ||||
|  | ||||
|     def __repr__(self): | ||||
|         r = "%s %s:" % (self.type, self.name) | ||||
| @@ -123,11 +123,11 @@ class identifier: | ||||
|         if self.module != None: | ||||
|             r = r + " from %s" % (self.module) | ||||
|         if self.info != None: | ||||
| 	    r = r + " " +  `self.info` | ||||
|             r = r + " " +  repr(self.info) | ||||
|         if self.extra != None: | ||||
| 	    r = r + " " + `self.extra` | ||||
|             r = r + " " + repr(self.extra) | ||||
|         if self.conditionals != None: | ||||
| 	    r = r + " " + `self.conditionals` | ||||
|             r = r + " " + repr(self.conditionals) | ||||
|         return r | ||||
|  | ||||
|  | ||||
| @@ -173,8 +173,8 @@ class identifier: | ||||
|     def update(self, header, module, type = None, info = None, extra=None, | ||||
|                conditionals=None): | ||||
|         if self.name == debugsym: | ||||
| 	    print "=> update %s : %s" % (debugsym, (module, type, info, | ||||
| 	                                 extra, conditionals)) | ||||
|             print("=> update %s : %s" % (debugsym, (module, type, info, | ||||
|                                          extra, conditionals))) | ||||
|         if header != None and self.header == None: | ||||
|             self.set_header(module) | ||||
|         if module != None and (self.module == None or self.header == self.module): | ||||
| @@ -220,7 +220,7 @@ class index: | ||||
|             self.references[name] = d | ||||
|  | ||||
|         if name == debugsym: | ||||
| 	    print "New ref: %s" % (d) | ||||
|             print("New ref: %s" % (d)) | ||||
|  | ||||
|         return d | ||||
|  | ||||
| @@ -256,89 +256,89 @@ class index: | ||||
|             elif type == "macro": | ||||
|                 self.macros[name] = d | ||||
|             else: | ||||
| 	        print "Unable to register type ", type | ||||
|                 print("Unable to register type ", type) | ||||
|  | ||||
|         if name == debugsym: | ||||
| 	    print "New symbol: %s" % (d) | ||||
|             print("New symbol: %s" % (d)) | ||||
|  | ||||
|         return d | ||||
|  | ||||
|     def merge(self, idx): | ||||
|         for id in idx.functions.keys(): | ||||
|         for id in list(idx.functions.keys()): | ||||
|               # | ||||
|               # macro might be used to override functions or variables | ||||
|               # definitions | ||||
|               # | ||||
| 	     if self.macros.has_key(id): | ||||
|              if id in self.macros: | ||||
|                  del self.macros[id] | ||||
| 	     if self.functions.has_key(id): | ||||
| 	         print "function %s from %s redeclared in %s" % ( | ||||
| 		    id, self.functions[id].header, idx.functions[id].header) | ||||
|              if id in self.functions: | ||||
|                  print("function %s from %s redeclared in %s" % ( | ||||
|                     id, self.functions[id].header, idx.functions[id].header)) | ||||
|              else: | ||||
|                  self.functions[id] = idx.functions[id] | ||||
|                  self.identifiers[id] = idx.functions[id] | ||||
|         for id in idx.variables.keys(): | ||||
|         for id in list(idx.variables.keys()): | ||||
|               # | ||||
|               # macro might be used to override functions or variables | ||||
|               # definitions | ||||
|               # | ||||
| 	     if self.macros.has_key(id): | ||||
|              if id in self.macros: | ||||
|                  del self.macros[id] | ||||
| 	     if self.variables.has_key(id): | ||||
| 	         print "variable %s from %s redeclared in %s" % ( | ||||
| 		    id, self.variables[id].header, idx.variables[id].header) | ||||
|              if id in self.variables: | ||||
|                  print("variable %s from %s redeclared in %s" % ( | ||||
|                     id, self.variables[id].header, idx.variables[id].header)) | ||||
|              else: | ||||
|                  self.variables[id] = idx.variables[id] | ||||
|                  self.identifiers[id] = idx.variables[id] | ||||
|         for id in idx.structs.keys(): | ||||
| 	     if self.structs.has_key(id): | ||||
| 	         print "struct %s from %s redeclared in %s" % ( | ||||
| 		    id, self.structs[id].header, idx.structs[id].header) | ||||
|         for id in list(idx.structs.keys()): | ||||
|              if id in self.structs: | ||||
|                  print("struct %s from %s redeclared in %s" % ( | ||||
|                     id, self.structs[id].header, idx.structs[id].header)) | ||||
|              else: | ||||
|                  self.structs[id] = idx.structs[id] | ||||
|                  self.identifiers[id] = idx.structs[id] | ||||
|         for id in idx.typedefs.keys(): | ||||
| 	     if self.typedefs.has_key(id): | ||||
| 	         print "typedef %s from %s redeclared in %s" % ( | ||||
| 		    id, self.typedefs[id].header, idx.typedefs[id].header) | ||||
|         for id in list(idx.typedefs.keys()): | ||||
|              if id in self.typedefs: | ||||
|                  print("typedef %s from %s redeclared in %s" % ( | ||||
|                     id, self.typedefs[id].header, idx.typedefs[id].header)) | ||||
|              else: | ||||
|                  self.typedefs[id] = idx.typedefs[id] | ||||
|                  self.identifiers[id] = idx.typedefs[id] | ||||
|         for id in idx.macros.keys(): | ||||
|         for id in list(idx.macros.keys()): | ||||
|               # | ||||
|               # macro might be used to override functions or variables | ||||
|               # definitions | ||||
|               # | ||||
|              if self.variables.has_key(id): | ||||
|              if id in self.variables: | ||||
|                  continue | ||||
|              if self.functions.has_key(id): | ||||
|              if id in self.functions: | ||||
|                  continue | ||||
|              if self.enums.has_key(id): | ||||
|              if id in self.enums: | ||||
|                  continue | ||||
| 	     if self.macros.has_key(id): | ||||
| 	         print "macro %s from %s redeclared in %s" % ( | ||||
| 		    id, self.macros[id].header, idx.macros[id].header) | ||||
|              if id in self.macros: | ||||
|                  print("macro %s from %s redeclared in %s" % ( | ||||
|                     id, self.macros[id].header, idx.macros[id].header)) | ||||
|              else: | ||||
|                  self.macros[id] = idx.macros[id] | ||||
|                  self.identifiers[id] = idx.macros[id] | ||||
|         for id in idx.enums.keys(): | ||||
| 	     if self.enums.has_key(id): | ||||
| 	         print "enum %s from %s redeclared in %s" % ( | ||||
| 		    id, self.enums[id].header, idx.enums[id].header) | ||||
|         for id in list(idx.enums.keys()): | ||||
|              if id in self.enums: | ||||
|                  print("enum %s from %s redeclared in %s" % ( | ||||
|                     id, self.enums[id].header, idx.enums[id].header)) | ||||
|              else: | ||||
|                  self.enums[id] = idx.enums[id] | ||||
|                  self.identifiers[id] = idx.enums[id] | ||||
|  | ||||
|     def merge_public(self, idx): | ||||
|         for id in idx.functions.keys(): | ||||
| 	     if self.functions.has_key(id): | ||||
|         for id in list(idx.functions.keys()): | ||||
|              if id in self.functions: | ||||
|                  # check that function condition agrees with header | ||||
|                  if idx.functions[id].conditionals != \ | ||||
|                     self.functions[id].conditionals: | ||||
| 		     print "Header condition differs from Function for %s:" \ | ||||
| 		        % id | ||||
| 		     print "  H: %s" % self.functions[id].conditionals | ||||
| 		     print "  C: %s" % idx.functions[id].conditionals | ||||
|                      print("Header condition differs from Function for %s:" \ | ||||
|                         % id) | ||||
|                      print("  H: %s" % self.functions[id].conditionals) | ||||
|                      print("  C: %s" % idx.functions[id].conditionals) | ||||
|                  up = idx.functions[id] | ||||
|                  self.functions[id].update(None, up.module, up.type, up.info, up.extra) | ||||
|          #     else: | ||||
| @@ -349,15 +349,15 @@ class index: | ||||
|     def analyze_dict(self, type, dict): | ||||
|         count = 0 | ||||
|         public = 0 | ||||
|         for name in dict.keys(): | ||||
|         for name in list(dict.keys()): | ||||
|             id = dict[name] | ||||
|             count = count + 1 | ||||
|             if id.static == 0: | ||||
|                 public = public + 1 | ||||
|         if count != public: | ||||
| 	    print "  %d %s , %d public" % (count, type, public) | ||||
|             print("  %d %s , %d public" % (count, type, public)) | ||||
|         elif count != 0: | ||||
| 	    print "  %d public %s" % (count, type) | ||||
|             print("  %d public %s" % (count, type)) | ||||
|  | ||||
|  | ||||
|     def analyze(self): | ||||
| @@ -383,16 +383,16 @@ class CLexer: | ||||
|             if not line: | ||||
|                 return None | ||||
|             self.lineno = self.lineno + 1 | ||||
| 	    line = string.lstrip(line) | ||||
| 	    line = string.rstrip(line) | ||||
|             line = line.lstrip() | ||||
|             line = line.rstrip() | ||||
|             if line == '': | ||||
|                 continue | ||||
|             while line[-1] == '\\': | ||||
|                 line = line[:-1] | ||||
|                 n = self.input.readline() | ||||
|                 self.lineno = self.lineno + 1 | ||||
| 		n = string.lstrip(n) | ||||
| 		n = string.rstrip(n) | ||||
|                 n = n.lstrip() | ||||
|                 n = n.rstrip() | ||||
|                 if not n: | ||||
|                     break | ||||
|                 else: | ||||
| @@ -406,9 +406,9 @@ class CLexer: | ||||
|         self.tokens.insert(0, token); | ||||
|  | ||||
|     def debug(self): | ||||
|         print "Last token: ", self.last | ||||
| 	print "Token queue: ", self.tokens | ||||
| 	print "Line %d end: " % (self.lineno), self.line | ||||
|         print("Last token: ", self.last) | ||||
|         print("Token queue: ", self.tokens) | ||||
|         print("Line %d end: " % (self.lineno), self.line) | ||||
|  | ||||
|     def token(self): | ||||
|         while self.tokens == []: | ||||
| @@ -421,8 +421,8 @@ class CLexer: | ||||
|                 return None | ||||
|  | ||||
|             if line[0] == '#': | ||||
| 	        self.tokens = map((lambda x: ('preproc', x)), | ||||
| 		                  string.split(line)) | ||||
|                 self.tokens = list(map((lambda x: ('preproc', x)), | ||||
|                                   line.split())) | ||||
|                 break; | ||||
|             l = len(line) | ||||
|             if line[0] == '"' or line[0] == "'": | ||||
| @@ -507,21 +507,21 @@ class CLexer: | ||||
|                     while i < l: | ||||
|                         o = ord(line[i]) | ||||
|                         if (o >= 97 and o <= 122) or (o >= 65 and o <= 90) or \ | ||||
| 			   (o >= 48 and o <= 57) or string.find( | ||||
| 			       " \t(){}:;,+-*/%&!|[]=><", line[i]) == -1: | ||||
|                            (o >= 48 and o <= 57) or \ | ||||
| 			   (" \t(){}:;,+-*/%&!|[]=><".find(line[i])) == -1: | ||||
|                             i = i + 1 | ||||
|                         else: | ||||
|                             break | ||||
|                     self.tokens.append(('name', line[s:i])) | ||||
|                     continue | ||||
| 		if string.find("(){}:;,[]", line[i]) != -1: | ||||
|                 if "(){}:;,[]".find(line[i]) != -1: | ||||
| #                 if line[i] == '(' or line[i] == ')' or line[i] == '{' or \ | ||||
| #                    line[i] == '}' or line[i] == ':' or line[i] == ';' or \ | ||||
| #                    line[i] == ',' or line[i] == '[' or line[i] == ']': | ||||
|                     self.tokens.append(('sep', line[i])) | ||||
|                     i = i + 1 | ||||
|                     continue | ||||
| 		if string.find("+-*><=/%&!|.", line[i]) != -1: | ||||
|                 if "+-*><=/%&!|.".find(line[i]) != -1: | ||||
| #                 if line[i] == '+' or line[i] == '-' or line[i] == '*' or \ | ||||
| #                    line[i] == '>' or line[i] == '<' or line[i] == '=' or \ | ||||
| #                    line[i] == '/' or line[i] == '%' or line[i] == '&' or \ | ||||
| @@ -534,7 +534,7 @@ class CLexer: | ||||
|  | ||||
|                     j = i + 1 | ||||
|                     if j < l and ( | ||||
| 		       string.find("+-*><=/%&!|", line[j]) != -1): | ||||
|                        "+-*><=/%&!|".find(line[j]) != -1): | ||||
| #                        line[j] == '+' or line[j] == '-' or line[j] == '*' or \ | ||||
| #                        line[j] == '>' or line[j] == '<' or line[j] == '=' or \ | ||||
| #                        line[j] == '/' or line[j] == '%' or line[j] == '&' or \ | ||||
| @@ -550,7 +550,7 @@ class CLexer: | ||||
|                     o = ord(line[i]) | ||||
|                     if (o >= 97 and o <= 122) or (o >= 65 and o <= 90) or \ | ||||
|                        (o >= 48 and o <= 57) or ( | ||||
| 		        string.find(" \t(){}:;,+-*/%&!|[]=><", line[i]) == -1): | ||||
|                         " \t(){}:;,+-*/%&!|[]=><".find(line[i]) == -1): | ||||
| #                         line[i] != ' ' and line[i] != '\t' and | ||||
| #                         line[i] != '(' and line[i] != ')' and | ||||
| #                         line[i] != '{'  and line[i] != '}' and | ||||
| @@ -627,27 +627,27 @@ class CParser: | ||||
|     def warning(self, msg): | ||||
|         if self.no_error: | ||||
|             return | ||||
| 	print msg | ||||
|         print(msg) | ||||
|  | ||||
|     def error(self, msg, token=-1): | ||||
|         if self.no_error: | ||||
|             return | ||||
|  | ||||
|         print "Parse Error: " + msg | ||||
|         print("Parse Error: " + msg) | ||||
|         if token != -1: | ||||
| 	    print "Got token ", token | ||||
|             print("Got token ", token) | ||||
|         self.lexer.debug() | ||||
|         sys.exit(1) | ||||
|  | ||||
|     def debug(self, msg, token=-1): | ||||
|         print "Debug: " + msg | ||||
|         print("Debug: " + msg) | ||||
|         if token != -1: | ||||
| 	    print "Got token ", token | ||||
|             print("Got token ", token) | ||||
|         self.lexer.debug() | ||||
|  | ||||
|     def parseTopComment(self, comment): | ||||
|         res = {} | ||||
| 	lines = string.split(comment, "\n") | ||||
|         lines = comment.split("\n") | ||||
|         item = None | ||||
|         for line in lines: | ||||
|             while line != "" and (line[0] == ' ' or line[0] == '\t'): | ||||
| @@ -657,17 +657,17 @@ class CParser: | ||||
|             while line != "" and (line[0] == ' ' or line[0] == '\t'): | ||||
|                 line = line[1:] | ||||
|             try: | ||||
| 		(it, line) = string.split(line, ":", 1) | ||||
|                 (it, line) = line.split(":", 1) | ||||
|                 item = it | ||||
|                 while line != "" and (line[0] == ' ' or line[0] == '\t'): | ||||
|                     line = line[1:] | ||||
| 		if res.has_key(item): | ||||
|                 if item in res: | ||||
|                     res[item] = res[item] + " " + line | ||||
|                 else: | ||||
|                     res[item] = line | ||||
|             except: | ||||
|                 if item != None: | ||||
| 		    if res.has_key(item): | ||||
|                     if item in res: | ||||
|                         res[item] = res[item] + " " + line | ||||
|                     else: | ||||
|                         res[item] = line | ||||
| @@ -682,10 +682,10 @@ class CParser: | ||||
|             self.comment = self.comment + token[1] | ||||
|         token = self.lexer.token() | ||||
|  | ||||
|         if string.find(self.comment, "DOC_DISABLE") != -1: | ||||
|         if self.comment.find("DOC_DISABLE") != -1: | ||||
|             self.stop_error() | ||||
|  | ||||
|         if string.find(self.comment, "DOC_ENABLE") != -1: | ||||
|         if self.comment.find("DOC_ENABLE") != -1: | ||||
|             self.start_error() | ||||
|  | ||||
|         return token | ||||
| @@ -708,7 +708,7 @@ class CParser: | ||||
|             if not quiet: | ||||
|                 self.warning("Missing * in type comment for %s" % (name)) | ||||
|             return((args, desc)) | ||||
| 	lines = string.split(self.comment, '\n') | ||||
|         lines = self.comment.split('\n') | ||||
|         if lines[0] == '*': | ||||
|             del lines[0] | ||||
|         if lines[0] != "* %s:" % (name): | ||||
| @@ -724,11 +724,11 @@ class CParser: | ||||
|             l = lines[0] | ||||
|             while len(l) > 0 and l[0] == '*': | ||||
|                 l = l[1:] | ||||
| 	    l = string.strip(l) | ||||
|             l = l.strip() | ||||
|             desc = desc + " " + l | ||||
|             del lines[0] | ||||
|  | ||||
| 	desc = string.strip(desc) | ||||
|         desc = desc.strip() | ||||
|  | ||||
|         if quiet == 0: | ||||
|             if desc == "": | ||||
| @@ -753,7 +753,7 @@ class CParser: | ||||
|             if not quiet: | ||||
|                 self.warning("Missing * in macro comment for %s" % (name)) | ||||
|             return((args, desc)) | ||||
| 	lines = string.split(self.comment, '\n') | ||||
|         lines = self.comment.split('\n') | ||||
|         if lines[0] == '*': | ||||
|             del lines[0] | ||||
|         if lines[0] != "* %s:" % (name): | ||||
| @@ -767,9 +767,9 @@ class CParser: | ||||
|         while len(lines) > 0 and lines[0][0:3] == '* @': | ||||
|             l = lines[0][3:] | ||||
|             try: | ||||
| 	        (arg, desc) = string.split(l, ':', 1) | ||||
| 		desc=string.strip(desc) | ||||
| 		arg=string.strip(arg) | ||||
|                 (arg, desc) = l.split(':', 1) | ||||
|                 desc=desc.strip() | ||||
|                 arg=arg.strip() | ||||
|             except: | ||||
|                 if not quiet: | ||||
|                     self.warning("Misformatted macro comment for %s" % (name)) | ||||
| @@ -777,11 +777,11 @@ class CParser: | ||||
|                 del lines[0] | ||||
|                 continue | ||||
|             del lines[0] | ||||
| 	    l = string.strip(lines[0]) | ||||
|             l = lines[0].strip() | ||||
|             while len(l) > 2 and l[0:3] != '* @': | ||||
|                 while l[0] == '*': | ||||
|                     l = l[1:] | ||||
| 		desc = desc + ' ' + string.strip(l) | ||||
|                 desc = desc + ' ' + l.strip() | ||||
|                 del lines[0] | ||||
|                 if len(lines) == 0: | ||||
|                     break | ||||
| @@ -794,11 +794,11 @@ class CParser: | ||||
|             l = lines[0] | ||||
|             while len(l) > 0 and l[0] == '*': | ||||
|                 l = l[1:] | ||||
| 	    l = string.strip(l) | ||||
|             l = l.strip() | ||||
|             desc = desc + " " + l | ||||
|             del lines[0] | ||||
|  | ||||
| 	desc = string.strip(desc) | ||||
|         desc = desc.strip() | ||||
|  | ||||
|         if quiet == 0: | ||||
|             if desc == "": | ||||
| @@ -829,7 +829,7 @@ class CParser: | ||||
|             if not quiet: | ||||
|                 self.warning("Missing * in function comment for %s" % (name)) | ||||
|             return(((ret[0], retdesc), args, desc)) | ||||
| 	lines = string.split(self.comment, '\n') | ||||
|         lines = self.comment.split('\n') | ||||
|         if lines[0] == '*': | ||||
|             del lines[0] | ||||
|         if lines[0] != "* %s:" % (name): | ||||
| @@ -844,9 +844,9 @@ class CParser: | ||||
|         while len(lines) > 0 and lines[0][0:3] == '* @': | ||||
|             l = lines[0][3:] | ||||
|             try: | ||||
| 	        (arg, desc) = string.split(l, ':', 1) | ||||
| 		desc=string.strip(desc) | ||||
| 		arg=string.strip(arg) | ||||
|                 (arg, desc) = l.split(':', 1) | ||||
|                 desc=desc.strip() | ||||
|                 arg=arg.strip() | ||||
|             except: | ||||
|                 if not quiet: | ||||
|                     self.warning("Misformatted function comment for %s" % (name)) | ||||
| @@ -854,11 +854,11 @@ class CParser: | ||||
|                 del lines[0] | ||||
|                 continue | ||||
|             del lines[0] | ||||
| 	    l = string.strip(lines[0]) | ||||
|             l = lines[0].strip() | ||||
|             while len(l) > 2 and l[0:3] != '* @': | ||||
|                 while l[0] == '*': | ||||
|                     l = l[1:] | ||||
| 		desc = desc + ' ' + string.strip(l) | ||||
|                 desc = desc + ' ' + l.strip() | ||||
|                 del lines[0] | ||||
|                 if len(lines) == 0: | ||||
|                     break | ||||
| @@ -880,27 +880,27 @@ class CParser: | ||||
|             l = lines[0] | ||||
|             while len(l) > 0 and l[0] == '*': | ||||
|                 l = l[1:] | ||||
| 	    l = string.strip(l) | ||||
|             l = l.strip() | ||||
|             if len(l) >= 6 and  l[0:6] == "return" or l[0:6] == "Return": | ||||
|                 try: | ||||
| 		    l = string.split(l, ' ', 1)[1] | ||||
|                     l = l.split(' ', 1)[1] | ||||
|                 except: | ||||
|                     l = "" | ||||
| 		retdesc = string.strip(l) | ||||
|                 retdesc = l.strip() | ||||
|                 del lines[0] | ||||
|                 while len(lines) > 0: | ||||
|                     l = lines[0] | ||||
|                     while len(l) > 0 and l[0] == '*': | ||||
|                         l = l[1:] | ||||
| 		    l = string.strip(l) | ||||
|                     l = l.strip() | ||||
|                     retdesc = retdesc + " " + l | ||||
|                     del lines[0] | ||||
|             else: | ||||
|                 desc = desc + " " + l | ||||
|                 del lines[0] | ||||
|  | ||||
| 	retdesc = string.strip(retdesc) | ||||
| 	desc = string.strip(desc) | ||||
|         retdesc = retdesc.strip() | ||||
|         desc = desc.strip() | ||||
|  | ||||
|         if quiet == 0: | ||||
|              # | ||||
| @@ -921,7 +921,7 @@ class CParser: | ||||
|  | ||||
|     def parsePreproc(self, token): | ||||
|         if debug: | ||||
| 	    print "=> preproc ", token, self.lexer.tokens | ||||
|             print("=> preproc ", token, self.lexer.tokens) | ||||
|         name = token[1] | ||||
|         if name == "#include": | ||||
|             token = self.lexer.token() | ||||
| @@ -946,7 +946,7 @@ class CParser: | ||||
|                     lst.append(token[1]) | ||||
|                     token = self.lexer.token() | ||||
|                 try: | ||||
| 		    name = string.split(name, '(') [0] | ||||
|                     name = name.split('(') [0] | ||||
|                 except: | ||||
|                     pass | ||||
|                 info = self.parseMacroComment(name, not self.is_header) | ||||
| @@ -975,7 +975,7 @@ class CParser: | ||||
|             apstr = self.lexer.tokens[0][1] | ||||
|             try: | ||||
|                 self.defines.append(apstr) | ||||
| 		if string.find(apstr, 'ENABLED') != -1: | ||||
|                 if apstr.find('ENABLED') != -1: | ||||
|                     self.conditionals.append("defined(%s)" % apstr) | ||||
|             except: | ||||
|                 pass | ||||
| @@ -983,7 +983,7 @@ class CParser: | ||||
|             apstr = self.lexer.tokens[0][1] | ||||
|             try: | ||||
|                 self.defines.append(apstr) | ||||
| 		if string.find(apstr, 'ENABLED') != -1: | ||||
|                 if apstr.find('ENABLED') != -1: | ||||
|                     self.conditionals.append("!defined(%s)" % apstr) | ||||
|             except: | ||||
|                 pass | ||||
| @@ -995,17 +995,17 @@ class CParser: | ||||
|                 apstr = apstr + tok[1] | ||||
|             try: | ||||
|                 self.defines.append(apstr) | ||||
| 		if string.find(apstr, 'ENABLED') != -1: | ||||
|                 if apstr.find('ENABLED') != -1: | ||||
|                     self.conditionals.append(apstr) | ||||
|             except: | ||||
|                 pass | ||||
|         elif name == "#else": | ||||
|             if self.conditionals != [] and \ | ||||
| 	       string.find(self.defines[-1], 'ENABLED') != -1: | ||||
|                self.defines[-1].find('ENABLED') != -1: | ||||
|                 self.conditionals[-1] = "!(%s)" % self.conditionals[-1] | ||||
|         elif name == "#endif": | ||||
|             if self.conditionals != [] and \ | ||||
| 	       string.find(self.defines[-1], 'ENABLED') != -1: | ||||
|                self.defines[-1].find('ENABLED') != -1: | ||||
|                 self.conditionals = self.conditionals[:-1] | ||||
|             self.defines = self.defines[:-1] | ||||
|         token = self.lexer.token() | ||||
| @@ -1038,7 +1038,7 @@ class CParser: | ||||
|                 while token != None and token[1] != ";": | ||||
|                     token = self.lexer.token() | ||||
|                 return token | ||||
| 	    elif token[0] == "name" and ignored_words.has_key(token[1]): | ||||
|             elif token[0] == "name" and token[1] in ignored_words: | ||||
|                 (n, info) = ignored_words[token[1]] | ||||
|                 i = 0 | ||||
|                 while i < n: | ||||
| @@ -1048,7 +1048,7 @@ class CParser: | ||||
|                 continue | ||||
|             else: | ||||
|                 if debug: | ||||
| 		    print "=> ", token | ||||
|                     print("=> ", token) | ||||
|                 return token | ||||
|         return None | ||||
|  | ||||
| @@ -1070,7 +1070,7 @@ class CParser: | ||||
|                 name = token[1] | ||||
|                 signature = self.signature | ||||
|                 if signature != None: | ||||
| 		    type = string.split(type, '(')[0] | ||||
|                     type = type.split('(')[0] | ||||
|                     d = self.mergeFunctionComment(name, | ||||
|                             ((type, None), signature), 1) | ||||
|                     self.index_add(name, self.filename, not self.is_header, | ||||
| @@ -1219,7 +1219,7 @@ class CParser: | ||||
|             elif token[0] == "name": | ||||
|                     if name != None: | ||||
|                         if self.comment != None: | ||||
| 			    comment = string.strip(self.comment) | ||||
|                             comment = self.comment.strip() | ||||
|                             self.comment = None | ||||
|                         self.enums.append((name, value, comment)) | ||||
|                     name = token[1] | ||||
| @@ -1607,7 +1607,7 @@ class docBuilder: | ||||
|     def __init__(self, name, directories=['.'], excludes=[]): | ||||
|         self.name = name | ||||
|         self.directories = directories | ||||
| 	self.excludes = excludes + ignored_files.keys() | ||||
|         self.excludes = excludes + list(ignored_files.keys()) | ||||
|         self.modules = {} | ||||
|         self.headers = {} | ||||
|         self.idx = index() | ||||
| @@ -1621,35 +1621,35 @@ class docBuilder: | ||||
|     def indexString(self, id, str): | ||||
|         if str == None: | ||||
|             return | ||||
| 	str = string.replace(str, "'", ' ') | ||||
| 	str = string.replace(str, '"', ' ') | ||||
| 	str = string.replace(str, "/", ' ') | ||||
| 	str = string.replace(str, '*', ' ') | ||||
| 	str = string.replace(str, "[", ' ') | ||||
| 	str = string.replace(str, "]", ' ') | ||||
| 	str = string.replace(str, "(", ' ') | ||||
| 	str = string.replace(str, ")", ' ') | ||||
| 	str = string.replace(str, "<", ' ') | ||||
| 	str = string.replace(str, '>', ' ') | ||||
| 	str = string.replace(str, "&", ' ') | ||||
| 	str = string.replace(str, '#', ' ') | ||||
| 	str = string.replace(str, ",", ' ') | ||||
| 	str = string.replace(str, '.', ' ') | ||||
| 	str = string.replace(str, ';', ' ') | ||||
| 	tokens = string.split(str) | ||||
|         str = str.replace("'", ' ') | ||||
|         str = str.replace('"', ' ') | ||||
|         str = str.replace("/", ' ') | ||||
|         str = str.replace('*', ' ') | ||||
|         str = str.replace("[", ' ') | ||||
|         str = str.replace("]", ' ') | ||||
|         str = str.replace("(", ' ') | ||||
|         str = str.replace(")", ' ') | ||||
|         str = str.replace("<", ' ') | ||||
|         str = str.replace('>', ' ') | ||||
|         str = str.replace("&", ' ') | ||||
|         str = str.replace('#', ' ') | ||||
|         str = str.replace(",", ' ') | ||||
|         str = str.replace('.', ' ') | ||||
|         str = str.replace(';', ' ') | ||||
|         tokens = str.split() | ||||
|         for token in tokens: | ||||
|             try: | ||||
|                 c = token[0] | ||||
| 		if string.find(string.letters, c) < 0: | ||||
|                 if string.ascii_letters.find(c) < 0: | ||||
|                     pass | ||||
|                 elif len(token) < 3: | ||||
|                     pass | ||||
|                 else: | ||||
| 		    lower = string.lower(token) | ||||
|                     lower = token.lower() | ||||
|                     # TODO: generalize this a bit | ||||
|                     if lower == 'and' or lower == 'the': | ||||
|                         pass | ||||
| 		    elif self.xref.has_key(token): | ||||
|                     elif token in self.xref: | ||||
|                         self.xref[token].append(id) | ||||
|                     else: | ||||
|                         self.xref[token] = [id] | ||||
| @@ -1657,18 +1657,18 @@ class docBuilder: | ||||
|                 pass | ||||
|  | ||||
|     def analyze(self): | ||||
|         print "Project %s : %d headers, %d modules" % (self.name, len(self.headers.keys()), len(self.modules.keys())) | ||||
|         print("Project %s : %d headers, %d modules" % (self.name, len(list(self.headers.keys())), len(list(self.modules.keys())))) | ||||
|         self.idx.analyze() | ||||
|  | ||||
|     def scanHeaders(self): | ||||
| 	for header in self.headers.keys(): | ||||
|         for header in list(self.headers.keys()): | ||||
|             parser = CParser(header) | ||||
|             idx = parser.parse() | ||||
|             self.headers[header] = idx; | ||||
|             self.idx.merge(idx) | ||||
|  | ||||
|     def scanModules(self): | ||||
| 	for module in self.modules.keys(): | ||||
|         for module in list(self.modules.keys()): | ||||
|             parser = CParser(module) | ||||
|             idx = parser.parse() | ||||
|             # idx.analyze() | ||||
| @@ -1681,8 +1681,8 @@ class docBuilder: | ||||
|             for file in files: | ||||
|                 skip = 0 | ||||
|                 for excl in self.excludes: | ||||
| 		    if string.find(file, excl) != -1: | ||||
| 		        print "Skipping %s" % file | ||||
|                     if file.find(excl) != -1: | ||||
|                         print("Skipping %s" % file) | ||||
|                         skip = 1 | ||||
|                         break | ||||
|                 if skip == 0: | ||||
| @@ -1691,8 +1691,8 @@ class docBuilder: | ||||
|             for file in files: | ||||
|                 skip = 0 | ||||
|                 for excl in self.excludes: | ||||
| 		    if string.find(file, excl) != -1: | ||||
| 		        print "Skipping %s" % file | ||||
|                     if file.find(excl) != -1: | ||||
|                         print("Skipping %s" % file) | ||||
|                         skip = 1 | ||||
|                         break | ||||
|                 if skip == 0: | ||||
| @@ -1754,7 +1754,7 @@ class docBuilder: | ||||
|             output.write("    <struct name='%s' file='%s' type='%s'" % ( | ||||
|                      name, self.modulename_file(id.header), id.info)) | ||||
|             name = id.info[7:] | ||||
| 	    if self.idx.structs.has_key(name) and ( \ | ||||
|             if name in self.idx.structs and ( \ | ||||
|                type(self.idx.structs[name].info) == type(()) or | ||||
|                 type(self.idx.structs[name].info) == type([])): | ||||
|                 output.write(">\n"); | ||||
| @@ -1768,7 +1768,7 @@ class docBuilder: | ||||
|                             desc = escape(desc) | ||||
|                         output.write("      <field name='%s' type='%s' info='%s'/>\n" % (field[1] , field[0], desc)) | ||||
|                 except: | ||||
| 		    print "Failed to serialize struct %s" % (name) | ||||
|                     print("Failed to serialize struct %s" % (name)) | ||||
|                 output.write("    </struct>\n") | ||||
|             else: | ||||
|                 output.write("/>\n"); | ||||
| @@ -1797,7 +1797,7 @@ class docBuilder: | ||||
|     def serialize_function(self, output, name): | ||||
|         id = self.idx.functions[name] | ||||
|         if name == debugsym: | ||||
| 	    print "=>", id | ||||
|             print("=>", id) | ||||
|  | ||||
|         output.write("    <%s name='%s' file='%s' module='%s'>\n" % (id.type, | ||||
|                      name, self.modulename_file(id.header), | ||||
| @@ -1816,8 +1816,8 @@ class docBuilder: | ||||
|             (ret, params, desc) = id.info | ||||
|             if (desc == None or desc == '') and \ | ||||
|                name[0:9] != "xmlThrDef" and name != "xmlDllMain": | ||||
| 	        print "%s %s from %s has no description" % (id.type, name, | ||||
| 		       self.modulename_file(id.module)) | ||||
|                 print("%s %s from %s has no description" % (id.type, name, | ||||
|                        self.modulename_file(id.module))) | ||||
|  | ||||
|             output.write("      <info>%s</info>\n" % (escape(desc))) | ||||
|             self.indexString(name, desc) | ||||
| @@ -1837,7 +1837,7 @@ class docBuilder: | ||||
|                     output.write("      <arg name='%s' type='%s' info='%s'/>\n" % (param[1], param[0], escape(param[2]))) | ||||
|                     self.indexString(name, param[2]) | ||||
|         except: | ||||
| 	    print "Failed to save function %s info: " % name, `id.info` | ||||
|             print("Failed to save function %s info: " % name, repr(id.info)) | ||||
|         output.write("    </%s>\n" % (id.type)) | ||||
|  | ||||
|     def serialize_exports(self, output, file): | ||||
| @@ -1848,63 +1848,63 @@ class docBuilder: | ||||
|             for data in ('Summary', 'Description', 'Author'): | ||||
|                 try: | ||||
|                     output.write("     <%s>%s</%s>\n" % ( | ||||
| 		                 string.lower(data), | ||||
|                                  data.lower(), | ||||
|                                  escape(dict.info[data]), | ||||
| 				 string.lower(data))) | ||||
|                                  data.lower())) | ||||
|                 except: | ||||
| 		    print "Header %s lacks a %s description" % (module, data) | ||||
| 	    if dict.info.has_key('Description'): | ||||
|                     print("Header %s lacks a %s description" % (module, data)) | ||||
|             if 'Description' in dict.info: | ||||
|                 desc = dict.info['Description'] | ||||
| 		if string.find(desc, "DEPRECATED") != -1: | ||||
|                 if desc.find("DEPRECATED") != -1: | ||||
|                     output.write("     <deprecated/>\n") | ||||
|  | ||||
|         ids = dict.macros.keys() | ||||
|         ids = list(dict.macros.keys()) | ||||
|         ids.sort() | ||||
|         for id in uniq(ids): | ||||
|             # Macros are sometime used to masquerade other types. | ||||
| 	    if dict.functions.has_key(id): | ||||
|             if id in dict.functions: | ||||
|                 continue | ||||
| 	    if dict.variables.has_key(id): | ||||
|             if id in dict.variables: | ||||
|                 continue | ||||
| 	    if dict.typedefs.has_key(id): | ||||
|             if id in dict.typedefs: | ||||
|                 continue | ||||
| 	    if dict.structs.has_key(id): | ||||
|             if id in dict.structs: | ||||
|                 continue | ||||
| 	    if dict.enums.has_key(id): | ||||
|             if id in dict.enums: | ||||
|                 continue | ||||
|             output.write("     <exports symbol='%s' type='macro'/>\n" % (id)) | ||||
|         ids = dict.enums.keys() | ||||
|         ids = list(dict.enums.keys()) | ||||
|         ids.sort() | ||||
|         for id in uniq(ids): | ||||
|             output.write("     <exports symbol='%s' type='enum'/>\n" % (id)) | ||||
|         ids = dict.typedefs.keys() | ||||
|         ids = list(dict.typedefs.keys()) | ||||
|         ids.sort() | ||||
|         for id in uniq(ids): | ||||
|             output.write("     <exports symbol='%s' type='typedef'/>\n" % (id)) | ||||
|         ids = dict.structs.keys() | ||||
|         ids = list(dict.structs.keys()) | ||||
|         ids.sort() | ||||
|         for id in uniq(ids): | ||||
|             output.write("     <exports symbol='%s' type='struct'/>\n" % (id)) | ||||
|         ids = dict.variables.keys() | ||||
|         ids = list(dict.variables.keys()) | ||||
|         ids.sort() | ||||
|         for id in uniq(ids): | ||||
|             output.write("     <exports symbol='%s' type='variable'/>\n" % (id)) | ||||
|         ids = dict.functions.keys() | ||||
|         ids = list(dict.functions.keys()) | ||||
|         ids.sort() | ||||
|         for id in uniq(ids): | ||||
|             output.write("     <exports symbol='%s' type='function'/>\n" % (id)) | ||||
|         output.write("    </file>\n") | ||||
|  | ||||
|     def serialize_xrefs_files(self, output): | ||||
|         headers = self.headers.keys() | ||||
|         headers = list(self.headers.keys()) | ||||
|         headers.sort() | ||||
|         for file in headers: | ||||
|             module = self.modulename_file(file) | ||||
|             output.write("    <file name='%s'>\n" % (module)) | ||||
|             dict = self.headers[file] | ||||
| 	    ids = uniq(dict.functions.keys() + dict.variables.keys() + \ | ||||
| 		  dict.macros.keys() + dict.typedefs.keys() + \ | ||||
| 		  dict.structs.keys() + dict.enums.keys()) | ||||
|             ids = uniq(list(dict.functions.keys()) + list(dict.variables.keys()) + \ | ||||
|                   list(dict.macros.keys()) + list(dict.typedefs.keys()) + \ | ||||
|                   list(dict.structs.keys()) + list(dict.enums.keys())) | ||||
|             ids.sort() | ||||
|             for id in ids: | ||||
|                 output.write("      <ref name='%s'/>\n" % (id)) | ||||
| @@ -1913,20 +1913,20 @@ class docBuilder: | ||||
|  | ||||
|     def serialize_xrefs_functions(self, output): | ||||
|         funcs = {} | ||||
| 	for name in self.idx.functions.keys(): | ||||
|         for name in list(self.idx.functions.keys()): | ||||
|             id = self.idx.functions[name] | ||||
|             try: | ||||
|                 (ret, params, desc) = id.info | ||||
|                 for param in params: | ||||
|                     if param[0] == 'void': | ||||
|                         continue | ||||
| 		    if funcs.has_key(param[0]): | ||||
|                     if param[0] in funcs: | ||||
|                         funcs[param[0]].append(name) | ||||
|                     else: | ||||
|                         funcs[param[0]] = [name] | ||||
|             except: | ||||
|                 pass | ||||
| 	typ = funcs.keys() | ||||
|         typ = list(funcs.keys()) | ||||
|         typ.sort() | ||||
|         for type in typ: | ||||
|             if type == '' or type == 'void' or type == "int" or \ | ||||
| @@ -1944,19 +1944,19 @@ class docBuilder: | ||||
|  | ||||
|     def serialize_xrefs_constructors(self, output): | ||||
|         funcs = {} | ||||
| 	for name in self.idx.functions.keys(): | ||||
|         for name in list(self.idx.functions.keys()): | ||||
|             id = self.idx.functions[name] | ||||
|             try: | ||||
|                 (ret, params, desc) = id.info | ||||
|                 if ret[0] == "void": | ||||
|                     continue | ||||
| 		if funcs.has_key(ret[0]): | ||||
|                 if ret[0] in funcs: | ||||
|                     funcs[ret[0]].append(name) | ||||
|                 else: | ||||
|                     funcs[ret[0]] = [name] | ||||
|             except: | ||||
|                 pass | ||||
| 	typ = funcs.keys() | ||||
|         typ = list(funcs.keys()) | ||||
|         typ.sort() | ||||
|         for type in typ: | ||||
|             if type == '' or type == 'void' or type == "int" or \ | ||||
| @@ -1971,7 +1971,7 @@ class docBuilder: | ||||
|  | ||||
|     def serialize_xrefs_alpha(self, output): | ||||
|         letter = None | ||||
| 	ids = self.idx.identifiers.keys() | ||||
|         ids = list(self.idx.identifiers.keys()) | ||||
|         ids.sort() | ||||
|         for id in ids: | ||||
|             if id[0] != letter: | ||||
| @@ -1984,7 +1984,7 @@ class docBuilder: | ||||
|             output.write("    </letter>\n") | ||||
|  | ||||
|     def serialize_xrefs_references(self, output): | ||||
|         typ = self.idx.identifiers.keys() | ||||
|         typ = list(self.idx.identifiers.keys()) | ||||
|         typ.sort() | ||||
|         for id in typ: | ||||
|             idf = self.idx.identifiers[id] | ||||
| @@ -1996,7 +1996,7 @@ class docBuilder: | ||||
|  | ||||
|     def serialize_xrefs_index(self, output): | ||||
|         index = self.xref | ||||
| 	typ = index.keys() | ||||
|         typ = list(index.keys()) | ||||
|         typ.sort() | ||||
|         letter = None | ||||
|         count = 0 | ||||
| @@ -2063,34 +2063,34 @@ class docBuilder: | ||||
|  | ||||
|     def serialize(self): | ||||
|         filename = "%s-api.xml" % self.name | ||||
|         print "Saving XML description %s" % (filename) | ||||
|         print("Saving XML description %s" % (filename)) | ||||
|         output = open(filename, "w") | ||||
|         output.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n') | ||||
|         output.write("<api name='%s'>\n" % self.name) | ||||
|         output.write("  <files>\n") | ||||
|         headers = self.headers.keys() | ||||
|         headers = list(self.headers.keys()) | ||||
|         headers.sort() | ||||
|         for file in headers: | ||||
|             self.serialize_exports(output, file) | ||||
|         output.write("  </files>\n") | ||||
|         output.write("  <symbols>\n") | ||||
|         macros = self.idx.macros.keys() | ||||
|         macros = list(self.idx.macros.keys()) | ||||
|         macros.sort() | ||||
|         for macro in macros: | ||||
|             self.serialize_macro(output, macro) | ||||
|         enums = self.idx.enums.keys() | ||||
|         enums = list(self.idx.enums.keys()) | ||||
|         enums.sort() | ||||
|         for enum in enums: | ||||
|             self.serialize_enum(output, enum) | ||||
|         typedefs = self.idx.typedefs.keys() | ||||
|         typedefs = list(self.idx.typedefs.keys()) | ||||
|         typedefs.sort() | ||||
|         for typedef in typedefs: | ||||
|             self.serialize_typedef(output, typedef) | ||||
|         variables = self.idx.variables.keys() | ||||
|         variables = list(self.idx.variables.keys()) | ||||
|         variables.sort() | ||||
|         for variable in variables: | ||||
|             self.serialize_variable(output, variable) | ||||
|         functions = self.idx.functions.keys() | ||||
|         functions = list(self.idx.functions.keys()) | ||||
|         functions.sort() | ||||
|         for function in functions: | ||||
|             self.serialize_function(output, function) | ||||
| @@ -2099,7 +2099,7 @@ class docBuilder: | ||||
|         output.close() | ||||
|  | ||||
|         filename = "%s-refs.xml" % self.name | ||||
|         print "Saving XML Cross References %s" % (filename) | ||||
|         print("Saving XML Cross References %s" % (filename)) | ||||
|         output = open(filename, "w") | ||||
|         output.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n') | ||||
|         output.write("<apirefs name='%s'>\n" % self.name) | ||||
| @@ -2111,19 +2111,19 @@ class docBuilder: | ||||
| def rebuild(): | ||||
|     builder = None | ||||
|     if glob.glob("parser.c") != [] : | ||||
|         print "Rebuilding API description for libxml2" | ||||
|         print("Rebuilding API description for libxml2") | ||||
|         builder = docBuilder("libxml2", [".", "."], | ||||
|                              ["xmlwin32version.h", "tst.c"]) | ||||
|     elif glob.glob("../parser.c") != [] : | ||||
|         print "Rebuilding API description for libxml2" | ||||
|         print("Rebuilding API description for libxml2") | ||||
|         builder = docBuilder("libxml2", ["..", "../include/libxml"], | ||||
|                              ["xmlwin32version.h", "tst.c"]) | ||||
|     elif glob.glob("../libxslt/transform.c") != [] : | ||||
|         print "Rebuilding API description for libxslt" | ||||
|         print("Rebuilding API description for libxslt") | ||||
|         builder = docBuilder("libxslt", ["../libxslt"], | ||||
|                              ["win32config.h", "libxslt.h", "tst.c"]) | ||||
|     else: | ||||
|         print "rebuild() failed, unable to guess the module" | ||||
|         print("rebuild() failed, unable to guess the module") | ||||
|         return None | ||||
|     builder.scan() | ||||
|     builder.analyze() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user