config.c
来自「Dos6.0」· C语言 代码 · 共 884 行 · 第 1/3 页
C
884 行
f.fDelete = TRUE;
else
{ /* See if need to install himem driver */
if ( !DevFlags.fHimem )
{
MoveToEndFile( szPtr, EMM386EXE );
f.fDelete = TRUE;
DevFlags.fNeedHiMem = TRUE;
/* M006: Create new name in case
was EMM386.SYS or EMM386.DOS. */
memcpy( DeviceLines[EMM386EXE],
EMM386_EXE,
strlen(szDevName) );
}
else
{
/* M006: Create new name in case
was EMM386.SYS or EMM386.DOS. */
memcpy( szPtr,
EMM386_EXE,
strlen(szDevName) );
}
f.fChangePath = TRUE;
DevFlags.fEmm386 = TRUE;
}
break;
#ifdef ADD_MOUSE
/* Process "DEVICE=MOUSE.SYS" line */
case MOUSE:
if ( vInfo.Flag.fMouse ) /* If adding new mouse driver need to */
f.fDelete = TRUE; /* REM out this line */
break;
#endif
case EGASYS:
f.fChangePath = TRUE;
DevFlags.fHaveEga = TRUE;
break;
case SHARE:
f.fChangePath = TRUE;
break;
case SETVER:
return( DEL_LINE ); /* Just don't copy the line */
default: /* No match found */
if ( iType == DEVICE )
{
if ( FindDataMatch( szDevName, REM_DEVICE ) ||
FindDataMatch( szDevName, DELETE_DRIVER ) )
f.fDelete = TRUE;
else if ( IsDistrFile( szDevName ) )
f.fChangePath = TRUE;
}
else if ( iType == INSTALL || iType == LOAD_HIGH )
if ( IsDistrFile( szDevName ) )
f.fChangePath = TRUE;
break;
} /* End switch */
if ( f.fChangePath == TRUE && !f.fNoCopy )
CreateDeviceLine( szNewString, szPtr, iType );
else if ( !f.fDelete )
strcpy( szNewString, szOldString );
return( f.fDelete ? REM_LINE : OK );
}
/***************************************************************************/
/* Function to add a device line to the new config.sys file. */
/* */
/* int AddNewDevice( char *szDevName, int iType ) */
/* */
/* Arguments: szDevName - Ptr to the device name and any parameters */
/* iType - Specifies if should be DEVICE= or INSTALL= */
/* RETURNS: int - Status of fputs() function */
/* */
/***************************************************************************/
static int near AddNewDevice( char *szDevName, int iType )
{
char *szOldString;
register iStatus;
szOldString = GetMemory( MAX_LEN * 2 );
CreateDeviceLine( szOldString, szDevName, iType );
iStatus = NewFilePuts( szOldString, NewFile );
FreeMemory( szOldString );
return( iStatus );
}
/***************************************************************************/
/* Creates a device string for the config.sys file in the form of: */
/* "DEVICE=X:\DOS_PATH\DEVICE /x/x/x" */
/* The drive letter is derived from vInfo.chDestin and the path from */
/* vInfo.szPath. */
/* */
/* void CreateDeviceLine( char *szLine, char *szDevice, int iType ) */
/* */
/* ARGUMENTS: szLine - Ptr to buffer to hold the new string */
/* szDevice - The name of the device with any needed params */
/* iType - Specifies if should be DEVICE= or INSTALL= */
/* RETURNS: void */
/* */
/***************************************************************************/
void CreateDeviceLine( char *szLine, char *szDevString, int iType )
{
char *szDevicePath;
if ( iType == LOAD_HIGH )
strcpy( szLine, szLoadHi );
else
strcpy( szLine, iType == DEVICE ? szDevice : szInstall );
szDevicePath = strchr( szLine, EOL );
BuildPath( szDevicePath, HD_BOOT_DRV, vInfo.szPath + 2, szDevString );
}
/***************************************************************************/
/* Allocates a buffer for and copies a device name and parameters to the */
/* specifed place in the DeviceLines array which holds ptrs to devices to */
/* add to the end of the new config.sys file. */
/* */
/* void MoveToEndFile( char szStr, int iDevice ) */
/* */
/* ARGUMENTS: szStr - Ptr to a device name and any needed parameters */
/* iDevice - An enumerated device descriptor for specifing */
/* an element in the DeviceLines[] array */
/* RETURNS: void */
/* */
/***************************************************************************/
static void near MoveToEndFile( char *szStr, int iDevice )
{
DeviceLines[ iDevice ] = GetMemory( MAX_LEN + 10 );
strcpy( DeviceLines[ iDevice ], szStr );
}
/***************************************************************************/
/* Reads a line from the specified open 'C' file handle and then parses */
/* off any trailing carriage return or newline characters. The function */
/* has the same calling arguments and returns the same thing as a fgets(). */
/* */
/* char *NewFileGets( char *szBuffer, int Count, FILE *File ) */
/* */
/* ARGUMENTS: szBuffer - Buffer to read the line into */
/* iCount - Max character to read in */
/* File - Ptr to open 'C' file structure */
/* RETURNS: char * - Ptr to szBuffer or NULL if error or end of file */
/* */
/***************************************************************************/
char *NewFileGets( char *szBuffer, int Count, FILE *File )
{
char *szPtr;
if ( (szBuffer = fgets( szBuffer, Count, File )) != NULL )
{
if ( (szPtr = strchr( szBuffer, '\n' )) != NULL )
*szPtr = EOL;
if ( (szPtr = strchr( szBuffer, '\r' )) != NULL )
*szPtr = EOL;
}
return( szBuffer );
}
/***************************************************************************/
/* Appends a newline character to a string and then writes the string to */
/* an open file. */
/* */
/* int NewFilePuts( char *szString, FILE *File ) */
/* */
/* ARGUMENTS: szString - Ptr to string to write to file */
/* File - Ptr to open 'C' file structure */
/* RETURNS: int - OK if sucessfull else non-zero value */
/* */
/***************************************************************************/
int NewFilePuts( char *szString, FILE *File )
{
strcat( szString, "\n" );
return( fputs( szString, File ) );
}
/***************************************************************************/
/* Checks the dos data and adds all lines from the [add-dev] class to the */
/* current location in the open new config.sys file. */
/* */
/* static int AddDevice( void ) */
/* */
/* ARGUMENTS: NONE */
/* RETURNS: int - File write status from fputs() */
/* */
/***************************************************************************/
static int near InstallNewDrivers( void )
{
char *szNewStr;
register i;
register iStatus;
for ( i = 0, iStatus = OK;
iStatus == OK &&
(szNewStr = GetDataString( ADD_DEVICE, i )) != NULL;
i++ )
iStatus = AddNewDevice( szNewStr, DEVICE );
if ( iStatus == OK )
iStatus = AddDrvParm();
return( iStatus );
}
/***************************************************************************/
static int near AddDrvParm()
{
char *szDrivparm;
char *szDataStr;
int iStatus;
UCHAR uchDrivparmDrv1;
UCHAR uchDrivparmDrv2;
iStatus = OK;
szDrivparm = GetMemory( MAX_LEN + 10 );
szDataStr = GetDataString( DRIV_PARM, 0 );
if ( szDataStr != NULL )
{
find_drive( &uchDrivparmDrv1, &uchDrivparmDrv2 );
strncpy( szDrivparm, szDataStr, MAX_LEN + 9 );
if ( uchDrivparmDrv1 != 0xff )
iStatus = add_driv_line( szDrivparm, uchDrivparmDrv1 );
if ( iStatus == OK && uchDrivparmDrv2 != 0xff )
iStatus = add_driv_line( szDrivparm, uchDrivparmDrv2 );
}
FreeMemory( szDrivparm );
return( iStatus );
}
/***************************************************************************/
static int near add_driv_line( char *szDrivparm, UCHAR uchDrv )
{
char szNum[4];
itoa( uchDrv, szNum,10 ); /* Create drive number string */
strcat( szDrivparm, " /d:" );
strcat( szDrivparm, szNum );
return( NewFilePuts( szDrivparm, NewFile ) );
}
/***************************************************************************/
void near find_drive( UCHAR *puchDrv1, UCHAR *puchDrv2 )
{
UCHAR chByte;
*puchDrv1 = *puchDrv2 = 0xff;
/*Get TANDY id byte at 0xf000:0xc000*/
chByte = (UCHAR) *( (UCHAR far *) ((0xf000L << 16L) | 0xc000L) );
if (chByte == 0x21)
{
/* At 40:B5 - bit 0 = 1 => drive A is 720K
- bit 1 = 1 => drive B is 720K */
chByte = (UCHAR) *( (UCHAR far *) ((0x0040L << 16) | 0x00b5L) );
if ( (chByte >>= 1) != 0 )
*puchDrv1 = 0;
if ( (chByte >> 1) != 0 )
*puchDrv2 = 1;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?