00001 /*****************************************************************************\ 00002 * * 00003 * Name : nechung console application * 00004 * Author : Chris Koeritz * 00005 * * 00006 ******************************************************************************* 00007 * Copyright (c) 1991-$now By Author. This program is free software; you can * 00008 * redistribute it and/or modify it under the terms of the GNU General Public * 00009 * License as published by the Free Software Foundation; either version 2 of * 00010 * the License or (at your option) any later version. This is online at: * 00011 * http://www.fsf.org/copyleft/gpl.html * 00012 * Please send any updates to: fred@gruntose.com * 00013 *****************************************************************************/ 00014 00016 00017 #include "nechung_oracle.h" 00018 00019 #include <basis/guards.h> 00020 #include <basis/istring.h> 00021 #include <loggers/console_logger.h> 00022 #include <opsystem/filename.h> 00023 #include <data_struct/static_memory_gremlin.h> 00024 00025 HOOPLE_STARTUP_CODE; 00026 00027 #undef LOG 00028 #define LOG(s) program_wide_logger().log(s) 00029 00030 #define DEFAULT_FORTUNE_FILE "fortunes.dat" 00031 00032 int main(int argc, char *argv[]) 00033 { 00034 SET_DEFAULT_CONSOLE_LOGGER; 00035 istring name; 00036 istring index; 00037 if (argc > 1) { 00038 // use the first command line argument. 00039 name = argv[1]; 00040 } else { 00041 // if nothing on the command line, then use our defaults. 00042 name = portable::env_string("NECHUNG"); 00043 // first try the environment variable. 00044 if (!name) name = DEFAULT_FORTUNE_FILE; 00045 // next, use the hardwired default. 00046 } 00047 00048 if (name.length() < 5) { 00049 LOG(istring("nechung:: file name is too short (") + name + ")."); 00050 return 1; 00051 } 00052 filename index_file_name(name); 00053 istring extension(index_file_name.extension()); 00054 int end = index_file_name.raw().end(); 00055 #ifdef DEBUG_NECHUNG 00056 LOG(istring("fortune filename is ") + name); 00057 LOG(istring("extension is ") + extension); 00058 #endif 00059 istring tmp = index_file_name; 00060 tmp.zap( (end + 1) - extension.length(), end); 00061 tmp += "idx"; 00062 istring base_part = filename(tmp).basename(); 00063 index_file_name = portable::env_string("TMP") + "/" + base_part; 00064 #ifdef DEBUG_NECHUNG 00065 LOG(istring("index file is ") + index_file_name); 00066 #endif 00067 index = index_file_name; 00068 00069 nechung_oracle some_fortunes(name, index); 00070 some_fortunes.display_random(); 00071 return 0; 00072 } 00073 00074 #ifdef __BUILD_STATIC_APPLICATION__ 00075 // static dependencies found by buildor_gen_deps.sh: 00076 #include <basis/array.cpp> 00077 #include <basis/byte_array.cpp> 00078 #include <basis/callstack_tracker.cpp> 00079 #include <basis/chaos.cpp> 00080 #include <basis/convert_utf.cpp> 00081 #include <basis/definitions.cpp> 00082 #include <basis/earth_time.cpp> 00083 #include <basis/guards.cpp> 00084 #include <basis/istring.cpp> 00085 #include <basis/log_base.cpp> 00086 #include <basis/memory_checker.cpp> 00087 #include <basis/mutex.cpp> 00088 #include <basis/object_base.cpp> 00089 #include <basis/outcome.cpp> 00090 #include <basis/packable.cpp> 00091 #include <basis/portable.cpp> 00092 #include <basis/sequence.cpp> 00093 #include <basis/set.cpp> 00094 #include <basis/utility.cpp> 00095 #include <basis/version_record.cpp> 00096 #include <data_struct/amorph.cpp> 00097 #include <data_struct/bit_vector.cpp> 00098 #include <data_struct/byte_hasher.cpp> 00099 #include <data_struct/configurator.cpp> 00100 #include <data_struct/hash_table.cpp> 00101 #include <data_struct/pointer_hash.cpp> 00102 #include <data_struct/stack.cpp> 00103 #include <data_struct/static_memory_gremlin.cpp> 00104 #include <data_struct/string_hash.cpp> 00105 #include <data_struct/string_hasher.cpp> 00106 #include <data_struct/string_table.cpp> 00107 #include <data_struct/symbol_table.cpp> 00108 #include <data_struct/table_configurator.cpp> 00109 #include <loggers/console_logger.cpp> 00110 #include <loggers/file_logger.cpp> 00111 #include <loggers/locked_logger.cpp> 00112 #include <loggers/null_logger.cpp> 00113 #include <loggers/program_wide_logger.cpp> 00114 #include <opsystem/byte_filer.cpp> 00115 #include <opsystem/command_line.cpp> 00116 #include <opsystem/critical_events.cpp> 00117 #include <opsystem/directory.cpp> 00118 #include <opsystem/filename.cpp> 00119 #include <opsystem/filetime.cpp> 00120 #include <opsystem/ini_config.cpp> 00121 #include <opsystem/ini_parser.cpp> 00122 #include <opsystem/path_configuration.cpp> 00123 #include <opsystem/rendezvous.cpp> 00124 #include <textual/byte_format.cpp> 00125 #include <textual/parser_bits.cpp> 00126 #include <textual/string_manipulation.cpp> 00127 #include <textual/tokenizer.cpp> 00128 #endif // __BUILD_STATIC_APPLICATION__ 00129
1.5.1