📄 insert.c
字号:
(chBuffer[i1] == ' ' || chBuffer[i1] == '\t'); ++i1)
;
/* Compare the two strings, up to the end of pszSection */
for (i2 = 0; i1 < MAX_INI_LINE_LENGTH && chBuffer[i1] != '\0' &&
pszSection[i2] != '\0' &&
toupper (pszSection[i2]) == toupper (chBuffer[i1]);
++i1, ++i2)
;
/* Did we find a match -- ie, did we get to the end of pszSection */
if (pszSection[i2] == '\0')
return (FALSE);
}
/* Section was not found */
return (TRUE);
}
/**********************************************************************
* HandleDuplicates - Searches for, and optionally replaces command
* strings within a file. When replacing, writes
* out the changed file.
*
* WORD wFunction - wFunction:
* HD_SEARCH - Search for duplicate commands. Add
* duplicate commands to lbxList.
* HD_REPLACE_ALL - Replace all matching commands with one
* pszReplace string. pszReplace will
* replace first matching string.
* 0-n - Replace n occurance of search string
* with pszReplace.
* pszSearch - String to search for.
* pszReplace - String to replace.
* fpInfile - Input file to search.
* fpOutfile - File to contain changes.
* pwndList - List box for storing matching strings.
*
* Returns: TRUE if an error occured.
**********************************************************************/
BOOL HandleDuplicates (WORD wFunction,
PSZ pszSearch,
PSZ pszReplace,
FILE *fpInfile,
FILE *fpOutfile,
PWND pwndList)
{
char chBuffer [MAX_INI_LINE_LENGTH + 1]; /* Character buffer - no line is */
/* assumed to be more than */
/* MAX_INI_LINE_LENGTH bytes in */
/* length. */
char chBuffer2[MAX_INI_LINE_LENGTH + 1]; /* Used for adding "REPLACE " to */
/* the beginning of the line */
/* in the list box. */
BOOL fMatch; /* Flag for match */
WORD wMatchCount = 0; /* Incriments for each match */
while (ReadLine (chBuffer, MAX_INI_LINE_LENGTH, fpInfile, FALSE) != EOF)
{
/* Set match flag */
fMatch = HdMatch (pszSearch, chBuffer);
switch (wFunction)
{
case HD_SEARCH: /* Search for duplicates */
/* Does chBuffer match the search string */
if (fMatch)
{
chBuffer2[0] = '\0';
strcat (chBuffer2, "REPLACE ");
strcat (chBuffer2, chBuffer);
/* Add item to the listbox */
SendMessage (pwndList, LB_ADDSTRING,
((WORD) (isaNil) << 8) + TRUE,
(DWORD) ((CHAR FAR *) (chBuffer2)));
}
break;
case HD_REPLACE_ALL: /* Replace all duplicates */
/* Is this the first match */
if (fMatch)
if (++wMatchCount == 1)
{
/* Replace first match with replace string */
if (OutputLine (pszReplace, fpOutfile))
return (TRUE);
}
/* If there was no match, output the line */
if (!fMatch)
if (OutputLine (chBuffer, fpOutfile))
return (TRUE);
break;
default: /* Replace wFunction duplicate line */
/* Is this the correct matching line */
if (fMatch && ++wMatchCount == wFunction)
{
/* Replace correct match with replace string */
if (OutputLine (pszReplace, fpOutfile))
return (TRUE);
/* Write out the rest of the file */
WriteThrough (fpInfile, fpOutfile);
}
else
if (OutputLine (chBuffer, fpOutfile))
return (TRUE);
break;
}
}
return (FALSE);
}
/**********************************************************************
* HdMatch - Match checking routine for HandleDuplicates
*
* pszSearch - Search string to compare for matched strings.
* pszFullLine - Line to compare to see if a match occured.
*
* Returns: TRUE if match occured, FALSE if not.
**********************************************************************/
BOOL HdMatch (char *pszSearch, char *pszFullLine)
{
WORD i; /* Looping variable */
for (i = 0; i < strlen (pszSearch) &&
toupper (pszSearch[i]) == toupper (pszFullLine[i]); ++i)
;
if (i == strlen (pszSearch))
return (TRUE);
else
return (FALSE);
}
/*********************************************************************
* OpenIniFile - Opens the MSD.INI file.
*
* Global:
* pszPathToProgram - Path to the .EXE file.
*
* Returns: File handle to MSD.INI. NULL if an error occured.
*********************************************************************/
FILE * OpenIniFile (VOID)
{
CHAR szIniPathname[_MAX_PATH]; /* Used to store .INI filename */
static WORD i; /* Looping variable */
static PSZ pszIniFilename = "MSD.INI"; /* .INI filename */
/* Copy the pathname to MSD.EXE to szIniPathname */
strcpy (szIniPathname, pszPathToProgram);
/* Search for the first "\" (it should be a fully qualified path, */
/* as in "C:\WINDOWS\MSD.EXE". */
for (i = strlen (szIniPathname); i > 0 && szIniPathname[i] != '\\'; --i)
;
if (i == 0) /* szIniPathname did not contain a fully qualified path */
{
/* Hope there is a MSD.INI file in the current directory */
strcpy (szIniPathname, pszIniFilename);
}
else /* A fully qualified path was found */
{
/* Remove MSD.EXE */
szIniPathname[++i] = '\0';
/* Add MSD.INI */
strcat (szIniPathname, pszIniFilename);
}
/* Open the .INI file */
return (OpenFile (szIniPathname, "rb", FALSE));
}
/**********************************************************************
* WriteThrough - Writes all characters through from input file to
* output file.
*
* fpInputFile - Input file.
* fpOutputFile - Output file.
*
* Returns: TRUE if an error occured.
**********************************************************************/
BOOL WriteThrough (FILE *fpInputFile, FILE *fpOutputFile)
{
CHAR chBuffer[256]; /* Input buffer */
BOOL fReturnValue = FALSE; /* Return value from various functions */
while (fReturnValue == FALSE)
{
if (ReadLine (chBuffer, 255, fpInputFile, FALSE) == EOF)
fReturnValue = TRUE;
if (fReturnValue == FALSE)
fReturnValue = OutputLine (chBuffer, fpOutputFile);
}
return (fReturnValue);
}
/**********************************************************************
* AddIniLine - Adds a line to the list box
*
* pszString - Comma delimited string to add to the list box.
* plbxCommands - Listbox to fill.
**********************************************************************/
VOID AddIniLine (PWND pwndList, PSZ pszString)
{
static char chBuffer[80]; /* Stores expanded string */
static int i, i1, i2; /* Looping varaibles */
static int fQuotedString; /* Flag. 1 means this is a quoted string */
static int aiColumns[] = /* Locations of the columns in list box */
{
INI_COMMAND_COL,
INI_SECTION_COL,
INI_FILENAME_COL,
79
};
/* Clear out chBuffer */
memset (chBuffer, ' ', 79);
chBuffer[80] = '\0';
/* Start loop to fill in the various sections */
for (i = 0; aiColumns[i] < 79; ++i)
{
/* Skip any white space at the beginning of the string */
for (i1 = 0; pszString[i1] != '\0' && pszString[i1] != ',' &&
(pszString[i1] == '\t' || pszString[i1] == ' '); ++i1)
;
/* Is the first character a quote */
if (pszString[i1] == '\"')
{
++i1;
fQuotedString = 1;
}
else
fQuotedString = 0;
/* Copy the command to chBuffer */
for (i2 = aiColumns[i]; i2 < aiColumns[i + 1] &&
pszString[i1] != '\0' &&
((fQuotedString && pszString[i1] != '\"') ||
(!fQuotedString && pszString[i1] != ','));
++i1, ++i2)
chBuffer[i2] = pszString[i1];
/* Search for the next section */
if (fQuotedString && pszString[i1] != '\0')
{
for (++i1; pszString[i1] != '\0' && pszString[i1] != ','; ++i1)
;
}
if (pszString[i1] != '\0')
{
/* Skip white space after the comma */
for (++i1; pszString[i1] != '\0' && pszString[i1] != ',' &&
(pszString[i1] == '\t' || pszString[i1] == ' '); ++i1)
;
}
pszString += i1;
}
chBuffer[i2] = '\0';
SendMessage (pwndList, LB_ADDSTRING, ((WORD) (isaNil) << 8) + TRUE,
(DWORD) ((CHAR FAR *) (chBuffer)));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -