Skip to content

Commit

Permalink
token file added, quiet mode added
Browse files Browse the repository at this point in the history
  • Loading branch information
T-F-S committed Jul 14, 2014
1 parent a47c411 commit 65e6a7b
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 35 deletions.
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Fri Jul 11 16:28:53 CEST 2014
build.number=56
#Mon Jul 14 09:38:37 CEST 2014
build.number=59
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
CSV-Sorter ANT build
</description>

<property name="version.number" value="0.93 beta"/>
<property name="version.date" value="2014/07/11"/>
<property name="version.number" value="0.94 beta"/>
<property name="version.date" value="2014/07/14"/>

<property name="root" location="."/>
<property name="src" location="${root}/src"/>
Expand Down
67 changes: 58 additions & 9 deletions doc/csvsorter.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% \LaTeX-Main\
%% The csvsorter program - version 0.93 beta (2014/07/11)
%% The csvsorter program - version 0.94 beta (2014/07/14)
%% csvsorter.tex: Manual
%%
%% Copyright (c) 2014, Prof. Dr. Dr. Thomas F. Sturm
Expand Down Expand Up @@ -44,6 +44,7 @@
\usepackage{varioref}
\usepackage[pdftex,bookmarks,raiselinks,pageanchor,hyperindex,colorlinks]{hyperref}
\usepackage{varwidth,cleveref,incgraph}
\usepackage{array,booktabs,csvsimple}

\usepackage[a4paper,left=2.5cm,right=2.5cm,top=1.5cm,bottom=1.5cm,
marginparsep=5mm,marginparwidth=10mm,
Expand All @@ -70,15 +71,16 @@
\usepackage[many,listings,minted]{tcolorbox}
\usetikzlibrary{arrows.meta}

\def\version{0.93 beta}%
\def\datum{2014/07/11}%
\def\version{0.94 beta}%
\def\datum{2014/07/14}%
\def\docdatum{\datum}

\hypersetup{
pdftitle={Manual for the csvsorter program},
pdfauthor={Thomas F. Sturm},
}


\tcbset{mysource/.style={
enhanced,colback=yellow!10!white,colframe=red!50!black,
coltitle=red!30!black,colbacktitle=red!50!yellow!20!white,
Expand Down Expand Up @@ -425,6 +427,17 @@ \section{Usage}
The CSV file to process and to write after processing (overwriting).
\end{optionbox}

\begin{optionbox}{t}{token file}
If the processing was successful, this file is written with content |\relax|.
If there was no success, nothing happens.
This file is used as token for interaction with the |csvsimple| \LaTeX package.
\end{optionbox}

\begin{optionbox}{q}{number}
If the number is zero, terminal messages are printed. Otherwise,
\csvsorter\ keeps quiet on the terminal, if no errors occur.
\end{optionbox}

\begin{itemize}
\item The presence of a configuration file is mandatory.
\item Note that the configuration file may contain the rest of the options.
Expand All @@ -443,7 +456,7 @@ \subsection{Example 1}

Processing:

\immediate\write18{csvsorter -c titlesort.xml -i songcontest.csv -o songcontest_sorted.csv}%
\immediate\write18{csvsorter -c titlesort.xml -i songcontest.csv -o songcontest_sorted.csv -l csvsorter.csvlog}%
\command*{csvsorter -c titlesort.xml -i songcontest.csv -o songcontest_sorted.csv}

Output file:
Expand All @@ -466,7 +479,7 @@ \subsection{Example 2}

Processing:

\immediate\write18{csvsorter -c televotesort.xml -i songcontest.csv -o songcontest_sorted.csv}%
\immediate\write18{csvsorter -c televotesort.xml -i songcontest.csv -o songcontest_sorted.csv -l csvsorter.csvlog}%
\command*{csvsorter -c televotesort.xml -i songcontest.csv -o songcontest_sorted.csv}

Output file:
Expand All @@ -491,7 +504,7 @@ \subsection{Example 3}

Processing:

\immediate\write18{csvsorter -c sumsort.xml -i songcontest.csv -o songcontest_sorted.csv}%
\immediate\write18{csvsorter -c sumsort.xml -i songcontest.csv -o songcontest_sorted.csv -l csvsorter.csvlog}%
\command*{csvsorter -c sumsort.xml -i songcontest.csv -o songcontest_sorted.csv}

Output file:
Expand Down Expand Up @@ -519,14 +532,44 @@ \subsection{Example 4}

Processing:

\immediate\write18{csvsorter -c filtersort.xml -i songcontest.csv -o songcontest_sorted.csv}%
\immediate\write18{csvsorter -c filtersort.xml -i songcontest.csv -o songcontest_sorted.csv -l csvsorter.csvlog}%

\command*{csvsorter -c filtersort.xml -i songcontest.csv -o songcontest_sorted.csv}

Output file:

\inputCSV[title={\detokenize{songcontest_sorted.csv}}]{songcontest_sorted.csv}

\clearpage

The example is continued with a demonstration of on-the-fly sort in
\LaTeX\ documents using
the |csvsimple|\footnote{\url{www.ctan.org/tex-archive/macros/latex/contrib/csvsimple}}
package.

Instead of sorting the |songcontest.csv| example beforehand, it can be
sorted on-the-fly while compiling a \LaTeX\ document:

\csvset{csvsorter log=csvsorter.csvlog}
\begin{tcblisting}{mycsv,title={\LaTeX\ example},listing and text,
minted language=latex,bicolor,colbacklower=white,fontlower=\small}
% \documentclass{article}
% \usepackage{array,booktabs,csvsimple}
% \begin{document}

\csvreader[sort by=sumsort.xml,
head to column names,
tabular=lllcc,
table head=\toprule\textbf{Artist} & \textbf{Title} & \textbf{Country} &
\textbf{Points} & \textbf{TV+JV}\\\midrule,
table foot=\bottomrule]
{songcontest.csv}{}
{\Artist & \itshape''\Title'' & \Country &
\bfseries\the\numexpr\Televote+\Juryvote\relax & $(\Televote+\Juryvote)$}

% \end{document}
\end{tcblisting}



\clearpage
Expand All @@ -541,7 +584,7 @@ \subsection{Example 5}

Processing:

\immediate\write18{csvsorter -c format.xml -i gradetab.csv -o gradetab_sorted.csv}%
\immediate\write18{csvsorter -c format.xml -i gradetab.csv -o gradetab_sorted.csv -l csvsorter.csvlog}%

\command*{csvsorter -c format.xml -i gradetab.csv -o gradetab_sorted.csv}

Expand Down Expand Up @@ -898,7 +941,13 @@ \section{Version History}
%\versionbox[before=\par]{Version \version\ (\datum)}
\versionbox[before=\par]{Version 0.93 beta (2014/07/11)}
\versionbox[before=\par]{Version 0.94 beta (2014/07/14)}
\begin{changelist}
\item[new] Token file for interaction with |csvsimple| with new command-line option 't'.
\item[new] New command-line option 'q' to set quiet state.
\end{changelist}
\versionbox{Version 0.93 beta (2014/07/11)}
\begin{changelist}
\item[new] Windows native executable wrapping the Jar-archive added.
\item[new] More log messages added.
Expand Down
4 changes: 2 additions & 2 deletions doc/songcontest.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Title,Artist,Country,Televote,Juryvote
The green hills of the shire,Frodo and Friends,New Zealand,76,45
La la la la la,The Singers,United Kingdom,25,62
One and two and three,Hansi Unterober,Germany,47,35
Rarara,Channel Rats,Grand Fenwick,12,14
The green hills of the shire,Frodo and Friends,New Zealand,76,45
Paris e Calais,Chantal and Pascal,France,47,41
The bell rings,Baab,Sweden,87,24
Rarara,Channel Rats,Grand Fenwick,12,14
83 changes: 66 additions & 17 deletions src/tfs/csvsorter/CSVSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class CSVSorter

static
{
VERSION = "0.93 beta";
DATE = "2014/07/11";
BUILD = 55;
VERSION = "0.94 beta";
DATE = "2014/07/14";
BUILD = 58;
PROGNAME = "CSV-Sorter";
}

Expand All @@ -42,11 +42,16 @@ public static String getFullVersion()
return PROGNAME + " " + VERSION + " b" + String.valueOf(BUILD) + " (" + DATE + ")";
}

public static String getCopyright()
{
return "Copyright (c) 2014, Prof. Dr. Dr. Thomas F. Sturm";
}

private enum OPTCODE { c, l, i, o, x };
private enum OPTCODE { c, l, i, o, x, t, q };

private static long startTime;
private static String startDate;
private static int quiet=0;


public CSVSorter(String configFileName, Map<OPTCODE,String> cmdmap) throws Exception
Expand Down Expand Up @@ -83,12 +88,20 @@ public CSVSorter(String configFileName, Map<OPTCODE,String> cmdmap) throws Excep
{
log.close();
}

if (configuration.getTokenFile()!=null)
{
PrintWriter token = new PrintWriter(new FileOutputStream(configuration.getTokenFile()),true);
token.println("\\relax");
token.close();
}
}


private void printLogHeader(PrintWriter log)
{
log.println(getFullVersion());
log.println(getCopyright());
log.println("Start time: "+startDate);
}

Expand Down Expand Up @@ -126,6 +139,10 @@ private void finalizeConfiguration(Configuration configuration, Map<OPTCODE,Stri
configuration.setAllowOverwrite(true);
break;
}
case t:
{
configuration.setTokenFile(value);
}
default:
}
}
Expand Down Expand Up @@ -345,6 +362,13 @@ private PrintWriter createOutputWriter(Configuration configuration, PrintWriter
}


public static void printWelcome()
{
System.out.println("This is "+getFullVersion());
System.out.println(getCopyright());
System.out.println("");
}


public static void printUsageAndExit()
{
Expand All @@ -357,6 +381,8 @@ public static void printUsageAndExit()
System.out.println(" -i input csv file");
System.out.println(" -o output csv file");
System.out.println(" -x input=output csv file");
System.out.println(" -t token file");
System.out.println(" -q number");
System.out.println("");
System.out.println("Example (all platforms):");
System.out.println("java -jar csvsorter.jar -c myconf.xml -i example.csv -o examplesorted.csv");
Expand All @@ -368,6 +394,14 @@ public static void printUsageAndExit()
System.out.println(" Command line options override configuration file settings.");
System.exit(1);
}


public static void printEarlyErrorAndExit(String message)
{
printWelcome();
System.out.println(message);
printUsageAndExit();
}



Expand All @@ -389,21 +423,18 @@ public static Map<OPTCODE,String> scanConfiguration(String s[])
}
catch (Exception ex)
{
System.out.println(opt+" invalid: "+ex.toString());
printUsageAndExit();
printEarlyErrorAndExit(opt+" invalid: "+ex.toString());
}
}
else
{
System.out.println(opt+" invalid");
printUsageAndExit();
printEarlyErrorAndExit(opt+" invalid");
}
i++;
}
if (i<s.length)
{
System.out.println(s[i]+" invalid: no value given");
printUsageAndExit();
printEarlyErrorAndExit(s[i]+" invalid: no value given");
}
return cmdmap;
}
Expand All @@ -414,33 +445,51 @@ public static void main(String s[])
{
startTime = System.nanoTime();
Date date = new Date();
/*
System.out.println("This is "+getFullVersion());
System.out.println(getCopyright());
System.out.println("");
*/
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
startDate = sdf.format(date);

Map<OPTCODE,String> cmdmap = scanConfiguration(s);
for (OPTCODE key : cmdmap.keySet())
{
System.out.println(key.toString()+": "+cmdmap.get(key));
}
String configFileName = cmdmap.get(OPTCODE.c);
if (configFileName==null)
{
System.out.println("Configuration file is missing.");
printUsageAndExit();
printEarlyErrorAndExit("Configuration file is missing.");
}
cmdmap.remove(OPTCODE.c);

try
{
quiet = Integer.parseInt(cmdmap.get(OPTCODE.q));
}
catch (Exception ex) {};
cmdmap.remove(OPTCODE.q);

if (quiet==0)
{
printWelcome();
}
try
{
new CSVSorter(configFileName, cmdmap);
}
catch (Exception e)
{
if (quiet!=0)
{
printWelcome();
}
System.out.println("Error: " + e.toString());
System.out.println("CSV-Sorter finished with errors.");
System.exit(1);
}
System.out.println("CSV-Sorter finished.");
if (quiet==0)
{
System.out.println("CSV-Sorter finished gracefully.");
}
}


Expand Down
Loading

0 comments on commit 65e6a7b

Please sign in to comment.