/[projet1]/public/pc/tools/osdk/main/common/includes/common.h
Defence Force logotype

Annotation of /public/pc/tools/osdk/main/common/includes/common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1339 - (hide annotations)
Thu Jan 7 18:52:43 2016 UTC (3 years, 11 months ago) by dbug
File MIME type: text/plain
File size: 5389 byte(s)
Some work in progress/cleaning with things signaled by Coverity
1 dbug 70
2     #ifndef _COMMON_H_
3     #define _COMMON_H_
4    
5 mmu_man 1163 #ifdef _MSC_VER
6 dbug 70 // Disable the warning C4706 -> assignment within conditional expression
7     // Allow us to use Warning level 4 instead of level 3
8     #pragma warning( disable : 4706)
9     #pragma warning( disable : 4786) // Debug symbols thing
10     #pragma warning( disable : 4996) // #define _CRT_SECURE_NO_WARNINGS
11 mmu_man 1163 #endif
12 dbug 70
13    
14     #include <string>
15     #include <vector>
16    
17 mmu_man 872 #include <fcntl.h>
18 dbug 208
19 mmu_man 872 #ifndef O_BINARY
20     #define O_BINARY 0
21     #endif
22    
23 dbug 898 #ifdef _WIN32
24     #define strncasecmp _strnicmp
25     #include <io.h>
26     #else
27     #include <unistd.h>
28     #endif
29 mmu_man 872
30 mmu_man 1215 #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 6
31     #define nullptr (NULL)
32     #endif
33 dbug 898
34 dbug 70 //
35 dbug 208 // Debugging macros
36     //
37     #ifdef _DEBUG
38 dbug 974 #define _BREAK_ __asm { int 3 }
39 dbug 208 #define _BREAK_IF_(cond) if (cond) __asm { int 3 } else ((void)0)
40     #else
41 dbug 974 #define _BREAK_ ((void)0)
42 dbug 208 #define _BREAK_IF_(cond) ((void)0)
43     #endif
44    
45    
46     //
47 dbug 70 // Argument parsing, error handling
48     //
49     void SetApplicationParameters(const char* pcApplicationName,int nVersionMajor,int nVersionMinor,const char* pcUsageMessage);
50    
51 dbug 1013 void ShowError(const char *pcMessage,...);
52 dbug 70
53    
54     class ArgumentParser
55     {
56     public:
57 dbug 974 ArgumentParser(int argc,char *argv[]);
58     ~ArgumentParser() {}
59 dbug 70
60 dbug 974 const char* GetParameter(int nParameterIndex);
61     int GetParameterCount();
62 dbug 70
63 dbug 974 bool ProcessNextArgument();
64 dbug 70
65 dbug 974 bool IsSwitch(const char *ptr_switch);
66     bool IsParameter();
67 dbug 70
68 dbug 974 std::string GetStringValue();
69     int GetIntegerValue(int default_value);
70     bool GetBooleanValue(bool default_value);
71     bool GetSeparator(const char* ptr_separator_list);
72     const char* GetRemainingStuff();
73 dbug 70
74     private:
75 dbug 974 ArgumentParser();
76 dbug 70
77 dbug 1339 protected:
78 dbug 974 int m_argc;
79     char** m_argv;
80     long m_first_param;
81 dbug 70
82 dbug 974 int m_remaining_argc;
83     long m_nb_arg;
84     const char* m_ptr_arg;
85 dbug 70 };
86    
87     bool get_switch(const char *&ptr_arg,const char *ptr_switch);
88     int get_value(const char *&ptr_arg,long default_value);
89     std::string get_string(const char *&ptr_arg);
90    
91    
92     //
93     // File loading and saving
94     //
95     bool LoadFile(const char* pcFileName,void* &pcBuffer,size_t &cBufferSize);
96     bool SaveFile(const char* pcFileName,const void* pcBuffer,size_t cBufferSize);
97 dbug 406 bool DeleteFile(const char* pcFileName);
98 dbug 70
99     bool LoadText(const char* pcFileName,std::vector<std::string>& cTextData);
100    
101 dbug 1075 bool IsUpToDate(const char* sourceFile,const char* targetFile);
102     bool IsUpToDate(const std::string& sourceFile,const std::string& targetFile);
103    
104 dbug 1322 //
105     // Batch processing
106     //
107     std::string ExpandFilePath(const std::string& sourceFile);
108     int ExpandFileList(const std::string& sourceFile,std::vector<std::string>& resolvedFileList);
109 dbug 1075
110 dbug 1322
111 dbug 1035 //
112     // Compression (moved out FilePack)
113     //
114     long LZ77_Compress(void *buf_src,void *buf_dest,long size_buf_src);
115     void LZ77_UnCompress(void *buf_src,void *buf_dest,long size);
116     long LZ77_ComputeDelta(unsigned char *buf_comp,long size_uncomp,long size_comp);
117 dbug 1038 extern unsigned char gLZ77_XorMask;
118 dbug 70
119     //
120     // Preprocessing and filtering
121     //
122     int StringReplace(std::string& cMainString,const std::string& cSearchedString,const std::string& cReplaceString);
123 dbug 208 std::string StringTrim(const std::string& cInputString,const std::string& cFilteredOutCharacterList=" \t\f\v\n\r");
124 dbug 70 std::string StringFormat(const char* pFormatString,...);
125 dbug 1045 std::string StringMakeLabel(const std::string& sourceString);
126 dbug 70
127     int ConvertAdress(const char *ptr_value);
128    
129     class TextFileGenerator
130     {
131     public:
132 dbug 974 enum Language_e
133     {
134     _eLanguage_Undefined_,
135     eLanguage_C,
136     eLanguage_Assembler,
137     eLanguage_BASIC
138     };
139 dbug 70
140 dbug 974 enum Endianness_e
141     {
142     _eEndianness_Undefined_,
143     _eEndianness_Little,
144     _eEndianness_Big
145     };
146 dbug 70
147 dbug 974 enum NumericBase_e
148     {
149     _eNumericBase_Undefined_,
150     _eNumericBase_Hexadecimal,
151     _eNumericBase_Decimal
152     };
153 dbug 70
154     public:
155 dbug 974 TextFileGenerator();
156     ~TextFileGenerator();
157 dbug 70
158 dbug 974 void SetDataSize(int nDataSize) { m_nDataSize=nDataSize; }
159     void SetFileType(Language_e nFileType) { m_nFileType=nFileType; }
160     void SetEndianness(Endianness_e nEndianness) { m_nEndianness=nEndianness; }
161     void SetNumericBase(NumericBase_e nNumericBase) { m_nNumericBase=nNumericBase; }
162     void SetValuesPerLine(unsigned int nValuesPerLine) { m_nValuesPerLine=nValuesPerLine; }
163     void SetLabel(const std::string& cLabel) { m_cLabelName=cLabel; }
164     void SetLineNumber(int nLineNumber) { m_nFirstLineNumber=nLineNumber; }
165     void SetIncrementLineNumber(int nIncrementLineNumber) { m_nIncrementLineNumber=nIncrementLineNumber; }
166 dbug 70
167 dbug 974 int GetDataSize() { return m_nDataSize; }
168     Language_e GetFileType() { return m_nFileType; }
169     Endianness_e GetEndianness() { return m_nEndianness; }
170     NumericBase_e GetNumericBase() { return m_nNumericBase; }
171     unsigned int GetValuesPerLine() { return m_nValuesPerLine; }
172     const std::string& GetLabel() { return m_cLabelName; }
173     int GetLineNumber() { return m_nFirstLineNumber; }
174     int GetIncrementLineNumber() { return m_nIncrementLineNumber; }
175 dbug 70
176 dbug 974 std::string ConvertData(const void* pSourceData,size_t nFileSize);
177 dbug 70
178     private:
179 dbug 974 int m_nDataSize;
180     Language_e m_nFileType;
181     Endianness_e m_nEndianness;
182     NumericBase_e m_nNumericBase;
183     unsigned int m_nValuesPerLine;
184 dbug 70
185 dbug 974 bool m_bEnableLineNumber;
186     int m_nFirstLineNumber;
187     int m_nIncrementLineNumber;
188 dbug 70
189 dbug 974 std::string m_cLabelName;
190 dbug 70 };
191    
192    
193     #endif // _COMMON_H_

  ViewVC Help
Powered by ViewVC 1.1.26