1 /*****************************************************************************\
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 1997-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
15 //! @file cgi_nechung.cpp Spits out a CGI appropriate chunk of text with a fortune in it.
17 #include "nechung_oracle.h"
19 #include <basis/astring.h>
20 #include <basis/environment.h>
21 #include <basis/guards.h>
22 #include <filesystem/filename.h>
23 #include <loggers/console_logger.h>
24 #include <loggers/critical_events.h>
25 #include <loggers/program_wide_logger.h>
29 //using namespace application;
30 using namespace basis;
31 using namespace filesystem;
32 using namespace loggers;
35 #define LOG(s) program_wide_logger::get().log(s, 0)
37 ////HOOPLE_STARTUP_CODE;
38 //hmmm: need this back when things are ready!
40 #define DEFAULT_FORTUNE_FILE "fortunes.dat"
42 int main(int argc, char *argv[])
49 // use the first command line argument.
52 // if nothing on the command line, then use our defaults.
53 name = environment::get("NECHUNG");
54 // first try the environment variable.
55 if (!name) name = DEFAULT_FORTUNE_FILE;
56 // next, use the hardwired default.
59 if (name.length() < 5) {
60 LOG(astring("nechung:: file name is too short (") + name + ").");
63 filename index_file_name(name);
64 astring extension(index_file_name.extension());
65 int end = index_file_name.raw().end();
67 LOG(astring("fortune filename is ") + name);
68 LOG(astring("extension is ") + extension);
70 astring tmp = index_file_name;
71 tmp.zap( (end + 1) - extension.length(), end);
73 astring base_part = filename(tmp).basename();
74 index_file_name = environment::TMP() + "/" + base_part;
76 LOG(astring("index file is ") + index_file_name);
78 index = index_file_name;
80 nechung_oracle some_fortunes(name, index);
81 // send the header for html text.
82 printf("<!DOCTYPE html>\n");
84 // send the preliminary gunk.
85 printf("<body text=\"#00ee00\" bgcolor=\"#000000\" link=\"#66ff99\" "
86 "vlink=\"#cc33cc\" alink=\"#ff9900\">\n");
87 //old text color #33ccff
88 printf("<tt style=\"font-weight: bold;\">\n");
89 printf("<font size=\"+1\">\n");
91 astring to_show = some_fortunes.pick_random();
93 for (int i = 0; i < to_show.length(); i++) {
94 if (to_show[i] == ' ') {
95 // spaces get translated to one non-breaking space.
98 } else if (to_show[i] == '\t') {
99 // tabs get translated to positioning at tab stops based on eight.
100 int to_add = 8 - line_posn % 8;
101 for (int j = 0; j < to_add; j++) printf(" ");
103 } else if (to_show[i] == '\r')
105 else if (to_show[i] == '\n') {
106 printf("<br>%c", to_show[i]);
109 printf("%c", to_show[i]);
121 #ifdef __BUILD_STATIC_APPLICATION__
122 // static dependencies found by buildor_gen_deps.sh:
123 #include <application/application_shell.cpp>
124 #include <basis/astring.cpp>
125 #include <basis/common_outcomes.cpp>
126 #include <basis/environment.cpp>
127 #include <basis/mutex.cpp>
128 #include <basis/utf_conversion.cpp>
129 #include <configuration/application_configuration.cpp>
130 #include <configuration/configurator.cpp>
131 #include <configuration/ini_configurator.cpp>
132 #include <configuration/ini_parser.cpp>
133 #include <configuration/table_configurator.cpp>
134 #include <configuration/variable_tokenizer.cpp>
135 #include <filesystem/byte_filer.cpp>
136 #include <filesystem/directory.cpp>
137 #include <filesystem/filename.cpp>
138 #include <filesystem/file_time.cpp>
139 #include <loggers/combo_logger.cpp>
140 #include <loggers/console_logger.cpp>
141 #include <loggers/critical_events.cpp>
142 #include <loggers/file_logger.cpp>
143 #include <loggers/program_wide_logger.cpp>
144 #include <structures/bit_vector.cpp>
145 #include <structures/checksums.cpp>
146 #include <structures/object_packers.cpp>
147 #include <structures/static_memory_gremlin.cpp>
148 #include <structures/string_hasher.cpp>
149 #include <structures/string_table.cpp>
150 #include <structures/version_record.cpp>
151 #include <textual/byte_formatter.cpp>
152 #include <textual/parser_bits.cpp>
153 #include <textual/string_manipulation.cpp>
154 #include <timely/earth_time.cpp>
155 #include <timely/time_stamp.cpp>
156 #endif // __BUILD_STATIC_APPLICATION__