topical media & game development

talk show tell print

lib-ch-example-sample-matrixMaker.cgi / cgi



  #!/bin/ch
  //*************************************************************
  // makematrix.cgi
  // creates a matrix of size specified
  // by the client. Submits operation options
  // to matrixCalculator.cgi.
  // History: created by Harry H. Cheng, 2/8/1996
  // Last modified: 2/22/96
  //*************************************************************
  
  include<cgi.h>
  
  void errorHandler(char *reason) {
      printf("<TITLE>Web Matrix Calculator Failed</TITLE>\n");
      printf("<body bgcolor=\"#FFFFFF\" text=\"#000000\" vlink=\"#FF0000\">\n");
      printf("<H3>Web Matrix Calculator Failed</H3>\n");
      printf("Your mathematical expression has not been submitted to Matrix Calculator,\n");
      printf("because \%s. ",reason);
      printf("<A HREF=\"/chhtml/toolkit/demos/cgi/sample/matrixCalculator.html\">Try again.</A>\n");
      printf("<p>
\n"); printf("<A HREF=\"http://www.softintegration.com\" target=\"_top\">\n"); printf("<img src=\"/chhtml/images/poweredbych.gif\" alt=\"Powered by Ch\"></A>\n"); exit(1); } int main() { int num, i, j, rowA, colA, rowB, colB, matrixNum; chstrarray name; chstrarray value; string_t reason; class CResponse Response; class CRequest Request; Response.setContentType("text/html"); Response.begin(); num = Request.getFormNameValue(name, value); if(num==0 || value[0]==NULL) { printf("No name/value has been submitted<p>\n"); exit(0); } for(i=0;i<num;i++) { if(!isnum(value[i])) { sprintf(reason,"\%s is not a valid dimension", value[i]); errorHandler(reason); } } if(num==1) { rowA=atoi(value[0]); colA=rowA; matrixNum = 1; } if(num==4) { rowA=atoi(value[0]); colA=atoi(value[1]); rowB=atoi(value[2]); colB=atoi(value[3]); matrixNum = 2; } printf("<HEAD>\n"); printf("<TITLE>\n"); printf("Web Matrix Calculator \n"); printf("</TITLE>\n"); printf("</HEAD>\n"); printf("<body bgcolor=\"#FFFFFF\" text=\"#000000\" vlink=\"#FF0000\">\n"); printf("<H1>Web Matrix Calculator </H1>\n"); printf("<HR>\n"); printf("<FORM method=\"POST\" action=/cgi-bin/chcgi/toolkit/demos/sample/matrixCalculator.ch>\n"); printf("<INPUT type=\"hidden\" name=\"matrixNum\" value=\"\%d\">\n", matrixNum); if(num == 1) { printf("<INPUT type=\"hidden\" name=\"rowA\" value=\%d>\n", rowA); printf("<INPUT type=\"hidden\" name=\"colA\" value=\%d>\n", colA); } if(num == 4) { printf("<INPUT type=\"hidden\" name=\"rowA\" value=\%d>\n", rowA); printf("<INPUT type=\"hidden\" name=\"colA\" value=\%d>\n", colA); printf("<INPUT type=\"hidden\" name=\"rowB\" value=\%d>\n", rowB); printf("<INPUT type=\"hidden\" name=\"colB\" value=\%d>\n", colB); } printf("A = \n"); printf("<BR>"); for(i=1;i<=rowA;i++) { for(j=1;j<=colA;j++) printf("<INPUT name=\"A\%d\%d\" value=\"\%d\" size=5>\n", i, j, i+j); printf("<BR>\n"); } if(num!=1) { printf("<P>\n"); printf("B = \n"); printf("<BR>"); for(i=1;i<=rowB;i++) { for(j=1;j<=colB;j++) { printf("<INPUT name=\"B\%d\%d\" value=\"\%d\" size=5>\n", i, j, i+j); } printf("<BR>\n"); } } printf("<P>\n"); printf("Expression\n<BR>\n"); if(num!=1) printf("<INPUT NAME=\"operation\" value = \"\%s\" SIZE=\"35\"></P>\n", "transpose(A)*B"); else printf("<INPUT NAME=\"operation\" value = \"\%s\" SIZE=\"35\"></P>\n", "2*A"); printf("<INPUT TYPE=submit VALUE=\"Calcualte\">\n"); printf("<INPUT TYPE=reset VALUE=\"Reset\">\n"); printf("</FORM>\n"); printf("<p>
\n"); printf("<A HREF=\"http://www.softintegration.com\" target=\"_top\">\n"); printf("<img src=\"/chhtml/images/poweredbych.gif\" alt=\"Powered by Ch\"></A>\n"); printf("</FONT>\n"); printf("</BODY>\n"); Response.end(); exit(0); }


(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.