any files ending in ".sh" or ".pl" and it will create aliases for them
in forms appropriate to the different shells. The .zz_auto_gen
subdirectory
-is created under the home directory (or under TMP in DOS and Win32) as
+is created under the home directory as
a storage place for the generated
files.</blockquote>
<h4> </h4>
astring target;
cmds.get_value("target", target);
if (!target) {
-/* no, this is wrong headed. make them supply a target if there is
- * no default target provided in the bundle.
- // a bogus default is provided if they don't specify the destination.
- target = environment::get("TMP") + "/unbundled";
-*/
provided_target = false;
} else {
//LOG(astring("target is now ") + target);
astring logdir = environment::get(LOGDIR_WORD);
#ifdef __WIN32__
if (!logdir) {
- logdir = environment::get("TMP") + "/logs";
+ logdir = environment::TMP() + "/logs";
environment::set(LOGDIR_WORD, logdir);
}
#else
tmp.zap( (end + 1) - extension.length(), end);
tmp += "idx";
astring base_part = filename(tmp).basename();
- index_file_name = environment::get("TMP") + "/" + base_part;
+ index_file_name = environment::TMP() + "/" + base_part;
#ifdef DEBUG_NECHUNG
LOG(astring("index file is ") + index_file_name);
#endif
tmp.zap( (end + 1) - extension.length(), end);
tmp += "idx";
astring base_part = filename(tmp).basename();
- index_file_name = environment::get("TMP") + "/" + base_part;
+ index_file_name = environment::TMP() + "/" + base_part;
#ifdef DEBUG_NECHUNG
LOG(astring("index file is ") + index_file_name);
#endif
}
#endif
-// used as a return value when the name cannot be determined.
-#ifndef EMBEDDED_BUILD
- #define SET_BOGUS_NAME(error) { \
- COMPLAIN(error); \
- if (output) { \
- fclose(output); \
- unlink(tmpfile.s()); \
- } \
- istring home_dir = env_string("HOME"); \
- to_return = home_dir + "/failed_to_determine.exe"; \
- }
-#else
- #define SET_BOGUS_NAME(error) { \
- COMPLAIN(error); \
- to_return = "unknown"; \
- }
-#endif
-
-istring application_name()
-{
- FUNCDEF("application_name");
- istring to_return;
-#ifdef __UNIX__
- to_return = get_cmdline_from_proc();
-#elif defined(__WIN32__)
- flexichar low_buff[MAX_ABS_PATH + 1];
- GetModuleFileName(NIL, low_buff, MAX_ABS_PATH - 1);
- istring buff = from_unicode_temp(low_buff);
- buff.to_lower(); // we lower-case the name since windows seems to UC it.
- to_return = buff;
-#elif defined(EMBEDDED_BUILD)
- SET_BOGUS_NAME("embedded_exe");
-#else
- #pragma error("hmmm: no means of finding app name is implemented.")
- SET_BOGUS_NAME("not_implemented_for_this_OS");
-#endif
- return to_return;
-}
-
istring module_name(const void *module_handle)
{
#ifdef __UNIX__
return to_return;
}
-istring env_string(const istring &variable_name)
-{
-#ifdef __WIN32__
- char *value = getenv(variable_name.upper().observe());
- // dos & os/2 require upper case for the name, so we just do it that way.
-#else
- char *value = getenv(variable_name.observe());
- // reasonable OSes support mixed-case environment variables.
-#endif
- istring to_return;
- if (value)
- to_return = istring(value);
- return to_return;
-}
-
-bool set_environ(const istring &variable_name, const istring &value)
-{
- int ret = 0;
-#ifdef __WIN32__
- ret = putenv((variable_name + "=" + value).s());
-#else
- ret = setenv(variable_name.s(), value.s(), true);
-#endif
- return !ret;
-}
-
timeval fill_timeval_ms(int duration)
{
timeval time_out; // timeval has tv_sec=seconds, tv_usec=microseconds.
namespace basis {
+astring environment::TMP()
+{
+ const static astring TMP_VARIABLE_NAME("TMP");
+ astring to_return = get(TMP_VARIABLE_NAME);
+ if (!to_return) {
+ // they did not see fit to set this in the environment. let's make something up.
+#ifdef __WIN32__
+ // windows default does not necessarily exist.
+ to_return = "c:/tmp";
+#else
+ // most reasonable OSes have a /tmp directory.
+ to_return = "/tmp";
+#endif
+ }
+ return to_return;
+}
+
astring environment::get(const astring &variable_name)
{
#ifdef __WIN32__
class environment : public virtual root_object
{
public:
+ static astring TMP();
+ //!< provides a single place to get the temporary directory.
+ /*!< this will locate the value of the TMP variable and return it. if the TMP
+ variable is not currently defined, this will try to do something reasonable for
+ a default value. */
+
static astring get(const astring &variable_name);
//!< looks up the "variable_name" in the current environment variables.
/*!< this returns the value for "variable_name" as it was found in the
in time for the user and process. the returned string will be empty if no
variable under that name could be found. */
-// static astring get(const char *variable_name) { return get(astring(variable_name)); }
- //!< synonym using simpler char pointer.
-
static bool set(const astring &variable_name, const astring &value);
//!< adds or creates "variable_name" in the environment.
/*!< changes the current set of environment variables by adding or
modifying the "variable_name". its new value will be "value". */
-// static bool set(const char *variable_name, const char *value)
-// { return set(astring(variable_name), astring(value)); }
- //!< synonym using simpler char pointers.
-
static basis::un_int system_uptime();
//!< gives the operating system's uptime in a small form that rolls over.
};
printf("no dir part found, app name after chewing: %s\n", __check_once_app_path.s());
// there was no directory component, so we'll try to guess one.
- astring temp_filename(environment::get("TMP")
+ astring temp_filename(environment::TMP()
+ a_sprintf("/zz_cmdfind.%d", chaos().inclusive(0, 999999999)));
system((astring("which ") + __check_once_app_path + " >" + temp_filename).s());
FILE *which_file = fopen(temp_filename.s(), "r");
fclose(output); \
unlink(tmpfile.s()); \
} \
- astring home_dir = env_string("HOME"); \
+ astring home_dir = environment::get("HOME"); \
to_return = home_dir + "/failed_to_determine.exe"; \
}
const char *TEST_FILE_SUFFIX = ".txt";
static astring __hidden_filename;
if (!__hidden_filename) {
- __hidden_filename = environment::get("TMP");
+ __hidden_filename = environment::TMP();
if (!__hidden_filename) __hidden_filename = "/tmp";
// try to create it just in case it wasn't there already.
directory::make_directory(__hidden_filename);
files.zap(0, 0); // toss the first element since that's our app filename.
if (!files.length()) {
- // pretend they gave us the list of files in the TMP directory. some of
+ // pretend they gave us the list of files in the current directory. some of
// these might fail if they're locked up.
-// astring tmpdir = environment::get("TMP");
astring tmpdir = application_configuration::current_directory();
directory dir(tmpdir);
for (int i = 0; i < dir.files().length(); i++) {
files.zap(0, 0); // toss the first element since that's our app filename.
if (!files.length()) {
- // pretend they gave us the list of files in the TMP directory. some of
+ // pretend they gave us the list of files in the current directory. some of
// these might fail if they're locked up.
-// astring tmpdir = environment::get("TMP");
astring tmpdir = application_configuration::current_directory();
directory dir(tmpdir);
for (int i = 0; i < dir.files().length(); i++) {
bool version_checker::good_version() const
{
- astring version_disabler = environment::get("TMP");
+ astring version_disabler = environment::TMP();
version_disabler += "/no_version_check.txt";
FILE *always_okay = fopen(version_disabler.s(), "r");
if (always_okay) {
#include "cromp_transaction.h"
+#include <basis/environment.h>
#include <basis/mutex.h>
+#include <loggers/critical_events.h>
#include <loggers/file_logger.h>
+#include <loggers/program_wide_logger.h>
#include <octopus/entity_defs.h>
#include <octopus/infoton.h>
#include <sockets/tcpip_stack.h>
namespace cromp {
-//#define DEBUG_CROMP_TRANSACTION
+#define DEBUG_CROMP_TRANSACTION
// uncomment for noisy version.
const int MAXIMUM_TRANSACTION = 100 * MEGABYTE;
// since the transaction stuff is so low-level, we risk a feedback loop if
// we log stuff when the program wide logger is itself a communication
// object.
- #define LOG(s) CLASS_EMERGENCY_LOG(file_logger(portable::env_string("TMP") + "/cromp_transaction.log"), s)
+ #define LOG(s) CLASS_EMERGENCY_LOG(file_logger(environment::TMP() + "/cromp_transaction.log"), s)
#else
#define LOG(s)
#endif