From 246510b2e59e3c0feadbb170cf02b486636c37f7 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 7 Jul 2014 23:29:39 +0000 Subject: csvsimple (7jul14) git-svn-id: svn://tug.org/texlive/trunk@34544 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/csvsimple/csvsimple.sty | 262 +++++++++++++++++++-- 1 file changed, 244 insertions(+), 18 deletions(-) (limited to 'Master/texmf-dist/tex/latex/csvsimple') diff --git a/Master/texmf-dist/tex/latex/csvsimple/csvsimple.sty b/Master/texmf-dist/tex/latex/csvsimple/csvsimple.sty index 51e622ee8ed..dae90fe51cd 100644 --- a/Master/texmf-dist/tex/latex/csvsimple/csvsimple.sty +++ b/Master/texmf-dist/tex/latex/csvsimple/csvsimple.sty @@ -1,8 +1,8 @@ -%% The LaTeX package csvsimple - version 1.07 (2013/09/25) +%% The LaTeX package csvsimple - version 1.10 (2014/07/07) %% csvsimple.sty: Simple LaTeX CSV file processing %% %% ------------------------------------------------------------------------------------------- -%% Copyright (c) 2008-2013 by Prof. Dr. Dr. Thomas F. Sturm +%% Copyright (c) 2008-2014 by Prof. Dr. Dr. Thomas F. Sturm %% ------------------------------------------------------------------------------------------- %% %% This work may be distributed and/or modified under the @@ -18,7 +18,7 @@ %% This work consists of all files listed in README %% \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{csvsimple}[2013/09/25 version 1.07 LaTeX CSV file processing] +\ProvidesPackage{csvsimple}[2014/07/07 version 1.10 LaTeX CSV file processing] \RequirePackage{pgfkeys,ifthen} @@ -26,6 +26,7 @@ %---- general \def\csv@warning#1{\PackageWarning{csvsimple}{#1}} +\def\csv@error#1#2{\PackageError{csvsimple}{#1}{#2}} \newread\csv@file \newcounter{csvinputline} @@ -119,6 +120,16 @@ \csv@breakline#1|\csv@termination|% } +% tab +\catcode`\^^I=12 +\def\csv@breakline@D#1^^I{\csv@breakline@kernel{#1}} + +\def\csv@scanline@D#1{% + \setcounter{csvcol}{0}% + \csv@breakline#1^^I\csv@termination^^I% + } +\catcode`\^^I=10 + % expands a CSV line and scans content \def\csv@escanline#1{% \toks@\expandafter{#1}% @@ -131,6 +142,13 @@ \def\csv@no@preprocessor#1#2{\let#2=#1\relax} +\def\csv@preprocessor@csvsorter#1#2#3#4{% + \begingroup% + \catcode`\"=13% + \immediate\write18{\csv@csvsorter@command\space -c "#1" -l "#2" -i "#3" -o "#4"}% + \endgroup% +} + %---- the loop \def\csv@AtEndLoop{\csv@addto@macro\@endloophook} @@ -140,7 +158,7 @@ % auto head names \def\set@csv@autohead{% - \toks0=\expandafter{\csname\csv@current@col\endcsname}% + \toks0=\expandafter{\csname\csv@current@col@clean\endcsname}% \toks1=\expandafter{\csname csvcol\roman{csvcol}\endcsname}% \edef\csv@temp{\noexpand\gdef\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\noexpand\gdef\the\toks0{}}}% \csv@temp% @@ -151,12 +169,17 @@ \def\set@csv@head{% \toks0={\gdef##1}% \toks1=\expandafter{\csname csvcol\roman{csvcol}\endcsname}% - \edef\csv@temp{\noexpand\pgfkeysdef{/csv head/\csv@current@col}{\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\the\toks0{}}}}% + \edef\csv@temp{\noexpand\pgfkeysdef{/csv head/\csv@current@col@clean}{\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\the\toks0{}}}}% \csv@temp% \edef\csv@temp{\noexpand\pgfkeysdef{/csv head/\thecsvcol}{\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\the\toks0{}}}}% \csv@temp% } +\catcode`\Q=3 +\def\csv@@clean@@head@@nameQ#1Q{\edef\csv@current@col@clean{#1}} +\def\csv@clean@head@name{\edef\csv@temp{\noexpand\csv@@clean@@head@@nameQ\csv@current@colQ}\csv@temp} +\catcode`\Q=11 + % head line \def\csv@processheadline{% \csvreadnext% @@ -165,6 +188,7 @@ \setcounter{csvcol}{0}% \loop% \stepcounter{csvcol}% + \csv@clean@head@name% \csv@opt@headtocolumnames% \set@csv@head% \ifnum\thecsvcol<\csv@columncount\repeat% @@ -246,13 +270,14 @@ % options \csvset{default,every csv,#1}% \csv@preprocessor\csv@filename\csv@ppfilename% + \csv@set@catcodes% \csv@prereading% \csv@table@begin% \setcounter{csvinputline}{0}% % start reading \openin\csv@file=\csv@ppfilename\relax% \ifeof\csv@file% - \csv@warning{File \csv@ppfilename\ not existent, not readable, or empty!}% + \csv@error{File '\csv@ppfilename' not existent, not readable, or empty!}{}% \else% % the head line \csv@opt@processheadline% @@ -304,6 +329,7 @@ \csv@latepostlastline% \csv@table@end% \csv@postreading% + \csv@reset@catcodes% } % user command @@ -337,21 +363,21 @@ \xdef\csv@columnnames{\the\toks0,\the\toks1}% }, command/.gstore in=\csv@body,% - check column count/.code={\ifthenelse{\equal{#1}{true}}{% - \global\let\csv@opt@checkcolumncount=\csv@checkcolumncount}{% - \global\let\csv@opt@checkcolumncount=\csv@nocheckcolumncount}}, + check column count/.is choice,% check column count/.default=true,% + check column count/true/.code={\global\let\csv@opt@checkcolumncount=\csv@checkcolumncount},% + check column count/false/.code={\global\let\csv@opt@checkcolumncount=\csv@nocheckcolumncount},% on column count error/.gstore in=\csv@columncounterror, - head/.code={\ifthenelse{\equal{#1}{true}}{% - \global\let\csv@opt@processheadline=\csv@processheadline% - \pgfkeysalso{check column count}}{% - \global\let\csv@opt@processheadline=\csv@noheadline% - \pgfkeysalso{check column count=false,late after head=}}}, + head/.is choice,% head/.default=true,% - head to column names/.code={\ifthenelse{\equal{#1}{true}}{% - \global\let\csv@opt@headtocolumnames=\set@csv@autohead}{% - \global\let\csv@opt@headtocolumnames=\csv@empty}},% + head/true/.code={\global\let\csv@opt@processheadline=\csv@processheadline% + \pgfkeysalso{check column count}},% + head/false/.code={\global\let\csv@opt@processheadline=\csv@noheadline% + \pgfkeysalso{check column count=false,late after head=}},% + head to column names/.is choice,% head to column names/.default=true,% + head to column names/true/.code={\global\let\csv@opt@headtocolumnames=\set@csv@autohead},% + head to column names/false/.code={\global\let\csv@opt@headtocolumnames=\csv@empty},% column count/.gstore in=\csv@columncount,% filter/.code={% \def\temp{#1}\toks@=\expandafter{\temp}% @@ -384,6 +410,19 @@ \global\let\csv@breakline\csv@breakline@B}, separator/pipe/.code={\global\let\csv@scanline=\csv@scanline@C% \global\let\csv@breakline\csv@breakline@C}, + separator/tab/.code={\global\let\csv@scanline=\csv@scanline@D% + \global\let\csv@breakline\csv@breakline@D% + \csvset{respect tab}}, + % + csvsorter command/.store in=\csv@csvsorter@command, + csvsorter configpath/.store in=\csv@csvsorter@configpath, + sort by/.style={preprocessor={\csv@preprocessor@csvsorter{\csv@csvsorter@configpath/#1}{\csv@csvsorter@log}}}, + new sorting rule/.style 2 args={sort by #1/.style={sort by={#2}}}, + csvsorter log/.store in=\csv@csvsorter@log, + csvsorter command=csvsorter, + csvsorter configpath=., + preprocessed file={\jobname_sorted._csv}, + csvsorter log={csvsorter.log}, % % default for reset default/.style={ @@ -451,7 +490,22 @@ table head=\hline\csvlinetotablerow\\\hline\endhead\hline\endfoot, late after line=\\, late after last line=\csv@tablefoot\end{longtable}\csv@posttable, - command=\csvlinetotablerow} + command=\csvlinetotablerow}, + autobooktabular/.style={ + file=#1, + after head=\csv@pretable\begin{tabular}{*{\csv@columncount}{l}}\csv@tablehead, + table head=\toprule\csvlinetotablerow\\\midrule, + late after line=\\, + table foot=\\\bottomrule, + late after last line=\csv@tablefoot\end{tabular}\csv@posttable, + command=\csvlinetotablerow}, + autobooklongtable/.style={ + file=#1, + after head=\csv@pretable\begin{longtable}{*{\csv@columncount}{l}}\csv@tablehead, + table head=\toprule\csvlinetotablerow\\\midrule\endhead\bottomrule\endfoot, + late after line=\\, + late after last line=\csv@tablefoot\end{longtable}\csv@posttable, + command=\csvlinetotablerow}, } % deprecated keys @@ -460,6 +514,166 @@ nohead/.style=no head, } +% catcodes +\def\csv@set@catcodes{% + \csv@catcode@tab@set% + \csv@catcode@tilde@set% + \csv@catcode@circumflex@set% + \csv@catcode@underscore@set% + \csv@catcode@and@set% + \csv@catcode@sharp@set% + \csv@catcode@dollar@set% + \csv@catcode@backslash@set% + \csv@catcode@leftbrace@set% + \csv@catcode@rightbrace@set% + \csv@catcode@percent@set} + +\def\csv@reset@catcodes{\csv@catcode@percent@reset% + \csv@catcode@rightbrace@reset% + \csv@catcode@leftbrace@reset% + \csv@catcode@backslash@reset% + \csv@catcode@dollar@reset% + \csv@catcode@sharp@reset% + \csv@catcode@and@reset% + \csv@catcode@underscore@reset% + \csv@catcode@circumflex@reset% + \csv@catcode@tilde@reset% + \csv@catcode@tab@reset% +} + + +\csvset{ + respect tab/.is choice, + respect tab/true/.code={% + \gdef\csv@catcode@tab@set{% + \xdef\csv@catcode@tab@value{\the\catcode`\^^I}% + \catcode`\^^I=12}% + \gdef\csv@catcode@tab@reset{\catcode`\^^I=\csv@catcode@tab@value}}, + respect tab/false/.code={% + \global\let\csv@catcode@tab@set\csv@empty% + \global\let\csv@catcode@tab@reset\csv@empty}, + respect tab/.default=true, + % + respect percent/.is choice, + respect percent/true/.code={% + \gdef\csv@catcode@percent@set{% + \xdef\csv@catcode@percent@value{\the\catcode`\%}% + \catcode`\%=12}% + \gdef\csv@catcode@percent@reset{\catcode`\%=\csv@catcode@percent@value}}, + respect percent/false/.code={% + \global\let\csv@catcode@percent@set\csv@empty% + \global\let\csv@catcode@percent@reset\csv@empty}, + respect percent/.default=true, + % + respect sharp/.is choice, + respect sharp/true/.code={% + \gdef\csv@catcode@sharp@set{% + \xdef\csv@catcode@sharp@value{\the\catcode`\#}% + \catcode`\#=12}% + \gdef\csv@catcode@sharp@reset{\catcode`\#=\csv@catcode@sharp@value}}, + respect sharp/false/.code={% + \global\let\csv@catcode@sharp@set\csv@empty% + \global\let\csv@catcode@sharp@reset\csv@empty}, + respect sharp/.default=true, + % + respect dollar/.is choice, + respect dollar/true/.code={% + \gdef\csv@catcode@dollar@set{% + \xdef\csv@catcode@dollar@value{\the\catcode`\$}% + \catcode`\$=12}% + \gdef\csv@catcode@dollar@reset{\catcode`\$=\csv@catcode@dollar@value}}, + respect dollar/false/.code={% + \global\let\csv@catcode@dollar@set\csv@empty% + \global\let\csv@catcode@dollar@reset\csv@empty}, + respect dollar/.default=true, + % + respect and/.is choice, + respect and/true/.code={% + \gdef\csv@catcode@and@set{% + \xdef\csv@catcode@and@value{\the\catcode`\&}% + \catcode`\&=12}% + \gdef\csv@catcode@and@reset{\catcode`\&=\csv@catcode@and@value}}, + respect and/false/.code={% + \global\let\csv@catcode@and@set\csv@empty% + \global\let\csv@catcode@and@reset\csv@empty}, + respect and/.default=true, + % + respect backslash/.is choice, + respect backslash/true/.code={% + \gdef\csv@catcode@backslash@set{% + \xdef\csv@catcode@backslash@value{\the\catcode`\\}% + \catcode`\\=12}% + \gdef\csv@catcode@backslash@reset{\catcode`\\=\csv@catcode@backslash@value}}, + respect backslash/false/.code={% + \global\let\csv@catcode@backslash@set\csv@empty% + \global\let\csv@catcode@backslash@reset\csv@empty}, + respect backslash/.default=true, + % + respect underscore/.is choice, + respect underscore/true/.code={% + \gdef\csv@catcode@underscore@set{% + \xdef\csv@catcode@underscore@value{\the\catcode`\_}% + \catcode`\_=12}% + \gdef\csv@catcode@underscore@reset{\catcode`\_=\csv@catcode@underscore@value}}, + respect underscore/false/.code={% + \global\let\csv@catcode@underscore@set\csv@empty% + \global\let\csv@catcode@underscore@reset\csv@empty}, + respect underscore/.default=true, + % + respect tilde/.is choice, + respect tilde/true/.code={% + \gdef\csv@catcode@tilde@set{% + \xdef\csv@catcode@tilde@value{\the\catcode`\~}% + \catcode`\~=12}% + \gdef\csv@catcode@tilde@reset{\catcode`\~=\csv@catcode@tilde@value}}, + respect tilde/false/.code={% + \global\let\csv@catcode@tilde@set\csv@empty% + \global\let\csv@catcode@tilde@reset\csv@empty}, + respect tilde/.default=true, + % + respect circumflex/.is choice, + respect circumflex/true/.code={% + \gdef\csv@catcode@circumflex@set{% + \xdef\csv@catcode@circumflex@value{\the\catcode`\^}% + \catcode`\^=12}% + \gdef\csv@catcode@circumflex@reset{\catcode`\^=\csv@catcode@circumflex@value}}, + respect circumflex/false/.code={% + \global\let\csv@catcode@circumflex@set\csv@empty% + \global\let\csv@catcode@circumflex@reset\csv@empty}, + respect circumflex/.default=true, + % + respect leftbrace/.is choice, + respect leftbrace/true/.code={% + \gdef\csv@catcode@leftbrace@set{% + \xdef\csv@catcode@leftbrace@value{\the\catcode`\{}% + \catcode`\{=12}% + \gdef\csv@catcode@leftbrace@reset{\catcode`\{=\csv@catcode@leftbrace@value}}, + respect leftbrace/false/.code={% + \global\let\csv@catcode@leftbrace@set\csv@empty% + \global\let\csv@catcode@leftbrace@reset\csv@empty}, + respect leftbrace/.default=true, + % + respect rightbrace/.is choice, + respect rightbrace/true/.code={% + \gdef\csv@catcode@rightbrace@set{% + \xdef\csv@catcode@rightbrace@value{\the\catcode`\}}% + \catcode`\}=12}% + \gdef\csv@catcode@rightbrace@reset{\catcode`\}=\csv@catcode@rightbrace@value}}, + respect rightbrace/false/.code={% + \global\let\csv@catcode@rightbrace@set\csv@empty% + \global\let\csv@catcode@rightbrace@reset\csv@empty}, + respect rightbrace/.default=true, + % + respect all/.style={respect tab,respect percent,respect sharp,respect dollar, + respect and,respect backslash,respect underscore,respect tilde,respect circumflex, + respect leftbrace,respect rightbrace}, + respect none/.style={respect tab=false,respect percent=false,respect sharp=false, + respect dollar=false,respect and=false,respect backslash=false, + respect underscore=false,respect tilde=false,respect circumflex=false, + respect leftbrace=false,respect rightbrace=false}, + respect none +} + \long\def\csv@autotabular[#1]#2{\csvloop{autotabular={#2},#1}} @@ -471,6 +685,18 @@ \def\csvautolongtable{% \@ifnextchar[{\csv@autolongtable}{\csv@autolongtable[]}} +\long\def\csv@autobooktabular[#1]#2{\csvloop{autobooktabular={#2},#1}} + +\def\csvautobooktabular{% + \@ifnextchar[{\csv@autobooktabular}{\csv@autobooktabular[]}} + + +\long\def\csv@autobooklongtable[#1]#2{\csvloop{autobooklongtable={#2},#1}} + +\def\csvautobooklongtable{% + \@ifnextchar[{\csv@autobooklongtable}{\csv@autobooklongtable[]}} + + \def\csvstyle#1#2{\csvset{#1/.style={#2}}} \def\csvnames#1#2{\csvset{#1/.style={column names={#2}}}} -- cgit v1.2.3