Writing HTML from GSL

The Gsharp Script Language contains specific functions for creating and setting Gsharp graphics, and also functions for general file I/O. The GSL I/O functions can be used to output the HTTP header and HTML commands needed to dynamically construct web pages. This section will guide you through a GSL script that constructs a very simple web page and explain the basic techniques that will be used as you develop your own dynamic web applications.

To output HTML, an output function must be used. GSL includes the following I/O functions, which closely correspond to the ANSI C functions of the same name:


  fopen(file_name, mode)

  fwrite(access_id, var1[, ... varN])

  fclose(access_id)
 
These functions can be used to output text to stdout or a file. When using standard system files, such as stdout, as the output file, fopen and fclose do not need to be called, as these files are managed by the system. Here are the access id's for the standard system files:
  stdin        0
  stdout       1
  stdmsg       2

Creating an HTML file without libhtml.gsl

GSL I/O functions can be called from a program to create a simple HTML page. Here is a short example:

  /*
   * Open file, write out HTML, close file
   */
  f = fopen("hello.html", "w");
  fwrite(f, "<HTML><HEAD><TITLE>GsharpWE Greeting</TITLE></HEAD>");
  fwrite(f, "<BODY BGCOLOR=#FFFFFF>");
  fwrite(f, "<CENTER><H1>Hello Wide World</H1>");
  fwrite(f, "</BODY></HTML>");
  fclose(f);

Creating an HTML file with libhtml.gsl

If you prefer you could create the same file using the functions in libhtml.gsl

  include "$UNIDIR/lib/libhtml.gsl";

  f = fopen("hello.html", "w");
  HTMLheader2(f, "GsharpWE Greeting", "AVS", "#FFFFFF");
  fwrite(f, "<CENTER>");
  HTMLheading(f, 1, "Hello Wide World");
  HTMLfooter(f);
  fclose(f);

This program can be run using the command:
  /bin/GsharpWE hello.gsl
When this GSL is run, the file hello.html is created. You can see the result here.

Now carry on to CGI programming with GSL