config.c
来自「Dos6.0」· C语言 代码 · 共 884 行 · 第 1/3 页
C
884 行
/***************************************************************************/
/* */
/* CONFIG.C */
/* */
/* Copyright (c) 1991 - Microsoft Corp. */
/* All rights reserved. */
/* Microsoft Confidential */
/* */
/* Processes the CONFIG.SYS file in the root directory or creates one */
/* if it doesn't already exist. */
/* */
/* NOTE: */
/* In order to correctly process the mouse driver the config.sys */
/* file processing must be done before calling ProcessAutoexec(). */
/* This will insure that any existing mouse.sys driver in the */
/* config.sys file has been identified and removed and the */
/* vInfo.fMouse flag has been set to signal adding mouse to */
/* autoexec.bat. */
/* */
/* */
/* Change log: */
/* */
/* Date Who # Description */
/* -------- --- ---- --------------------------------------------- */
/* 12/07/89 JAH Created */
/* 02/19/91 DLB M006 Rename HIMEM.DOS and EMM386.DOS to */
/* HIMEM.SYS and EMM386.EXE. Also move EMM386 */
/* after rename is done, not before. */
/* */
/***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <io.h>
#include <dos.h>
#include <string.h>
#include <ctype.h>
#include <alias.h>
#include <global.h>
#include <strlib.h>
#include <data.h>
#include <upgrade.h>
#include <errors.h>
#include <prompts.h>
/***************************************************************************/
extern void NewAutoConfig ( int iType, char *szFile );
void ProcessFile ( int iType, char *szOldFile, char *szNewFile,
int (*Funcs[])( int iStatus ) );
int BuildNewFile( int (*Funcs[])( int Status ) );
void CreateDeviceLine ( char *szLine, char *szDevice, int iType );
/* void ProcessConfig ( void ); */
int NewConfigFirst ( int iStatus );
int NewConfigLast ( int iStatus );
int ProcessConfigLine ( int iStatus );
char *NewFileGets ( char *szBuffer, int Count, FILE *File );
int NewFilePuts ( char *szString, FILE *File );
static int near ProcessShellLine ( char *szStr );
static int near ProcessDeviceLine ( char *szPtr, int iType );
static int near InstallNewDrivers ( void );
static int near AddNewDevice ( char *szDevName, int iType );
static void near MoveToEndFile ( char *szStr, int iDevice );
static int near AddDrvParm ( void );
static int near add_driv_line ( char *szDrivparm, UCHAR uchDrv );
static void near find_drive ( UCHAR *puchDrv1, UCHAR *puchDrv2 );
/***************************************************************************/
/* M006 */
enum DEV_TAGS { HIMEMSYS, HIMEMDOS, SMARTDRV, EMM386SYS, EMM386DOS, EMM386EXE,
MOUSE, RAMDRIVE, EGASYS, SHARE, SETVER,
LAST_DEVICE };
#define MAX_LEN 256 /* Max length of line in autoexec.bat */
#define STR_BUF_LEN 128
#define MAX_RAM_DRIVE 23 /* Max number of RAM drives installed */
#define MAX_DEV_LINE RAMDRIVE + MAX_RAM_DRIVE + 1
#define HIMEM_SYS Devices[ HIMEMSYS ] /* M006 */
#define HIMEM_DOS Devices[ HIMEMDOS ] /* M006 */
#define SMARTDRV_SYS Devices[ SMARTDRV ]
#define EMM386_SYS Devices[ EMM386SYS ]
#define EMM386_DOS Devices[ EMM386DOS ] /* M006*/
#define EMM386_EXE Devices[ EMM386EXE ]
#define MOUSE_SYS Devices[ MOUSE ]
#define RAMDRIVE_SYS Devices[ RAMDRIVE ]
#define DEVICE 0 /* Specifies a device driver */
#define INSTALL 1 /* Specifies an installable program */
#define LOAD_HIGH 2
#define REM_LINE 1
#define DEL_LINE 2
/***************************************************************************/
/* declared in upgrade.c */
extern char *szAutoBat; /* Autoexec drive, path and name str */
extern char *szConfSys; /* Config.sys drive, path and name str */
FILE *OldFile; /* File handle for existing autoexec */
FILE *NewFile; /* File handle for new autoexec */
char *szNewString; /* Config.sys line for new file */
char *szOldString; /* Config.sys line from old file */
char *szShell = "SHELL=";
char *szCommandShell = "COMMAND.COM ";
static char *szDevice = "DEVICE=";
static char *szInstall = "INSTALL=";
static char *szLoadHi = "DEVICEHIGH=";
static char *szDosEqu = "DOS";
static char *szShellEqu = "SHELL";
static char *szInstallEqu = "INSTALL";
static char *szDeviceEqu = "DEVICE";
static char *szLoadHiEqu = "DEVICEHIGH";
struct BITS
{
unsigned fXma :1;
unsigned fHimem :1;
unsigned fSmartDrv :1;
unsigned fRamDrv :1;
unsigned fEmm386 :1;
unsigned fPath :1;
unsigned fMouse :1;
unsigned fDosKey :1;
unsigned fDosShell :1;
unsigned fNeedHiMem :1;
unsigned fHaveDosEqu :1;
unsigned fHaveEga :1;
unsigned fHaveComspec:1;
} DevFlags;
/* M006 */
static char *Devices[] = { "HIMEM.SYS", "HIMEM.DOS", "SMARTDRV.SYS",
"EMM386.SYS", "EMM386.DOS", "EMM386.EXE", "MOUSE.SYS",
"RAMDRIVE.SYS", "EGA.SYS", "SHARE.EXE",
"SETVER.EXE", NULL };
static UCHAR DeviceNameLen[] = { (UCHAR) 9, (UCHAR) 9, (UCHAR) 12,
(UCHAR) 10, (UCHAR) 10, (UCHAR) 10, (UCHAR) 9,
(UCHAR) 12, (UCHAR) 7, (UCHAR) 9,
(UCHAR) 10, (UCHAR) 0 };
/* M006 */
static char *DeviceLines[ MAX_DEV_LINE ];
static int RamDriveCount; /* # of times RAMDRIVE installed */
/***************************************************************************/
/* Process an autoexec or config.sys file by opening the old file and and */
/* and creating a new file and then passing a series of parsing functions */
/* from the caller to BuildNewFile(). If the original file doesn't exist */
/* or there is an error creating the new file a new file will be created */
/* using the information in the vInfo structure. */
/* */
/* void ProcessFile( int iType, char *szOldFile, char *szNewFile, */
/* int (*Funcs[])( int iStatus ) ) */
/* */
/* ARGUMENTS: iType - 0 == AUTOEXEC.BAT, 1 == CONFIG.SYS */
/* szOldFile - Name of existing file to process */
/* szNewFile - Name for new file to be created */
/* Funcs - Array of ptrs to file processing functions */
/* RETURNS: void */
/* */
/* */
/***************************************************************************/
void ProcessFile( int iType, char *szOldFile, char *szNewFile,int (*Funcs[])( int iStatus ) )
{
register iStatus;
iStatus = ERROR;
if ( !vInfo.Flag.fNewSysFiles &&
(OldFile = fopen( szOldFile, "rt" )) != NULL )
{
if ( (NewFile = fopen( szNewFile, "wt" )) != NULL )
{
iStatus = BuildNewFile( Funcs );
iStatus |= fclose( NewFile );
}
iStatus |= fclose( OldFile );
if ( iStatus != OK )
ProcessCopyError( szOldFile, ERR_PROCESSING );
}
if ( iStatus != OK )
NewAutoConfig( iType, szNewFile );
}
/***************************************************************************/
/* Generic file processing function. Accepts an array of 3 pointers to 3 */
/* functions which will do the actual processing of the file. The 3 */
/* 3 functions must be provided which do the following with the int arg */
/* passed to the function the current error status up to that point. */
/* */
/* int Function1( int ) - Add new lines to the file which are needed */
/* before lines from the original file are processed*/
/* int Function2( int ) - Called once for each line found in original file */
/* returns 0 if line is to be added else !0 */
/* The line read from the file is in szOldString & */
/* the function fills in szNewString to be written */
/* int Function3( int ) - Cleanup function to do anything needed before */
/* the new file is closed. */
/* */
/* */
/* int BuildNewFile( *Func[])( int Status ) ) */
/* */
/* ARGUMENTS: Funct - Array of pointers to 3 functions. */
/* RETURNS: int - OK if sucessfull else ERROR */
/* */
/* NOTE: When a line is specified for not being copied it is prefixed */
/* with a REM and written anyway. */
/***************************************************************************/
int BuildNewFile( int (*Func[])( int Status ) )
{
register iStatus;
register iToDo;
szOldString = GetMemory( MAX_LEN * 3 );
szNewString = szOldString + (MAX_LEN + 10);
iStatus = OK;
iStatus = (*Func[0])( OK ); /* Call startup function */
/* Loop once for each line */
/* line in the old file */
while ( iStatus == OK && !feof( OldFile ) )
{
if ( NewFileGets( szOldString, MAX_LEN, OldFile ) != NULL )
{
if ( (iToDo = (*Func[1])( OK )) != OK )
{
if ( iToDo == REM_LINE )
{
strcpy( szNewString, "REM " );
strncpy( szNewString + 4, szOldString, MAX_LEN );
iStatus = NewFilePuts( szNewString, NewFile );
}
/* Else just don't copy the line */
}
else
iStatus = NewFilePuts( szNewString, NewFile );
}
if ( ferror( OldFile ) || ferror( NewFile ) )
iStatus = ERROR;
}
iStatus = (*Func[2])( iStatus );
FreeMemory( szOldString );
return( iStatus );
}
/***************************************************************************/
/* Creates a new config.sys file in the tmp directory. If an old config.sys*/
/* exists in the root directory it will be used as a model and will be */
/* fixed up to reflect then new paths to the DOS directory and the new */
/* requirement that EMM386.EXE, RAMDRIVE.SYS and SMARTDRV.SYS require that */
/* HIMEM.SYS be installed to suppy XMA memory access. If there was not an */
/* old file a new default file will created. */
/* */
/* void ProcessConfig( void ) */
/* */
/* ARGUMENTS: NONE */
/* RETURNS: void */
/* */
/***************************************************************************/
void ProcessConfig( void )
{
static int (*Funcs[])(int) = { NewConfigFirst, ProcessConfigLine,
NewConfigLast };
ProcessFile( CONFIG_SYS, szConfSys, vInfo.szTmpConfig, Funcs );
}
/***************************************************************************/
/* Initializes the DeviceLines[] array to all NULL ptrs and then install */
/* any new devices which are specified in the DOSDATA.DAT file. */
/* */
/* int NewConfigFirst( int iStatus ) */
/* */
/* ARGUMENTS: iStatus - Current error status of the file processing */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?