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

#include <rlhtmldir.h>

Inheritance diagram for rlHtmlDir:
Inheritance graph
[legend]
Collaboration diagram for rlHtmlDir:
Collaboration graph
[legend]

Public Types

enum  { list_files_and_directories = 1, list_directories_only = 2, list_files_only = 3 }
 

Public Member Functions

 rlHtmlDir ()
 
virtual ~rlHtmlDir ()
 
int cd (const char *dir, int is_initial_dir=0)
 
const char * getHtml (int generate_html_header_and_trailer=1)
 
int getFilenames (rlSpreadsheetRow *row)
 
- Public Member Functions inherited from rlHtml
 rlHtml ()
 
virtual ~rlHtml ()
 
const char * htmlHeader ()
 
const char * htmlTrailer ()
 
int textFile (const char *filename, rlString &text)
 
int hexdumpFile (const char *filename, rlString &text)
 

Public Attributes

enum rlHtmlDir:: { ... }  WHAT_TO_LIST
 
rlString initialPath
 
rlString currentPath
 
rlString pattern
 
int recursive
 
int list_what
 
int hide_hidden_files
 
rlString textHome
 
rlString textPath
 
rlString textrlHtmlDirCSS
 
rlString startHtml
 
rlString endHtml
 

Private Attributes

rlString html
 

Detailed Description

class for a file selector with html

Definition at line 25 of file rlhtmldir.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
list_files_and_directories 
list_directories_only 
list_files_only 

Definition at line 28 of file rlhtmldir.h.

Constructor & Destructor Documentation

◆ rlHtmlDir()

rlHtmlDir::rlHtmlDir ( )

Definition at line 19 of file rlhtmldir.cpp.

20  :rlHtml()
21 {
23  pattern = "*";
24  initialPath = "";
25  currentPath = "";
26  recursive = 0;
28  textHome = "Home:";
29  textPath = "Path:";
30  textrlHtmlDirCSS = "rlhtml.css";
31 }
rlString textHome
Definition: rlhtmldir.h:60
int hide_hidden_files
Definition: rlhtmldir.h:59
rlString pattern
Definition: rlhtmldir.h:56
rlString textPath
Definition: rlhtmldir.h:61
int list_what
Definition: rlhtmldir.h:58
rlString initialPath
Definition: rlhtmldir.h:54
int recursive
Definition: rlhtmldir.h:57
rlString currentPath
Definition: rlhtmldir.h:55
rlHtml()
Definition: rlhtml.cpp:21
rlString textrlHtmlDirCSS
Definition: rlhtmldir.h:62

◆ ~rlHtmlDir()

rlHtmlDir::~rlHtmlDir ( )
virtual

Definition at line 33 of file rlhtmldir.cpp.

34 {
35 }

Member Function Documentation

◆ cd()

int rlHtmlDir::cd ( const char *  dir,
int  is_initial_dir = 0 
)
dir := ".." | "absolute_path" | "relative_path"

Definition at line 37 of file rlhtmldir.cpp.

38 {
39  rlString dirCopy;
40  dirCopy = dirIn;
41  const char *dir = dirCopy.text();
42  if(*dir == '.')
43  {
44  if(dir[1] == '.')
45  {
46  if(strlen( initialPath.text() ) < strlen( currentPath.text() ))
47  {
48  char *cptr = strrchr(currentPath.text(),'/');
49  if(cptr != NULL)
50  {
51  if(cptr != currentPath.text()) *cptr = '\0'; // cd ..
52  return 0;
53  }
54  }
55  }
56  return -1;
57  }
58  else if(*dir == '/') // cd /absolute/path
59  {
60  currentPath = dir;
61  if(is_initial_dir) initialPath = dir;
62  }
63  else if(*dir == '~')
64  {
65  currentPath = initialPath; // cd home
66  }
67  else
68  {
69  currentPath += "/";
70  currentPath += dir; // cd into subdirectory
71  }
72  return 0;
73 }
char * text()
Definition: rlstring.cpp:126
rlString initialPath
Definition: rlhtmldir.h:54
rlString currentPath
Definition: rlhtmldir.h:55

◆ getFilenames()

int rlHtmlDir::getFilenames ( rlSpreadsheetRow row)
list of filenames found
return: number of files found

Definition at line 177 of file rlhtmldir.cpp.

178 {
179  if(row == NULL) return 0;
180  rlSpawn spawn;
181  rlString cmd;
182  const char *line;
183  rlString file;
184 #ifdef RLWIN32
185  if(recursive) cmd.printf("rlfind \"%s\" -name \"%s\"", currentPath.text(), pattern.text());
186  else cmd.printf("rlfind \"%s\" -only \"%s\"", currentPath.text(), pattern.text());
187 #else
188  if(recursive) cmd.printf("sh -c \"rlfind '%s' -name '%s' | sort\"", currentPath.text(), pattern.text());
189  else cmd.printf("sh -c \"rlfind '%s' -only '%s' | sort\"", currentPath.text(), pattern.text());
190 #endif
191  spawn.spawn(cmd.text());
192  row->clear();
193  int i=1;
194  while(1)
195  {
196  line = spawn.readLine();
197  if(line == NULL) break;
198  file = line;
199  if(hide_hidden_files == 0 || (hide_hidden_files == 1 && strncmp(file.text(),".",1) != 0))
200  {
201  file.removeNewline();
202  row->setText(i++,file.text());
203  //printf("file=%s\n", file.text());
204  }
205  }
206  return i-1;
207 }
void setText(int column, const char *text)
int hide_hidden_files
Definition: rlhtmldir.h:59
rlString pattern
Definition: rlhtmldir.h:56
char * text()
Definition: rlstring.cpp:126
int removeNewline()
Definition: rlstring.cpp:271
const char * readLine()
Definition: rlspawn.cpp:307
int printf(const char *format,...)
Definition: rlstring.cpp:145
int recursive
Definition: rlhtmldir.h:57
rlString currentPath
Definition: rlhtmldir.h:55
int spawn(const char *command)
Definition: rlspawn.cpp:168

◆ getHtml()

const char * rlHtmlDir::getHtml ( int  generate_html_header_and_trailer = 1)
html can be configured with rlhtml.css

Definition at line 75 of file rlhtmldir.cpp.

76 {
77  html = "";
78  if(generate_html_header_and_trailer)
79  {
80  html = htmlHeader();
81  }
82 
83  html += startHtml.text();
84  html += "<pre class=\"rlhtmldirpre\">\n";
85 
86  rlSpawn spawn;
87  rlString cmd;
88  const char *line;
89  rlString file;
90  rlString htmlline;
91  char *cptr;
92 #ifdef RLWIN32
93  if(recursive) cmd.printf("rlfind \"%s\" -name \"%s\"", currentPath.text(), pattern.text());
94  else cmd.printf("rlfind \"%s\"", currentPath.text());
95  //else cmd.printf("rlfind \"%s\" -only \"%s\"", currentPath.text(), pattern.text());
96 #else
97  if(recursive) cmd.printf("sh -c \"rlfind '%s' -name '%s' | sort\"", currentPath.text(), pattern.text());
98  else cmd.printf("sh -c \"rlfind '%s' -only '%s' | sort\"", currentPath.text(), pattern.text());
99 #endif
100  if(1) //recursive == 0)
101  {
102  htmlline.printf("%s <a class=\"rlhtmldirhome\" href=\"ftp://rlhtmldirhome%s\">%s</a>\n", textHome.text(), initialPath.text(), initialPath.text());
103  html += htmlline.text();
104  htmlline.printf("%s %s\n", textPath.text(), currentPath.text());
105  html += htmlline.text();
106  if(strcmp(initialPath.text(),currentPath.text()) != 0)
107  {
108  htmlline.printf("<a class=\"rlhtmldirup\" href=\"ftp://rlhtmldirup/dir/up\">..</a>\n");
109  html += htmlline.text();
110  }
111  }
112  spawn.spawn(cmd.text());
113  while(1)
114  {
115  line = spawn.readLine();
116  // printf("line=%s", line);
117  if(line == NULL) break;
118  if(strncmp(line,"#EOF#",5) == 0) break;
119  file = line;
120  file.removeNewline();
121  cptr = strstr(file.text()," [");
122  if(cptr != NULL)
123  {
124  if (strcmp(cptr," [d]") == 0)
125  {
126  // list = 1 (list files and directories)
127  // list = 2 (list directories only)
128  // list = 3 (list files only)
129  if(list_what != list_files_only)
130  {
131  if(cptr != NULL) *cptr = '\0';
132  if(strcmp(initialPath.text(),file.text()) != 0 && strcmp(currentPath.text(),file.text()) != 0 )
133  {
134  cptr = strrchr(file.text(),'/');
135  if(cptr == NULL) cptr = file.text();
136  cptr++;
137  if(recursive) htmlline.printf("+<a class=\"rlhtmldir\" href=\"ftp://rlhtmldir%s\">%s</a>\n", file.text(), file.text());
138  else htmlline.printf("+<a class=\"rlhtmldir\" href=\"ftp://rlhtmldir%s\">%s</a>\n", file.text(), cptr);
139  html += htmlline.text();
140  }
141  }
142  }
143  else if(strcmp(cptr," [f]") == 0)
144  {
145  // list = 1 (list files and directories)
146  // list = 2 (list directories only)
147  // list = 3 (list files only)
149  {
150  if(cptr != NULL) *cptr = '\0';
151  cptr = strrchr(file.text(),'/');
152  if(cptr == NULL) cptr = file.text();
153  cptr++;
154  if(hide_hidden_files == 0 || (hide_hidden_files == 1 && strncmp(cptr,".",1) != 0))
155  {
156  if(recursive) htmlline.printf(" <a class=\"rlhtmlfile\" href=\"ftp://rlhtmlfile%s\">%s</a>\n", file.text(), file.text());
157  else htmlline.printf(" <a class=\"rlhtmlfile\" href=\"ftp://rlhtmlfile%s\">%s</a>\n", file.text(), cptr);
158  html += htmlline.text();
159  }
160  }
161  }
162  }
163  }
164 
165  html += "</pre>\n";
166  html += endHtml.text();
167 
168  if(generate_html_header_and_trailer)
169  {
170  html += htmlTrailer();
171  }
172 
173  //printf("HTML=\n%s", html.text());
174  return html.text();
175 }
rlString textHome
Definition: rlhtmldir.h:60
const char * htmlTrailer()
Definition: rlhtml.cpp:39
int hide_hidden_files
Definition: rlhtmldir.h:59
rlString pattern
Definition: rlhtmldir.h:56
const char * htmlHeader()
Definition: rlhtml.cpp:29
rlString endHtml
Definition: rlhtmldir.h:65
char * text()
Definition: rlstring.cpp:126
rlString startHtml
Definition: rlhtmldir.h:64
rlString textPath
Definition: rlhtmldir.h:61
int list_what
Definition: rlhtmldir.h:58
int removeNewline()
Definition: rlstring.cpp:271
const char * readLine()
Definition: rlspawn.cpp:307
rlString initialPath
Definition: rlhtmldir.h:54
int printf(const char *format,...)
Definition: rlstring.cpp:145
int recursive
Definition: rlhtmldir.h:57
rlString currentPath
Definition: rlhtmldir.h:55
rlString html
Definition: rlhtmldir.h:67
int spawn(const char *command)
Definition: rlspawn.cpp:168

Member Data Documentation

◆ currentPath

rlString rlHtmlDir::currentPath

Definition at line 55 of file rlhtmldir.h.

◆ endHtml

rlString rlHtmlDir::endHtml

Definition at line 65 of file rlhtmldir.h.

◆ hide_hidden_files

int rlHtmlDir::hide_hidden_files

Definition at line 59 of file rlhtmldir.h.

◆ html

rlString rlHtmlDir::html
private

Definition at line 67 of file rlhtmldir.h.

◆ initialPath

rlString rlHtmlDir::initialPath

Definition at line 54 of file rlhtmldir.h.

◆ list_what

int rlHtmlDir::list_what

Definition at line 58 of file rlhtmldir.h.

◆ pattern

rlString rlHtmlDir::pattern

Definition at line 56 of file rlhtmldir.h.

◆ recursive

int rlHtmlDir::recursive

Definition at line 57 of file rlhtmldir.h.

◆ startHtml

rlString rlHtmlDir::startHtml

Definition at line 64 of file rlhtmldir.h.

◆ textHome

rlString rlHtmlDir::textHome

Definition at line 60 of file rlhtmldir.h.

◆ textPath

rlString rlHtmlDir::textPath

Definition at line 61 of file rlhtmldir.h.

◆ textrlHtmlDirCSS

rlString rlHtmlDir::textrlHtmlDirCSS

Definition at line 62 of file rlhtmldir.h.

◆ WHAT_TO_LIST

enum { ... } rlHtmlDir::WHAT_TO_LIST

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