⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 data.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************/
/* 																								*/
/* DATA.C																						*/
/* 																								*/
/*		Copyright (c) 1991 - Microsoft Corp.											*/
/*		All rights reserved.																	*/
/*		Microsoft Confidential																*/
/* 																								*/
/* Functions for accessing the data in DOSDATA.DAT. The functions 			*/
/* InitDosData() must be called before any other functions in this			*/
/* module are called.																		*/
/*																									*/
/* Created 11-11-89 - johnhe																*/
/***************************************************************************/

#include		<stdio.h>
#include		<stdlib.h>
#include 	<string.h>
#include		<dos.h>
#include 	<fcntl.h>
#include 	<io.h>
#include		<share.h>
#include 	<sys\\types.h>
#include 	<sys\\stat.h>

#include		<alias.h>
#include 	<disk_io.h>
#include 	<data.h>
#include 	<strlib.h>
#include	<window.h>
#include	<dosonly.h>
#include	<install.h>
#include 	<message.h>

#ifdef	OEM_PROGRAM
#include		<oem.h>
#else
#include		<global.h>
#endif

char ***ppszBanners = NULL;

void DosUnreadLine (char *szBuffer);
int DosReadChar (int iFile);
void DosUnreadChar (char ch);

/***************************************************************************/

#define	USIZE					sizeof( unsigned )	/* Size of unsigne value	*/
#define	RELOC_LEN			(1024 * 2)				/* Size of relocate buffer */

/***************************************************************************/

							/* Class is an array of ptrs to the different labels	*/
							/* indentifing a specific class in dosdata.dat			*/

static char *Class[] = {		"[lie-to]", "[rename]", "[delete]",
										"[device]", "[drivparm]", "[rem-device]",
										"[no-install]", "[dif-file]",

											/* Start of nonOEM sepecific data classes	*/

										"[dif-disk]", "[bios]",

											/* Distribution disk label strings */
										"[dist_label]",

											/* User disk label strings */
										"[user_label]",

											/* Compression ratio values */
										"[compression-ratio]",

											/* Distribution disk prompts */
										"[user_prompt]", "[prompt]",

										"[dif-path]", "[global-rename]", "[upd-device]",
										"[video-list]", "[video-drv]", "[disk-bytes]",
										"[disk-type]",	"[video-grb]", "[netfiles]",
										"[drv-vers]", "[del-driver]",
										"[component-bytes]", "[total-bytes]",

										"[backup-windos]",
										"[backup-win]",
										"[backup-dos]",
										"[undelete-windos]",
										"[undelete-win]",
										"[undelete-dos]",
                              "[optcomp-undelete]",
										"[antivirus-windos]",
										"[antivirus-win]",
										"[antivirus-dos]",
                              "[optcomp-antivirus]",

                                 /* Emergency-floppy layouts */
                              "[dos360]", "[dos720]", "[dos120]",

                                 /* 3rd party disk caching */
                              "[caches]",

                                 /* Utilities that won't run with smartdrv */
                              "[conflicts-smartdrv]",

                                 /* Drivers we can't add files before */
                              "[LoadAfter]",

											/* Distribution disk file layouts */
										"[distr-0]", "[distr-1]", "[distr-2]",
										"[distr-3]", "[distr-4]", "[distr-5]",
										"[distr-6]", "[distr-7]", "[distr-8]",
                              "[distr-9]", "[distr-10]","[distr-11]",
                              "[distr-12]","[distr-13]","[distr-14]",

											/* User disk file layouts */
										"[disk-0]", "[disk-1]", "[disk-2]",
										"[disk-3]", "[disk-4]", "[disk-5]",
										"[disk-6]", "[disk-7]", "[disk-8]",
										"[disk-9]",

										"OEMTABLE" };

							/* Data is an array of ptrs to the arrays of strings	*/
							/* for each of the different classes listed by label	*/
							/*	above. To access a specific string in one of the	*/
							/* class use the method:										*/
							/*			szStr = *(Data[ ENUM_CLASS ] + Index)			*/
							/* Where Index is the string in the array you need.	*/

static char			**Data[ END_CLASS ];

static char			*szDosDataFile;

static char			*szUpgrade = "INSTALL"; 	/* Label for upgrade data		*/
static char 		*szSearch  = "OEMTABLE";	/* Label for search data		*/

static char			*pchStringBuf;		/* Flat buffer to hold the data text	*/
static struct DDR	*OemList;			/* Array of DDR structures					*/

static unsigned	MaxOem;				/* Number of DDR structs in OEM list	*/
static unsigned	StrListLen; 		/* Number of bytes in string buffer 	*/
static long			lDataOffset;		/* Ptr offset in file to data area		*/

static unsigned	*RelocBuf;			/* Ptr to buffer for relocating data	*/

static int			iDiskType;			/* Distribution diskette type 1=360K,	*/
												/* 2 = 720K, 3 = 1.2meg, 4 = 1.44meg	*/

static unsigned	ShareAccess;



/***************************************************************************/
/* Initializes the data from the DOSDATA file. Allocates buffers and data	*/
/* lengths and then reads in the OEM list and the string buffer and then	*/
/* initializes the disk labels and list of files from each disk.				*/
/* 																								*/
/* void InitDosData( char *szFile )														*/
/* 																								*/
/* ARGUMENTS:	szFile	- Ptr to complete dosdata.dat file						*/
/* RETURNS: 	void																			*/
/* 																								*/
/***************************************************************************/

void InitDosData( char *szFile )
{
	register 	i;
	char			*szTmp;
	int			iFile;
	struct DDR	*Oem;

	if ( _osmajor < 3  || (_osmajor == 3 && _osminor < 10) )
		ShareAccess = O_RDONLY;
	else
		ShareAccess = SH_DENYWR;

										/* Start with NULL ptr for all data classes	*/
	szDosDataFile = szFile;
	for ( i = 0; i < END_CLASS; i++ )
		Data[ i ] = NULL;

	RelocBuf = GetMemory( RELOC_LEN );		/* Allocate a relocation buffer	*/

										/* Allocate buffers for and read in the list */
										/* of OEM structures and the data area which */
										/* contains all of the data strings 			*/

	if ( _dos_open( szDosDataFile, ShareAccess, &iFile	) == OK )
	{
		MaxOem = GetNextDataBlock( iFile, &OemList ) / sizeof( struct DDR );
		StrListLen = GetNextDataBlock( iFile, &pchStringBuf );

															/* Save start of OEM data area */

		lDataOffset = _dos_seek( iFile, 0L, SEEK_CUR ) + (long)USIZE;
		_dos_close( iFile );
														/* Load non-OEM specific data */
		if ( (Oem = GetOemRecord( szUpgrade, 0, 0 )) == NULL )
			FatalError( CORRUPT_DATA_ERROR );

		LoadOemData( Oem );
	}
	else
		FatalError( FATAL_DATA_READ_ERROR );

	szTmp = GetDataString( DISK_TYPE, 0 );
	if ( szTmp == NULL )
		FatalError( FATAL_DATA_READ_ERROR );
	else
		iDiskType = atoi( szTmp );
}


#if defined (UPGRADE_PROGRAM) || defined (OEM_PROGRAM)
/***************************************************************************/
/* Reads and stores the advertising banner strings in the DOSMSG file.     */
/* 																								*/
/* void InitBannerData (char *szFile)												   */
/* 																								*/
/* ARGUMENTS:	szFile	- Ptr to SETUP.MSG file                            */
/* RETURNS: 	void																			*/
/* 																								*/
/***************************************************************************/
void InitBannerData( char *szFile )
{
	register 	i, u;         /* Index variables               */
	char		*szBuffer;    /* Input line                    */
	int			iFile;        /* DOS file handle               */
   char *aszDefault[DEFAULT_BANNER_LINES];


   GetMessage (aszDefault, DEFAULT_BANNER_TEXT);
   ppszBanners = GetMemory (MAX_BANNER_SCREENS * sizeof (char **));

	if (_osmajor < 3  || (_osmajor == 3 && _osminor < 10))
      ShareAccess = O_RDONLY;
	else
	  ShareAccess = SH_DENYWR;

	if (_dos_open (szFile, ShareAccess, &iFile) != OK)
      {
        /* If the banner file isn't there, indiciate that there */
        /*   are no banners to display.                         */
        ppszBanners[0] = GetMemory (DEFAULT_BANNER_LINES * sizeof (char *));
        for (i=0; i < DEFAULT_BANNER_LINES-1; ++i)
          ppszBanners[0][i] = aszDefault[i];

        ppszBanners[1] = GetMemory (sizeof (char *));
        ppszBanners[1][0] = NULL;
        return;
      }

    szBuffer = GetMemory (MAX_SCRN_LINE_LEN + 1);

    /* Initalize the banner screen number */
    i = 0;

    /* Find the section */
    while (i < MAX_BANNER_SCREENS - 1 &&
           MyFindSection (BANNER_SECTION, iFile, (int) NULL) != TRUE)
      {
        /* Initialize the banner lines */
        ppszBanners[i] = GetMemory (MAX_BANNER_LINES * sizeof (char *));
        u = 0;

        while ((DosReadLine (szBuffer, MAX_SCRN_LINE_LEN, iFile)) == FALSE &&
               szBuffer[0] != '[')
          {
            /* Ignore lines beginning with a semi-colon */
            if (szBuffer[0] == ';')
              continue;

            if (u < MAX_BANNER_LINES - 1)
              {
                ppszBanners[i][u] = GetMemory (strlen (szBuffer) + 1);
                strcpy (ppszBanners[i][u++], szBuffer);
              }
          }

        /* Unread this line if it was a [section] so */
        /*   that MyFindSection can find it          */
        if (szBuffer[0] == '[')
          DosUnreadLine (szBuffer);

        /* NULL out this screen's last pointer */
        if (u < MAX_BANNER_LINES)
          ppszBanners[i][u] = NULL;

        /* Bump i */
        ++i;
      }

    /* NULL out the next screen's first pointer */
    if (i < MAX_BANNER_SCREENS)
      {
        ppszBanners[i] = GetMemory (sizeof (char *));
        ppszBanners[i][0] = NULL;
      }

    /* Close the message file */
    _dos_close (iFile);
}
#endif


/*********************************************************************
 * MyFindSection - Finds the specified section entry in fpInsertFile.
 *                 All information with fpInsertFile up to and including
 *                 the section line are written to fpOutputFile.
 *
 * szSection   - Section to search for.
 * iFileIn     - DOS filehandle to read.
 * iFileOut    - DOS filehandle to write, NULL if write is not required.
 *
 * Returns:  TRUE if an error occured, or the section was not found.
 *           FALSE if the section was found.
 *********************************************************************/

int MyFindSection (char *szSection, int iFileIn, int iFileOut)
{
  char *szBuffer;  /* Input buffer     */
  register int i;  /* Looping variable */


  /* Allocate sufficient space for szBuffer */
  szBuffer = GetMemory (MAX_SYSTEM_INI_LINE_LEN + 1);

  /* Read the line */
  while (DosReadLine (szBuffer, MAX_SYSTEM_INI_LINE_LEN, iFileIn) != TRUE)
    {
      /* Write the line out to the output file */
      if (iFileOut)
        DosWriteLine (szBuffer, iFileOut);

      /* Skip whitespace at beginning of szBuffer */
      for (i = 0; i < MAX_SYSTEM_INI_LINE_LEN && szBuffer[i] != '\0' &&
                   (szBuffer[i] == ' ' || szBuffer[i] == '\t');  ++i)
        ;

      /* Do we have a match */
      if (strnicmp (szSection, &szBuffer[i], strlen (szSection)) == 0)
        {
          FreeMemory (szBuffer);
          return (FALSE);
        }
    }

  /* Section was not found */
  FreeMemory (szBuffer);
  return (TRUE);
}

char *szUnreadLine = NULL;  /* Stores the unread line */
int iUnread = -1;           /* Index to the unread line */

/*********************************************************************
 * DosUnreadLine - Stores a line of text to pass out of DosReadLine.
 *
 * szBuffer - String is to be stored
 *
 * Returns:  Nothing.
 *********************************************************************/

void DosUnreadLine (char *szBuffer)
{
  szUnreadLine = GetMemory (strlen (szBuffer) + 1);
  strcpy (szUnreadLine, szBuffer);
  iUnread = 0;
}

/*********************************************************************
 * DosReadLine - Reads a single text line from disk using _dos_read.
 *
 * szBuffer - String is stored here
 * iLength  - Maximum number of characters to read
 * iFile    - DOS file handle
 *
 * Returns:  TRUE at end of file, FALSE otherwise.
 *********************************************************************/

int DosReadLine (char *szBuffer, int iLength, int iFile)
{
  int  i = 0;                 /* Index for szBuffer                 */
  int  c = 0x7F;              /* Character read in from disk        */
  int  iNext;                 /* Next Character read in from disk   */

  /* BUGBUG 27-Feb-1993 bens Bogus input routine
   *
   * The following loop is not very graceful about handling long lines.
   * Current behavior with the "--iLength" in the for loop causes us to
   * read n-1 characters into the buffer, and then stop, leaving room
   * to put the null terminator.
   *
   * The "feature" of this loop is that lines longer than iLength will
   * be split into two or more lines.
   */

  while (--iLength && c != '\0')
    {
      /* Pull from the "unread" data first */
      if (iUnread != -1)
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -