32 using namespace basis;
35 using namespace nodes;
44 #define BASE_LOG(s) program_wide_logger::get().log(s, ALWAYS_PRINT)
46 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
70 int write_marks_page(
const astring &output_filename,
71 const astring &template_filename, output_style way);
77 virtual int execute();
84 void increase_nesting(
astring &output);
87 void decrease_nesting(
astring &output);
95 void inject_javascript_function(
astring &output);
98 void write_category_start(
const astring &name,
int node_depth,
astring &output);
101 void write_category_end(
int depth,
astring &output);
111 marks_maker::marks_maker()
114 c_style(ST_HUMAN_READABLE)
120 This program needs three filenames as command line parameters. The -i flag\n\
121 is used to specify the input filename, the -t flag specifies a template web\n\
122 page which is used as the wrapper around the links, and the -o flag specifies\n\
123 the web page to be created. The input file is expected to be in the HOOPLE\n\
124 link database format. The output file will be created from the template file\n\
125 by finding the phrase $INSERT_LINKS_HERE in it and replacing that with html\n\
126 formatted link and categories from the input file. Another tag of $TODAYS_DATE\n\
127 will be replaced with the date when the output file is regenerated. A final\n\
128 tag of $INSERT_JAVASCRIPT_HERE is replaced with a link opening function.\n\
129 Note that an optional -s flag can specify a value of \"human\" readable\n\
130 or \"mozilla\" bookmarks style to specify the style of the output file\n\
132 The HOOPLE link format is documented here:\n\
133 http://feistymeow.org/guides/link_database/format_manifesto.txt\n\
135 program_wide_logger::get().log(to_show, ALWAYS_PRINT);
139 void marks_maker::increase_nesting(
astring &output)
145 LOG(
a_sprintf(
"++increased depth to %d...", c_current_depth));
147 output += string_manipulation::indentation(spaces);
149 output += parser_bits::platform_eol_to_chars();
152 void marks_maker::decrease_nesting(
astring &output)
157 LOG(
a_sprintf(
"--decreased depth to %d...", c_current_depth));
160 output += string_manipulation::indentation(spaces);
161 output +=
"</dl><p>";
162 output += parser_bits::platform_eol_to_chars();
165 void marks_maker::write_category_start(
const astring &name,
int node_depth,
astring &output)
167 FUNCDEF(
"write_category_start");
170 int heading_num = node_depth + 1;
173 if (c_style == ST_MOZILLA_MARKS) heading =
"3";
180 output += string_manipulation::indentation(c_current_depth *
SPACING_CHUNK);
189 output += parser_bits::platform_eol_to_chars();
191 increase_nesting(output);
194 void marks_maker::write_category_end(
int depth,
astring &output)
197 decrease_nesting(output);
212 output += parser_bits::platform_eol_to_chars();
217 if (c_style != ST_MOZILLA_MARKS) {
226 if (c_style != ST_MOZILLA_MARKS) {
230 description +=
"...";
238 output += indentulus;
239 output +=
"<dt><li>";
240 output +=
"<a href=\"";
241 output += linko.
_url;
243 output += description;
246 if (c_style != ST_MOZILLA_MARKS) {
247 output +=
" ";
248 output +=
"<a href=\"javascript:open_mark('";
249 output += linko.
_url;
251 output +=
"[launch]";
257 output += parser_bits::platform_eol_to_chars();
266 write_category_start(nod->
name(), nod->
depth(), to_return);
271 write_link(nod, *lin, to_return, nod->
depth());
275 for (
int i = 0; i < nod->
branches(); i++) {
280 write_category_end(nod->
depth(), to_return);
285 void marks_maker::inject_javascript_function(
astring &output)
287 FUNCDEF(
"inject_javascript_function");
289 <script language=\"javascript1.2\">\n\
291 function open_mark(url) {\n\
292 if (typeof open_mark.next_num == 'undefined') {\n\
293 // must initialize this before use.\n\
294 open_mark.next_num = 0;\n\
296 // pick the next number for our auto-generated name.\n\
297 open_mark.next_num++;\n\
298 winname = \"wingo\" + open_mark.next_num;\n\
299 // open URL they asked for and give its window all permissions.\n\
300 winner = window.open(url, winname);\n\
301 // bring that new window into focus so they can see it.\n\
308 bool found_it = output.
replace(
"$INSERT_JAVASCRIPT_HERE", scrip);
311 "the insertion point for '$INSERT_JAVASCRIPT_HERE'");
314 int marks_maker::write_marks_page(
const astring &output_filename,
315 const astring &template_filename, output_style style)
324 increase_nesting(long_string);
326 long_string += recurse_on_node(top);
327 decrease_nesting(long_string);
329 byte_filer template_file(template_filename,
"r");
331 if (!template_file.good())
334 template_file.close();
337 inject_javascript_function(full_template);
340 bool found_it = full_template.
replace(
"$INSERT_LINKS_HERE", long_string);
343 "the insertion point for '$INSERT_LINKS_HERE'");
345 full_template.
replace(
"$TODAYS_DATE", time_stamp::notarize(
true));
349 if (!output_file.good())
352 output_file.write(full_template);
360 BASE_LOG(c_categories.access_root().text_form());
364 c_categories.link_count(), c_categories.category_count()));
370 int marks_maker::execute()
380 if (!cmds.get_value(
'i', input_filename,
false))
382 if (!cmds.get_value(
'o', output_filename,
false))
384 if (!cmds.get_value(
't', template_filename,
false))
386 cmds.get_value(
's', style_used,
false);
387 if (!style_used) style_used =
"human";
395 if (outname.exists()) {
397 + output_filename +
" already exists. It would be over-written if "
401 output_style styley = ST_HUMAN_READABLE;
402 if (style_used ==
astring(
"mozilla")) styley = ST_MOZILLA_MARKS;
404 int ret = c_categories.read_csv_file(input_filename);
407 ret = write_marks_page(output_filename, template_filename, styley);
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 length() const
Returns the current length of the string.
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.
const basis::astring & name() const
returns the name of this node.
symbol_tree * branch(int index) const
returns the "index"th branch.
virtual int depth() const
Returns the distance of "this" from the root. The root's depth is 0.
virtual int branches() const
Returns the number of branches currently connected to this tree.
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 formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
#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.
const int MAX_DESCRIP_DISPLAYED
const int MAX_URL_DISPLAYED
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.
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.