#include "stdafx.h" #include "_Form.h" #define EOM 0 #define NULL 0 // class subroutine, cut double spaces char* _Form::clear_space(char* msg) { int i=0; char tmp_msg[MAXLINE]; while(*msg != EOM) { if((*msg ==' ') && (*(msg+1) == ' ')) { ++msg; } else { tmp_msg[i++] = *msg; }++msg; }tmp_msg[i] = NULL; strcpy(out_msg, tmp_msg); return(out_msg); } //// class subroutine, change & and separate variables char* _Form::clear_amp(char* msg) { int i=0; char tmp_msg[MAXLINE]; while(*msg !=EOM) { if(*msg =='&') { tmp_msg[i++]='\n'; } else { tmp_msg[i++] = *msg; }++msg; }tmp_msg[i] = NULL; strcpy(out_msg, tmp_msg); return(out_msg); }// class subroutine, change + to space char* _Form::clear_plus(char* msg) { int i = 0; char tmp_msg[MAXLINE]; while(*msg != EOM) { if(*msg == '+') { tmp_msg[i++]=' '; } else { tmp_msg[i++] = *msg; }++msg; }tmp_msg[i]=NULL; strcpy(out_msg, tmp_msg); return(out_msg); }//// class subroutine, change hexadecimal to decimal char* _Form::clear_control(char* msg) { char val_msg[3]; int i=0; char tmp_msg[MAXLINE]; while(*msg != EOM) { if(*msg == '%') { val_msg[0]=*(msg+1); val_msg[1]=*(msg+2); val_msg[2]=0; tmp_msg[i++]=ahextoi(val_msg); msg +=3; } else { tmp_msg[i++]=*msg; msg++; } }tmp_msg[i] = NULL; strcpy(out_msg, tmp_msg); return(out_msg); }//// class subroutine, convert a hex string to a dec string int _Form::ahextoi(char* value) { int dec_value=0; int i=0; while(*(value+i) != EOM) { if((*(value+i) >= '0') && (*(value+i)<='9')) { dec_value = ( *(value+i)-'0') + (dec_value * 16); } else if ((*(value+i) >= 'A') && (*(value+i) <= 'F')) { dec_value=(((*(value+i)-'A')+10)+(dec_value*16)); } else if ((*(value+i) >='a') && (*(value+i) <='f')) { dec_value=(((*(value+i)-'a')+10)+(dec_value*16)); }i++; }return(dec_value); }// class subroutine, clear the extra charaters in the message char* _Form::clear_all(char* msg) { char local_msg[MAXLINE]; strcpy(local_msg, clear_space(msg)); strcpy(local_msg, clear_amp(local_msg)); strcpy(local_msg, clear_plus(local_msg)); strcpy(local_msg, clear_control(local_msg)); return((msg)); }/* decision routines */ //// class subroutine // obtain the variable value char* _Form::get_variable(char* msg, char* start_msg) { int start_flag=0; int length; int start_length; int j; int i=0; char tmp_msg[MAXLINE]; length=strlen(msg); start_length=strlen(start_msg); tmp_msg[0]=0; while(i<=length) { if(strncmp(msg+i,start_msg,start_length-1) !=0) { i++; } else { start_flag=1; break; } }if(start_flag==0) { return ""; } i+=start_length; j=0; while(i<=length) { if((*(char *)(msg+i) == '&') || (*(char *)(msg+i) ==' ') || (*(char *)(msg+i) == 13) || (*(char *)(msg+i) == 0)) { break; }tmp_msg[j++]=*(msg+i); i++; }tmp_msg[j]=0; strcpy(out_msg, tmp_msg); return(out_msg); } /* #define TRUE 1 #define FALSE 0 // class subroutine, check a value from input //intcheck_msg(char* variable_value, char* expect_value) { if(strcmp(variable_value, expect_value) == 0) { return TRUE; } else { return FALSE; } } */ /* ++++++++++++++++++++++++++++++++++++++++ */