[vtkusers] vtk-tcl2cxx.sed

Issac Trotts ijtrotts at ucdavis.edu
Wed Jan 8 23:33:18 EST 2003


Here's a sed script to help with conversion of vtk 
Tcl scripts to C++.  It can be run by listing .tcl files
on the command line, or by piping or pasting to stdin.

The user has to do some cleanup afterwards, but a lot of the repetitive
work is taken care of by the script.  

Issac




#!/bin/sed -f
#
# vtk-tcl2cxx.sed
# Written by Issac Trotts (ijtrotts at ucdavis.edu), 2003.
# Distribute and mutate freely.
# This script has no warrantee, but feedback is encouraged.
#

# remove tabs
s/      /    /g

# strip leading and trailing space.
# user can run GNU indent or favorite editor afterwards.
s/^ *//
s/ *$//

# remove tcl-isms
s/^package require .*$//

# comments
s/#/\/\//g

# allocation of new objects
s/^\(vtk[^ ]*\) \+\([^ ]*\)$/\1 * \2 = \1::New();/

# no-argument function calls
s/^ *\([a-z][^ ]*\) \+\([A-Z][^ ]*\) *$/\1->\2();/

# one-argument function calls (redundant) 
s/^ *\([a-z][^ ]*\) \+\([A-Z][^ ]*\) \+\([a-z][^ ]*\)$/\1->\2(\3);/

# function calls with arguments
s/^ *\([a-z][^ ]*\) \+\([A-Z][^ ]*\) \+\(.*\)$/\1->\2(\3 \4);/

# [foo GetBar] SetBaz ...
s/^\( *\)\(\[.\+\]\) \+\([A-Z][^ ]*\) \+\(.*\)$/\1\2->\3(\4);/

# no-argument function calls in square brackets
s/\[ *\([a-z][^ ]*\) \+\([A-Z][^ ]*\) *\]/\1->\2()/g

# clean up parens 
s/ *)/)/g

# numerical arg lists
s/\(\<-\?[.0-9]\+\) \+/\1, /g

# set foo bar
s/^\( *\)set \+\([a-z][^ ]*\) \+\(.*\)$/\1\2 = \3;/

# dollar signs
s/\$//g


-- 



More information about the vtkusers mailing list