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

📄 fiufile.cpp

📁 用c++变得一个测量财富的+游戏
💻 CPP
📖 第 1 页 / 共 4 页
字号:
char                   *filDs;
char                   *filWcs;
/************************* Procedure Body *****************************/

if ((pasFilePath == NULL) ||
    (pasDestLen  <= 0)    ||
    (refFileExt  == NULL))
  {
  filErr = FAILED_;
  }
else
  {
  filDs = LIUstrchrLast( pasFilePath, '.');
  if (pasMakeWcSpec)
    {
    filWcs = new char[40];
    if (filDs)
      {
      sprintf(filWcs,"*%s", filDs);
      LIUstrncpy( refFileExt, filWcs, pasDestLen );
      }
    else
      {
      LIUstrncpy( refFileExt, "*.*", pasDestLen );
      }
    }
  else
    {
    if (filDs)
      {
      filDs++;
      LIUstrncpy( refFileExt, filDs, pasDestLen );
      }
    else
      {
      *refFileExt = '\0';
      }
    }
  }
return(filErr);
} /* FIUextractExt end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  FIUdeleteFile

    PURPOSE:  to delete the specified file.  If file not
      found, return an error.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   filErr             FNC    (SUCCEEDED_ / FAILED_) error return    **
**\p*******************************************************************/

STAT_TYPE FIUdeleteFile( const char *pasFilePath )

{ /* FIUdeleteFile procedure */

/******************* Local Constant Declarations **********************/
/* Proc name for error log */
CHARPTR FIL_PROC_NAME = "FIUdeleteFile";

/******************* Local Variable Declarations **********************/
/* error return flag       */
int                     filUnlink;
STAT_TYPE               filErr;
int                     filFileFound;

/************************* Procedure Body *****************************/
/* Initialize return val   */
filErr = FAILED_;

filFileFound = FIUfileExists( pasFilePath );
if (filFileFound)
  {
  filUnlink = unlink( pasFilePath );
  if (filUnlink != 0)
    {
    ERAerrorLog( FIL_PROC_NAME,
      "Failed to delete file '%s'", pasFilePath );
    }
  else
    {
    filErr = SUCCEEDED_;
    }
  }
else
  {
  ERAerrorLog( FIL_PROC_NAME,
    "File '%s' not found, can't delete",
    pasFilePath );
  }

return(filErr);
} /* FIUdeleteFile end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUdeleteWCfiles

    PURPOSE:  to delete one or more files matching file template
      with wild card characters.  WARNING: Use at your own risk.
      If you call FIUdeleteWCfiles( "*.*" ); then all files
      in the current directory (not write protected) will be
      deleted without the usual DOS prompts to be SURE.  Return
      a count of the number of files actually deleted.

**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filDelCnt          int, Number of files matching template and    **
**                      deleted successfully. 0 on any error          **
**\p*******************************************************************/

int FIUdeleteWCfiles( const char *pasNukemFileSpec )
{
/*********** Local Constant & Variable Declarations *******************/
CHARPTR FIL_PROC_NAME="FIUdeleteWCfiles";
int                     filDelCnt        = 0;
int                     filUnlink;
const char             *filNukeMe;

/************************* Procedure Body *****************************/
filNukeMe = FIUgetFirstFilename( pasNukemFileSpec );

while (filNukeMe)
  {
  filUnlink = unlink( filNukeMe );
  if (filUnlink != 0)
    {
    ERAerrorLog( FIL_PROC_NAME,
      "Failed to delete file '%s'", filNukeMe );
    }
  else
    {
    filDelCnt++;
    }
  filNukeMe = FIUgetNextFilename();
  }

return(filDelCnt);
} /* FIUdeleteWCfiles end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUbuildDefaultFname

    PURPOSE:  User specifies path, a name, and an extension. A desirable
     default path/filename is created.

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

STAT_TYPE FIUbuildDefaultFname
( const char    *pasPath,
  const char    *pasName,
  const char    *pasExt,
  int            pasLen,
  char          *refDefName,
  int            pasDefaultChar )

{
/*********** Local Constant & Variable Declarations *******************/
#define FIL_FNAME_LEN   9
#define FIL_MAXPATH     120

CHAR                   *FIL_PROC_NAME = "FIUbuildDefaultFname";
STAT_TYPE               filErr        = SUCCEEDED_; /* Iniz ret val   */
char                    filName[FIL_FNAME_LEN+1];
char                    filPath[FIL_MAXPATH+1];

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

if ((pasName == NULL)           ||
    (pasLen  <= 0)              ||
    (refDefName == NULL))
  {
  ERAerrorLog( FIL_PROC_NAME, "Bad param");
  }
else
  {
  LIUstrncpy( filName, (char *)pasName, FIL_FNAME_LEN );
  FIUmakeFnameChars( filName, pasDefaultChar );
  if (pasPath)
    {
    FIUconstructFilePath( pasPath, filName, FIL_MAXPATH, filPath );
    }
  else
    {
    strcpy( filPath, filName );
    }
  if (pasExt)
    {
    FIUsetExtender( pasExt, filPath );
    }
  LIUstrncpy( refDefName, filPath, pasLen );
  }

return(filErr);
} /* FIUbuildDefaultFname end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUmakeFnameChars

    PURPOSE:  to convert all characters which are NOT VALID
      file name characters into pasSubstChar characters, so that
      the string may be used as a filename.

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

STAT_TYPE FIUmakeFnameChars( char *refMessyName,
                             int   pasSubstChar )
{
/*********** Local Constant & Variable Declarations *******************/
STAT_TYPE               filErr        = SUCCEEDED_; /* Iniz ret val   */
char                   *filCptr;
int                     filCh;

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

if ((refMessyName == NULL)  ||
    (*refMessyName == '\0') ||
    (pasSubstChar <= ' ')   ||
    (pasSubstChar > 'z'))
  {
  filErr = FAILED_;
  }
else
  {
  filCptr = refMessyName;
  while (*filCptr)
    {
    filCh = *filCptr;
    if ((filCh < '0')  ||
        (filCh > 'Z'))
      {
      if ((filCh != '$') &&
          (filCh != '@'))
        {
        filCh = pasSubstChar;
        }
      }
    *filCptr = filCh;
    filCptr++;
    }
  }

return(filErr);
} /* FIUmakeFnameChars end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUfopen

    PURPOSE:  to open a file, increasing registered file open count.

**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   filFptr            FILE *, file pointer, NULL on error           **
**\p*******************************************************************/

FILE *FIUfopen( const char *pasFilePath, const char *pasFileMode )
{
/*********** Local Constant & Variable Declarations *******************/
FILE *filFptr = NULL;
/************************* Procedure Body *****************************/

if ((pasFilePath == NULL) || (pasFileMode == NULL))
  {
  ERAparameterError("FIUfopen");
  }
else
  {
  filFptr = fopen(pasFilePath,pasFileMode);
  if (filFptr)
    {
    fimFilesOpened++;
    }
  }

return(filFptr);
} /* FIUfopen end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUfclose

    PURPOSE:  to close an opened file and decrease the file open
      counter.

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

STAT_TYPE FIUfclose( FILE **refFptr )
{
/*********** Local Constant & Variable Declarations *******************/
FILE    *filFptr;
STAT_TYPE filErr = FAILED_;

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

if ((refFptr) && (*refFptr))
  {
  filFptr = *refFptr;
  if (fclose(filFptr) == 0)
    {
    filErr = SUCCEEDED_;
    fimFilesOpened--;
    }
  *refFptr = NULL;
  }

return(filErr);
} /* FIUfclose end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUnumFilesOpened

    PURPOSE:  to report number of files now opened via FIUfopen().

**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   fimFilesOpened     int, number of files currently opened         **
**\p*******************************************************************/

int FIUnumFilesOpened()
{
/************************* Procedure Body *****************************/

return(fimFilesOpened);
} /* FIUnumFilesOpened end */

/*\p********************************************************************
**                                                                    **
    NAME:  FIUnewline

    PURPOSE:  to write a newline to the file

**   Return Val         type/expected/description                     **
**   ------------       --------------------------------------------  **
**   fimFilesOpened     int, number of files currently opened         **
**\p*******************************************************************/

STAT_TYPE FIUnewline( FILE *pasFptr, int pasNum )
{
/************************* Procedure Body *****************************/
STAT_TYPE filErr = SUCCEEDED_;

if (pasFptr)
  {
  while (pasNum > 0)
    {
    fprintf(pasFptr,"\n");
    pasNum--;
    }
  }
else
  {
  filErr = FAILED_;
  }

return(filErr);
} /* FIUnewline end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  fiuCopy

    PURPOSE:  to copy from the specified source file name
      (including full path) to the destination file
      (also including full path in its name).

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   filErr             FNC    (SUCCEEDED_ / FAILED_) error return    **
**\p*******************************************************************/

STAT_TYPE fiuCopy
( const char    *pasSourceFile,
  const char    *pasDestFile,
  const char    *pasWriteMode )

{ /* fiuCopy procedure */

/******************* Local Constant Declarations **********************/
/* Proc name for error log */
CHARPTR FIL_PROC_NAME = "fiuCopy";

#define FIL_MIN_BUF      512
#define FIL_DEF_BUF    32000

/******************* Local Variable Declarations **********************/
/* error return flag       */

⌨️ 快捷键说明

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