lib/htmshell.c File Reference

#include "common.h"
#include "obscure.h"
#include "cheapcgi.h"
#include "htmshell.h"
#include "errabort.h"
#include "dnautil.h"

Include dependency graph for htmshell.c:

Go to the source code of this file.

Functions

void htmlNoEscape ()
void htmlDoEscape ()
void htmlVaParagraph (char *line, va_list args)
void htmlParagraph (char *line,...)
void htmlVaCenterParagraph (char *line, va_list args)
void htmlCenterParagraph (char *line,...)
void htmlHorizontalLine ()
void htmHorizontalLine (FILE *f)
void htmlNbSpaces (int count)
void htmTextOut (FILE *f, char *s)
void htmlTextOut (char *s)
char * htmlEncode (char *s)
char * htmlWarnStartPattern ()
char * htmlWarnEndPattern ()
void htmlVaWarn (char *format, va_list args)
void htmlAbort ()
void htmlMemDeath ()
static void earlyWarningHandler (char *format, va_list args)
static void earlyAbortHandler ()
void htmlPushEarlyHandlers ()
void htmlSetStyle (char *style)
void htmlSetBackground (char *imageFile)
void htmlSetBgColor (int color)
void htmlSetCookie (char *name, char *value, char *expires, char *path, char *domain, boolean isSecure)
void _htmStart (FILE *f, char *title)
void htmlStart (char *title)
void htmStart (FILE *f, char *title)
void htmEnd (FILE *f)
void htmlEnd ()
void htmlEchoInput ()
void htmlBadVar (char *varName)
void htmlImage (char *fileName, int width, int height)
void htmErrOnlyShell (void(*doMiddle)())
void htmEmptyShell (void(*doMiddle)(), char *method)
void htmShell (char *title, void(*doMiddle)(), char *method)
void htmShellWithHead (char *title, char *head, void(*doMiddle)(), char *method)
void htmlIncludeFile (char *path)
void htmlIncludeWebFile (char *file)

Variables

static char const rcsid [] = "$Id: htmshell.c,v 1.32 2006/12/13 18:17:55 angie Exp $"
jmp_buf htmlRecover
static bool NoEscape = FALSE
static char * htmlStyle
char * htmlStyleUndecoratedLink
static char * htmlBackground = NULL
static int htmlBgColor = 0xFFFFFF
boolean gotBgColor = FALSE


Function Documentation

void _htmStart ( FILE *  f,
char *  title 
)

Definition at line 331 of file htmshell.c.

References gotBgColor, htmlBackground, htmlBgColor, and htmlStyle.

Referenced by htmlStart(), and htmStart().

00334 {
00335 fputs("<HTML>", f);
00336 fprintf(f,"<HEAD>\n<TITLE>%s</TITLE>\n", title);
00337 fprintf(f, "\t<META http-equiv=\"Content-Script-Type\" content=\"text/javascript\">\n");
00338 if (htmlStyle != NULL)
00339     fputs(htmlStyle, f);
00340 fputs("</HEAD>\n\n",f);
00341 fputs("<BODY",f);
00342 if (htmlBackground != NULL )
00343     fprintf(f, " BACKGROUND=\"%s\"", htmlBackground);
00344 if (gotBgColor)
00345     fprintf(f, " BGCOLOR=\"%X\"", htmlBgColor);
00346 fputs(">\n",f);
00347 }

Here is the caller graph for this function:

static void earlyAbortHandler (  )  [static]

Definition at line 243 of file htmshell.c.

Referenced by htmlPushEarlyHandlers().

00245 {
00246 printf("</BODY></HTML>");
00247 exit(0);
00248 }

Here is the caller graph for this function:

static void earlyWarningHandler ( char *  format,
va_list  args 
) [static]

Definition at line 229 of file htmshell.c.

References FALSE, htmlStart(), htmlVaParagraph(), htmlWarnEndPattern(), htmlWarnStartPattern(), and TRUE.

Referenced by htmlPushEarlyHandlers().

00231 {
00232 static boolean initted = FALSE;
00233 if (!initted)
00234     {
00235     htmlStart("Very Early Error");
00236     initted = TRUE;
00237     }
00238 printf("%s", htmlWarnStartPattern());
00239 htmlVaParagraph(format,args);
00240 printf("%s", htmlWarnEndPattern());
00241 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmEmptyShell ( void(*)()  doMiddle,
char *  method 
)

Definition at line 408 of file htmshell.c.

References htmlAbort(), htmlRecover, htmlVaWarn(), popAbortHandler(), popWarnHandler(), pushAbortHandler(), and pushWarnHandler().

Referenced by htmShell(), and htmShellWithHead().

00410 {
00411 int status;
00412 
00413 /* Set up error recovery (for out of memory and the like)
00414  * so that we finish web page regardless of problems. */
00415 pushAbortHandler(htmlAbort);
00416 pushWarnHandler(htmlVaWarn);
00417 status = setjmp(htmlRecover);
00418 
00419 /* Do your main thing. */
00420 if (status == 0)
00421     {
00422     doMiddle();
00423     }
00424 
00425 popWarnHandler();
00426 popAbortHandler();
00427 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmEnd ( FILE *  f  ) 

Definition at line 367 of file htmshell.c.

Referenced by doDetailLine(), and htmlEnd().

00368 {
00369 fputs("\n</BODY>\n</HTML>\n", f);
00370 }

Here is the caller graph for this function:

void htmErrOnlyShell ( void(*)()  doMiddle  ) 

Definition at line 393 of file htmshell.c.

References htmlRecover.

00395 {
00396 int status;
00397 
00398 /* Set up error recovery. */
00399 status = setjmp(htmlRecover);
00400 
00401 /* Do your main thing. */
00402 if (status == 0)
00403     {
00404     doMiddle();
00405     }
00406 }

void htmHorizontalLine ( FILE *  f  ) 

Definition at line 74 of file htmshell.c.

Referenced by pslShowAlignmentStranded().

00076 {
00077 fprintf(f, "<P><HR ALIGN=\"CENTER\"></P>");
00078 }

Here is the caller graph for this function:

void htmlAbort (  ) 

Definition at line 218 of file htmshell.c.

References htmlRecover.

Referenced by htmEmptyShell().

00220 {
00221 longjmp(htmlRecover, -1);
00222 }

Here is the caller graph for this function:

void htmlBadVar ( char *  varName  ) 

Definition at line 382 of file htmshell.c.

References cgiBadVar().

00383 {
00384 cgiBadVar(varName);
00385 }

Here is the call graph for this function:

void htmlCenterParagraph ( char *  line,
  ... 
)

Definition at line 60 of file htmshell.c.

References htmlVaCenterParagraph().

00061 {
00062 va_list args;
00063 va_start(args, line);
00064 htmlVaCenterParagraph(line, args);
00065 va_end(args);
00066 }

Here is the call graph for this function:

void htmlDoEscape (  ) 

Definition at line 31 of file htmshell.c.

References FALSE, and NoEscape.

00032 {
00033 NoEscape = FALSE;
00034 }

void htmlEchoInput (  ) 

Definition at line 378 of file htmshell.c.

00379 {
00380 }

char* htmlEncode ( char *  s  ) 

Definition at line 127 of file htmshell.c.

References needMem().

00129 {
00130 size_t len = 0;
00131 char c;
00132 char *encStr;
00133 char *p = s;
00134 /* First pass through s to determine encoded length to allocate: */
00135 /* [as a shortcut, we could simply allocate 6*length of s] */
00136 while ((c = *p++) != 0)
00137     {
00138     switch (c)
00139         {
00140         case '>':
00141         case '<':
00142             len += 4;
00143             break;
00144         case '&':
00145             len += 5;
00146             break;
00147         case '"':
00148             len += 6;
00149             break;
00150         default:
00151             len++;
00152             break;
00153         }
00154     }
00155 encStr = needMem(len+1);
00156 /* Second pass through s to encode: */
00157 len = 0;
00158 p = s;
00159 while ((c = *p++) != 0)
00160     {
00161     switch (c)
00162         {
00163         case '>':
00164             strcat(encStr+len, "&gt;");
00165             len += 4;
00166             break;
00167         case '<':
00168             strcat(encStr+len, "&lt;");
00169             len += 4;
00170             break;
00171         case '&':
00172             strcat(encStr+len, "&amp;");
00173             len += 5;
00174             break;
00175         case '"':
00176             strcat(encStr+len, "&quot;");
00177             len += 6;
00178             break;
00179         default:
00180             encStr[len++] = c;
00181             break;
00182         }
00183     }
00184 return encStr;
00185 }

Here is the call graph for this function:

void htmlEnd (  ) 

Definition at line 373 of file htmshell.c.

References htmEnd().

Referenced by htmShell(), and htmShellWithHead().

00374 {
00375 htmEnd(stdout);
00376 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlHorizontalLine (  ) 

Definition at line 68 of file htmshell.c.

References htmlParagraph().

Referenced by htmlVaWarn().

00070 {
00071 htmlParagraph("<HR ALIGN=\"CENTER\">");
00072 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlImage ( char *  fileName,
int  width,
int  height 
)

Definition at line 388 of file htmshell.c.

00389 {
00390 printf("<P ALIGN=\"CENTER\"><IMG SRC=\"%s\" WIDTH=\"%d\" HEIGHT=\"%d\" ALIGN=\"BOTTOM\" BORDER=\"0\"></P>", fileName, width, height);
00391 }

void htmlIncludeFile ( char *  path  ) 

Definition at line 479 of file htmshell.c.

References errAbort(), fileExists(), freeMem(), and readInGulp().

Referenced by htmlIncludeWebFile().

00480 {
00481 char *str = NULL;
00482 size_t len = 0;
00483 
00484 if (path == NULL)
00485     errAbort("Program error: including null file");
00486 if (!fileExists(path))
00487    errAbort("Missing file %s", path); 
00488 readInGulp(path, &str, &len);
00489 
00490 if (len <= 0)
00491     errAbort("Error reading included file: %s", path);
00492 
00493 puts(str);
00494 freeMem(str);
00495 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlIncludeWebFile ( char *  file  ) 

Definition at line 499 of file htmshell.c.

References htmlIncludeFile(), and safef().

00500 {
00501 char path[256];
00502 char *docRoot = "/usr/local/apache/htdocs";
00503 
00504 safef(path, sizeof path, "%s/%s", docRoot, file);
00505 htmlIncludeFile(path);
00506 }

Here is the call graph for this function:

void htmlMemDeath (  ) 

Definition at line 224 of file htmshell.c.

References errAbort().

00225 {
00226 errAbort("Out of memory.");
00227 }

Here is the call graph for this function:

void htmlNbSpaces ( int  count  ) 

Definition at line 80 of file htmshell.c.

00082 {
00083 int i;
00084 for (i=0; i<count; ++i)
00085     printf("&nbsp;");
00086 }

void htmlNoEscape (  ) 

Definition at line 26 of file htmshell.c.

References NoEscape, and TRUE.

00027 {
00028 NoEscape = TRUE;
00029 }

void htmlParagraph ( char *  line,
  ... 
)

Definition at line 44 of file htmshell.c.

References htmlVaParagraph().

Referenced by htmlHorizontalLine().

00045 {
00046 va_list args;
00047 va_start(args, line);
00048 htmlVaParagraph(line, args);
00049 va_end(args);
00050 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlPushEarlyHandlers (  ) 

Definition at line 250 of file htmshell.c.

References earlyAbortHandler(), earlyWarningHandler(), pushAbortHandler(), and pushWarnHandler().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlSetBackground ( char *  imageFile  ) 

Definition at line 284 of file htmshell.c.

References htmlBackground.

Referenced by main().

00287 {
00288 htmlBackground = imageFile;
00289 }

Here is the caller graph for this function:

void htmlSetBgColor ( int  color  ) 

Definition at line 294 of file htmshell.c.

References gotBgColor, htmlBgColor, and TRUE.

00297 {
00298 htmlBgColor = color;
00299 gotBgColor = TRUE;
00300 }

void htmlSetCookie ( char *  name,
char *  value,
char *  expires,
char *  path,
char *  domain,
boolean  isSecure 
)

Definition at line 302 of file htmshell.c.

References cgiEncode(), and TRUE.

00304 {
00305 char* encoded_name;
00306 char* encoded_value;
00307 char* encoded_path = NULL;
00308 
00309 encoded_name = cgiEncode(name);
00310 encoded_value = cgiEncode(value);
00311 if(path != NULL)
00312         encoded_path = cgiEncode(path);
00313 
00314 printf("Set-Cookie: %s=%s; ", encoded_name, encoded_value);
00315 
00316 if(expires != NULL)
00317     printf("expires=%s; ", expires);
00318 
00319 if(path != NULL)
00320     printf("path=%s; ", encoded_path);
00321 
00322 if(domain != NULL)
00323     printf("domain=%s; ", domain);
00324 
00325 if(isSecure == TRUE)
00326     printf("secure");
00327 
00328 printf("\n");
00329 }

Here is the call graph for this function:

void htmlSetStyle ( char *  style  ) 

Definition at line 273 of file htmshell.c.

References htmlStyle.

00278 {
00279 htmlStyle = style;
00280 }

void htmlStart ( char *  title  ) 

Definition at line 349 of file htmshell.c.

References _htmStart().

Referenced by earlyWarningHandler(), and htmShell().

00351 {
00352 puts("Content-Type:text/html");
00353 puts("\n");
00354 
00355 puts("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">");
00356 _htmStart(stdout, title);
00357 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlTextOut ( char *  s  ) 

Definition at line 121 of file htmshell.c.

References htmTextOut().

00123 {
00124 htmTextOut(stdout, s);
00125 }

Here is the call graph for this function:

void htmlVaCenterParagraph ( char *  line,
va_list  args 
)

Definition at line 52 of file htmshell.c.

Referenced by htmlCenterParagraph().

00054 {
00055 fputs("<P ALIGN=\"CENTER\">", stdout);
00056 vfprintf(stdout, line, args);
00057 fputs("</P>\n", stdout);
00058 }

Here is the caller graph for this function:

void htmlVaParagraph ( char *  line,
va_list  args 
)

Definition at line 36 of file htmshell.c.

Referenced by earlyWarningHandler(), htmlParagraph(), and htmlVaWarn().

00038 {
00039 fputs("<P>", stdout);
00040 vfprintf(stdout, line, args);
00041 fputs("</P>\n", stdout);
00042 }

Here is the caller graph for this function:

void htmlVaWarn ( char *  format,
va_list  args 
)

Definition at line 200 of file htmshell.c.

References htmlHorizontalLine(), htmlVaParagraph(), htmlWarnEndPattern(), htmlWarnStartPattern(), and va_copy.

Referenced by htmEmptyShell().

00202 {
00203 va_list argscp;
00204 va_copy(argscp, args);
00205 
00206 htmlHorizontalLine();
00207 printf("%s", htmlWarnStartPattern());
00208 htmlVaParagraph(format,args);
00209 printf("%s", htmlWarnEndPattern());
00210 htmlHorizontalLine();
00211 
00212 /* write warning/error message to stderr so they get logged. */
00213 vfprintf(stderr, format, argscp);
00214 va_end(argscp);
00215 fputc('\n', stderr);
00216 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* htmlWarnEndPattern (  ) 

Definition at line 194 of file htmshell.c.

Referenced by earlyWarningHandler(), htmlVaWarn(), and qaScanForErrorMessage().

00196 {
00197 return "<!-- HGERROR-END -->\n";
00198 }

Here is the caller graph for this function:

char* htmlWarnStartPattern (  ) 

Definition at line 188 of file htmshell.c.

Referenced by earlyWarningHandler(), htmlVaWarn(), and qaScanForErrorMessage().

00190 {
00191 return "<!-- HGERROR-START -->\n";
00192 }

Here is the caller graph for this function:

void htmShell ( char *  title,
void(*)()  doMiddle,
char *  method 
)

Definition at line 434 of file htmshell.c.

References dnaUtilOpen(), htmEmptyShell(), htmlEnd(), and htmlStart().

Referenced by webBlat().

00435 {
00436 /* Preamble. */
00437 dnaUtilOpen();
00438 htmlStart(title);
00439 
00440 /* Call wrapper for error handling. */
00441 htmEmptyShell(doMiddle, method);
00442 
00443 /* Post-script. */
00444 htmlEnd();
00445 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmShellWithHead ( char *  title,
char *  head,
void(*)()  doMiddle,
char *  method 
)

Definition at line 456 of file htmshell.c.

References dnaUtilOpen(), htmEmptyShell(), htmlBackground, and htmlEnd().

00457 {
00458 /* Preamble. */
00459 dnaUtilOpen();
00460 
00461 puts("Content-Type:text/html");
00462 puts("\n");
00463 
00464 puts("<HTML>");
00465 printf("<HEAD>%s<TITLE>%s</TITLE>\n</HEAD>\n\n", head, title);
00466 if (htmlBackground == NULL)
00467     puts("<BODY>\n");
00468 else
00469     printf("<BODY BACKGROUND=\"%s\">\n", htmlBackground);
00470 
00471 /* Call wrapper for error handling. */
00472 htmEmptyShell(doMiddle, method);
00473 
00474 /* Post-script. */
00475 htmlEnd();
00476 }

Here is the call graph for this function:

void htmStart ( FILE *  f,
char *  title 
)

Definition at line 359 of file htmshell.c.

References _htmStart().

Referenced by doDetailLine().

00361 {
00362 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n", f);
00363 _htmStart(f, title);
00364 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmTextOut ( FILE *  f,
char *  s 
)

Definition at line 88 of file htmshell.c.

References NoEscape.

Referenced by htmlTextOut().

00090 {
00091 char c;
00092 if (NoEscape)
00093     {
00094     fputs(s, f);
00095     return;
00096     }
00097 
00098 while ((c = *s++) != 0)
00099     {
00100     switch (c)
00101         {
00102         case '>':
00103             fputs("&gt;", f);
00104             break;
00105         case '<':
00106             fputs("&lt;", f);
00107             break;
00108         case '&':
00109             fputs("&amp;", f);
00110             break;
00111         case '"':
00112             fputs("&quot;", f);
00113             break;
00114         default:
00115             fputc(c, f);
00116             break;
00117         }
00118     }
00119 }

Here is the caller graph for this function:


Variable Documentation

boolean gotBgColor = FALSE

Definition at line 292 of file htmshell.c.

Referenced by _htmStart(), and htmlSetBgColor().

char* htmlBackground = NULL [static]

Definition at line 282 of file htmshell.c.

Referenced by _htmStart(), htmlSetBackground(), and htmShellWithHead().

int htmlBgColor = 0xFFFFFF [static]

Definition at line 291 of file htmshell.c.

Referenced by _htmStart(), and htmlSetBgColor().

jmp_buf htmlRecover

Definition at line 22 of file htmshell.c.

char* htmlStyle [static]

Initial value:

 
    "<STYLE TYPE=\"text/css\">"
    ".hiddenText {background-color: silver}"
    ".normalText {background-color: white}"
    "</STYLE>\n"

Definition at line 259 of file htmshell.c.

Referenced by _htmStart(), and htmlSetStyle().

char* htmlStyleUndecoratedLink

Initial value:


   "<STYLE TYPE=\"text/css\"> "
   "<!-- "
   "A {text-decoration: none} "
   "-->"
   "</STYLE>\n"

Definition at line 265 of file htmshell.c.

bool NoEscape = FALSE [static]

Definition at line 24 of file htmshell.c.

Referenced by htmlDoEscape(), htmlNoEscape(), and htmTextOut().

char const rcsid[] = "$Id: htmshell.c,v 1.32 2006/12/13 18:17:55 angie Exp $" [static]

Definition at line 20 of file htmshell.c.


Generated on Tue Dec 25 19:56:19 2007 for blat by  doxygen 1.5.2