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