msdsys.c
资源名称:DOS系统的源代码.rar [点击查看]
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:77k
源码类别:
操作系统开发
开发平台:
Visual C++
- /*********************************************************************
- * Microsoft Diagnostics Version 2.0
- *
- * A diagnostic utility to detect as much useful information about a
- * customer's computer system as is possible.
- *
- * Microsoft Diagnostics: We detect the World.
- *
- * MSDSYS.C - Source file for system related code (ie file I/O).
- ********************************************************************/
- /* Include Files */
- #include "msd.h"
- /********************************************************************
- * OpenFile - Opens a file and provides appropriate error handling.
- *
- * pszFilename - Name of file
- * pszMode - Mode to open the file.
- * fShowError - Displays errors when TRUE.
- *
- * Returns: FILE handle, or NULL if an error condition occured.
- ********************************************************************/
- FILE * OpenFile (PSZ pszFilename, PSZ pszMode, BOOL fShowError)
- {
- FILE *fp; /* Local storage for the file pointer */
- /* Open the file */
- fp = fopen (pszFilename, pszMode);
- /* Give appropriate error message, if necessary */
- if (fShowError && (fp == NULL || fCriticalError))
- {
- fCriticalError = FALSE;
- ShowError (ERR_OK_BUTTON, pszErrorOpening, pszFilename,
- _strerror (NULL));
- return (NULL);
- }
- /* If all went well, return the file pointer to the calling routine */
- return (fp);
- }
- /********************************************************************
- * CloseFile - Closes a file and provides appropriate error handling.
- *
- * fp - File handle to close
- *
- * Returns: TRUE if an error occured.
- ********************************************************************/
- BOOL CloseFile (FILE *fp)
- {
- WORD wReturnValue; /* Return value from fclose */
- /* Close the file */
- wReturnValue = fclose (fp);
- /* Give appropriate error message, if necessary */
- if (wReturnValue == EOF)
- {
- fCriticalError = FALSE;
- ShowError (ERR_OK_BUTTON, pszErrorClosing, NULL, _strerror (NULL));
- return (TRUE);
- }
- return (FALSE);
- }
- /**********************************************************************
- * CreateTempFile - Uses a DOS 3+ call to create a unique file
- *
- * pszPathname - Path to where the temp file needs to go.
- *
- * Returns: Error number:
- * 03 - Path not found.
- * 04 - No more handles.
- * 05 - Access denied.
- **********************************************************************/
- WORD CreateTempFile (PSZ pszPathname)
- {
- union REGS inregs, outregs; /* Register values for int86x */
- struct SREGS sregs; /* Segment register values */
- CHAR FAR * fpszPathname = (CHAR FAR *) pszPathname;
- inregs.h.ah = 0x5A;
- inregs.x.cx = 0;
- sregs.ds = (WORD) FP_SEG (fpszPathname);
- inregs.x.dx = (WORD) FP_OFF (fpszPathname);
- int86x (0x21, &inregs, &outregs, &sregs);
- if (outregs.x.cflag)
- return (outregs.x.ax);
- else
- return (0);
- }
- /**********************************************************************
- * DeleteFile - Deletes file specified by pszFilename
- *
- * pszFilename - File to delete
- *
- * Returns: Error number:
- * 02 - File not found.
- * 03 - Path not found.
- * 05 - Access denied.
- **********************************************************************/
- WORD DeleteFile (PSZ pszPathname)
- {
- union REGS inregs, outregs; /* Register values for intdos */
- struct SREGS sregs; /* Segment register values */
- CHAR FAR * fpszPathname = (CHAR FAR *) pszPathname;
- inregs.h.ah = 0x41;
- sregs.ds = (WORD) FP_SEG (fpszPathname);
- inregs.x.dx = (WORD) FP_OFF (fpszPathname);
- int86x (0x21, &inregs, &outregs, &sregs);
- if (outregs.x.cflag)
- return (outregs.x.ax);
- else
- return (0);
- }
- /**********************************************************************
- * RenameFile - Renames a file.
- *
- * pszPathname1 - File to rename.
- * pszPathname2 - New filename.
- *
- * Returns: Error number:
- * 02 - File not found.
- * 03 - Path not found.
- * 05 - Access denied.
- * 17 - (11H) Not the same device.
- **********************************************************************/
- WORD RenameFile (PSZ pszPathname1, PSZ pszPathname2)
- {
- union REGS inregs, outregs; /* Register values for intdos */
- struct SREGS sregs; /* Segment register values */
- CHAR FAR * fpszPathname1 = (CHAR FAR *) pszPathname1;
- CHAR FAR * fpszPathname2 = (CHAR FAR *) pszPathname2;
- inregs.h.ah = 0x56;
- sregs.ds = (WORD) FP_SEG (fpszPathname1);
- inregs.x.dx = (WORD) FP_OFF (fpszPathname1);
- sregs.es = (WORD) FP_SEG (fpszPathname2);
- inregs.x.di = (WORD) FP_OFF (fpszPathname2);
- int86x (0x21, &inregs, &outregs, &sregs);
- if (outregs.x.cflag)
- return (outregs.x.ax);
- else
- return (0);
- }
- WORD wNmbrFound = 0;
- /*********************************************************************
- * FindFile - Finds all of the pszFilename files on the system.
- *
- * pszFilename - Filename to find.
- *
- * pszPathname - Path to start searching from (NULL if it's to be
- * ignored).
- *
- * fSearchFlags - SEARCH_FLOPPIES Search floppies.
- * SEARCH_LOCAL_DRIVES Search local hard disks.
- * SEARCH_NET_DRIVES Search net drives (and
- * all other drives).
- * SEARCH_ROOT Search the root directory.
- * RECURSE_INTO_SUB_DIRS Search recursively into
- * subdirectories.
- *
- * Only one of the following should be specified at
- * one time:
- * SEARCH_LANMAN_ROOT Searches in the LANMAN
- * root directory.
- * SEARCH_WINDIR Uses the "windir="
- * environment variable.
- * SEARCH_BOOT_DRIVE Search just the boot drive.
- *
- * chDriveLetter - If fSearchFlags does not specify the drive type(s)
- * to search, this contains the drive letter to
- * search. (' ' to search current drive).
- *
- * Returns: Pointer to an array of strings to pszFilename files, the
- * last pointer is a NULL pointer. If pszFilename could
- * not be found, or an error occured, the first pointer is a
- * NULL.
- *********************************************************************/
- FILE_INFO FAR *FindFile (PSZ pszFilename,
- PSZ pszPathname,
- BOOL fSearchFlags,
- CHAR chDriveLetter)
- {
- CHAR chCurrentPath[_MAX_PATH + 1]; /* Stores current drive & directory */
- WORD wCurrentDrive; /* Stores the current drive number */
- WORD i; /* Looping variable */
- DISK_STRUCT *pDisk = NULL; /* Pointer to disk drive info */
- /* structure */
- OS_VERSION_STRUCT *pOsVer = NULL; /* Pointer to DOS info structure */
- BOOL fReturnValue = FALSE; /* Stores the return value from */
- /* fuctions */
- FILE_INFO FAR *pFileInfo = NULL; /* Pointer to file info linked list */
- FILE_INFO FAR *pfi = NULL; /* Another pointer to file info list */
- /* (this one is changed by the */
- /* called routines). */
- /* Save the current drive and directory */
- wCurrentDrive = _getdrive();
- _getdcwd (wCurrentDrive, chCurrentPath, _MAX_PATH);
- /* Allocate enough room for the find file info */
- pFileInfo = _fmalloc (sizeof (FILE_INFO));
- if (pFileInfo == NULL)
- {
- OutOfMemory();
- return (NULL);
- }
- pfi = pFileInfo;
- /* Set the first pointer to null, to show that */
- /* this is the last on the list. */
- pFileInfo->fpNextFileInfo = NULL;
- /* Get the disk and operating system structures */
- fReturnValue = GetFindFileInfo (&pDisk, &pOsVer, fSearchFlags);
- if (fReturnValue)
- {
- FreeFileInfo (pFileInfo);
- return (NULL);
- }
- /* Zero out the counter for files found */
- wNmbrFound = 0;
- /* Change to the appropriate drive and directory if necessary */
- if (pszPathname != NULL)
- {
- /* Check to see if a drive was passed to us */
- if (pszPathname[1] == ':')
- {
- WORD wDrive = toupper (pszPathname[0]) - 'A' + 1;
- if (_chdrive (wDrive))
- {
- MessageBox ("Drive does not exist", pszPathname, NULL, MB_OK | 0x8000);
- return (NULL);
- }
- if (chdir (&pszPathname[2]))
- {
- MessageBox (pszPathNotThere, pszPathname, NULL, MB_OK | 0x8000);
- return (NULL);
- }
- }
- else
- if (chdir (pszPathname))
- {
- MessageBox (pszPathNotThere, pszPathname, NULL, MB_OK | 0x8000);
- return (NULL);
- }
- }
- /* Boot drive search */
- if (fSearchFlags & SEARCH_BOOT_DRIVE)
- {
- FindOnBootDrive (&pfi,
- pDisk,
- pOsVer,
- pszFilename,
- fSearchFlags);
- }
- else if (fSearchFlags & SEARCH_WINDIR)
- {
- /* Find the "windir=" environment variable */
- for (i = 0;
- environ[i][0] != ' ' && memcmp ("windir=", environ[i], 7) != 0;
- ++i)
- ;
- /* If found, put the fully qualified path into chWinDir */
- if (environ[i][0] == 'w')
- {
- /* Change to the drive and directory of the file */
- chDriveLetter = environ[i][7];
- chdir (&environ[i][9]);
- /* Find the file */
- FindFileOnDrive (&pfi,
- pszFilename,
- fSearchFlags,
- chDriveLetter);
- }
- else
- {
- /* Free up pFileInfo */
- _ffree (pFileInfo);
- /* Set the flags for finding the windows file the hard way */
- fSearchFlags = SEARCH_LOCAL_DRIVES |
- SEARCH_ROOT |
- RECURSE_INTO_SUB_DIRS;
- /* Find the file */
- pFileInfo = FindFile (pszFilename, pszPathname,
- fSearchFlags, chDriveLetter);
- }
- }
- else if (fSearchFlags & SEARCH_LANMAN_ROOT)
- {
- unsigned short int err=0, ta=0;
- struct wksta_info_0 *wksta0;
- char wkstabuf[BUFSIZ];
- CHAR chBuffer[_MAX_PATH + 1];
- /* Get the LANMAN root */
- err = NetWkstaGetInfo (NULL, 0, wkstabuf, BUFSIZ, &ta);
- if (err == 0)
- {
- wksta0 = (struct wksta_info_0 *) wkstabuf;
- _fmemcpy (chBuffer, wksta0->wki0_root, _MAX_PATH);
- /* Change to the drive and directory of the file */
- chDriveLetter = chBuffer[0];
- chdir (&chBuffer[2]);
- /* Find the file */
- FindFileOnDrive (&pfi,
- pszFilename,
- fSearchFlags,
- chDriveLetter);
- }
- else
- {
- /* Free up pFileInfo */
- _ffree (pFileInfo);
- /* Set the flags for finding the LANMAN file the hard way */
- fSearchFlags = SEARCH_LOCAL_DRIVES |
- SEARCH_ROOT |
- RECURSE_INTO_SUB_DIRS;
- /* Find the file */
- pFileInfo = FindFile (pszFilename, pszPathname,
- fSearchFlags, chDriveLetter);
- }
- }
- else if ((fSearchFlags & (SEARCH_FLOPPIES |
- SEARCH_LOCAL_DRIVES |
- SEARCH_NET_DRIVES |
- SEARCH_BOOT_DRIVE)) == 0)
- {
- /* Single drive search */
- FindFileOnDrive (&pfi,
- pszFilename,
- fSearchFlags,
- chDriveLetter);
- }
- else
- {
- /* Search 'em all */
- for (i = 0; i < pDisk->wNmbrDrives; ++i)
- {
- /* Floppy Search */
- if ((fSearchFlags & SEARCH_FLOPPIES) &&
- (pDisk->asdi[i].wDriveType == DISK_FLOPPY_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_525_360K ||
- pDisk->asdi[i].wDriveType == DISK_525_12M ||
- pDisk->asdi[i].wDriveType == DISK_35_720K ||
- pDisk->asdi[i].wDriveType == DISK_SINGLE_DENSITY_8_INCH ||
- pDisk->asdi[i].wDriveType == DISK_DOUBLE_DENSITY_8_INCH ||
- pDisk->asdi[i].wDriveType == DISK_35_144M ||
- pDisk->asdi[i].wDriveType == DISK_OPTICAL_DISK ||
- pDisk->asdi[i].wDriveType == DISK_35_288M))
- {
- FindFileOnDrive (&pfi,
- pszFilename,
- fSearchFlags,
- pDisk->asdi[i].chDriveLetter);
- }
- /* Local drive search */
- if ((fSearchFlags & SEARCH_LOCAL_DRIVES) &&
- (pDisk->asdi[i].wDriveType == DISK_FIXED_DISK ||
- pDisk->asdi[i].wDriveType == DISK_RAM_DISK ||
- pDisk->asdi[i].wDriveType == DISK_CD_ROM_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_SUBST_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_ASSIGN_DRIVE))
- {
- FindFileOnDrive (&pfi,
- pszFilename,
- fSearchFlags,
- pDisk->asdi[i].chDriveLetter);
- }
- /* Remote/Net drive search */
- if ((fSearchFlags & SEARCH_NET_DRIVES) &&
- pDisk->asdi[i].wDriveType == DISK_REMOTE_DRIVE)
- {
- FindFileOnDrive (&pfi,
- pszFilename,
- fSearchFlags,
- pDisk->asdi[i].chDriveLetter);
- }
- }
- }
- /* Restore the current drive and directory */
- _chdrive (wCurrentDrive);
- chdir (chCurrentPath);
- /* Free up the disk and operating system info */
- free (pDisk);
- free (pOsVer);
- return (pFileInfo);
- }
- /*********************************************************************
- * FindOnBootDrive - Finds a particular file on the boot drive. If
- * the operating system does not have the ability
- * to return the boot drive, it will check the first
- * hard disk, the first floppy, then all other
- * drives on the system (based on the flags set in
- * fSearchFlags, of course).
- *
- * ppFileInfo - Pointer to file info structure's pointer.
- * pszFilename - Filename to search for.
- * fSearchFlags - Flags to control the search.
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL FindOnBootDrive (FILE_INFO FAR * FAR *ppFileInfo,
- DISK_STRUCT *pDisk,
- OS_VERSION_STRUCT *pOsVer,
- PSZ pszFilename,
- BOOL fSearchFlags)
- {
- BOOL fSkipFirstFloppy = TRUE; /* Allows us to skip drives */
- BOOL fSkipFirstHardDisk = TRUE; /* we already checked */
- /* Check to see if DOS can tell us it's boot drive */
- if (pOsVer->wDosMajor >= 4)
- {
- /* Set the flags for the appropriate search */
- fSearchFlags = fSearchFlags | SEARCH_ROOT;
- /* Find it */
- FindFileOnDrive (ppFileInfo,
- pszFilename,
- fSearchFlags,
- pOsVer->chDosBootDrive);
- }
- else
- {
- WORD i; /* Looping variable */
- /* We have to hunt for a suitable boot drive */
- /* Set the flags for the appropriate search */
- fSearchFlags = fSearchFlags |
- SEARCH_FLOPPIES |
- SEARCH_LOCAL_DRIVES |
- SEARCH_ROOT;
- /* Check the first hard disk */
- if (fSearchFlags & SEARCH_LOCAL_DRIVES)
- {
- for (i = 0; i < pDisk->wNmbrDrives; ++i)
- {
- if (pDisk->asdi[i].wDriveType == DISK_FIXED_DISK ||
- pDisk->asdi[i].wDriveType == DISK_RAM_DISK ||
- pDisk->asdi[i].wDriveType == DISK_CD_ROM_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_SUBST_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_ASSIGN_DRIVE)
- {
- FindFileOnDrive (ppFileInfo,
- pszFilename,
- fSearchFlags,
- pDisk->asdi[i].chDriveLetter);
- break;
- }
- }
- }
- /* Check the first floppy */
- if (fSearchFlags & SEARCH_FLOPPIES)
- {
- for (i = 0; i < pDisk->wNmbrDrives; ++i)
- {
- if (pDisk->asdi[i].wDriveType == DISK_FLOPPY_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_525_360K ||
- pDisk->asdi[i].wDriveType == DISK_525_12M ||
- pDisk->asdi[i].wDriveType == DISK_35_720K ||
- pDisk->asdi[i].wDriveType == DISK_SINGLE_DENSITY_8_INCH ||
- pDisk->asdi[i].wDriveType == DISK_DOUBLE_DENSITY_8_INCH ||
- pDisk->asdi[i].wDriveType == DISK_35_144M ||
- pDisk->asdi[i].wDriveType == DISK_OPTICAL_DISK ||
- pDisk->asdi[i].wDriveType == DISK_35_288M)
- {
- FindFileOnDrive (ppFileInfo,
- pszFilename,
- fSearchFlags,
- pDisk->asdi[i].chDriveLetter);
- break;
- }
- }
- }
- /* Check all other drives */
- for (i = 0; i < pDisk->wNmbrDrives; ++i)
- {
- /* Floppy drive check */
- if (pDisk->asdi[i].wDriveType == DISK_FLOPPY_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_525_360K ||
- pDisk->asdi[i].wDriveType == DISK_525_12M ||
- pDisk->asdi[i].wDriveType == DISK_35_720K ||
- pDisk->asdi[i].wDriveType == DISK_SINGLE_DENSITY_8_INCH ||
- pDisk->asdi[i].wDriveType == DISK_DOUBLE_DENSITY_8_INCH ||
- pDisk->asdi[i].wDriveType == DISK_35_144M ||
- pDisk->asdi[i].wDriveType == DISK_OPTICAL_DISK ||
- pDisk->asdi[i].wDriveType == DISK_35_288M)
- {
- if (fSearchFlags & SEARCH_FLOPPIES)
- {
- /* This is a floppy and we are */
- /* searching floppies. */
- if (fSkipFirstFloppy)
- {
- fSkipFirstFloppy = FALSE;
- continue;
- }
- FindFileOnDrive (ppFileInfo,
- pszFilename,
- fSearchFlags,
- pDisk->asdi[i].chDriveLetter);
- continue;
- }
- else
- {
- /* This is a floppy, and we aren't */
- /* searching floppies. */
- continue;
- }
- }
- /* Hard Disk check */
- if (pDisk->asdi[i].wDriveType == DISK_FIXED_DISK ||
- pDisk->asdi[i].wDriveType == DISK_RAM_DISK ||
- pDisk->asdi[i].wDriveType == DISK_CD_ROM_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_SUBST_DRIVE ||
- pDisk->asdi[i].wDriveType == DISK_ASSIGN_DRIVE)
- {
- if (fSearchFlags & SEARCH_LOCAL_DRIVES)
- {
- /* This is a hard disk and we are */
- /* searching hard disks. */
- if (fSkipFirstHardDisk)
- {
- fSkipFirstHardDisk = FALSE;
- continue;
- }
- FindFileOnDrive (ppFileInfo,
- pszFilename,
- fSearchFlags,
- pDisk->asdi[i].chDriveLetter);
- continue;
- }
- else
- {
- /* This is a hard disk, and we aren't */
- /* searching hard disks. */
- continue;
- }
- }
- /* Network drive type check */
- if (pDisk->asdi[i].wDriveType == DISK_REMOTE_DRIVE)
- {
- if (fSearchFlags & SEARCH_NET_DRIVES)
- {
- /* This is a remote drive and we are */
- /* searching remote drives. */
- FindFileOnDrive (ppFileInfo,
- pszFilename,
- fSearchFlags,
- pDisk->asdi[i].chDriveLetter);
- continue;
- }
- else
- {
- /* This is a remote drive, and we aren't */
- /* searching remote drives. */
- continue;
- }
- }
- }
- }
- return (FALSE);
- }
- /*********************************************************************
- * FindFileOnDrive - Searches a single drive for the appropriate
- * file(s).
- *
- * ppFileInfo - Pointer to current file info structure.
- * pszFilename - Pointer to filename to search for.
- * fSearchFlags - Flags to control the searching method.
- * chDriveLetter - Drive to search.
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL FindFileOnDrive (FILE_INFO FAR * FAR *ppFileInfo,
- PSZ pszFilename,
- BOOL fSearchFlags,
- CHAR chDriveLetter)
- {
- CHAR chCurrentPath[_MAX_PATH + 1]; /* Stores current drive & directory */
- WORD wCurrentDrive; /* Stores the current drive number */
- WORD wReturnValue; /* Return value from some functions */
- /* Change to the requested drive */
- if (chDriveLetter != ' ')
- {
- wReturnValue = _chdrive (chDriveLetter - 'A' + 1);
- if (wReturnValue != 0 || fCriticalError)
- {
- fCriticalError = FALSE;
- return (TRUE);
- }
- }
- /* Save the current drive and directory */
- wCurrentDrive = _getdrive();
- _getdcwd (wCurrentDrive, chCurrentPath, _MAX_PATH);
- /* Change to the root directory, if necessary */
- if (fSearchFlags & SEARCH_ROOT)
- {
- wReturnValue = chdir ("\");
- if (wReturnValue != 0 || fCriticalError)
- {
- fCriticalError = FALSE;
- return (TRUE);
- }
- }
- /* Search the current working directory */
- wReturnValue = FindFileInCwd (ppFileInfo, pszFilename, fSearchFlags);
- if (wReturnValue)
- return (wReturnValue);
- /* Restore the current drive and directory */
- _chdrive (wCurrentDrive);
- chdir (chCurrentPath);
- return (FALSE);
- }
- /*********************************************************************
- * FindFileInCwd - Searches the current working directory for the
- * appropriate file(s).
- *
- * ppFileInfo - Pointer to current file info structure.
- * pszFilename - Pointer to filename to search for.
- * fSearchFlags - Flags to control the searching method.
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL FindFileInCwd (FILE_INFO FAR * FAR *ppFileInfo,
- PSZ pszFilename,
- BOOL fSearchFlags)
- {
- WORD wReturnValue; /* Return value from _dos_findfirst/next */
- struct find_t ft; /* Structure of file data */
- FILE_INFO FAR *pfi = NULL; /* Far pointer to a file info structure */
- PSZ pszCurrentDir = NULL; /* Stores current directory */
- wReturnValue = _dos_findfirst (pszFilename, 0xFFFF, &ft);
- if (wReturnValue == 0 && fCriticalError == FALSE)
- {
- do
- {
- /* Search was successful */
- if (++wNmbrFound > 255)
- {
- MessageBox ("255 Files Maximum", NULL, NULL, MB_OK | 0x8000);
- return (TRUE);
- }
- /* Find a new place to store information */
- pfi = _fmalloc (sizeof (FILE_INFO));
- if (pfi == NULL)
- {
- OutOfMemory();
- return (TRUE);
- }
- /* Zero out pfi's "next" pointer */
- pfi->fpNextFileInfo = NULL;
- /* Make current pointer's "next" pointer point to */
- /* this new location. */
- (*ppFileInfo)->fpNextFileInfo = (VOID FAR *) pfi;
- /* Fill in the values */
- (*ppFileInfo)->bAttrib = ft.attrib;
- (*ppFileInfo)->wTime = ft.wr_time;
- (*ppFileInfo)->wDate = ft.wr_date;
- (*ppFileInfo)->dwSize = ft.size;
- /* Put in the fully qualified path */
- pszCurrentDir = malloc (_MAX_PATH + 1);
- if (pszCurrentDir == NULL)
- {
- OutOfMemory();
- return (TRUE);
- }
- if (_getdcwd (0, pszCurrentDir, _MAX_PATH) == NULL)
- {
- free (pszCurrentDir);
- OutOfMemory();
- return (TRUE);
- }
- if (pszCurrentDir[strlen (pszCurrentDir) - 1] != '\')
- strcat (pszCurrentDir, "\");
- strcat (pszCurrentDir, ft.name);
- /* Find a new place to store the path to the file */
- (*ppFileInfo)->fpszPathToFile =
- _fmalloc (strlen (pszCurrentDir) + 1);
- if ((*ppFileInfo)->fpszPathToFile == NULL)
- {
- free (pszCurrentDir);
- OutOfMemory();
- return (TRUE);
- }
- _fstrcpy ((*ppFileInfo)->fpszPathToFile,
- (CHAR FAR *) pszCurrentDir);
- /* Get the version number info */
- if (fSearchFlags & SEARCH_VERSION)
- {
- BYTE * pVer, * pVer2; /* VS_VERSION_INFO "struct" */
- VS_FIXEDFILEINFO *pValue; /* VS_FIXEDFILEINFO struct */
- /* Get the version "structs" */
- pVer = GetFileVersion (pszCurrentDir, TRUE);
- /* Store a duplicate for free'ing purposes */
- pVer2 = pVer;
- if (pVer != NULL)
- {
- /* Align pVer on a 32 bit boundary */
- pVer = DWORDUP (pVer);
- /* Move past the first two WORDs */
- pVer += 4;
- /* Move past the string */
- while (*pVer != ' ')
- ++pVer;
- /* Set the pValue structure pointer */
- pValue = (VS_FIXEDFILEINFO *) (DWORDUP (pVer + 1));
- /* Set the values in the fileinfo structure */
- (*ppFileInfo)->dwFileVersionMS = pValue->dwFileVersionMS;
- (*ppFileInfo)->dwFileVersionLS = pValue->dwFileVersionLS;
- /* Free up the memory allocated in GetFileVersion */
- free (pVer2);
- }
- else
- {
- (*ppFileInfo)->dwFileVersionMS = 0;
- (*ppFileInfo)->dwFileVersionLS = 0;
- }
- }
- else
- {
- (*ppFileInfo)->dwFileVersionMS = 0;
- (*ppFileInfo)->dwFileVersionLS = 0;
- }
- free (pszCurrentDir);
- /* Set the current pointer to the new area */
- *ppFileInfo = (FILE_INFO FAR *) pfi;
- }
- while ((wReturnValue = _dos_findnext (&ft)) == 0);
- }
- /* Return if there is a critical error */
- if (fCriticalError)
- {
- fCriticalError = FALSE;
- return (TRUE);
- }
- /* Now, search for subdirectories to recurse into */
- if (fSearchFlags & RECURSE_INTO_SUB_DIRS)
- {
- /* Begin searching for subdirectories */
- wReturnValue = _dos_findfirst ("*.*", 0xFFFF, &ft);
- if (wReturnValue == 0 && fCriticalError == FALSE)
- {
- do
- {
- BOOL fReturnValue; /* Return value from FindFileInCwd */
- /* Search was successful */
- /* If this was not a subdirectory, skip it */
- if ((ft.attrib & _A_SUBDIR) == 0)
- continue;
- /* If this is the subdirectory "." or "..", skip it */
- if (strcmp (ft.name, pszDot) == 0 ||
- strcmp (ft.name, pszDotDot) == 0)
- continue;
- /* Change to the new subdirectory */
- if (chdir (ft.name) != 0)
- return (TRUE);
- /* Recurse into this subdirectory */
- fReturnValue = FindFileInCwd (ppFileInfo,
- pszFilename,
- fSearchFlags);
- if (fReturnValue)
- return (fReturnValue);
- /* Change back to the current directory */
- if (chdir ("..") != 0)
- return (TRUE);
- }
- while ((wReturnValue = _dos_findnext (&ft)) == 0);
- }
- }
- /* Return if there is a critical error */
- if (fCriticalError)
- {
- fCriticalError = FALSE;
- return (TRUE);
- }
- return (FALSE);
- }
- /*********************************************************************
- * GetFindFileInfo - Obtains the disk and DOS information for the
- * FindFile() routine.
- *
- * ppDisk - Pointer to disk structure pointer.
- * ppOsVer - Pointer to operating system structure pointer.
- * fSearchFlags - Flags to control the searching method.
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL GetFindFileInfo (DISK_STRUCT **ppDisk,
- OS_VERSION_STRUCT **ppOsVer,
- BOOL fSearchFlags)
- {
- BOOL fReturnValue; /* Stores the return value from fuctions */
- WORD wSize; /* Number of bytes to malloc */
- /* Get the minimum disk drive information */
- wSize = GetInfoSize (IDI_DISK_DRIVE_RECORD, FALSE);
- *ppDisk = malloc (wSize);
- if (*ppDisk == NULL)
- {
- OutOfMemory();
- return (TRUE);
- }
- /* Zero out the structure */
- memset (*ppDisk, ' ', wSize);
- /* Get the information, TRUE for minimum info, FALSE for header */
- /* record, TRUE for report flag */
- fReturnValue = GetInfo (IDI_DISK_DRIVE_RECORD, *ppDisk, TRUE, FALSE, TRUE);
- if (fReturnValue)
- {
- free (*ppDisk);
- OutOfMemory();
- return (TRUE);
- }
- /* Get the operating system info */
- if (fSearchFlags & SEARCH_BOOT_DRIVE)
- {
- wSize = GetInfoSize (IDI_OS_VERSION_RECORD, FALSE);
- *ppOsVer = malloc (wSize);
- if (*ppOsVer == NULL)
- {
- free (*ppDisk);
- OutOfMemory();
- return (TRUE);
- }
- /* Zero out the structure */
- memset (*ppOsVer, ' ', wSize);
- fReturnValue = GetInfo (IDI_OS_VERSION_RECORD, *ppOsVer,
- FALSE, FALSE, TRUE);
- if (fReturnValue)
- {
- free (*ppDisk);
- free (*ppOsVer);
- OutOfMemory();
- return (TRUE);
- }
- }
- return (FALSE);
- }
- /*********************************************************************
- * FreeFileInfo - Frees up the memory allocated to a FILE_INFO array.
- *
- * pFileInfo - Pointer to the array of FILE_INFOs to free.
- *********************************************************************/
- VOID FreeFileInfo (FILE_INFO FAR *pFileInfo)
- {
- FILE_INFO FAR * pfi = NULL; /* Pointer to FILE_INFO structure */
- if (pFileInfo == NULL)
- return;
- while (pFileInfo->fpNextFileInfo != NULL)
- {
- pfi = (FILE_INFO FAR *) pFileInfo->fpNextFileInfo;
- _ffree (pFileInfo->fpszPathToFile);
- _ffree (pFileInfo->fpNextFileInfo);
- pFileInfo = (FILE_INFO FAR *) pfi;
- }
- }
- VOID ProceduralLangChk (INT argc, PSZ argv[], BOOL fFlag)
- {
- /* */
- BOOL fReturnValue = 0;
- PSZ psz1 = maxParsedLine + 2;
- PSZ psz2 = maxParsedLine + 6;
- WORD * pw;
- if (fFlag)
- {
- fReturnValue = ParseLine (argv[argc - 1]) | 0xDF80;
- }
- else
- fReturnValue = 0xFF80;
- fFlag = (fFlag) ? 0 : 1;
- fReturnValue = fReturnValue >> 5;
- maxParsedLine = (((fReturnValue >> 8) + 1) & fParserBitmask) ? psz1 : psz2;
- pw = (WORD *) maxParsedLine;
- --pw;
- *pw = fReturnValue; /*
- */
- }
- #if HEAP_DEBUG
- /*********************************************************************
- * NoMemory - Displays the insufficient memory message (debug version)
- *
- * No parameters or return values.
- *********************************************************************/
- VOID NoMemory (PSZ pszFile, WORD wLine)
- {
- CHAR chBuffer1[80]; /* Local string buffer */
- CHAR chBuffer2[80]; /* Local string buffer */
- HeapCheck ("Inside OOM Check");
- sprintf (chBuffer1, "%s:%u", pszFile, wLine);
- sprintf (chBuffer2, "_memavl = %u, _memmax = %u", _memavl(), _memmax());
- ShowError (ERR_OK_BUTTON, pszInsufMemory, chBuffer1, chBuffer2);
- HeapCheck ("Inside OOM Check");
- }
- #else
- /*********************************************************************
- * NoMemory - Displays the insufficient memory message (release version)
- *
- * No parameters or return values.
- *********************************************************************/
- VOID NoMemory (VOID)
- {
- ShowError (ERR_OK_BUTTON, pszInsufMemory, NULL, NULL);
- }
- #endif
- /*********************************************************************
- * AllocStringSpace - Allocates space for string pointers and string
- * data.
- *
- * wNmbrStrings - Number of string pointers to allocate.
- * wNmbrChars - Total number of characters to allocate.
- *
- * Returns: Pointer to string pointer array.
- *********************************************************************/
- QSZ * AllocStringSpace (WORD wNmbrStrings,
- WORD wNmbrChars)
- {
- QSZ * pqszStrings; /* String pointer */
- /* Allocate space for the pointer area and string area */
- #if HEAP_DEBUG
- HeapCheck ("Inside AllocStringSpace");
- _heapset ('1');
- #endif
- if ((pqszStrings = calloc (wNmbrStrings + 1, sizeof (QSZ))) != NULL)
- pqszStrings[0] = Qmalloc (wNmbrChars);
- #if HEAP_DEBUG
- HeapCheck ("Inside AllocStringSpace");
- _heapset ('2');
- #endif
- if (pqszStrings == NULL || pqszStrings[0] == NULL)
- {
- free (pqszStrings);
- OutOfMemory();
- return (NULL);
- }
- return (pqszStrings);
- }
- /*********************************************************************
- * FreeStringSpace - Frees strings allocated via AllocStringSpace.
- *
- * pqszStrings - Pointer to string pointer array.
- *********************************************************************/
- VOID FreeStringSpace (QSZ *pqszStrings)
- {
- Qfree (pqszStrings[0]);
- free (pqszStrings);
- }
- /*********************************************************************
- * DisplayLen - Calculates the length of a displayed line, skipping
- * over the '&' control characters.
- *
- * qszString - String pointer.
- *
- * Returns: Displayed length of string.
- *********************************************************************/
- WORD DisplayLen (QSZ qszString)
- {
- WORD i; /* Looping variable */
- WORD wLength; /* Displayed length of the string */
- for (i = 0, wLength = 0; qszString[i] != ' '; ++i, ++wLength)
- {
- /* Is this a control character */
- if (qszString[i] == '&')
- {
- ++i;
- /* &# == Alternate color */
- if (qszString[i] >= '1' &&
- qszString[i] <= '3')
- ++i;
- /* &0 == Normal color */
- if (qszString[i] == '0')
- ++i;
- /* Now check to see if we are at the */
- /* end of the string */
- if (qszString[i] == ' ')
- break;
- }
- }
- return (wLength);
- }
- /*********************************************************************
- * QstrcatAlign - Concatinates a string, right aligned to a particular
- * column.
- *
- * qszString1 - String that will have qszString2 added to it.
- * qszString2 - String to be added to qszString1.
- * WORD wIndent - Column for alignment.
- *
- * Returns: Pointer to qszString1.
- *********************************************************************/
- QSZ QstrcatAlign (QSZ qszString1, QSZ qszString2, WORD wIndent)
- {
- WORD wLength; /* Length of qszString1 */
- WORD wDisLen; /* Displayed length of qszString1 */
- WORD wNewIndent; /* New indent, if the original indent was too small */
- wLength = Qstrlen (qszString1);
- wDisLen = DisplayLen (qszString1);
- wNewIndent = ((INT) wIndent - (INT) wDisLen > 0) ? wIndent - wDisLen : 0;
- return (QstrcpyAlign (&qszString1[wLength], qszString2, wNewIndent));
- }
- /*********************************************************************
- * QstrcpyAlign - Copies a string, right aligned to a particular
- * column.
- *
- * qszString1 - String that will have qszString2 copied to it.
- * qszString2 - String to be copied to qszString1.
- * WORD wIndent - Column for alignment.
- *
- * Returns: Pointer to qszString1.
- *********************************************************************/
- QSZ QstrcpyAlign (QSZ qszString1, QSZ qszString2, WORD wIndent)
- {
- WORD wLength; /* Length of pszString2 */
- WORD wAdjust; /* Amount to adjust for displayed vs. actual length */
- wLength = Qstrlen (qszString2);
- wAdjust = wLength - DisplayLen (qszString2);
- if (wIndent - wAdjust > wLength)
- {
- wIndent = wIndent - wLength - wAdjust;
- Qmemset (qszString1, ' ', wIndent);
- }
- else
- wIndent = 0;
- return (Qstrcpy (&qszString1[wIndent], qszString2));
- }
- /*********************************************************************
- * QstrncpyAlign - Copies a string, right aligned to a particular
- * column.
- *
- * qszString1 - String that will have qszString2 added to it.
- * qszString2 - String to be added to qszString1.
- * wNmbrChars - Number of characters to copy.
- * WORD wIndent - Column for alignment.
- *
- * Returns: Pointer to qszString1.
- *********************************************************************/
- QSZ QstrncpyAlign (QSZ qszString1,
- QSZ qszString2,
- WORD wNmbrChars,
- WORD wIndent)
- {
- WORD wLength; /* Length of pszString2 */
- WORD wAdjust; /* Amount to adjust for displayed vs. actual length */
- wLength = Qstrlen (qszString2);
- wAdjust = wLength - DisplayLen (qszString2);
- if (wIndent - wAdjust > wLength)
- {
- wIndent = wIndent - wLength - wAdjust;
- Qmemset (qszString1, ' ', wIndent);
- }
- else
- wIndent = 0;
- return (Qstrncpy (&qszString1[wIndent], qszString2, wNmbrChars));
- }
- /*********************************************************************
- * PrepNextString - Sets the current string to end after the last
- * blank character, and sets the next string pointer
- * to just beyond the end of the current string.
- *
- * pqszStrings - Array of strings.
- * i - Current string in array of string pointers.
- *
- * Returns: Pointer to qszString1.
- *********************************************************************/
- QSZ PrepNextString (QSZ *pqszStrings, WORD i)
- {
- QSZ qszString = NULL; /* Single string pointer */
- /* Look back to find the last non-blank character */
- qszString = pqszStrings[i] + Qstrlen (pqszStrings[i]) - 1;
- while (*qszString == ' ')
- --qszString;
- /* Set the correct string length */
- *(++qszString) = ' ';
- /* Set the pointer for the next string */
- pqszStrings[i + 1] = ++qszString;
- return (qszString);
- }
- /*********************************************************************
- * ShowError - Displays an error message in an appropriate manner.
- *
- * fFlags - Flag for determining which buttons to display
- * pszString1 - Strings to display in the error window/message
- * pszString2 - "
- * pszString3 - "
- *
- * Global: References fReportOnly to determine how to display the
- * error message.
- *********************************************************************/
- VOID ShowError (BOOL fFlags,
- PSZ pszString1,
- PSZ pszString2,
- PSZ pszString3)
- {
- WORD wLength; /* Length of each string */
- wLength = strlen (pszString1) - 1;
- if (pszString1[wLength] == 'n')
- pszString1[wLength] = ' ';
- wLength = strlen (pszString2) - 1;
- if (pszString2[wLength] == 'n')
- pszString2[wLength] = ' ';
- wLength = strlen (pszString3) - 1;
- if (pszString3[wLength] == 'n')
- pszString3[wLength] = ' ';
- /* Check to see if the /F paramter was used */
- if (fReportOnly || !fCwIsReady)
- {
- PutString (NULL);
- PutString (pszString1);
- if (pszString2[0])
- {
- PutString (pszString2);
- if (pszString2[0])
- PutString (pszString3);
- }
- }
- /* Used to prevent compile warnings */
- if (fFlags == 0)
- fFlags = 1;
- #if CW_INCLUDED
- else
- MessageBox (pszString1, pszString2, pszString3, fFlags | 0x8000);
- #endif
- }
- /*********************************************************************
- * WriteLine - Writes a line of text to the report file
- *
- * qszString - String to output
- * fileOutput - File to write to
- * fFilterFlag - Filters out undesireable control characters
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL WriteLine (QSZ qszString, FILE *fileOutput, BOOL fFilterFlag)
- {
- BOOL fReturnValue = FALSE; /* Return value from WriteChar */
- while (!fReturnValue && *qszString)
- {
- if (fFilterFlag &&
- (*qszString < ' ' && *qszString != 'n' &&
- *qszString != 'r' && *qszString != 't'))
- *qszString = '.';
- fReturnValue = WriteChar (*(qszString++), fileOutput);
- }
- /* Output the trailing newline character */
- if (!fReturnValue)
- fReturnValue = WriteChar ('n', fileOutput);
- return (fReturnValue);
- }
- /*********************************************************************
- * _WriteLine - Writes a line of text to the report file without
- * pagination or line wrapping
- *
- * qszString - String to output
- * fileOutput - File to write to
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL _WriteLine (PSZ pszString, FILE *fileOutput)
- {
- BOOL fReturnValue = FALSE; /* Return value from WriteChar */
- while (!fReturnValue && *pszString)
- fReturnValue = _WriteChar (*(pszString++), fileOutput);
- return (fReturnValue);
- }
- /*********************************************************************
- * WriteChar - Writes a character to the report file, and performs
- * appropriate error handling.
- *
- * chChar - Character to output
- * fileOutput - File to write to
- *
- * Globals:
- * wColumnCount - Current column number
- * wLineCount - Current line number
- * wPageCount - Current page number
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL WriteChar (CHAR chChar, FILE *fileOutput)
- {
- BOOL fReturnValue = FALSE; /* Return value from various functions */
- /* TRUE if previous character was 'n' */
- static BOOL fPrevCharWasNewline = FALSE; /* or 'f'. Used for indenting */
- WORD i; /* Looping variable */
- switch (chChar)
- {
- case 'n':
- fPrevCharWasNewline = TRUE;
- /* Is there enough room on the page for this new line */
- if (++wLineCount <= LINES_PER_PAGE)
- {
- /* There is room. Set the values for the new line */
- wColumnCount = 0;
- /* Write the linefeed */
- fReturnValue = _WriteChar (chChar, fileOutput);
- if (fReturnValue)
- return (fReturnValue);
- break;
- }
- else
- {
- /* There wasn't enough room. Make a new page */
- if (wPageCount != 0)
- fReturnValue = WritePageBreak (fileOutput);
- }
- break;
- case 'f':
- fPrevCharWasNewline = TRUE;
- /* Set the values for the new line and page */
- wColumnCount = 0;
- wLineCount = 0;
- /* Write the form feed */
- fReturnValue = _WriteChar (chChar, fileOutput);
- break;
- default:
- if (++wColumnCount > REPORT_WIDTH)
- {
- fReturnValue = WriteChar ('n', fileOutput);
- if (fReturnValue)
- return (fReturnValue);
- }
- if (fPrevCharWasNewline)
- {
- /* Left Indent */
- for (i = 0; i < wReportIndent && fReturnValue == FALSE; ++i)
- fReturnValue = _WriteChar (' ', fileOutput);
- }
- fReturnValue = _WriteChar (chChar, fileOutput);
- fPrevCharWasNewline = FALSE;
- }
- /* Pass the return value back up the chain */
- return (fReturnValue);
- }
- /*********************************************************************
- * OutputLine - Writes a line of text to an output file
- *
- * pszString - String to output
- * fileOutput - File to write to
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL OutputLine (PSZ pszString, FILE *fileOutput)
- {
- BOOL fReturnValue = FALSE; /* Return value from WriteChar */
- while (!fReturnValue && *pszString)
- fReturnValue = _WriteChar (*(pszString++), fileOutput);
- /* Output the trailing newline character */
- if (!fReturnValue)
- fReturnValue = _WriteChar ('n', fileOutput);
- return (fReturnValue);
- }
- /*********************************************************************
- * _WriteChar - Low level writes of a character to the output file.
- *
- * chChar - Character to output
- * fileOutput - File to write to
- *
- * Returns: TRUE if an error occured.
- *********************************************************************/
- BOOL _WriteChar (CHAR chChar, FILE *fileOutput)
- {
- BOOL fReturnValue; /* Return value from various functions */
- fReturnValue = fputc (chChar, fileOutput);
- if (fReturnValue == EOF || fCriticalError)
- {
- fCriticalError = FALSE;
- ShowError (ERR_OK_BUTTON, pszErrorWriting, _strerror (NULL), "");
- return (TRUE);
- }
- /* No error occured, so return FALSE */
- return (FALSE);
- }
- /*********************************************************************
- * ReadLine - Reads a line of text from the input file
- *
- * pszString - String to fill with input data
- * fileInput - File to read from
- * fHexDump - Read file in hex
- *
- * Returns: Number of characters read, EOF if error or end of file.
- *********************************************************************/
- INT ReadLine (PSZ pszString,
- WORD wMaxChar,
- FILE *fileInput,
- BOOL fHexDump)
- {
- BOOL fReturnValue = FALSE; /* Return value from ReadChar */
- BOOL fEndOfLine = FALSE; /* TRUE if end of line encountered */
- WORD wCharCount = 0; /* Number of characters read */
- INT iChar; /* Character read from file */
- /* Read the characters for a line */
- while (!fReturnValue && !fEndOfLine && wCharCount < wMaxChar)
- {
- iChar = ReadChar (fileInput);
- /* Handle special cases */
- switch (iChar)
- {
- case EOF:
- if (wCharCount > 0)
- {
- /* If this is not the first character, treat it like a 'r' */
- fEndOfLine = TRUE;
- break;
- }
- else
- return (EOF);
- case 'r':
- fEndOfLine = TRUE;
- break;
- case 'n':
- continue;
- case ' ':
- iChar = ' ';
- /* Fall through to default */
- default:
- pszString[wCharCount++] = (CHAR) iChar;
- }
- }
- /* Make sure the terminating