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

📄 findfile.c

📁 德国Hyperstone公司dsp的CF卡驱动程序
💻 C
字号:
/*
 **************************************************************
 *
 *  hyperstone MS-DOS FAT File System Drivers
 *
 *  Directory Scanning Routines
 *
 *  Christoph Baumhof 2000-03-21
 *  Reinhard K乭ne 2000-03-21
 *  Mihajlo Varga 2000-03-21
 *
 *  Copyright (C) 1997-2000 hyperstone electronics GmbH Konstanz
 *
 *  2000-03-21 initial release
 *
 * $Id$
 *
 * $Log$
 *
 **************************************************************
 *
 * Changes:
 *
 **************************************************************
 */

#include <stdio.h>
#include <stdlib.h>

#include "dir.h"

#ifdef __HYPERSTONE__
#include "hy_dos.h"

int _ROOTEntrySize(int drive, int partnum);
int _readROOTEntry(int drive, int partnum, struct directory * dir);

int PathMatches(const char *pathname, char *nameFromDirectory)
{
  return 1;
}

void CopyFileName(char *dest_name, char *src_name)
{
char *c;
int l1, l2;

  for(l1=FNAME_SIZE,c=&src_name[FNAME_SIZE-1]; (*c==' ')&&(l1>0); --c,--l1);
  memcpy(dest_name, src_name, l1);
  dest_name[l1] = '.';
  for(l2=FEXT_SIZE,c=&src_name[FNAME_SIZE+FEXT_SIZE-1];
     (*c==' ')&&(l2>0); --c,--l2);
  memcpy(dest_name+l1+1, src_name+FNAME_SIZE, l2);
  dest_name[l1+l2+1] = 0;
}

int findfirst(const char *pathname, struct ffblk *ffblk, int attrib)
{
struct directory *dir, *tmp;
int found, DirIndex;

  dir = calloc(1, _ROOTEntrySize(0, 0)+sizeof(struct directory));
  // one extra entry, clear this entry for loop endtest: while (tmp->name[0])
  if (dir)
    _readROOTEntry(0, 0, dir);
  else
    return -1;
  tmp = dir;
  found = 0;
  DirIndex = 0;
  do
    {
      if ((tmp->name[0] != DELMARK) &&
	  !(tmp->attr & D_VOLID) &&
	  !(tmp->attr & D_DIR)   &&
	  (tmp->attr != D_LONG_FILENAME) &&
	  tmp->size &&
	  PathMatches(pathname, tmp->name))
	{
	  CopyFileName(ffblk->ff_name, tmp->name);
	  memcpy(ffblk->ff_reserved, pathname, sizeof(ffblk->ff_reserved));
	  ffblk->DirIndex = DirIndex+1;
	  ffblk->Dir = dir;
	  found = 1;
	}
      else
	{
	  tmp++;
	  DirIndex++;
	}
    }
  while(tmp->name[0] && !found);
  if (!found)
    {
      free(dir);
      return -1;
    }
  return 0;
}

int findnext(struct ffblk *ffblk)
{
struct directory *dir, *tmp;
int found, DirIndex;
char *pathname;

  dir = ffblk->Dir;
  if (!dir)
    return -1;
  DirIndex = ffblk->DirIndex;
  tmp = &dir[DirIndex];
  pathname = ffblk->ff_reserved;
  found = 0;
  do
    {
      if ((tmp->name[0] != DELMARK) &&
	  !(tmp->attr & D_VOLID) &&
	  !(tmp->attr & D_DIR)   &&
	  (tmp->attr != D_LONG_FILENAME) &&
	  tmp->size &&
	  PathMatches(pathname, tmp->name))
	{
	  CopyFileName(ffblk->ff_name, tmp->name);
	  ffblk->DirIndex = DirIndex+1;
	  ffblk->Dir = dir;
	  found = 1;
	}
      else
	{
	  tmp++;
	  DirIndex++;
	}
    }
  while(tmp->name[0] && !found);
  if (!found)
    {
      free(dir);
      return -1;
    }
  return 0;
}

#endif


⌨️ 快捷键说明

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