topical media & game development
lib-ch-example-sample-calculator-cgi.cgi / cgi
#!/bin/ch
/* Copyright (c) 2001 by SoftIntegration, Inc. All Rights Reserved */
/* Web Calculator source code written in Ch */
include <cgi.h>
include <stdio.h>
include <stdlib.h>
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 fullname`;
remove(fullname);
errorHandler(stradd("invalid value for expression.<br> ", message));
}
else {
remove(fullname);
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();
}
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);
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.