lib/textOut.c File Reference

#include "common.h"
#include "errabort.h"
#include "cheapcgi.h"
#include "pipeline.h"
#include "textOut.h"

Include dependency graph for textOut.c:

Go to the source code of this file.

Functions

static void textOutWarnHandler (char *format, va_list args)
static void textOutAbortHandler ()
static char * getCompressSuffix (char *compressType)
static char ** getCompressor (char *compressType)
static void cleanEnvVars (char *compressType)
pipelinetextOutInit (char *fileName, char *compressType)
void textOutClose (struct pipeline **pCompressPipeline)

Variables

static char const rcsid [] = "$Id: textOut.c,v 1.3 2006/08/04 06:00:20 markd Exp $"


Function Documentation

static void cleanEnvVars ( char *  compressType  )  [static]

Definition at line 74 of file textOut.c.

References errAbort(), sameWord, textOutCompressBzip2, textOutCompressCompress, textOutCompressGzip, and textOutCompressZip.

Referenced by textOutInit().

00077 {
00078 if (sameWord(compressType, textOutCompressGzip))
00079     {
00080     unsetenv("GZIP");
00081     unsetenv("GZIP_OPT");
00082     }
00083 else if (sameWord(compressType, textOutCompressCompress))
00084     {
00085     /* No environment variables mentioned in man page. */
00086     }
00087 else if (sameWord(compressType, textOutCompressBzip2))
00088     {
00089     unsetenv("BZIP");
00090     unsetenv("BZIP2");
00091     }
00092 else if (sameWord(compressType, textOutCompressZip))
00093     {
00094     unsetenv("ZIPOPT");
00095     }
00096 else
00097     {
00098     errAbort("cleanEnvVars: Unsupported textOutCompress type %s",
00099              compressType);
00100     }
00101 }

Here is the call graph for this function:

Here is the caller graph for this function:

static char** getCompressor ( char *  compressType  )  [static]

Definition at line 52 of file textOut.c.

References errAbort(), sameWord, textOutCompressBzip2, textOutCompressCompress, textOutCompressGzip, and textOutCompressZip.

Referenced by textOutInit().

00054 {
00055 static char *GZ_WRITE[] = {"gzip", "-qc", NULL};
00056 static char *Z_WRITE[] = {"compress", "-c", NULL};
00057 static char *BZ2_WRITE[] = {"bzip2", "-qzc", NULL};
00058 static char *ZIP_WRITE[] = {"zip", "-q", NULL};
00059 
00060 if (sameWord(compressType, textOutCompressGzip))
00061     return GZ_WRITE;
00062 else if (sameWord(compressType, textOutCompressCompress))
00063     return Z_WRITE;
00064 else if (sameWord(compressType, textOutCompressBzip2))
00065     return BZ2_WRITE;
00066 else if (sameWord(compressType, textOutCompressZip))
00067     return ZIP_WRITE;
00068 else
00069     errAbort("getCompressor: Unsupported textOutCompress type %s",
00070              compressType);
00071 return NULL;
00072 }

Here is the call graph for this function:

Here is the caller graph for this function:

static char* getCompressSuffix ( char *  compressType  )  [static]

Definition at line 31 of file textOut.c.

References errAbort(), sameWord, textOutCompressBzip2, textOutCompressCompress, textOutCompressGzip, and textOutCompressZip.

Referenced by textOutInit().

00033 {
00034 static char *gzipSuffix = ".gz";
00035 static char *compressSuffix = ".Z";
00036 static char *bz2Suffix = ".bz2";
00037 static char *zipSuffix = ".zip";
00038 if (sameWord(compressType, textOutCompressGzip))
00039     return gzipSuffix;
00040 else if (sameWord(compressType, textOutCompressCompress))
00041     return compressSuffix;
00042 else if (sameWord(compressType, textOutCompressBzip2))
00043     return bz2Suffix;
00044 else if (sameWord(compressType, textOutCompressZip))
00045     return zipSuffix;
00046 else
00047     errAbort("getCompressSuffix: Unsupported textOutCompress type %s",
00048              compressType);
00049 return NULL;
00050 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void textOutAbortHandler (  )  [static]

Definition at line 25 of file textOut.c.

Referenced by textOutInit().

00027 {
00028 exit(-1);
00029 }

Here is the caller graph for this function:

void textOutClose ( struct pipeline **  pCompressPipeline  ) 

Definition at line 152 of file textOut.c.

References pipelineFree(), and pipelineWait().

00155 {
00156 if (pCompressPipeline && *pCompressPipeline)
00157     {
00158     fflush(stdout);
00159     fclose(stdout);
00160     pipelineWait(*pCompressPipeline);
00161     pipelineFree(pCompressPipeline);
00162     }
00163 }

Here is the call graph for this function:

struct pipeline* textOutInit ( char *  fileName,
char *  compressType 
) [read]

Definition at line 104 of file textOut.c.

References cleanEnvVars(), endsWith(), errnoAbort(), getCompressor(), getCompressSuffix(), isEmpty, pipelineFd(), pipelineOpen1(), pipelineWrite, pushAbortHandler(), pushWarnHandler(), sameWord, textOutAbortHandler(), textOutCompressNone, textOutWarnHandler(), and trimSpaces().

00110 {
00111 struct pipeline *compressPipeline = NULL;
00112 
00113 trimSpaces(fileName);
00114 if (isEmpty(fileName))
00115     {
00116     printf("Content-Type: text/plain\n\n");
00117     }
00118 else if (isEmpty(compressType) || sameWord(compressType, textOutCompressNone))
00119     {
00120     printf("Content-Type: application/octet-stream\n");
00121     printf("Content-Disposition: attachment; filename=%s\n\n", fileName);
00122     }
00123 else
00124     {
00125     char *suffix = getCompressSuffix(compressType);
00126 
00127     printf("Content-Type: application/x-%s\n", compressType);
00128     if (endsWith(fileName, suffix))
00129         printf("Content-Disposition: attachment; filename=%s\n\n", fileName);
00130     else
00131         printf("Content-Disposition: attachment; filename=%s%s\n\n",
00132                fileName, suffix);
00133 
00134     /* Send the Content header uncompressed! */
00135     fflush(stdout);
00136 
00137     /* Make sure no environment variables interfere with compressor. */
00138     cleanEnvVars(compressType);
00139 
00140     /* Redirect stdout to compressor pipeline object. */
00141     compressPipeline = pipelineOpen1(getCompressor(compressType),
00142                                      pipelineWrite, NULL, NULL);
00143     if (-1 == dup2(pipelineFd(compressPipeline), STDOUT_FILENO))
00144         errnoAbort("dup2(pipelineFd %d, stdout %d) failed in textOpen()",
00145                    pipelineFd(compressPipeline), STDOUT_FILENO);
00146     }
00147 pushWarnHandler(textOutWarnHandler);
00148 pushAbortHandler(textOutAbortHandler);
00149 return(compressPipeline);
00150 }

Here is the call graph for this function:

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

Definition at line 11 of file textOut.c.

Referenced by textOutInit().

00013 {
00014 char *hLine =
00015 "---------------------------------------------------------------------------\n";
00016 if (format != NULL) {
00017     fflush(stdout);
00018     fprintf(stdout, "%s", hLine);
00019     vfprintf(stdout, format, args);
00020     fprintf(stdout, "\n");
00021     fprintf(stdout, "%s", hLine);
00022     }
00023 }

Here is the caller graph for this function:


Variable Documentation

char const rcsid[] = "$Id: textOut.c,v 1.3 2006/08/04 06:00:20 markd Exp $" [static]

Definition at line 9 of file textOut.c.


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