AppUtil.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Maintainer: fehr@suse.de
00003 
00004 #ifndef _AppUtil_h
00005 #define _AppUtil_h
00006 
00007 #include <time.h>
00008 #include <libintl.h>
00009 #include <cstdarg>
00010 #include <cstdio>
00011 #include <fstream>
00012 #include <sstream>
00013 #include <string>
00014 #include <list>
00015 #include <map>
00016 
00017 using std::string;
00018 
00019 namespace storage
00020 {
00021 
00022 class AsciiFile;
00023 
00024 bool searchFile(AsciiFile& File_Cr, string Pat_Cv, string& Line_Cr);
00025 bool searchFile(AsciiFile& File_Cr, string Pat_Cv, string& Line_Cr,
00026                 int& StartLine_ir);
00027 void tolower( string& s );
00028 void timeMark(const char*const Text_pcv, bool PrintDiff_bi = true);
00029 void createPath(string Path_Cv);
00030 bool checkNormalFile(string Path_Cv);
00031 bool checkDir(string Path_Cv);
00032 
00033 string dupDash(const string& s);
00034 string extractNthWord(int Num_iv, string Line_Cv, bool GetRest_bi = false);
00035 std::list<string> splitString( const string& s, const string& delChars=" \t\n",
00036                           bool multipleDelim=true, bool skipEmpty=true,
00037                           const string& quotes="" );
00038 string mergeString( const std::list<string>& l, const string& del=" " );
00039 std::map<string,string> makeMap( const std::list<string>& l, 
00040                                  const string& delim = "=",
00041                                  const string& removeSur = " \t\n" );
00042 void getFindMap( const char* path, std::map<string,string>& m,
00043                  bool unique=true );
00044 void getFindRevMap( const char* path, std::map<string,string>& m );
00045 void removeLastIf(string& Text_Cr, char Char_cv);
00046 string kbyteToHumanString( unsigned long long size );
00047 string normalizeDevice( const string& dev );
00048 void normalizeDevice( string& dev );
00049 string undevDevice( const string& dev );
00050 void undevDevice( string& dev );
00051 bool isNfsDev( const string& dev );
00052 bool runningFromSystem();
00053 void delay(int Microsec_iv);
00054 unsigned getMajorDevices( const string& driver );
00055 
00056 int createLogger( const string& component, const string& name,
00057                   const string& logpath, const string& logfile );
00058 
00059 void log_msg( unsigned level, const char* file, unsigned line, 
00060               const char* func, const char* add_str, const char* format, ... ) 
00061         __attribute__ ((format(printf, 6, 7)));
00062 
00063 #define y2debug(format, ...)  \
00064     log_msg( 0, __FILE__, __LINE__, __FUNCTION__, NULL, format, ##__VA_ARGS__ )
00065 #define y2milestone(format, ...)  \
00066     log_msg( 1, __FILE__, __LINE__, __FUNCTION__, NULL, format, ##__VA_ARGS__ )
00067 #define y2warning(format, ...)  \
00068     log_msg( 2, __FILE__, __LINE__, __FUNCTION__, NULL, format, ##__VA_ARGS__ )
00069 #define y2error(format, ...)  \
00070     log_msg( 3, __FILE__, __LINE__, __FUNCTION__, NULL, format, ##__VA_ARGS__ )
00071 
00072 #define y2deb(op) log_op( 0, __FILE__, __LINE__, __FUNCTION__, NULL, op )
00073 #define y2mil(op) log_op( 1, __FILE__, __LINE__, __FUNCTION__, NULL, op )
00074 #define y2war(op) log_op( 2, __FILE__, __LINE__, __FUNCTION__, NULL, op )
00075 #define y2err(op) log_op( 3, __FILE__, __LINE__, __FUNCTION__, NULL, op )
00076 
00077 #define log_op( level, file, line, function, add, op )                \
00078     {                                                                 \
00079     std::ostringstream __buf;                                         \
00080     __buf << op;                                                      \
00081     log_msg( level, file, line, function, add, "%s", __buf.str().c_str() ); \
00082     }                                                                
00083 
00084 inline string sformat( const char* txt, ... )
00085     {
00086     unsigned s = strlen(txt)+3072;
00087     char * mem = new char[s];
00088     if( mem != NULL )
00089         {
00090         va_list p;
00091         va_start( p, txt );
00092         vsnprintf( mem, s-1, txt, p );
00093         va_end( p );
00094         mem[s-1]=0;
00095         string s( mem );
00096         delete [] mem;
00097         return( s );
00098         }
00099     else
00100         return( "" );
00101     }
00102 
00103 inline const char* _(const char* msgid)
00104     {
00105     return( dgettext("storage", msgid) );
00106     }
00107 
00108 inline const char* _(const char* msgid1, const char* msgid2, unsigned long int n)
00109     {
00110     return( dngettext ("storage", msgid1, msgid2, n) );
00111     }
00112 
00113 #define IPC_PROJ_ID 7890
00114 
00115 extern bool system_cmd_testmode;
00116 extern const string app_ws;
00117 
00118 }
00119 
00120 #endif

Generated on Tue Sep 25 21:19:22 2007 for yast2-storage by  doxygen 1.5.3