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("content-type: text/html\n\n");
83 // send the preliminary gunk.
84 printf("<body text=\"#00ee00\" bgcolor=\"#000000\" link=\"#66ff99\" "
85 "vlink=\"#cc33cc\" alink=\"#ff9900\">\n");
86 //old text color #33ccff
87 printf("<tt style=\"font-weight: bold;\">\n");
88 printf("<font size=\"+1\">\n");
90 astring to_show = some_fortunes.pick_random();
92 for (int i = 0; i < to_show.length(); i++) {
93 if (to_show[i] == ' ') {
94 // spaces get translated to one non-breaking space.
97 } else if (to_show[i] == '\t') {
98 // tabs get translated to positioning at tab stops based on eight.
99 int to_add = 8 - line_posn % 8;
100 for (int j = 0; j < to_add; j++) printf(" ");
102 } else if (to_show[i] == '\r')
104 else if (to_show[i] == '\n') {
105 printf("<br>%c", to_show[i]);
108 printf("%c", to_show[i]);
120 #ifdef __BUILD_STATIC_APPLICATION__
121 // static dependencies found by buildor_gen_deps.sh:
122 #include <application/application_shell.cpp>
123 #include <basis/astring.cpp>
124 #include <basis/common_outcomes.cpp>
125 #include <basis/environment.cpp>
126 #include <basis/mutex.cpp>
127 #include <basis/utf_conversion.cpp>
128 #include <configuration/application_configuration.cpp>
129 #include <configuration/configurator.cpp>
130 #include <configuration/ini_configurator.cpp>
131 #include <configuration/ini_parser.cpp>
132 #include <configuration/table_configurator.cpp>
133 #include <configuration/variable_tokenizer.cpp>
134 #include <filesystem/byte_filer.cpp>
135 #include <filesystem/directory.cpp>
136 #include <filesystem/filename.cpp>
137 #include <filesystem/file_time.cpp>
138 #include <loggers/combo_logger.cpp>
139 #include <loggers/console_logger.cpp>
140 #include <loggers/critical_events.cpp>
141 #include <loggers/file_logger.cpp>
142 #include <loggers/program_wide_logger.cpp>
143 #include <structures/bit_vector.cpp>
144 #include <structures/checksums.cpp>
145 #include <structures/object_packers.cpp>
146 #include <structures/static_memory_gremlin.cpp>
147 #include <structures/string_hasher.cpp>
148 #include <structures/string_table.cpp>
149 #include <structures/version_record.cpp>
150 #include <textual/byte_formatter.cpp>
151 #include <textual/parser_bits.cpp>
152 #include <textual/string_manipulation.cpp>
153 #include <timely/earth_time.cpp>
154 #include <timely/time_stamp.cpp>
155 #endif // __BUILD_STATIC_APPLICATION__