47 const char __egs_fs = 92;
49 const char __egs_fs =
'/';
61 EGS_I64 i2 = n % 1000000000;
62 data <<
" " << (int) i1 <<
" " << (
int) i2;
72 if (data.eof() || !data.good()) {
81 static FILE *egs_info_fp = stdout;
82 static FILE *egs_warning_fp = stderr;
83 static FILE *egs_error_fp = stderr;
85 static EGS_LOCAL
char __egsf_write_buf[8192];
87 static void EGS_LOCAL __egs_default_information(
const char *msg, ...) {
92 vsprintf(__egsf_write_buf,msg,ap);
96 vfprintf(egs_info_fp, msg, ap);
102 static void EGS_LOCAL __egs_default_warning(
const char *msg, ...) {
107 vsprintf(__egsf_write_buf,msg,ap);
112 vfprintf(egs_warning_fp, msg, ap);
113 fflush(egs_warning_fp);
118 static void EGS_LOCAL __egs_default_error(
const char *msg, ...) {
123 vsprintf(__egsf_write_buf,msg,ap);
128 vfprintf(egs_error_fp, msg, ap);
141 egsWarning(
"egsSetInfoFunction: info function can not be NULL!\n");
171 template <
class T>
void __egs_swap_bytes(T *v) {
172 char *c = (
char *) v;
182 __egs_swap_bytes<int>(n);
185 __egs_swap_bytes<float>(n);
189 char *c = (
char *) n;
196 int n = first.size()-1;
198 string result(first);
199 if (c ==
'/' && c != __egs_fs) {
200 result[n] = __egs_fs;
202 if (result[n] != __egs_fs) {
223 while (i < c.size()) {
224 p1= str.find_first_of(c[i++]);
225 if (p1 != str.npos) {
231 size_t p2 = str.npos;
232 while (p1 != str.npos && i < fs.size()) {
233 p2 = str.find_first_of(fs[i++],p1+1);
234 if (p2 != str.npos) {
239 if (p1 != str.npos && p2 != str.npos) {
240 string envvar = str.substr(p1+1, p2-(p1+1));
241 char *envval = getenv(envvar.c_str());
243 string envloc = envval ? string(envval) : string();
244 if (!envloc.empty()) {
246 size_t last = envloc.find_last_of(
"/\\");
247 if (last != envloc.size()-1) {
248 if (envloc[last] == __egs_fs) {
255 str.replace(p1, p2-p1+1,envloc);
258 if (str[p1] ==
'$') {
259 egsWarning(
"\n\n *** egs++ egsExpandPath: Undefined environment variable $%s \n\n", envvar.c_str());
262 egsWarning(
"\n\n *** egs++ egsExpandPath: Undefined environment variable %%%s%% \n\n", envvar.c_str());
267 size_t found = str.find(
"\\");
268 while (found != str.npos) {
269 str.replace(found,1,
"/");
270 found = str.find(
"\\");
273 found = str.find(
"//");
274 while (found != str.npos) {
275 str.replace(found,2,
"/");
276 found = str.find(
"//");
284 for (j=aname.size()-1; j>=0; j--) {
285 if (aname[j] ==
'/' || aname[j] == __egs_fs) {
295 while (j < aname.size()) {
296 result += aname[j++];
305 #include <sys/types.h>
315 char *var = getenv(
"COMPUTERNAME");
317 var = getenv(
"HOSTNAME");
319 var = getenv(
"HOST");
328 int err = gethostname(buf,1023);
345 if (key.size() < 2) {
349 for (js=0; js<key.size(); js++)
if (key[js] ==
'$') {
352 if (js >= key.size()) {
356 for (je=key.size()-1; je>=0; je--)
if (key[je] ==
'$') {
363 for (
int j=js+1; j<je; j++) {
371 unsigned char *p = (
unsigned char *)(&nl);
372 if (p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78) {
375 if (p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12) {
383 if (path.size() < 2) {
386 if ((path[0] ==
'/' || path[0] == __egs_fs) &&
387 (path[1] ==
'/' || path[1] == __egs_fs)) {
390 if (path.size() < 3) {
393 if (!isalpha(path[0])) {
396 if (path[1] !=
':') {
399 if (path[2] !=
'/' && path[2] != __egs_fs) {
404 return (path[0] ==
'/');
408 bool egsEquivStr(
const string &a,
const string &b) {
409 unsigned int sz = a.size();
410 if (b.size() != sz) {
413 for (
unsigned int i = 0; i < sz; ++i)
414 if (tolower(a[i]) != tolower(b[i])) {
Base class for advanced EGSnrc C++ applications.
static EGS_Application * activeApplication()
Get the active application.
virtual void appFatal(const char *)
Write a warning message and exit.
virtual void appInformation(const char *)
Write an information message.
virtual void appWarning(const char *)
Write a warning message.
EGS_Application class header file.
Global egspp functions header file.
void(* EGS_InfoFunction)(const char *,...)
Defines a function printf-like prototype for functions to be used to report info, warnings,...
#define EGS_EXPORT
Export symbols from the egspp library.
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,...
string egsHostName()
Get the name of the host the program is running on.
int egsGetPid()
Get the process id.
int egsGetEndian()
Get the endianess of the machine.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
EGS_InfoFunction egsSetInfoFunction(EGS_InfoType t, EGS_InfoFunction func)
Set a function to be used for outputing information, warning messages or reporting fatal errors.
bool egsIsAbsolutePath(const string &path)
Does the string path represent an absolute path name?
string egsExpandPath(const string &aname)
Expands first environment variable found in a file name.
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,...
string egsSimplifyCVSKey(const string &key)
Remove the $'s from a CVS key.
void egsSetDefaultIOFunctions()
Reset I/O functions to their defaults.
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...
void egsSwapBytes(int *n)
Swap the bytes of 32 bit integers.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.
string egsStripPath(const string &aname)
Strip the path from a file name and return the result.