46 const char __egs_fs = 92;
48 const char __egs_fs =
'/';
60 EGS_I64 i2 = n % 1000000000;
61 data <<
" " << (int) i1 <<
" " << (
int) i2;
71 if (data.eof() || !data.good()) {
80 static FILE *egs_info_fp = stdout;
81 static FILE *egs_warning_fp = stderr;
82 static FILE *egs_error_fp = stderr;
84 static EGS_LOCAL
char __egsf_write_buf[8192];
86 static void EGS_LOCAL __egs_default_information(
const char *msg, ...) {
91 vsprintf(__egsf_write_buf,msg,ap);
95 vfprintf(egs_info_fp, msg, ap);
101 static void EGS_LOCAL __egs_default_warning(
const char *msg, ...) {
106 vsprintf(__egsf_write_buf,msg,ap);
111 vfprintf(egs_warning_fp, msg, ap);
112 fflush(egs_warning_fp);
117 static void EGS_LOCAL __egs_default_error(
const char *msg, ...) {
122 vsprintf(__egsf_write_buf,msg,ap);
127 vfprintf(egs_error_fp, msg, ap);
140 egsWarning(
"egsSetInfoFunction: info function can not be NULL!\n");
147 egsInformation = func;
165 egsInformation = __egs_default_information;
166 egsWarning = __egs_default_warning;
167 egsFatal = __egs_default_error;
170 template <
class T>
void __egs_swap_bytes(T *v) {
171 char *c = (
char *) v;
181 __egs_swap_bytes<int>(n);
184 __egs_swap_bytes<float>(n);
188 char *c = (
char *) n;
195 int n = first.size()-1;
197 string result(first);
198 if (c ==
'/' && c != __egs_fs) {
199 result[n] = __egs_fs;
201 if (result[n] != __egs_fs) {
222 while (i < c.size()) {
223 p1= str.find_first_of(c[i++]);
224 if (p1 != str.npos) {
230 size_t p2 = str.npos;
231 while (p1 != str.npos && i < fs.size()) {
232 p2 = str.find_first_of(fs[i++],p1+1);
233 if (p2 != str.npos) {
238 if (p1 != str.npos && p2 != str.npos) {
239 string envvar = str.substr(p1+1, p2-(p1+1));
240 char *envval = getenv(envvar.c_str());
242 string envloc = envval ? string(envval) : string();
243 if (!envloc.empty()) {
245 size_t last = envloc.find_last_of(
"/\\");
246 if (last != envloc.size()-1) {
247 if (envloc[last] == __egs_fs) {
254 str.replace(p1, p2-p1+1,envloc);
257 if (str[p1] ==
'$') {
258 egsWarning(
"\n\n *** egs++ egsExpandPath: Undefined environment variable $%s \n\n", envvar.c_str());
261 egsWarning(
"\n\n *** egs++ egsExpandPath: Undefined environment variable %%%s%% \n\n", envvar.c_str());
266 size_t found = str.find(
"\\");
267 while (found != str.npos) {
268 str.replace(found,1,
"/");
269 found = str.find(
"\\");
272 found = str.find(
"//");
273 while (found != str.npos) {
274 str.replace(found,2,
"/");
275 found = str.find(
"//");
283 for (j=aname.size()-1; j>=0; j--) {
284 if (aname[j] ==
'/' || aname[j] == __egs_fs) {
294 while (j < aname.size()) {
295 result += aname[j++];
304 #include <sys/types.h>
314 char *var = getenv(
"COMPUTERNAME");
316 var = getenv(
"HOSTNAME");
318 var = getenv(
"HOST");
327 int err = gethostname(buf,1023);
344 if (key.size() < 2) {
348 for (js=0; js<key.size(); js++)
if (key[js] ==
'$') {
351 if (js >= key.size()) {
355 for (je=key.size()-1; je>=0; je--)
if (key[je] ==
'$') {
362 for (
int j=js+1; j<je; j++) {
370 unsigned char *p = (
unsigned char *)(&nl);
371 if (p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78) {
374 if (p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12) {
382 if (path.size() < 2) {
385 if ((path[0] ==
'/' || path[0] == __egs_fs) &&
386 (path[1] ==
'/' || path[1] == __egs_fs)) {
389 if (path.size() < 3) {
392 if (!isalpha(path[0])) {
395 if (path[1] !=
':') {
398 if (path[2] !=
'/' && path[2] != __egs_fs) {
403 return (path[0] ==
'/');
407 bool egsEquivStr(
const string &a,
const string &b) {
408 unsigned int sz = a.size();
409 if (b.size() != sz) {
412 for (
unsigned int i = 0; i < sz; ++i)
413 if (tolower(a[i]) != tolower(b[i])) {
#define EGS_EXPORT
Export symbols from the egspp library.
string egsStripPath(const string &aname)
Strip the path from a file name and return the result.
bool EGS_EXPORT egsGetI64(istream &data, EGS_I64 &n)
Reads a 64 bit integer from the stream data and assigns it to n. Returns true on success, false on failure.
int egsGetPid()
Get the process id.
bool egsIsAbsolutePath(const string &path)
Does the string path represent an absolute path name?
bool EGS_EXPORT egsStoreI64(ostream &data, EGS_I64 n)
Writes the 64 bit integer n to the output stream data and returns true on success, false on failure.
string egsJoinPath(const string &first, const string &second)
Join two path variables (or a path and a file name) using the platform specific directory separator a...
EGS_InfoFunction egsSetInfoFunction(EGS_InfoType t, EGS_InfoFunction func)
Set a function to be used for outputing information, warning messages or reporting fatal errors...
void egsSetDefaultIOFunctions()
Reset I/O functions to their defaults.
Global egspp functions header file.
virtual void appInformation(const char *)
Write an information message.
void egsSwapBytes(int *n)
Swap the bytes of 32 bit integers.
virtual void appFatal(const char *)
Write a warning message and exit.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
string egsExpandPath(const string &aname)
Expands first environment variable found in a file name.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
int egsGetEndian()
Get the endianess of the machine.
static EGS_Application * activeApplication()
Get the active application.
string egsSimplifyCVSKey(const string &key)
Remove the $'s from a CVS key.
virtual void appWarning(const char *)
Write a warning message.
void(* EGS_InfoFunction)(const char *,...)
Defines a function printf-like prototype for functions to be used to report info, warnings...
EGS_Application class header file.
Base class for advanced EGSnrc C++ applications.
string egsHostName()
Get the name of the host the program is running on.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.