rllib  1
Public Member Functions | Private Attributes | List of all members
rlReport Class Reference

#include <rlreport.h>

Collaboration diagram for rlReport:
Collaboration graph
[legend]

Public Member Functions

 rlReport ()
 
virtual ~rlReport ()
 
int open (const char *filename)
 
int close ()
 
int printf (const char *format,...)
 
int beginDocument ()
 
int endDocument ()
 
int include (const char *filename, rlIniFile *ini=NULL)
 
int includeHeader (const char *documentclass="\ocumentclass[a4paper]{article}", const char *language="\sepackage[english]{babel}", const char *inputenc="\sepackage[utf8]{inputenc}", const char *layout="\etlength{\arindent}{0pt} \etlength{\opmargin}{-50pt} \etlength{\ddsidemargin}{0pt} \etlength{\extwidth}{480pt} \etlength{\extheight}{700pt}")
 
int includeCSV (const char *filename, int use_first_row_as_title=1, const char *legend=NULL, char delimitor='\t')
 
int includeImage (const char *filename, const char *legend=NULL, float scale=1.0f)
 
int spawn (const char *command)
 
int pdflatex (const char *command=NULL)
 

Private Attributes

FILE * fout
 
rlString file
 

Detailed Description

class for generating PDF files with LaTeX
//### typical usage begin  #############################################
int report(PARAM *p)
{
  rlReport r;
  rlString filename;
  filename  = p->file_prefix; // use an individual filename for each client
  filename += ".tex";
  r.open(filename.text());
  r.includeHeader("\\documentclass[a4paper]{article}","\\usepackage[ngerman]{babel}"); // german article on A4 paper
  //// here we may include our own header definitions
  r.beginDocument();
  //// --- begin here we use the methods: printf(), include(), includeCSV(), includeImage(), spawn() --------------
  r.printf("\\section{Teil 1}\n");
  r.printf("Hallo Welt\n");
  r.includeImage("test.jpg","Testbild",0.8f);
  r.includeCSV("test.csv",1,"Test CSV");
  r.printf("\\cppbegin{main.cpp}\n");
  r.include("main.cpp");
  r.printf("\\end{lstlisting}\n");
  r.printf("\\simplecodebegin{Verzeichnis Inhalt}\n");
  r.spawn("ls -al");
  r.printf("\\end{lstlisting}\n");
  //// --- end here we use the methods: printf(), include(), includeCSV(), includeImage(), spawn() ----------------
  r.endDocument();
  r.close();
  r.pdflatex(); // pdflatex -interaction=nonstopmode file.tex
  filename  = p->file_prefix;
  filename += ".pdf";
  pvDownloadFileAs(p,filename.text(), "report.pdf");
  pvClientCommand(p,"pdf","report.pdf"); // open report.pdf on the client using the pdf-viewer
  return 0;
}
//### typical usage end  ###############################################

Definition at line 64 of file rlreport.h.

Constructor & Destructor Documentation

◆ rlReport()

rlReport::rlReport ( )

Definition at line 21 of file rlreport.cpp.

22 {
23  fout = NULL;
24 }
FILE * fout
Definition: rlreport.h:150

◆ ~rlReport()

rlReport::~rlReport ( )
virtual

Definition at line 26 of file rlreport.cpp.

27 {
28  close();
29 }
int close()
Definition: rlreport.cpp:45

Member Function Documentation

◆ beginDocument()

int rlReport::beginDocument ( )
    print "\\begin{document}"  to the output file

Definition at line 67 of file rlreport.cpp.

68 {
69  return printf("\\begin{document}\n");
70 }
int printf(const char *format,...)
Definition: rlreport.cpp:53

◆ close()

int rlReport::close ( )
    close the output file

Definition at line 45 of file rlreport.cpp.

46 {
47  if(fout == NULL) return -1;
48  fclose(fout);
49  fout = NULL;
50  return 0;
51 }
FILE * fout
Definition: rlreport.h:150

◆ endDocument()

int rlReport::endDocument ( )
    print "\\end{document}"  to the output file

Definition at line 72 of file rlreport.cpp.

73 {
74  return printf("\\end{document}\n");
75 }
int printf(const char *format,...)
Definition: rlreport.cpp:53

◆ include()

int rlReport::include ( const char *  filename,
rlIniFile ini = NULL 
)
    Include a file to the output.
    If ini != NULL then the content of ini can be used as text modules as follows:
    Withnin file we use something like \$[SECTION][NAME] to address the text module we want to include.

Definition at line 77 of file rlreport.cpp.

78 {
79  FILE *fin;
80  char line[rl_PRINTF_LENGTH]; // should be big enough
81  char *cptr, *start, *section, *name;
82 
83  if(fout == NULL) return -1;
84  if(filename == NULL) return -1;
85  if(ini == NULL)
86  {
87  fin = fopen(filename,"r");
88  if(fin == NULL)
89  {
90  printf ("rlReport::include() ERROR: Could not find %s\n",filename);
91  ::printf("rlReport::include() ERROR: Could not find %s\n",filename);
92  return -1;
93  }
94  while(fgets(line,sizeof(line)-1,fin) != NULL)
95  {
96  fprintf(fout,"%s",line);
97  }
98  fclose(fin);
99  return 0;
100  }
101  else
102  {
103  fin = fopen(filename,"r");
104  if(fin == NULL)
105  {
106  printf ("rlReport::include() ERROR: Could not find %s\n",filename);
107  ::printf("rlReport::include() ERROR: Could not find %s\n",filename);
108  return -1;
109  }
110  while(fgets(line,sizeof(line)-1,fin) != NULL)
111  {
112  start = &line[0];
113  while(*start != '\0')
114  {
115  cptr = strstr(start,"\\$[");
116  if(cptr == NULL)
117  {
118  fprintf(fout,"%s",start);
119  break;
120  }
121  else
122  {
123  *cptr = '\0';
124  fprintf(fout,"%s", start);
125  cptr += 3;
126  section = cptr;
127  cptr = strchr(cptr,']');
128  if(cptr == NULL)
129  {
130  ::printf("rlReport::include ERROR in line=%s", line);
131  fclose(fin);
132  return -1;
133  }
134  *cptr = '\0';
135  cptr++;
136  cptr++;
137  name = cptr;
138  cptr = strchr(cptr,']');
139  if(cptr == NULL)
140  {
141  ::printf("rlReport::include ERROR in line=%s", line);
142  fclose(fin);
143  return -1;
144  }
145  *cptr = '\0';
146  cptr++;
147  start = cptr;
148  fprintf(fout,"%s", ini->text(section,name));
149  }
150  }
151  }
152  fclose(fin);
153  return 0;
154  }
155 }
const char * text(const char *section, const char *name)
Definition: rlinifile.cpp:208
int printf(const char *format,...)
Definition: rlreport.cpp:53
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
FILE * fout
Definition: rlreport.h:150

◆ includeCSV()

int rlReport::includeCSV ( const char *  filename,
int  use_first_row_as_title = 1,
const char *  legend = NULL,
char  delimitor = '\t' 
)
    print a CSV table  to the output file
    filename := name.csv
    use_first_row_as_title := 0 | 1
    legend := NULL | text_describing_the_table

Definition at line 241 of file rlreport.cpp.

242 {
243  int x,y,xmax,ymax;
244  rlSpreadsheetTable t(delimitor);
245  if(fout == NULL) return -1;
246  if(filename == NULL) return -1;
247  if(t.read(filename) < 0)
248  {
249  printf ("rlReport::includeCSV() ERROR: Could not find %s\n",filename);
250  ::printf("rlReport::includeCSV() ERROR: Could not find %s\n",filename);
251  return -1;
252  }
253 
254  x = xmax = 1;
255  while(t.exists(x,1) && xmax < 1024) xmax = x++;
256  y = ymax = 1;
257  while(t.exists(1,y) && ymax < 256*256) ymax = y++;
258 
259  printf("\\begin{center}\n");
260  printf("\\begin{longtable}");
261 
262  x = 1;
263  printf("{");
264  while(x <= xmax) { printf(" | l"); x++; }
265  printf(" | }\n");
266  printf(" \\hline\n");
267  for(y=1; y<=ymax; y++)
268  {
269  if(y==1 && use_first_row_as_title) printf(" \\rowcolor{gray}\n");;
270  printf(" ");
271  for(x=1; x<=xmax; x++)
272  {
273  printf("%s ", t.text(x,y));
274  if(x < xmax) printf("& ");
275  }
276  printf(" \\\\\n");
277  if(y < ymax) printf(" \\hline\n");
278  }
279  printf(" \\hline\n");
280  if(legend != NULL) printf(" \\caption{%s}\n", legend);
281 
282  printf("\\end{longtable}\n");
283  printf("\\end{center}\n");
284  return 0;
285 }
int printf(const char *format,...)
Definition: rlreport.cpp:53
FILE * fout
Definition: rlreport.h:150

◆ includeHeader()

int rlReport::includeHeader ( const char *  documentclass = "\\documentclass[a4paper]{article}",
const char *  language = "\\usepackage[english]{babel}",
const char *  inputenc = "\\usepackage[utf8]{inputenc}",
const char *  layout = "\\setlength{\\parindent}{0pt} \\setlength{\\topmargin}{-50pt} \\setlength{\\oddsidemargin}{0pt} \\setlength{\\textwidth}{480pt} \\setlength{\\textheight}{700pt}" 
)
    Include the LaTeX header to the output file.
    If optional_parameter == NULL then output the default parameters.
    Examples:
      includeHeader("\\usepackage[a4paper]{article}", "\\usepackage[ngerman]{babel}");
      includeHeader("\\usepackage[a4paper]{book}",    "\\usepackage[english,greek]{babel}");
    See:
      http://en.wikibooks.org/wiki/LaTeX/Internationalization
    Our default LaTeX header is within the fprintf() statements of rlReport::includeHeader()
      You may printf() or include() more header definitions and then call
      r.beginDocument();

Definition at line 157 of file rlreport.cpp.

158 {
159  if(fout == NULL) return -1;
160  if(documentclass == NULL) documentclass = "\\documentclass[a4paper]{article}";
161  if(language == NULL) language = "\\usepackage[english]{babel}";
162  if(inputenc == NULL) inputenc = "\\usepackage[utf8]{inputenc}";
163  if(layout == NULL) layout = "\\setlength{\\parindent}{0pt} \\setlength{\\topmargin}{-50pt} \\setlength{\\oddsidemargin}{0pt} \\setlength{\\textwidth}{480pt} \\setlength{\\textheight}{700pt}";
164 
165  fprintf(fout,"%s","% --- header begin ------------------------------------------------------------------------------------------------\n");
166  fprintf(fout, " %s\n", documentclass);
167  fprintf(fout, " %s\n", inputenc);
168  fprintf(fout,"%s"," \\usepackage[pdftex]{hyperref}\n");
169  fprintf(fout,"%s"," \\pdfcatalog{/UseThumbs /UseOutlines}\n");
170  fprintf(fout,"%s"," \\usepackage{amssymb}\n");
171  fprintf(fout,"%s"," \\newcommand{\\arrow}{\\begin{math}->\\end{math}} % define arrow symbol\n");
172  fprintf(fout,"%s"," \\newcommand{\\asterix}{\\begin{math}*\\end{math}} % define asterix symbol\n");
173  fprintf(fout, " %s\n", language);
174  fprintf(fout,"%s"," \\usepackage{textcomp} % define euro\n");
175  fprintf(fout,"%s"," \\usepackage{longtable} % use tables over several pages\n");
176  fprintf(fout,"%s"," \\usepackage{colortbl}\n");
177  fprintf(fout,"%s","\n");
178  fprintf(fout,"%s"," % % --- documentation support for sourcecode -------------\n");
179  fprintf(fout,"%s"," \\usepackage{listings}\n");
180  fprintf(fout,"%s"," \\usepackage{color}\n");
181  fprintf(fout,"%s"," \\definecolor{white}{rgb}{1.0,1.0,1.0}\n");
182  fprintf(fout,"%s"," \\definecolor{gray}{rgb}{0.5,0.5,0.5}\n");
183  fprintf(fout,"%s"," \\definecolor{darkred}{rgb}{0.5,0.0,0.0}\n");
184  fprintf(fout,"%s"," \\definecolor{lightgray}{rgb}{0.95,0.95,0.95}\n");
185  fprintf(fout,"%s"," \\definecolor{mygray}{gray}{0.55}\n");
186  fprintf(fout,"%s"," \\newcommand{\\simplecodestyle}{\\lstset{basicstyle=\\ttfamily\\small\\mdseries,backgroundcolor=\\color{lightgray},breaklines=true}}\n");
187  fprintf(fout,"%s"," \\newcommand{\\codestyle}{\\lstset{basicstyle=\\ttfamily\\small\\mdseries,keywordstyle=\\bfseries\\color{blue},commentstyle=\\color{gray},stringstyle=\\color{darkred},backgroundcolor=\\color{lightgray},breaklines=true}}\n");
188  fprintf(fout,"%s"," \\newcommand{\\simplecodebegin}[1]{\\simplecodestyle\\begin{lstlisting}[frame=single,flexiblecolumns=true,tabsize={8},inputencoding={utf8},title={#1}]}\n");
189  fprintf(fout,"%s"," \\newcommand{\\bashbegin}[1]{\\codestyle\\begin{lstlisting}[language=bash,frame=single,flexiblecolumns=true,tabsize={8},inputencoding={utf8},title={#1}]}\n");
190  fprintf(fout,"%s"," \\newcommand{\\bashsimple}[0]{\\codestyle\\begin{lstlisting}[language=bash,frame=single,flexiblecolumns=true,tabsize={8},inputencoding={utf8}]}\n");
191  fprintf(fout,"%s"," \\newcommand{\\cppbegin}[1]{\\codestyle\\begin{lstlisting}[language=C++,frame=single,flexiblecolumns=true,tabsize={8},inputencoding={utf8},title={#1}]}\n");
192  fprintf(fout,"%s"," \\newcommand{\\cppsimple}[0]{\\codestyle\\begin{lstlisting}[language=C++,frame=single,flexiblecolumns=true],tabsize={8},inputencoding={utf8}}\n");
193  fprintf(fout,"%s"," \\newcommand{\\cppend}{\\end{lstlisting}}\n");
194  fprintf(fout,"%s"," \\newcommand{\\pybegin}[1]{\\codestyle\\begin{lstlisting}[language=Python,frame=single,flexiblecolumns=true,tabsize={8},inputencoding={utf8},title={#1}]}\n");
195  fprintf(fout,"%s"," \\newcommand{\\xmlbegin}[1]{\\codestyle\\begin{lstlisting}[language=XML,frame=single,flexiblecolumns=true,tabsize={8},inputencoding={utf8},title={#1}]}\n");
196  fprintf(fout,"%s"," \\newcommand{\\tclbegin}[1]{\\codestyle\\begin{lstlisting}[language=tcl,frame=single,flexiblecolumns=true,tabsize={8},inputencoding={utf8},title={#1}]}\n");
197  fprintf(fout,"%s"," \\lstdefinelanguage{mylua}\n");
198  fprintf(fout,"%s"," {keywords={while,for,elseif,if,else,then,do,end,return,function,and,or,not,nil,true,false},\n");
199  fprintf(fout,"%s"," sensitive=true,\n");
200  fprintf(fout,"%s"," morecomment=[l][\\color{mygray}]{--},\n");
201  fprintf(fout,"%s"," string=[b],\n");
202  fprintf(fout,"%s"," }\n");
203  fprintf(fout,"%s"," \\newcommand{\\luabegin}[1]{\\codestyle\\begin{lstlisting}[language=mylua,frame=single,flexiblecolumns=true,tabsize={8},inputencoding={utf8},title={#1}]}\n");
204  fprintf(fout,"%s"," % % --- usage example begin -----------------------------\n");
205  fprintf(fout,"%s"," % \\cppbegin{Titel of our C++ code snippet}\n");
206  fprintf(fout,"%s"," % printf(\"hello world\\n\");\n");
207  fprintf(fout,"%s"," % \\end{lstlisting}\n");
208  fprintf(fout,"%s"," % % --- usage example end -------------------------------\n");
209  fprintf(fout,"%s","\n");
210  fprintf(fout,"%s","\n");
211  fprintf(fout,"%s"," % % --- graphics support --------------------------------\n");
212  fprintf(fout,"%s"," \\usepackage{graphicx}\n");
213  fprintf(fout,"%s"," \\usepackage{float}\n");
214  fprintf(fout,"%s"," \\newcommand{\\img}[3]{\n");
215  fprintf(fout,"%s"," \\setlength\\fboxsep{0pt}\n");
216  fprintf(fout,"%s"," \\setlength\\fboxrule{1pt}\n");
217  fprintf(fout,"%s"," \\begin{figure}\n");
218  fprintf(fout,"%s"," \\begin{center}\n");
219  fprintf(fout,"%s"," \\fbox{\\includegraphics[scale=#1]{#2}}\n");
220  fprintf(fout,"%s"," \\caption{#3}\n");
221  fprintf(fout,"%s"," \\end{center}\n");
222  fprintf(fout,"%s"," \\end{figure}\n");
223  fprintf(fout,"%s"," }\n");
224  fprintf(fout,"%s"," \\newcommand{\\imgH}[3]{\n");
225  fprintf(fout,"%s"," \\setlength\\fboxsep{0pt}\n");
226  fprintf(fout,"%s"," \\setlength\\fboxrule{1pt}\n");
227  fprintf(fout,"%s"," \\begin{figure}[H]\n");
228  fprintf(fout,"%s"," \\begin{center}\n");
229  fprintf(fout,"%s"," \\fbox{\\includegraphics[scale=#1]{#2}}\n");
230  fprintf(fout,"%s"," \\caption{#3}\n");
231  fprintf(fout,"%s"," \\end{center}\n");
232  fprintf(fout,"%s"," \\end{figure}\n");
233  fprintf(fout,"%s"," }\n");
234  fprintf(fout,"%s","\n");
235  fprintf(fout,"%s"," % % --- definition of the paper layout ------------------- \n");
236  fprintf(fout, " %s\n", layout);
237  fprintf(fout,"%s","% --- header end --------------------------------------------------------------------------------------------------\n");
238  return 0;
239 }
FILE * fout
Definition: rlreport.h:150

◆ includeImage()

int rlReport::includeImage ( const char *  filename,
const char *  legend = NULL,
float  scale = 1.0f 
)
    Include a graphic into our document.
    filename := name.jpg | name.png
    legend := NULL | text_describeing_the_image

Definition at line 287 of file rlreport.cpp.

288 {
289  if(fout == NULL) return -1;
290  if(filename == NULL) return -1;
291  if(legend == NULL) legend = "";
292  printf("\\img{%.1f}{%s}{%s}\n", scale, filename, legend);
293  return 0;
294 }
int printf(const char *format,...)
Definition: rlreport.cpp:53
FILE * fout
Definition: rlreport.h:150

◆ open()

int rlReport::open ( const char *  filename)
    open the output file for writeing

Definition at line 31 of file rlreport.cpp.

32 {
33  char *cptr;
34  file = "";
35  if(filename == NULL) return -1;
36  if(fout != NULL) fclose(fout);
37  file = filename;
38  cptr = strstr(file.text(),".tex");
39  if(cptr != NULL) *cptr = '\0';
40  fout = fopen(filename,"w");
41  if(fout == NULL) return -1;
42  return 0;
43 }
FILE * fout
Definition: rlreport.h:150
char * text()
Definition: rlstring.cpp:126
rlString file
Definition: rlreport.h:151

◆ pdflatex()

int rlReport::pdflatex ( const char *  command = NULL)
    Run "pdflatex -interaction=nonstopmode file.tex" if command==NULL or
    what you specify by your own command.

Definition at line 308 of file rlreport.cpp.

309 {
310  char cmd[rl_PRINTF_LENGTH]; // should be big enough
311  if(command == NULL)
312  {
313  sprintf(cmd,"pdflatex -interaction=nonstopmode %s.tex", file.text());
314  system(cmd); // run pdflatex twice
315  return system(cmd);
316  }
317  else
318  {
319  sprintf(cmd,"%s %s.tex", command, file.text());
320  system(cmd); // run pdflatex twice
321  return system(cmd);
322  }
323 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
char * text()
Definition: rlstring.cpp:126
rlString file
Definition: rlreport.h:151

◆ printf()

int rlReport::printf ( const char *  format,
  ... 
)
    print text to the output file

Definition at line 53 of file rlreport.cpp.

54 {
55  int ret;
56  char line[rl_PRINTF_LENGTH]; // should be big enough
57 
58  va_list ap;
59  va_start(ap,format);
60  ret = rlvsnprintf(line, rl_PRINTF_LENGTH - 1, format, ap);
61  va_end(ap);
62  if(ret < 0) return ret;
63  fprintf(fout,"%s",line);
64  return ret;
65 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
FILE * fout
Definition: rlreport.h:150
int rlvsnprintf(char *text, int len, const char *format, va_list ap)
Definition: rlcutil.cpp:197

◆ spawn()

int rlReport::spawn ( const char *  command)
    Run the external "command" and include what is printed by "command" to the output file.
    This works as follows:
      sprintf(cmd,"%s > %s.temp", command, file.text())
      system(cmd);
      include(file.text() + ".temp");

Definition at line 296 of file rlreport.cpp.

297 {
298  char cmd[rl_PRINTF_LENGTH]; // should be big enough
299 
300  if(fout == NULL) return -1;
301  if(command == NULL) return -1;
302  sprintf(cmd,"%s > %s.temp", command, file.text());
303  system(cmd);
304  sprintf(cmd,"%s.temp", file.text());
305  return include(cmd);
306 }
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
FILE * fout
Definition: rlreport.h:150
char * text()
Definition: rlstring.cpp:126
rlString file
Definition: rlreport.h:151
int include(const char *filename, rlIniFile *ini=NULL)
Definition: rlreport.cpp:77

Member Data Documentation

◆ file

rlString rlReport::file
private

Definition at line 151 of file rlreport.h.

◆ fout

FILE* rlReport::fout
private

Definition at line 150 of file rlreport.h.


The documentation for this class was generated from the following files: