Merge branch 'release-2.140.101'
[feisty_meow.git] / nucleus / applications / nechung / nechung.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : nechung console application                                       *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *******************************************************************************
7 * Copyright (c) 1991-$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 *****************************************************************************/
14
15 //! @file nechung.cpp The application base for the Nechung Oracle Program (NOP).
16
17 #include "nechung_oracle.h"
18
19 #include <basis/astring.h>
20 #include <basis/guards.h>
21 #include <basis/environment.h>
22 #include <filesystem/filename.h>
23 #include <loggers/console_logger.h>
24 #include <loggers/program_wide_logger.h>
25
26 //using namespace application;
27 using namespace basis;
28 using namespace filesystem;
29 using namespace loggers;
30
31 ///HOOPLE_STARTUP_CODE;
32 //hmmm: missing.
33
34 #undef LOG
35 #define LOG(s) program_wide_logger::get().log((s), 0)
36 //hmmm: need ALWAYS_PRINT back in there!
37
38 #define DEFAULT_FORTUNE_FILE "fortunes.dat"
39
40 int main(int argc, char *argv[])
41 {
42   SETUP_CONSOLE_LOGGER;
43
44   astring name;
45   astring index;
46   if (argc > 1) {
47     // use the first command line argument.
48     name = argv[1];
49   } else {
50     // if nothing on the command line, then use our defaults.
51     name = environment::get("NECHUNG");
52       // first try the environment variable.
53     if (!name) name = DEFAULT_FORTUNE_FILE;
54       // next, use the hardwired default.
55   }
56
57   if (name.length() < 5) {
58     LOG(astring("nechung:: file name is too short (") + name + ").");
59     return 1;
60   }
61   filename index_file_name(name);
62   astring extension(index_file_name.extension());
63   int end = index_file_name.raw().end();
64 #ifdef DEBUG_NECHUNG
65   LOG(astring("fortune filename is ") + name);
66   LOG(astring("extension is ") + extension);
67 #endif
68   astring tmp = index_file_name;
69   tmp.zap( (end + 1) - extension.length(), end);
70   tmp += "idx";
71   astring base_part = filename(tmp).basename();
72   index_file_name = environment::TMP() + "/" + base_part;
73 #ifdef DEBUG_NECHUNG
74   LOG(astring("index file is ") + index_file_name);
75 #endif
76   index = index_file_name;
77
78   nechung_oracle some_fortunes(name, index);
79   some_fortunes.display_random();
80   return 0;
81 }
82
83 #ifdef __BUILD_STATIC_APPLICATION__
84   // static dependencies found by buildor_gen_deps.sh:
85   #include <application/application_shell.cpp>
86   #include <basis/astring.cpp>
87   #include <basis/common_outcomes.cpp>
88   #include <basis/environment.cpp>
89   #include <basis/mutex.cpp>
90   #include <basis/utf_conversion.cpp>
91   #include <configuration/application_configuration.cpp>
92   #include <configuration/configurator.cpp>
93   #include <configuration/ini_configurator.cpp>
94   #include <configuration/ini_parser.cpp>
95   #include <configuration/table_configurator.cpp>
96   #include <configuration/variable_tokenizer.cpp>
97   #include <filesystem/byte_filer.cpp>
98   #include <filesystem/directory.cpp>
99   #include <filesystem/filename.cpp>
100   #include <filesystem/file_time.cpp>
101   #include <loggers/combo_logger.cpp>
102   #include <loggers/console_logger.cpp>
103   #include <loggers/critical_events.cpp>
104   #include <loggers/file_logger.cpp>
105   #include <loggers/program_wide_logger.cpp>
106   #include <structures/bit_vector.cpp>
107   #include <structures/checksums.cpp>
108   #include <structures/object_packers.cpp>
109   #include <structures/static_memory_gremlin.cpp>
110   #include <structures/string_hasher.cpp>
111   #include <structures/string_table.cpp>
112   #include <structures/version_record.cpp>
113   #include <textual/byte_formatter.cpp>
114   #include <textual/parser_bits.cpp>
115   #include <textual/string_manipulation.cpp>
116   #include <timely/earth_time.cpp>
117   #include <timely/time_stamp.cpp>
118 #endif // __BUILD_STATIC_APPLICATION__
119