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

📄 ffindx.c

📁 嵌入式系统中文件系统源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
					copyName(fileName, ffres->ff_name, 0);

				ap_free(blkBuffer);
				ap_free(fileName);
				return 0;
			} /* if loop status */
			/* not found, try next entry */
		} /* for loop j */

		/* not found in this cluster, try next cluster in the chain */
		prevCluster = cluster;
		cluster = FAT_read_fat_cluster(drive, cluster);
		nThEntry = -1;
	}
	/* all clusters in the chain have been searched, file not found */
	ap_free(blkBuffer);
	ap_free(fileName);
	FATErrno = ERROR_FILE_NOT_EXIST;
	return -1;
  }
}



/*************************************************************
Function : FAT_findclose
Description:
	clean up the memory occupied by the previous search
Input:
	ffres - a structure that holds the results of the previous search
Output:
	0	SUCCESS
	-1	FAILURE
**************************************************************/
int FAT_findclose(struct ffblk *ffres)
{
  struct FAT_FFInternal *ffInfo;	/* internal information for FAT_findnext */

#ifdef FAT1X_DEBUG
  SprintStringLn("[FAT_findclose]");
#endif

  FATErrno = 0;

  if (InitFAT == FALSE)
  {
	FATErrno = ERROR_FILE_SYSTEM_NOT_INIT;
	return -1;
  }

  if (ffres->ff_reserved == 0)
  {
	FATErrno = ERROR_FILE_NOT_EXIST;
	return -1;
  }

  sc_waitSemaphore(FATDirSemaphoreID);

  ffInfo = (struct FAT_FFInternal *)ffres->ff_reserved;
  ap_free(ffInfo);
  ffres->ff_reserved = 0;

  sc_signalSemaphore(FATDirSemaphoreID);

  return 0;
}

/*
int
findclose_r(struct ffblk *ffres)
{
  ;
}
*/


/*************************************************************
Function : nameCompare
Description:
	compare a filename with the wildcard name
Input:
	wild - a wildcard name
	name - filename
	unicode - 1 if the filename is in unicode
		  0 if the filename is not unicode
Output:
	1	the filename matchs
	0	the filename not matchs
**************************************************************/
int nameCompare(unsigned char *wild, unsigned char *name, char unicode)
{
  int index;

  if (unicode == 0)
  {
	// unicode is not used in filename
	// still have to deal with single-byte and double-byte mix
	while (*wild != '\0')
	{
		// if wild has successive '*'s, let wild points to the last '*'

		// recursively compare the next part if the current char is a '*'
		// for example,  wild = "*a.txt", name = "aba.txt"
		//		nameCompare("a.txt", "aba.txt")
		// unmatch =>	nameCompare("a.txt", "ba.txt")
		// unmatch =>	nameCompare("a.txt", "a.txt")
		// match!
		if (*wild == '*')
		{
			// skip all successive '*'
			while (*wild == '*')
				wild++;
			if (*wild == '\0')
				return 1;
			index = 0;
			while (*(name + index) != '\0')
			{
				if (nameCompare(wild, (name + index), 0) == 1)
					return 1;
				if (*(name + index) > 0x80)
					index += 2;	// a double byte char
				else
					index++;	// a single byte char
			}
			return 0;
		}
		// skip one char in name if the current wild name is '?'
		else if (*wild == '?')
		{
			if (*name == '\0')
				return 0;
			else
			{
				wild++;
				if (*name > 0x80)
					name += 2;	// a double byte char
				else
					name++;		// a single byte char
			}
		}
		else if (*wild == '.' && *(wild + 1) == '*' && *(wild + 2) == '\0')
				return 1;
		else
		{
			if (*name > 0x80)
			{
				// the current name char is a double-byte char
				if (*wild != *name || *(wild + 1) != *(name + 1))
					return 0;
				else
				{
					wild += 2;
					name += 2;
				}
			}
			else
			{
				// the current char is a single-byte char
				if (iCompareChar(*wild, *name) != 1)
					return 0;
				else
				{
					wild++;
					name++;
				}
			}
		}
	}

	if (*wild == '\0' && *name == '\0')
		return 1;
	else
  		return 0;
  }
#ifdef FAT_LFN
  else
  {
	while (*wild != '\0')
	{
		// recursively compare the next part if the current char is a '*'
		// for example,  wild = "*a.txt", name = "aba.txt"
		//		nameCompare("a.txt", "aba.txt")
		// unmatch =>	nameCompare("a.txt", "ba.txt")
		// unmatch =>	nameCompare("a.txt", "a.txt")
		// match!
		if (*wild == '*')
		{
			// skip all successive '*'
			while (*wild == '*')
				wild++;
			if (*wild == '\0')
				return 1;
			index = 0;
			while (*(name + index) != '\0' || *(name + index + 1) != '\0')
			{
				if (nameCompare(wild, (name + index), 1) == 1)
					return 1;
				index += 2;	// unicode
			}
			return 0;
		}
		// skip one char in name if the current wild name is '?'
		else if (*wild == '?')
		{
			if (*name == '\0' && *(name + 1) == '\0')
				return 0;
			else
			{
				wild++;
				name += 2;
			}
		}
		else if (*wild == '.' && *(wild + 1) == '*' && *(wild + 2) == '\0')
				return 1;
		else
		{
			if (*(name + 1) == '\0')
			{
				// the current name char is a english char
				if (iCompareChar(*wild, *name) != 1)
					return 0;
				else
				{
					wild++;
					name += 2;
				}
			}
/* marked by chilong 9/11/2001			
#ifdef FAT_CHINESE_LFN
			else
			{
				// the current name char is a chinese char
#ifdef FAT_USE_UNICODE
				if (*name != big5_to_unicode_LSB(*wild, *(wild + 1)))
#else
				if (*name != *(wild + 1))
#endif	// FAT_USE_UNICODE
					return 0;
					
				name++;
#ifdef FAT_USE_UNICODE
				if (*name != big5_to_unicode_MSB(*wild, *(wild + 1)))
#else
				if (*name != *wild)
#endif	// FAT_USE_UNICODE
					return 0;
				name++;
				wild += 2; 
			}
#else
			else
				return 0;
#endif	// FAT_CHINESE_LFN
   marked by chilong 9/11/2001 */

/**** modified by chilong 9/11/2001 ****/
#ifdef FAT_CHINESE_LFN
			else
			{
				// the current name char is a chinese char
#ifdef FAT_USE_UNICODE
				if (guiQueryLanguageType() == LANGUAGE_CHT)
				{
					if (*name != big5_to_unicode_LSB(*wild, *(wild + 1)))
						return 0;
				}
				else if (guiQueryLanguageType() == LANGUAGE_CHS)
				{
					if (*name != gb_to_unicode_LSB(*wild, *(wild + 1)))
						return 0;
				}
				// no other support yet
				else
					return 0;
#else
				if (*name != *(wild + 1))
					return 0;
#endif	// FAT_USE_UNICODE
					
				name++;
#ifdef FAT_USE_UNICODE
				if (guiQueryLanguageType() == LANGUAGE_CHT)
				{
					if (*name != big5_to_unicode_MSB(*wild, *(wild + 1)))
						return 0;
				}
				else if (guiQueryLanguageType() == LANGUAGE_CHS)
				{
					if (*name != gb_to_unicode_MSB(*wild, *(wild + 1)))
						return 0;
				}
				// no other support yet
				else
					return 0;

#else
				if (*name != *wild)
					return 0;
#endif	// FAT_USE_UNICODE
				name++;
				wild += 2; 
			}
#else
			else
				return 0;
#endif	// FAT_CHINESE_LFN
   

/**** modified by chilong 9/11/2001 ****/   
		}
	}

	if (*wild == '\0' && *name == '\0' && *(name + 1) == '\0')
		return 1;
	else
  		return 0;
  }
#endif	// FAT_LFN
}



/*************************************************************
Function : getShortName
Description:
	get a short filename from an dir entry
Input:
	dir - the directory entry
Output:
	name - the short filename
**************************************************************/
void getShortName(unsigned char *dir, unsigned char *name)
{
  int i = 0;
  int index = 0;

  // get the name part
  for (i = 0; i < FAT_FILE_NAME_LENGTH; i++)
  {
	// the name part ends when a ' ' is met or all chars have been checked
	if (dir[i] == ' ')
		break;

	name[index++] = dir[i];
  }
  // name part ends, insert a dot
  name[index++] = '.';
  // get the extension part
  for (i = 0; i < FAT_EXT_NAME_LENGTH; i++)
  {
	if (dir[FAT_FILE_NAME_LENGTH + i] == ' ')
		break;

	name[index++] = dir[FAT_FILE_NAME_LENGTH + i];
  }

  // if the filename ends with a '.', discard it
  if (name[index - 1] == '.')
	name[index - 1] = '\0';
  else
	name[index] = '\0';
}



/*************************************************************
Function : copyName
Description:
	copy a unicode/non-unicode filename to a non-unicode destination
Input:
	source - the source name
	unicode - 1 if the source is in unicode
	          0 if not
Output:
	dest - the destination filename (non-unicode)
**************************************************************/
void copyName(unsigned char *source, unsigned char *dest, char unicode)
{
  int k;
  int index;

  if (unicode == 0)
  {
	// non-unicode
	k = 0;
	while (source[k] != '\0')
	{
		dest[k] = source[k];
		k++;
	}
	dest[k] = '\0';
  }
#ifdef FAT_LFN
  else
  {
	// unicode
	k = 0;
	index = 0;
	while (source[k] != '\0' || source[k + 1] != '\0')
	{
		if (source[k + 1] == '\0')
		{
			// an english char
			dest[index] = source[k];
			index++;
			k += 2;
		}
#ifdef FAT_CHINESE_LFN
		else
		{
			// a chinese char, have to do unicode-to-big5 conversion
#ifdef FAT_USE_UNICODE
			dest[index] = unicode_to_big5_MSB(source[k + 1], source[k]);
#else
			dest[index] = source[k + 1];
#endif	// FAT_USE_UNICODE

			index++;
#ifdef FAT_USE_UNICODE
			dest[index] = unicode_to_big5_LSB(source[k + 1], source[k]);
#else
			dest[index] = source[k];
#endif	// FAT_USE_UNICODE
			index++;
			k += 2;
		}
#else	// FAT_CHINESE_LFN
		else
		{
			dest[index] = '\0';
			return;
		}
#endif	// CHINSES_LFN
	}
	dest[index] = '\0';
  }
#endif
  return;
}



#endif	// #ifdef FAT_ID



⌨️ 快捷键说明

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