📄 htinit.c
字号:
/* Configuration-specific Initialialization HTInit.c** ----------------------------------------*//* Define a basic set of suffixes and presentations** ------------------------------------------------*/#include "HTUtils.h"#include "tcp.h"/* Implements:*/#include "HTInit.h"#include "HTML.h"#include "HTPlain.h"#include "HTMLGen.h"#include "HTFile.h"#include "HTFormat.h"#include "HTMIME.h"#include "HTWSRC.h"#include "HTSaveToFile.h" /* LJM */#include "userdefs.h"#include "LYUtils.h"#include "LYGlobalDefs.h"#include "LYSignal.h"#include "LYSystem.h"#include "LYexit.h"#include "LYLeaks.h"#define FREE(x) if (x) {free(x); x = NULL;}#ifdef VMS#define DISPLAY "DECW$DISPLAY"#else#define DISPLAY "DISPLAY"#endif /* VMS */PRIVATE int HTLoadTypesConfigFile PARAMS((char *fn));PRIVATE int HTLoadExtensionsConfigFile PARAMS((char *fn));PUBLIC void HTFormatInit NOARGS{ FILE *fp = NULL; char *cp = NULL;#ifdef NeXT HTSetPresentation("application/postscript", "open %s", 1.0, 2.0, 0.0, 0); HTSetPresentation("image/x-tiff", "open %s", 2.0, 2.0, 0.0, 0); HTSetPresentation("image/tiff", "open %s", 1.0, 2.0, 0.0, 0); HTSetPresentation("audio/basic", "open %s", 1.0, 2.0, 0.0, 0); HTSetPresentation("*", "open %s", 1.0, 0.0, 0.0, 0);#else if ((cp = getenv(DISPLAY)) != NULL && *cp != '\0') { /* Must have X11 */ HTSetPresentation("application/postscript", "ghostview %s&", 1.0, 3.0, 0.0, 0); HTSetPresentation("image/gif", XLoadImageCommand, 1.0, 3.0, 0.0, 0); HTSetPresentation("image/x-xbm", XLoadImageCommand, 1.0, 3.0, 0.0, 0); HTSetPresentation("image/x-xbitmap", XLoadImageCommand, 1.0, 3.0, 0.0, 0); HTSetPresentation("image/x-png", XLoadImageCommand, 2.0, 3.0, 0.0, 0); HTSetPresentation("image/png", XLoadImageCommand, 1.0, 3.0, 0.0, 0); HTSetPresentation("image/x-rgb", XLoadImageCommand, 1.0, 3.0, 0.0, 0); HTSetPresentation("image/x-tiff", XLoadImageCommand, 2.0, 3.0, 0.0, 0); HTSetPresentation("image/tiff", XLoadImageCommand, 1.0, 3.0, 0.0, 0); HTSetPresentation("image/jpeg", XLoadImageCommand, 1.0, 3.0, 0.0, 0); HTSetPresentation("video/mpeg", "mpeg_play %s &", 1.0, 3.0, 0.0, 0); }#endif#ifdef EXEC_SCRIPTS /* set quality to 999.0 for protected exec applications */#ifndef VMS HTSetPresentation("application/x-csh", "csh %s", 999.0, 3.0, 0.0, 0); HTSetPresentation("application/x-sh", "sh %s", 999.0, 3.0, 0.0, 0); HTSetPresentation("application/x-ksh", "ksh %s", 999.0, 3.0, 0.0, 0);#else HTSetPresentation("application/x-VMS_script", "@%s", 999.0, 3.0, 0.0, 0);#endif /* not VMS */#endif /* EXEC_SCRIPTS *//* * Add our header handlers. */ HTSetConversion("www/mime", "www/present", HTMIMEConvert, 1.0, 0.0, 0.0, 0); HTSetConversion("www/mime", "www/download", HTMIMEConvert, 1.0, 0.0, 0.0, 0); HTSetConversion("www/mime", "www/source", HTMIMEConvert, 1.0, 0.0, 0.0, 0); HTSetConversion("www/mime", "www/dump", HTMIMEConvert, 1.0, 0.0, 0.0, 0);/* * Add our compressed file handlers. */ HTSetConversion("www/compressed", "www/present", HTCompressed, 1.0, 0.0, 0.0, 0); HTSetConversion("www/compressed", "www/download", HTCompressed, 1.0, 0.0, 0.0, 0); HTSetConversion("www/compressed", "www/present", HTCompressed, 1.0, 0.0, 0.0, 0); HTSetConversion("www/compressed", "www/source", HTCompressed, 1.0, 0.0, 0.0, 0); HTSetConversion("www/compressed", "www/dump", HTCompressed, 1.0, 0.0, 0.0, 0); /* * Added the following to support some content types beginning to surface. */ HTSetConversion("application/html", "text/x-c", HTMLToC, 0.5, 0.0, 0.0, 0); HTSetConversion("application/html", "text/plain", HTMLToPlain, 0.5, 0.0, 0.0, 0); HTSetConversion("application/html", "www/present", HTMLPresent, 2.0, 0.0, 0.0, 0); HTSetConversion("application/html", "www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("application/x-wais-source", "www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("application/x-wais-source", "www/present", HTWSRCConvert, 2.0, 0.0, 0.0, 0); HTSetConversion("application/x-wais-source", "www/download", HTWSRCConvert, 1.0, 0.0, 0.0, 0); HTSetConversion("application/x-wais-source", "www/dump", HTWSRCConvert, 1.0, 0.0, 0.0, 0); /* * Save all unknown mime types to disk. */ HTSetConversion("www/source", "www/present", HTSaveToFile, 1.0, 3.0, 0.0, 0); HTSetConversion("www/source", "www/source", HTSaveToFile, 1.0, 3.0, 0.0, 0); HTSetConversion("www/source", "www/download", HTSaveToFile, 1.0, 3.0, 0.0, 0); HTSetConversion("www/source", "*", HTSaveToFile, 1.0, 3.0, 0.0, 0); /* * Output all www/dump presentations to stdout. */ HTSetConversion("www/source", "www/dump", HTDumpToStdout, 1.0, 3.0, 0.0, 0);/* * Now add our basic conversions. */ HTSetConversion("text/x-sgml", "www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/x-sgml", "www/present", HTMLPresent, 2.0, 0.0, 0.0, 0); HTSetConversion("text/sgml", "www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/sgml", "www/present", HTMLPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/plain","www/present", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/plain","www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/html", "www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/html", "text/x-c", HTMLToC, 0.5, 0.0, 0.0, 0); HTSetConversion("text/html", "text/plain", HTMLToPlain, 0.5, 0.0, 0.0, 0); HTSetConversion("text/html", "www/present", HTMLPresent, 1.0, 0.0, 0.0, 0); /* * These should override the default types as necessary. */ HTLoadTypesConfigFile(global_type_map); /* * Load the local maps. */ if ((fp = fopen(personal_type_map,"r")) != NULL) { fclose(fp); /* These should override everything else. */ HTLoadTypesConfigFile(personal_type_map); } else { char buffer[256];#ifdef VMS sprintf(buffer, "sys$login:%s", personal_type_map);#else sprintf(buffer, "%s/%s", (Home_Dir() ? Home_Dir() : ""), personal_type_map);#endif HTLoadTypesConfigFile(buffer); } /* * Put text/html and text/plain at beginning of list. - kw */ HTReorderPresentation(WWW_PLAINTEXT, WWW_PRESENT); HTReorderPresentation(WWW_HTML, WWW_PRESENT);}PUBLIC void HTPreparsedFormatInit NOARGS{ if (LYPreparsedSource) { HTSetConversion("text/html", "www/source", HTMLParsedPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/html", "www/dump", HTMLParsedPresent, 1.0, 0.0, 0.0, 0); }}/* Some of the following is taken from: *//*Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)Permission to use, copy, modify, and distribute this materialfor any purpose and without fee is hereby granted, providedthat the above copyright notice and this permission noticeappear in all copies, and that the name of Bellcore not beused in advertising or publicity pertaining to thismaterial without the specific, prior written permissionof an authorized representative of Bellcore. BELLCOREMAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITYOF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.*//****************************************************** Metamail -- A tool to help diverse mail readers cope with diverse multimedia mail formats. Author: Nathaniel S. Borenstein, Bellcore ******************************************************* */struct MailcapEntry { char *contenttype; char *command; char *testcommand; int needsterminal; int copiousoutput; int needtofree; char *label; char *printcommand; float quality; long int maxbytes;};PRIVATE int ExitWithError PARAMS((char *txt));PRIVATE int PassesTest PARAMS((struct MailcapEntry *mc));#define LINE_BUF_SIZE 2048#define TMPFILE_NAME_SIZE 256PRIVATE char *GetCommand ARGS2( char *, s, char **, t){ char *s2; int quoted = 0; /* marca -- added + 1 for error case -- oct 24, 1993. */ s2 = malloc(strlen(s)*2 + 1); /* absolute max, if all % signs */ if (!s2) ExitWithError("Out of memory"); *t = s2; while (s && *s) { if (quoted) { if (*s == '%') *s2++ = '%'; /* Quote through next level, ugh! */ *s2++ = *s++; quoted = 0; } else { if (*s == ';') { *s2 = '\0'; return(++s); } if (*s == '\\') { quoted = 1; ++s; } else { *s2++ = *s++; } } } *s2 = '\0'; return(NULL);}/* no leading or trailing space, all lower case */PRIVATE char *Cleanse ARGS1( char *, s){ char *tmp, *news; /* strip leading white space */ while (*s && isspace((unsigned char) *s)) ++s; news = s; /* put in lower case */ for (tmp=s; *tmp; ++tmp) { *tmp = TOLOWER ((unsigned char)*tmp); } /* strip trailing white space */ while ((tmp > news) && *--tmp && isspace((unsigned char) *tmp)) *tmp = '\0'; return(news);}PRIVATE int ProcessMailcapEntry ARGS2( FILE *, fp, struct MailcapEntry *, mc){ int i, j; size_t rawentryalloc = 2000, len; char *rawentry, *s, *t, *LineBuf; LineBuf = (char *)malloc(LINE_BUF_SIZE); if (!LineBuf) ExitWithError("Out of memory"); rawentry = (char *)malloc(1 + rawentryalloc); if (!rawentry) ExitWithError("Out of memory"); *rawentry = '\0'; while (fgets(LineBuf, LINE_BUF_SIZE, fp)) { if (LineBuf[0] == '#') continue; len = strlen(LineBuf); if (len == 0) continue; if (LineBuf[len-1] == '\n') LineBuf[--len] = '\0'; if ((len + strlen(rawentry)) > rawentryalloc) { rawentryalloc += 2000; rawentry = realloc(rawentry, rawentryalloc+1); if (!rawentry) ExitWithError("Out of memory"); } if (len > 0 && LineBuf[len-1] == '\\') { LineBuf[len-1] = '\0'; strcat(rawentry, LineBuf); } else { strcat(rawentry, LineBuf); break; } } FREE(LineBuf); for (s = rawentry; *s && isspace((unsigned char) *s); ++s) ; if (!*s) { /* totally blank entry -- quietly ignore */ FREE(rawentry); return(0); } s = strchr(rawentry, ';'); if (s == NULL) { if (TRACE) { fprintf(stderr, "ProcessMailcapEntry: Ignoring invalid mailcap entry: %s\n", rawentry); } FREE(rawentry); return(0); } *s++ = '\0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -