| 1 |
#!/bin/ksh |
| 2 |
|
| 3 |
|
| 4 |
purpose="manual" |
| 5 |
|
| 6 |
for arg;do |
| 7 |
if [[ $arg = "-h" || $arg = "-help" || $arg = "--help" ]] |
| 8 |
then |
| 9 |
echo "" |
| 10 |
echo "format_listings" |
| 11 |
echo "Possible options:" |
| 12 |
echo " -manual : format the examples for the manual (default)" |
| 13 |
echo " -tutorial : format the examples for the tutorial" |
| 14 |
echo "" |
| 15 |
exit |
| 16 |
fi |
| 17 |
|
| 18 |
if [[ $arg = "-tutorial" ]] |
| 19 |
then |
| 20 |
purpose="tutorial" |
| 21 |
fi |
| 22 |
|
| 23 |
if [[ $arg = "-manual" ]] |
| 24 |
then |
| 25 |
purpose="manual" |
| 26 |
fi |
| 27 |
|
| 28 |
done |
| 29 |
|
| 30 |
|
| 31 |
# format the FORTRAN listings |
| 32 |
|
| 33 |
for fortran in examples/$purpose/fortran/source/*.f |
| 34 |
do |
| 35 |
fortran_cc=${fortran}_cc # 'cc' here means 'colour coded' |
| 36 |
temp="temp.x" |
| 37 |
|
| 38 |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $fortran_cc |
| 39 |
echo "<!DOCTYPE part PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"" >> $fortran_cc |
| 40 |
echo " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">" >> $fortran_cc |
| 41 |
echo "" >> $fortran_cc |
| 42 |
echo "<programlisting>" >> $fortran_cc |
| 43 |
|
| 44 |
|
| 45 |
# remove any '<' or '>' which might confuse the XML parser |
| 46 |
sed "s/>/\>/g" $fortran > $temp |
| 47 |
|
| 48 |
sed "s/</\</g" $temp >> $fortran_cc |
| 49 |
|
| 50 |
# format the comments |
| 51 |
cp $fortran_cc $temp |
| 52 |
# sed "s/^\([Cc\*].*\)/<comment>\1<\/comment>/g" $fortran >> $fortran_cc |
| 53 |
sed "s/^\([Cc\*].*\)/<comment>\1<\/comment>/g" $temp > $fortran_cc |
| 54 |
|
| 55 |
# format the action routines |
| 56 |
cp $fortran_cc $temp |
| 57 |
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\)/<function>\1<\/function>/g" $temp > $fortran_cc |
| 58 |
|
| 59 |
# format the parameter names [we identify them by ('XXX' ] |
| 60 |
cp $fortran_cc $temp |
| 61 |
sed "s/\(('\)\([^']*\)\('\)/\1<parameter>\2<\/parameter>\3/g" $temp > $fortran_cc |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
echo "</programlisting>" >> $fortran_cc |
| 66 |
rm -f $temp |
| 67 |
done |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
# format the C listings |
| 72 |
|
| 73 |
for c in examples/$purpose/c/source/*.c |
| 74 |
do |
| 75 |
c_cc=${c}_cc # 'cc' here means 'colour coded' |
| 76 |
temp="temp.x" |
| 77 |
|
| 78 |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $c_cc |
| 79 |
echo "<!DOCTYPE part PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"" >> $c_cc |
| 80 |
echo " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">" >> $c_cc |
| 81 |
echo "" >> $c_cc |
| 82 |
echo "<programlisting>" >> $c_cc |
| 83 |
|
| 84 |
|
| 85 |
# remove any '<' or '>' which might confuse the XML parser |
| 86 |
sed "s/>/\>/g" $c > $temp |
| 87 |
|
| 88 |
sed "s/</\</g" $temp >> $c_cc |
| 89 |
|
| 90 |
# format the comments |
| 91 |
cp $c_cc $temp |
| 92 |
sed "s/\(\/\*.*\*\/\)/<comment>\1<\/comment>/g" $temp > $c_cc |
| 93 |
|
| 94 |
# format the action routines |
| 95 |
cp $c_cc $temp |
| 96 |
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\)/<function>\1<\/function>/g" $temp > $c_cc |
| 97 |
|
| 98 |
# format the parameter names [we identify them by ('XXX' ] |
| 99 |
cp $c_cc $temp |
| 100 |
sed "s/\(('\)\([^']*\)\('\)/\1<parameter>\2<\/parameter>\3/g" $temp > $c_cc |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
echo "</programlisting>" >> $c_cc |
| 105 |
rm -f $temp |
| 106 |
done |
| 107 |
|
| 108 |
|
| 109 |
# format the MagML listings |
| 110 |
|
| 111 |
for magml in examples/$purpose/magml/source/*.magml examples/$purpose/metgram/source/*.epsml |
| 112 |
do |
| 113 |
magml_cc=${magml}_cc # 'cc' here means 'colour coded' |
| 114 |
temp="temp.x" |
| 115 |
|
| 116 |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $magml_cc |
| 117 |
echo "<!DOCTYPE part PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"" >> $magml_cc |
| 118 |
echo " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">" >> $magml_cc |
| 119 |
echo "" >> $magml_cc |
| 120 |
echo "<programlisting>" >> $magml_cc |
| 121 |
|
| 122 |
|
| 123 |
# remove any '<' or '>' which might confuse the XML parser |
| 124 |
sed "s/>/\>/g" $magml > $temp |
| 125 |
sed "s/</\</g" $temp >> $magml_cc |
| 126 |
|
| 127 |
# format the comments |
| 128 |
cp $magml_cc $temp |
| 129 |
sed "s/\(<!--.*-->\)/<comment>\1<\/comment>/g" $temp > $magml_cc |
| 130 |
|
| 131 |
# format any attribute names (single-quotes) |
| 132 |
cp $magml_cc $temp |
| 133 |
sed "s/\(\w*\)\([ \t]*=[ \t]*\)'/<parameter>\1<\/parameter>\2'/g" $temp > $magml_cc |
| 134 |
|
| 135 |
|
| 136 |
# format any attribute names (double-quotes) |
| 137 |
# cp $magml_cc $temp |
| 138 |
# sed "s/\(\w*\)\([ \t]*=[ \t]*\)\"/<parameter>\1<\/parameter>\2\"/g" $temp > $magml_cc |
| 139 |
|
| 140 |
|
| 141 |
# format any attribute values (single-quotes) |
| 142 |
# cp $magml_cc $temp |
| 143 |
# sed "s/'\(\w*\)'/<classname>\1<\/classname>/g" $temp > $magml_cc |
| 144 |
|
| 145 |
|
| 146 |
# format the tag names |
| 147 |
cp $magml_cc $temp |
| 148 |
sed "s/<\(\/*\w*\)/\<<classname>\1<\/classname>/g" $temp > $magml_cc |
| 149 |
|
| 150 |
|
| 151 |
# format the action routines |
| 152 |
cp $magml_cc $temp |
| 153 |
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\)/<function>\1<\/function>/g" $temp > $magml_cc |
| 154 |
|
| 155 |
# format the parameter names [we identify them by ('XXX' ] |
| 156 |
cp $magml_cc $temp |
| 157 |
sed "s/\(('\)\([^']*\)\('\)/\1<parameter>\2<\/parameter>\3/g" $temp > $magml_cc |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
echo "</programlisting>" >> $magml_cc |
| 162 |
rm -f $temp |
| 163 |
done |
| 164 |
|
| 165 |
|
| 166 |
# format the Python listings |
| 167 |
|
| 168 |
for py in examples/$purpose/python/source/*.py |
| 169 |
do |
| 170 |
py_cc=${py}_cc # 'cc' here means 'colour coded' |
| 171 |
temp="temp.x" |
| 172 |
|
| 173 |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $py_cc |
| 174 |
echo "<!DOCTYPE part PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"" >> $py_cc |
| 175 |
echo " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">" >> $py_cc |
| 176 |
echo "" >> $py_cc |
| 177 |
echo "<programlisting>" >> $py_cc |
| 178 |
|
| 179 |
|
| 180 |
# remove any '<' or '>' which might confuse the XML parser |
| 181 |
sed "s/>/\>/g" $py > $temp |
| 182 |
sed "s/</\</g" $temp >> $py_cc |
| 183 |
|
| 184 |
# format the 'import Magics' directive |
| 185 |
cp $py_cc $temp |
| 186 |
sed "s/\(import Magics\)/<classname>\1<\/classname>/g" $temp > $py_cc |
| 187 |
|
| 188 |
# format the comments |
| 189 |
cp $py_cc $temp |
| 190 |
sed "s/\(#.*\)/<comment>\1<\/comment>/g" $temp > $py_cc |
| 191 |
|
| 192 |
# format the action routines |
| 193 |
cp $py_cc $temp |
| 194 |
sed "s/\(Magics\.[A-Z0-9a-z_]*\)/<function>\1<\/function>/g" $temp > $py_cc |
| 195 |
|
| 196 |
# format the parameter names [we identify them by ("XXX" ] |
| 197 |
cp $py_cc $temp |
| 198 |
sed "s/\((\"\)\([^\"]*\)\(\"\)/\1<parameter>\2<\/parameter>\3/g" $temp > $py_cc |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
echo "</programlisting>" >> $py_cc |
| 203 |
rm -f $temp |
| 204 |
done |
| 205 |
|
| 206 |
|