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

📄 fiufile.cpp

📁 用c++变得一个测量财富的+游戏
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                          int         pasMM,
                          int         pasDD,
                          int         pasYY )
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE               filErr;
/************************* Procedure Body *****************************/

filErr = fiuSetFileDT( pasFileName, pasMM, pasDD, pasYY, TRUE_ );
return(filErr);
} /* FIUsetFileDate end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUsetFileTime

    PURPOSE:  to set the specified time stamp for the file indicated

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

STAT_TYPE FIUsetFileTime( const char *pasFileName,
                          int         pasHH,
                          int         pasMM,
                          int         pasSS )
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE               filErr;
/************************* Procedure Body *****************************/

filErr = fiuSetFileDT( pasFileName, pasHH, pasMM, pasSS, FALSE_ );

return(filErr);
} /* FIUsetFileTime end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUgetFileDate

    PURPOSE:  to get the date stamp for the specified file

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

static STAT_TYPE fiuGetFileDT( const char *pasFileName,
                               int        *refMMorHH,
                               int        *refDDorMM,
                               int        *refYYorSS,
                               BOOLEAN     pasTgetDate )
{
/*********** Local Constant & Variable Declarations *******************/
#define FLL_OPENOK 0
STAT_TYPE               filErr;
int                     fHandle;
unsigned                fStat;
unsigned                fDate;
unsigned                fTime;

/************************* Procedure Body *****************************/
fStat = _dos_open(pasFileName, O_RDONLY, &fHandle );

if (fStat == FLL_OPENOK)
  {
  filErr = SUCCEEDED_;
  _dos_getftime( fHandle, &fDate, &fTime );
  _dos_close( fHandle );
  if (pasTgetDate)
    {
    if (refYYorSS) *refYYorSS = ((fDate >> 9) & 0x7f ) + 1980;
    if (refDDorMM) *refDDorMM = fDate & 0x1f;
    if (refMMorHH) *refMMorHH = (fDate >> 5) & 0x0f;
    }
  else
    {
    if (refYYorSS) *refYYorSS = (fTime & 0x01f) << 1;
    if (refDDorMM) *refDDorMM = (fTime >> 5) & 0x2f;
    if (refMMorHH) *refMMorHH = (fTime >> 11) & 0x1f;
    }
  }
else
  {
  filErr = FAILED_;
  }

return(filErr);
} /* fiuGetFileDT end */

STAT_TYPE FIUgetFileDate( const char *pasFileName,
                          int        *refMM,
                          int        *refDD,
                          int        *refYY )
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE               filErr;
/************************* Procedure Body *****************************/

filErr = fiuGetFileDT(pasFileName,refMM,refDD,refYY, TRUE_ );
return(filErr);
} /* FIUgetFileDate end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUgetFileTime

    PURPOSE:  to get the specified time stamp for the file indicated

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

STAT_TYPE FIUgetFileTime( const char *pasFileName,
                          int        *refHH,
                          int        *refMM,
                          int        *refSS )
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE               filErr;
/************************* Procedure Body *****************************/

filErr = fiuGetFileDT(pasFileName,refHH,refMM,refSS, FALSE_ );

return(filErr);
} /* FIUgetFileTime end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUisFloppyFile

    PURPOSE:  to check if the specified file refers to a floppy disk.
      If no floppy specifier is found in the file name, then get
      the current working directory and check it.


**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filFlp             BOOLEAN, TRUE if file refers to a floppy disk **
** By Matthew J. W. Ratcliff                                          **
**\p*******************************************************************/

BOOLEAN FIUisFloppyFile( const char *pasFname )
{
/*********** Local Constant & Variable Declarations *******************/
BOOLEAN                 filFlp;
int                     filDrive;
/************************* Procedure Body *****************************/
filFlp = FALSE_;

if (pasFname)
  {
  if (*pasFname)
    {
    if (pasFname[1] == ':')
      {
      if ((toupper(*pasFname) == 'A') ||
          (toupper(*pasFname) == 'B'))
        {
        filFlp = TRUE_;
        }
      }
    else // get current working...
      {
      filDrive = getdisk() + 'A';
      if ((filDrive == 'A') || (filDrive == 'B'))
        {
        filFlp = TRUE_;
        }
      }
    }
  }

return(filFlp);
} /* FIUisFloppyFile end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUlocateFile

    PURPOSE:  to locate a file.  See if it's in the current directory.
      If not, see if it's in the default directory the caller passes
      in.  If not, see if it is in ANY ONE of the system search
      path directories.  When found, build a full drive/path file
      name and return that to the caller dude(ette).

** By Matthew J. W. Ratcliff                                          **
**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filErr             STAT_TYPE, SUCCEEDED_ or FAILED_              **
**\p*******************************************************************/

STAT_TYPE       FIUlocateFile( const char *pasArgvZeroOrDefaultPath,
                               const char *pasFileToFind,
                               int         pasFullPathLen,
                               char       *refFullPathToFile )
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE               filErr        = SUCCEEDED_; /* Iniz ret val   */
char                   *filPath;
char                   *filFile;
BOOLEAN                 filExists;
char                   *filEnv;
char                   *filPenv;
char                   *filNextPath;

/************************* Procedure Body *****************************/
filExists = FALSE_;


if ((pasFileToFind) && (pasFullPathLen > 0) && (refFullPathToFile))
  {
  filPath = new char[FIP_MAX_NAME_LEN+1];
  filFile = new char[FIP_MAX_NAME_LEN+1];

  filErr = FIUgetCwd( FIP_MAX_NAME_LEN, filPath );
  }
else // parameter error
  {
  filErr = FAILED_;
  }

if (filErr == SUCCEEDED_)
  {
  FIUconstructFilePath( filPath, pasFileToFind, FIP_MAX_NAME_LEN, filFile );
  /****************************************
  * Does it exist in the CWD?
  */
  filExists = FIUfileExists( filFile );
  if (!filExists && pasArgvZeroOrDefaultPath != NULL)
    {
    /****************************************
    * Try default path from passed command line.
    * For DOS it should be argv[0]. For
    * Windows this should be the default path. That
    * is, we want the caller to pass in the value
    * returned by the Windows API call:
    *  int GetModuleFileName(HINSTANCE hinst,
    *                        LPSTR     lpszfilename,
    *                        int       cbFileName );
    * Returns zero on error.
    */
    STAT_TYPE FIUextractPath( const char *pasFilePath,
                          int         pasDestLen,
                          char       *refFullPath );

    FIUextractPath( pasArgvZeroOrDefaultPath, FIP_MAX_NAME_LEN, filPath );
    
    FIUconstructFilePath( filPath,
                          pasFileToFind,
                          FIP_MAX_NAME_LEN,
                          filFile );
    filExists = FIUfileExists( filFile );
    }
  if (!filExists)
    {
    /****************************************
    * Still not found.
    * Try system search path.
    */
    filPenv = getenv("PATH");
    if (filPenv)
      {
      filEnv = new char[strlen(filPenv)+1];
      strcpy(filEnv,filPenv);
      filPenv     = filEnv;
      filNextPath = filPenv;
      do
        {
        filNextPath = strchr(filNextPath, ';'); // find semicolon separator
                                                // in path list
        if (filNextPath)
          {
          *filNextPath = '\0';
          filNextPath++;
          }
        LIUstrncpy(filPath, filPenv, FIP_MAX_NAME_LEN );
        filPenv = filNextPath;
        FIUconstructFilePath( filPath,
                              pasFileToFind,
                              FIP_MAX_NAME_LEN,
                              filFile );
        filExists = FIUfileExists( filFile );
        }
      while ((filExists == FALSE_) && (filNextPath != NULL));
      }
    }
  }
if (filExists)
  {
  LIUstrncpy( refFullPathToFile, filFile, pasFullPathLen ); 
  }

LIMDELA(filPath);
LIMDELA(filFile);
return(filErr);
} /* FIUlocateFile end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUgetCwd

    PURPOSE:  to get a copy of the current working directory

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

STAT_TYPE       FIUgetCwd( int          pasPathLen,
                           char        *refPath )
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE               filErr        = SUCCEEDED_; /* Iniz ret val   */
/************************* Procedure Body *****************************/
if ((pasPathLen <= 0) || (refPath == NULL))
  {
  filErr = FAILED_;
  }
else
  {
#ifdef _MSC_VER
  _getcwd( refPath, pasPathLen );
#else
  getcwd( refPath, pasPathLen );
#endif
  }

return(filErr);
} /* FIUgetCwd end */


/*\p********************************************************************
**                                                                    **
    NAME:  FIUchangeDrive

    PURPOSE:  to set default disk drive

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

STAT_TYPE FIUchangeDrive( int pasDriveLetter )
{
/*********** Local Constant & Variable Declarations *******************/
#define FIL_OLD_DRIVE_A	0
#define FIL_DRIVE_A     1

STAT_TYPE filErr;
int       filResult;
/************************* Procedure Body *****************************/
  
pasDriveLetter = toupper( pasDriveLetter );

if (pasDriveLetter >= 'A') // 1=A, 2=B, etc.
  {
  pasDriveLetter = pasDriveLetter - (int)'A' + 1;
  }                                      
// else it is assumed the user passed in a 1 for 'A, etc.
// if user passed in a 0 this means the user is using some
// OLD DOS mentality, where some DOS functions assumed 0 = A and
// others assumed 1 = A.  So, if we see a 0, don't flag it as an
// error, just set it to 1 for 'A'
else if (pasDriveLetter == FIL_OLD_DRIVE_A)
  {
  pasDriveLetter = FIL_DRIVE_A;
  }  

filErr = SUCCEEDED_;                                      

// Both microsoft and borland implement _chdrive
// the same way.
filResult = _chdrive( pasDriveLetter );
if (filResult < 0) filErr = FAILED_;

return( filErr );
}


/*\p********************************************************************
**                                                                    **
    NAME:  FIUgetDrive

    PURPOSE:  to get default disk drive letter

**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filDriveLetter	int, current drive letter, 'A', 'B', etc.     **
**\p*******************************************************************/

int FIUgetDrive( )
{
/*********** Local Constant & Variable Declarations *******************/
int       filDriveLetter;
/************************* Procedure Body *****************************/

// Both microsoft and borland implement _getdrive
// the same way.
filDriveLetter = _getdrive() + (int)'A' - 1;

return( filDriveLetter );
}

⌨️ 快捷键说明

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