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