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

📄 out2window.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
			case LIST_LOWER_ALPHA:				pcTxt += tNumber2Alpha(					auiHdrCounter[tIndex],					ucNFC == LIST_UPPER_ALPHA,					pcTxt);				break;			case LIST_OUTLINE_NUM:				pcTxt += sprintf(pcTxt, "%02u",					auiHdrCounter[tIndex]);				break;			default:				DBG_DEC(ucNFC);				DBG_FIXME();				pcTxt += sprintf(pcTxt, "%u",					auiHdrCounter[tIndex]);				break;			}			if (tIndex < tStyleIndex) {				*pcTxt++ = '.';			} else if (tIndex == tStyleIndex) {				*pcTxt++ = ' ';			}		}	}	*pcTxt = '\0';	NO_DBG_MSG_C((int)pStyle->usIstd >= 1 &&		(int)pStyle->usIstd <= 9 &&		eNumType != level_type_none &&		eNumType != level_type_outline, szLine);	NO_DBG_MSG_C(szLine[0] != '\0', szLine);	fail(pcTxt < szLine);	return (size_t)(pcTxt - szLine);} /* end of tStyle2Window *//* * vRemoveRowEnd - remove the end of table row indicator * * Remove the double TABLE_SEPARATOR characters from the end of the string. * Special: remove the TABLE_SEPARATOR, 0x0a sequence */static voidvRemoveRowEnd(char *szRowTxt){	int	iLastIndex;	TRACE_MSG("vRemoveRowEnd");	fail(szRowTxt == NULL || szRowTxt[0] == '\0');	iLastIndex = (int)strlen(szRowTxt) - 1;	if (szRowTxt[iLastIndex] == TABLE_SEPARATOR ||	    szRowTxt[iLastIndex] == (char)0x0a) {		szRowTxt[iLastIndex] = '\0';		iLastIndex--;	} else {		DBG_HEX(szRowTxt[iLastIndex]);	}	if (iLastIndex >= 0 && szRowTxt[iLastIndex] == (char)0x0a) {		szRowTxt[iLastIndex] = '\0';		iLastIndex--;	}	if (iLastIndex >= 0 && szRowTxt[iLastIndex] == TABLE_SEPARATOR) {		szRowTxt[iLastIndex] = '\0';		return;	}	DBG_DEC(iLastIndex);	DBG_HEX(szRowTxt[iLastIndex]);	DBG_MSG(szRowTxt);} /* end of vRemoveRowEnd *//* * tComputeStringLengthMax - max string length in relation to max column width * * Return the maximum string length */static size_ttComputeStringLengthMax(const char *szString, size_t tColumnWidthMax){	const char	*pcTmp;	size_t	tLengthMax, tLenPrev, tLen, tWidth;	TRACE_MSG("tComputeStringLengthMax");	fail(szString == NULL);	fail(tColumnWidthMax == 0);	pcTmp = strchr(szString, '\n');	if (pcTmp != NULL) {		tLengthMax = (size_t)(pcTmp - szString + 1);	} else {		tLengthMax = strlen(szString);	}	if (tLengthMax == 0) {		return 0;	}	tLen = 0;	tWidth = 0;	for (;;) {		tLenPrev = tLen;		tLen += tGetCharacterLength(szString + tLen);		DBG_DEC_C(tLen > tLengthMax, tLen);		DBG_DEC_C(tLen > tLengthMax, tLengthMax);		fail(tLen > tLengthMax);		tWidth = tCountColumns(szString, tLen);		if (tWidth > tColumnWidthMax) {			return tLenPrev;		}		if (tLen >= tLengthMax) {			return tLengthMax;		}	}} /* end of tComputeStringLengthMax *//* * tGetBreakingPoint - get the number of bytes that fit the column * * Returns the number of bytes that fit the column */static size_ttGetBreakingPoint(const char *szString,	size_t tLen, size_t tWidth, size_t tColumnWidthMax){	int	iIndex;	TRACE_MSG("tGetBreakingPoint");	fail(szString == NULL);	fail(tLen > strlen(szString));	fail(tWidth > tColumnWidthMax);	if (tWidth < tColumnWidthMax ||	    (tWidth == tColumnWidthMax &&	     (szString[tLen] == ' ' ||	      szString[tLen] == '\n' ||	      szString[tLen] == '\0'))) {		/* The string already fits, do nothing */		return tLen;	}	/* Search for a breaking point */	for (iIndex = (int)tLen - 1; iIndex >= 0; iIndex--) {		if (szString[iIndex] == ' ') {			return (size_t)iIndex;		}	}	/* No breaking point found, just fill the column */	return tLen;} /* end of tGetBreakingPoint *//* * tComputeColumnWidthMax - compute the maximum column width */static size_ttComputeColumnWidthMax(short sWidth, long lCharWidth, double dFactor){	size_t	tColumnWidthMax;	TRACE_MSG("tComputeColumnWidthMax");	fail(sWidth < 0);	fail(lCharWidth <= 0);	fail(dFactor <= 0.0);	tColumnWidthMax = (size_t)(		(lTwips2MilliPoints(sWidth) * dFactor + lCharWidth / 2.0) /		 lCharWidth);	if (tColumnWidthMax == 0) {		/* Minimum column width */		return 1;	}	if (tColumnWidthMax > 1) {		/* Make room for the TABLE_SEPARATOR_CHAR */		tColumnWidthMax--;	}	NO_DBG_DEC(tColumnWidthMax);	return tColumnWidthMax;} /* end of tComputeColumnWidthMax *//* * vTableRow2Window - put a table row into a diagram */voidvTableRow2Window(diagram_type *pDiag, output_type *pOutput,	const row_block_type *pRowInfo,	conversion_type eConversionType, int iParagraphBreak){	output_type	tRow;	char	*aszColTxt[TABLE_COLUMN_MAX];	char	*szLine, *pcTxt;	double	dMagnify;	long	lCharWidthLarge, lCharWidthSmall;	size_t	tColumnWidthTotal, atColumnWidthMax[TABLE_COLUMN_MAX];	size_t	tSize, tColumnWidthMax, tWidth, tLen;	int	iIndex, iNbrOfColumns, iTmp;	BOOL	bNotReady;	TRACE_MSG("vTableRow2Window");	fail(pDiag == NULL || pOutput == NULL || pRowInfo == NULL);	fail(pOutput->szStorage == NULL);	fail(pOutput->pNext != NULL);	fail(iParagraphBreak < 0);	/* Character sizes */	lCharWidthLarge = lComputeStringWidth("W", 1,				pOutput->tFontRef, pOutput->usFontSize);	NO_DBG_DEC(lCharWidthLarge);	lCharWidthSmall = lComputeStringWidth("i", 1,				pOutput->tFontRef, pOutput->usFontSize);	NO_DBG_DEC(lCharWidthSmall);	/* For the time being: use a fixed width font */	fail(lCharWidthLarge != lCharWidthSmall);	vRemoveRowEnd(pOutput->szStorage);	/* Split the row text into a set of column texts */	aszColTxt[0] = pOutput->szStorage;	for (iNbrOfColumns = 1;	     iNbrOfColumns < TABLE_COLUMN_MAX;	     iNbrOfColumns++) {		aszColTxt[iNbrOfColumns] =				strchr(aszColTxt[iNbrOfColumns - 1],					TABLE_SEPARATOR);		if (aszColTxt[iNbrOfColumns] == NULL) {			break;		}		*aszColTxt[iNbrOfColumns] = '\0';		aszColTxt[iNbrOfColumns]++;		NO_DBG_DEC(iNbrOfColumns);		NO_DBG_MSG(aszColTxt[iNbrOfColumns]);	}	/* Work around a bug in Word */	while (iNbrOfColumns > (int)pRowInfo->ucNumberOfColumns &&	       pRowInfo->asColumnWidth[iNbrOfColumns] == 0) {		iNbrOfColumns--;	}	DBG_DEC_C(iNbrOfColumns != (int)pRowInfo->ucNumberOfColumns,		iNbrOfColumns);	DBG_DEC_C(iNbrOfColumns != (int)pRowInfo->ucNumberOfColumns,		pRowInfo->ucNumberOfColumns);	if (iNbrOfColumns != (int)pRowInfo->ucNumberOfColumns) {		werr(0, "Skipping an unmatched table row");		return;	}#if defined(__FULL_TEXT_SEARCH)	/* No table formatting: use for full-text search (untested) */	for (iIndex = 0; iIndex < iNbrOfColumns; iIndex++) {		fprintf(pDiag->pOutFile, "%s\n" , aszColTxt[iIndex]);	}#else	if (bAddTableRow(pDiag, aszColTxt, iNbrOfColumns,			pRowInfo->asColumnWidth, pRowInfo->ucBorderInfo)) {		/* All work has been done */		return;	}	/* Fill the table with maximum column widths */	if (eConversionType == conversion_text ||	    eConversionType == conversion_fmt_text) {		if (iParagraphBreak == 0 ||		    iParagraphBreak >= MAX_SCREEN_WIDTH) {			dMagnify = (double)MAX_SCREEN_WIDTH;		} else if (iParagraphBreak <= MIN_SCREEN_WIDTH) {			dMagnify = (double)MIN_SCREEN_WIDTH;		} else {			dMagnify = (double)iParagraphBreak;		}		dMagnify /= (double)DEFAULT_SCREEN_WIDTH;		DBG_FLT_C(dMagnify < 0.99 || dMagnify > 1.01, dMagnify);	} else {		dMagnify = 1.0;	}	tColumnWidthTotal = 0;	for (iIndex = 0; iIndex < iNbrOfColumns; iIndex++) {		atColumnWidthMax[iIndex] = tComputeColumnWidthMax(					pRowInfo->asColumnWidth[iIndex],					lCharWidthLarge,					dMagnify);		tColumnWidthTotal += atColumnWidthMax[iIndex];	}	/*	 * Get enough space for the row.	 * Worst case: three bytes per UTF-8 character	 */	tSize = 3 * (1 + tColumnWidthTotal + (size_t)iNbrOfColumns + 3);	szLine = xmalloc(tSize);	do {		/* Print one line of a table row */		bNotReady = FALSE;		pcTxt = szLine;		*pcTxt++ = TABLE_SEPARATOR_CHAR;		for (iIndex = 0; iIndex < iNbrOfColumns; iIndex++) {			tColumnWidthMax = atColumnWidthMax[iIndex];			if (aszColTxt[iIndex] == NULL) {				/* Add an empty column */				for (iTmp = 0;				     iTmp < (int)tColumnWidthMax;				     iTmp++) {					*pcTxt++ = (char)FILLER_CHAR;				}				*pcTxt++ = TABLE_SEPARATOR_CHAR;				*pcTxt = '\0';				continue;			}			/* Compute the length and width of the column text */			tLen = tComputeStringLengthMax(					aszColTxt[iIndex], tColumnWidthMax);			NO_DBG_DEC(tLen);			while (tLen != 0 &&					(aszColTxt[iIndex][tLen - 1] == '\n' ||					 aszColTxt[iIndex][tLen - 1] == ' ')) {				aszColTxt[iIndex][tLen - 1] = ' ';				tLen--;			}			tWidth = tCountColumns(aszColTxt[iIndex], tLen);			fail(tWidth > tColumnWidthMax);			tLen = tGetBreakingPoint(aszColTxt[iIndex],					tLen, tWidth, tColumnWidthMax);			tWidth = tCountColumns(aszColTxt[iIndex], tLen);			if (tLen == 0 && *aszColTxt[iIndex] == '\0') {				/* No text at all */				aszColTxt[iIndex] = NULL;			} else {				/* Add the text */				pcTxt += sprintf(pcTxt,					"%.*s", (int)tLen, aszColTxt[iIndex]);				if (tLen == 0 && *aszColTxt[iIndex] != ' ') {					tLen = tGetCharacterLength(							aszColTxt[iIndex]);					DBG_CHR(*aszColTxt[iIndex]);					DBG_FIXME();					fail(tLen == 0);				}				aszColTxt[iIndex] += tLen;				while (*aszColTxt[iIndex] == ' ') {					aszColTxt[iIndex]++;				}				if (*aszColTxt[iIndex] == '\0') {					/* This row is now complete */					aszColTxt[iIndex] = NULL;				} else {					/* This row needs more lines */					bNotReady = TRUE;				}			}			/* Fill up the rest */			for (iTmp = 0;			     iTmp < (int)tColumnWidthMax - (int)tWidth;			     iTmp++) {				*pcTxt++ = (char)FILLER_CHAR;			}			/* End of column */			*pcTxt++ = TABLE_SEPARATOR_CHAR;			*pcTxt = '\0';		}		/* Output the table row line */		*pcTxt = '\0';		tRow = *pOutput;		tRow.szStorage = szLine;		fail(pcTxt < szLine);		tRow.tNextFree = (size_t)(pcTxt - szLine);		tRow.lStringWidth = lComputeStringWidth(					tRow.szStorage,					tRow.tNextFree,					tRow.tFontRef,					tRow.usFontSize);		vString2Diagram(pDiag, &tRow);		TRACE_MSG("after vString2Diagram in vTableRow2Window");	} while (bNotReady);	/* Clean up before you leave */	szLine = xfree(szLine);	TRACE_MSG("leaving vTableRow2Window");#endif /* __FULL_TEXT_SEARCH */} /* end of vTableRow2Window */

⌨️ 快捷键说明

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