2 char country code assoc list & example

Q&A's, tips, howto's

2 char country code assoc list & example

Postby CaveGuy » Tue Jun 20, 2017 10:05 am

Given the reverse dns generated by (setq rdns (net-lookup ip-add))
This example appends the expanded name if there is a 2 char code..
The value/time saver here, is the assoc list of countries.

Code: Select all
;;;
;;; Expand 2 char country codes
;;; by caveguy
;;;
(define (expand-cc rdns , tmp)
   (if (and (= "." (first (slice rdns -3)))
            (setq tmp (upper-case (slice rdns -2)))
            (setq tmp (assoc tmp cntrylst))
            (setq tmp (last tmp)))
       (string rdns " \""  tmp "\"")
       (string rdns "")))
#
(set 'cntrylst '(
  ("AF" "Afghanistan")
  ("AX" "Åland Isl.")
  ("AL" "Albania")
  ("DZ" "Algeria")
  ("AS" "American Samoa")
  ("AD" "Andorra")
  ("AO" "Angola")
  ("AI" "Anguilla")
  ("AQ" "Antarctica")
  ("AG" "Antigua & Barbuda")
  ("AR" "Argentina")
  ("AM" "Armenia")
  ("AW" "Aruba")
  ("AU" "Australia")
  ("AT" "Austria")
  ("AZ" "Azerbaijan")
  ("BS" "Bahamas")
  ("BH" "Bahrain")
  ("BD" "Bangladesh")
  ("BB" "Barbados")
  ("BY" "Belarus")
  ("BE" "Belgium")
  ("BZ" "Belize")
  ("BJ" "Benin")
  ("BM" "Bermuda")
  ("BT" "Bhutan")
  ("BO" "Bolivia")
  ("BQ" "Bonaire")
  ("BA" "Bosnia & Herzegovina")
  ("BW" "Botswana")
  ("BV" "Bouvet Isl.")
  ("BR" "Brazil")
  ("IO" "British Indian Ocean Terr.")
  ("BN" "Brunei Darussalam")
  ("BG" "Bulgaria")
  ("BF" "Burkina Faso")
  ("BI" "Burundi")
  ("KH" "Cambodia")
  ("CM" "Cameroon")
  ("CA" "Canada")
  ("CV" "Cape Verde")
  ("KY" "Cayman Isl.")
  ("CF" "Central African Rep.")
  ("TD" "Chad")
  ("CL" "Chile")
  ("CN" "China")
  ("CX" "Christmas Isl.")
  ("CC" "Cocos Isl.")
  ("CO" "Colombia")
  ("KM" "Comoros")
  ("CG" "Congo")
  ("CD" "Congo")
  ("CK" "Cook Isl.")
  ("CR" "Costa Rica")
  ("CI" "Côte d'Ivoire")
  ("HR" "Croatia")
  ("CU" "Cuba")
  ("CW" "Curaçao")
  ("CY" "Cyprus")
  ("CZ" "Czech Rep.")
  ("DK" "Denmark")
  ("DJ" "Djibouti")
  ("DM" "Dominica")
  ("DO" "Dominican Rep.")
  ("EC" "Ecuador")
  ("EG" "Egypt")
  ("SV" "El Salvador")
  ("GQ" "Equatorial Guinea")
  ("ER" "Eritrea")
  ("EE" "Estonia")
  ("ET" "Ethiopia")
  ("EU" "European Union")
  ("FK" "Falkland Isl.")
  ("FO" "Faroe Isl.")
  ("FJ" "Fiji")
  ("FI" "Finland")
  ("FR" "France")
  ("GF" "French Guiana")
  ("PF" "French Polynesia")
  ("TF" "French Southern Terr.")
  ("GA" "Gabon")
  ("GM" "Gambia")
  ("GE" "Georgia")
  ("DE" "Germany")
  ("GH" "Ghana")
  ("GI" "Gibraltar")
  ("GR" "Greece")
  ("GL" "Greenland")
  ("GD" "Grenada")
  ("GP" "Guadeloupe")
  ("GU" "Guam")
  ("GT" "Guatemala")
  ("GG" "Guernsey")
  ("GN" "Guinea")
  ("GW" "Guinea-Bissau")
  ("GY" "Guyana")
  ("HT" "Haiti")
  ("HM" "Heard & McDonald Isl.")
  ("VA" "Vatican)")
  ("HN" "Honduras")
  ("HK" "Hong Kong")
  ("HU" "Hungary")
  ("IS" "Iceland")
  ("IN" "India")
  ("ID" "Indonesia")
  ("IR" "Iran")
  ("IQ" "Iraq")
  ("IE" "Ireland")
  ("IM" "Isle of Man")
  ("IL" "Israel")
  ("IT" "Italy")
  ("JM" "Jamaica")
  ("JP" "Japan")
  ("JE" "Jersey")
  ("JO" "Jordan")
  ("KZ" "Kazakhstan")
  ("KE" "Kenya")
  ("KI" "Kiribati")
  ("KP" "Korea, North")
  ("KR" "Korea, South")
  ("KW" "Kuwait")
  ("KG" "Kyrgyzstan")
  ("LA" "Lao")
  ("LV" "Latvia")
  ("LB" "Lebanon")
  ("LS" "Lesotho")
  ("LR" "Liberia")
  ("LY" "Libya")
  ("LI" "Liechtenstein")
  ("LT" "Lithuania")
  ("LU" "Luxembourg")
  ("MO" "Macao")
  ("MK" "Macedonia")
  ("MG" "Madagascar")
  ("MW" "Malawi")
  ("MY" "Malaysia")
  ("MV" "Maldives")
  ("ML" "Mali")
  ("MT" "Malta")
  ("MH" "Marshall Isl.")
  ("MQ" "Martinique")
  ("MR" "Mauritania")
  ("MU" "Mauritius")
  ("YT" "Mayotte")
  ("MX" "Mexico")
  ("FM" "Micronesia")
  ("MD" "Moldova")
  ("MC" "Monaco")
  ("MN" "Mongolia")
  ("ME" "Montenegro")
  ("MS" "Montserrat")
  ("MA" "Morocco")
  ("MZ" "Mozambique")
  ("MM" "Myanmar")
  ("NA" "Namibia")
  ("NR" "Nauru")
  ("NP" "Nepal")
  ("NL" "Netherlands")
  ("NC" "New Caledonia")
  ("NZ" "New Zealand")
  ("NI" "Nicaragua")
  ("NE" "Niger")
  ("NG" "Nigeria")
  ("NU" "Niue")
  ("NF" "Norfolk Isl.")
  ("MP" "Mariana Isl.")
  ("NO" "Norway")
  ("OM" "Oman")
  ("PK" "Pakistan")
  ("PW" "Palau")
  ("PS" "Palestine")
  ("PA" "Panama")
  ("PG" "Papua New Guinea")
  ("PY" "Paraguay")
  ("PE" "Peru")
  ("PH" "Philippines")
  ("PN" "Pitcairn")
  ("PL" "Poland")
  ("PT" "Portugal")
  ("PR" "Puerto Rico")
  ("QA" "Qatar")
  ("RE" "Réunion")
  ("RO" "Romania")
  ("RU" "Russian Federation")
  ("RW" "Rwanda")
  ("BL" "Saint Barthélemy")
  ("SH" "Saint Helena, Ascension")
  ("KN" "Saint Kitts & Nevis")
  ("LC" "Saint Lucia")
  ("MF" "French Saint Martin")
  ("PM" "Saint Pierre & Miquelon")
  ("VC" "Saint Vincent & Grenadines")
  ("WS" "Samoa")
  ("SM" "San Marino")
  ("ST" "Sao Tome & Principe")
  ("SA" "Saudi Arabia")
  ("SN" "Senegal")
  ("RS" "Serbia")
  ("SC" "Seychelles")
  ("SL" "Sierra Leone")
  ("SG" "Singapore")
  ("SX" "Dutch Saint Martin")
  ("SK" "Slovakia")
  ("SI" "Slovenia")
  ("SB" "Solomon Isl.")
  ("SO" "Somalia")
  ("ZA" "South Africa")
  ("GS" "Georgia & Sandwich Isl.")
  ("SS" "South Sudan")
  ("ES" "Spain")
  ("LK" "Sri Lanka")
  ("SD" "Sudan")
  ("SR" "Suriname")
  ("SJ" "Svalbard & Jan Mayen")
  ("SZ" "Swaziland")
  ("SE" "Sweden")
  ("CH" "Switzerland")
  ("SY" "Syrian Arab Rep.")
  ("TW" "Taiwan")
  ("TJ" "Tajikistan")
  ("TZ" "Tanzania")
  ("TH" "Thailand")
  ("TL" "Timor-Leste")
  ("TG" "Togo")
  ("TK" "Tokelau")
  ("TO" "Tonga")
  ("TT" "Trinidad & Tobago")
  ("TN" "Tunisia")
  ("TR" "Turkey")
  ("TM" "Turkmenistan")
  ("TC" "Turks & Caicos Isl.")
  ("TV" "Tuvalu")
  ("UG" "Uganda")
  ("UA" "Ukraine")
  ("AE" "United Arab Emirates")
  ("GB" "United Kingdom")
  ("UK" "United Kingdom")
  ("US" "United States")
  ("UM" "US Outlying Isl.")
  ("UY" "Uruguay")
  ("UZ" "Uzbekistan")
  ("VU" "Vanuatu")
  ("VE" "Venezuela")
  ("VN" "Viet Nam")
  ("VG" "Brit. Virgin Isl.")
  ("VI" "US Virgin Isl.")
  ("WF" "Wallis & Futuna")
  ("EH" "Western Sahara")
  ("YE" "Yemen")
  ("ZM" "Zambia")
  ("ZW" "Zimbabwe")))
Bob the Caveguy aka Lord High Fixer.
CaveGuy
 
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests

cron