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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1339 - (show 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
2 #ifndef _COMMON_H_
3 #define _COMMON_H_
4
5 #ifdef _MSC_VER
6 // 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 #endif
12
13
14 #include <string>
15 #include <vector>
16
17 #include <fcntl.h>
18
19 #ifndef O_BINARY
20 #define O_BINARY 0
21 #endif
22
23 #ifdef _WIN32
24 #define strncasecmp _strnicmp
25 #include <io.h>
26 #else
27 #include <unistd.h>
28 #endif
29
30 #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 6
31 #define nullptr (NULL)
32 #endif
33
34 //
35 // Debugging macros
36 //
37 #ifdef _DEBUG
38 #define _BREAK_ __asm { int 3 }
39 #define _BREAK_IF_(cond) if (cond) __asm { int 3 } else ((void)0)
40 #else
41 #define _BREAK_ ((void)0)
42 #define _BREAK_IF_(cond) ((void)0)
43 #endif
44
45
46 //
47 // Argument parsing, error handling
48 //
49 void SetApplicationParameters(const char* pcApplicationName,int nVersionMajor,int nVersionMinor,const char* pcUsageMessage);
50
51 void ShowError(const char *pcMessage,...);
52
53
54 class ArgumentParser
55 {
56 public:
57 ArgumentParser(int argc,char *argv[]);
58 ~ArgumentParser() {}
59
60 const char* GetParameter(int nParameterIndex);
61 int GetParameterCount();
62
63 bool ProcessNextArgument();
64
65 bool IsSwitch(const char *ptr_switch);
66 bool IsParameter();
67
68 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
74 private:
75 ArgumentParser();
76
77 protected:
78 int m_argc;
79 char** m_argv;
80 long m_first_param;
81
82 int m_remaining_argc;
83 long m_nb_arg;
84 const char* m_ptr_arg;
85 };
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 bool DeleteFile(const char* pcFileName);
98
99 bool LoadText(const char* pcFileName,std::vector<std::string>& cTextData);
100
101 bool IsUpToDate(const char* sourceFile,const char* targetFile);
102 bool IsUpToDate(const std::string& sourceFile,const std::string& targetFile);
103
104 //
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
110
111 //
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 extern unsigned char gLZ77_XorMask;
118
119 //
120 // Preprocessing and filtering
121 //
122 int StringReplace(std::string& cMainString,const std::string& cSearchedString,const std::string& cReplaceString);
123 std::string StringTrim(const std::string& cInputString,const std::string& cFilteredOutCharacterList=" \t\f\v\n\r");
124 std::string StringFormat(const char* pFormatString,...);
125 std::string StringMakeLabel(const std::string& sourceString);
126
127 int ConvertAdress(const char *ptr_value);
128
129 class TextFileGenerator
130 {
131 public:
132 enum Language_e
133 {
134 _eLanguage_Undefined_,
135 eLanguage_C,
136 eLanguage_Assembler,
137 eLanguage_BASIC
138 };
139
140 enum Endianness_e
141 {
142 _eEndianness_Undefined_,
143 _eEndianness_Little,
144 _eEndianness_Big
145 };
146
147 enum NumericBase_e
148 {
149 _eNumericBase_Undefined_,
150 _eNumericBase_Hexadecimal,
151 _eNumericBase_Decimal
152 };
153
154 public:
155 TextFileGenerator();
156 ~TextFileGenerator();
157
158 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
167 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
176 std::string ConvertData(const void* pSourceData,size_t nFileSize);
177
178 private:
179 int m_nDataSize;
180 Language_e m_nFileType;
181 Endianness_e m_nEndianness;
182 NumericBase_e m_nNumericBase;
183 unsigned int m_nValuesPerLine;
184
185 bool m_bEnableLineNumber;
186 int m_nFirstLineNumber;
187 int m_nIncrementLineNumber;
188
189 std::string m_cLabelName;
190 };
191
192
193 #endif // _COMMON_H_

  ViewVC Help
Powered by ViewVC 1.1.26