/* * numchar.c v1.0 (1999-08-03) * * This program finds all possible ways a phone number may be expressed * using the US system in which digits of a phone number can be replaced * by characters. * *===============================================================================* * * Copyright (c) 1999 G. Adam Stanislav * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include #include #include #ifdef _WIN32 #define PHDECODE "PHDECODE.EXE" #else #define PHDECODE "phdecode" #endif static int onepass = 0; static unsigned char *source = NULL; static unsigned char *destin = NULL; static const unsigned char digits[24] = "ABCDEFGHIJKLMNOPRSTUVWXY"; static void displaynumber(int digit) { register unsigned char c, save; register int i, j; c = save = destin[digit]; if (c == '\0') { printf("\t%s\n", destin); } else { switch (toupper(c)) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '*': case '#': case '-': break; case 'A': case 'B': case 'C': c = '2'; break; case 'D': case 'E': case 'F': c = '3'; break; case 'G': case 'H': case 'I': c = '4'; break; case 'J': case 'K': case 'L': c = '5'; break; case 'M': case 'N': case 'O': c = '6'; break; case 'P': case 'R': case 'S': c = '7'; break; case 'T': case 'U': case 'V': c = '8'; break; case 'W': case 'X': case 'Y': c = '9'; break; case 'Q': case 'Z': c = '?'; break; default: c = '-'; break; } destin[digit] = c; displaynumber(digit+1); if (onepass == 0 && c >= '2' && c <= '9') { i = c - '2'; for (j = 0; j < 3; j++) { destin[digit] = digits[i*3+j]; displaynumber(digit+1); } } destin[digit] = save; } } static int numchar(char *src) { if (src == NULL) return 1; destin = strdup(src); if (destin == NULL) { fprintf(stderr, "NUMCHAR: Not enough memory.\n"); return 1; } source = src; displaynumber(0); free(destin); source = NULL; destin = NULL; return 0; } int main(int argc, char *argv[]) { int i; if (strstr(argv[0], PHDECODE)) onepass = 1; for (i = 1; i < argc; i++) { printf("\n%s:\n" + (i == 1), argv[i]); if (numchar(argv[i])) return 1; } return 0; }