1
1
#!/usr/bin/python3
2
2
3
- ## Copyright 2018-2023 John Donoghue
3
+ ## Copyright 2018-2024 John Donoghue
4
4
##
5
5
## This program is free software: you can redistribute it and/or modify it
6
6
## under the terms of the GNU General Public License as published by
16
16
## along with this program. If not, see
17
17
## <https://www.gnu.org/licenses/>.
18
18
19
- ## mkfuncdocs v1.0.7
19
+ ## mkfuncdocs v1.0.8
20
20
## mkfuncdocs.py will attempt to extract the help texts from functions in src
21
21
## dirs, extracting only those that are in the specifed INDEX file and output them
22
22
## to stdout in texi format
@@ -89,6 +89,36 @@ def find_defun_line_in_file(filename, fnname):
89
89
90
90
return - 1
91
91
92
+ def find_function_line_in_file (filename , fnname ):
93
+ linecnt = 0
94
+ func = False
95
+ defun_line = re .compile (r"^\s*function \s*" )
96
+ with open (filename , 'rt' ) as f :
97
+ for line in f :
98
+ if func == True :
99
+ x = line .strip ()
100
+ if x .startswith ("## -*- texinfo -*-" ):
101
+ return linecnt
102
+ else :
103
+ func = False
104
+
105
+ if re .match (defun_line , line ):
106
+ if line .find ("=" ) != - 1 :
107
+ x = line .split ("=" )
108
+ x = x [- 1 ]
109
+ else :
110
+ x = line .replace ("function " , "" )
111
+
112
+ x = x .split ("(" )
113
+ x = x [0 ].strip ()
114
+ if x == fnname :
115
+ func = True
116
+
117
+ linecnt = linecnt + 1
118
+
119
+ return - 1
120
+
121
+
92
122
def read_m_file (filename , skip = 0 ):
93
123
help = []
94
124
inhelp = False
@@ -195,6 +225,29 @@ def read_index (filename, ignore):
195
225
196
226
return index ;
197
227
228
+ def find_class_file (fname , paths ):
229
+
230
+ for f in paths :
231
+ # class constructor ?
232
+ name = f + "/@" + fname + "/" + fname + ".m"
233
+ if os .path .isfile (name ):
234
+ return name , 0
235
+
236
+ # perhaps classname.func format ?
237
+ x = fname .split ("." )
238
+ if len (x ) > 0 :
239
+ zname = x .pop ()
240
+ cname = "." .join (x )
241
+ name = f + "/" + cname + ".m"
242
+ if os .path .isfile (name ):
243
+ idx = find_function_line_in_file (name , zname )
244
+ if idx >= 0 :
245
+ return name , idx
246
+ name = f + "/@" + cname + "/" + zname + ".m"
247
+ if os .path .isfile (name ):
248
+ return name , 0
249
+ return None , - 1
250
+
198
251
def find_func_file (fname , paths , prefix , scanfiles = False ):
199
252
for f in paths :
200
253
name = f + "/" + fname + ".m"
@@ -205,7 +258,6 @@ def find_func_file(fname, paths, prefix, scanfiles=False):
205
258
if os .path .isfile (name ):
206
259
return name , 0
207
260
name = f + "/" + fname + ".cc"
208
- name = f + "/" + fname + ".cc"
209
261
if os .path .isfile (name ):
210
262
return name , 0
211
263
name = f + "/" + fname + ".cpp"
@@ -335,19 +387,26 @@ def process (args):
335
387
ref = f .split ("/" )[- 1 ]
336
388
filename , lineno = find_func_file (path , options ["srcdir" ], options ["funcprefix" ])
337
389
elif "." in f :
338
- parts = f .split ('.' )
339
- cnt = 0
340
- path = ""
341
- for p in parts :
390
+ path = f
391
+ ref = f .split ("." )[- 1 ]
392
+ name = f .split ("." )[- 1 ]
393
+ filename , lineno = find_class_file (path , options ["srcdir" ])
394
+
395
+ if not filename :
396
+ parts = f .split ('.' )
397
+ cnt = 0
398
+ path = ""
399
+ for p in parts :
342
400
if cnt < len (parts )- 1 :
343
401
path = path + "/+"
344
402
else :
345
403
path = path + "/"
346
404
path = path + p
347
405
cnt = cnt + 1
348
- name = f ;
349
- ref = parts [- 1 ]
350
- filename , lineno = find_func_file (path , options ["srcdir" ], options ["funcprefix" ])
406
+ name = f ;
407
+ ref = parts [- 1 ]
408
+ filename , lineno = find_func_file (path , options ["srcdir" ], options ["funcprefix" ])
409
+
351
410
elif "/" in f :
352
411
path = f
353
412
name = f
@@ -360,7 +419,7 @@ def process (args):
360
419
filename , lineno = find_func_file (path , options ["srcdir" ], options ["funcprefix" ], options ['allowscan' ])
361
420
362
421
if not filename :
363
- sys .stderr .write ("Warning: Cant find source file for {}\n " .format (path ))
422
+ sys .stderr .write ("Warning: Cant find source file for {}\n " .format (f ))
364
423
else :
365
424
h = read_help (filename , lineno )
366
425
0 commit comments