csv2latex_0.18.1.orig/0000775000175000017500000000000012330012547012626 5ustar benbencsv2latex_0.18.1.orig/CHANGES0000664000175000017500000000365212330011645013625 0ustar benben2014-04-29 (0.18.1) * cleanup, minor update (README) 2010-04-17 (0.18) * workaround when double-quotes are only on some cells (Google Docs) thanks to Florian Heinze 2010-02-06 (0.17) * added --repeatheder, --nohlines, --novlines thanks to Mathew Polzin * updated manpage 2009-09-18 (0.16) * generated manpage added into source (docbook-to-man not needed) 2009-08-28 (0.16) * use unisgned when needed (MAXUINT = 4G on 32bits systems) 2009-07-24 * fixed empty tabular bug when number of CSV rows matches --lines * added \newline between tabulars 2009-07-15 (0.15) * added use of longtable package 2009-04-16 (0.14) * replace "$\backslash$" by "\textbackslash" 2009-04-16 (0.14) * --noescape option added. * gzip --force in Makefile. * will release soon. 2009-04-13 (0.14) * now escape '\' as "$\backslash$". not released yet. 2009-03-11 (0.13) * max lines per table now architecture dependant 2009-01-29 (0.12-3) * now, --lines 0 means no limit per output table (actually 2 Giga lines) 2009-01-24 (0.12-2) * manpage added (sgml) 2009-01-24 (0.12-1) * minor bugfix (getMaximums) in case of unexpected EOF * --version looks nicer 2009-01-23 (0.12) * added --reduce option, based on the idea from Boaz (need {relsize}) 2009-01-22 (0.11) * bugfix a bad behaviour when getting a separator inside a block * rewritten some parsing code 2008-11-11 (0.10-1) * Added co(l)on as --delimiter. Modified Usage message. Better --guess 2007-11-29 (0.9-3) * added s(p)ace as --delimiter. * added --colorrows option 2007-04-17 (0.9-2) * added bad filename detection after bug reported by James R. Phillips 2006-03-04 (0.9-1) * added "--separator t" option by Owen Solberg 2005-11-22 (0.8-1) * Initial release as unofficial debian package 2002- * source released as csv2latex.c * various fixes and options added csv2latex_0.18.1.orig/csv2latex.10000664000175000017500000001565012325041155014633 0ustar benben.TH "CSV2LATEX" "1" .SH "NAME" csv2latex \(em convert a csv file into a LaTeX document .SH "SYNOPSIS" .PP \fBcsv2latex\fR [\fB\-\-nohead\fP] [\fB\-\-longtable\fP] [\fB\-\-noescape\fP] [\fB\-\-guess\fP] [\fB\-\-separator \fIc\fR|\fIs\fR|\fIt\fR|\fIp\fR|\fIl\fR\fP] [\fB\-\-block \fIq\fR|\fId\fR|\fIn\fR\fP] [\fB\-\-lines \fI#\fR\fP] [\fB\-\-position \fIl\fR|\fIc\fR|\fIr\fR\fP] [\fB\-\-colorrows \fI0-1\fR\fP] [\fB\-\-reduce \fI1\fR|\fI2\fR|\fI3\fR|\fI4\fR\fP] [\fB\-\-repeatheader\fP] [\fB\-\-nohlines\fP] [\fB\-\-novlines\fP] [file] .SH "DESCRIPTION" .PP This manual page documents the \fBcsv2latex\fR program. .PP \fBcsv2latex\fR is a program that reads a "comma separated values" (csv) file and outputs a LaTeX file with one or more tabular environments to display the printable values of the csv file. The LaTeX code is flushed on the standard output. .PP So-called "comma separated values" files are common formats for exchanging two-dimensinal tables between programs such as spreadsheets editors, to represent almost any kind of data. By default, a csv file is made of printable data separated by commas (`,'), each comma representing a `cell' separator, and each line representing a row. By extension, cell separators can be represented by tabs if the comma is considered as printable data. Moreover, some non true csv files can be assumed as two-dimensional tables as well. In some circumstances, if the printable data includes the cell separator of the exchange format, the latter can use a second extra character to embrace the printable data into a block (e.g: quoted text). Thus, it is still possible to parse the file by using the block delimiter (used twice to embrace the cell) instead of the separator. .PP \fBcsv2latex\fR aims to parse various csv formats plus formats that fits into the above definiton, assuming the data is text, and to produce a yet simple LaTeX file using the "tabular" environment for a table-style layout. Some options of output will also use macros provided by extra LaTeX packages that are commonly included in the main LaTeX distributions. .SH "OPTIONS" .PP This program follows the usual GNU command line syntax, with long options starting with two dashes (`\-'). A summary of options is included below. .IP "\fB-h\fP \fB\-\-help\fP " 10 Show summary of options. .IP "\fB-v\fP \fB\-\-version\fP " 10 Show version of program. .IP "\fB-n\fP \fB\-\-nohead\fP " 10 Do not output the LaTeX document header. This is useful when the output is to be included as a separate file into the master document. .IP "\fB-t\fP \fB\-\-longtable\fP " 10 uses the 'longtable' package instead of the 'tabular' one. This is useful when the input is long, with \fB\-\-lines 0\fP option. This option uses the extra `longtable' LaTeX package. If you also use \fB\-\-nohead\fP option, do not forget to add the following line into the header of your master document: "\\usepackage{longtable}". .IP "\fB-x\fP \fB\-\-noescape\fP " 10 Do not escape TeX control characters from the input. This is useful when the input contains already TeX code. .IP "\fB-g\fP \fB\-\-guess\fP " 10 Try to guess the csv format. This is useful when the input is not strictly a comma separated set of printable data. For example, a line like %Foo, Bar%:%Wizz: Hey% may be parsed as "Foo, Bar" then "Wizz: Hey". .IP "\fB-s \fIc\fR|\fIs\fR|\fIt\fR|\fIp\fR|\fIl\fR\fP \fB\-\-separator \fIc\fR|\fIs\fR|\fIt\fR|\fIp\fR|\fIl\fR\fP " 10 Set the given separator as cell separator of the csv format. `c' means a comma (default). `s' means a semicolon. `t' means a tab. `p' means a space. `l' means a colon. .IP "\fB-b \fIq\fR|\fId\fR|\fIn\fR\fP \fB\-\-block \fIq\fR|\fId\fR|\fIn\fR\fP " 10 Set the given block delimiter that embraces the printable data of the csv format. `q' means a simple quote. `d' means a double quote. `n' means no quoting at all (default). .IP "\fB-l \fI#\fR\fP \fB\-\-lines \fI#\fR\fP " 10 Force to output multiple tabulars, each having a limited number of lines. The given argument must be a POSITIVE INTEGER VALUE. This is useful when the number of input rows is too big to fit into a single papersheet. A good average for a4 paper is about 40 lines (default). 0 means infinity (actualy about 2 Giga lines). .IP "\fB-p \fIl\fR|\fIc\fR|\fIr\fR\fP \fB\-\-position \fIl\fR|\fIc\fR|\fIr\fR\fP " 10 Set the text position in all cells at once. This simply uses one of the three basic cell formating options of the LaTeX tabular environment. `l' means left-aligned (default). `c' means centered. `r' means right-aligned. .IP "\fB-c \fI0-1\fR\fP \fB\-\-colorrows \fI0-1\fR\fP " 10 Alternate white/gray rows on the LaTeX output, having the given graylevel. The given argument must be a REAL NUMBER BETWEEN 0 AND 1. 0 means black while 1 means white. A nice looking value is 0.75 when printed on white paper. This option uses the extra `colortbl' LaTeX package. If you also use \fB\-\-nohead\fP option, do not forget to add the following line into the header of your master document: "\\usepackage{colortbl}". .IP "\fB-r \fI1\fR|\fI2\fR|\fI3\fR|\fI4\fR\fP \fB\-\-reduce \fI1\fR|\fI2\fR|\fI3\fR|\fI4\fR\fP " 10 Reduce the size of the tabular and the font in the LaTeX output, given a reduction level. The given argument must be one of 1, 2, 3 or 4. The more the level is high, the more the tabular will appear small. This is useful to shrink the table width when the printable data is made of very long text. This option uses the extra `relsize' LaTeX package. If you also use \fB\-\-nohead\fP option, do not forget to add the following line into the header of your master document: "\\usepackage{relsize}". .IP "\fB-z\fP \fB\-\-nohlines\fP " 10 Do not output horizontal lines in the table(s). .IP "\fB-y\fP \fB\-\-novlines\fP " 10 Do not output vertical lines in the table(s). .IP "\fB-e\fP \fB\-\-repeatheader\fP " 10 Repeat the first row of the first table in every table. This is useful when the output is very long and separated in multiple tables. .SH "EXAMPLES" .PP Create a PDF document with small text, alternate gray rows, 80 lines per table, from a guessed csv format of the january stats that my boss created with his super point-and-click spreadsheet program (which could not generate a PDF output!). .PP \fBcsv2latex \-\-guess \-\-lines 80 \-\-colorrows 0.75 \-\-reduce 2 january_stats.csv > january_stats.tex && pdflatex january_stats.tex\fR .PP Quickly preview a phonebook from a file formated as "Surname" "Name" "Phone" "Cellular": .PP \fBcsv2latex \-s p \-b d \-l 42 phonebook-sorted.txt | latex\fR .SH "SEE ALSO" .PP tex (1), latex (1). .\" created by instant / docbook-to-man, Sat 06 Feb 2010, 20:20 csv2latex_0.18.1.orig/README0000664000175000017500000000127312325041155013512 0ustar benben csv2latex: a CSV to LaTeX file converter. author: Benoît Rouits thanks: Valéry Febvre Jason J. Corso Boaz Gezer Rafael Laboissiere Cristof Bodner Mathew Polzin Florian Heinze homepage: http://herewe.servebeer.com/csv2latex/ download: http://herewe.servebeer.com/csv2latex/releases/ checkout: http://herewe.servebeer.com/svn//csv2latex browse: http://herewe.servebeer.com/svn/csv2latex copyright: © 2003- Benoît Rouits published under license: GNU GPL version 2 (see COPYING file) csv2latex_0.18.1.orig/Makefile0000664000175000017500000000105612325041155014271 0ustar benbenPROGNAME=csv2latex PREFIX=/usr BINDIR=$(PREFIX)/bin MANDIR=$(PREFIX)/share/man/man1 CFLAGS=-Wall -Wextra -pedantic -Os GZIP=gzip --to-stdout all: ${CC} $(CFLAGS) $(PROGNAME).c -o $(PROGNAME) $(GZIP) $(PROGNAME).1 > $(PROGNAME).1.gz install: strip $(PROGNAME) install $(PROGNAME) ${DESTDIR}$(BINDIR)/$(PROGNAME) install $(PROGNAME).1.gz ${DESTDIR}$(MANDIR)/$(PROGNAME).1.gz uninstall: $(RM) ${DESTDIR}$(BINDIR)/$(PROGNAME) $(RM) ${DESTDIR}$(MANDIR)/$(PROGNAME).1.gz clean: $(RM) $(PROGNAME) $(RM) $(PROGNAME).1.gz # vim:set ts=8 sw=8 noexpandtab et: csv2latex_0.18.1.orig/csv2latex.c0000664000175000017500000004161112325041155014711 0ustar benben/* * csv2latex.c, copyright © 2002- Benoît Rouits * ********************************************************* * csv2latex translates a .csv file to a LaTex document. * ********************************************************* * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; version 2 only * of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * see the COPYING file included in the csv2latex package or * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt * */ #include #include #include #include #include #include #include #include "version.h" typedef struct { char* tab; /* actual escapes */ int size; /* escape tab len */ } texcape; typedef struct { char block; /* CSV delimitor if any */ char sep; /* CSV separator */ unsigned int cols; /* CSV columns */ unsigned int chars; /* CSV max data length */ unsigned int rows; /* CSV total number of lines */ char pos; /* position in cell (align) */ unsigned int lines; /* rows per LaTeX tabular */ unsigned int guess; /* guess or not the CSV format */ unsigned int header; /* put LaTeX document header or not */ unsigned int red; /* table reduction level (from 1 to 4)*/ unsigned int longtable; /* use package longtable */ unsigned int escape; /* escape TeX control chars or not */ unsigned int repeat; /* repeat table headers for each LaTeX table section or not */ unsigned int vlines; /* insert vertical lines between columns or not */ unsigned int hlines; /* insert horizontal lines between rows or not */ char* clrrow; /* row graylevel (from 0 to 1) */ texcape* tex; /* TeX escapes */ } config; #define MAXUINT ((unsigned int)(-1)) void rtfm(char* prog) { printf("%s translates a csv file to a LaTeX file\n", basename(prog)); printf("Example: %s january_stats.csv > january_stats.tex\n", basename(prog)); printf("Usage: %s [--nohead] (LaTeX) no document header: useful for inclusion\n", basename(prog)); printf(" [--longtable] (LaTeX) use package longtable: useful for long input\n"); printf(" [--noescape] (LaTeX) do not escape text: useful for mixed CSV/TeX input\n"); printf(" [--guess] (CSV) guess separator and block |\n" " [--separator <(c)omma|(s)emicolon|(t)ab|s(p)ace|co(l)on>] (CSV's comma)\n" " [--block <(q)uote|(d)ouble|(n)one>] (CSV) block delimiter (e.g: none)\n"); printf(" [--lines n] (LaTeX) rows per table: useful for long tabulars\n"); printf(" [--position ] (LaTeX) text align in cells\n"); printf(" [--colorrows graylevel] (LaTeX) alternate gray rows (e.g: 0.75)\n"); printf(" [--reduce level] (LaTeX) reduce table size (e.g: 1)\n"); printf(" [--repeatheader] (LaTeX) repeat table header (for long tables)\n"); printf(" [--nohlines] (LaTeX) don't put hline between table rows\n"); printf(" [--novlines] (LaTeX) don't put vline between columns\n"); printf(" csv_file.csv\n"); printf("The \"longtable\" option needs the {longtable} LaTeX package\n"); printf("The \"colorrows\" option needs the {colortbl} LaTeX package\n"); printf("The \"reduce\" option needs the {relsize} LaTeX package\n"); return; } config* parseOptions (config* conf, int argc, char **argv) { /* thx to */ int opt; int tmp; #if defined USE_GETOPT #else int longopt_index = 0; static struct option long_options[] = { {"help", 0, NULL, 'h'}, {"guess", 0, NULL, 'g'}, {"block", 1, NULL, 'b'}, {"lines", 1, NULL, 'l'}, {"noescape", 0, NULL, 'x'}, {"nohead", 0, NULL, 'n'}, {"version", 0, NULL, 'v'}, {"position", 1, NULL, 'p'}, {"separator", 1, NULL, 's'}, {"colorrows", 1, NULL, 'c'}, {"reduce", 1, NULL, 'r'}, {"longtable", 0, NULL, 't'}, {"repeatheader",0, NULL, 'e'}, {"novlines", 0, NULL, 'y'}, {"nohlines", 0, NULL, 'z'}, {NULL, 0, NULL, 0} /* marks end-of-list */ }; #endif #if defined USE_GETOPT while ((opt = getopt (argc, argv, "hvgnxteyz?b:l:p:s:c:r:")) != EOF) { #else while ((opt = getopt_long (argc, argv, "hvgnxteyz?b:l:p:s:c:r:", long_options, &longopt_index)) > 0) { #endif switch (opt) { case '?': case 'h': rtfm (argv[0]); exit (EXIT_SUCCESS); break; case 'g': /* guess the CSV */ conf->guess=1; break; case 't': /* use package longtable */ /* thx to */ conf->longtable=1; break; case 'b': /* csv block delimiter */ if(optarg[0] == 'q') conf->block = '\''; else if(optarg[0] == 'd') conf->block = '"'; else if(optarg[0] == 'n') conf->block = 0; /* no block delimiter */ break; case 'l': /* number of lines per TeX tabulars */ if(isdigit(optarg[0])) { conf->lines=atoi(optarg); } else { fprintf(stderr, "option \"lines\" need a positive integer value\n"); exit(EXIT_FAILURE); } break; case 'n': conf->header=0; break; case 'x': conf->escape=0; break; case 'v': /* version */ printf ("%s © 2002- Benoît Rouits \n" "\tVersion %s (%s)\n", PACKAGE, VERSION, RELEASE_DATE); exit (EXIT_SUCCESS); break; case 'p': /* LaTeX position in cell */ conf->pos=optarg[0]; /* position char in cell */ break; case 's': /* csv block separator */ if(optarg[0] == 'c') conf->sep = ','; else if(optarg[0] == 's') conf->sep = ';'; else if(optarg[0] == 't') conf->sep = '\t'; else if(optarg[0] == 'p') conf->sep = ' '; else if(optarg[0] == 'l') conf->sep = ':'; break; case 'c': /* color rows (thx to ) */ if(isdigit(optarg[0])) { conf->clrrow = (char*)malloc(strlen(optarg)+1); strcpy(conf->clrrow,optarg); } else { fprintf(stderr, "option \"colorrows\" needs a real value between 0 and 1\n"); exit(EXIT_FAILURE); } break; case 'r': /* reduce table size (original idea thx to ) */ if(isdigit(optarg[0])) { tmp = atoi(optarg); conf->red=(tmp>4)?4:(tmp<0)?0:tmp; /* [1-4] */ } else { fprintf(stderr, "option \"reduce\" needs an integer value between 1 and 4\n"); exit(EXIT_FAILURE); } break; case 'e': /*repeat table header for each table section*/ conf->repeat=1; break; case 'y': /*don't draw vlines between columns*/ conf->vlines=0; break; case 'z': /*don't draw hlines between rows*/ conf->hlines=0; break; } } return conf; } int guessCSV(config* conf, FILE* in) { /* guess the block delimiter and the csv separator */ int token; token=getc(in); /* first char is block delimiter */ if(token == EOF) { fprintf(stderr,"ERROR: emtpy file ?\n"); return(-1); } else if (ispunct(token) || token == ' ') { /* found first block delimiter, act this way */ conf->block=token; fprintf(stderr,"Guessed '%c' as Block Delimiter\n", conf->block); /* stream file while token is printable data */ while((token=getc(in)) != conf->block && token != '\n' && token != EOF) {/* getc has been done */} if(token == conf->block){ /* second delimiter : next is separator */ conf->sep=getc(in); fprintf(stderr,"Guessed '%c' as Separator\n", conf->sep); return(0); }else{ return (-1); /* what else ? */ } }else{ /* no block delimiter, act this way */ conf->block=0; fprintf(stderr,"Guessed No Block Delimiter\n"); /* stream file while input is not a control char */ while(isalnum((token=getc(in))) && token != '\n' && token != EOF) {/* getc has been done */} /* guess CSV separator */ if(ispunct(token) || token == '\t' || token == ' '){ conf->sep=token; fprintf(stderr,"Guessed %c as Separator\n", conf->sep); return(0); } else { /* did not found any separator */ fprintf(stderr,"ERROR: Did not guess any Separator!\n"); return(-1); } } return(0); } void getMaximums(config* conf, FILE* in) { /* gets the number of cols and chars of a csv file assuming a separator */ int token=0; unsigned int curcol=0; unsigned int curchar=0; unsigned int inblock=0; /* init */ conf->chars=0; conf->cols=0; conf->rows=0; while (token != EOF) { token=getc(in); /* EOF ? */ if (token == EOF) { continue; } /* decide the maximums */ if (token == '\n') { curcol++; conf->cols=(conf->colscols; conf->chars=(conf->charschars; conf->rows++; curcol=0; curchar=0; inblock=0; /* reset block state */ continue; } /* enter/quit a block */ if (conf->block && token == conf->block) { inblock=!inblock; continue; } /* count cols in current line */ if (token == conf->sep && ((conf->block && !inblock) || !conf->block)) { curcol++; continue; } /* count chars in current cell */ if (token != conf->block && ((conf->block && inblock) || !conf->block)) { curchar++; continue; } } return; } void doTeXsub(config* conf, char newsep, FILE* in, FILE* out) { /* substitutes CSV sep by LaTeX newsep and some TeX code */ int token=0; int max; int numcols; unsigned int lines; int inblock=0; int csvrows; int firstrow=1; int nosep=0; int token1=0; int token2=0; char headerrow[1000]; headerrow[0]='\0'; max=numcols=conf->cols; csvrows=conf->rows; /* choose infinity when conf->lines is 0 */ lines=(conf->lines)?conf->lines:MAXUINT; while (token!=EOF) { token2=token1; /* second last character, used for detection of quotation marks */ token1=token; /* last character, used for detection of quotation marks */ token=getc(in); /* EOF ? */ if (token == EOF) { continue; } /* new line ? */ if (token == '\n') { inblock = 0; /* close block if any */ /* fill empty cols if any */ while (numcols > 1) { putc(newsep,out); numcols--; } if (!(firstrow && (conf->longtable && conf->repeat))) { fprintf(out,"\\\\\n"); /* TeX new line */ } else { /* first row and repeat and longtable */ fprintf(out, "%s\\\\\n", headerrow); } if(conf->hlines) { fprintf(out,"\\hline\n"); /* TeX draw hline */ } if (firstrow && (conf->longtable && conf->repeat)) { fprintf(out, "%s", "\\endhead\n"); } if(firstrow && conf->repeat) { char tmp[12]; sprintf(tmp,(conf->hlines?"\\\\\n\\hline":"\\\\\n")); strcat(headerrow,tmp); } firstrow=0; numcols=max; /* reset numcols */ lines--; csvrows--; /* put a colored row or not (alternate) */ if (conf->clrrow && (lines % 2)) { fprintf(out,"\\colorrow "); } /* if the LaTeX tabular is full create a new one, except if no more row or this is a long table */ if (!lines && csvrows && !conf->longtable) { fprintf(out,"\\end{tabular}\n"); fprintf(out, "\\newline\n"); fprintf(out,"\\begin{tabular}{"); if(conf->vlines) { putc('|',out); } while(numcols--) { putc(conf->pos, out); if(conf->vlines) { putc('|',out); } } fprintf(out, "}\n"); if(conf->hlines) { fprintf(out, "\\hline\n"); } if(conf->repeat && !conf->longtable) { fprintf(out,"%s",headerrow); putc('\n',out); } numcols=max; lines=(conf->lines)?conf->lines:MAXUINT; } /* else end of CSV data */ continue; } /* if commas in cells */ /* thx to */ if (token == '\"'){ if (nosep==0) nosep=1; else nosep=0; } /* new column ? */ if ((token == conf->sep && ((conf->block && !inblock) || !conf->block)) && nosep == 0) { if (!(firstrow && (conf->longtable && conf->repeat))) putc(newsep,out); numcols--; if(firstrow && conf->repeat) { char tmp[2]; tmp[0]=newsep; tmp[1]='\0'; strcat(headerrow,tmp); } continue; } /* enter/quit a block ? */ if (conf->block && token == conf->block) { inblock=!inblock; continue; } /* data ? */ if ((token != conf->block && ((conf->block && inblock) || !conf->block)) && ((token=='\"' && token1=='\"' && token2=='\"') || token!='\"')) { /* look for special TeX char to escape */ /* FIXME: put all that into a subroutine */ int i=0; if (conf->escape) for (i=0;i < conf->tex->size; i++) { if (token == conf->tex->tab[i]) { switch (token) { case '\\': fprintf(out, "\\textbackslash{}"); if(firstrow && conf->repeat) { char tmp[17]; sprintf(tmp,"\\textbackslash{}"); strcat(headerrow,tmp); } break; default: fprintf(out, "\\%c", token); if(firstrow && conf->repeat) { char tmp[3]; tmp[0]='\\'; tmp[1]=token; tmp[2]='\0'; strcat(headerrow,tmp); } break; } break; /* there was some escaping */ } } /* or print raw char */ if ( (i >= conf->tex->size) || (!conf->escape) ) { if (!(firstrow && (conf->longtable && conf->repeat))) putc(token, out); /* do not print the header twice */ if(firstrow && conf->repeat) { char tmp[2]; tmp[0]=token; tmp[1]='\0'; strcat(headerrow,tmp); } } continue; } /* do nothing if unexpected char: just loop */ } return; } void doTeXdoc(config* conf, FILE* in, FILE* out) { /* prepares the LaTeX tabular layout */ int maxcols; int numcols; char* relsize[5] = {"0", "0.5", "1", "2", "4"}; /* LaTeX relsize good values */ char* tabcolsep[5] = {"0", "0.05", "0.1", "0.2", "0.4"}; /* LaTeX tabcolsep good values */ numcols=maxcols=conf->cols; if(conf->header){ fprintf(out, "\\documentclass[a4paper]{article}\n"); fprintf(out, "\\usepackage[T1]{fontenc}\n"); fprintf(out, "\\usepackage[latin1]{inputenc}\n"); if (conf->red){ fprintf(out,"\\usepackage{relsize}\n"); } if (conf->clrrow){ fprintf(out,"\\usepackage{colortbl}\n"); } if (conf->longtable){ fprintf(out,"\\usepackage{longtable}\n"); } fprintf(out, "\\begin{document}\n"); } if (conf->clrrow){ fprintf(out,"\\def\\colorrow{\\rowcolor[gray]{%s}}\n", conf->clrrow); } if (conf->red){ fprintf(out,"\\relsize{-%s}\n", relsize[conf->red]); fprintf(out,"\\addtolength\\tabcolsep{-%sem}\n", tabcolsep[conf->red]); } if (conf->longtable) { fprintf(out, "\\begin{longtable}{"); if(conf->vlines) putc('|',out); } else { fprintf(out, "\\begin{tabular}{"); if(conf->vlines) putc('|',out); } while(numcols--) { fprintf(out, "%c",conf->pos); /* position in cell */ if(conf->vlines) putc('|',out); } fprintf(out, "}\n"); if(conf->hlines) fprintf(out, "\\hline\n"); doTeXsub(conf, '&', in, out); /* & is LaTeX separator */ if (conf->longtable) { fprintf(out, "\\end{longtable}\n"); } else { fprintf(out, "\\end{tabular}\n"); } if (conf->red){ fprintf(out,"\\addtolength\\tabcolsep{+%sem}\n", tabcolsep[conf->red]); fprintf(out,"\\relsize{+%s}\n", relsize[conf->red]); } if(conf->header){ fprintf(out, "\\end{document}\n"); } return; } int main (int argc, char **argv) { FILE* fp; config* conf; extern int optind, opterr, optopt; if(argc == 1){ rtfm(argv[0]); exit(EXIT_SUCCESS); } conf=(config*)malloc(sizeof(config)); /* defaults (ensure init): */ conf->cols=1; /* CSV: if getMaximums fails */ conf->rows=0; /* CSV: must be 0 */ conf->chars=0; /* CSV: must be 0 */ conf->pos='l'; /* usual; LaTeX */ conf->lines=40; /* usual; LaTeX */ conf->guess=0; /* usual */ conf->sep=','; /* default; csv */ conf->block=0; /* default; csv */ conf->header=1; /* usual; LaTeX */ conf->escape=1; /* usual; LaTeX */ conf->clrrow=NULL; /* default; LaTeX */ conf->red=0; /* default; LaTeX */ conf->longtable=0; /* default; without package longtable */ conf->repeat=0; /* default; do not repeat the header row */ conf->vlines=1; /* default; draw lines between columns */ conf->hlines=1; /* default; draw lines between rows */ /* TeX charaters to escape */ conf->tex=(texcape*)malloc(sizeof(texcape)); conf->tex->tab = "\\_#$%^&{}~"; conf->tex->size = 10; conf=parseOptions(conf, argc, argv); fp=fopen(argv[optind],"r"); if (!fp){ fprintf(stderr,"Can't open file %s\n", argv[optind]); exit(EXIT_FAILURE); } if(conf->guess){ if(guessCSV(conf, fp)){ fprintf(stderr,"Please run again by using -- delimiter (if any) and --separator\n"); exit(EXIT_FAILURE); } rewind(fp); } getMaximums(conf, fp); rewind(fp); doTeXdoc(conf, fp, stdout); free(conf->tex); if (conf->clrrow) free(conf->clrrow); conf->clrrow=NULL; free(conf); fclose(fp); return 0; } csv2latex_0.18.1.orig/csv2latex.sgml0000664000175000017500000003457512325041155015444 0ustar benben BENOIT"> ROUITS"> january 24, 2009"> 1"> brouits@free.fr"> CSV2LATEX"> Ubuntu"> Debian"> GNU"> GPL"> ]>
&dhemail;
&dhfirstname; &dhsurname; 2003 &dhusername; &dhdate;
&dhucpackage; &dhsection; &dhpackage; convert a csv file into a LaTeX document &dhpackage; file DESCRIPTION This manual page documents the &dhpackage; program. &dhpackage; is a program that reads a "comma separated values" (csv) file and outputs a LaTeX file with one or more tabular environments to display the printable values of the csv file. The LaTeX code is flushed on the standard output. So-called "comma separated values" files are common formats for exchanging two-dimensinal tables between programs such as spreadsheets editors, to represent almost any kind of data. By default, a csv file is made of printable data separated by commas (`,'), each comma representing a `cell' separator, and each line representing a row. By extension, cell separators can be represented by tabs if the comma is considered as printable data. Moreover, some non true csv files can be assumed as two-dimensional tables as well. In some circumstances, if the printable data includes the cell separator of the exchange format, the latter can use a second extra character to embrace the printable data into a block (e.g: quoted text). Thus, it is still possible to parse the file by using the block delimiter (used twice to embrace the cell) instead of the separator. &dhpackage aims to parse various csv formats plus formats that fits into the above definiton, assuming the data is text, and to produce a yet simple LaTeX file using the "tabular" environment for a table-style layout. Some options of output will also use macros provided by extra LaTeX packages that are commonly included in the main LaTeX distributions. OPTIONS This program follows the usual &gnu; command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. Show summary of options. Show version of program. Do not output the LaTeX document header. This is useful when the output is to be included as a separate file into the master document. uses the 'longtable' package instead of the 'tabular' one. This is useful when the input is long, with option. This option uses the extra `longtable' LaTeX package. If you also use option, do not forget to add the following line into the header of your master document: "\\usepackage{longtable}". Do not escape TeX control characters from the input. This is useful when the input contains already TeX code. Try to guess the csv format. This is useful when the input is not strictly a comma separated set of printable data. For example, a line like %Foo, Bar%:%Wizz: Hey% may be parsed as "Foo, Bar" then "Wizz: Hey". Set the given separator as cell separator of the csv format. `c' means a comma (default). `s' means a semicolon. `t' means a tab. `p' means a space. `l' means a colon. Set the given block delimiter that embraces the printable data of the csv format. `q' means a simple quote. `d' means a double quote. `n' means no quoting at all (default). Force to output multiple tabulars, each having a limited number of lines. The given argument must be a POSITIVE INTEGER VALUE. This is useful when the number of input rows is too big to fit into a single papersheet. A good average for a4 paper is about 40 lines (default). 0 means infinity (actualy about 2 Giga lines). Set the text position in all cells at once. This simply uses one of the three basic cell formating options of the LaTeX tabular environment. `l' means left-aligned (default). `c' means centered. `r' means right-aligned. Alternate white/gray rows on the LaTeX output, having the given graylevel. The given argument must be a REAL NUMBER BETWEEN 0 AND 1. 0 means black while 1 means white. A nice looking value is 0.75 when printed on white paper. This option uses the extra `colortbl' LaTeX package. If you also use option, do not forget to add the following line into the header of your master document: "\\usepackage{colortbl}". Reduce the size of the tabular and the font in the LaTeX output, given a reduction level. The given argument must be one of 1, 2, 3 or 4. The more the level is high, the more the tabular will appear small. This is useful to shrink the table width when the printable data is made of very long text. This option uses the extra `relsize' LaTeX package. If you also use option, do not forget to add the following line into the header of your master document: "\\usepackage{relsize}". Do not output horizontal lines in the table(s). Do not output vertical lines in the table(s). Repeat the first row of the first table in every table. This is useful when the output is very long and separated in multiple tables. EXAMPLES Create a PDF document with small text, alternate gray rows, 80 lines per table, from a guessed csv format of the january stats that my boss created with his super point-and-click spreadsheet program (which could not generate a PDF output!). &dhpackage; --guess --lines 80 --colorrows 0.75 --reduce 2 january_stats.csv > january_stats.tex && pdflatex january_stats.tex Quickly preview a phonebook from a file formated as "Surname" "Name" "Phone" "Cellular": &dhpackage; -s p -b d -l 42 phonebook-sorted.txt | latex SEE ALSO tex (1), latex (1).
csv2latex_0.18.1.orig/COPYING0000664000175000017500000004310312325041155013663 0ustar benben GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. csv2latex_0.18.1.orig/csv2latex.ebuild0000664000175000017500000000105112325041155015725 0ustar benben# Copyright 1999-2008 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ DESCRIPTION="A csv to LaTeX file converter" HOMEPAGE="http://herewe.servebeer.com/csv2latex/" SRC_URI="${HOMEPAGE}/releases/${P}-0.17.tar.gz" LICENSE="GPL" SLOT="0" KEYWORDS="~x86" IUSE="" src_compile() { emake || die "emake failed" } src_install() { PREFIX="usr/local" mkdir -p ${D}/${PREFIX}/bin mkdir -p ${D}/${PREFIX}/share/man/man1 emake install DESTDIR="${D}" PREFIX=${PREFIX} || die "Install failed" } csv2latex_0.18.1.orig/version.h0000664000175000017500000000013012330011670014452 0ustar benben#define PACKAGE "csv2latex" #define RELEASE_DATE "2014-04-29" #define VERSION "0.18.1" csv2latex_0.18.1.orig/PLAN0000664000175000017500000000121612325041155013304 0ustar benbenfuture feature: --lines -40 (consider `-' as `less than') (not easy, would be default) find N so that (1) (N < 40) and (2) TOTAL%N is either 0 or maximal and (3) N is minimal) (1) because of paper size and readability in general. N is lines-per-tabular (2) do not have a near-to-empty tabular. TOTAl%N is lines-for-the-latest-tabular (3) do not make useless small tabulars. TOTAL/N is the number of tabulars - is this a correct definition ? possible feature: --reduce auto (not easy, would be default) compute --reduce due to linelength and \textwidth. possible feature: --lines auto (would be default) compute --lines due to fontsize and \textheight.