int get_attribute( const list<TagAttribute> *as, const char *name, int dflt, const char *s1, int v1, ... ) { if (as) { list<TagAttribute>::const_iterator i; for (i = as->begin(); i != as->end(); ++i) { if (cmp_nocase((*i).first, name) == 0) { const char *s = s1; int v = v1; va_list va; va_start(va, v1); for (;;) { if (cmp_nocase(s, (*i).second) == 0) break; s = va_arg(va, const char *); if (!s) { v = dflt; break; } v = va_arg(va, int); } va_end(va); return v; } } } return dflt; }
int str2month_full(const string &month) { for (int i = 0; i < 12; i++) { if (cmp_nocase(month_full[i], month) == 0) { return i; } } return 0; }
int get_attribute( const list<TagAttribute> *as, const char *name, // Attribute name const char *dflt1, // If attribute not specified int dflt2, // If string value does not match s1, ... const char *s1, int v1, ... ) { if (as) { list<TagAttribute>::const_iterator i; for (i = as->begin(); i != as->end(); ++i) { if (cmp_nocase((*i).first, name) == 0) { dflt1 = (*i).second.c_str(); break; } } } if (!dflt1) return dflt2; const char *s = s1; int v = v1; va_list va; va_start(va, v1); for (;;) { if (cmp_nocase(s, dflt1) == 0) break; s = va_arg(va, const char *); if (!s) break; v = va_arg(va, int); } va_end(va); return s ? v : dflt2; }
int get_attribute( const list<TagAttribute> *as, const char *name, int dflt ) { if (as) { list<TagAttribute>::const_iterator i; for (i = as->begin(); i != as->end(); ++i) { if (cmp_nocase((*i).first, name) == 0) return atoi((*i).second.c_str()); } } return dflt; }
string get_attribute( const list<TagAttribute> *as, const char *name, const char *dflt ) { if (as) { list<TagAttribute>::const_iterator i; for (i = as->begin(); i != as->end(); ++i) { if (cmp_nocase((*i).first, name) == 0) return string((*i).second); } } return string(dflt); }
string t_credentials::encode(void) const { string s = auth_scheme; s += ' '; if (cmp_nocase(auth_scheme,AUTH_DIGEST) == 0) { s += digest_response.encode(); } else { for (list<t_parameter>::const_iterator i = auth_params.begin(); i != auth_params.end(); i++) { if (i != auth_params.begin()) s += ','; s += i->encode(); } } return s; }
string get_attribute( const list<TagAttribute> *as, const char *name, bool *exists ) { *exists = true; if (as) { list<TagAttribute>::const_iterator i; for (i = as->begin(); i != as->end(); ++i) { if (cmp_nocase((*i).first, name) == 0) return string((*i).second); } } *exists = false; return string(""); }
void comp_vecs(const char *fn1, const char *fn2) { char str1[128], str2[128]; enum line_type ty1, ty2; int no1, no2, err_cnt, np_cnt, req; FILE *if1, *if2; err_cnt = np_cnt = 0; req = TRUE; if(fopen_s(&if1, fn1, "r")) { printf("\n*** 1st file (%s) not found ***", fn1); return; } if(fopen_s(&if2, fn2, "r")) { printf("\n*** 2nd file (%s) not found ***", fn2); return; } for(;;) // while there is still input { if(req) // if another line needs to be input { ty1 = find_line(if1, str1); ty2 = find_line(if2, str2); } if(ty1 == bad_line && ty2 == bad_line) // if end of file on both files break; if(ty1 == bad_line || ty2 == bad_line) // if end of file on one file { printf("\n%s%s%s%s" , fn1, (ty1 == bad_line ? " short" : " long"), "er than ", fn2); break; } if(ty1 == test_no) // if 'test number' line in file 1 no1 = get_dec(str1); if(ty2 == test_no) // if 'test number' line in file 2 no2 = get_dec(str2); if(cmp_nocase(str1, str2) == 0) { req = TRUE; continue; // if lines are the same continue } if(ty1 == test_no && ty2 == test_no) // if not the same but both are at a { // 'test number' line np_cnt += abs(no2 - no1); req = FALSE; if(no2 < no1) // extra tests in file 2 { printf("\nextra test(s) in %s:\n %s", fn2, str2); no2 = sync(no1, if2, str2, np_cnt < 10); // skip tests in file 2 } if(no1 < no2) // extra test in file 1 { printf("\nextra test(s) in %s:\n %s", fn1, str1); no1 = sync(no2, if1, str1, np_cnt < 10);// skip tests in file 1 } } else if(ty1 != ty2) // cannot synchronise test vector files { printf("\n*** synchronisation error tests %i and %i ***", no1, no2); fflush(stdout); return; } else if(ty1 != bad_line) // test vector mismatch { err_cnt++; printf("\r*** mismatch error test %i ***", no1); } fflush(stdout); } if(np_cnt && !err_cnt) // all tests present match printf("\nother tests match\n"); else { if(err_cnt) printf("\r%s doesn't match %s (%i errors)\n", fn2, fn1, err_cnt); else printf("\r%s matches %s\n", df_string(fn2), df_string(fn1)); } fclose(if1); fclose(if2); }