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