36 #include <boost/algorithm/string/predicate.hpp> 37 #include <boost/algorithm/string/trim.hpp> 38 #include <boost/format.hpp> 69 {
Warn,
true,
false,
SCR_STDERR,
false,
"\nWarning (%s, %s(), %d):\n"},
70 {
UsrErr,
true,
false,
SCR_NONE,
true,
"\nUser Error (%s, %s(), %d):\n"},
71 {
Err,
true,
false,
SCR_NONE,
true,
"\nError (%s, %s(), %d):\n"},
72 {
PrgErr,
true,
false,
SCR_NONE,
true,
"\nInternal Error (%s, %s(), %d):\n"}
86 int _xprintf(
const char *
const xprintf_file,
const char *
const xprintf_func,
const int xprintf_line,
MessageType type,
const char *
const fmt, ... )
92 static int mpi_msg_id = 0;
107 default: screen=NULL;
114 fprintf(screen,
"[mpi_id=%d] ", sys_info.
my_proc );
115 if (mf.
log && sys_info.
log)
116 fprintf(sys_info.
log,
"[mpi_id=%d] ", sys_info.
my_proc );
119 if ( (screen) && ( sys_info.
my_proc != 0 ) )
126 char format_message[1024];
127 va_start( argptr, fmt );
128 vsprintf(format_message, fmt, argptr);
133 BOOST_THROW_EXCEPTION( ExcXprintfMsg()
134 << EI_XprintfHeader( boost::str(boost::format(mf.
head) % xprintf_file % xprintf_func % xprintf_line) )
135 << EI_XprintfMessage( format_message ) );
143 printf(
"MPI_Barrier() error in xprintf()\n");
144 exit( EXIT_FAILURE );
149 fprintf(screen,
"[msg_id=%d] ", mpi_msg_id );
150 if (mf.
log && sys_info.
log)
151 fprintf(sys_info.
log,
"[msg_id=%d] ", mpi_msg_id );
154 #ifndef FLOW123D_DEBUG_MESSAGES 155 if (type ==
Warn) mf.
head=
"\nWarning: ";
159 if (screen) fprintf(screen,mf.
head,xprintf_file,xprintf_func,xprintf_line);
160 if (mf.
log && sys_info.
log)
161 fprintf(sys_info.
log,mf.
head,xprintf_file,xprintf_func,xprintf_line);
167 if (mf.
log && sys_info.
log)
169 va_start( argptr, fmt );
170 rc=vfprintf(sys_info.
log,fmt,argptr);
173 fflush(sys_info.
log);
178 va_start( argptr, fmt );
179 rc=vfprintf(screen,fmt,argptr);
203 if (size == 0 ) size++;
205 if ( rc == NULL )
xprintf(
Err ,
"Not enough memory for allocating %u bytes\n", size );
236 rc = realloc( ptr, size );
237 if ( rc == NULL )
xprintf(
Err ,
"Not enough memory for allocating %u bytes\n", size );
273 INPUT_CHECK(!( rc != 0 ),
"Error executing external command: %s\n", cmd );
285 OLD_ASSERT(!( src == NULL ),
"NULL pointer as argument of function xstrcpy()\n");
286 length = strlen( src ) + 1;
287 rc = (
char*)
xmalloc(length *
sizeof(
char));
301 const char *
const whitespace_delim=
" \t\r\n";
303 rc =
xstrtok( s, whitespace_delim, position);
316 char *
xstrtok(
char *s1,
const char *delim,
int position )
319 static char * full_string = NULL;
320 static int token_count;
322 OLD_ASSERT(!( delim == NULL ),
"NULL pointer as delimiter in xstrtok()\n");
329 full_string[0] = 0x0;
336 INPUT_CHECK( token_count == position || position < 0,
"Requested position %d dosn't match token position %d", position, token_count);
337 rc = strtok( s1, delim );
340 INPUT_CHECK(!( rc == NULL ),
"Missing token no. %d: original string '%s' with delimiters '%s'\n", token_count, full_string, delim );
363 while ((p >= s) && ((*p ==
' ') || (*p ==
'\t') || (*p ==
'\r') || (*p ==
'\n')))
381 OLD_ASSERT(!( s == NULL ),
"NULL pointer as argument of function xmkdir()\n");
382 rc = mkdir(s, S_IRWXU);
385 INPUT_CHECK(!( rc != 0 ),
"Cannot make directory %s\n", s );
397 OLD_ASSERT(!( s == NULL ),
"NULL pointer as argument of function xrmdir()\n");
399 INPUT_CHECK(!( rc != 0 ),
"Cannot delete directory %s\n", s );
410 OLD_ASSERT(!( s == NULL ),
"NULL pointer as argument of function xchdir()\n");
412 INPUT_CHECK(!( rc != 0 ),
"Cannot change directory to %s\n", s );
423 OLD_ASSERT(!( fname == NULL ),
"NULL pointer as argument of function xremove()\n");
424 if( access( fname , F_OK ) == 0 )
426 rc =
remove( fname );
427 INPUT_CHECK(!( rc != 0 ),
"Cannot remove file %s\n", fname );
430 xprintf(
Warn,
"File '%s' does not exist, can not remove. Ignoring.\n", fname );
443 rc = getcwd( tmp, PATH_MAX );
444 OLD_ASSERT( rc,
"Cannot get name of current working directory\n");
bool log
log the message - YES/NO
int xremove(const char *fname)
DELETE a FILE with error handling.
#define INPUT_CHECK(i,...)
Debugging macros.
char * xstrcpy(const char *src)
MAKE BRAND NEW COPY OF STRING.
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
void * xrealloc(void *ptr, size_t size)
Reallocation of memory block with checking.
System structure for various global variables.
int xchomp(char *s)
Delete trailing whitespace characters (space,tab,CR,NL).
int xrmdir(const char *s)
RMDIR with err handling.
bool stop
terminate the program
int xmkdir(const char *s)
MKDIR WITH ERROR HANDLING.
int _xprintf(const char *const xprintf_file, const char *const xprintf_func, const int xprintf_line, MessageType type, const char *const fmt,...)
Multi-purpose printing routine: messages, warnings, errors.
int screen
print to stdout,stderr,NULL
void * xmalloc(size_t size)
Memory allocation with checking.
INTERNAL DEFINITIONS FOR XPRINTF.
MessageType
Identifiers for various output messages.
int xchdir(const char *s)
CHDIR WITH ERROR HANDLING.
static struct MsgFmt msg_fmt[]
char * xstrtok(char *s, int position)
STRTOK WITH ERROR HANDLING and whitespace delimiters.
const char * head
message formating string
char * xgetcwd(void)
GET CURRENT WORKING DIRECTORY with error handling.
#define MPI_Barrier(comm)
int xsystem(const char *cmd)
SYSTEM with err handling.
bool mpi
treat as global message (invoke MPI_Barrier() when printing)