////////////////////////////////////////////////////////////////////////////// // // // template_cmpr.slt -- Telix SALT Function to compare a string against // // a template that contains wild cards. The // // template is passed to the function. // // // // Wildcard format: ? - Indicates any single byte is acceptable. // // %xy - Indicates that a numeric variable is // // acceptable. x - indicates the variable // // length. y - indicates which one of three // // passed variables to compare to. // // ~ - Indicates that a single byte integer (0-9) // // is acceptable. // // // // Author: Dave Minor // // // // Date: 10-APR-1990 // // // ////////////////////////////////////////////////////////////////////////////// template_cmpr(str string_in, str template, int int_1, int int_2, int int_3) { int length, locate, template_length, string_in_length, valid, var_number, int_1_loc = 999, int_2_loc = 999, int_3_loc = 999; str active_template[81], active_template_compare[2], string_in_compare[2], work_template[81], str_length[4], str_var_number[4], temp_string[9], str_int_1[9], str_int_2[9], str_int_3[9]; //////////////////////// Check for % wild cards and insert intger variables ////////////////////////// if(int_1 != UNUSED) { valid = _true; while(valid) { if((locate = strposi(template, "%", 0)) != -1) { work_template = ""; subchrs(template,0,locate,work_template); strcat(active_template,work_template); subchrs(template,locate+1,1,str_length); length = stoi(str_length); subchrs(template,locate+2,1,str_var_number); var_number = stoi(str_var_number); if(var_number == 1) { itos(int_1,str_int_1); while(strlen(str_int_1) < length) { temp_string = "0"; strcat(temp_string,str_int_1); substr(temp_string,0,strlen(temp_string),str_int_1); } int_1_loc = strlen(active_template)+(length-1); strcat(active_template,str_int_1); } if(var_number == 2) { itos(int_2,str_int_2); while(strlen(str_int_2) < length) { temp_string = "0"; strcat(temp_string,str_int_2); substr(temp_string,0,strlen(temp_string),str_int_2); } int_2_loc = strlen(active_template)+(length-1); strcat(active_template,str_int_2); } if(var_number == 3) { itos(int_3,str_int_3); while(strlen(str_int_3) < length) { temp_string = "0"; strcat(temp_string,str_int_3); substr(temp_string,0,strlen(temp_string),str_int_3); } int_3_loc = strlen(active_template)+(length-1); strcat(active_template,str_int_3); } delchrs(template,0,locate+3); } else { valid = _false; } } } else { substr(template,0,strlen(template),active_template); } /////////////////////////////////////////// Compare string_in to active_template ////////////////////////////////// _template_match = _match; for(locate = 0; locate < strlen(active_template); locate = locate + 1) { subchrs(string_in,locate,1,string_in_compare); subchrs(active_template,locate,1,active_template_compare); if(string_in_compare != active_template_compare) { _template_match = _const_mismatch; if(locate == int_1_loc) { _template_match = _int_1_mismatch; break; } if(locate == int_2_loc) { _template_match = _int_2_mismatch; break; } if(locate == int_3_loc) { _template_match = _int_3_mismatch; break; } if(active_template_compare == "~") { if((subchr(string_in_compare,0)) < 48 || (subchr(string_in_compare,0) > 57)) { _template_match = _int_mismatch; break; } else { _template_match = _match; } } if(active_template == "?") { _template_match = _match; } } } }