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

📄 htmlout.c

📁 将rft格式文件转换成html格式文件
💻 C
📖 第 1 页 / 共 3 页
字号:
			    	xval=mval;			    }			}		}		_RTFGetToken2();	}	csTop=savecsTop;}/* * This function "cheats" by using rtfMajor (raw input character) rather * than rtfMinor (corresponding standard character code).  This is based on * the assumption than the function won't see anything other than * '0'..'9' and that the result of mapping the standard codes for such chars * would be the same chars. */static voidPutHex(){	int mval;	if(rtfMajor <= '9'){		mval=rtfMajor-'0';	} else if(rtfMajor <= 'F'){		mval=rtfMajor-'A'+10;	} else {		mval=rtfMajor-'a'+10;	}     if (++charnum == 2) {    	xval=xval*16+mval;		fputc((char) xval, PictFile);		charnum = 0;    } else {    	xval=mval;    }}char zeros[512];/*	A placeable Windows metafile is a standard Windows metafile that has an 	additional 22-byte header. The header contains information about the aspect 	ratio and original size of the metafile, permitting applications to display 	the metafile in its intended form. The header for a placeable Windows metafile 	has the following form: typedef struct {    DWORD   key;    HANDLE  hmf;    RECT    bbox;    WORD    inch;    DWORD   reserved;    WORD    checksum;} METAFILEHEADER;NOTE: DWORD=4bytes, HANDLE=2,WORD=2,RECT=8.(Apparently the IBM does byte swapping?)Following are the members of a placeable metafile header: key			Specifies the binary key that uniquely identifies this file type. 			This member must be set to 0x9AC6CDD7L. hmf			Unused; must be zero. bbox		Specifies the coordinates of the smallest rectangle that encloses 			the picture. The coordinates are in metafile units as defined by the inch 			member. *** the first two points are fixed, the second two are			the height and width ***inch		Specifies the number of metafile units to the inch. To avoid numeric 			overflow, this value should be less than 1440. 			Most applications use 576 or 1000.  *** we use 1440 ***reserved	Unused; must be zero. checksum	Specifies the checksum. It is the sum (using the XOR operator) of the 			first 10 words of the header. */unsigned char wmfhead[22]={/* key = */ 0xd7,0xcd,0xc6,0x9a,/* hmf = */ 0,0,/* bbox = */ 0xfc,0xff,0xfc,0xff, /*width*/0,0,/*height*/0,0,/* inch = */ 0xa0,0x05,/* reserved = */ 0,0,0,0,/* checksum = */ 0,0};voidNabPicture(){    struct FDest *OD;    /*     * First create the reference to the picture, and then change the class     * callback so that the contents of the picture are written to a file. If     * we are already gathering a link, or the -i option was specified,     * change the format of the link to IMG.     */    char filename[256];    char rfilename[256];    char reftext[512];#ifdef NOTDEF    if(inTable){		RTFMsg ("Error, Graphics not allowed in tables - skipping\n");		context();    	RTFSkipGroup ();		PopIState();		return;    }#endif    sprintf(filename, "%s%d.%s", FPrefix, ++outfuniq, PictExt);    sprintf(rfilename, "%s%d.%s", FPrefixR, outfuniq, PFileExt);    /* find the previous destination */    if (ISS == NULL) {		RTFMsg ("Error, State Stack is null\n");	    context();	exit(1);    }    switch (ISS->destination) {	/* string destinations */    case rtfFootnote:	OD = &Footnote;	break;    default:	OD = &File1;	break;    }    if(PNText){	/* We have saved ParNumText */    	PNText=0;    	PlayST(&PNSave);    }    if(FNText==1){	    	FNText=2;	    	PlayST(&FNSave);	    	FNText=0;    }    if(inTable){	    sprintf(LineBuffer,"<IMG SRC=\"%s\">", rfilename);		AppendText(&(cell[cellno].cbuff), LineBuffer);	}else {	    if (IStyle_Chg)	TestStyle(OD);	    if (OD->TSpecial == MTDiscard){			RTFSkipGroup ();			PopIState();			return;	    }	    if (IMG || OD->TSpecial == MTHot) {	    	sprintf(LineBuffer,"<IMG SRC=\"%s\">", rfilename);	    } else {		    sprintf(LineBuffer,"<A href=\"%s\">Click here for Picture </A>", rfilename);	    }	    if (OD->NeedPar) {			DoPmark(OD);			OD->NeedPar = 0;	    }	    putwrap(LineBuffer,OD,0);	}	if(WriteGraf){		    PictFile = OpenOutputFile(filename, "wb",PictType);	    if (PictFile == NULL) {			RTFPanic ("Open of %s Failed", filename);	    }	    if (PictType == FTPICT) {		fwrite(zeros, 512, 1, PictFile);   		} else if (PictType == FTWMF ) {   			int i;   			/* write a WMF header for a placeable Windows Metafile. */   			/* Calculate Width and Heigth of bounding box */   			wmfhead[10]=(PicGoalWid-4)%256;   			wmfhead[11]=(PicGoalWid-4)/256;   			wmfhead[12]=(PicGoalHt-4)%256;   			wmfhead[13]=(PicGoalHt-4)/256;   			/* compute Checksum */   			wmfhead[20]=0;   			wmfhead[21]=0;   			for(i=0;i<20;i+=2){   				wmfhead[20]^=wmfhead[i];   				wmfhead[21]^=wmfhead[i+1];   				}   			fwrite(wmfhead,22,1,PictFile);   		}   		ReadPict();   		RTFSetClassCallback (rtfText, PutHTML);   		PopIState();    } else {		RTFSkipGroup ();		PictFile=NULL;		PopIState();    }}static voidTestStyle(OD)    struct FDest *OD;{/*	Change the style of the output text to the new style.	If the style changes, force correct nesting of HTML tags.*/    int PMidx, i, j,k;    int OldPMidx;    int OldTSpecial = OD->TSpecial;	if (!InBody) {	    /*	     * If we get here, we have text destined for the body. close out	     * the head section.	     */	    if (Title.used) {		sprintf(LineBuffer,"<title>%s</title>", Title.ptr);		putwrap(LineBuffer, &File1,1);	    }	    putwrap("</head><body>", &File1,1);	    InBody = 1;	}	    if(OD->HPTags<0)    	OldPMidx = -1;    else    	OldPMidx = OD->TStack[OD->HPTags];    /* Look for Special Text Style Matches - these override normal processing */    IStyle_Chg = 0;    OD->TSpecial = 0;            /* Find a match on the new paragraph and text styles */    PMidx = PMatchLen;		/* to catch a null ParStyle */    for(k=0;ParStyle[k]!='\0';k+=i){/* for each alias in ParStyle */    	/* find the size of the ParStyle alias */    	for(i=0;ParStyle[k+i]!='\0'&&ParStyle[k+i]!=',';i++);	    for (PMidx = 0; PMidx < PMatchLen; PMidx++) {			if (strncmp(PMatchArr[PMidx].PStyle, ParStyle,i) == 0) {			    break;		    }		}		if (PMidx != PMatchLen)break;	}    if (PMidx == PMatchLen){		PMidx = 0;		/* The first entry is the default */		if(strcmp(ParStyle,"")!=0){			for(i=0;i<256&&badstyles[i]!=NULL;i++) /* Save off mismatches */				if(strcmp(badstyles[i],ParStyle)==0)					break;			if(i<256&&badstyles[i]==NULL){				badstyles[i]=ParStyle;				RTFMsg ("Unknown Paragraph style: %s\n",ParStyle);			}		}	}            	if(PMatchArr[PMidx].PTidx>MTSPECIAL&&    	(PMatchArr[PMidx].PTidx != MTHref || OD != &Footnote)){    	OD->TSpecial=PMatchArr[PMidx].PTidx;    } else {	    for (i = 0; i < TMatchLen; i++) {			if ((TMatchArr[i].TStyle == (TMatchArr[i].TMask & TStyle)) &&			    (TMatchArr[i].Font[0] == '\0' || strcmp(TMatchArr[i].Font, TFont) == 0) &&			    (TMatchArr[i].FSize == 0 || TMatchArr[i].FSize == TSize)) {			    /* can't have hot text in footnote */			    if (TMatchArr[i].TTidx == MTHref && OD == &Footnote)					continue;			    if (TMatchArr[i].TTidx > MTSPECIAL) {					OD->TSpecial = TMatchArr[i].TTidx;					break;			    }			}	    }    }    if (inTable){ /* force specials off */    	OD->TSpecial=0;    	ParStyle="_Table";    }	if (FNMatch.TStyle == (TStyle) &&	    strcmp(FNMatch.Font, TFont) == 0 &&	     FNMatch.FSize == TSize) {			OD->TSpecial = MTFootNote;	}    if (OldTSpecial != OD->TSpecial) {	    switch(OldTSpecial){	    case MTName:		    putwrap("\"> </a>", OD,0);			OD->wrap=PTagArr[OD->PTidx].DoFold;	    	break;	    case MTHref:		    putwrap("\">", OD,0);		    if(OD->TSpecial!=MTHot){		    	RTFMsg ("Error, at end of href, hot text not found\n");	    		context();	    		putwrap("</a>", OD,0);		    }			OD->wrap=PTagArr[OD->PTidx].DoFold;	    	break;	    case MTHot:			putwrap("</a>",OD,OD->wrap);	    	break;	    case MTFootNote:			if (OD == &File1) {				putwrap("]</a>", OD,OD->wrap);				FNMatch.Font= "NotAFont";			} else {				putwrap("]</a>",OD,OD->wrap);			}	    	break;	    }    }	if (OD->TSpecial != 0){  		if (OldTSpecial != OD->TSpecial) {			while (OD->HTTags > OD->HPTags) {			    putwrap(TTagArr[TMatchArr[OD->TStack[OD->HTTags]].TTidx].EndTag,				OD,OD->wrap);			    OD->HTTags--;			}		    switch(OD->TSpecial){		    case MTName:		    	if (OD->NeedPar) {					putwrap(PTagArr[OD->PTidx].ParTag, OD,OD->wrap);					OD->NeedPar = 0;		   		}				putwrap("<a name=\"", OD,0);				OD->wrap=0;		   		break;		    case MTHref:		    	if (OD->NeedPar) {					putwrap(PTagArr[OD->PTidx].ParTag, OD,OD->wrap);					OD->NeedPar = 0;		   		}				putwrap("<a href=\"", OD,0);				OD->wrap=0;		   		break;		    case MTHot:			    if(OldTSpecial!=MTHref){			    	RTFMsg ("Error, hot text found without preceding href\n");	   				context();		  						    }		    					break;		    case MTFootNote:				if (OD->NeedPar) {					putwrap(PTagArr[OD->PTidx].ParTag, OD,OD->wrap);					OD->NeedPar = 0;				}				if (OD == &File1) {					anyfoot=1;					sprintf(LineBuffer,"<a href=\"%s_fn.html#fn%d\">[", FPrefixR,uniqnum);					putwrap(LineBuffer,OD,OD->wrap);				} else {					sprintf(LineBuffer,"<a name=\"fn%d\">[", uniqnum++);					putwrap(LineBuffer,OD,OD->wrap);				}				break;		    }		}		return;	}    OD->PTidx = PMatchArr[PMidx].PTidx;    if (PMidx != OldPMidx) { /* Paragraph Style changed */    	int pushpop=0;		/* Pop all of the Text Styles */		while (OD->HTTags > OD->HPTags) {		    putwrap(TTagArr[TMatchArr[OD->TStack[OD->HTTags]].TTidx].EndTag,			OD,OD->wrap);		    OD->HTTags--;		}		if (PMatchArr[PMidx].NestLev > OD->HPTags + 1) {		    RTFMsg ("Error, found style:%s at a nesting level of %d\n"			,ParStyle, OD->HPTags);		    context();		}		while (OD->HPTags >= PMatchArr[PMidx].NestLev) {		    /* Pop Paragraph Tags  */		    if(OD->TStack[OD->HPTags] == PMidx){		    	pushpop=1;		    	break;		    } else {			    if (strcmp(PTagArr[PMatchArr[OD->TStack[OD->HPTags]].PTidx].EndTag, "") != 0			    && strcmp(PTagArr[OD->PTidx].StartTag, "") == 0) {				/* if there was a closing tag, we no longer need a paragraph */				OD->NeedPar = 0;			    }			    putwrap(PTagArr[PMatchArr[OD->TStack[OD->HPTags]].PTidx].EndTag, OD,			    PTagArr[PMatchArr[OD->TStack[OD->HPTags]].PTidx].DoFold);			    OD->HPTags--;			}		}		if(!pushpop){			if(OD->HPTags >= 0&&!PTagArr[PMatchArr[OD->TStack[OD->HPTags]].PTidx].CanNest) {			    /* Nesting Error */			    RTFMsg ("Error, can't use style:%s within %s\n",				ParStyle,				PMatchArr[OD->TStack[OD->HPTags]].PStyle);			    context();			}			/* Now push the new style */			OD->HPTags++;			OD->TStack[OD->HPTags] = PMidx;			if (strcmp(PTagArr[OD->PTidx].StartTag, "") != 0) {			    /* if there is a Starting tag, we no longer need a paragraph */			    putwrap(PTagArr[OD->PTidx].StartTag, OD,PTagArr[OD->PTidx].DoFold);			    OD->NeedPar = 0;			}		}		OD->HTTags = OD->HPTags;  		OD->wrap=PTagArr[OD->PTidx].DoFold;	}    if (OD->NeedPar) {		DoPmark(OD);		OD->NeedPar = 0;    }  	if(ToCLev==0){			 HToCLev=PTagArr[PMatchArr[PMidx].PTidx].ToCLev;		} else {			 HToCLev=ToCLev;		}    /* Check remaining Text Styles to see if they should be popped */    for (i = OD->HPTags + 1; i <= OD->HTTags; i++) {	if ((TMatchArr[OD->TStack[i]].TStyle != (TMatchArr[OD->TStack[i]].TMask & TStyle)) ||	    (TMatchArr[OD->TStack[i]].Font[0] != '\0' && strcmp(TMatchArr[OD->TStack[i]].Font, TFont) != 0) ||	    (TMatchArr[OD->TStack[i]].FSize != 0 && TMatchArr[OD->TStack[i]].FSize != TSize)) {	    while (OD->HTTags >= i) {		putwrap(TTagArr[TMatchArr[OD->TStack[OD->HTTags]].TTidx].EndTag,		    OD,OD->wrap);		OD->HTTags--;	    }	}    }    /* Now check all Text Styles and see if anything else must be pushed */    if (PTagArr[PMatchArr[OD->TStack[OD->HPTags]].PTidx].AllowText) {	for (i = 0; i < TMatchLen; i++) {	    if ((TMatchArr[i].TStyle == (TMatchArr[i].TMask & TStyle)) &&		(TMatchArr[i].Font[0] == '\0' || strcmp(TMatchArr[i].Font, TFont) == 0) &&		(TMatchArr[i].FSize == 0 || TMatchArr[i].FSize == TSize)) {		for (j = OD->HPTags + 1; j <= OD->HTTags; j++) {		    if (TMatchArr[OD->TStack[j]].TTidx == TMatchArr[i].TTidx)			break;		}		if (j > OD->HTTags) {		    /* didn't find it - push it on */		    OD->HTTags++;

⌨️ 快捷键说明

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