2525import os , pickle , urllib .request , urllib .parse , urllib .error , sys
2626from pyparsing import *
2727from html .entities import entitydefs
28- from htmllib import HTMLParser
28+ from html . parser import HTMLParser
2929from formatter import AbstractFormatter , DumbWriter
3030
3131# cache dir (preparsed source and HTML asoundlib API)
@@ -114,29 +114,24 @@ class AsoundlibAPIHTMLParser(HTMLParser):
114114 HTML asoundlib API from the alsa website.
115115 """
116116
117- HTMLParser .entitydefs ['nbsp' ] = ' '
118-
119117 def __init__ (self , name , data ):
120- f = AbstractFormatter (DumbWriter (open (name , 'w' ), 100 ))
121- HTMLParser .__init__ (self , f )
118+ self . f = AbstractFormatter (DumbWriter (open (name , 'w' ), 100 ))
119+ HTMLParser .__init__ (self )
122120 self .feed (data )
123121 self .close ()
124122
125- def start_h1 (self , attrs ):
126- HTMLParser .start_h1 (self , attrs )
127- self .handle_data ("--- titlestart" )
128- self .do_br (None )
129-
130- def start_table (self , attrs ):
131- if len (attrs ) == 1 and attrs [0 ] == ("class" , "memname" ):
132- self .handle_data ("--- itemstart" )
133- self .do_br (None )
123+ def handle_data (self , data ):
124+ self .f .add_literal_data (data )
134125
135- def start_tr (self , attrs ):
136- self .do_br (None )
137-
138- def anchor_end (self ):
139- pass
126+ def handle_starttag (self , tag , attrs ):
127+ if tag == "div" :
128+ if len (attrs ) == 1 and attrs [0 ] == ("class" , "title" ):
129+ self .handle_data ("\n --- titlestart\n " )
130+ if len (attrs ) == 1 and attrs [0 ] == ("class" , "ingroups" ):
131+ self .handle_data ("\n \n " )
132+ elif tag == 'table' :
133+ if len (attrs ) == 1 and attrs [0 ] == ("class" , "memname" ):
134+ self .handle_data ("\n --- itemstart" )
140135
141136def parse_asoundlib_api (lines ):
142137 """
@@ -154,7 +149,8 @@ def parse_asoundlib_api(lines):
154149 comment = ""
155150 enumsublist = []
156151 for line in lines :
157- line = line [:- 1 ]
152+ # convert to space
153+ line = line [:- 1 ].replace ('\xa0 ' , ' ' )
158154 if False :
159155 if id (current ) == id (defines ):
160156 print ("defines " , end = ' ' )
@@ -168,7 +164,7 @@ def parse_asoundlib_api(lines):
168164 print (" " , end = ' ' )
169165 print ("%s %d %s" % (id (current ), state , line ))
170166
171- if line .startswith ('Define Documentation' ):
167+ if line .startswith ('Macro Definition Documentation' ):
172168 current = defines
173169 state = 0
174170 elif line .startswith ('Typedef Documentation' ):
@@ -185,36 +181,42 @@ def parse_asoundlib_api(lines):
185181 elif line .startswith ('--- titlestart' ):
186182 state = 5
187183 elif state == 5 :
188- title = line
184+ title = line . strip ()
189185 state = 0
190186 elif current == None :
191187 continue
192188 elif state == 1 :
193189 if line == "" :
190+ name = ' ' .join (name .split ())
194191 state = 2
195192 else :
196193 name += line
197- elif state == 2 :
194+ elif state == 2 and line != "" :
195+ comment = line .strip ()
198196 if id (current ) == id (enums ):
199197 state = 3
200198 else :
201- comment = line
202199 current .append ((name , comment ))
203200 name = ""
204201 comment = ""
205202 state = 0
206- elif state == 3 and line .startswith ('Enumerator:' ):
203+ elif state == 3 and line .startswith ('Enumerator' ):
204+ enum , subcomment = line [10 :].split (' ' , 1 )
205+ enumsublist = [(enum .strip (), subcomment .strip ())]
206+ linewasempty = False
207207 state = 4
208- enumsublist = []
209208 elif state == 4 :
210- if line == "" :
209+ if linewasempty and line == "" :
211210 current .append ((name , comment , enumsublist ))
212211 name = ""
213212 comment = ""
214213 state = 0
214+ elif line == "" :
215+ linewasempty = True
215216 else :
216217 enum , subcomment = line .split (' ' , 1 )
217- enumsublist .append ((enum , subcomment ))
218+ enumsublist .append ((enum .strip (), subcomment .strip ()))
219+ linewasempty = False
218220
219221 return (title , defines , typedefs , enums , functions )
220222
@@ -353,7 +355,7 @@ def print_api_coverage(urls, look_constant, look_usage, excludes):
353355 name = names [- 1 ]
354356 if ')' in name :
355357 names = d [0 ].split ('(' )
356- name = names [- 2 ].split ()[ - 1 ]
358+ name = names [- 2 ].removesuffix ( ') ' ). removeprefix ( '* ' )
357359 print_name (d [0 ], d [1 ], name , look_constant , look_usage , el )
358360 print_stat (title , "Typedefs" )
359361 print ("\n " * 2 )
0 commit comments