Structured Text (Re: [Mapserver-dev] SWIG MapScript docs)

Norman Vine nhv at cape.com
Wed Feb 18 11:21:56 EST 2004


This is a multi-part message in MIME format.

------=_NextPart_000_0101_01C3F611.6AB5C480
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Jean-Francois Doyon writes:
> 
> Well I've never documented API's using it, but reading the docs suggests
> there are elements for functions, method, function parameters, and so on ...
> 
> You can see the list of elements available from the online book:
> 
> http://www.docbook.org/tdg/en/html/docbook.html
> 
> The trickier question is whether the transformation tools render things in
> the way you expect/would like.  Just because you use the proper xml elements
> doesn't mean the transformation will do something with them, or doesn't mean
> that whatever it does with them you will like.  

< dreaming >
I wonder if any of us is smart enough to figure out how to have
SWIG itself generate most of the documentation for us
< /dreaming >

Attached python script should dump the SWIG parse tree

to use copy script into your 

$SRC/mapserver/mapscript/python  directory 

and execute it

Note to change the extension language for the SWIG parser 
 see SWIG_LANGUAGE_OPTION at top of file and set appropriately

Cheers

Norman
------=_NextPart_000_0101_01C3F611.6AB5C480
Content-Type: text/plain;
	name="swig_tree.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="swig_tree.py"

#! /usr/bin/env python

#
SWIG_LANGUAGE_OPTION = "-python"

from distutils.core import setup, Extension
#from distutils import sysconfig
from distutils.spawn import spawn
from distutils.dir_util import mkpath,remove_tree
from distutils.file_util import copy_file
from distutils.sysconfig import parse_makefile,expand_makefile_vars
from distutils.dep_util import newer
from string import split
import os,sys
from os import path
import re
import string

# set to see progress messages
noisy=1

# path to mapserver directory
ms_dir=path.join("..","..")

# set this to reflect your installation
# This is the typical Unix location
local_dir="/usr/local"
local_lib_dir = path.join(local_dir,"lib")
local_include_dir = path.join(local_dir,"include")

# local containers to hold the actual lists to eventually pass to distutils
lib_list = []
extra_objects_list = []
defined_macros_list = []
include_dirs_list = [ms_dir, local_include_dir]
library_dirs_list = [ms_dir, local_lib_dir]

def configure(verbose=noisy):
    """parse mapserver Makefile for local configuration"""
    global lib_list, defined_macros_list, ms_dir
    global include_dirs_list, using_ogr

    DICT = parse_makefile(path.join(ms_dir,"Makefile"))
    
    if verbose > 1:
        print DICT
        print DICT.keys()

    for key in DICT.keys():
        data = DICT[key].split()
        if verbose > 1:
            print 'key,data',key,data
            
        for entry in data:
            entry.strip()
            if verbose > 1:
                print '\t',entry
            if entry[0:2] == '-D':
                entry = entry[2:]
                if entry == 'USE_OGR':
                    using_ogr = 1
                    if verbose > 1:
                        print 'USING OGR'
                defined_macros_list.append((entry,None))
            elif entry[0:2] == '-I':
                entry = entry[2:]
                if verbose > 1:
                    print key,entry
                include_dirs_list.append(entry)
            
    for lib in split(DICT[expand_makefile_vars("LDFLAGS",DICT)]):
        lib = lib.strip()
        if lib[0:2] == '-l':
            lib_list.append(lib[2:])
            
    if os.name == 'posix':        
        lib_list.append('supc++')

    if verbose > 1:
        print 'defined_macros_list ',defined_macros_list
        print 'lib_list ',lib_list
        print 'include_dirs_list ',include_dirs_list


def swig(verbose=noisy):
    
    swig_message = """compile mapscript.i with swig"""

    ifile = "mapscript.i"
  
    copy_file(os.path.join("../",ifile),ifile)

    swig_cmd = ["swig", SWIG_LANGUAGE_OPTION ]
    swig_cmd2 = ["-dump_tree", ifile ]
    swig_opts = []
    
    for macro in defined_macros_list:
        data,key = macro
        swig_opts.append('-D%s'%data)

    cmd = swig_cmd + swig_opts + swig_cmd2
    
    try:                        
        spawn(cmd, verbose=noisy)
    except:
        print "\nSwig Error"
        print swig_message
        raise sys.exit()

def main():
    configure()
    swig()

if __name__ == '__main__':
    main()

------=_NextPart_000_0101_01C3F611.6AB5C480--




More information about the mapserver-dev mailing list