1*fae261c0SBarry Smith#!/usr/bin/env python 2*fae261c0SBarry Smith""" Adds links in the manual pages to implementations of the function""" 3*fae261c0SBarry Smith 4*fae261c0SBarry Smithimport os 5*fae261c0SBarry Smithimport re 6*fae261c0SBarry Smith 7*fae261c0SBarry Smithdef processfile(petsc_dir,dir,file,implsClassAll,implsFuncAll): 8*fae261c0SBarry Smith #print('Processing '+os.path.join(dir,file)) 9*fae261c0SBarry Smith itemName = file[0:-3] 10*fae261c0SBarry Smith func = list(filter(lambda x: x.find(itemName+'_') > -1, implsFuncAll)) 11*fae261c0SBarry Smith iclass = list(filter(lambda x: x.find('_p_'+itemName) > -1, implsClassAll)) 12*fae261c0SBarry Smith if func or iclass: 13*fae261c0SBarry Smith with open(os.path.join(dir,file),'a') as f: 14*fae261c0SBarry Smith f.write('\n## Implementations\n') 15*fae261c0SBarry Smith if func: 16*fae261c0SBarry Smith for str in func: 17*fae261c0SBarry Smith f.write(re.sub('(.*\.[ch]x*u*).*('+itemName+'.*)(\(.*\))','<A HREF=\"PETSC_DOC_OUT_ROOT_PLACEHOLDER/\\1.html#\\2\">\\2() in \\1</A><BR>',str,count=1)+'\n') 18*fae261c0SBarry Smith if iclass: 19*fae261c0SBarry Smith for str in iclass: 20*fae261c0SBarry Smith f.write(re.sub('(.*\.[ch]x*u*):.*struct.*(_p_'+itemName+').*{','<A HREF=\"PETSC_DOC_OUT_ROOT_PLACEHOLDER/\\1.html#\\2\">\\2 in \\1</A><BR>',str,count=1)+'\n') 21*fae261c0SBarry Smith 22*fae261c0SBarry Smithdef loadstructfunctions(petsc_dir): 23*fae261c0SBarry Smith '''Creates the list of structs and class functions''' 24*fae261c0SBarry Smith import subprocess 25*fae261c0SBarry Smith implsClassAll = subprocess.check_output(['git', 'grep', 'struct\s\+_[pn]_[^\s]\+.*{', '--', '*.c', '*.cpp', '*.cu', '*.c', '*.h', '*.cxx'], cwd = petsc_dir).strip().decode('utf-8') 26*fae261c0SBarry Smith implsClassAll = list(filter(lambda x: not (x.find('/tests/') > -1 or x.find('/tutorials') > -1 or x.find(';') > -1), implsClassAll.split('\n'))) 27*fae261c0SBarry Smith 28*fae261c0SBarry Smith implsFuncAll = subprocess.check_output(['git', 'grep', '-n', '^\(static \)\?\(PETSC_EXTERN \)\?\(PETSC_INTERN \)\?\(extern \)\?PetscErrorCode \+[^_ ]\+_[^_ ]\+(', '--', '*/impls/*.c', '*/impls/*.cpp', '*/impls/*.cu', '*/impls/*.c', '*/impls/*.h', '*/impls/*.cxx'], cwd = petsc_dir).strip().decode('utf-8') 29*fae261c0SBarry Smith implsFuncAll = list(filter(lambda x: not (x.find('_Private') > -1 or x.find('_private') > -1 or x.find(';') > -1), implsFuncAll.split('\n'))) 30*fae261c0SBarry Smith return (implsClassAll,implsFuncAll) 31*fae261c0SBarry Smith 32*fae261c0SBarry Smithdef main(petsc_dir): 33*fae261c0SBarry Smith (implsClassAll,implsFuncAll) = loadstructfunctions(petsc_dir) 34*fae261c0SBarry Smith for dirpath, dirnames, filenames in os.walk(os.path.join(petsc_dir,'doc','manualpages'),topdown=True): 35*fae261c0SBarry Smith #print('Processing directory '+dirpath) 36*fae261c0SBarry Smith for file in filenames: 37*fae261c0SBarry Smith if file.endswith('.md'): processfile(petsc_dir,dirpath,file,implsClassAll,implsFuncAll) 38*fae261c0SBarry Smith 39*fae261c0SBarry Smithif __name__ == "__main__": 40*fae261c0SBarry Smith main(os.path.abspath(os.environ['PETSC_DIR'])) 41