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

📄 etc.c

📁 UNIX/LINUX平台下面SMS网管原代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	char *p;	int  result = 0;        p = string;        for(; *p; p++) 	{		if(*p != ' ')		{			result = 1;			break;		}	}	return result;}/* * function	: string function */char *RightTrim(char *string ){	int n = strlen( string ) - 1;	while( n > 0 )	{		if ( *( string + n ) != 0x20 )	{		*( string + n + 1 ) = 0;		break;	}		else		n --;	}	return string;}char *LeftTrim(char *string){	while( *( string ++ ) == 0x20 );	return string - 1;}char *AllTrim(char *string){	return RightTrim( LeftTrim( string ) );}/* * function	: GetSystemLimit * author	: TANG * parameters	:  * 1.  resource - 	 *	RLIMIT_CORE (0 indicates to prevent from creating a core file. * 	RLIMIT_CPU * 	RLIMIT_DATA 	init_data + uninit_data + heap * 	RLIMIT_FSIZE * 	RLIMIT_MEMLOCK  (reserved for future use) * 	RLIMIT_NOFILE   max files opened by a process *	RLIMIT_NPROC    max number of a child process * 	RLIMIT_OFILE    the same as NOFILE *	RLIMIT_RSS  *	RLIMIT_STACK *	RLIMIT_VMEM     max size in bytes of the mapped * 2. soft_len - soft length, which can be set no more than hard_len.  *   	 	 When the actual exceeds it, a signal will be sent  *   		 to the corresponding process. * 3. hard_len - hard length, which CANNOT be set.  */int GetSystemLimit(int resource, long *soft_len, long *hard_len){	struct rlimit limit;	if( getrlimit(resource, &limit) < 0 )	{		return -1;	}	*soft_len = limit.rlim_cur;	*hard_len = limit.rlim_max;	return 0;}/* * SepChar: 0 -- no separate char, else -- the separate char * YearMode: 0 -- 4 digits, else -- 2 digits * Days: 0 -- current day, >0 -- day in the future, <0 -- day in the past  */void GetPowerDate(char *DateStr, char SepChar, int YearMode, int Days){	struct tm *curr_tm;	time_t curr_t;	char year[5];	time(&curr_t);	curr_t += (Days * 3600L * 24L);	curr_tm = localtime(&curr_t);		if (!YearMode) sprintf(year, "%04d", curr_tm->tm_year + 1900);	else sprintf(year, "%02d", curr_tm->tm_year % 100);	if (SepChar)		sprintf(DateStr, "%s%c%02d%c%02d",		                 year, SepChar,		                 curr_tm->tm_mon + 1, SepChar,		                 curr_tm->tm_mday);	else		sprintf(DateStr, "%s%02d%02d",		                 year,		                 curr_tm->tm_mon + 1,		                 curr_tm->tm_mday);}void GetPowerTime(char *TimeStr, char SepChar, int Secs){	struct tm *curr_tm;	time_t curr_t;	time(&curr_t);	curr_t += Secs;	curr_tm = localtime(&curr_t);		if (SepChar)		sprintf(TimeStr, "%02d%c%02d%c%02d",		                 curr_tm->tm_hour,SepChar,		                 curr_tm->tm_min,SepChar,		                 curr_tm->tm_sec);	else		sprintf(TimeStr, "%02d%02d%02d",		                 curr_tm->tm_hour,		                 curr_tm->tm_min,		                 curr_tm->tm_sec);}/*  * DChar, DTChar, TChar: 0 -- no separate char, else -- the separate char * YearMode: 0 -- 4 digits, else -- 2 digits*/void GetPowerDateTime(char *Str,char DChar,char DTChar,char TChar,int YearMode){	struct tm *curr_tm;	time_t curr_t;	char year[5];	char datestr[20],timestr[20];	time(&curr_t);	curr_tm = localtime(&curr_t);		if (!YearMode) sprintf(year,"%04d",curr_tm->tm_year + 1900);	else sprintf(year,"%02d",curr_tm->tm_year % 100);	if (DChar)		sprintf(datestr,"%s%c%02d%c%02d", 		                year,DChar,		                curr_tm->tm_mon + 1,DChar, 		                curr_tm->tm_mday);	else		sprintf(datestr,"%s%02d%02d", 		                year, 		                curr_tm->tm_mon + 1, 		                curr_tm->tm_mday);	if (TChar)		sprintf(timestr,"%02d%c%02d%c%02d", 		                curr_tm->tm_hour,TChar, 		                curr_tm->tm_min,TChar, 		                curr_tm->tm_sec);	else		sprintf(timestr,"%02d%02d%02d", 		                curr_tm->tm_hour, 		                curr_tm->tm_min, 		                curr_tm->tm_sec);	if (DTChar)		sprintf(Str, "%s%c%s", datestr, DTChar, timestr);	else		sprintf(Str, "%s%s", datestr, timestr);}/* * Cut off characters except 0~9 and x and X. */void PureNumber(char *purenum, char *mixnum){	char *p;	char tmp[64];	int  i = 0;	memset(tmp, 0, sizeof(tmp));	p = mixnum;	while(*p)	{		if( (*p >= 0x30 && *p <= 0x39) || *p == 0x58 || *p == 0x78 )                {                        tmp[i++] = *p;                }		p++;	}	strcpy(purenum, tmp);}/* 根据身份证生成校验位 */char GetIdMac(char *id){	int i,s,y;	char MACBIT[11]={"10X98765432"};	int W[18]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1};	s=0;	for (i=0;i<=16;i++)	{		s=s+(id[i]-48)*W[i];	}		y=s%11;		return (MACBIT[y]);}/*  * 检验18位身份证的有效性  * 可惜不能校验15位的身份证 */int CheckID(char *id){	int iLen,iRet;	char sDate[10];	char sid[18];		iLen=strlen(id);		if (iLen!=15 && iLen!=18) return -1;		memset(sDate,0,sizeof(sDate));		if (iLen==15)	{		strncpy(sDate,id+6,6);		sDate[6]=0x00;		iRet=CheckDate(sDate);		return iRet;	}	if (iLen==18)	{		strncpy(sDate,id+6,8);		sDate[8]=0x00;		iRet=CheckDate(sDate);				if (iRet<0)		{			return iRet;		}				if (id[17]!=GetIdMac(id)) return -1;		}	return 0;}/* 检验日期的有效性 */int CheckDate(char * pDate){	int iLen,iYear,iMonth,iDay;	char sYear[10],sMonth[10],sDay[10];		iLen=strlen(pDate);		if (iLen==6)	{		strncpy(sYear,pDate,2);		sYear[2]=0x00;		strncpy(sMonth,pDate+2,2);		sMonth[2]=0x00;		strncpy(sDay,pDate+4,2);		sDay[2]=0x00;	}	else if (iLen==8)	{		strncpy(sYear,pDate,4);		sYear[4]=0x00;		strncpy(sMonth,pDate+4,2);		sMonth[2]=0x00;		strncpy(sDay,pDate+6,2);		sDay[2]=0x00;	}	else if (iLen==10)	{		strncpy(sYear,pDate,4);		sYear[4]=0x00;		strncpy(sMonth,pDate+5,2);		sMonth[2]=0x00;		strncpy(sDay,pDate+8,2);		sDay[2]=0x00;	}	else		return -1;	iYear=atol(sYear);	iMonth=atoi(sMonth);	iDay=atoi(sDay);		if (strlen(sYear)==4)	{		if (iYear>2100 || iYear<1800 )	return -1;	}	if (iMonth>12 || iMonth<1) return -1;	if (iDay>31 || iDay<1)	return -1;	if (iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11)	{		if (iDay>30) return -1;	}	if (iMonth==2)	{		if ((iYear%4==0 && iYear%100!=0) || iYear%400==0 )		{			if (iDay>29)	return -1;		}		else		{			if (iDay>28)	return -1;		}	}		return 0;}/* 转化15位身份证到18位 */int id_OldToNew(char * id_old,char * id_new){	char tmp[20];	sscanf(id_old,"%s",id_old);	if (strlen(id_old)!=15)		return -1;	memset(tmp,0x00,sizeof(tmp));	memcpy(tmp,id_old,6);	memcpy(tmp+6,"19",2);	memcpy(tmp+8,id_old+6,9);	memset(id_new,0x00,sizeof(id_new));	strcpy(id_new,tmp);	id_new[17]=GetIdMac(tmp);	id_new[18]=0x00;	return 0;}/* 转化18位身份证回15位 */int id_NewToOld(char * id_new,char * id_old){	char tmp[20];	sscanf(id_new,"%s",tmp);	if (strlen(tmp)!=18) return -1;	memset(id_old,0x00,sizeof(id_old));	memcpy(id_old,tmp,6);	memcpy(id_old+6,tmp+8,9);	id_old[15]=0x00;	return 0;}/*   函数说明:Trim_SupChar(对客户号中的补充字符进行删除)   输入参数:客户号   输出参数:   描述:*/static void Trim_SupChar(){	char cp_TmpBuf[1024];	char *pc_TmpBuf;	int ip_Loc;		memset(cp_TmpBuf,0,sizeof(cp_TmpBuf));	pc_TmpBuf=strstr(cg_Buffer,SPLIT);		if( pc_TmpBuf != NULL  ){		ip_Loc=pc_TmpBuf-&cg_Buffer[0];		memcpy(cp_TmpBuf,cg_Buffer,ip_Loc);		cp_TmpBuf[ip_Loc]='\0';		strcat(cp_TmpBuf,&cg_Buffer[ip_Loc+1]);				printf("Verify String is [%s]\n",cp_TmpBuf);		strcpy(cg_Buffer1,cp_TmpBuf);	}}/*   函数说明: 递归求模   输入参数: 客户号的长度   输出参数: 模值   描述:*/static int Do_Comp_Val(int n){        int ip_RetVal;        int ip_TmpVal,ip_TmpVal1;        int j;        if(n== 0)       return CONST_MOD;        ip_TmpVal=Do_Comp_Val(n-1);        for(j=0;j<10;j++)                if( cg_Buffer1[n-1] == char_map[0][j] )		{                        ip_TmpVal1=char_map[1][j];                        break;                }        /*        if( cg_Buffer[n-1] > 10 ){                ip_TmpVal1=cg_Buffer[n-1]-55;        }        */        ip_TmpVal+=ip_TmpVal1;        ip_TmpVal=ip_TmpVal%10;        if(ip_TmpVal == 0 )	{                ip_TmpVal=10;        }		ip_TmpVal*=2;        ip_TmpVal=ip_TmpVal%37;        ip_RetVal=ip_TmpVal;        return ip_RetVal;}/*   函数说明: 客户号校验位的产生   输入参数: 客户号   输出参数: 校验位(整数)   描述:*/static char CustomNo_Ver_Pro(){	int ip_RetVal,n,m,j;	int ip_TmpVal;	char cp_RetChar;	ig_CharLen=strlen(cg_Buffer1);	n=ig_CharLen;	ip_RetVal=Do_Comp_Val(n);		m=0;	while(1)	{		ip_TmpVal=CONST_MOD*m+1-ip_RetVal;			if( ip_TmpVal > 0 )		{			ip_RetVal=ip_TmpVal;			break; 		}		m+=1;	}		        for(j=0;j<10;j++)	{                if( ip_RetVal == char_map[1][j] )		{                        cp_RetChar=char_map[0][j];                        break;		}	}		return cp_RetChar;		}char PUB_ProCifCusNoVer(char *epcBuf){	int  ip_CustomNo_Ver;	char cp_RetChar;	memset(cg_Buffer,0,sizeof(cg_Buffer));	memset(cg_Buffer1,0,sizeof(cg_Buffer1));	strcpy(cg_Buffer,epcBuf);	Trim_SupChar();	strcpy(cg_Buffer1,cg_Buffer);	cp_RetChar=CustomNo_Ver_Pro();		return(cp_RetChar);}int CompareID(char *id1, char *id2){	char tmpId1[18 + 1];	char tmpId2[18 + 1];	memset(tmpId1, 0, sizeof(tmpId1));	memset(tmpId2, 0, sizeof(tmpId2));	PureNumber(tmpId2, id2);		if( !strncmp(id1, tmpId2, strlen(id1)) ) return SUCCESS;		if( strlen(id1) == 15 && strlen(tmpId2) == 18)	{		id_OldToNew(id1, tmpId1);	}	else if( strlen(id1) == 18 && strlen(tmpId2) == 15 )	{		id_NewToOld(id1, tmpId1);	}	if( strcmp(tmpId1, tmpId2) ) return FAILURE;	return SUCCESS;}

⌨️ 快捷键说明

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