at_startup.H

Go to the documentation of this file.
00001 
00007 //
00008 // performing some sanity checks
00009 //
00010 
00011 #if defined(__GNUG__) && __GNUC__ < 3
00012  #error "Please compile again with a newer version of GCC (version >= 3.2.x, better >=3.4.x)"
00013 #endif
00014 
00015 #if #cpu (x86_64)
00016  #ifndef ASM_X86_64
00017   #warning "inline assembler for X86_64 is disabled!"
00018   #warning "you may want to optimize your makefile settings!"
00019  #else
00020   #warning "there is rudimentary inline assembler support for X86_64, but sieving is still faster using X86_32 mode..."
00021   #warning "however, server + ecm is faster for X86_64"
00022  #endif
00023 #else
00024  #ifdef ASM_X86_64
00025    #warning "please review the makefile!"
00026    #error "X86_64-inline assembler code for non-X86_64 compatible cpu/mode?"
00027  #endif
00028 #endif
00029 
00030 #if #cpu (i386)
00031  #ifndef ASM_386
00032    #warning "inline assembler for i386 is disabled!"
00033    #warning "you may want to optimize your makefile settings!"
00034  #endif
00035 
00036  #if defined(ASM_ATHLON)
00037    #ifndef ASM_CMOV
00038      #warning "using athlon-inline assembler, but ASM_CMOV not enabled!" 
00039      #warning "you may want to activate CMOV in the makefile, because ATHLON supports it!"
00040    #endif
00041  #endif
00042 #else
00043  #ifdef ASM_386
00044    #warning "please review the makefile!"
00045    #error "i386-inline assembler code for non-i386 compatible cpu?"
00046  #endif
00047 #endif
00048 
00049 #if !defined (unix) && defined(USE_NETWORK)
00050   #error "network support only for Unix-systems"
00051 #endif
00052 
00053 
00054 #include <cstring>  // for strdup and friends...
00055 #include <string>
00056 #include <iostream>
00057 #include <iomanip>
00058 #include "utils.H"
00059 
00060 using namespace std;
00061 
00062 
00063 #ifndef USE_NETWORK
00064  #ifdef IS_SERVER
00065   #error "Illegal configuration: SERVER and no USE_NETWORK"
00066  #endif
00067 #else
00068  #ifndef IS_STANDALONE
00069   #ifdef IS_SERVER
00070    #include <map>
00071   #endif
00072   #include "unix_buffer.H"
00073  #endif
00074 #endif
00075 
00076 #ifndef IS_SERVER
00077  #ifndef IS_CLIENT
00078   #undef IS_STANDALONE
00079   #define IS_STANDALONE
00080  #endif
00081 #endif
00082 
00083 #ifdef IS_SERVER
00084  #ifdef IS_CLIENT
00085   #error "Illegal Configuration SERVER-CLIENT"
00086  #else
00087   #ifdef IS_STANDALONE
00088    #error "Illegal Configuration SERVER-STANDALONE"
00089   #endif
00090  #endif
00091 #endif
00092 
00093 #ifdef IS_CLIENT
00094  #ifdef IS_STANDALONE
00095   #error "Illegal Configuration CLIENT-STANDALONE"
00096  #endif
00097 #endif
00098 
00099 #if defined(USE_FIBHEAP) && defined(USE_FAKEHEAP)
00100  #error "defines USE_FIBHEAP and USE_FAKEHEAP exclude each other!"
00101 #endif
00102 
00103 #ifdef REACT_ON_SIGUSR
00104  // a little class that catches signal SIGUSR1 and SIGUSR2
00105  // and stores these flags...
00106  // can be useful to abort some long-running algorithms
00107  // without aborting the program or altering configuration parameters.
00108  #include "usr_signals.cc"
00109  Cusr_signal_proxy USRSignalHandler;
00110 #endif
00111 
00112 
00113 // propagate IS_STANDALONE-condition from compiletime to runtime,
00114 // so that certain modules can be compiled independently of it.
00115 bool compiled_IS_STANDALONE()
00116 {
00117   #ifdef IS_STANDALONE
00118    return true;
00119   #else
00120    return false;
00121   #endif
00122 }
00123 
00124 
00125 
00126 // output to screen/terminal can optionally be handled by a ncurses based
00127 // wrapper, but on default all windows will be merged into cout.
00128 #ifdef USE_NCURSES
00129  #include <my_ncurses.H>
00130 #endif
00131 
00132 ostream cout_titel(cout.rdbuf());
00133 ostream cout_network(cout.rdbuf());
00134 ostream cout_status(cout.rdbuf()); 
00135 
00136 
00137 #ifdef USE_NCURSES
00138 class Cncursed : private ForbidAssignment
00139 {
00140 private:
00141   static Cncursed* myself;
00142   static void suicide() { delete myself; }
00143 
00144   typedef streambuf* Pstreambuf;
00145   typedef Cwin* Pwin;
00146   Pstreambuf cout_titel_buf, cout_network_buf, cout_status_buf,
00147              cerr_buf, clog_buf, cout_buf;
00148   Pwin window1, window2, window3;
00149 public:
00150  Cncursed()
00151  {
00152    if (myself)
00153     {
00154       MARK;
00155       cerr << "You may not call me twice, I'm unique!" << endl;
00156       exit(93);
00157     }
00158    myself=this; // I am myself, really!
00159    init_my_ncurses();
00160    window1 = new Cwin(8,0,0,0);
00161    window2 = new Cwin(8,0,8,0);
00162    window3 = new Cwin(0,0,16,0);
00163    cout_titel_buf=cout_titel.rdbuf(window1->rdbuf());
00164    cout_network_buf=cout_network.rdbuf(window1->rdbuf());
00165    cout_status_buf=cout_status.rdbuf(window2->rdbuf());
00166    cerr_buf=cerr.rdbuf(window2->rdbuf());
00167    clog_buf=clog.rdbuf(window2->rdbuf());
00168    cout_buf=cout.rdbuf(window3->rdbuf());
00169    atexit(suicide);
00170  }
00171  ~Cncursed()
00172  {
00173    cout_titel.rdbuf(cout_titel_buf);
00174    cout_network.rdbuf(cout_network_buf);
00175    cout_status.rdbuf(cout_status_buf);
00176    cerr.rdbuf(cerr_buf);
00177    clog.rdbuf(clog_buf);
00178    cout.rdbuf(cout_buf);
00179    delete window1; delete window2; delete window3;
00180 
00181    exit_my_ncurses();
00182 
00183 #if 0
00184    // print statistical information before exiting,
00185    // since screen should be cleared now!
00186    display_StatusLegend();
00187    StatusReport(true);
00188 #endif
00189  }
00190 };
00191 Cncursed* Cncursed::myself = NULL;
00192 #endif
00193 
00194 
00195 inline void PrintHeader(string name)
00196 {
00197 #if defined(VERSION)
00198   name=name+" "+VERSION;
00199 #endif
00200   string author = "(C) 1998 - 2007 Thorsten Reinecke";
00201   string email = "(qsieve@thorstenreinecke.de)";
00202   const int L = 5+MAX(name.length(),MAX(author.length(),email.length()));
00203   const string sep(L,'-');
00204   int f;
00205   f=(L-name.length())>>1; name=string(f,' ')+name+string(f+1,' '); name.resize(L);
00206   f=(L-author.length())>>1; author=string(f,' ')+author+string(f+1,' '); author.resize(L);
00207   f=(L-email.length())>>1; email=string(f,' ')+email+string(f+1,' '); email.resize(L);
00208   cout_titel << " -" << sep << "-" << endl;
00209   cout_titel << "- " << name << " -" << endl;
00210   cout_titel << "- " << author << " -" << endl;
00211   cout_titel << "- " << email << " -" << endl;
00212   cout_titel << " -" << sep << "-" << endl;
00213 #ifdef __GNUG__
00214   {
00215     const string s=__VERSION__;
00216     cout << "(" << __DATE__ << ", " << __TIME__ << " using ";
00217     if (s[0]<='9') cout << "gcc ";
00218     cout << __VERSION__ << ")" << endl;
00219   }
00220 #endif
00221   cout << endl;
00222   cout << "This is free software; see the source for copying conditions.  There is NO" << endl
00223        << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << endl
00224        << endl;
00225 }

Generated on Wed Nov 7 23:29:25 2007 for Qsieve by  doxygen 1.5.4