/********************************************************************** * Calculates what portion of a digit string is the country code using * known country code length patterns used throughout the world. Can * analyze number without a database hit * Given: buff -- not populated, but should be char[5]. * pattern -- the digit pattern to look at. * Returns: buff, with country actual country code from pattern. * integer = length of country code, or 0 if bad pattern. */ int findCCodeInPatt(buff, pattern) char *buff; char *pattern; { int numdigs=2; /* Set default length to 2 digits */ int d1=0; int d2=0; d1=pattern[0]-'0'; d2=pattern[1]-'0'; buff[0]='\0'; switch (d1) { case 1: case 7: numdigs=1; break; case 2: if (d2!=0 && d2!=7) numdigs=3; break; case 3: if (d2==5 || d2==7 || d2==8) numdigs=3; break; case 4: if (d2==2) numdigs=3; break; case 5: if (d2==0 || d2==9) numdigs=3; break; case 6: if (d2 >= 7) numdigs=3; break; case 8: if (d2==0 || d2==3 || d2==5 || d2>=7) numdigs=3; break; case 9: if (d2==6 || d2==7 || d2==9) numdigs=3; break; default: numdigs=0; } /* end switch (d1) */ if (d2<0 || d2>9) { /* No good if second digit is not a digit */ numdigs=0; } else { if (strlen(pattern) < numdigs) { /* No good if pattern not long enough */ numdigs=0; } else { /* Copy country code portion of pattern into buff */ strncpy(buff,pattern,numdigs); buff[numdigs]='\0'; } } return(numdigs); }