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

📄 basefun.cc

📁 此源代码只用于学习,不得用于其他商业活动 .
💻 CC
📖 第 1 页 / 共 2 页
字号:
		}
		//校验月份
		strncpy(tmp, pchString + 4, 4);
		tmp[2] = 0;
		num = atoi(tmp);
		iMonth = num;
		if ((num < 1) || (num > 12))
		{
			return false;
		}
		//校验天
		strncpy(tmp, pchString + 6, 2);
		tmp[2] = 0;
		num = atoi(tmp);
		if ((num < 1) || (num > 31))
		{
			return false;
		}
	}

	switch(iMonth)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if ((num < 1) || (num > 31))
			{
				return false;
			}
			break;
		case 2:
			//判断闰年
			if (((iYear%4 == 0) && (iYear%100 != 0)) || (iYear%400 == 0))
			{
				if ((num < 1) || (num > 29))
				{
					return false;
				}
			}
			else
			{
				if ((num < 1) || (num > 28))
				{
					return false;
				}
			}
			break;
		default :
			if((num < 1) || (num > 30))
			{
				return false;
			}
	}

	return true;
}

/*
*	Function Name:	CheckTime
*	Description:	校验时间正确性
*	Input Param:
*		pchString -------> 输入字符串(格式hhmmss或者为hhmmsss最后一位是十分之一秒)
*	Returns:
*		成功,返回true
*		失败,返回false
*	Complete:	2002/03/13
*	Update:		2003/01/25
*/
bool CheckTime(const char *pchString)
{
	int num,i;
	char tmp[LENGTH];

	if ((strlen(pchString) != 6) && (strlen(pchString) != 7))
	{
		return false;
	}

	int iLen = strlen(pchString);
	for (i=0; i<iLen; i++)
	{
		if ((pchString[i] < '0') || (pchString[i] > '9'))
		{
			return false;
		}
	}

	//校验小时
	strncpy(tmp, pchString, 2);
	tmp[2] = 0;
	num = atoi(tmp);
	if ((num < 0) || (num > 23))
	{
		return false;
	}

	//校验分钟
	strncpy(tmp, pchString + 2, 2);
	tmp[2] = 0;
	num = atoi(tmp);
	if ((num < 0) || (num > 59))
	{
		return false;
	}

	//校验秒
	strncpy(tmp, pchString + 4, 2);
	tmp[2] = 0;
	num = atoi(tmp);
	if ((num < 0) || (num > 59))
	{
		return false;
	}
	//校验十分之一秒
	if(strlen(pchString) == 7)
	{
		strncpy(tmp, pchString + 6, 1);
		tmp[1] = 0;
		num = atoi(tmp);
		if((num < 0) || (num > 9))
		{
			return false;
		}
	}
	return true;
}
/*
*	Function Name:	CheckDateTime
*	Description:	校验日期正确性
*	Input Param:
*		pchString -------> 输入字符串(格式yyyymmddhhmmss)
*	Returns:
*		成功,返回true
*		失败,返回false
*	complete:	2004/07/23
*/
bool CheckDateTime(const char *pchString)
{
	char szTemp[8 + 1];
	memset(szTemp, 0, sizeof(szTemp));

	memcpy(szTemp, pchString, 8);

	return (CheckDate(szTemp) && CheckTime(pchString + 8));
}

/*
*	Function Name:	hhmmssToss
*	Description:	时分秒转换为秒
*	Input Param:
*		pchString -------> 输入字符串(格式为hhmmss)
*	Returns:
*		Duration -------> 秒数
*	complete:	2002/03/13
*/
long hhmmssToss(char * pchString)
{
	long Duration;
	char tmp[LENGTH];

	//小时转换为秒
	memcpy(tmp,pchString,2);
	tmp[2] = 0;
	Duration = 3600*atoi(tmp);

	//分钟转换为秒
	memcpy(tmp,pchString+2,2);
	tmp[2] = 0;
	Duration += 60*atoi(tmp);

	//累加秒
	memcpy(tmp,pchString+4,2);
	tmp[2] = 0;
	Duration += atoi(tmp);

	return Duration;
}




/*
*    Function Name    : SearchOneFile
*    Description      :	判断所给的匹配模式在所给的目录下有相应的文件存在
*    Input lv_chParameters :
*	pathname    -----------> 路径名
*	Format      -----------> 匹配模式
*	Filename    -----------> 匹配成功的文件名
*	Returns          : 如果该路径下该文件存在,返回FIND_OK
*			   如果该路径下该文件不存在,返回FIND_NOFILE
*			   如果出现路径不能打开,返回FIND_PATHERROR
*			   如果出现找到的文件不能访问,返回FIND_NOREAD
*	complete	:2001/12/06
*/
int SearchOneFile(const char *Pathname, const char *Format, char *Filename)
{
	DIR *dirp = NULL;
	struct dirent entry;
	struct dirent temp;
	struct dirent *dp = &temp;
	char chFileName[LENGTH];
	char chFullName[LENGTH];
	char chTmpPath[LENGTH];

	memset(chFileName, 0, sizeof(chFileName));
	memset(chTmpPath, 0, sizeof(chTmpPath));

	strcpy(chTmpPath, Pathname);

	FullPath(chTmpPath);
	dirp = opendir(chTmpPath);
	if (dirp == NULL)
	{
		sprintf(Filename, "open dir %s FAILED", Pathname);
		return FIND_PATHERROR;
	}

	while (readdir_r(dirp, &entry, &dp) == 0)
	{
		if (dp == NULL)
		{
			closedir(dirp);
			return FIND_NOFILE;
		}
		strcpy(chFileName, dp->d_name);
		sprintf(chFullName, "%s%s", chTmpPath, chFileName);

		if ((strcmp(chFileName, ".") == 0) || (strcmp(chFileName, "..") == 0))
		{
			continue;
		}
		if (IsDirectory(chFullName) == true)
		{
			continue;
		}
		if (chFileName[0] == '~')
		{
			continue;
		}
		if (Compare(chFileName, Format) == true)
		{
			strcpy(Filename, chFileName);
			closedir(dirp);
			if (access(chFullName, F_OK|R_OK) == -1)
			{
				return FIND_NOREAD;
			}
			return FIND_OK;
		}
	}
	closedir(dirp);
	return FIND_NOFILE;
}

/*
*    Function Name    : SearchOneFile
*    Description      :	判断所给的匹配模式在所给的多个目录下有相应的文件存在
*    Input lv_chParameters :
*	pathname    -----------> 路径名
*	Format      -----------> 匹配模式
*	Filename    -----------> 匹配成功的文件名
*	Returns          : 如果该路径下该文件存在,返回正整数
*			   如果该路径下该文件不存在,返回0
*			   如果出现异常,返回负整数
*	complete	:2003/01/07
*/
int SearchOneFile(const char Pathname[TOTAL][LENGTH], const char Format[TOTAL][LENGTH], const int TotalIn, char *Filename)
{
	int iCount = 0;
	int iReturn = 0;

	for (iCount=0; iCount<TotalIn; iCount++)
	{
		if ((iReturn = SearchOneFile(Pathname[iCount], Format[iCount], Filename)) > 0)
		{
			return 1;
		}
		else if (0 == iReturn)
		{
			continue;
		}
		else
		{
			return iReturn;
		}
	}
	return 0;
}


bool SearchAllFiles(const char *Pathname, const char *Format, vector<string> &vecFileSet)
{
	DIR *dirp = 0;
	struct dirent entry;
	struct dirent temp;
	struct dirent *dp = &temp;
	char chFileName[LENGTH];
	char chFullName[LENGTH];
	char chTmpPath[LENGTH];
	string sFileName;

	memset(chFileName, 0, sizeof(chFileName));
	memset(chTmpPath, 0, sizeof(chTmpPath));

	strcpy(chTmpPath, Pathname);

	FullPath(chTmpPath);
	dirp = opendir(chTmpPath);
	if (dirp == NULL)
	{
		return false;
	}

	while (readdir_r(dirp, &entry, &dp) == 0)
	{
		if (dp == NULL)
		{
			closedir(dirp);
			return true;
		}
		strcpy(chFileName, dp->d_name);
		sprintf(chFullName, "%s%s", chTmpPath, chFileName);

		if ((strcmp(chFileName, ".") == 0) || (strcmp(chFileName, "..") == 0))
		{
			continue;
		}
		if (IsDirectory(chFullName) == true)
		{
			continue;
		}
		if (chFileName[0] == '~')
		{
			continue;
		}
		if (Compare(chFileName, Format) == true)
		{
			sFileName = chFileName;
			vecFileSet.push_back(sFileName);
		}
	}//end while (readdir_r(dirp, &entry, &dp) == 0)
	closedir(dirp);
	return true;
}


/*
*    Function Name    : CopyFile
*    Description      :	将一个文件从源目录拷贝到目标目录并改名
*    Input lv_chParameters :
*	DesFullFileName    -----------> 源目录+源文件名
*	SrcFullFileName    -----------> 目标目录+目标文件名
*	Returns          : 如果源文件不存在,返回-1
*			   如果不能创建目标文件,返回-2
*			   如果文件流出现异常,返回-3
*			   未知的错误,返回-4
*			   正确则返回0
*	complete	:2003/01/06
*/
int CopyFile(const char *SrcFullFileName, const char *DesFullFileName)
{
	int iReturn = 0;

	if (-1 == access(SrcFullFileName, F_OK|R_OK))
	{
		return -1;
	}
	if ((0 == access(DesFullFileName, F_OK|R_OK)) && strcmp(SrcFullFileName, DesFullFileName))
	{
		if (-1 == unlink(DesFullFileName))
		{
			return -4;
		}
	}

	iReturn = link(SrcFullFileName, DesFullFileName);

	if (iReturn == 0)
	{
		return 0;
	}

	else if ((iReturn == -1) && (errno == EXDEV))
	{
		FILE *fSrc = NULL;
		FILE *fDes = NULL;
		char chTemp[BUFFSIZE];

		if (NULL == (fSrc = fopen(SrcFullFileName, "r")))
		{
			return -1;
		}

		if (NULL == (fDes = fopen(DesFullFileName, "w+")))
		{
			fclose(fSrc);
			return -2;
		}

		for(;;)
		{
			memset(chTemp, 0, sizeof(chTemp));
			iReturn  = 0;

			if (BUFFSIZE == (iReturn = fread(chTemp, sizeof(char), BUFFSIZE, fSrc)))
			{
				fwrite(chTemp, sizeof(char), BUFFSIZE, fDes);
			}
			else
			{
				if(feof(fSrc))
				{
					fwrite(chTemp, sizeof(char), iReturn, fDes);
					break;
				}
				if(ferror(fSrc))
				{
					fclose(fSrc);
					fclose(fDes);
					return -3;
				}
			}
		}

		fclose(fSrc);
		fclose(fDes);

		return 0;
	}
	else
	{
		return -4;
	}
}

/*
*    Function Name    : MoveFile
*    Description      :	将一个文件从源目录移动到目标目录并改名
*    Input lv_chParameters :
*	DesFullFileName    -----------> 源目录+源文件名
*	SrcFullFileName    -----------> 目标目录+目标文件名
*	Returns          : 如果源文件不存在,返回-1
*			   如果不能创建目标文件,返回-2
*			   如果文件流出现异常,返回-3
*			   未知的错误,返回-4
*			   如果不能删除源文件,返回-5
*			   正确则返回0
*	complete	:2003/01/06
*/
int MoveFile(const char *SrcFullFileName, const char * DesFullFileName)
{
	int iReturn = 0;
	iReturn = CopyFile(SrcFullFileName, DesFullFileName);
	if (0 == iReturn)
	{
		if (0 != unlink(SrcFullFileName))
		{
			return -5;
		}
	}
	return iReturn;
}

/*
*    Function Name    : GetFileRows
*    Description      :	得到文件的行数
*    Input lv_chParameters :
*	pchFullFileName    -----------> 带路径的文件名
*	Returns          : 如果出错,返回-1
*			   正确则返回文件的行数
*	complete	:2003/01/06
*/
long GetFileRows(const char *pchFullFileName)
{
	FILE *fp = NULL;
	char chCommand[BUFFSIZE];
	char chTemp[BUFFSIZE];
	long lRows = 0;

	if (pchFullFileName[0] == '\0')
	{
		return -1;
	}
	if (access(pchFullFileName, F_OK|R_OK) == -1)
	{
		return -1;
	}

	sprintf(chCommand, "wc -l %s | awk '{print $1}'", pchFullFileName);

	if (NULL == (fp = popen(chCommand, "r")))
	{
		return -1;
	}

	if (NULL == fgets(chTemp, sizeof(chTemp), fp))
	{
		pclose(fp);
		return -1;
	}

	pclose(fp);

	lRows = atol(chTemp);

	if (lRows < 0)
	{
		return -1;
	}

	return lRows;
}

/*
*	Function Name:	GetShortSystemDate
*	Description:	获得当前系统日期(两位年)
*	Input Param:
*		CurrentDate -------> 当前系统日期(格式yymmdd)
*	Returns:	无
*	complete:	2003/01/24
*/
void GetShortSystemDate(char *pchCurrentDate)
{
	char chTempDate[LENGTH];
	memset(chTempDate, 0, sizeof(chTempDate));

	GetSystemDate(chTempDate);

	strcpy(pchCurrentDate, chTempDate + 2);

	return;
}

/*
*	Function Name:	GetShortProcessName
*	Description:	如果进程命令行是绝对路径则获得进程的短名称,如果不是则保持输入参数的原状
*	Input Param:
*		pchFullProcName -------> 进程的命令行
*	Returns:	无
*	complete:	2003/03/18
*/
void GetShortProcName(char *pchProcName)
{
	//此变量用来截取不带路径的执行文件名
	char *pchTemp = 0;
	pchTemp = strrchr(pchProcName, '/');

	char chShortName[LENGTH];
	memset(chShortName, 0, sizeof(chShortName));

	if(0 == pchTemp)
	{
		Trim(pchProcName);
	}
	else
	{
		pchTemp++;
		strcpy(chShortName, pchTemp);
		strcpy(pchProcName, chShortName);
		Trim(pchProcName);
	}
	return;
}

//pszPlain:明文
//pszCryptograph:密文
void Encrypt(const char *pszPlain, char *pszCryptograph)
{
	for(size_t i = 0; i < strlen(pszPlain); ++i)
	{
		pszCryptograph[i] = pszPlain[i] + 12;
	}
	return;
}

//pszCryptograph:密文
//pszPlain:明文
void Decrypt(const char *pszCryptograph, char *pszPlain)
{
	for(size_t i = 0; i < strlen(pszCryptograph); ++i)
	{
		pszPlain[i] = pszCryptograph[i] - 12;
	}
	return;
}

⌨️ 快捷键说明

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