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

Generated on Thu Jul 6 00:40:24 2006 for yast2-storage by  doxygen 1.4.6