%%
%% This is file `codicefiscaleitaliano.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% codicefiscaleitaliano.dtx  (with options: `package')
%%   ______________________________________________________
%%   The codicefiscaleitaliano package for LaTeX and XeLaTeX
%%   Copyright (C) 2012 Claudio Beccari
%%   All rights reserved
%% 
%%   License information appended
%% 
%%
%% File `codicefiscaleitaliano.dtx'.
%% Copyright (C)  2012 Claudio Beccari  all rights reserved.
%%
\NeedsTeXFormat{LaTeX2e}[2011/06/20]
\ProvidesPackage{codicefiscaleitaliano}%
        [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
1\or0\or5\or7\or9\or13\or15\or17\or19%
\or21\fi
\else
\valore=\expandafter\ifcase\numexpr\Letter-\A\relax
1\or0\or5\or7\or9\or13\or15\or17\or19%
\or21\or2\or4\or18\or20\or11\or3\or6\or8%
\or12\or14\or16\or10\or22\or25\or24\or23\fi
\fi}
\def\getEvenValore{%
\ifnum\Letter<\A
\valore=\numexpr\Letter-\zero\relax
\else
\valore=\numexpr\Letter-\A\relax
\fi}
\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
\countdef\zero=260 \zero=`\0
\countdef\Letter=262
\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 <invio> 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 <invio> per continuare.
}%
\else
\ifcontrollo
\advance\somma-\valore
\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 <invio>; il file
verra' elaborato lo stesso ma il codice
fiscale deve venire ricontrollato!}
\fi
\fi
\fi\ifcontrollo\ifstampacodice\codfisc\fi\fi\endgroup}

%% 
%% Copyright 2012 Claudio Beccari
%% 
%% Distributable under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
%% This work is "author-maintained"
%% 
%% This work consists of this file codicefiscaleitaliano.dtx, a README file
%% and the derived files codicefiscaleitaliano.sty and codicefiscaleitaliano.pdf.
%% 
%%
%% End of file `codicefiscaleitaliano.sty'.
