ULONG _DateOrTimeToUl(char *szDate, ULONG *pulDate) { char *pcDst, *pcSrc ; UCHAR ucType; char szSrc[20]; ULONG ulTime[3]; if (szDate == NULL || pulDate == NULL) { MT_ERRLOG(0); return TBS_FAILED; } strcpy(szSrc, szDate); pcSrc = szSrc; pcDst = szSrc; ucType = 0; for (; ;) { if (*pcSrc <= '9' && *pcSrc >= '0') pcSrc++; else if (*pcSrc == '-' || *pcSrc == ':'|| *pcSrc == '\0') { if (ucType > 2) return TBS_FAILED; if (*pcSrc == '\0') { if ((ULONG )_atoul(pcDst, &ulTime[ucType]) != TBS_SUCCESS) return TBS_FAILED; break; } *pcSrc = 0; if ((ULONG )_atoul(pcDst, &ulTime[ucType]) != TBS_SUCCESS) return TBS_FAILED; pcSrc++; pcDst = pcSrc; ucType++; } else { return TBS_FAILED; } } *pulDate = (ulTime[0] << 16) | (ulTime[1] << 8) | (ulTime[2]); return TBS_SUCCESS; }
int _atol(char *szSrc, int *ulVal) { ULONG ulFlag = 0; ULONG ulTmp; if (szSrc == NULL || ulVal == NULL) { MT_ERRLOG(0); return 1; } if (*szSrc == '-') { ulFlag = 1; szSrc++; } if (_atoul(szSrc, &ulTmp) != 0) { return 1; } if (ulFlag == 1) *ulVal = 0 - (char )ulTmp; else *ulVal = (char )ulTmp; return 0; }
/*used for convert hex value from string to int*/ static int str_to_num(const char *str, unsigned char *pvalue) { if ( *str == '0' && (*(str+1) == 'x' || *(str+1) == 'X') ){ if (*(str+2) == '\0'){ return -1; } else{ return _atoulx(str+2, pvalue); } } else { return _atoul(str,pvalue); } }
ULONG _VerifyTime (char *szTime1) { char *pcTmp, *pcTime ; char szTmp[10] = "", szTime[20]; UCHAR ucType; ULONG ulNum; ULONG ulLimit[3] = {23, 59, 59}; if (szTime1 == NULL || strlen(szTime1) > 8 || szTime1[0] == '\0') return TBS_FAILED; strcpy(szTime, szTime1); pcTmp = szTmp; pcTime = szTime; ucType = 0; for(; ;) { if (*pcTime <= '9' && *pcTime >= '0') *pcTmp++ = *pcTime++; else if (*pcTime == ':' || *pcTime == '\0') { if (ucType > 2 || szTmp[0] == '\0') return TBS_FAILED; *pcTmp = 0; if ((ULONG )_atoul(szTmp, &ulNum) != TBS_SUCCESS) return TBS_FAILED; if (ulNum > ulLimit[ucType]) return TBS_FAILED; if (*pcTime == '\0') break; pcTime++; pcTmp = szTmp; *szTmp = '\0'; ucType++; } else { return TBS_FAILED; } } if (ucType < 2) return TBS_FAILED; return TBS_SUCCESS; }
ULONG _VerifyDate (char *szDate1) { char *pcTmp, *pcDate ; char szTmp[10] = "", szDate[20]; UCHAR ucType; ULONG ulNum[3]; ULONG ulLimit[3][2] = {{2007, 2099}, {1, 12}, {1, 31}}; ULONG ulMaxDay[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (szDate1 == NULL || strlen(szDate1) > 10 || szDate1[0] == 0) return TBS_FAILED; strcpy(szDate, szDate1); pcTmp = szTmp; pcDate = szDate; ucType = 0; for (;;) { if (*pcDate <= '9' && *pcDate >= '0') *pcTmp++ = *pcDate++; else if (*pcDate == '-' || *pcDate == '\0') { if (ucType > 2) return TBS_FAILED; *pcTmp = 0; if ((ULONG )_atoul(szTmp, &ulNum[ucType]) != TBS_SUCCESS) return TBS_FAILED; if (ulNum[ucType] > ulLimit[ucType][1]|| ulNum[ucType] < ulLimit[ucType][0]) return TBS_FAILED; if (*pcDate == '\0') break; pcDate++; pcTmp = szTmp; *szTmp = '\0'; ucType++; } else { return TBS_FAILED; } } if (ucType < 2) return TBS_FAILED; if (ulNum[0] % 4 != 0) ulMaxDay[1] = 28; if (ulNum[2] > ulMaxDay[ulNum[1] - 1]) return TBS_FAILED; return TBS_SUCCESS; }