rllib  1
Public Member Functions | List of all members
rlHtml Class Reference

#include <rlhtml.h>

Inheritance diagram for rlHtml:
Inheritance graph
[legend]

Public Member Functions

 rlHtml ()
 
virtual ~rlHtml ()
 
const char * htmlHeader ()
 
const char * htmlTrailer ()
 
int textFile (const char *filename, rlString &text)
 
int hexdumpFile (const char *filename, rlString &text)
 

Detailed Description

conveniance base class for html

Definition at line 25 of file rlhtml.h.

Constructor & Destructor Documentation

◆ rlHtml()

rlHtml::rlHtml ( )

Definition at line 21 of file rlhtml.cpp.

22 {
23 }

◆ ~rlHtml()

rlHtml::~rlHtml ( )
virtual

Definition at line 25 of file rlhtml.cpp.

26 {
27 }

Member Function Documentation

◆ hexdumpFile()

int rlHtml::hexdumpFile ( const char *  filename,
rlString text 
)
hexdump representation of text file

Definition at line 100 of file rlhtml.cpp.

101 {
102  char tmp[4096];
103  int maxlen = sizeof(tmp);
104  maxlen -= 8;
105  rlSpawn sp;
106  rlString cmd;
107  cmd.printf("od -A x -t x1z -v \"%s\"", filename);
108  sp.spawn(cmd.text());
109 
110  text = htmlHeader();
111  text += "<pre id=\"rlHexdumpFile\">\n";
112  const char *line;
113  while((line = sp.readLine()) != NULL)
114  {
115  const char *source = line;
116  char *dest = &tmp[0];
117  int i = 1;
118  while(*source != '\0' && i<maxlen)
119  {
120  i++;
121  if(*source == '<')
122  {
123  source++;
124  *dest++ = '&';
125  *dest++ = 'l';
126  *dest++ = 't';
127  *dest++ = ';';
128  }
129  else if(*source == '>')
130  {
131  source++;
132  *dest++ = '&';
133  *dest++ = 'g';
134  *dest++ = 't';
135  *dest++ = ';';
136  }
137  else
138  {
139  *dest++ = *source++;
140  }
141  }
142  *dest = '\0';
143  text += tmp;
144  }
145  text += "</pre>\n";
146  text += htmlTrailer();
147  return 0;
148 }
const char * htmlTrailer()
Definition: rlhtml.cpp:39
const char * htmlHeader()
Definition: rlhtml.cpp:29
char * text()
Definition: rlstring.cpp:126
const char * readLine()
Definition: rlspawn.cpp:307
int printf(const char *format,...)
Definition: rlstring.cpp:145
int spawn(const char *command)
Definition: rlspawn.cpp:168

◆ htmlHeader()

const char * rlHtml::htmlHeader ( )
html can be configured with rlhtml.css

Definition at line 29 of file rlhtml.cpp.

30 {
31  return "<html>\n"
32  "<head>\n"
33  " <meta charset=\"utf-8\"> <title>rlHtmlDir</title>\n"
34  " <link rel=\"stylesheet\" type=\"text/css\" href=\"rlhtml.css\">\n"
35  "</head>\n"
36  "<body id=\"rlhtmlbody\">\n";
37 }

◆ htmlTrailer()

const char * rlHtml::htmlTrailer ( )

Definition at line 39 of file rlhtml.cpp.

40 {
41  return "</body>\n"
42  "</html>\n";
43 }

◆ textFile()

int rlHtml::textFile ( const char *  filename,
rlString text 
)
html representation of text file

Definition at line 45 of file rlhtml.cpp.

46 {
47  struct stat statbuf;
48  rlStat(filename, &statbuf);
49 
50  char tmp[4096];
51  int maxlen = sizeof(tmp);
52  maxlen -= 8;
53  rlFileLoad fl;
54  if(fl.load(filename) < 0) return -1;
55  text = htmlHeader();
56  sprintf(tmp,"<p>File=%s Size=%ldByte, %ldkByte</p><hr>\n", filename, statbuf.st_size, statbuf.st_size/(1024));
57  text += tmp;
58  text += "<pre id=\"rlTextFile\">\n";
59  const char *line = fl.firstLine();
60  while(line != NULL)
61  {
62  const char *source = line;
63  char *dest = &tmp[0];
64  int i = 1;
65  while(*source != '\0' && i<maxlen)
66  {
67  i++;
68  if(*source == '<')
69  {
70  source++;
71  *dest++ = '&';
72  *dest++ = 'l';
73  *dest++ = 't';
74  *dest++ = ';';
75  }
76  else if(*source == '>')
77  {
78  source++;
79  *dest++ = '&';
80  *dest++ = 'g';
81  *dest++ = 't';
82  *dest++ = ';';
83  }
84  else
85  {
86  *dest++ = *source++;
87  }
88  }
89  *dest = '\0';
90  strcat(dest,"\n");
91  text += tmp;
92  line = fl.nextLine();
93  }
94  text += "</pre>\n";
95  text += htmlTrailer();
96  return 0;
97 }
const char * htmlTrailer()
Definition: rlhtml.cpp:39
int load(const char *filename)
Definition: rlfileload.cpp:33
const char * htmlHeader()
Definition: rlhtml.cpp:29
const char * nextLine()
Definition: rlfileload.cpp:91
const char * firstLine()
Definition: rlfileload.cpp:81
int rlStat(const char *filepath, struct stat *buf)
Definition: rlcutil.cpp:804

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