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
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 ", xx);
printf("y = %s\n ", yy);
printf("%s = %f\n", exprr, expr);
Response.end();
}
void errorHandler(char *reason) {
class CResponse Response;
Response.begin();
Response.title("Web Calculator");
fprintf stdout << ENDFILE
Web Calculator Failed
Your mathematical expression has not been submitted to Web Calculator
because $reason.
Try again.
SoftIntegration, Inc.
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);
}
|
|