⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htinit.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (!strncasecomp(rawentry, "text/html", 9) ||	!strncasecomp(rawentry, "text/plain", 10)) {	--s;	*s = ';';	if (TRACE) {		fprintf(stderr,			"ProcessMailcapEntry: Ignoring mailcap entry: %s\n",			rawentry);	}	FREE(rawentry);	return(0);    }    for (i = 0, j = 0; rawentry[i]; i++) {	if (rawentry[i] != ' ') {	    rawentry[j++] = TOLOWER(rawentry[i]);	}    }    rawentry[j] = '\0';    mc->needsterminal = 0;    mc->copiousoutput = 0;    mc->needtofree = 1;    mc->testcommand = NULL;    mc->label = NULL;    mc->printcommand = NULL;    mc->contenttype = (char *)malloc(1 + strlen(rawentry));    if (!mc->contenttype)	ExitWithError("Out of memory");    strcpy(mc->contenttype, rawentry);    mc->quality = 1.0;    mc->maxbytes = 0;    t = GetCommand(s, &mc->command);    if (!t) {	goto assign_presentation;    }    s = t;    while (s && *s && isspace((unsigned char) *s)) ++s;    while (s) {	char *arg, *eq, *mallocd_string;	t = GetCommand(s, &mallocd_string);	arg = mallocd_string;	eq = strchr(arg, '=');	if (eq) {	    *eq++ = '\0';	}	if (arg && *arg) {	    arg = Cleanse(arg);	    if (!strcmp(arg, "needsterminal")) {		mc->needsterminal = 1;	    } else if (!strcmp(arg, "copiousoutput")) {		mc->copiousoutput = 1;	    } else if (eq && !strcmp(arg, "test")) {		mc->testcommand = NULL;		StrAllocCopy(mc->testcommand, eq);		if (TRACE)		    fprintf(stderr,		    	    "ProcessMailcapEntry: Found testcommand:%s\n",			    mc->testcommand);	    } else if (eq && !strcmp(arg, "description")) {		mc->label = eq;	    } else if (eq && !strcmp(arg, "label")) {		mc->label = eq; /* bogus old name for description */	    } else if (eq && !strcmp(arg, "print")) {		mc->printcommand = eq;	    } else if (eq && !strcmp(arg, "textualnewlines")) {		/* no support for now.  What does this do anyways? */		/* ExceptionalNewline(mc->contenttype, atoi(eq)); */	    } else if (eq && !strcmp(arg, "q")) {	        mc->quality = atof(eq);		if (mc->quality > 0.000 && mc->quality < 0.001)		    mc->quality = 0.001;	    } else if (eq && !strcmp(arg, "mxb")) {	        mc->maxbytes = atol(eq);		if (mc->maxbytes < 0)		    mc->maxbytes = 0;	    } else if (strcmp(arg, "notes")) { /* IGNORE notes field */		if (*arg && TRACE)		    fprintf(stderr,			"ProcessMailcapEntry: Ignoring mailcap flag '%s'.\n",			    arg);	    }	}      FREE(mallocd_string);      s = t;    }assign_presentation:    FREE(rawentry);    if (PassesTest(mc)) {	if (TRACE)	    fprintf(stderr,	    	    "ProcessMailcapEntry Setting up conversion %s : %s\n",		    mc->contenttype, mc->command);	HTSetPresentation(mc->contenttype, mc->command,			  mc->quality, 3.0, 0.0, mc->maxbytes);    }    FREE(mc->command);    FREE(mc->contenttype);    return(1);}PRIVATE void BuildCommand ARGS5(	char **, 	pBuf,	size_t,		Bufsize,	char *,		controlstring,	char *,		TmpFileName,	size_t,		TmpFileLen){    char *from, *to;    int prefixed = 0;    for (from = controlstring, to = *pBuf; *from != '\0'; from++) {	if (prefixed) {	    prefixed = 0;	    switch(*from) {		case '%':		    *to++ = '%';		    break;		case 'n':		case 'F':		    if (TRACE) {		        fprintf(stderr,			     "BuildCommand: Bad mailcap \"test\" clause: %s\n",				controlstring);		    }		case 's':		    if (TmpFileLen && TmpFileName) {			if ((to - *pBuf) + TmpFileLen + 1 > Bufsize) {			    *to = '\0';			    if (TRACE) {				fprintf(stderr,			"BuildCommand: Too long mailcap \"test\" clause,\n");				fprintf(stderr,					"              ignoring: %s%s...\n",					*pBuf, TmpFileName);			    }			    **pBuf = '\0';			    return;			}			strcpy(to, TmpFileName);			to += strlen(TmpFileName);		    }		    break;		default:		    if (TRACE) {			fprintf(stderr,  "BuildCommand: Ignoring unrecognized format code in mailcap file '%%%c'.\n",			*from);		    }		    break;	    }	} else if (*from == '%') {	    prefixed = 1;	} else {	    *to++ = *from;	}	if (to >= *pBuf + Bufsize) {	    (*pBuf)[Bufsize - 1] = '\0';	    if (TRACE) {		fprintf(stderr,			"BuildCommand: Too long mailcap \"test\" clause,\n");		fprintf(stderr,			"              ignoring: %s...\n",			*pBuf);	    }	    **pBuf = '\0';	    return;	}    }    *to = '\0';}PRIVATE int PassesTest ARGS1(	struct MailcapEntry *,	mc){    int result;    char *cmd, TmpFileName[TMPFILE_NAME_SIZE];    char *cp = NULL;    /*     *  Make sure we have a command     */    if (!mc->testcommand)	return(1);    /*     *  Save overhead of system() calls by faking these. - FM     */    if (0 == strcasecomp(mc->testcommand, "test -n \"$DISPLAY\"")) {	FREE(mc->testcommand);	if (TRACE)	    fprintf(stderr,		    "PassesTest: Testing for XWINDOWS environment.\n");    	if ((cp = getenv(DISPLAY)) != NULL && *cp != '\0') {	    if (TRACE)	        fprintf(stderr,"PassesTest: Test passed!\n");	    return(0 == 0);	} else {	    if (TRACE)	        fprintf(stderr,"PassesTest: Test failed!\n");	    return(-1 == 0);	}    }    if (0 == strcasecomp(mc->testcommand, "test -z \"$DISPLAY\"")) {	FREE(mc->testcommand);	if (TRACE)	    fprintf(stderr,		    "PassesTest: Testing for NON_XWINDOWS environment.\n");    	if (!((cp = getenv(DISPLAY)) != NULL && *cp != '\0')) {	    if (TRACE)	        fprintf(stderr,"PassesTest: Test passed!\n");	    return(0 == 0);	} else {	    if (TRACE)	        fprintf(stderr,"PassesTest: Test failed!\n");	    return(-1 == 0);	}    }    /*     *  Why do anything but return success for this one! - FM     */    if (0 == strcasecomp(mc->testcommand, "test -n \"$LYNX_VERSION\"")){	FREE(mc->testcommand);	if (TRACE) {	    fprintf(stderr,		    "PassesTest: Testing for LYNX environment.\n");	    fprintf(stderr,"PassesTest: Test passed!\n");	}	return(0 == 0);    } else    /*     *  ... or failure for this one! - FM     */    if (0 == strcasecomp(mc->testcommand, "test -z \"$LYNX_VERSION\"")) {	FREE(mc->testcommand);	if (TRACE) {	    fprintf(stderr,		    "PassesTest: Testing for non-LYNX environment.\n");	    fprintf(stderr,"PassesTest: Test failed!\n");	}	return(-1 == 0);    }    /*     *  Build the command and execute it.     */    tempname(TmpFileName, NEW_FILE);    cmd = (char *)malloc(1024);    if (!cmd)	ExitWithError("Out of memory");    BuildCommand(&cmd, 1024,		 mc->testcommand,		 TmpFileName,		 strlen(TmpFileName));    if (TRACE)	fprintf(stderr,"PassesTest: Executing test command: %s\n", cmd);    result = system(cmd);    FREE(cmd);    /*     *  Free the test command as well since     *  we wont be needing it anymore.     */    FREE(mc->testcommand);    if (TRACE && result)	fprintf(stderr,"PassesTest: Test failed!\n");    else if (TRACE)	fprintf(stderr,"PassesTest: Test passed!\n");    return(result == 0);}PRIVATE int ProcessMailcapFile ARGS1(	char *,		file){    struct MailcapEntry mc;    FILE *fp;    if (TRACE)	fprintf(stderr,		"ProcessMailcapFile: Loading file '%s'.\n",		file);    if ((fp = fopen(file, "r")) == NULL) {	if (TRACE)	    fprintf(stderr,		"ProcessMailcapFile: Could not open '%s'.\n",		    file);	return(-1 == 0);    }    while (fp && !feof(fp)) {	ProcessMailcapEntry(fp, &mc);    }    fclose(fp);    return(0 == 0);}PRIVATE int ExitWithError ARGS1(	char *,		txt){    if (txt)	fprintf(stderr, "metamail: %s\n", txt);#ifndef NOSIGHUP    (void) signal(SIGHUP, SIG_DFL);#endif /* NOSIGHUP */    (void) signal(SIGTERM, SIG_DFL);#ifndef VMS    (void) signal(SIGINT, SIG_DFL);#endif /* !VMS */#ifdef SIGTSTP    if (no_suspend)	(void) signal(SIGTSTP,SIG_DFL);#endif /* SIGTSTP */    exit(-1);    return(-1);}PRIVATE int HTLoadTypesConfigFile ARGS1(	char *,		fn){  return ProcessMailcapFile(fn);}/* ------------------------------------------------------------------------ *//* ------------------------------------------------------------------------ *//* ------------------------------------------------------------------------ *//*	Define a basic set of suffixes**	------------------------------****	The LAST suffix for a type is that used for temporary files**	of that type.**	The quality is an apriori bias as to whether the file should be**	used.  Not that different suffixes can be used to represent files**	which are of the same format but are originals or regenerated,**	with different values.*/PUBLIC void HTFileInit NOARGS{    FILE *fp;    if (TRACE)	fprintf(stderr,		"HTFileInit: Loading default (HTInit) extension maps.\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -