Frequently Asked Questions on Ch Applet
  1. How can I run Ch applets from remote servers on my client machine, instead of just downloading the source code?
  2. How can I send Ch applets from my server so that clients will execute them, instead of just downloading the source code?
  3. Why does a command can run in a terminal prompt, but cannot be executed in a Ch applet?
  4. How can a dynamic applet be created by CGI and executed across network?

Q: How can I run Ch applets from remote servers on my client machine, instead of just downloading the source code?

To run a safe Ch program with file extension .sch downloaded from a Web server as an applet, the following setup procedures for a client of the Ch language environment shall be followed.

  • Setup the Ch language environment on your machine. If you have not setup Ch on your local machine, download and install Ch first.

  • Type ch on your terminal. By default, program ch shall be located in a system directory. If you get an error message complaining that command ch is not found, the Ch language environment has not been setup in the default mode or it has not been installed.

  • Type ch -S on your terminal. Once Ch has been installed, test if it can be run as a safe shell on your terminal by typing ch -Sd. By executing the command ch -Sd, a default startup file .schrc will be copied from CHHOME/config/ to your home directory.
  • If you are running Unix, check to see if there are two files called .mime.types and .mailcap in your home directory. Copy them from the directory CHHOME/config. These two files in your home directory must be readable. If these two dot files already exist in your home directory, you can add the lines to these existing files. File .mime.types shall contain the following line application/x-sch sch so that files with extensions .sch are treated as application programs. File .mailcap will contain the following line application/x-sch; ch -S %s Therefore, the program with extension .sch will be executed in a safe shell.
  • As a system administrator, if you want to tighten the security of your whole system, you can modify the system-wide startup file CHHOME/config/schrc and individual user's startup file CHHOME/config/.schrc to restrict the search paths for commands, functions, and include files executable by applets. You can also limit the file permission for ~/.schrc in each user account to read only by changing the ownership of the file using the following command:
        chown root .schrc
        chmod 444  .schrc
    

  • After the above setup, restart your web broswer.

  • You may want to test your client of the Ch langugae environment by running our applet demos.

Q: How can I send Ch applets from my server so that clients will execute them, instead of just downloading the source code?

Ch CGI User's Guide has detailed instructions on how to setup different Web servers for handling Ch applets. Make sure after setup, restart the Web server.

Q: Why does a command can run in a terminal prompt, but cannot be executed in a Ch applet?

A Ch applet is normally executed in a safe shell for security reason. The command line option -S of the Ch program started by the client of the Ch language environment indicates that the applet will be executed in safe shell. The path for commands executable by the safe shell is contolled by the system-wide startup file CHHOME/config/schrc which includes ~/.schrc in your home directory. Besides the path for Ch programs, the path CHHOME/sbin/ contains system level programs executable from the safe shell. You can symbolically link other commands to this directory. For example, if you want to invoke my_command from a Ch applet, you can type

   ln -s /my_command_path/my_command my_command
inside the sbin directory. Since applets are downloaded from Web servers and executed in your local machine, make sure you do not put destructive commands such as rm in this directory.

Q:How can a dynamic applet be created by CGI and executed across network?

If a CGI program dynamically creates a Ch applet in the fly and the applet is then executed in a client machine, then such an applet that is created and delivered on demand is called dynamic applet. To create a Ch dynamic applet, the first line of output from the CGI script should be

     content-type: application/x-sch
to indicate that the output is the MIME type of Ch dynamic applet. For example, This CGI script will create the following dynamic applet,
     #include<stdio.h>
     int main() {
       double x = 3;
       printf("x = %f, ", x);
       printf("x*sin(2*x) = %f\n", x*sin(2*x));
     }
Note: A very difficult-to-debug mistake in the creation of dynamic applet is that the newline character is missing. For example, if the last output statement of this CGI script is
     printf("}");
instead of
     printf("}\n");
The created dynamic applet will not work.