Date: Tue, 16 Jan 96 21:22 EST From: dleibold@else.net (Dave Leibold) Subject: Revised ctrycode.c (Country Codes Lookup) Here is a revised edition of ctrycode.c, a C source for lookup of country codes. One glaring cootie prevented a proper readout for France (+33); some other wording cleanups were done to conform to more familiar usages and such (mostly indicated by Bob Goudreau). ---- begin program source ---- /* Based on the areacode.c for TELECOM Digest (areacode.c received from Brint Cooper, updated 5 Jan 1996 by Carl Moore) */ #include #include /* ctrycode.c - adapted from areacode.c, originating with AREACODE.MAC (Ver. 1.0 - January 2, 1981 by Kelly Smith; Ken Yap (ken@rochester.arpa) also appears in that program's credits). Compile: cc -O -o ctrycode ctrycode.c Run: ctrycode nnn nnn ... ctrycode displays the country or region assigned to a telephone country code. These country codes may have 1, 2 or 3 digits. 16 Jan 1996 - corrected and cleaned up a few items (most notably a bug which interfered with +33 France, plus cleaned up some wordings). This 1996 version was prepared by David Leibold using latest available country code information. Country codes are officially assigned by the International Telecommunications Union and published under their Recommendation E.164 (as of 1996). Bug reports, corrections, comments can be sent to dleibold@else.net. ** Entries must be in sorted order because binary search is used. */ /* add country codes */ char *countrycode[] = { "1 Canada, United States, Bahamas, Bermuda, Caribbean nations", "20 Egypt", "212Morocco", "213Algeria", "216Tunisia", "218Libya", "220Gambia", "221Senegal", "222Mauritania", "223Mali", "224Guinea", "225Cote d'Ivoire (Ivory Coast)", "226Burkina Faso", "227Niger", "228Togolese Republic", "229Benin", "230Mauritius", "231Liberia", "232Sierra Leone", "233Ghana", "234Nigeria", "235Chad", "236Central African Republic", "237Cameroon", "238Cape Verde", "239Sao Tome and Principe", "240Equatorial Guinea", "241Gabon", "242Congo", "243Zaire", "244Angola", "245Guinea-Bissau", "246Diego Garcia", "247Ascension", "248Seychelles", "249Sudan", "250Rwanda", "251Ethiopia", "252Somalia", "253Djibouti", "254Kenya", "255Tanzania", "256Uganda", "257Burundi", "258Mozambique", "259Zanzibar", "260Zambia", "261Madagascar", "262Reunion", "263Zimbabwe", "264Namibia", "265Malawi", "266Lesotho", "267Botswana", "268Swaziland", "269Comoros and Mayotte", "27 South Africa", "290Saint Helena", "291Eritrea", "297Aruba", "298Faroe Islands", "299Greenland", "30 Greece", "31 Netherlands", "32 Belgium", "33 France", "34 Spain", "350Gibraltar", "351Portugal", "352Luxembourg", "353Ireland", "354Iceland", "355Albania", "356Malta", "357Cyprus", "358Finland", "359Bulgaria", "36 Hungary", "37 (DISCONTINUED - was East Germany; 49 now used throughout Germany)", "370Lithuania", "371Latvia", "372Estonia", "373Moldova", "374Armenia", "375Belarus", "376Andorra", "377Monaco", "378San Marino", "379Vatican City", "38 (DISCONTINUED - Yugoslavia now split into 381, 385, 386, 387, 389)", "380Ukraine", "381Yugoslavia", "385Croatia", "386Slovenia", "387Bosnia and Herzegovina", "389Macedonia (Former Yugoslav Rep.)", "39 Italy", "40 Romania", "41 Switzerland and Liechtenstein", "42 Czech and Slovak Republics", "43 Austria", "44 United Kingdom", "45 Denmark", "46 Sweden", "47 Norway", "48 Poland", "49 Germany", "500Falkland Islands", "501Belize", "502Guatemala", "503El Salvador", "504Honduras", "505Nicaragua", "506Costa Rica", "507Panama", "508Saint Pierre and Miquelon", "509Haiti", "51 Peru", "52 Mexico", "53 Cuba", "54 Argentina", "55 Brazil", "56 Chile", "57 Colombia", "58 Venezuela", "590Guadeloupe", "591Bolivia", "592Guyana", "593Ecuador", "594Guiana", "595Paraguay", "596Martinique", "597Suriname", "598Uruguay", "599Netherlands Antilles", "60 Malaysia", "61 Australia", "62 Indonesia", "63 Philippines", "64 New Zealand", "65 Singapore", "66 Thailand", "670Northern Mariana Islands", "671Guam", "672Australian External Territories", "673Brunei Darussalam", "674Nauru", "675Papua New Guinea", "676Tonga", "677Solomon Islands", "678Vanuatu", "679Fiji", "680Palau", "681Wallis and Futuna", "682Cook Islands", "683Niue", "684American Samoa", "685Western Samoa", "686Kiribati", "687New Caledonia", "688Tuvalu", "689French Polynesia", "690Tokelau", "691Micronesia", "692Marshall Islands", "7 Russia, Kazakhstan, Tajikistan, Turkmenistan, Uzbekistan", "800International Freephone", "81 Japan", "82 Korea", "84 Vietnam", "850North Korea", "852Hong Kong", "853Macau", "855Cambodia", "856Laos", "86 China", "870Inmarsat: SNAC service", "871Inmarsat: Atlantic Ocean East", "872Inmarsat: Pacific Ocean", "873Inmarsat: Indian Ocean", "874Inmarsat: Atlantic Ocean West", "875Reserved for maritime mobile services", "876Reserved for maritime mobile services", "877Reserved for maritime mobile services", "878Reserved for maritime mobile services", "879Reserved for maritime mobile services", "880Bangladesh", "886Taiwan", "90 Turkey", "91 India", "92 Pakistan", "93 Afghanistan", "94 Sri Lanka", "95 Burma (Myanmar)", "960Maldives", "961Lebanon", "962Jordan", "963Syria", "964Iraq", "965Kuwait", "966Saudi Arabia", "967Yemen", "968Oman", "969(formerly South Yemen - now 967 after unification)", "971United Arab Emirates", "972Israel", "973Bahrain", "974Qatar", "975Bhutan", "976Mongolia", "977Nepal", "98 Iran", "994Azerbaijan", "995Georgia", "996Kyrgyz Republic" }; char *where(code) char *code; { register int i, codelen, high, low, mid; int strncmp(); char incode[3]; if ((codelen = strlen(code))> 3) return ("not a valid country code"); strncpy(incode, code, 3); if (codelen < 3) incode[2] = ' '; if (codelen < 2) incode[1] = ' '; low = 0; high = sizeof(countrycode) / sizeof(countrycode[0]); while (low <= high) { mid = (low + high) / 2; i = strncmp(incode, countrycode[mid], 3); if (i < 0) high = mid - 1; else if (i> 0) low = mid + 1; else return (countrycode[mid] + 3); } return ("not a valid country code"); } main(argc, argv) int argc; char *argv[]; { char *where(); if (argc < 2) { printf("Usage: ctrycode nnn nnn ...\n"); printf("This program displays countries for given "); printf("telephone country codes\n"); exit(1); } for (--argc, ++argv; argc> 0; --argc, ++argv) printf("Country code %s is %s. \n", *argv, where(*argv)); }

AltStyle によって変換されたページ (->オリジナル) /