common.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "common.h"
  2. int GetParaFromStr(char *Str,char *Para,char *Value){
  3. int ValueLen=0,ParaLen=0;
  4. char ParaTemp[22];
  5. char *p;
  6. char d;
  7. int i=0;
  8. if(0==*Str || 0==*Para)return 0;
  9. while(0!=(d=*Para) && ParaLen<20){
  10. ParaTemp[i++]=d;
  11. if(d=='=' || d==';')return 0;
  12. Para++;
  13. ParaLen++;
  14. }
  15. ParaTemp[ParaLen++]='=';
  16. ParaTemp[ParaLen]=0;
  17. p=strstr(Str,ParaTemp);
  18. p+=ParaLen;
  19. //--
  20. while(*p>0x20 && ';'!=*p && ValueLen<=80){
  21. *Value=*p;
  22. p++;
  23. Value++;
  24. ValueLen++;
  25. }
  26. *Value=0;
  27. return ValueLen;
  28. }
  29. char msgCmp(char *msg, char *target){
  30. char *p1=target, *p2=msg;
  31. while(*p1 != 0){
  32. if(*p1 != *p2) return 0;
  33. p1++;p2++;
  34. }
  35. return 1;
  36. }
  37. // '56'->0X56
  38. unsigned char charStrToHex(char d1, char d2){
  39. unsigned char p1=d1;
  40. unsigned char p2=d2;
  41. if(p1>='0' && p1 <='9') p1 -= 0x30;
  42. else if(p1>='a' && p1 <='f') p1 -= 0x57;
  43. else if(p1>='A' && p1 <='F') p1 -= 0x37;
  44. else return 0;
  45. p1<<=4;p1&=0xF0;
  46. if(p2>='0' && p2 <='9') p2 -= 0x30;
  47. else if(p2>='a' && p2 <='f') p2 -= 0x57;
  48. else if(p2>='A' && p2 <='F') p2 -= 0x37;
  49. else return 0;
  50. return (p1|p2);
  51. }