📄 file.c
字号:
if (! bTempFnd ) { // And if a temp was not found add one.
if ( ISEOF(*lpFileOffset) && !ISCRLF(*(lpFileOffset-1)) && bPathFnd ) {
*pTo = CR,++pTo;
*pTo = LF,++pTo;
}
strcpy(TmpWorkSpace,pszSET); // construct set statement.
strcat(TmpWorkSpace," ");
strcat(TmpWorkSpace,pszTEMP);
strcat(TmpWorkSpace,"=");
strcat(TmpWorkSpace,szSetupPath);
catpath(TmpWorkSpace,pszTEMP);
pTo = fnCopyBuf((LPSTR)(TmpWorkSpace),pTo,strlen(TmpWorkSpace));
*pTo = CR,++pTo;
*pTo = LF,++pTo;
*pTo = '\0';
szSearch = TmpWorkSpace;
while ( *szSearch != '=' )
++szSearch;
++szSearch;
DosMkDir(szSearch); // Make the directory.
bBufMod = TRUE;
}
if ( ISEOF(*lpFileOffset) )
*pTo = '\0'; // Assure buffer terminated !!!
FFREE(pHead); // Free the old buffer.
return bBufMod; // Return state of buffer
}
/* BOOL fnEditPath(char *ExistingPath);
*
* Function will add the szSetupPath to the users path statement in the
* autoexec.bat file. The szSetupPath will be the first location in the
* path statement. The path can be in about a million fucked up forms
* depending on the level of stupidity in the user. Here are a few to
* think about. DOS will accept any of these.
*
* PATH=C:\foo;C:\foobar;...
* SET PATH=C:\foo;C:\foobar;...
* PATH C:\foo;C:\foobar;...
* PATH =C:\foo;C:\foobar;...
* PATH= C:\foo;C:\foobar;...
* PATH = C:\foo;C:\foobar;...
*
* ENTRY: ExistingPath - near buffer containing the path statement to be
* edited.
*
* EXIT: BOOL, TRUE = Path succesfully modified.
* FALSE = Path was too long after modification (path >= 128).
*
*/
BOOL fnEditPath(ExistingPath)
char *ExistingPath;
{
char TmpWorkSpace[PHILSMAXPATH];
char NewPathBuff[PHILSMAXPATH];
char *Path;
char *InsertPoint;
unsigned i = 0;
Path = ExistingPath;
while ( *Path != 'h' && *Path != 'H' ) { /* look for end of PATH */
TmpWorkSpace[i] = *Path;
++Path, ++i;
}
TmpWorkSpace[i] = *Path++; /* Cat on the 'h' or 'H' */
TmpWorkSpace[i+1] = *Path++; /* Cat on a ' ' or an '=' */
TmpWorkSpace[i+2] = '\0'; /* Terminate. */
/* There may be extranious crapola here so lets rid ourselvs of it. */
while ( *Path == ' ' || *Path == '=' || *Path == '\t' )
++Path;
strcpy(NewPathBuff,Path);
/* now we have a "path =" or "path " null terminated string. Now we need
to assure that in all cases of path editing, the users local windows
installation directory comes before a shared windows directory. This
of course is only relevent if we are doing a net setup. */
strcat(TmpWorkSpace,szSetupPath); /* Now cat the new path seg */
strcat(TmpWorkSpace,";"); /* Cat on the seperator */
if ( (InsertPoint = fnMyStrPath(NewPathBuff,szSetupPath)) ) {
*InsertPoint++ = '\0';
while ( !ISEOL(*InsertPoint) && *InsertPoint != ';' )
++InsertPoint;
if ( *InsertPoint == ';' )
++InsertPoint;
strcat(NewPathBuff,InsertPoint);
}
if ( bIsNetSetup ) {
strcat(TmpWorkSpace,szDiskPath); /* Now cat the new path seg */
strcat(TmpWorkSpace,";"); /* Cat on the seperator */
if ( (InsertPoint = fnMyStrPath(NewPathBuff,szDiskPath)) ) {
*InsertPoint++ = '\0';
while ( !ISEOL(*InsertPoint) && *InsertPoint != ';' )
++InsertPoint;
if ( *InsertPoint == ';' )
++InsertPoint;
strcat(NewPathBuff,InsertPoint);
}
}
strcat(TmpWorkSpace,NewPathBuff); /* Now the rest of the path */
/* Last but not least, check to make sure we don't insert a path that
is too long into the dudes autoexec.bat, also check to make sure
we don't edit the path when there was no reason to */
if ( strlen(TmpWorkSpace) >= PHILSMAXPATH )
return FALSE;
else {
if (! stricmp(TmpWorkSpace,ExistingPath) )
return FALSE;
strcpy(ExistingPath,TmpWorkSpace); /* Put path back into orig buf */
return TRUE;
}
}
/* BOOL fnPathline(LPSTR);
*
* Function determines if the string pointed to by sStrPtr is a path statement
* of any one of three possible forms:
*
* PATH=C:\foo;C:\foobar;...
* SET PATH=C:\foo;C:\foobar;...
* PATH C:\foo;C:\foobar;...
*
* Function returns true or false as to weather or not the string is a path
* or not.
*
*/
BOOL fnPathline(sStrPtr)
LPSTR sStrPtr;
{
if ( !strncmpinf(pszPATH,sStrPtr,strlen(pszPATH)) ) // First, check the easy case
return TRUE;
else {
if ( !strncmpinf(pszSET,sStrPtr,strlen(pszSET)) ) {
sStrPtr += strlen(pszSET); // Advance past set statement
while ( ISFILL(*sStrPtr) ) // Seek for beginning of path
++sStrPtr;
if ( !strncmpinf(pszPATH,sStrPtr,strlen(pszPATH)) )
return TRUE;
}
}
return FALSE;
}
/* char *fnMyStrPath(char *szPath, char *szSearchStr);
*
* Function will return BOOL value as to weather the Search string exists
* any where within the source string. The difference between this func
* the C run time func is that this one is simpler and is also not case
* sensitive.
*
* ENTRY: szPath - Char buffer to be searched.
*
* szSearchStr - String that will be searched for.
*
* EXIT: char* - Returns pointer to first char of string that matches.
*
*
* WARNING: Source and search strings MUST be null terminated.
*
*
*/
char *fnMyStrPath(szPath, szSearchStr)
char *szPath;
char *szSearchStr;
{
unsigned len; // Get length of search string.
len = strlen(szSearchStr);
while (! ISEOL(*szPath) ) {
if ( ! strnicmp(szPath,szSearchStr,len)) {
if ( ISEOL(*(szPath + len)) || *(szPath + len) == ';' )
return szPath;
}
++szPath;
}
return NULL;
}
/* BOOL fnMouseline(LPSTR szLine, PSTR szMouseName);
*
* Function will make the determination as to weather or not a given line
* (usually from an autoexec.bat file) is a mouse installation line or
* not.
*
* ENTRY: szLine - The line from the autoexec.bat file for which the
* determination will be made.
*
* EXIY: Boolean as to weather the line is a mouse installation line or
* not.
*
*/
BOOL fnMouseline(szLine,szMouseName)
LPSTR szLine;
PSTR szMouseName;
{
char TmpWorkBuf[MAXCMDLINELEN*2];
unsigned index;
fnCopyBuf(szLine,TmpWorkBuf,fnLinelenl(szLine));
fnTerminate(TmpWorkBuf);
if (! fnMystrstr(TmpWorkBuf,szMouseName) )
return FALSE;
else {
if ( strlen(TmpWorkBuf) < 128 && fnFileExists(TmpWorkBuf) )
return TRUE;
else
return FALSE;
}
}
/* BOOL fnTempLine(LPSTR);
*
* Function determines if the string pointed to by sStrPtr is a temp
* environment variable definition of the following form.
*
* SET TEMP=C:\foo
*
* Function returns true or false as to weather or not the string is a temp
* environment variable or not.
*
*/
BOOL fnTempline(sStrPtr)
LPSTR sStrPtr;
{
while ( ISWHITE(*sStrPtr) ) // May be whitespace before set statement.
++sStrPtr;
if (! strncmpinf("set temp",sStrPtr,8)) {
sStrPtr += 8;
if ( *sStrPtr == '=' || *sStrPtr == ' ' || *sStrPtr == '\t' )
return TRUE;
}
return FALSE;
}
/* BOOL fnFileExists(char *szFile);
*
* Function will determine if the given filename (weather qualified or not)
* exists.
*
* ENTRY: szFile - File name, qualifed or not.
*
* EXIT: Boolean as to existance of file.
*
* WARNING: Function assumes you will be looking for a .com file.
*
*/
BOOL fnFileExists(szFile)
char *szFile;
{
int fh;
char szTmpBuf[PHILSMAXPATH];
char *tmp;
unsigned Disks[26];
if ( szFile[strlen(szFile) - 4] != '.' ) {
tmp = szFile;
tmp += (strlen(szFile) - 1);
while ( *tmp && UPCASE(*tmp) != 'E' )
--tmp;
*(tmp+1) = '\0';
strcat(szFile,".com");
}
/* First see if the file exists by trying to open it. */
fh = FOPEN(szFile); // Try to open the file.
if ( fh == -1 ) { /* May need to prepend a drive spec. */
if ( szFile[1] != ':' ) {
GetFixedDisks(Disks);
szTmpBuf[0] = (char)(Disks[0] + 'A');
szTmpBuf[1] = ':';
szTmpBuf[2] = '\0';
strcat(szTmpBuf,szFile);
fh = FOPEN(szTmpBuf); // Try to open the file.
}
}
if ( fh != -1 ) {
FCLOSE(fh);
return TRUE;
}
/* Next, see if the file exists anywhere on the path. */
_searchenv(szFile,pszPATH,szTmpBuf);
if ( *szTmpBuf )
return TRUE;
else
return FALSE;
}
/* void FAR PASCAL fnTweekMouse(PSTR szMouseDrv,PSTR szMouseName);
*
* Function will look into the autoexec.bat and config.sys files and
* replace an existing mouse.com/mouse.sys file installation entry with
* a new entry line which will install a new mouse driver from the windows
* installation directory.
*
* ENTRY: szMouseDrv - Buffer of sufficent size to hold the name of the
* mouse driver + the logocal drive volume.
*
* szMouseName - Name of mouse driver to be upgraded. One of:
* hpmouse,mouse.
*
* RETURNS: No formal return, fills buffer provided with name of DOS
* mouse driver.
*
*/
void FAR PASCAL fnTweekMouse(szMouseDrv,szMouseName)
PSTR szMouseDrv;
PSTR szMouseName;
{
char szConfigLine[MAXCMDLINELEN*2];
char szMouseLnConst[MAX_INF_LINE_LEN];
char szProfileBuf[MAX_INF_LINE_LEN];
char *pMouseFnd;
BOOL IsAddY = FALSE;
PINF pinfSectP;
if (! stricmp(szMouseName,pszADD_Y) )
IsAddY = TRUE;
strcpy(szMouseLnConst,szMouseName);
strcpy(szProfileBuf,szMouseName);
fnProcessFile(NULL,NULL,NULL,NULL,NULL,NULL,ASSURE_OPEN);
if ( fnModifyPath(DO_MOUSE,szMouseName) ) {
gbAutoMod = TRUE;
if ( IsAddY )
szProfileBuf[0] = '\0';
else
strcat(szProfileBuf,pszCOMEXT);
}
else {
strcat(szMouseLnConst,pszSYSEXT);
strcat(szProfileBuf,pszSYSEXT);
/* First, find out what mouse driver if any is in config.sys. */
if ( fnUpdateDevice(pszMSSYS,RETURN_PRESENCE,szConfigLine) )
pMouseFnd = pszMSSYS;
else if ( fnUpdateDevice(pszHPSYS,RETURN_PRESENCE,szConfigLine) )
pMouseFnd = pszHPSYS;
else
pMouseFnd = NULL;
/* Second, are we doing an add_y switch operation ? */
if ( IsAddY && pMouseFnd && !fnMystrstr(szConfigLine,"/Y") ) {
fnUpdateDevice(pMouseFnd,REMOUT_DEVICE,szConfigLine);
strcat(szConfigLine," /Y");
fnUpdateDevice(szConfigLine,ADD_DEVICE,szConfigLine);
szProfileBuf[0] = '\0';
gbSysMod = TRUE;
}
else if ( IsAddY && !pMouseFnd ) {
strcpy(szMouseLnConst,pszMOUSE);
strcat(szMouseLnConst,pszSYSEXT);
strcpy(szProfileBuf,szMouseLnConst);
strcat(szMouseLnConst," /Y");
fnConstructDeviceEntry(szConfigLine,szMouseLnConst,0,0);
fnUpdateDevice(szConfigLine,ADD_DEVICE,szConfigLine);
gbSysMod = TRUE;
}
else if ( !IsAddY ) {
if ( pMouseFnd )
fnUpdateDevice(pMouseFnd,REMOUT_DEVICE,szConfigLine);
strcat(szMouseLnConst," /Y");
fnConstructDeviceEntry(szConfigLine,szMouseLnConst,0,0);
fnUpdateDevice(szConfigLine,ADD_DEVICE,szConfigLine);
gbSysMod = TRUE;
}
/* the case of (IsAddY && pMouseFnd && fnMystrstr(szConfigLine,"/Y")
will work ok even though szProfileBuf contains add_y.sys. This
will remain true as long as one never adds a profile string of
add_y.sys to the [dos.mouse] section of setup.inf. */
}
/* Last thing to do, get name of DOS mouse driver to copy. */
infGetProfileString(NULL,DOS_MOUSE_SECT,szProfileBuf,szMouseLnConst);
infParseField(szMouseLnConst,1,szMouseDrv);
}
// write out a file.
//
// in:
// szFile file to write.
// lpBuf null terminated string
// returns
// TRUE success
// FALSE faile
static int SaveFile( PSTR szFile, LPSTR lpBuf )
{
int fh;
unsigned utowrite;
unsigned BufLen;
char buf[ MAXPATHLEN ];
for ( BufLen = 0; lpBuf[ BufLen ] != '\0'; BufLen++ )
;
if (szFile[1] != ':')
{
ExpandFileName( szSetupPath, buf );
catpath( buf, szFile );
}
else
strcpy(buf, szFile);
if ( _dos_creat( buf, 0, &fh) == 0 )
{
if ( _dos_write( fh, lpBuf, BufLen, &utowrite ) == 0 &&
utowrite == BufLen )
{
_dos_close( fh );
return WRITE_SUCCESS;
}
close( fh );
return WRITE_FAIL;
}
else
return CREATE_FAIL;
}
#endif // DOSONLY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -