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 void log_msg( unsigned level, const char* file, unsigned line, 
00063               const char* func, const char* add_str, const char* format, ... ) 
00064         __attribute__ ((format(printf, 6, 7)));
00065 
00066 #define y2debug(format, ...)  \
00067     log_msg( 0, __FILE__, __LINE__, __FUNCTION__, NULL, format, ##__VA_ARGS__ )
00068 #define y2milestone(format, ...)  \
00069     log_msg( 1, __FILE__, __LINE__, __FUNCTION__, NULL, format, ##__VA_ARGS__ )
00070 #define y2warning(format, ...)  \
00071     log_msg( 1, __FILE__, __LINE__, __FUNCTION__, "[WARNING]", format, ##__VA_ARGS__ )
00072 #define y2error(format, ...)  \
00073     log_msg( 2, __FILE__, __LINE__, __FUNCTION__, NULL, format, ##__VA_ARGS__ )
00074 
00075 #define y2deb(op) log_op( 0, __FILE__, __LINE__, __FUNCTION__, NULL, op )
00076 #define y2mil(op) log_op( 1, __FILE__, __LINE__, __FUNCTION__, NULL, op )
00077 #define y2war(op) log_op( 1, __FILE__, __LINE__, __FUNCTION__, "[WARNING]", op)
00078 #define y2err(op) log_op( 2, __FILE__, __LINE__, __FUNCTION__, NULL, op )
00079 
00080 #define log_op( level, file, line, function, add, op )                \
00081     {                                                                 \
00082     std::ostringstream __buf;                                         \
00083     __buf << op;                                                      \
00084     log_msg( level, file, line, function, add, __buf.str().c_str() ); \
00085     }                                                                
00086 
00087 inline string sformat( const char* txt, ... )
00088     {
00089     unsigned s = strlen(txt)+3072;
00090     char * mem = new char[s];
00091     if( mem != NULL )
00092         {
00093         va_list p;
00094         va_start( p, txt );
00095         vsnprintf( mem, s-1, txt, p );
00096         va_end( p );
00097         mem[s-1]=0;
00098         string s( mem );
00099         delete [] mem;
00100         return( s );
00101         }
00102     else
00103         return( "" );
00104     }
00105 
00106 inline const char* _(const char* msgid)
00107     {
00108     return( dgettext("storage", msgid) );
00109     }
00110 
00111 inline const char* _(const char* msgid1, const char* msgid2, unsigned long int n)
00112     {
00113     return( dngettext ("storage", msgid1, msgid2, n) );
00114     }
00115 
00116 #define IPC_PROJ_ID 7890
00117 
00118 extern bool system_cmd_testmode;
00119 extern const string app_ws;
00120 
00121 }
00122 
00123 #endif

Generated on Wed Apr 30 15:02:08 2008 for yast2-storage by  doxygen 1.4.6