home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


SSIDump

The SSIDump program is a handy debugging utility that dumps the SSI environment variables and command-line arguments back to the browser (see Listing 32.1).

Listing 32.1 ssidump.c—SSI Program for Dumping SSI Environment Variables


// SSIDUMP.C
// This program dumps the SSI environment variables
// to the screen.  The code is platform-independent.
// Compile it for your system and place it in your
// CGI-BIN directory.

#include <windows.h>  // only required for Windows machines
#include <stdio.h>

void main(int argc, char * argv[]) {

     // First declare our variables.  This program
     // only uses one, i, a generic integer counter.

     int i;

     // Print some nice-looking header
     // information.  Note that unlike a CGI
     // program, there is no need to include the
     // standard HTTP headers.

     printf(“<H1>SSI Environment Dump</H1>\n”);
     printf(“<B>Command-Line Arguments:</B>\n”);

     // Now print the command-line arguments.
     // By convention, arg[0] is the path to this
     // program at run-time.  args[1] through
     // arg[argc-1] are passed to the program as
     // parameters.  Only some servers will allow
     // command-line arguments.  We’ll use a nice
     // bulleted list format to make it readable:

printf(“<ul>\n”);
     for (i = 0; i < argc; i++) {
          printf(“<li>argv[%i]=%s\n”,i,argv[i]);
     }
     printf(“</ul>\n”);

     // Now print out whatever environment variables
     // are visible to us.  We’ll use the bulleted
     // list format again:

     printf(“<b>Environment Variables:</b>\n<ul>\n”);
     i = 0;
     while (_environ[i])
{
          printf(“<li>%s\n”,_environ[i]);
          i++;
}
     printf(“</ul>\n”);

     // Flush the output and we’re done

     fflush(stdout);
     return;
}

RQ

The RQ program hunts up a random quotation or other bit of text from a file and outputs it. The quotation file uses a simple format: Each entry must be contiguous, but can span any number of lines. Entries are separated by a single blank line. Listing 32.2 is a sample quotation file. The entries were chosen randomly by RQ itself. Make of that what you will.

Listing 32.2 Rq.txt—Sample Text File for Use with the RQ Program


KEEPING THIS A HAPPY FILE:
o All entries should start flush-left.
o Entries may be up to 8K in length.
o Entries must be at least one line.
o Entries may contain 1-9999 lines (8K max).
o Line length is irrelevant; CRs are ignored.
o Entries are separated by ONE blank line.
o The last entry must be followed by a blank line, too.
o The first entry (these lines here) will never get picked,
o so we use it to document the file.
o Length of the file doesn’t change retrieval time.
o Any line beginning with “--” it is treated as a byline.
o It must be the last line in the block, otherwise the
o quotation might get cut off.
o You can use HTML formatting tags.

Drunk is feeling sophisticated when you can’t say it.
--Anon

What really flatters a man is that you think him worth
flattery.
--George Bernard Shaw

True patriotism hates injustice in its own land more
than anywhere else.
--Clarence Darrow

If by “fundies” we mean “fanatics,” that’s okay with
me, but in that case shouldn’t we call them fannies?
--Damon Knight

My <I>other</I> car is <I>also</I> a Porsche.
--Bumper Sticker

The death sentence is a necessary and efficacious means for
the Church to attain its ends when rebels against it disturb
the ecclesiastical unity, especially obstinate heretics who
cannot be restrained by any other penalty from continuing to
disturb ecclesiastical order.
--Pope Leo XIII

Note that although the preceding sample file has text quotations in it, you can just as easily use RQ for random links or graphics. For random links or graphics, leave off the bylines and use standard <A HREF> format. You can even use RQ for single words or phrases used to complete a sentence in real-time. For example, the phrases in parentheses can come from an RQ file to complete this sentence: “If you don’t like this page, you’re (a pusillanimous slug) (a cultured person) (pond scum) (probably dead) (quite perceptive) (drunk) (an editor).” I’ll leave it to you to figure out which are compliments and which are insults.


NOTE:  RQ has security precautions built in. It does not read from a file that’s located anywhere other than the same directory as RQ itself or a subdirectory under it. This precaution prevents malicious users from misusing RQ to read files elsewhere on the server. It looks for two periods in case the user tries to evade the path requirement by ascending the directory tree. It checks for a double-backslash in case it finds itself on an NT server and the user tries to slip in a UNC file specification. Finally, it checks for a colon in case the user tries to specify a drive letter. If RQ finds any of these situations, it writes out an error message and dies.

RQ can accept the name of a quotation file from a command-line argument. If you’re unlucky enough to run RQ on a server that doesn’t support command-line arguments, or if you leave the command-line arguments off, RQ tries to open Rq.txt in the same directory it’s in. You can have multiple executables, each reading a different file, simply by having copies of RQ with different names. RQ looks for its executable name at runtime, strips the extension, and adds .txt. So if you have a copy of RQ named RQ2, it opens Rq2.txt.

Listing 32.3 shows the code for the rq.c program.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.