Ch CGI Code for Web Complex Calculator
#!/bin/ch
/* Copyright (c) 2001 by SoftIntegration, Inc. All Rights Reserved */
/* Web Complex Calculator source code written in Ch */
#include
#include
void calculate_it(char *xx, char *yy, char *exprr) {
class CResponse Response;
double complex x = streval(xx);
double complex y = streval(yy);
double complex expr = streval(exprr);
Response.begin();
Response.title("Web Complex 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 Complex Calculator");
fprintf stdout << ENDFILE
Web Complex Calculator Failed
Your mathematical expression has not been submitted to Web Complex 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(!iscnum(x))
errorHandler("x is not a valid complex number");
y = Request.getForm("y");
if(!y)
errorHandler("you didn't input y value");
else if(!iscnum(y))
errorHandler("y is not a valid complex number");
expr = Request.getForm("expr");
if(!expr)
errorHandler ("you didn't input complex mathematical expression");
calculate_it(x, y, expr);
}
|
|