• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

makedocstrings.py

Go to the documentation of this file.
00001 # Copyright 2002 Gary Bishop
00002 # This file is part of PLplot.
00003 
00004 # PLplot is free software; you can redistribute it and/or modify
00005 # it under the terms of the GNU Library General Public License as published by
00006 # the Free Software Foundation; version 2 of the License.
00007 
00008 # PLplot is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 # GNU Library General Public License for more details.
00012 
00013 # You should have received a copy of the GNU Library General Public License
00014 # along with the file PLplot; if not, write to the Free Software
00015 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00016 
00017 # The recent versions of SWIG (at least for 1.3.11) do not handle documentation
00018 # strings correctly
00019 # This script is a quick hack to fixup the doc strings in the 
00020 # SWIG-generated c code, but presumably this script
00021 # will not always be necessary
00022 
00023 import sys, re
00024 
00025 def main():
00026   if len(sys.argv) != 3:
00027     print 'usage: makedocstrings infile outfile'
00028     
00029   infile = open(sys.argv[1], 'rt')
00030   outfile = open(sys.argv[2], 'wt')
00031 
00032   docstrings = {}
00033   
00034   while 1:
00035     line = infile.readline()
00036     if not line:
00037       break
00038     m = re.match(r'#define _doc_([a-zA-Z_0-9]+)', line)
00039     if m:
00040       name = m.group(1)
00041       value = '_doc_'+name
00042       docstrings[name] = value
00043       #print 'got',name
00044 
00045     if re.match(r'static PyMethodDef SwigMethods', line):
00046       outfile.write(line)
00047       #print 'here'
00048       while 1:
00049         line = infile.readline()
00050         m = re.match('[ \t]+\{[ \t]\(char \*\)"([a-zA-Z_0-9]+)"(.*)\,[ ]*NULL[ ]*\},', line)
00051         if not m:
00052           m = re.match('[ \t]+\{[ \t]\(char \*\)"([a-zA-Z_0-9]+)"(.*)\},', line)
00053           if not m:
00054             break
00055         func = m.group(1)
00056         #print 'look for',func
00057         if func in docstrings.keys():
00058           line = '\t{ (char *)"%s"%s, %s },\n' % (func, m.group(2), docstrings[func])
00059         outfile.write(line)
00060 
00061     outfile.write(line)
00062 
00063 if __name__ == '__main__':
00064   main()

Generated on Wed Oct 12 2011 20:42:21 for PLplot by  doxygen 1.7.1