Ch CGI Code for Web Calculator

#!/bin/ch /* Copyright (c) 2001 by SoftIntegration, Inc. All Rights Reserved */ /* Web Calculator source code written in Ch */ #include <cgi.h> void calculate_it(char *xx, char *yy, char *exprr) { class CResponse Response; double x = strtod(xx, NULL); double y = strtod(yy, NULL); double expr = streval(exprr); Response.begin(); Response.title("Web Calculator"); printf("x = %s\n<br>", xx); printf("y = %s\n<br>", yy); printf("%s = %f\n<p>", exprr, expr); Response.end(); } void errorHandler(char *reason) { class CResponse Response; Response.begin(); Response.title("Web Calculator"); fprintf stdout << ENDFILE <H3>Web Calculator Failed</H3> Your mathematical expression has not been submitted to Web Calculator because $reason. <A HREF="/docs/ch/cgi/calculator_cgi.html">Try again.</A> <P><HR SIZE=4> <A HREF="http://www.softintegration.com">SoftIntegration, Inc.</A> ENDFILE Response.end(); exit(0); } int main() { class CRequest Request; int num; chchar *x, *y, *expr; x = Request.getForm("x"); if(!x) errorHandler("you didn't input x value"); else if(!isnum(x)) errorHandler("x is not a valid number"); y = Request.getForm("y"); if(!y) errorHandler("you didn't input y value"); else if(!isnum(y)) errorHandler("y is not a valid number"); expr = Request.getForm("expr"); if(!expr) errorHandler ("you didn't input mathematical expression"); calculate_it(x, y, expr); }