#!/Library/Frameworks/Python.framework/Versions/Current/bin/python
# L-34 MCS 275 Wed 9 Apr 2008 : show_hello_world2.py

# This CGI script takes the input of the form show_hello_world2.html
# and displays the code in a textarea element.

import cgi
form = cgi.FieldStorage()

L = form['language'].value
Lv = {'0':'C', '1':'Java', '2':'Python'}

if L == '0':
   c = '#include <stdio.h>\n\n' \
     + 'int main(void)\n' \
     + '{\n' \
     + '   printf(\"Hello World!\\n\");\n' \
     + '   return 0;\n' \
     + '}\n'
elif L == '1':
   c = 'public class HelloWorld\n' \
     + '{\n' \
     + '   public static void main(String[] args)\n' \
     + '   {\n' \
     + '      System.out.print(\"Hello World!\");\n' \
     + '      System.out.println();\n' \
     + '   }\n' \
     + '}\n'
else:
   c = 'print \"Hello World!\"'

print "Content-Type: text/html\n"
print "<h1> Hello World! in %s </h1>" % Lv[L]
print "<textarea rows = 4 columns = 30>"
print c
print "</textarea>"
print "<p> <input type = \"submit\" " \
  + " value = \"execute the code\"> </p>"
