common.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. }
  52. unsigned char AscToHex(unsigned char aHex)
  53. {
  54. if((aHex>=0)&&(aHex<=9))
  55. aHex += 0x30;
  56. else if((aHex>=10)&&(aHex<=15))//A-F
  57. //aHex += 0x37;
  58. aHex += 0x57;
  59. else aHex = 0xff;
  60. return aHex;
  61. }
  62. void AscStrTurnHexStr(char *AscStr, char *HexStr)
  63. {
  64. char *pAscStr=AscStr;
  65. unsigned char d,h,l;
  66. while(0!=(d=(unsigned char)*pAscStr++)){
  67. l=d&0x0f;
  68. h=d>>4;
  69. *HexStr++=AscToHex(h);
  70. *HexStr++=AscToHex(l);
  71. }
  72. *HexStr=0;
  73. }
  74. void LwEndingToBiEndingStr(char *data, int len){
  75. char tt[2];
  76. int i;
  77. for(i=0;i<len/4;i++){
  78. tt[0]=data[4*i];
  79. tt[1]=data[4*i+1];
  80. data[4*i]=data[4*i+2];
  81. data[4*i+1]=data[4*i+3];
  82. data[4*i+2]=tt[0];
  83. data[4*i+3]=tt[1];
  84. }
  85. }