From 821ed061f8505099e7c751f71b757deeebd86dbd Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 6 May 2012 23:28:08 +0000 Subject: codicefiscaleitaliano git-svn-id: svn://tug.org/texlive/trunk@26234 c570f23f-e606-0410-a88d-b1316a301751 --- .../doc/latex/codicefiscaleitaliano/README | 2 +- .../codicefiscaleitaliano.pdf | Bin 208187 -> 216315 bytes .../codicefiscaleitaliano.dtx | 202 ++++++++++++++------- .../codicefiscaleitaliano.sty | 56 +++++- 4 files changed, 185 insertions(+), 75 deletions(-) diff --git a/Master/texmf-dist/doc/latex/codicefiscaleitaliano/README b/Master/texmf-dist/doc/latex/codicefiscaleitaliano/README index 25e677c32d9..8a31dee6ccd 100755 --- a/Master/texmf-dist/doc/latex/codicefiscaleitaliano/README +++ b/Master/texmf-dist/doc/latex/codicefiscaleitaliano/README @@ -1,4 +1,4 @@ -Codicefiscaleitaliano bundle; version 1.1 2012/05/03 +Codicefiscaleitaliano bundle; version 1.2 2012/05/06 This small package is intended to check the consistency of the Italian fiscal code string; a misspelled string is evidently inconsistent, but diff --git a/Master/texmf-dist/doc/latex/codicefiscaleitaliano/codicefiscaleitaliano.pdf b/Master/texmf-dist/doc/latex/codicefiscaleitaliano/codicefiscaleitaliano.pdf index 838233dd376..e874c1d2fdb 100755 Binary files a/Master/texmf-dist/doc/latex/codicefiscaleitaliano/codicefiscaleitaliano.pdf and b/Master/texmf-dist/doc/latex/codicefiscaleitaliano/codicefiscaleitaliano.pdf differ diff --git a/Master/texmf-dist/source/latex/codicefiscaleitaliano/codicefiscaleitaliano.dtx b/Master/texmf-dist/source/latex/codicefiscaleitaliano/codicefiscaleitaliano.dtx index 1caaec36b09..6b93eb58a29 100755 --- a/Master/texmf-dist/source/latex/codicefiscaleitaliano/codicefiscaleitaliano.dtx +++ b/Master/texmf-dist/source/latex/codicefiscaleitaliano/codicefiscaleitaliano.dtx @@ -55,22 +55,22 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % %<+package>\ProvidesPackage{codicefiscaleitaliano}% %<*package> - [2012/05/03 v.1.1 Controlla il codice fiscale italiano] + [2012/05/06 v.1.2 Controlla il codice fiscale italiano] % %<*driver> -\documentclass{ltxdoc} +\documentclass[letterpaper]{ltxdoc} \hfuzz 10pt \usepackage{multicol} \usepackage[utf8]{inputenc} \usepackage[italian,english]{babel} -\usepackage{array,booktabs} +\usepackage{array,booktabs,trace} \usepackage{codicefiscaleitaliano} \GetFileInfo{codicefiscaleitaliano.dtx} \title{The extension package \textsf{codicefiscaleitaliano}\thanks{Version number \fileversion; last revised \filedate.}} \author{Claudio Beccari} \date{} -\begin{document} +\begin{document}\errorcontextlines=20 \maketitle \begin{multicols}{2} \tableofcontents @@ -80,11 +80,11 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % % \fi % -% \CheckSum{149} +% \CheckSum{206} % \begin{abstract} % This small package is meant to help users to check the Italian Fiscal Code spelling; % it produces an ``info'' message in the log file if the code is selfconsitent; otherwise, -% without actually correcting the code, it issues an error message the informs the user +% without actually correcting the code, it issues an error message that informs the user % of the incorrecteness of the current fiscal code and urges him to provide for a revision, % but it does not forbid to continue typesetting the document. % @@ -119,9 +119,8 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. %\item[M] è una lettera che identifica il mese di nascita della persona; %\item[GG] sono le cifre del giorno di nascita della persona, eventualmente % aggiunte al numero 40, nel caso delle persone di sesso femminile; -%\item[LLLL] è il codice indicativo del comune di nascita della persona, -% se è nata in Italia, oppure il codice identificativa della nazione estera -% dove essa è nata; +%\item[LLLL] è il codice indicativo del comune o della nazione straniera di +% nascita della persona, a seconda che sia nata in Italia o all'estero; %\item[K] è la lettera di controllo. % \end{description} % Per evitare situazioni di \emph{omocodia}, cioè di persone identificate dallo @@ -129,7 +128,7 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % venire sostituite da apposite lettere, ma solo l'Amministrazione Centrale dello % Stato può farlo perché solo l'amministrazione conosce quali codici siano già % stati attribuiti, a chi e quando. -% All'utente finale non resta altra possibilità che controllare mediante la lettera +% All'utente finale non resta altra possibilità che verificare mediante la lettera % di controllo la coerenza dell'intero codice, ma non di generare codici solo % a partire dalle generalità di una persona; o meglio, non sarebbe molto complicato % farlo, ma si potrebbe solo generare il codice di default, non un codice che @@ -143,7 +142,10 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. %\begin{flushleft} %|\codicefiscaleitaliano{|\meta{codice fiscale da controllare}|}| %\end{flushleft} -%Il \meta{codice fiscale da controllare} va scritto in lettere maiuscole. +% Il \meta{codice fiscale da controllare} va scritto in lettere maiuscole. Come +% impostazione predefinita il comando |\codicefiscaleitaliano| esegue solo la +% verifica della coerenza del codice immesso. La versione asteriscata +% |\codicefiscaleitaliano*| produce anche la stampa del codice verificato. % % Eseguito il controllo il pacchetto si limita di scrivere un messaggio nel file % log per ricordare quale codice si è controllato, se l'esito del controllo è @@ -157,7 +159,8 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % due errori, del tutto invalido ai fini legali; probabilmente potrebbe dare luogo % a qualche altro reato, a seconda del documento che si sta scrivendo. % -% Esempio: |\codicefiscaleitaliano{NGLMRA08M64L500N}|\codicefiscaleitaliano{NGLMRA08M64L500N} +% Esempio: |\codicefiscaleitaliano{NGLMRA08M64L500N}| +%\codicefiscaleitaliano{NGLMRA08M64L500N} % % Siccome il codice è valido, non appaiono messaggi sullo schermo; se fosse stato % invalido, sarebbe apparso un vistoso messaggio d'errore sullo schermo. @@ -166,10 +169,29 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % nella macro |\CFisc| che può essere usata per scrivere il codice senza doverlo % ribattere. Infatti ottengo: \CFisc. % +% Peraltro il comando |\codicefiscaleitaliano*{NGLMRA08M64L500N}| produce direttamente +% \codicefiscaleitaliano*{NGLMRA08M64L500N}. Ma il comando asteriscato non produce +% niente se il codice fiscale non è consistente, mentre entrambi i comandi definiscono +% comunque la macro |\CFisc|, il cui uso produce il codice fiscale immesso per essere +% verificato sia esso consistente oppure errato. +% +% Attenzione: devono essere prese alcune precauzioni: +% \begin{enumerate} +% \item Il codice fiscale da controllare deve essere immesso \emph{solo} in lettere +% maiuscole, però può avere i suoi campi spaziati e gli spazi non contano nella determinazione della lunghezza della stringa da controllare. Infatti il codice +% |\codicefiscaleitaliano*{NGL MRA 08M64 L500 N}| produce nel file log l'informazione +% che il codice fiscale è consistente e nel testo ripete la stringa spaziata immessa +% per il controllo: \codicefiscaleitaliano*{NGL MRA 08M64 L500 N}. +% \item Se il codice immesso ha meno di 16 caratteri, il comando produce un avviso +% di errore e non esegue nessun controllo. +% \item Se il codice immesso ha più di 16 caratteri il comando produce un avviso +% di errore e non esegue nessun controllo. +% \end{enumerate} +% %\selectlanguage{english} % \section{Disclaimer} % Although I did my best so as to assure a correct control of the fiscal code -% string I cannot be absolutely sure that this control does not produce false +% string, I cannot be absolutely sure that this control does not produce false % positive or false negative results. % % Since this work is subject to the \LaTeX\ Project Public Licence, it is the @@ -204,24 +226,23 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % Here begins the code documentation; I warn the reader that this code % contains some ``dirty tricks'', at least according to my opinion; therefore % the reading might result quite difficult. I try to be clear also -% for myself, because I would like to understand it when I read this code -% some time from now. +% for my own behalf, because I would like to be able to understand it when +% I read it some time from now. % % In the preamble of this documented \TeX\ file we requested a % recent \LaTeX\ kernel; actually this code contains very little \LaTeX\ code, % but it requires a sufficiently recent typesetting engine, therefore a -% sufficiently recent \LaTeX\ kernel; most of the code contained here after +% sufficiently recent \LaTeX\ kernel; most of the code contained hereafter % is primitive \TeX\ code. % % The control algorithm requires that each fiscal code string character be -% examined and according to its position in the code (even or odd position -% order) be assigned a specific value according to a table established by -% the legislation, see table~\ref{tab:valori}. +% examined and, according to its position in the code (even or odd position +% order), be assigned a specific value according to a table established by +% the law: see table~1. % %\begin{table}\centering %\caption{Values to be assigned to the single characters in the fiscal code % string according to their position} -%\label{tab:valori} %\medskip %\begin{tabular}{ccc} %\toprule @@ -272,46 +293,58 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % % Once assigned the above numeric value to each one of the first fifteen % characters of the code, it is necessary to sum them up and compute this -% sum's modulo~26 value; this value is in the interval from zero to~25, and -% it is used to look up in the second column of table~\ref{tab:valori} which +% sum's modulo~26 value; this value lies in the interval from zero to~25, and +% it is used to look up in the second column of table~1 which % letter corresponds to such a number; this is the computed control letter, -% and the sixteenth character of the fiscal code string must match such -% computed control letter. +% and the sixteenth character of the fiscal code string subject to testing +% must match such computed control letter. % -% We have to produce macros to detach from the fiscal code string one -% character at a time form left to right; we have to determine its even +% We have to produce macros to detach from left to right one +% character at a time from the fiscal code string; we have to determine its even % or odd position, assign it a value and sum up all such values. +% Such macros should verify also if the input fiscal code is long exactly 16 +% characters long. In particular I prefer to do the following: The recursion +% goes on for 16 cycles; if before the end of the full recursion the remaining +% string is void, an error message is issued and code is produced to exit the +% recursion and the whole procedure. Similarly, if at the end of the recursion +% the string is not void, another error message is issued and the procedure is +% exited. We need a couple of logical switches to perform the whole procedure. +% \iffalse +%<*package> +% \fi +% \begin{macrocode} +\newif\ifcontrollo \controllotrue +\newif\ifstampacodice \stampacodicefalse +% \end{macrocode} % % First we define a delimited argument macro that detaches the leftmost % character and retrieves its \textsc{ascii} address, while reassigning % the remaining characters to the possibly shortened fiscal code string; -% at the end of the process the fiscal code string should vanish. +% at the end of the process the fiscal code string should vanish. % % Notice that with the input string right delimited by an exclamation mark, % only the first token (the first character) is assigned to argument |#1|, -% and the remaining string to the second argument |#2|. Notice also the +% and the remaining string to the second argument |#2|. Notice also that % |\Letter| is a \TeX\ counter and the notation |`#1| retrieves the \textsc{ascci} % address corresponding to argument |#1|. It would be wrong to write % |`\#1| because the |\Letter| counter would be assigned the \textsc{ascii} % address of |#|. -% \iffalse -%<*package> -% \fi % \begin{macrocode} -\def\getCFletter#1#2!{\Letter=`#1\def\CFisc{#2}} +\def\getCFletter#1#2!{\ifx#1\space\getCFLetter#2!\else + \Letter=`#1\def\CFisc{#2}\fi} % \end{macrocode} % % Now we generate a macro that assigns counter|\valore| a specific value % for odd positioned characters, according to the third column of -% table~\ref{tab:valori}. We first check if the \textsc{ascii} address of -% the character precedes that of character `A'; in this is true we are dealing +% table~1. We first check if the \textsc{ascii} address of +% the character precedes that of character `A'; in this is true, we are dealing % with a digit, otherwise with a letter. Since the third column of -% table~\ref{tab:valori} does not contain ordered values we need a look up +% table~1 does not contain ordered values we need a look up % table: even better, we need a numeric expression that yields a value between % zero and 25 depending on the \textsc{ascii} address of the examined % character: such an address is contained in counter |\Letter| therefore we % have to subtract the \textsc{ascii} address of zero or of `A' depending if -% the character is a digit or a letter; that is the purpose of the |\numexpr| +% the character is a digit or a letter; this is the purpose of the |\numexpr| % numerical expressions performed with the \mbox{$\varepsilon$-\TeX} syntax: % \begin{macrocode} \def\getOddValore{% @@ -339,10 +372,10 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % \end{macrocode} % % Now comes the real testing macro. First the fiscal code string to be checked -% is passed to the control sequence |\CFisc|; then a group is opened so that +% is assigned to the control sequence |\CFisc|; then a group is opened so that % any assignment performed within this group remains local and everything is % undone upon closing the group. Several counters are assigned a name; the -% choice of using counter numbers above 255 is a habit of mine since when I +% choice of using counter numbers above 255 is a habit of mine since the time when I % first discovered this \makebox{$\varepsilon$-\TeX} feature is permanently % included within the modern distributions of the \TeX\ system; apparently this % dates back to the year 2005, so that it may be assumed that now every \TeX\ @@ -354,7 +387,10 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % % % \begin{macrocode} -\newcommand\codicefiscaleitaliano[1]{\edef\CFisc{#1}% +\newcommand*\codicefiscaleitaliano{% +\@ifstar{\c@dfiscit[\stampacodicetrue]}{\c@dfiscit}} +\newcommand*\c@dfiscit[2][\stampacodicefalse]{#1\edef\CFisc{#2}% +\let\codfisc\CFisc \begingroup \countdef\cifra=256 \cifra=\z@ \countdef\A=258\A=`\A @@ -364,7 +400,7 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. \countdef\somma=266 \somma=\z@ % \end{macrocode} % -% Then we start a ``while"\dots`do'\dots cycle by resorting to the \LaTeX\ +% Then we start a ``while"\dots`do'\dots'' cycle by resorting to the \LaTeX\ % kernel macro |\@wiledo|; we use the counter |\cifra| to count and point to % the position of a character and we cycle trough all the 16 fiscal code % characters; on the first run when |\cifra| equals zero, the immediate @@ -381,14 +417,46 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % sixteenth character of the fiscal code string to be checked. % \begin{macrocode} \@whilenum\cifra<16\do{\advance\cifra\@ne -\expandafter\getCFletter\CFisc!\relax -\ifodd\cifra -\getOddValore% +\ifx\CFisc\@empty + \cifra=16\controllofalse + \PackageError{codicefiscaleitaliano}{% + \MessageBreak + ************************************** + \MessageBreak + Il codice fiscale #2\MessageBreak + non ha 16 caratteri. + \MessageBreak + L'esecuzione della verifica viene\MessageBreak + interrotta. + \MessageBreak + ************************************** + }{Premere per continuare}% +\else + \expandafter\getCFletter\CFisc!\relax + \ifodd\cifra + \getOddValore% + \else + \getEvenValore% + \fi + \advance\somma\valore +\fi}\unless\ifx\CFisc\@empty\controllofalse + \PackageError{codicefiscaleitaliano}{% + \MessageBreak + ************************************** + \MessageBreak + Il codice immesso #2\MessageBreak + contiene piu' di 16 caratteri. + \MessageBreak + L'esecuzione della verifica viene\MessageBreak + interrotta. + \MessageBreak + ************************************** + }{% + Premere per continuare. + }% \else -\getEvenValore% -\fi -\advance\somma\valore -}\advance\somma-\valore + \ifcontrollo + \advance\somma-\valore % \end{macrocode} % % Now we proceed with the actual verification. The input string control letter @@ -407,31 +475,33 @@ and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf. % Agency of Incomes, or by any other document. Suitable messages are therefore % issued. % \begin{macrocode} -\Letter\somma -\divide\Letter by 26\relax -\somma=\numexpr\somma - 26*\Letter\relax -\ifnum\valore=\somma -\PackageInfo{codicefiscaleitaliano}{\MessageBreak -Codice fiscale OK} -\else -\PackageError{codicefiscaleitaliano}{\MessageBreak -********************\MessageBreak -Codice fiscale #1 errato\MessageBreak -********************}{% -Premi S oppure Q oppure ; il file -verra' elaborato lo stesso ma il codice -fiscale deve venire ricontrollato!} -\fi -\endgroup} + \Letter\somma + \divide\Letter by 26\relax + \somma=\numexpr\somma - 26*\Letter\relax + \ifnum\valore=\somma + \PackageInfo{codicefiscaleitaliano}{\MessageBreak + Codice fiscale OK} + \else + \controllofalse + \PackageError{codicefiscaleitaliano}{\MessageBreak + ***************************************\MessageBreak + Codice fiscale #2 errato\MessageBreak + ***************************************}{% + Premi S oppure Q oppure ; il file + verra' elaborato lo stesso ma il codice + fiscale deve venire ricontrollato!} + \fi + \fi +\fi\ifcontrollo\ifstampacodice\codfisc\fi\fi\endgroup} \endinput % \end{macrocode} -% Please, be careful if the fiscal code string is found consistent; it might +% Please, be careful if the fiscal code string is found consistent: it might % contain two typos whose effects compensate each other. In any case do not -% blame me; I did my best to implement the checking algorithm according to +% blame me: I did my best to implement the checking algorithm according to % the fiscal code legislation; do not blame \TeX\ and company either, because % they do their computations the best they can. If it is possible that two -%or more errors compensate their effects, this is due to the way the fiscal +% or more errors compensate their effects, this is due to the way the fiscal % code has been defined. % \iffalse % diff --git a/Master/texmf-dist/tex/latex/codicefiscaleitaliano/codicefiscaleitaliano.sty b/Master/texmf-dist/tex/latex/codicefiscaleitaliano/codicefiscaleitaliano.sty index 756f756b555..6d59f18a97f 100644 --- a/Master/texmf-dist/tex/latex/codicefiscaleitaliano/codicefiscaleitaliano.sty +++ b/Master/texmf-dist/tex/latex/codicefiscaleitaliano/codicefiscaleitaliano.sty @@ -18,8 +18,11 @@ %% \NeedsTeXFormat{LaTeX2e}[2011/06/20] \ProvidesPackage{codicefiscaleitaliano}% - [2012/05/03 v.1.1 Controlla il codice fiscale italiano] -\def\getCFletter#1#2!{\Letter=`#1\def\CFisc{#2}} + [2012/05/06 v.1.2 Controlla il codice fiscale italiano] +\newif\ifcontrollo \controllotrue +\newif\ifstampacodice \stampacodicefalse +\def\getCFletter#1#2!{\ifx#1\space\getCFLetter#2!\else +\Letter=`#1\def\CFisc{#2}\fi} \def\getOddValore{% \ifnum\Letter<\A \valore=\expandafter\ifcase\numexpr\Letter-\zero\relax @@ -37,7 +40,10 @@ \else \valore=\numexpr\Letter-\A\relax \fi} -\newcommand\codicefiscaleitaliano[1]{\edef\CFisc{#1}% +\newcommand*\codicefiscaleitaliano{% +\@ifstar{\c@dfiscit[\stampacodicetrue]}{\c@dfiscit}} +\newcommand*\c@dfiscit[2][\stampacodicefalse]{#1\edef\CFisc{#2}% +\let\codfisc\CFisc \begingroup \countdef\cifra=256 \cifra=\z@ \countdef\A=258\A=`\A @@ -46,6 +52,21 @@ \countdef\valore=264 \countdef\somma=266 \somma=\z@ \@whilenum\cifra<16\do{\advance\cifra\@ne +\ifx\CFisc\@empty +\cifra=16\controllofalse +\PackageError{codicefiscaleitaliano}{% +\MessageBreak +************************************** +\MessageBreak +Il codice fiscale #2\MessageBreak +non ha 16 caratteri. +\MessageBreak +L'esecuzione della verifica viene\MessageBreak +interrotta. +\MessageBreak +************************************** +}{Premere per continuare}% +\else \expandafter\getCFletter\CFisc!\relax \ifodd\cifra \getOddValore% @@ -53,7 +74,24 @@ \getEvenValore% \fi \advance\somma\valore -}\advance\somma-\valore +\fi}\unless\ifx\CFisc\@empty\controllofalse +\PackageError{codicefiscaleitaliano}{% +\MessageBreak +************************************** +\MessageBreak +Il codice immesso #2\MessageBreak +contiene piu' di 16 caratteri. +\MessageBreak +L'esecuzione della verifica viene\MessageBreak +interrotta. +\MessageBreak +************************************** +}{% +Premere per continuare. +}% +\else +\ifcontrollo +\advance\somma-\valore \Letter\somma \divide\Letter by 26\relax \somma=\numexpr\somma - 26*\Letter\relax @@ -61,15 +99,17 @@ \PackageInfo{codicefiscaleitaliano}{\MessageBreak Codice fiscale OK} \else +\controllofalse \PackageError{codicefiscaleitaliano}{\MessageBreak -********************\MessageBreak -Codice fiscale #1 errato\MessageBreak -********************}{% +***************************************\MessageBreak +Codice fiscale #2 errato\MessageBreak +***************************************}{% Premi S oppure Q oppure ; il file verra' elaborato lo stesso ma il codice fiscale deve venire ricontrollato!} \fi -\endgroup} +\fi +\fi\ifcontrollo\ifstampacodice\codfisc\fi\fi\endgroup} %% %% Copyright 2012 Claudio Beccari -- cgit v1.2.3