#!/usr/bin/python2 # -*- coding: utf-8 -*- """ © Florian MORTGAT """ import os, sys import re from _getphpdoc_indexdata import funcIndex # funcIndex is a dictionary of the following form: # funcIndex = { # 'funcName': ('docfile.html', 'description'), # 'str_replace': ('function.str-replace.html', 'Replace all occurrences of the search string with the replacement string'), # 'array_push': ('function.array-push.html', 'Push one or more elements onto the end of array') # } # It has been extracted from indexes.functions.html using some regexes # bdir = '/home/florian/Documents/documentation info/php/manual/php-chunked-xhtml' os.chdir(bdir) class O:'' G=O() USAGE="""Usage: getphpdoc.py [MODE] [QUERY] MODE: list prints a list of all functions whose name partially matches QUERY. show prints the documentation of the function specified in QUERY or, if not found, a list of partially matching functions. QUERY: QUERY is the name of the function to display or the first letters of that name (or even a regular expression). """ SUGGEST_LIMIT = 50 def main (): try: action = sys.argv[1] q = sys.argv[2] except: print USAGE return if action=='list': # list entries starting with 2nd arg n=0 for name in sorted (funcIndex): if n >= SUGGEST_LIMIT: break if re.match ('^'+q, name): print name n+=1 elif action=='show': # show entry # if q is a file, print it if os.path.isfile (q): print open (q,'r').read () # if it is a whole function name, print it elif q in funcIndex: filename,desc = funcIndex[q] if os.path.isfile (filename): print open (filename,'r').read () else: print "file not found: %s"%filename # if it is a partial function name, print suggestions else: print '<pre style="font-size:130%;font-family:arial">' print 'requested: "%s"n'%q for name in sorted (funcIndex): if re.search (q, name): filename, desc = funcIndex[name] print '<a href="%s">%s</a>: <span style="font-size: 70%%">%s</span>'%( filename, name, desc) if __name__ == "__main__": try: main () except KeyboardInterrupt: print ("Leaving: User typed Ctrl+C")