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

📄 fs_ffind.c

📁 keil arm flash fs 最新版 在Keil arm下使用
💻 C
字号:
/*----------------------------------------------------------------------------
 *      R T L  -  F l a s h   F i l e   S y s t e m
 *----------------------------------------------------------------------------
 *      Name:    FS_FFIND.C 
 *      Purpose: File System Format Function
 *      Rev.:    V3.22
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include "File_Config.h"
#include <string.h>

/*--------------------------- ffind -----------------------------------------*/

int ffind (const char *pattern, FINFO *info) {
   /* Find a file that matches the search pattern. */
   IOB *fcb;
   const char *pat;
   int handle;
   int len1,len2,len;
   BOOL joker;

   /* Find unused _iob[] structure. */
   if ((handle = fs_find_iob ()) == EOF) {
      /* Cannot find any unused _iob[] structure */
      return (1);
   }

   fcb = &_iob[handle];
   fcb->drive = fs_get_drive (pattern);
   if (fcb->drive != DRV_NONE) {
      /* Skip drive letter 'X:' */
      pattern += 2;
   }
   else {
      fcb->drive = _DEF_DRIVE;
   }
   if (fcb->drive != DRV_MCARD) {
      /* Set drive parameters. */
      if (fs_set_params (fcb) == __FALSE) {
         return (1);
      }
   }

   pat  = pattern;
   len1 = 0;
   len2 = 0;
   while (*pat != 0) {
      len1 ++;
      if (*pat == '\\') {
         len2 = len1;
      }
      pat ++;
   }
   pat = pattern + len2;

   if (strcmp (pat,"*.*") == 0) {
      joker = __TRUE;
      len1 = len2 = 0;
   }
   else {
      len1 = fs_strpos (pat, '*');
      len2 = strlen (pat);
      if (len1 == -1) {
         /* Joker character not found in pattern. */
         joker = __FALSE;
      }
      else {
         /* Joker character '*' found in pattern. */
         joker  = __TRUE;
         len2  -= (len1 + 1);
      }
   }

   for (;;) {
      if (fcb->drive == DRV_MCARD) {
         if (fat_ffind (pattern, info, fcb) == __FALSE) {
            return (1);
         }
      }
      else {
         if (_ffind (info, fcb) == __FALSE) {
            return (1);
         }
      }
      info->name[255] = 0;

      if (joker == __FALSE) {
         /* No joker character, must exactly match. */
         if (strcmp (info->name, pat) == 0) {
found:      fcb->fileID = info->fileID;
            if (fcb->drive == DRV_MCARD) {
               info->attrib = fcb->attrib;
               info->size   = fcb->fsize;
            }
            else {
               fcb->_fblock = 0;
               info->size   = __getfsize (fcb, __FALSE);
               info->attrib = 0;
            }
            return (0);
         }
      }
      else {
         /* Joker character found. */
         if (len1 == 0 && len2 == 0) {
            goto found;
         }
         if (len1 && memcmp (info->name, pat, len1) != 0) {
            /* First part of filename does not match pattern. */
            continue;
         }
         if (len2 == 0) {
            goto found;
         }
         len = strlen ((char *)info->name);
         if (len < len1+len2) {
            /* 'fname' not long enough. */
            continue;
         }
         if (memcmp (&info->name[len-len2],&pat[len1+1],len2) == 0) {
            /* OK, last part of filename matches pattern. */
            goto found;
         }
      }
   }
}

/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/

⌨️ 快捷键说明

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