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

📄 fiufind.cpp

📁 用c++变得一个测量财富的+游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*\t*******************************************************************/
/*    Creation Date .......  Fri  06-04-1993  07:37:52                */
/*    Filename  ...........  fiufile.cpp                              */
/*    Project .............  File Utilities                           */
/*    Author  .............  Matthew J. W. Ratcliff                   */
/*    Language  ...........  C++                                      */
/*    Operating System  ...  DOS/Windows                              */
/*    Processor  ..........  FIU - File Utilities                     */
/*    Function: Support code for file related operations.             */
/*                                                                    */
/*                                                                    */
/*\t*******************************************************************/

/*\r********************************************************************
**                         Revision History
***********************************************************************/
/*

   Date    By           Change Description
dd-mmm-yy  nnn          text
---------  ----         -----------------------------------------------
17-Jun-94  MJWR         Carved from FIUFILE.CPP.  This allows you to
                        use a subset of the file processing without
                        the added burden of ERAxxx.
07-Jul-94  MJWR         Return BOOLEAN not int for "FIUxxx" test functions.
                        Also modify fiuFindFirst to accept a parameter
                        allowing it to search for any file type, not just
                        file names.  Used by FIUpathExists function.

**\r*/

/*\i********************************************************************
**                       Module Include Files
***********************************************************************/

/*********************** System Include Files *************************/
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <io.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdlib.h>
#ifdef _MSC_VER
#include <direct.h>
#pragma message("Compiling for Microsoft C")
#else              
#include <dir.h>
#pragma message("Compiling for Borland C")
#endif

/********************** Constant Include Files ************************/
#include "liidSys.h"
#include "figfile.h"
#include "fipfile.h"
#include "liustrg.h"

/***************** External Variable Include Files ********************/


/***************** External Procedure Include Files *******************/
#include "fiufile.h"

/*\i*/

/*\m********************************************************************
**                       Module Declarations
***********************************************************************/

/************************* Module Constants ***************************/


/************************* Module Variables ***************************/

static FIG_DOS_FBLK_TY fimFblk;

/************************* Module Procedures **************************/

/*\m*/

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  fiuFindFirst
    NAME:  fiuFindNext

    PURPOSE:  Setup fimFblk structure with first or next
      file information based on the DOS findfirst/findnext
      functions.  Code is setup to compile and run under
      Borland or Microsoft C.  Both functions return a
      SUCCEEDED_ or FAILED_ condition, so it's easy to tell
      the result.
**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   filFound           FNC    STAT_TYPE, SUCCEEDED_ or FAILED_       **
**\p*******************************************************************/

STAT_TYPE       fiuFindFirst( const char *pasFilePath,
                              FIG_DOS_FBLK_TY *refFblk,
                              unsigned         pasSeaMode ) // = FIG_NORMAL );

{
/******************* Local Variable Declarations **********************/
#define FIL_FOUND_FILE  0
STAT_TYPE               filFound;
int                     filStatus;
/************************* Procedure Body *****************************/

#ifdef _MSC_VER
filStatus       = _dos_findfirst( pasFilePath, pasSeaMode,
                                  (struct _find_t *)refFblk );
#else
filStatus       = findfirst( pasFilePath,
                             (struct ffblk *)refFblk, pasSeaMode );
#endif

filFound = FAILED_;
if (filStatus == FIL_FOUND_FILE)
  {
  filFound = SUCCEEDED_;
  }
return(filFound);
}

STAT_TYPE       fiuFindNext( FIG_DOS_FBLK_TY *refFblk )

{
/******************* Local Variable Declarations **********************/
#define FIL_FOUND_FILE  0
STAT_TYPE               filFound;
int                     filStatus;
/************************* Procedure Body *****************************/

#ifdef _MSC_VER
filStatus       = _dos_findnext( (struct _find_t *)refFblk );
#else
filStatus       = findnext( (struct ffblk *)refFblk );
#endif

filFound = FAILED_;
if (filStatus == FIL_FOUND_FILE)
  {
  filFound = SUCCEEDED_;
  }
return(filFound);
}
/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  FIUfileSize

    PURPOSE:  to return the size, in bytes, of the specified
      file.  Return 0 if file not found.

        Use "findfirst" function.  This gives a structure
        including file size info.  This allows us to
        find the size of a file without opening it (the
        information comes from the File Allocation Table).
        Thus, you can check size on a file that you may
        not have permission to open.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   filSiz             FNC    INT32, size of file in bytes, 0=error  **
**\p*******************************************************************/

INT32 FIUfileSize( const char *pasFilePath )

{ /* FIUfileSize procedure */

/******************* Local Constant Declarations **********************/
/* Proc name for error log */
#define FIL_FOUND_FILE 0

/******************* Local Variable Declarations **********************/
/* error return flag       */
INT32                   filSiz;
STAT_TYPE               filFound;

/************************* Procedure Body *****************************/

filFound = fiuFindFirst( pasFilePath, &fimFblk );
if (filFound == FAILED_)
  {
  filSiz          = 0L;
  }
else
  {
  filSiz          = fimFblk.fsize;
  }

return(filSiz);
} /* FIUfileSize end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  FIUfileExists

    PURPOSE:  to attempt to open the file for read. If successful,
      return TRUE_, else return FALSE_.


        NOTE: This algorithm doesn't distinguish between
         the conditions "file does not exist" and
         "file access denied".  In the latter case, it doesn't
         really matter if the file exists or not - you can't
         open it anyway.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   filFindFlg         FNC    BOOLEAN, TRUE_ if exists, else FALSE_  **
**\p*******************************************************************/

BOOLEAN FIUfileExists( const char *pasFilePath )

{ /* FIUfileExists procedure */
/******************* Local Constant Declarations **********************/
#define FIL_FOUND_FILE 0

/******************* Local Variable Declarations **********************/
/* error return flag       */
STAT_TYPE               filFound;
BOOLEAN                 filFindFlag;

/************************* Procedure Body *****************************/

filFound = fiuFindFirst( pasFilePath, &fimFblk  );

filFindFlag = FALSE_;
if (filFound == SUCCEEDED_)
  {
  filFindFlag = TRUE_;
  }

return(filFindFlag);
} /* FIUfileExists end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUgetFirstFilename

    PURPOSE:  to get the first file name based on the passed
      name string, with or without wildcards.  Return a
      character pointer to the filename.  If no file found
      return NULL.

**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filErr             STAT_TYPE, SUCCEEDED_ or FAILED_              **
**\p*******************************************************************/

static char    fimFindFile[FIP_MAX_NAME_LEN+1];
static char    fimFindPath[FIP_MAX_NAME_LEN+1];

const char *FIUgetFirstFilename( const char *pasFileSpec,
                                 BOOLEAN     pasReturnFullPath)
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE               filErr        = SUCCEEDED_; /* Iniz ret val   */
const char             *filFile;
STAT_TYPE               filStat;

⌨️ 快捷键说明

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