38 using namespace basis;
41 using namespace nodes;
50 #define BASE_LOG(s) program_wide_logger::get().log(s, ALWAYS_PRINT)
52 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), \
53 a_sprintf("line %d: ", _categories._line_number) + s, ALWAYS_PRINT)
64 _loader_count(0), _link_spool(0), _functions_pending(0) {}
66 virtual int execute();
69 int write_marks_page(
const astring &output_filename,
70 const astring &template_filename);
97 This program needs three filenames as command line parameters. The -i flag\n\
98 is used to specify the input filename, the -t flag specifies a template web\n\
99 page which is used as the wrapper around the links, and the -o flag specifies\n\
100 the web page to be created. The input file is expected to be in the HOOPLE\n\
101 link database format. The output file will be created from the template file\n\
102 by finding the phrase $INSERT_LINKS_HERE in it and replacing that with html\n\
103 formatted link and categories from the input file. Another tag of $TODAYS_DATE\n\
104 will be replaced with the date when the output file is regenerated.\n\
105 The HOOPLE link format is documented here:\n\
106 http://feistymeow.org/guides/link_database/format_manifesto.txt\n\
108 program_wide_logger::get().log(to_show, ALWAYS_PRINT);
117 int node_num =
node->_uid;
119 int parent_node = parent? parent->
_uid : -1;
122 for (
int i = chewed_name.
end(); i >= 0; i--) {
124 if (chewed_name[i] ==
'\'') {
125 chewed_name.
zap(i, i);
126 chewed_name.
insert(i,
"\\'");
129 output +=
a_sprintf(
" b.add(%d, %d, '%s');\n", node_num, parent_node,
138 int parent_node =
node->_uid;
140 for (
int i = chewed_name.
end(); i >= 0; i--) {
142 if (chewed_name[i] ==
'\'') {
143 chewed_name.
zap(i, i);
144 chewed_name.
insert(i,
"\\'");
163 if (! (_link_spool % 100) ) {
166 output +=
" setTimeout('run_tree_loaders()', 0);\n";
170 output +=
a_sprintf(
"function tree_loader_%d() {\n", _loader_count++);
174 output +=
a_sprintf(
" b.add(%d, %d, '%s', '%s');\n",
175 linko.
_uid, parent_node, chewed_name.
s(), linko.
_url.
s());
178 int marks_maker_javascript::execute()
187 if (!cmds.get_value(
'i', input_filename,
false))
189 if (!cmds.get_value(
'o', output_filename,
false))
191 if (!cmds.get_value(
't', template_filename,
false))
198 int ret = _categories.read_csv_file(input_filename);
201 ret = write_marks_page(output_filename, template_filename);
207 int marks_maker_javascript::write_marks_page(
const astring &output_filename,
208 const astring &template_filename)
216 long_string +=
"<div class=\"marks_target\" id=\"martarg\">Marks Target</div>\n";
219 long_string +=
"\n<div class=\"dtree\">\n";
220 long_string +=
"<script type=\"text/javascript\">\n";
221 long_string +=
"<!--\n";
223 long_string +=
"function open_mark(url) {\n";
224 long_string +=
" window.open(url, '', '');\n";
225 long_string +=
"}\n";
229 long_string +=
" b = new dTree('b');\n";
231 long_string +=
" b.config.useCookies = false;\n";
232 long_string +=
" b.config.folderLinks = false;\n";
235 tree::iterator itty = _categories.access_root().start(tree::prefix);
237 while ( (curr = itty.
next()) ) {
240 write_category(nod, long_string);
245 write_link(nod, *lin, long_string);
250 long_string +=
" setTimeout('run_tree_loaders()', 0);\n";
251 long_string +=
"}\n\n";
253 long_string +=
a_sprintf(
"function tree_loader_%d()"
254 "{ setTimeout('run_tree_loaders()', 0); }\n", _loader_count++);
256 long_string +=
"\nconst max_funcs = 1000;\n";
257 long_string +=
"var loader_functions = new Array(max_funcs);\n";
258 long_string +=
"var curr_func = 0;\n";
259 long_string +=
"var done_rendering = false;\n\n";
261 long_string +=
a_sprintf(
"for (var i = 0; i < %d; i++) {\n", _loader_count);
262 long_string +=
" loader_functions[curr_func++] "
263 "= 'tree_loader_' + i + '()';\n";
264 long_string +=
"}\n";
266 long_string +=
"var run_index = 0;\n";
267 long_string +=
"function run_tree_loaders() {\n";
268 long_string +=
" if (done_rendering) return;\n";
269 long_string +=
" if (run_index >= curr_func) {\n";
271 long_string +=
" if (document.getElementById) {\n";
272 long_string +=
" x = document.getElementById('martarg');\n";
273 long_string +=
" x.innerHTML = '';\n";
274 long_string +=
" x.innerHTML = b;\n";
275 long_string +=
" } else { document.write(b); }\n";
278 long_string +=
" done_rendering = true;\n";
279 long_string +=
" return;\n";
280 long_string +=
" }\n";
281 long_string +=
" var next_func = loader_functions[run_index++];\n";
282 long_string +=
" setTimeout(next_func, 0);\n";
283 long_string +=
"}\n";
285 long_string +=
a_sprintf(
" run_tree_loaders();\n", _loader_count);
287 long_string +=
"//-->\n";
288 long_string +=
"</script>\n";
289 long_string +=
"<p><a href=\"javascript: b.openAll();\">open all</a> | "
290 "<a href=\"javascript: b.closeAll();\">close all</a></p>\n";
291 long_string +=
"</div>\n";
293 byte_filer template_file(template_filename,
"r");
295 if (!template_file.good())
298 template_file.close();
301 int indy = full_template.
ifind(
"</title>");
304 "a <head> declaration");
306 full_template.
insert(indy + 8,
"\n\n"
307 "<link rel=\"StyleSheet\" href=\"/yeti/javascript/dtree/dtree.css\" "
308 "type=\"text/css\" />\n"
309 "<script type=\"text/javascript\" src=\"/yeti/javascript/"
310 "dtree/dtree.js\"></script>\n");
313 bool found_it = full_template.
replace(
"$INSERT_LINKS_HERE", long_string);
316 "the insertion point");
317 full_template.
replace(
"$TODAYS_DATE", time_stamp::notarize(
true));
320 if (outname.exists()) {
322 + output_filename +
" already exists. It would be over-written if "
327 if (!output_file.good())
330 output_file.write(full_template);
338 _categories.link_count(), _categories.category_count()));
int print_instructions(bool good, const astring &program_name)
The application_shell is a base object for console programs.
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
bool replace(const astring &tag, const astring &replacement)
replaces the first occurrence of "tag" text with the "replacement".
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
void insert(int position, const astring &to_insert)
Copies "to_insert" into "this" at the "position".
int end() const
returns the index of the last (non-null) character in the string.
int ifind(char to_find, int position=0, bool reverse=false) const
like the find() methods above, but case-insensitive.
Provides file managment services using the standard I/O support.
Provides operations commonly needed on file names.
const basis::astring & raw() const
returns the astring that we're holding onto for the path.
filename basename() const
returns the base of the filename; no directory.
basis::astring _description
An object representing the interstitial cell in most linked data structures.
tree * next()
Returns a pointer to the next tree in the direction of traversal.
A dynamically linked tree with an arbitrary number of branches.
int elements() const
the maximum number of elements currently allowed in this amorph.
contents * borrow(int field)
Returns a pointer to the information at the index "field".
#define SETUP_COMBO_LOGGER
a macro that retasks the program-wide logger as a combo_logger.
#define non_continuable_error(c, f, i)
an extra piece of information used, if available, in bounds_halt below.
#define NULL_POINTER
The value representing a pointer to nothing.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
const int MEGABYTE
Number of bytes in a megabyte.
bool negative(const type &a)
negative returns true if "a" is less than zero.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.