|
/* FUNCTIONS */
void save_search_string(char *buf, char *leftBound, char *rightBound, char *PreFix)
{
int i,j,k,intTmp, offsetA, offsetB;
char *strTmpA;
char *strTmpB;
char *strTmpC;
char *strTmpD;
char *strPos;
intTmp = strlen(buf) + 1;
if ((strTmpA = (char *)malloc(intTmp * sizeof(char))) == NULL) {
lr_output_message("Insufficient memory available");
return;
}
if ((strTmpB = (char *)malloc(intTmp * sizeof(char))) == NULL) {
lr_output_message("Insufficient memory available");
return;
}
if ((strTmpC = (char *)malloc(intTmp * sizeof(char))) == NULL) {
lr_output_message("Insufficient memory available");
return;
}
if ((strTmpD = (char *)malloc(intTmp * sizeof(char))) == NULL) {
lr_output_message("Insufficient memory available");
return;
}
i = 0;
strPos = (char *)strstr(buf, leftBound);
if(strPos != NULL){
offsetA = (int)(strPos - buf);
}
else offsetA = -1;
strPos = (char *)strstr(buf, rightBound);
if(strPos != NULL) offsetB = (int)(strPos - buf);
else offsetB = -1;
if((offsetA < 0)||(offsetB < 0)){
sprintf(strTmpC, "%s_count", PreFix);
lr_save_string ("0", strTmpC);
free(strTmpA);
free(strTmpB);
free(strTmpC);
free(strTmpD);
return;
}
if(offsetA < offsetB){
memcpy(strTmpA, buf + offsetA + strlen(leftBound), offsetB - offsetA - strlen(leftBound));
sprintf(strTmpA + offsetB - offsetA - strlen(leftBound), "\x0");
i++;
sprintf(strTmpC, "%s_%d", PreFix, i);
lr_save_string (strTmpA, strTmpC);
if(strlen(buf) > (offsetB + strlen(rightBound))){
memcpy(strTmpB, buf + offsetB + strlen(rightBound), strlen(buf) - offsetB - strlen(rightBound));
sprintf(strTmpB + strlen(buf) - offsetB - strlen(rightBound), "\x0");
}
else sprintf(strTmpB, "");
}
if(offsetA > offsetB){
memcpy(strTmpB, buf + offsetB + strlen(rightBound), strlen(buf) - offsetB - strlen(rightBound));
sprintf(strTmpB + strlen(buf) - offsetB - strlen(rightBound), "\x0");
}
while(strcmp(strTmpB, "") != 0){
strPos = (char *)strstr(strTmpB, leftBound);
if(strPos != NULL) offsetA = (int)(strPos - strTmpB);
else offsetA = -1;
strPos = (char *)strstr(strTmpB, rightBound);
if(strPos != NULL) offsetB = (int)(strPos - strTmpB);
else offsetB = -1;
if((offsetA < 0)||(offsetB < 0)){
sprintf(strTmpC, "%s_count", PreFix);
sprintf(strTmpD, "%d", i);
lr_save_string (strTmpD, strTmpC);
free(strTmpA);
free(strTmpB);
free(strTmpC);
free(strTmpD);
return;
}
if(offsetA < offsetB){
memcpy(strTmpA, strTmpB + offsetA + strlen(leftBound), offsetB - offsetA - strlen(leftBound));
sprintf(strTmpA + offsetB - offsetA - strlen(leftBound), "\x0");
i++;
sprintf(strTmpC, "%s_%d", PreFix, i);
lr_save_string (strTmpA, strTmpC);
sprintf(strTmpC, "%s_count", PreFix);
sprintf(strTmpD, "%d", i);
lr_save_string (strTmpD, strTmpC);
if(strlen(buf) > (offsetB + strlen(rightBound))){
memcpy(strTmpC, strTmpB + offsetB + strlen(rightBound), strlen(strTmpB) - offsetB - strlen(rightBound));
sprintf(strTmpC + strlen(strTmpB) - offsetB - strlen(rightBound), "\x0");
}
else sprintf(strTmpC, "");
}
if(offsetA > offsetB){
memcpy(strTmpC, strTmpB + offsetB + strlen(rightBound), strlen(strTmpB) - offsetB - strlen(rightBound));
sprintf(strTmpC + strlen(strTmpB) - offsetB - strlen(rightBound), "\x0");
}
sprintf(strTmpB, "%s", strTmpC);
}
free(strTmpA);
free(strTmpB);
free(strTmpC);
free(strTmpD);
return;
}
//==================================
使用方法:
sendBuf 和 recvBuf 等变量定义略...
//save_search_string(返回变量,左边界,右边界,参数名);
save_search_string(recvBuf,"<ORDER_ID type=\"string\">","</ORDER_ID>","Search_Id");
if(strcmp("ok!", lr_eval_string ("{RespondCode_1}")) == 0)
{
lr_message("Pass!");
}
else
{
lr_message("Fail!");
} |
|