|
@@ -106,3 +106,137 @@ char* stringtrimspace( char * s )
|
|
|
*p2 = '\0';
|
|
|
return (s);
|
|
|
}
|
|
|
+
|
|
|
+int DiffTimeb(struct timeb ST, struct timeb ET)
|
|
|
+{
|
|
|
+ //return milli-second
|
|
|
+ unsigned int StartTime,StopTime;
|
|
|
+
|
|
|
+ StartTime=(unsigned int)ST.time;
|
|
|
+ StopTime=(unsigned int)ET.time;
|
|
|
+ return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
|
|
|
+}
|
|
|
+
|
|
|
+void trim(char *s)
|
|
|
+{
|
|
|
+ int i=0, j, k, l=0;
|
|
|
+
|
|
|
+ while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
|
|
|
+ i++;
|
|
|
+
|
|
|
+ j = strlen(s)-1;
|
|
|
+ while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
|
|
|
+ j--;
|
|
|
+
|
|
|
+ if(i==0 && j==strlen(s)-1) { }
|
|
|
+ else if(i==0) s[j+1] = '\0';
|
|
|
+ else {
|
|
|
+ for(k=i; k<=j; k++) s[l++] = s[k];
|
|
|
+ s[l] = '\0';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int mystrcmp(char *p1,char *p2)
|
|
|
+{
|
|
|
+ while(*p1==*p2)
|
|
|
+ {
|
|
|
+ if(*p1=='\0' || *p2=='\0')
|
|
|
+ break;
|
|
|
+ p1++;
|
|
|
+ p2++;
|
|
|
+ }
|
|
|
+ if(*p1=='\0' && *p2=='\0')
|
|
|
+ return(PASS);
|
|
|
+ else
|
|
|
+ return(FAIL);
|
|
|
+}
|
|
|
+
|
|
|
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
|
|
|
+{
|
|
|
+ strncpy(dest, src + start, cnt);
|
|
|
+ dest[cnt] = 0;
|
|
|
+}
|
|
|
+
|
|
|
+int strposs(char *source, char *substr, int idx)
|
|
|
+{
|
|
|
+ char stack[strlen(source)];
|
|
|
+ int result=0;
|
|
|
+ int count=0;
|
|
|
+
|
|
|
+ while(count<=idx)
|
|
|
+ {
|
|
|
+ memset(stack,0,sizeof stack);
|
|
|
+ strncpy(stack, source+result, strlen(source)-result);
|
|
|
+
|
|
|
+ int loc = strcspn(stack, substr);
|
|
|
+
|
|
|
+ if(loc>0)
|
|
|
+ result += (loc+1);
|
|
|
+ else
|
|
|
+ result = -1;
|
|
|
+
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void getSubStr(char *dest, char* src, char *split, int idx)
|
|
|
+{
|
|
|
+
|
|
|
+ int start = (strposs(src,",",idx)+1);
|
|
|
+ int cnt = (strposs(src,",",idx+1)-2)-(strposs(src,",",idx)+1);
|
|
|
+
|
|
|
+ strncpy(dest, src + start, cnt);
|
|
|
+ dest[cnt] = 0;
|
|
|
+}
|
|
|
+
|
|
|
+void split(char **arr, char *str, const char *del)
|
|
|
+{
|
|
|
+ char *s = strtok(str, del);
|
|
|
+
|
|
|
+ while(s != NULL)
|
|
|
+ {
|
|
|
+ *arr++ = s;
|
|
|
+ s = strtok(NULL, del);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int strpos(char *source, char *substr, int skip)
|
|
|
+{
|
|
|
+ char stack[strlen(source)];
|
|
|
+ strncpy(stack, source+skip, strlen(source)-skip);
|
|
|
+ char *p = strstr(stack, substr);
|
|
|
+ if (p)
|
|
|
+ return p - stack+skip;
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+
|
|
|
+char * strtrim( char * s )
|
|
|
+{
|
|
|
+ char * p1 = s;
|
|
|
+ char * p2 = s;
|
|
|
+ while(*p1 != '\0')
|
|
|
+ {
|
|
|
+ while(*p1 == '\t' || *p1 == '\n' || *p1 == '\r') //while(*p1 == ' ' || *p1 == '\t' || *p1 == '\n' || *p1 == '\r')
|
|
|
+ {
|
|
|
+ p1 ++;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ * p2 ++ = *p1 ++;
|
|
|
+ //printf("p2=%s\n",p2);
|
|
|
+ }
|
|
|
+ *p2 = '\0';
|
|
|
+ return (s);
|
|
|
+}
|
|
|
+
|
|
|
+char *random_uuid(char* buf)
|
|
|
+{
|
|
|
+ uuid_t uuid;
|
|
|
+
|
|
|
+ uuid_generate(uuid);
|
|
|
+ uuid_unparse(uuid, buf);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|