COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/Dbg.cpp
Go to the documentation of this file.
00001 
00002 #include <coopy/Dbg.h>
00003 
00004 #include <string>
00005 using namespace std;
00006 
00007 bool _csv_verbose = false;
00008 bool _csv_strict = false;
00009 
00010 string coopy_default_table_name = "sheet";
00011 string coopy_default_eol_style = "default";
00012 string coopy_eol_store = "\n";
00013 
00014 #ifdef __linux__
00015 #ifdef __GNUC__
00016 #ifndef __llvm__
00017 #define USE_TRACE
00018 #endif
00019 #endif
00020 #endif
00021 
00022 #ifdef USE_TRACE
00023 #include <execinfo.h>
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 void coopy_print_trace(FILE *out, const char *file, int line) {
00027     const size_t max_depth = 100;
00028     size_t stack_depth;
00029     void *stack_addrs[max_depth];
00030     char **stack_strings;
00031     stack_depth = backtrace(stack_addrs, max_depth);
00032     stack_strings = backtrace_symbols(stack_addrs, stack_depth);
00033     fprintf(out, "Assertion thrown at %s:%d by code called from:\n", file, line);
00034     for (size_t i = 1; i < stack_depth; i++) {
00035         fprintf(out, " --> %s\n", stack_strings[i]);
00036     }
00037     free(stack_strings); // malloc()ed by backtrace_symbols
00038     fflush(out);
00039 }
00040 #else
00041 void coopy_print_trace(FILE *out, const char *file, int line) {
00042     fprintf(out, "Assertion thrown at %s:%d, cannot trace on this platform\n", file, line);
00043 }
00044 #endif
00045 
00046 void coopy_set_verbose(bool verbose) {
00047   _csv_verbose = verbose;
00048 }
00049 
00050 bool coopy_is_verbose() {
00051   return _csv_verbose;
00052 }
00053 
00054 void coopy_set_strict(bool strict) {
00055   _csv_strict = strict;
00056 }
00057 
00058 bool coopy_is_strict() {
00059   return _csv_strict;
00060 }
00061 
00062 void coopy_set_default_table_name(const char *name) {
00063   coopy_default_table_name = name;
00064   coopy_eol_store = "\n";
00065   if (coopy_default_table_name=="CRLF") {
00066     coopy_eol_store = "\r\n";
00067   } else {
00068     coopy_eol_store = "\n";
00069   }
00070 }
00071 
00072 const char *coopy_get_default_table_name() {
00073   return coopy_default_table_name.c_str();
00074 }
00075 
00076 
00077 void coopy_set_default_eol_style(const char *name) {
00078   coopy_default_eol_style = name;
00079 }
00080 
00081 const char *coopy_get_default_eol_style() {
00082   return coopy_default_eol_style.c_str();
00083 }
00084 
00085 const char *coopy_eol() {
00086   return coopy_eol_store.c_str();
00087 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines