#!/bin/ksh purpose="manual" for arg;do if [[ $arg = "-h" || $arg = "-help" || $arg = "--help" ]] then echo "" echo "format_listings" echo "Possible options:" echo " -manual : format the examples for the manual (default)" echo " -tutorial : format the examples for the tutorial" echo "" exit fi if [[ $arg = "-tutorial" ]] then purpose="tutorial" fi if [[ $arg = "-manual" ]] then purpose="manual" fi done # format the FORTRAN listings for fortran in examples/$purpose/fortran/source/*.f do fortran_cc=${fortran}_cc # 'cc' here means 'colour coded' temp="temp.x" echo "" > $fortran_cc echo "> $fortran_cc echo " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">" >> $fortran_cc echo "" >> $fortran_cc echo "" >> $fortran_cc # remove any '<' or '>' which might confuse the XML parser sed "s/>/\>/g" $fortran > $temp sed "s/> $fortran_cc # format the comments cp $fortran_cc $temp # sed "s/^\([Cc\*].*\)/\1<\/comment>/g" $fortran >> $fortran_cc sed "s/^\([Cc\*].*\)/\1<\/comment>/g" $temp > $fortran_cc # format the action routines cp $fortran_cc $temp sed "s/\(PRESET\|PSETC\|PSETI\|PSETR\|PSET1C\|PSET1R\|PSET1I\|POPEN\|PCLOSE\|PCOAST\|PCONT\|PTEXT\|PLEGEND\|PAXIS\|PGRAPH\|PIMAGE\|PGRIB\|PNETCDF\|PODB\|PNEW\|POBS\|PSYMB\|PWIND\|PBOXPLOT\|PLINE\)/\1<\/function>/g" $temp > $fortran_cc # format the parameter names [we identify them by ('XXX' ] cp $fortran_cc $temp sed "s/\(('\)\([^']*\)\('\)/\1\2<\/parameter>\3/g" $temp > $fortran_cc echo "" >> $fortran_cc rm -f $temp done # format the C listings for c in examples/$purpose/c/source/*.c do c_cc=${c}_cc # 'cc' here means 'colour coded' temp="temp.x" echo "" > $c_cc echo "> $c_cc echo " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">" >> $c_cc echo "" >> $c_cc echo "" >> $c_cc # remove any '<' or '>' which might confuse the XML parser sed "s/>/\>/g" $c > $temp sed "s/> $c_cc # format the comments cp $c_cc $temp sed "s/\(\/\*.*\*\/\)/\1<\/comment>/g" $temp > $c_cc # format the action routines cp $c_cc $temp sed "s/\(mag_reset\|mag_setc\|mag_seti\|mag_setr\|mag_set1c\|mag_set1r\|mag_set1i\|mag_open\|mag_close\|mag_coast\|mag_cont\|mag_text\|mag_legend\|mag_axis\|mag_graph\|mag_image\|mag_grib\|mag_netcdf\|mag_odb\|mag_new\|mag_obs\|mag_bufr\|mag_symb\|mag_wind\|mag_boxplot\)/\1<\/function>/g" $temp > $c_cc # format the parameter names [we identify them by ('XXX' ] cp $c_cc $temp sed "s/\(('\)\([^']*\)\('\)/\1\2<\/parameter>\3/g" $temp > $c_cc echo "" >> $c_cc rm -f $temp done # format the MagML listings for magml in examples/$purpose/magml/source/*.magml examples/$purpose/metgram/source/*.epsml do magml_cc=${magml}_cc # 'cc' here means 'colour coded' temp="temp.x" echo "" > $magml_cc echo "> $magml_cc echo " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">" >> $magml_cc echo "" >> $magml_cc echo "" >> $magml_cc # remove any '<' or '>' which might confuse the XML parser sed "s/>/\>/g" $magml > $temp sed "s/> $magml_cc # format the comments cp $magml_cc $temp sed "s/\(<!--.*-->\)/\1<\/comment>/g" $temp > $magml_cc # format any attribute names (single-quotes) cp $magml_cc $temp sed "s/\(\w*\)\([ \t]*=[ \t]*\)'/\1<\/parameter>\2'/g" $temp > $magml_cc # format any attribute names (double-quotes) # cp $magml_cc $temp # sed "s/\(\w*\)\([ \t]*=[ \t]*\)\"/\1<\/parameter>\2\"/g" $temp > $magml_cc # format any attribute values (single-quotes) # cp $magml_cc $temp # sed "s/'\(\w*\)'/\1<\/classname>/g" $temp > $magml_cc # format the tag names cp $magml_cc $temp sed "s/<\(\/*\w*\)/\<\1<\/classname>/g" $temp > $magml_cc # format the action routines cp $magml_cc $temp sed "s/\(mag_reset\|mag_setc\|mag_seti\|mag_setr\|mag_set1c\|mag_set1r\|mag_set1i\|mag_open\|mag_close\|mag_coast\|mag_cont\|mag_text\|mag_legend\|mag_axis\|mag_graph\|mag_image\|mag_grib\|mag_netcdf\|mag_odb\|mag_new\|mag_obs\|mag_bufr\|mag_symb\|mag_wind\|mag_boxplot\)/\1<\/function>/g" $temp > $magml_cc # format the parameter names [we identify them by ('XXX' ] cp $magml_cc $temp sed "s/\(('\)\([^']*\)\('\)/\1\2<\/parameter>\3/g" $temp > $magml_cc echo "" >> $magml_cc rm -f $temp done # format the Python listings for py in examples/$purpose/python/source/*.py do py_cc=${py}_cc # 'cc' here means 'colour coded' temp="temp.x" echo "" > $py_cc echo "> $py_cc echo " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">" >> $py_cc echo "" >> $py_cc echo "" >> $py_cc # remove any '<' or '>' which might confuse the XML parser sed "s/>/\>/g" $py > $temp sed "s/> $py_cc # format the 'import Magics' directive cp $py_cc $temp sed "s/\(import Magics\)/\1<\/classname>/g" $temp > $py_cc # format the comments cp $py_cc $temp sed "s/\(#.*\)/\1<\/comment>/g" $temp > $py_cc # format the action routines cp $py_cc $temp sed "s/\(Magics\.[A-Z0-9a-z_]*\)/\1<\/function>/g" $temp > $py_cc # format the parameter names [we identify them by ("XXX" ] cp $py_cc $temp sed "s/\((\"\)\([^\"]*\)\(\"\)/\1\2<\/parameter>\3/g" $temp > $py_cc echo "" >> $py_cc rm -f $temp done