feisty meow concerns codebase  2.140
nechung.cpp
Go to the documentation of this file.
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 
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>
25 
26 //using namespace application;
27 using namespace basis;
28 using namespace filesystem;
29 using namespace loggers;
30 
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 {
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:
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>
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>
106  #include <structures/bit_vector.cpp>
107  #include <structures/checksums.cpp>
111  #include <structures/string_table.cpp>
113  #include <textual/byte_formatter.cpp>
114  #include <textual/parser_bits.cpp>
116  #include <timely/earth_time.cpp>
117  #include <timely/time_stamp.cpp>
118 #endif // __BUILD_STATIC_APPLICATION__
119 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
Definition: astring.cpp:521
int end() const
returns the index of the last (non-null) character in the string.
Definition: astring.h:86
int length() const
Returns the current length of the string.
Definition: astring.cpp:132
static astring TMP()
provides a single place to get the temporary directory.
Definition: environment.cpp:39
static astring get(const astring &variable_name)
looks up the "variable_name" in the current environment variables.
Definition: environment.cpp:57
Provides operations commonly needed on file names.
Definition: filename.h:64
basis::astring extension() const
returns the extension for the file, if one is present.
Definition: filename.cpp:299
const basis::astring & raw() const
returns the astring that we're holding onto for the path.
Definition: filename.cpp:97
filename basename() const
returns the base of the filename; no directory.
Definition: filename.cpp:385
#define SETUP_CONSOLE_LOGGER
< a macro that retasks the program-wide logger as a console_logger.
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37
A logger that sends to the console screen using the standard output device.
int main(int argc, char *argv[])
Definition: nechung.cpp:40
#define LOG(s)
HOOPLE_STARTUP_CODE;.
Definition: nechung.cpp:35
#define DEFAULT_FORTUNE_FILE
Definition: nechung.cpp:38