📄 msdsys.c
字号:
WORD wLength; /* Length of pszString2 */
WORD wAdjust; /* Amount to adjust for displayed vs. actual length */
wLength = Qstrlen (qszString2);
wAdjust = wLength - DisplayLen (qszString2);
if (wIndent - wAdjust > wLength)
{
wIndent = wIndent - wLength - wAdjust;
Qmemset (qszString1, ' ', wIndent);
}
else
wIndent = 0;
return (Qstrncpy (&qszString1[wIndent], qszString2, wNmbrChars));
}
/*********************************************************************
* PrepNextString - Sets the current string to end after the last
* blank character, and sets the next string pointer
* to just beyond the end of the current string.
*
* pqszStrings - Array of strings.
* i - Current string in array of string pointers.
*
* Returns: Pointer to qszString1.
*********************************************************************/
QSZ PrepNextString (QSZ *pqszStrings, WORD i)
{
QSZ qszString = NULL; /* Single string pointer */
/* Look back to find the last non-blank character */
qszString = pqszStrings[i] + Qstrlen (pqszStrings[i]) - 1;
while (*qszString == ' ')
--qszString;
/* Set the correct string length */
*(++qszString) = '\0';
/* Set the pointer for the next string */
pqszStrings[i + 1] = ++qszString;
return (qszString);
}
/*********************************************************************
* ShowError - Displays an error message in an appropriate manner.
*
* fFlags - Flag for determining which buttons to display
* pszString1 - Strings to display in the error window/message
* pszString2 - "
* pszString3 - "
*
* Global: References fReportOnly to determine how to display the
* error message.
*********************************************************************/
VOID ShowError (BOOL fFlags,
PSZ pszString1,
PSZ pszString2,
PSZ pszString3)
{
WORD wLength; /* Length of each string */
wLength = strlen (pszString1) - 1;
if (pszString1[wLength] == '\n')
pszString1[wLength] = '\0';
wLength = strlen (pszString2) - 1;
if (pszString2[wLength] == '\n')
pszString2[wLength] = '\0';
wLength = strlen (pszString3) - 1;
if (pszString3[wLength] == '\n')
pszString3[wLength] = '\0';
/* Check to see if the /F paramter was used */
if (fReportOnly || !fCwIsReady)
{
PutString (NULL);
PutString (pszString1);
if (pszString2[0])
{
PutString (pszString2);
if (pszString2[0])
PutString (pszString3);
}
}
/* Used to prevent compile warnings */
if (fFlags == 0)
fFlags = 1;
#if CW_INCLUDED
else
MessageBox (pszString1, pszString2, pszString3, fFlags | 0x8000);
#endif
}
/*********************************************************************
* WriteLine - Writes a line of text to the report file
*
* qszString - String to output
* fileOutput - File to write to
* fFilterFlag - Filters out undesireable control characters
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL WriteLine (QSZ qszString, FILE *fileOutput, BOOL fFilterFlag)
{
BOOL fReturnValue = FALSE; /* Return value from WriteChar */
while (!fReturnValue && *qszString)
{
if (fFilterFlag &&
(*qszString < ' ' && *qszString != '\n' &&
*qszString != '\r' && *qszString != '\t'))
*qszString = '.';
fReturnValue = WriteChar (*(qszString++), fileOutput);
}
/* Output the trailing newline character */
if (!fReturnValue)
fReturnValue = WriteChar ('\n', fileOutput);
return (fReturnValue);
}
/*********************************************************************
* _WriteLine - Writes a line of text to the report file without
* pagination or line wrapping
*
* qszString - String to output
* fileOutput - File to write to
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL _WriteLine (PSZ pszString, FILE *fileOutput)
{
BOOL fReturnValue = FALSE; /* Return value from WriteChar */
while (!fReturnValue && *pszString)
fReturnValue = _WriteChar (*(pszString++), fileOutput);
return (fReturnValue);
}
/*********************************************************************
* WriteChar - Writes a character to the report file, and performs
* appropriate error handling.
*
* chChar - Character to output
* fileOutput - File to write to
*
* Globals:
* wColumnCount - Current column number
* wLineCount - Current line number
* wPageCount - Current page number
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL WriteChar (CHAR chChar, FILE *fileOutput)
{
BOOL fReturnValue = FALSE; /* Return value from various functions */
/* TRUE if previous character was '\n' */
static BOOL fPrevCharWasNewline = FALSE; /* or '\f'. Used for indenting */
WORD i; /* Looping variable */
switch (chChar)
{
case '\n':
fPrevCharWasNewline = TRUE;
/* Is there enough room on the page for this new line */
if (++wLineCount <= LINES_PER_PAGE)
{
/* There is room. Set the values for the new line */
wColumnCount = 0;
/* Write the linefeed */
fReturnValue = _WriteChar (chChar, fileOutput);
if (fReturnValue)
return (fReturnValue);
break;
}
else
{
/* There wasn't enough room. Make a new page */
if (wPageCount != 0)
fReturnValue = WritePageBreak (fileOutput);
}
break;
case '\f':
fPrevCharWasNewline = TRUE;
/* Set the values for the new line and page */
wColumnCount = 0;
wLineCount = 0;
/* Write the form feed */
fReturnValue = _WriteChar (chChar, fileOutput);
break;
default:
if (++wColumnCount > REPORT_WIDTH)
{
fReturnValue = WriteChar ('\n', fileOutput);
if (fReturnValue)
return (fReturnValue);
}
if (fPrevCharWasNewline)
{
/* Left Indent */
for (i = 0; i < wReportIndent && fReturnValue == FALSE; ++i)
fReturnValue = _WriteChar (' ', fileOutput);
}
fReturnValue = _WriteChar (chChar, fileOutput);
fPrevCharWasNewline = FALSE;
}
/* Pass the return value back up the chain */
return (fReturnValue);
}
/*********************************************************************
* OutputLine - Writes a line of text to an output file
*
* pszString - String to output
* fileOutput - File to write to
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL OutputLine (PSZ pszString, FILE *fileOutput)
{
BOOL fReturnValue = FALSE; /* Return value from WriteChar */
while (!fReturnValue && *pszString)
fReturnValue = _WriteChar (*(pszString++), fileOutput);
/* Output the trailing newline character */
if (!fReturnValue)
fReturnValue = _WriteChar ('\n', fileOutput);
return (fReturnValue);
}
/*********************************************************************
* _WriteChar - Low level writes of a character to the output file.
*
* chChar - Character to output
* fileOutput - File to write to
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL _WriteChar (CHAR chChar, FILE *fileOutput)
{
BOOL fReturnValue; /* Return value from various functions */
fReturnValue = fputc (chChar, fileOutput);
if (fReturnValue == EOF || fCriticalError)
{
fCriticalError = FALSE;
ShowError (ERR_OK_BUTTON, pszErrorWriting, _strerror (NULL), "");
return (TRUE);
}
/* No error occured, so return FALSE */
return (FALSE);
}
/*********************************************************************
* ReadLine - Reads a line of text from the input file
*
* pszString - String to fill with input data
* fileInput - File to read from
* fHexDump - Read file in hex
*
* Returns: Number of characters read, EOF if error or end of file.
*********************************************************************/
INT ReadLine (PSZ pszString,
WORD wMaxChar,
FILE *fileInput,
BOOL fHexDump)
{
BOOL fReturnValue = FALSE; /* Return value from ReadChar */
BOOL fEndOfLine = FALSE; /* TRUE if end of line encountered */
WORD wCharCount = 0; /* Number of characters read */
INT iChar; /* Character read from file */
/* Read the characters for a line */
while (!fReturnValue && !fEndOfLine && wCharCount < wMaxChar)
{
iChar = ReadChar (fileInput);
/* Handle special cases */
switch (iChar)
{
case EOF:
if (wCharCount > 0)
{
/* If this is not the first character, treat it like a '\r' */
fEndOfLine = TRUE;
break;
}
else
return (EOF);
case '\r':
fEndOfLine = TRUE;
break;
case '\n':
continue;
case '\0':
iChar = ' ';
/* Fall through to default */
default:
pszString[wCharCount++] = (CHAR) iChar;
}
}
/* Make sure the terminating \0 is on the end of the string */
pszString[wCharCount++] = '\0';
return (wCharCount);
}
/*********************************************************************
* ReadChar - Reads a character of from the input file
*
* fileInput - File to read from
*
* Returns: Character read.
*********************************************************************/
INT ReadChar (FILE *fileInput)
{
INT iReturnValue; /* Return value from various functions */
iReturnValue = fgetc (fileInput);
if (fCriticalError || (iReturnValue == EOF && (ferror (fileInput))))
{
fCriticalError = FALSE;
ShowError (ERR_OK_BUTTON, pszErrorReading, _strerror (NULL), "");
}
/* No error occured, so return FALSE */
return (iReturnValue);
}
/*********************************************************************
* _DosGetLine - Obtains a line of text and places it into the
* character buffer pchInputString. Currently uses
* the DOS input line function.
*
* pchInputString - Place to store the input line.
*
* iMaxChar - Maximum number of characters to allow for input.
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL _DosGetLine (CHAR *pchInputString, INT iMaxChar)
{
BOOL fReturnValue; /* Return value from PutString() */
CHAR chBuffer[258]; /* Temporary storage for the input string */
WORD i; /* Looping variable */
/* Set the maximum number of characters to input */
chBuffer[0] = (CHAR) iMaxChar;
/* Set the maximum number of characters from previous input */
chBuffer[1] = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -