#!/usr/local/bin/clisp -ansi -q -E utf-8
;;;; -*- mode:lisp; coding:utf-8 -*-

;; Clean the packages imported into COMMON-LISP-USER:
(MAPC (LAMBDA (USED) (UNUSE-PACKAGE USED "COMMON-LISP-USER"))
      (REMOVE (FIND-PACKAGE "COMMON-LISP")
              (COPY-SEQ (PACKAGE-USE-LIST "COMMON-LISP-USER"))))


(defparameter *departements*
  ;; (numero département préfecture sous-préfectures région)
  '(("01" "Ain" "Bourg-en-Bresse" ("Belley" "Gex" "Nantua") "Auvergne-Rhône-Alpes")
    ("02" "Aisne" "Laon" ("Château-Thierry" "Saint-Quentin" "Soissons" "Vervins")
     "Nord-Pas-de-Calais-Picardie")
    ("03" "Allier" "Moulins" ("Montluçon" "Vichy") "Auvergne-Rhône-Alpes")
    ("04" "Alpes-de-Haute-Provence" "Digne-les-Bains"
     ("Barcelonnette" "Castellane" "Forcalquier") "Provence-Alpes-Côte d'Azur")
    ("05" "Hautes-Alpes" "Gap" ("Briançon") nil)
    ("06" "Alpes-Maritimes" "Nice" ("Grasse") nil)
    ("07" "Ardèche" "Privas" ("Largentière" "Tournon-sur-Rhône")
     "Auvergne-Rhône-Alpes")
    ("08" "Ardennes" "Charleville-Mézières" ("Rethel" "Sedan" "Vouziers")
     "Alsace-Champagne-Ardenne-Lorraine")
    ("09" "Ariège" "Foix" ("Pamiers" "Saint-Girons")
     "Languedoc-Roussillon-Midi-Pyrénées")
    ("10" "Aube" "Troyes" ("Bar-sur-Aube" "Nogent-sur-Seine")
     "Alsace-Champagne-Ardenne-Lorraine")
    ("11" "Aude" "Carcassonne" ("Limoux" "Narbonne")
     "Languedoc-Roussillon-Midi-Pyrénées")
    ("12" "Aveyron" "Rodez" ("Millau" "Villefranche-de-Rouergue") nil)
    ("13" "Bouches-du-Rhône" "Marseille" ("Aix-en-Provence" "Arles" "Istres")
     "Provence-Alpes-Côte d'Azur")
    ("14" "Calvados" "Caen" ("Bayeux" "Lisieux" "Vire")
     "Région Normandie|Normandie")
    ("15" "Cantal" "Aurillac" ("Mauriac" "Saint-Flour") "Auvergne-Rhône-Alpes")
    ("16" "Charente" "Angoulême" ("Cognac" "Confolens")
     "Aquitaine-Limousin-Poitou-Charentes")
    ("17" "Charente-Maritime" "La Rochelle"
     ("Jonzac" "Rochefort" "Saint-Jean-d'Angély" "Saintes") nil)
    ("18" "Cher" "Bourges" ("Saint-Amand-Montrond" "Vierzon") "Centre-Val de Loire")
    ("19" "Corrèze" "Tulle" ("Brive-la-Gaillarde" "Ussel")
     "Aquitaine-Limousin-Poitou-Charentes")
    ("2A" "Corse-du-Sud" "Ajaccio" ("Sartène") "Corse")
    ("2B" "Haute-Corse" "Bastia" ("Calvi" "Corte") nil)
    ("21" "Côte-d'Or" "Dijon" ("Beaune" "Montbard") "Bourgogne-Franche-Comté")
    ("22" "Côtes-d'Armor" "Saint-Brieuc" ("Dinan" "Guingamp" "Lannion") "Bretagne")
    ("23" "Creuse" "Guéret" ("Aubusson") "Aquitaine-Limousin-Poitou-Charentes")
    ("24" "Dordogne" "Périgueux" ("Bergerac" "Nontron" "Sarlat-la-Canéda") nil)
    ("25" "Doubs" "Besançon" ("Montbéliard" "Pontarlier") "Bourgogne-Franche-Comté")
    ("26" "Drôme" "Valence" ("Die" "Nyons") "Auvergne-Rhône-Alpes")
    ("27" "Eure" "Évreux" ("Les Andelys" "Bernay") "Région Normandie|Normandie")
    ("28" "Eure-et-Loir" "Chartres" ("Châteaudun" "Dreux" "Nogent-le-Rotrou")
     "Centre-Val de Loire")
    ("29" "Finistère" "Quimper" ("Brest" "Châteaulin" "Morlaix") "Bretagne")
    ("30" "Gard" "Nîmes" ("Alès" "Le Vigan") "Languedoc-Roussillon-Midi-Pyrénées")
    ("31" "Haute-Garonne" "Toulouse" ("Muret" "Saint-Gaudens") nil)
    ("32" "Gers" "Auch" ("Condom" "Mirande") nil)
    ("33" "Gironde" "Bordeaux"
     ("Arcachon" "Blaye" "Langon" "Lesparre-Médoc" "Libourne")
     "Aquitaine-Limousin-Poitou-Charentes")
    ("34" "Hérault" "Montpellier" ("Béziers" "Lodève")
     "Languedoc-Roussillon-Midi-Pyrénées")
    ("35" "Ille-et-Vilaine" "Rennes" ("Fougères" "Redon" "Saint-Malo") "Bretagne")
    ("36" "Indre" "Châteauroux" ("Le Blanc" "La Châtre" "Issoudun")
     "Centre-Val de Loire")
    ("37" "Indre-et-Loire" "Tours" ("Chinon" "Loches") nil)
    ("38" "Isère" "Grenoble" ("La Tour-du-Pin" "Vienne") "Auvergne-Rhône-Alpes")
    ("39" "Jura" "Lons-le-Saunier" ("Dole" "Saint-Claude")
     "Bourgogne-Franche-Comté")
    ("40" "Landes" "Mont-de-Marsan" ("Dax") "Aquitaine-Limousin-Poitou-Charentes")
    ("41" "Loir-et-Cher" "Blois" ("Romorantin-Lanthenay" "Vendôme")
     "Centre-Val de Loire")
    ("42" "Loire" "Saint-Étienne" ("Montbrison" "Roanne") "Auvergne-Rhône-Alpes")
    ("43" "Haute-Loire" "Le Puy-en-Velay" ("Brioude" "Yssingeaux") nil)
    ("44" "Loire-Atlantique" "Nantes" ("Ancenis" "Châteaubriant" "Saint-Nazaire")
     "Pays de la Loire")
    ("45" "Loiret" "Orléans" ("Montargis" "Pithiviers") "Centre-Val de Loire")
    ("46" "Lot" "Cahors" ("Figeac" "Gourdon") "Languedoc-Roussillon-Midi-Pyrénées")
    ("47" "Lot-et-Garonne" "Agen" ("Marmande" "Nérac" "Villeneuve-sur-Lot")
     "Aquitaine-Limousin-Poitou-Charentes")
    ("48" "Lozère" "Mende" ("Florac") "Languedoc-Roussillon-Midi-Pyrénées")
    ("49" "Maine-et-Loire" "Angers" ("Cholet" "Saumur" "Segré") "Pays de la Loire")
    ("50" "Manche" "Saint-Lô" ("Avranches" "Cherbourg" "Coutances")
     "Région Normandie|Normandie")
    ("51" "Marne" "Châlons-en-Champagne"
     ("Épernay" "Reims" "Sainte-Menehould" "Vitry-le-François")
     "Alsace-Champagne-Ardenne-Lorraine")
    ("52" "Haute-Marne" "Chaumont" ("Langres" "Saint-Dizier") nil)
    ("53" "Mayenne" "Laval" ("Château-Gontier" "Mayenne") "Pays de la Loire")
    ("54" "Meurthe-et-Moselle" "Nancy" ("Briey" "Lunéville" "Toul")
     "Alsace-Champagne-Ardenne-Lorraine")
    ("55" "Meuse" "Bar-le-Duc" ("Commercy" "Verdun") nil)
    ("56" "Morbihan" "Vannes" ("Lorient" "Pontivy") "Bretagne")
    ("57" "Moselle" "Metz" ("Forbach" "Sarrebourg" "Sarreguemines" "Thionville")
     "Alsace-Champagne-Ardenne-Lorraine")
    ("58" "Nièvre" "Nevers"
     ("Château-Chinon (Ville)" "Clamecy" "Cosne-Cours-sur-Loire")
     "Bourgogne-Franche-Comté")
    ("59" "Nord" "Lille"
     ("Avesnes-sur-Helpe" "Cambrai" "Douai" "Dunkerque" "Valenciennes")
     "Nord-Pas-de-Calais-Picardie")
    ("60" "Oise" "Beauvais" ("Clermont" "Compiègne" "Senlis") nil)
    ("61" "Orne" "Alençon" ("Argentan" "Mortagne-au-Perche")
     "Région Normandie|Normandie")
    ("62" "Pas-de-Calais" "Arras"
     ("Béthune" "Boulogne-sur-Mer" "Calais" "Lens" "Montreuil" "Saint-Omer")
     "Nord-Pas-de-Calais-Picardie")
    ("63" "Puy-de-Dôme" "Clermont-Ferrand" ("Ambert" "Issoire" "Riom" "Thiers")
     "Auvergne-Rhône-Alpes")
    ("64" "Pyrénées-Atlantiques" "Pau" ("Bayonne" "Oloron-Sainte-Marie")
     "Aquitaine-Limousin-Poitou-Charentes")
    ("65" "Hautes-Pyrénées" "Tarbes" ("Argelès-Gazost" "Bagnères-de-Bigorre")
     "Languedoc-Roussillon-Midi-Pyrénées")
    ("66" "Pyrénées-Orientales" "Perpignan" ("Céret" "Prades") nil)
    ("67" "Bas-Rhin" "Strasbourg" ("Haguenau" "Molsheim" "Saverne" "Sélestat")
     "Alsace-Champagne-Ardenne-Lorraine")
    ("68" "Haut-Rhin" "Colmar" ("Altkirch" "Mulhouse" "Thann") nil)
    ("69" "Circonscription départementale du Rhône" "Lyon"
     ("Villefranche-sur-Saône") "Auvergne-Rhône-Alpes")
    ("70" "Haute-Saône" "Vesoul" ("Lure") "Bourgogne-Franche-Comté")
    ("71" "Saône-et-Loire" "Mâcon"
     ("Autun" "Chalon-sur-Saône" "Charolles" "Louhans") nil)
    ("72" "Sarthe" "Le Mans" ("La Flèche" "Mamers") "Pays de la Loire")
    ("73" "Savoie" "Chambéry" ("Albertville" "Saint-Jean-de-Maurienne")
     "Auvergne-Rhône-Alpes")
    ("74" "Haute-Savoie" "Annecy"
     ("Bonneville" "Saint-Julien-en-Genevois" "Thonon-les-Bains") nil)
    ("75" "Paris" "Île-de-France" nil nil)
    ("76" "Seine-Maritime" "Rouen" ("Dieppe" "Le Havre")
     "Région Normandie|Normandie")
    ("77" "Seine-et-Marne" "Melun" ("Fontainebleau" "Meaux" "Provins" "Torcy")
     "Île-de-France")
    ("78" "Yvelines" "Versailles"
     ("Mantes-la-Jolie" "Rambouillet" "Saint-Germain-en-Laye") nil)
    ("79" "Deux-Sèvres" "Niort" ("Bressuire" "Parthenay")
     "Aquitaine-Limousin-Poitou-Charentes")
    ("80" "Somme" "Amiens" ("Abbeville" "Montdidier" "Péronne")
     "Nord-Pas-de-Calais-Picardie")
    ("81" "Tarn" "Albi" ("Castres") "Midi-Pyrénées")
    ("82" "Tarn-et-Garonne" "Montauban" ("Castelsarrasin") nil)
    ("83" "Var" "Toulon" ("Brignoles" "Draguignan") "Provence-Alpes-Côte d'Azur")
    ("84" "Vaucluse" "Avignon" ("Apt" "Carpentras") nil)
    ("85" "Vendée" "La Roche-sur-Yon" ("Fontenay-le-Comte" "Les Sables-d'Olonne")
     "Pays de la Loire")
    ("86" "Vienne" "Poitiers" ("Châtellerault" "Montmorillon")
     "Aquitaine-Limousin-Poitou-Charentes")
    ("87" "Haute-Vienne" "Limoges" ("Bellac" "Rochechouart") nil)
    ("88" "Vosges" "Épinal" ("Neufchâteau" "Saint-Dié-des-Vosges")
     "Alsace-Champagne-Ardenne-Lorraine")
    ("89" "Yonne" "Auxerre" ("Avallon" "Sens") "Bourgogne-Franche-Comté")
    ("90" "Territoire de Belfort" "Belfort" nil nil)
    ("91" "Essonne" "Évry" ("Étampes" "Palaiseau") "Île-de-France")
    ("92" "Hauts-de-Seine" "Nanterre" ("Antony" "Boulogne-Billancourt") nil)
    ("93" "Seine-Saint-Denis" "Bobigny" ("Le Raincy" "Saint-Denis") nil)
    ("94" "Val-de-Marne" "Créteil" ("L'Haÿ-les-Roses" "Nogent-sur-Marne") nil)
    ("95" "Val-d'Oise" "Cergy" ("Argenteuil" "Pontoise" "Sarcelles") nil)
    ("971" "Guadeloupe" "Basse-Terre" ("Pointe-à-Pitre") "Guadeloupe")
    ("972" "Martinique" "Fort-de-France" ("La Trinité" "Le Marin" "Saint-Pierre")
     "Martinique")
    ("973" "Guyane" "Cayenne" ("Saint-Laurent-du-Maroni") "Guyane")
    ("974" "La Réunion" "Saint-Denis" ("Saint-Benoît" "Saint-Paul" "Saint-Pierre")
     "La Réunion")
    ("976" "Mayotte" "Mamoudzou" ("Mayotte") nil)
    ("975" "Saint-Pierre-et-Miquelon" nil nil "Pays et territoire d'outre-mer")
    ("977" "Saint-Barthélemy" nil nil "Pays et territoire d'outre-mer")
    ("978" "Saint-Martin" nil nil "Région ultrapériphérique")
    ("987" "Polynésie française" nil nil "Pays et territoire d'outre-mer")
    ("989" "île de Clipperton" nil nil nil)
    ("986" "Wallis-et-Futuna" nil nil "Pays et territoire d'outre-mer")
    ("988" "Nouvelle-Calédonie" nil nil "Pays et territoire d'outre-mer")
    ("984" "Terres australes et antarctiques françaises" nil nil nil)))

(defun departement (numero)
  (let ((numero (format nil "~2,'0D" numero)))
    (find numero *departements* :key (function first) :test (function string-equal))))

(defun main (numeros)
  (format t "~:{~3A ~A~%~
             ~@[    Préfecture:       ~A.~%~]~
             ~@[    Sous-préfectures: ~{~A~^, ~}.~%~]~
             ~:*~:[~@[    ~A.~%~]~;~@[    Région:           ~A.~%~]~]~}"
          (remove nil (mapcar (function departement) numeros)))
  0)

#+(and clisp (not testing))
(ext:exit (main ext:*args*))


;; ISO 3166-2:FR
;;
;; Les départements français possèdent un code ISO sous la forme suivante :
;; FR-XX où XX est le code du département (par ex FR-2B pour la
;; Haute-Corse). Ceci ne concerne que les départements métropolitains ;
;; les départements d'outre-mer ont un code ISO spécifique, par exemple
;; FR-GP pour la Guadeloupe.
ViewGit