home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2UTIL.ZIP / AC.C next >
Text File  |  1990-05-21  |  15KB  |  456 lines

  1. #include <io.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. int get_ac(char *ac);
  7. int search(int i, char *ac);
  8. int get_state(char *state);
  9. int main(int argc, char **argv);
  10.  
  11.  
  12. struct AREA_CODE
  13. {
  14.     char *zip;
  15.     char *state;
  16.     char *loc[15];
  17. };
  18.  
  19. struct AREA_CODE ac_tag[56];
  20.  
  21. main(argc, argv)
  22. int argc;
  23. char **argv;
  24. {
  25.    register i;
  26.    int ac;
  27.  
  28.  
  29.    ac_tag[0].zip     = strdup("AL");
  30.    ac_tag[0].state   = strdup("Alabama");
  31.    ac_tag[0].loc[0]  = strdup("205 All locations");
  32.  
  33.    ac_tag[1].zip     = strdup("AK");
  34.    ac_tag[1].state   = strdup("Alaska");
  35.    ac_tag[1].loc[0]  = strdup("907 All locations");
  36.  
  37.    ac_tag[2].zip     = strdup("AZ");
  38.    ac_tag[2].state   = strdup("Arizona");
  39.    ac_tag[2].loc[0]  = strdup("602 All locations");
  40.  
  41.    ac_tag[3].zip     = strdup("AR");
  42.    ac_tag[3].state   = strdup("Arkansas");
  43.    ac_tag[3].loc[0]  = strdup("501 All locations");
  44.  
  45.    ac_tag[4].zip     = strdup("CA");
  46.    ac_tag[4].state   = strdup("California");
  47.    ac_tag[4].loc[0]  = strdup("209 Fresno");
  48.    ac_tag[4].loc[1]  = strdup("213 Los Angeles");
  49.    ac_tag[4].loc[2]  = strdup("408 San Jose");
  50.    ac_tag[4].loc[3]  = strdup("415 San Francisco");
  51.    ac_tag[4].loc[4]  = strdup("510 Oakland");
  52.    ac_tag[4].loc[5]  = strdup("619 San Diego");
  53.    ac_tag[4].loc[6]  = strdup("707 Santa Rosa");
  54.    ac_tag[4].loc[7]  = strdup("714 Orange");
  55.    ac_tag[4].loc[8]  = strdup("805 Bakersfield");
  56.    ac_tag[4].loc[9]  = strdup("818 Pasedena");
  57.    ac_tag[4].loc[10] = strdup("916 Sacramento");
  58.  
  59.    ac_tag[5].zip     = strdup("CN");
  60.    ac_tag[5].state   = strdup("Canada");
  61.    ac_tag[5].loc[0]  = strdup("204 Manitoba");
  62.    ac_tag[5].loc[1]  = strdup("306 Saskatchewan");
  63.    ac_tag[5].loc[2]  = strdup("403 Alberta");
  64.    ac_tag[5].loc[3]  = strdup("416 Toronto, Ontario");
  65.    ac_tag[5].loc[4]  = strdup("418 Quebec, Quebec");
  66.    ac_tag[5].loc[5]  = strdup("506 New Brunswick");
  67.    ac_tag[5].loc[6]  = strdup("514 Montreal, Quebec");
  68.    ac_tag[5].loc[7]  = strdup("519 London, Quebec");
  69.    ac_tag[5].loc[8]  = strdup("604 British Columbia");
  70.    ac_tag[5].loc[9]  = strdup("613 Ottawa, Ontario");
  71.    ac_tag[5].loc[10] = strdup("705 North Bay, Ontario");
  72.    ac_tag[5].loc[11] = strdup("709 Newfoundland");
  73.    ac_tag[5].loc[12] = strdup("807 Thunder Bay, Ontario");
  74.    ac_tag[5].loc[13] = strdup("819 Sherbrooke, Quebec");
  75.    ac_tag[5].loc[14] = strdup("902 Novia Scotia, Prince Edward Island");
  76.  
  77.    ac_tag[6].zip     = strdup("CO");
  78.    ac_tag[6].state   = strdup("Colorado");
  79.    ac_tag[6].loc[0]  = strdup("303 Denver");
  80.    ac_tag[6].loc[1]  = strdup("719 Colorado Springs");
  81.  
  82.    ac_tag[7].zip     = strdup("CT");
  83.    ac_tag[7].state   = strdup("Connecticut");
  84.    ac_tag[7].loc[0]  = strdup("203 All locations");
  85.  
  86.    ac_tag[8].zip     = strdup("DE");
  87.    ac_tag[8].state   = strdup("Deleware");
  88.    ac_tag[8].loc[0]  = strdup("302 All locations");
  89.  
  90.    ac_tag[9].zip     = strdup("DC");
  91.    ac_tag[9].state   = strdup("District of Columbia");
  92.    ac_tag[9].loc[0]  = strdup("202 Washington");
  93.  
  94.    ac_tag[10].zip    = strdup("FL");
  95.    ac_tag[10].state  = strdup("Florida");
  96.    ac_tag[10].loc[0] = strdup("305 Miami");
  97.    ac_tag[10].loc[1] = strdup("407 Ontario");
  98.    ac_tag[10].loc[2] = strdup("813 Fort Meyers");
  99.    ac_tag[10].loc[3] = strdup("904 Jacksonville");
  100.  
  101.    ac_tag[11].zip    = strdup("GA");
  102.    ac_tag[11].state  = strdup("Georgia");
  103.    ac_tag[11].loc[0] = strdup("404 Atlanta");
  104.    ac_tag[11].loc[1] = strdup("912 Savannah");
  105.  
  106.    ac_tag[12].zip    = strdup("HI");
  107.    ac_tag[12].state  = strdup("Hawaii");
  108.    ac_tag[12].loc[0] = strdup("808 All locations");
  109.  
  110.    ac_tag[13].zip    = strdup("ID");
  111.    ac_tag[13].state  = strdup("Idaho");
  112.    ac_tag[13].loc[0] = strdup("208 All locations");
  113.  
  114.    ac_tag[14].zip    = strdup("IL");
  115.    ac_tag[14].state  = strdup("Illinois");
  116.    ac_tag[14].loc[0] = strdup("217 Springfield");
  117.    ac_tag[14].loc[1] = strdup("309 Peoria");
  118.    ac_tag[14].loc[2] = strdup("312 Chicago");
  119.    ac_tag[14].loc[3] = strdup("618 Centralia");
  120.    ac_tag[14].loc[4] = strdup("815 Rockford");
  121.  
  122.    ac_tag[15].zip    = strdup("IN");
  123.    ac_tag[15].state  = strdup("Indiana");
  124.    ac_tag[15].loc[0] = strdup("219 South Bend");
  125.    ac_tag[15].loc[1] = strdup("317 Indianapolis");
  126.    ac_tag[15].loc[2] = strdup("812 Evansville");
  127.  
  128.    ac_tag[16].zip    = strdup("IA");
  129.    ac_tag[16].state  = strdup("Iowa");
  130.    ac_tag[16].loc[0] = strdup("319 Dubuque");
  131.    ac_tag[16].loc[1] = strdup("515 Des Moines");
  132.    ac_tag[16].loc[2] = strdup("712 Council Bluffs");
  133.  
  134.    ac_tag[17].zip    = strdup("KS");
  135.    ac_tag[17].state  = strdup("Kansas");
  136.    ac_tag[17].loc[0] = strdup("316 Wichita");
  137.    ac_tag[17].loc[1] = strdup("913 Topeka");
  138.  
  139.    ac_tag[18].zip    = strdup("KY");
  140.    ac_tag[18].state  = strdup("Kentucky");
  141.    ac_tag[18].loc[0] = strdup("502 Louisville");
  142.    ac_tag[18].loc[1] = strdup("606 Winchester");
  143.  
  144.    ac_tag[19].zip    = strdup("LA");
  145.    ac_tag[19].state  = strdup("Louisiana");
  146.    ac_tag[19].loc[0] = strdup("318 Shreveport");
  147.    ac_tag[19].loc[1] = strdup("504 New Orleans");
  148.  
  149.    ac_tag[20].zip    = strdup("ME");
  150.    ac_tag[20].state  = strdup("Maine");
  151.    ac_tag[20].loc[0] = strdup("207 All locations");
  152.  
  153.    ac_tag[21].zip    = strdup("MD");
  154.    ac_tag[21].state  = strdup("Maryland");
  155.    ac_tag[21].loc[0] = strdup("301 All locations");
  156.  
  157.    ac_tag[22].zip    = strdup("MA");
  158.    ac_tag[22].state  = strdup("Massachusetts");
  159.    ac_tag[22].loc[0] = strdup("413 Springfield");
  160.    ac_tag[22].loc[1] = strdup("508 Eastern Massachusetts");
  161.    ac_tag[22].loc[2] = strdup("617 Boston");
  162.  
  163.    ac_tag[23].zip    = strdup("MX");
  164.    ac_tag[23].state  = strdup("Mexico");
  165.    ac_tag[23].loc[0] = strdup("706 Northwest Mexico");
  166.    ac_tag[23].loc[1] = strdup("903 Northwest Mexico");
  167.    ac_tag[23].loc[2] = strdup("905 Mexico City");
  168.  
  169.    ac_tag[24].zip    = strdup("MI");
  170.    ac_tag[24].state  = strdup("Michigan");
  171.    ac_tag[24].loc[0] = strdup("313 Detroit");
  172.    ac_tag[24].loc[1] = strdup("517 Lansing");
  173.    ac_tag[24].loc[2] = strdup("616 Grand Rapids");
  174.    ac_tag[24].loc[3] = strdup("906 Escanaba");
  175.  
  176.    ac_tag[25].zip    = strdup("MN");
  177.    ac_tag[25].state  = strdup("Minnesota");
  178.    ac_tag[25].loc[0] = strdup("218 Duluth");
  179.    ac_tag[25].loc[1] = strdup("507 Rochester");
  180.    ac_tag[25].loc[2] = strdup("612 Minneapolis");
  181.  
  182.    ac_tag[26].zip    = strdup("MS");
  183.    ac_tag[26].state  = strdup("Mississippi");
  184.    ac_tag[26].loc[0] = strdup("601 All locations");
  185.  
  186.    ac_tag[27].zip    = strdup("MO");
  187.    ac_tag[27].state  = strdup("Missouri");
  188.    ac_tag[27].loc[0] = strdup("314 St. Louis");
  189.    ac_tag[27].loc[1] = strdup("417 Springfield");
  190.    ac_tag[27].loc[2] = strdup("816 Kansas City");
  191.  
  192.    ac_tag[28].zip    = strdup("MT");
  193.    ac_tag[28].state  = strdup("Montana");
  194.    ac_tag[28].loc[0] = strdup("406 All locations");
  195.  
  196.    ac_tag[29].zip    = strdup("NE");
  197.    ac_tag[29].state  = strdup("Nebraska");
  198.    ac_tag[29].loc[0] = strdup("308 North Platte");
  199.    ac_tag[29].loc[1] = strdup("402 Omaha");
  200.  
  201.    ac_tag[30].zip    = strdup("NV");
  202.    ac_tag[30].state  = strdup("Nevada");
  203.    ac_tag[30].loc[0] = strdup("702 All locations");
  204.  
  205.    ac_tag[31].zip    = strdup("NH");
  206.    ac_tag[31].state  = strdup("New Hampshire");
  207.    ac_tag[31].loc[0] = strdup("603 All locations");
  208.  
  209.    ac_tag[32].zip    = strdup("NJ");
  210.    ac_tag[32].state  = strdup("New Jersey");
  211.    ac_tag[32].loc[0] = strdup("201 Newark");
  212.    ac_tag[32].loc[1] = strdup("609 Trenton");
  213.  
  214.    ac_tag[33].zip    = strdup("NM");
  215.    ac_tag[33].state  = strdup("New Mexico");
  216.    ac_tag[33].loc[0] = strdup("505 All locations");
  217.  
  218.    ac_tag[34].zip    = strdup("NY");
  219.    ac_tag[34].state  = strdup("New York");
  220.    ac_tag[34].loc[0] = strdup("212 New York City, Manhattan, Bronx");
  221.    ac_tag[34].loc[1] = strdup("315 Syracuse");
  222.    ac_tag[34].loc[2] = strdup("516 Hempstead");
  223.    ac_tag[34].loc[3] = strdup("518 Albany");
  224.    ac_tag[34].loc[4] = strdup("607 Binghamton");
  225.    ac_tag[34].loc[5] = strdup("716 Buffalo");
  226.    ac_tag[34].loc[6] = strdup("718 New York City, Brooklyn, Queens, Statan Island");
  227.    ac_tag[34].loc[7] = strdup("914 White Plains");
  228.  
  229.    ac_tag[35].zip    = strdup("NC");
  230.    ac_tag[35].state  = strdup("North Carolina");
  231.    ac_tag[35].loc[0] = strdup("704 Charlotte");
  232.    ac_tag[35].loc[1] = strdup("919 Raleigh");
  233.  
  234.    ac_tag[36].zip    = strdup("ND");
  235.    ac_tag[36].state  = strdup("North Dakota");
  236.    ac_tag[36].loc[0] = strdup("701 All locations");
  237.  
  238.    ac_tag[37].zip    = strdup("OH");
  239.    ac_tag[37].state  = strdup("Ohio");
  240.    ac_tag[37].loc[0] = strdup("216 Cleveland");
  241.    ac_tag[37].loc[1] = strdup("419 Toledo");
  242.    ac_tag[37].loc[2] = strdup("513 Cincinatti");
  243.    ac_tag[37].loc[3] = strdup("614 Columbus");
  244.  
  245.    ac_tag[38].zip    = strdup("OK");
  246.    ac_tag[38].state  = strdup("Oklahoma");
  247.    ac_tag[38].loc[0] = strdup("405 Oklahoma City");
  248.    ac_tag[38].loc[1] = strdup("918 Tulsa");
  249.  
  250.    ac_tag[39].zip    = strdup("OR");
  251.    ac_tag[39].state  = strdup("Oregon");
  252.    ac_tag[39].loc[0] = strdup("503 All locations");
  253.  
  254.    ac_tag[40].zip    = strdup("PA");
  255.    ac_tag[40].state  = strdup("Pennsylvania");
  256.    ac_tag[40].loc[0] = strdup("215 Philadelphia");
  257.    ac_tag[40].loc[1] = strdup("412 Pittsburgh");
  258.    ac_tag[40].loc[2] = strdup("717 Harrisburg");
  259.    ac_tag[40].loc[3] = strdup("814 Altoona");
  260.  
  261.    ac_tag[41].zip    = strdup("PR");
  262.    ac_tag[41].state  = strdup("Puerto Rico");
  263.    ac_tag[41].loc[0] = strdup("809 Anguilla, Antigua, Bahamas, Barbados, \
  264. Bequia, Bermuda, Cayman Islands,        Dominca, Dominican Republic, \
  265. Jamaica, Montserrat, Mustique, Nevis,        Palm Island, Puerto Rico, \
  266. St. Kitts, St. Lucia, St. Vincent,            Trinidad and Tobabo, \
  267. Union Island, Virgin Islands");
  268.  
  269.    ac_tag[42].zip    = strdup("RI");
  270.    ac_tag[42].state  = strdup("Rhode Island");
  271.    ac_tag[42].loc[0] = strdup("401 All locations");
  272.  
  273.    ac_tag[43].zip    = strdup("SC");
  274.    ac_tag[43].state  = strdup("South Carolina");
  275.    ac_tag[43].loc[0] = strdup("803 All locations");
  276.  
  277.    ac_tag[44].zip    = strdup("SD");
  278.    ac_tag[44].state  = strdup("South Dakota");
  279.    ac_tag[44].loc[0] = strdup("605 All locations");
  280.  
  281.    ac_tag[45].zip    = strdup("TN");
  282.    ac_tag[45].state  = strdup("Tennessee");
  283.    ac_tag[45].loc[0] = strdup("615 Nashville");
  284.    ac_tag[45].loc[1] = strdup("901 Memphis");
  285.  
  286.    ac_tag[46].zip    = strdup("TX");
  287.    ac_tag[46].state  = strdup("Texas");
  288.    ac_tag[46].loc[0] = strdup("214 Dallas");
  289.    ac_tag[46].loc[1] = strdup("409 Galveston");
  290.    ac_tag[46].loc[2] = strdup("512 San Antonio");
  291.    ac_tag[46].loc[3] = strdup("713 Houston");
  292.    ac_tag[46].loc[4] = strdup("806 Amarillo");
  293.    ac_tag[46].loc[5] = strdup("817 Fort Worth");
  294.    ac_tag[46].loc[6] = strdup("915 Sweetwater");
  295.  
  296.    ac_tag[47].zip    = strdup("  ");
  297.    ac_tag[47].state  = strdup("Toll Free");
  298.    ac_tag[47].loc[0] = strdup("800 All locations");
  299.  
  300.    ac_tag[48].zip    = strdup("UT");
  301.    ac_tag[48].state  = strdup("Utah");
  302.    ac_tag[48].loc[0] = strdup("801 All locations");
  303.  
  304.    ac_tag[49].zip    = strdup("VT");
  305.    ac_tag[49].state  = strdup("Vermont");
  306.    ac_tag[49].loc[0] = strdup("802 All locations");
  307.  
  308.    ac_tag[50].zip    = strdup("VI");
  309.    ac_tag[50].state  = strdup("Virgin Islands");
  310.    ac_tag[50].loc[0] = strdup("809 Anguilla, Antigua, Bahamas, Barbados, \
  311. Bequia, Bermuda, Cayman Islands,        Dominca, Dominican Republic, \
  312. Jamaica, Montserrat, Mustique, Nevis,        Palm Island, Puerto Rico, \
  313. St. Kitts, St. Lucia, St. Vincent,            Trinidad and Tobabo, \
  314. Union Island, Virgin Islands");
  315.  
  316.    ac_tag[51].zip    = strdup("VA");
  317.    ac_tag[51].state  = strdup("Virginia");
  318.    ac_tag[51].loc[0] = strdup("703 Arlington");
  319.    ac_tag[51].loc[1] = strdup("804 Richmond");
  320.  
  321.    ac_tag[52].zip    = strdup("WA");
  322.    ac_tag[52].state  = strdup("Washington");
  323.    ac_tag[52].loc[0] = strdup("206 Seattle");
  324.    ac_tag[52].loc[1] = strdup("509 Spokane");
  325.  
  326.    ac_tag[53].zip    = strdup("WV");
  327.    ac_tag[53].state  = strdup("West Virginia");
  328.    ac_tag[53].loc[0] = strdup("304 All locations");
  329.  
  330.    ac_tag[54].zip    = strdup("WI");
  331.    ac_tag[54].state  = strdup("Wisconsin");
  332.    ac_tag[54].loc[0] = strdup("414 Milwaukee");
  333.    ac_tag[54].loc[1] = strdup("608 Madison");
  334.    ac_tag[54].loc[2] = strdup("715 Eau Claire");
  335.  
  336.    ac_tag[55].zip    = strdup("WY");
  337.    ac_tag[55].state  = strdup("Wyoming");
  338.    ac_tag[55].loc[0] = strdup("307 All locations");
  339.  
  340.  
  341.     if (argc == 1)
  342.     {
  343.     puts("** OS/2 Area Code Finder **");
  344.     puts("   (C) Marcusfilm 1990");
  345.     puts("\nProgram searches for telephone area codes,");
  346.     puts("   syntax: ac xxx [xxx [xxx ... ] ]");
  347.     puts("   xxx is an Area Code or State name.");
  348.     puts("   Two letter state postal codes like TX for Texas, CA for California");
  349.     puts("      can be used, otherwise type the state name.");
  350.     puts("   Enter two word state name like this: New*Jersey");
  351.     puts("   Enter * for a list of all Area Codes.");
  352.  
  353.     return 0;
  354.     }
  355.  
  356.     for (i = 1; i < argc; i++)        /* process command line parameters    */
  357.     {
  358.     ac = atoi(argv[i]);        /* see if it's an area code or state */
  359.     if (ac)             /* if not 0 then area code        */
  360.         get_ac(argv[i]);
  361.     else
  362.         get_state(argv[i]);
  363.     }
  364.  
  365.     return 0;
  366. }
  367.  
  368. get_ac(ac)
  369. char *ac;
  370. {
  371.     register i;
  372.     int idx;
  373.  
  374.     for (i = 0; i < 56; i++)
  375.     {
  376.     if ((idx = search(i, ac)) != -1)
  377.     {
  378.         printf("\n%s  %s area code\n", ac_tag[i].zip, ac_tag[i].state);
  379.         printf("    %s.\n", ac_tag[i].loc[idx]);
  380.         return 0;
  381.     }
  382.     }
  383.  
  384.     printf("Area Code %s, not found.\n", ac);
  385.     return 1;
  386. }
  387.  
  388. search(i, ac)
  389. int i;
  390. char *ac;
  391. {
  392.     register j;
  393.  
  394.     for (j = 0; j < 15; j++)
  395.     {
  396.     if (!ac_tag[i].loc[j])
  397.         return -1;
  398.     if (strstr(ac_tag[i].loc[j], ac))
  399.         return j;
  400.     }
  401.  
  402.     return -1;
  403.  
  404. }
  405.  
  406.  
  407.  
  408. get_state(state)
  409. char *state;
  410. {
  411.     register i, j, type;
  412.     char *strstate, *ast;
  413.     int suffix;
  414.  
  415.     type = (strlen(state) == 2);    /* zip code abbreviation    */
  416.     if (*state == '*')
  417.     type = 2;
  418.  
  419.     while(ast = strchr(state, '*')) /* remove all asterisks (*) */
  420.     *ast = ' ';
  421.  
  422.     for (i = 0; i < 56; i++)
  423.     {
  424.     switch (type)
  425.     {
  426.         case 0: strstate = strdup(ac_tag[i].state);
  427.             break;
  428.         case 1: strstate = strdup(ac_tag[i].zip);
  429.             break;
  430.         case 2: strstate = strdup(" ");
  431.             break;
  432.     }
  433.  
  434.     if (strstr(strupr(strstate), strupr(state)))
  435.     {
  436.         suffix = (ac_tag[i].loc[1]) ? 's' : ' ';
  437.         printf("\n%s  %s area code%c\n", ac_tag[i].zip, ac_tag[i].state, suffix);
  438.         for (j = 0; j < 15; j++)
  439.         {
  440.         if (!ac_tag[i].loc[j])
  441.             if (type == 2)
  442.             break;
  443.             else
  444.             return 0;
  445.         printf("    %s.\n", ac_tag[i].loc[j]);
  446.         }
  447.         if (type < 2)
  448.         return 0;
  449.     }
  450.     }
  451.  
  452.     return (type == 2) ? 0 : printf("State %s, not found.\n", state);
  453. }
  454.  
  455. 
  456.