/[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 1163 - (show annotations)
Tue Sep 16 18:15:30 2014 UTC (5 years ago) by mmu_man
File MIME type: text/plain
File size: 5142 byte(s)
common.h: guard VC++ specific pragmas

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 //#define _CRT_SECURE_NO_WARNINGS
12 #endif
13
14
15 #include <string>
16 #include <vector>
17
18 #include <fcntl.h>
19
20 #ifndef O_BINARY
21 #define O_BINARY 0
22 #endif
23
24 #ifdef _WIN32
25 #define strncasecmp _strnicmp
26 #include <io.h>
27 #else
28 #include <unistd.h>
29 #endif
30
31
32 //
33 // Debugging macros
34 //
35 #ifdef _DEBUG
36 #define _BREAK_ __asm { int 3 }
37 #define _BREAK_IF_(cond) if (cond) __asm { int 3 } else ((void)0)
38 #else
39 #define _BREAK_ ((void)0)
40 #define _BREAK_IF_(cond) ((void)0)
41 #endif
42
43
44 //
45 // Argument parsing, error handling
46 //
47 void SetApplicationParameters(const char* pcApplicationName,int nVersionMajor,int nVersionMinor,const char* pcUsageMessage);
48
49 void ShowError(const char *pcMessage,...);
50
51
52 class ArgumentParser
53 {
54 public:
55 ArgumentParser(int argc,char *argv[]);
56 ~ArgumentParser() {}
57
58 const char* GetParameter(int nParameterIndex);
59 int GetParameterCount();
60
61 bool ProcessNextArgument();
62
63 bool IsSwitch(const char *ptr_switch);
64 bool IsParameter();
65
66 std::string GetStringValue();
67 int GetIntegerValue(int default_value);
68 bool GetBooleanValue(bool default_value);
69 bool GetSeparator(const char* ptr_separator_list);
70 const char* GetRemainingStuff();
71
72 private:
73 ArgumentParser();
74
75 private:
76 int m_argc;
77 char** m_argv;
78 long m_first_param;
79
80 int m_remaining_argc;
81 long m_nb_arg;
82 const char* m_ptr_arg;
83 };
84
85 bool get_switch(const char *&ptr_arg,const char *ptr_switch);
86 int get_value(const char *&ptr_arg,long default_value);
87 std::string get_string(const char *&ptr_arg);
88
89
90 //
91 // File loading and saving
92 //
93 bool LoadFile(const char* pcFileName,void* &pcBuffer,size_t &cBufferSize);
94 bool SaveFile(const char* pcFileName,const void* pcBuffer,size_t cBufferSize);
95 bool DeleteFile(const char* pcFileName);
96
97 bool LoadText(const char* pcFileName,std::vector<std::string>& cTextData);
98
99 bool IsUpToDate(const char* sourceFile,const char* targetFile);
100 bool IsUpToDate(const std::string& sourceFile,const std::string& targetFile);
101
102
103 //
104 // Compression (moved out FilePack)
105 //
106 long LZ77_Compress(void *buf_src,void *buf_dest,long size_buf_src);
107 void LZ77_UnCompress(void *buf_src,void *buf_dest,long size);
108 long LZ77_ComputeDelta(unsigned char *buf_comp,long size_uncomp,long size_comp);
109 extern unsigned char gLZ77_XorMask;
110
111 //
112 // Preprocessing and filtering
113 //
114 int StringReplace(std::string& cMainString,const std::string& cSearchedString,const std::string& cReplaceString);
115 std::string StringTrim(const std::string& cInputString,const std::string& cFilteredOutCharacterList=" \t\f\v\n\r");
116 std::string StringFormat(const char* pFormatString,...);
117 std::string StringMakeLabel(const std::string& sourceString);
118
119 int ConvertAdress(const char *ptr_value);
120
121 class TextFileGenerator
122 {
123 public:
124 enum Language_e
125 {
126 _eLanguage_Undefined_,
127 eLanguage_C,
128 eLanguage_Assembler,
129 eLanguage_BASIC
130 };
131
132 enum Endianness_e
133 {
134 _eEndianness_Undefined_,
135 _eEndianness_Little,
136 _eEndianness_Big
137 };
138
139 enum NumericBase_e
140 {
141 _eNumericBase_Undefined_,
142 _eNumericBase_Hexadecimal,
143 _eNumericBase_Decimal
144 };
145
146 public:
147 TextFileGenerator();
148 ~TextFileGenerator();
149
150 void SetDataSize(int nDataSize) { m_nDataSize=nDataSize; }
151 void SetFileType(Language_e nFileType) { m_nFileType=nFileType; }
152 void SetEndianness(Endianness_e nEndianness) { m_nEndianness=nEndianness; }
153 void SetNumericBase(NumericBase_e nNumericBase) { m_nNumericBase=nNumericBase; }
154 void SetValuesPerLine(unsigned int nValuesPerLine) { m_nValuesPerLine=nValuesPerLine; }
155 void SetLabel(const std::string& cLabel) { m_cLabelName=cLabel; }
156 void SetLineNumber(int nLineNumber) { m_nFirstLineNumber=nLineNumber; }
157 void SetIncrementLineNumber(int nIncrementLineNumber) { m_nIncrementLineNumber=nIncrementLineNumber; }
158
159 int GetDataSize() { return m_nDataSize; }
160 Language_e GetFileType() { return m_nFileType; }
161 Endianness_e GetEndianness() { return m_nEndianness; }
162 NumericBase_e GetNumericBase() { return m_nNumericBase; }
163 unsigned int GetValuesPerLine() { return m_nValuesPerLine; }
164 const std::string& GetLabel() { return m_cLabelName; }
165 int GetLineNumber() { return m_nFirstLineNumber; }
166 int GetIncrementLineNumber() { return m_nIncrementLineNumber; }
167
168 std::string ConvertData(const void* pSourceData,size_t nFileSize);
169
170 private:
171 int m_nDataSize;
172 Language_e m_nFileType;
173 Endianness_e m_nEndianness;
174 NumericBase_e m_nNumericBase;
175 unsigned int m_nValuesPerLine;
176
177 bool m_bEnableLineNumber;
178 int m_nFirstLineNumber;
179 int m_nIncrementLineNumber;
180
181 std::string m_cLabelName;
182 };
183
184
185 #endif // _COMMON_H_

  ViewVC Help
Powered by ViewVC 1.1.26