\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{edb}[2003/02/19 $Id: edb.sty,v 1.2 2006/11/05 10:35:30 alex Exp alex $ edb for pLaTeX]

\typeout{$Id: edb.sty,v 1.2 2006/11/05 10:35:30 alex Exp alex $}

%
% \EdbEID{EID}
%
\def\EdbEID#1{}

%
% \EdbEOID{EOID}
%
\def\EdbEOID#1{}

%
% \EdbEMAIL{mail-address}{encoded-mail-address}
%
\def\EdbEMAIL#1#2{#2}
%
% \EdbURL{url}{encoded-url}
%
\def\EdbURL#1#2{#2}

%
% \EdbEOI{eid-of-interest}{text}
%
\def\EdbEOI#1#2{\underline{#2}}

%
% \EdbDelete{deleted-text}
%
\def\EdbDelete#1{}

%
% \EdbInsert{inserted-text}
%
\def\EdbInsert#1{#1}

\def\Edb@English{E}
\def\Edb@Japanese{J}
\def\Edb@Language{J}

\def\Edb@EtAlA{et al}
\def\Edb@EtAlB{et al.}

%
% EdbColDef{edb:columnname}{index}{language}{contents}
%
\def\EdbColDef#1#2#3#4{\def\@temp{#4}\ifx\@temp\@empty\else%
	\@namedef{#1:#2}{#4}%
	\@namedef{#1:N}{#2}%
	\@namedef{#1:#2:#3}{#4}%
	\@namedef{#1:N:#3}{#2}%
\fi%
\@tempcnta=#2\relax\ifnum\@tempcnta=0%
	\@namedef{#1:N}{#2}%
	\@namedef{#1:N:#3}{#2}%
\fi%
	\def\Edb@Language{#3}%
}

\def\edb@index@prefix{}
%
% \EdbColEID{columnname}{index}
%
\def\EdbColEID#1#2{\@ifundefined{#1\edb@index@prefix:#2:@}{0}{\@nameuse{#1\edb@index@prefix:#2:@}}}

%
% \EdbColItems{columnname}
%
\def\EdbColItems#1{\@ifundefined{#1\edb@index@prefix:N}{0}{\@nameuse{#1\edb@index@prefix:N}}}

%
% \EdbColUseItem{prefix}{columnname}{index}{postfix}{string-if-undefined}
% IF defined
%    #1 columnname#prefix:index: #4
% ELSE
%    #5
% ENDIF
\def\EdbColUseItem#1#2#3#4#5{\@ifundefined{#2\edb@index@prefix:#3}{#5}{{#1\@nameuse{#2\edb@index@prefix:#3}#4}}}
%
% \EdbColDefined{columnname}{strings-if-defined}{strings-if-undefined}
%
\def\EdbColDefined#1#2#3{\@ifundefined{#1\edb@index@prefix:N}{#3}{{#2}}}
%
% \EdbColUseItems{prefix}{columnname}{postfix}
% .... [item1]#3#1[item2]#3#1 .... #3#1[itemN] ...
%
\def\EdbColUseItems#1#2#3{%
    \@tempcnta=0\relax%
    \loop \ifnum\@tempcnta<\EdbColItems{#2}%
	\advance\@tempcnta by 1\relax%
	\def\@HEAD{#1}\def\@TAIL{#3}%
	\ifnum\@tempcnta=1\def\@HEAD{}\fi%
	\ifnum\@tempcnta=\EdbColItems{#2}\def\@TAIL{}\fi%
	\EdbColUseItem{\@HEAD}{#2}{\the\@tempcnta}{\@TAIL}{}%
    \repeat%
}
%
% \EdbColUse{prefix}{prefix-each-item}{columnname}{postfix-each-item}{postfix}{strings-if-undefined}
%
%\def\EdbColUse#1#2#3#4#5#6{\@ifundefined{#3\edb@index@prefix:N}{#6}{{#1\EdbColUseItems{#2}{#3}{#4}#5}}}
\def\EdbColUse#1#2#3#4#5#6{\@ifundefined{#3\edb@index@prefix:N}{#6}%
{{%
	\ifnum\EdbColItems{#3}=0\else#1\fi%
	\EdbColUseItems{#2}{#3}{#4}%
	\ifnum\EdbColItems{#3}=0\else#5\fi%
}}}
%
% \EdbColUseR{prefix}{prefix-each-item}{columnname}{columnname2}{postfix-each-item}{postfix}{strings-if-undefined}
%
\def\EdbColUseItemsR#1#2#3#4{%
    \@tempcnta=0\relax%
    \loop \ifnum\@tempcnta<\EdbColItems{#2}%
	\advance\@tempcnta by 1\relax%
	\def\@HEAD{#1}\def\@TAIL{#4}%
	\ifnum\@tempcnta=1\def\@HEAD{}\fi%
	\ifnum\@tempcnta=\EdbColItems{#2}\def\@TAIL{}\fi%
	\EdbColUseItem{\@HEAD}{#2}{\the\@tempcnta}{\edef\edb@index@prefix{\edb@index@prefix:\the\@tempcnta}#3\@TAIL}{}%
    \repeat%
}
%\def\EdbColUseR#1#2#3#4#5#6#7{\@ifundefined{#3\edb@index@prefix:N}{#7}{{#1\EdbColUseItemsR{#2}{#3}{#4}{#5}#6}}}
\def\EdbColUseR#1#2#3#4#5#6#7{\@ifundefined{#3\edb@index@prefix:N}{#7}%
{{%
	\ifnum\EdbColItems{#3}=0\else#1\fi%
	\EdbColUseItemsR{#2}{#3}{#4}{#5}%
	\ifnum\EdbColItems{#3}=0\else#6\fi%
}}}

%
% \EdbColUseAndItems{prefix}{columnname}{postfix}
%
\def\EdbColUseAndItems#1#2#3{%
    \@tempcnta=0\relax%
    \@tempcntb\EdbColItems{#2}\relax%
    \advance\@tempcntb by -1\relax%
    \loop \ifnum\@tempcnta<\EdbColItems{#2}%
	\advance\@tempcnta by 1\relax%
	\def\@HEAD{#1}\def\@TAIL{#3}%
	\ifnum\@tempcnta=1\def\@HEAD{}\fi%
	\ifnum\@tempcnta=\EdbColItems{#2}\def\@TAIL{}%
	\else \ifnum\@tempcnta=\@tempcntb%
	\def\@TAIL{ {\itshape and }}%
	\fi\fi%
	\EdbColUseItem{\@HEAD}{#2}{\the\@tempcnta}{\@TAIL}{}%
    \repeat%
}
\def\EdbColUseEtAlItems#1#2#3{%
    \@tempcnta=0\relax%
    \@tempcntb\EdbColItems{#2}\relax%
    \advance\@tempcntb by -1\relax%
    \loop \ifnum\@tempcnta<\EdbColItems{#2}%
	\advance\@tempcnta by 1\relax%
	\def\@HEAD{#1}\def\@TAIL{#3}%
	\ifnum\@tempcnta=1\def\@HEAD{}\fi%
	\ifnum\@tempcnta=\EdbColItems{#2}\def\@HEAD{#1 \slshape}\def\@TAIL{}%
	\else \ifnum\@tempcnta=\@tempcntb	\def\@TAIL{}%
	\def\@TAIL{ }%
	\fi\fi%
	\EdbColUseItem{\@HEAD}{#2}{\the\@tempcnta}{\@TAIL}{}%
    \repeat%
}
%
% \EdbColUseAnd{prefix}{prefix-each-item}{columnname}{postfix-each-item}{postfix}{strings-if-undefined}
%
\def\EdbColUseAnd#1#2#3#4#5#6{%
\@tempcnta=\EdbColItems{#3}%
{\def\EdbSMG{}%
\def\EdbGMS{}%
\xdef\@person{\@nameuse{#3\edb@index@prefix:\the\@tempcnta}}
}
\ifx\@person\Edb@EtAlA%
  \@ifundefined{#3\edb@index@prefix:N}{#6}{{#1\EdbColUseEtAlItems{#2}{#3}{#4}#5}}%
\else\ifx\@person\Edb@EtAlB%
  \@ifundefined{#3\edb@index@prefix:N}{#6}{{#1\EdbColUseEtAlItems{#2}{#3}{#4}#5}}%
\else%
  \@ifundefined{#3\edb@index@prefix:N}{#6}{{#1\EdbColUseAndItems{#2}{#3}{#4}#5}}%
\fi\fi%
}

\def\EdbColUseAndPersonItems#1#2#3{%
    \@tempcnta=0\relax%
    \@tempcntb\EdbColItems{#2}\relax%
    \@tempcntb\EdbColItems{#2}\relax%
    \advance\@tempcntb by -1\relax%
    \loop \ifnum\@tempcnta<\EdbColItems{#2}%
	\advance\@tempcnta by 1\relax%
	\def\@HEAD{#1}\def\@TAIL{#3}%
	\ifnum\@tempcnta=1\def\@HEAD{}\fi%
	\ifnum\@tempcnta=\EdbColItems{#2}\def\@TAIL{}%
	\else \ifnum\@tempcnta=\@tempcntb%
	\def\@TAIL{ {\it and }}%
	\fi\fi%
	\EdbColUseItem{\@HEAD}{#2}{\the\@tempcnta}{\@TAIL}{}%
    \repeat%
}
%
\def\EdbColUseAndPerson#1#2#3#4#5#6{\@ifundefined{#3\edb@index@prefix:N}{#6}{{#1\EdbColUseAndPersonItems{#2}{#3}{#4}#5}}}

%
% \EdbAND
%
\def\EdbAND{ {\itshape and} }

%
% \EdbSMG{Surname}{Middlename}{Givenname}
%
\def\EdbSMG#1#2#3{{\def\@MN{#2}\ifx\@MN\@empty{#1 #3}\else{#1 #2 #3}\fi}}

%
% \EdbGMS{Givenname}{Middlename}{Surname}
%
\def\EdbGMS#1#2#3{{\def\@MN{#2}\ifx\@MN\@empty{#1 #3}\else{#1 #2 #3}\fi}}

%
% inner macro
% \@tempcnta := #1 mod #2
\def\@edbmodulo#1#2{%
\@tempcnta=#1\relax%
\@tempcntb=#1\relax%
\divide\@tempcntb by #2\relax%
\multiply\@tempcntb by #2\relax%
\advance\@tempcnta by -\@tempcntb\relax%
}

%
% \EdbDate{YYYYMMDD}
%
\newcounter{Y}
\newcounter{M}
\newcounter{D}
\def\@EdbDateGetYMD#1{%
  \@tempcnta=#1\divide\@tempcnta by 10000\relax\c@Y=\@tempcnta\relax%
  \@edbmodulo{#1}{10000}\divide\@tempcnta by 100\relax\c@M=\@tempcnta\relax%
  \@edbmodulo{#1}{100}\relax\c@D=\@tempcnta\relax%
}
%
\def\EdbDateY@E#1{%
  \@EdbDateGetYMD{#1}%
  \ifnum\c@Y>0 \number\c@Y\fi%
}
%
\def\EdbDateYM@E#1{%
  \@EdbDateGetYMD{#1}%
  \ifnum\c@Y>0 %
    \ifnum\c@M>0 \ifnum\c@M<13\ifcase\c@M%
      \or Jan.\ \or Feb.\ \or Mar.\ \or Apr.\ \or May\ \or Jun.\ %
      \or Jul.\ \or Aug.\ \or Sep.\ \or Oct.\ \or Nov.\ \or Dec.\ \fi\fi\fi%
    \number\c@Y%
  \fi%
}
%
\def\EdbDateYMD@E#1{%
  \@EdbDateGetYMD{#1}%
  \ifnum\c@Y>0 %
    \ifnum\c@M>0 \ifnum\c@M<13%
      \ifcase\c@M%
        \or Jan.\ \or Feb.\ \or Mar.\ \or Apr.\ \or May\ \or Jun.\ %
        \or Jul.\ \or Aug.\ \or Sep.\ \or Oct.\ \or Nov.\ \or Dec.\ \fi%
      \ifnum\c@D>0 \ifnum\c@D<32 \number\c@D, \fi\fi%
    \fi\fi%
    \number\c@Y%
  \fi%
}
\def\EdbDateY@J#1{%
  \@EdbDateGetYMD{#1}%
  \ifnum\c@Y>0 \number\c@Y 年\fi%
}
%
\def\EdbDateYM@J#1{%
  \@EdbDateGetYMD{#1}%
  \ifnum\c@Y>0 \number\c@Y 年%
    \ifnum\c@M>0 \ifnum\c@M<13 \number\c@M 月\fi\fi%
  \fi%
}
%
\def\EdbDateYMD@J#1{%
  \@EdbDateGetYMD{#1}%
  \ifnum\c@Y>0 \number\c@Y 年%
    \ifnum\c@M>0 \ifnum\c@M<13 \number\c@M 月%
      \ifnum\c@D>0 \ifnum\c@D<32 \number\c@D 日\fi\fi%
    \fi\fi%
  \fi%
}
\let\EdbDate=\EdbDateYMD@J

%
% \EdbPage{startpage}{endpage}
%
\def\EdbPage#1#2{%
\def\@tempa{#1}%
\def\@tempb{#2}%
\ifx\@tempa\@empty \else%
  \ifx\@tempa\@tempb p.\@tempa\else pp.\@tempa--\@tempb\fi%
\fi%
}

%
% \EdbDatePeriod{YYYYMMDD}{YYYYMMDD}
%
\def\EdbDatePeriodYM@E#1#2{%
  \@tempcnta=#1\divide\@tempcnta by 10000\edef\@Ya{\the\@tempcnta}%
  \@edbmodulo{#1}{10000}\divide\@tempcnta by 100\edef\@Ma{\the\@tempcnta}%
  \@edbmodulo{#1}{100}\edef\@Da{\the\@tempcnta}%
  \@tempcnta=#2\divide\@tempcnta by 10000\edef\@Yb{\the\@tempcnta}%
  \@edbmodulo{#2}{10000}\divide\@tempcnta by 100\edef\@Mb{\the\@tempcnta}%
  \@edbmodulo{#2}{100}\edef\@Db{\the\@tempcnta}%
  \ifnum\@Ya>0\relax\relax%
    \ifcase\@Ma%
      \or Jan.\or Feb.\or Mar.\or Apr.\or May\or Jun.\or Jul.\or Aug.\or Sep.\or Oct.\or Nov.\or Dec.\fi%
    \ifnum\@Ya>0\relax\ifnum\@Ya=\@Yb\else\ \@Ya\fi\fi%
    --%
  \fi%
  \ifnum\@Yb>0\relax%
    \ifcase\@Mb%
      \or Jan.\or Feb.\or Mar.\or Apr.\or May\or Jun.\or Jul.\or Aug.\or Sep.\or Oct.\or Nov.\or Dec.\fi%
    \ \@Yb%
  \fi%
}
\def\EdbDatePeriodYM@J#1#2{%
  \@tempcnta=#1\divide\@tempcnta by 10000\edef\@Ya{\the\@tempcnta}%
  \@edbmodulo{#1}{10000}\divide\@tempcnta by 100\edef\@Ma{\the\@tempcnta}%
  \@edbmodulo{#1}{100}\edef\@Da{\the\@tempcnta}%
  \@tempcnta=#2\divide\@tempcnta by 10000\edef\@Yb{\the\@tempcnta}%
  \@edbmodulo{#2}{10000}\divide\@tempcnta by 100\edef\@Mb{\the\@tempcnta}%
  \@edbmodulo{#2}{100}\edef\@Db{\the\@tempcnta}%
  \ifnum\@Ya>0\relax\@Ya 年%
    \ifnum\@Ma>0\relax\ifnum\@Ma<13\relax\@Ma 月\fi\fi%
  \fi%
  \ifnum\@Yb>0\relax%
    \ifnum\@Ya=\@Yb\relax%
      \ifnum\@Ma=\@Mb\relax%
      \else%
        $\sim$\ \ifnum\@Mb>0\relax\ifnum\@Mb<13\relax\@Mb 月\fi\fi%
      \fi%
    \else%
      $\sim$\ \ifnum\@Yb<9999\relax\@Yb 年\ifnum\@Mb>0\relax\ifnum\@Mb<13\relax\@Mb 月\fi\fi\fi%
    \fi%
  \fi%
}
\let\EdbDatePeriod=\EdbDatePeriodYM@J
%
\endinput
