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

📄 fileutil.c

📁 NUcleus plus 支持的文件系统。 是学习文件系统的很好参考资料。
💻 C
📖 第 1 页 / 共 5 页
字号:
/************************************************************************
*                                                                       
*       Copyright (c) 2001 by Accelerated Technology, Inc.              
*                                                                       
*  PROPRIETARY RIGHTS of Accelerated Technology are  involved in        
*  the subject matter of this material.  All manufacturing,             
*  reproduction, use, and sales rights pertaining to this subject       
*  matter are  governed by the license agreement.  The recipient of     
*     this software implicitly accepts the terms of the license.        
*                                                                       
*                                                                       
*************************************************************************

*************************************************************************
* FILE NAME                                     VERSION                 
*                                                                       
*       FILEUTIL.C                              FILE  2.3
*                                                                       
* COMPONENT                                                             
*                                                                       
*       Nucleus File                                                    
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*                                                                       
* DATA STRUCTURES                                                       
*                                                                       
*       None.                                                           
*                                                                       
* FUNCTIONS                                                             
*                                                                       
*       pc_allspace                         Test if size characters in  
*                                            a string are spaces.       
*       copybuff                            Copy one buffer to another. 
*       pc_cppad                            Copy one buffer to another  
*                                            and right fill with spaces.
*       pc_isdot                            Test to see if fname is     
*                                            exactly '.'.               
*       pc_isdotdot                         Test if a filename is       
*                                            exactly {'.','.'};         
*       pc_memfill                          Fill a buffer with a        
*                                            character.                 
*       pc_parsedrive                       Get a drive number from a   
*                                            path specifier.            
*       pc_parsenewname                     Setup the new file name.    
*       pc_next_fparse                      Next upperbar file name.    
*       pc_fileparse                        Copy the short file name and
*                                            the short file extension.  
*       pc_nibbleparse                      Nibble off the left most    
*                                            part of a pathspec.        
*       pc_parsepath                        Parse a path specifier into 
*                                            path, file,ext.            
*       pc_patcomp                          Compare strings1 and        
*                                            strings2 as upper letter.  
*       pc_strcat                           strcat                      
*       pc_usewdcard                        Check the use wild card.    
*       pc_use_upperbar                     Check the use upperbar name.
*       pc_checkpath                        Check the name.             
*       _swap16                             16bit data byte swap.       
*       _swap32                             32bit data byte swap.       
*       _through16                          16bit data byte through.    
*       _through32                          32bit data byte through.    
*                                                                       
* DEPENDENCIES                                                          
*                                                                       
*       pcdisk.h                            File common definitions     
*                                                                       
*************************************************************************/

#include        "file\pcdisk.h"


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_allspace                                                     
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Test if the first size spaces of string are ' ' characters.     
*       Test if size characters in a string are spaces                  
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Kyoichiro Toda
*                                                                       
* INPUTS                                                                
*                                                                       
*       p                                   String                      
*       i                                   Size                        
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       Return YES if n bytes of p are spaces                           
*       YES if all spaces.                                              
*                                                                       
*************************************************************************/
INT pc_allspace(UINT8 *p, INT i)
{

    while (i--)
        if (*p++ != ' ')
            return(NO);
    return(YES);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       copybuf                                                         
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Copy one buffer to another                                      
*       Essentially strncpy. Copy size BYTES from from to to.           
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Kyoichiro Toda
*                                                                       
* INPUTS                                                                
*                                                                       
*       vto                                 Copy to data buffer         
*       vfrom                               Copy from data buffer       
*       size                                Size                        
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID copybuff(VOID *vto, VOID *vfrom, INT size)
{
UINT8       *to   = (UINT8 *) vto;
UINT8       *from = (UINT8 *) vfrom;


    while (size--)
        *to++ = *from++;
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_cppad                                                        
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Copy one buffer to another and right fill with spaces           
*       Copy up to size characters from "from" to "to". If less than    
*       size characters are transferred before reaching \0 fill "to"    
*       with ' ' characters until its length reaches size.              
*       Note: "to" is NOT ! Null terminated.                            
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Kyoichiro Toda
*                                                                       
* INPUTS                                                                
*                                                                       
*       to                                  Copy to data buffer         
*       from                                Copy from data buffer       
*       size                                Size                        
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_cppad(UINT8 *to, UINT8 *from, INT size)
{

    while (size--)
    {
        if (*from)
            *to++ = *from++;
        else
            *to++ = ' ';
    }
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_isdot                                                        
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Test to see if fname is exactly '.' followed by seven spaces and
*       fext is exactly three spaces.                                   
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Kyoichiro Toda
*                                                                       
* INPUTS                                                                
*                                                                       
*       fname                               File name                   
*       fext                                File extension              
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       Return YES if File is exactly '.'                               
*       YES if file:ext == '.'                                          
*                                                                       
*************************************************************************/
INT pc_isdot(UINT8 *fname, UINT8 *fext)
{
INT         stat,stat2,stat3;


    stat =  (*fname == '.');
    stat2 = pc_allspace(fname+1, 7) && pc_allspace(fext, 3);
    stat3 = (*(fname+1) == '\0') && (fext == NULL);
    return( stat && (stat2 | stat3) );
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_isdotdot                                                     
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Test if a filename is exactly {'.','.'};                        
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Kyoichiro Toda
*                                                                       
* INPUTS                                                                
*                                                                       
*       fname                               File name                   
*       fext                                File extension              
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       Return YES if File is exactly '.'                               
*       YES if file:ext == {'.','.'}                                    
*                                                                       
*************************************************************************/
INT pc_isdotdot(UINT8 *fname, UINT8 *fext)
{
INT         stat,stat2,stat3;


    stat =  ( (*fname == '.') && (*(fname+1) == '.') );
    stat2 = ( pc_allspace(fname+2, 6) && pc_allspace(fext, 3) );
    stat3 = (*(fname+2) == '\0') && (fext == NULL);
    return( stat && (stat2 | stat3) );
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_memfill                                                      
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Fill to with size instances of c                                
*       Fill a buffer with a character                                  
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Kyoichiro Toda
*                                                                       
* INPUTS                                                                
*                                                                       
*       vto                                 Copy to data buffer         
*       size                                Size                        
*       c                                   Character                   
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       Return YES if File is exactly '.'                               
*       YES if file:ext == '.'                                          
*                                                                       
*************************************************************************/
VOID pc_memfill(VOID *vto, INT size, UINT8 c)
{
UINT8       *to = (UINT8 *) vto;


    while (size--)
        *to++ = c;
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_parsedrive                                                   
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Get a drive number from a path specifier                        
*       Take a path specifier in path and extract the drive number from 
*       it. If the second character in path is ':' then the first char  
*       is assumed to be a drive specifier and 'A' is subtracted from it
*       to give the drive number. If the drive number is valid, driveno 
*       is updated and a pointer to the text just beyond ':' is returned.
*       Otherwise null is returned. If the second character in path is  
*       not ':' then the default drive number is put in driveno and path
*       is returned.                                                    
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Kyoichiro Toda
*                                                                       
* INPUTS                                                                
*                                                                       
*       driveno                             Drive number                
*       path                                Path name                   
*                                                                       
* OUTPUTS                                                               
*                                                                       

⌨️ 快捷键说明

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