/[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 872 - (show annotations)
Tue Sep 25 22:43:47 2012 UTC (7 years, 4 months ago) by mmu_man
File MIME type: text/plain
File size: 4412 byte(s)
POSIXify common/

* define O_BINARY on platforms which don't define it
* include <curses.h> on *nix to have a usable getch()
* use real POSIX functions instead of _-prefixed win32 versions
* use strncasecmp() instead of nonstandard memicmp()
* use stat() instead of _findfirst() since we don't even use the globbed result anyway

This now builds both for linux and mingw32.

1
2 #ifndef _COMMON_H_
3 #define _COMMON_H_
4
5 // Disable the warning C4706 -> assignment within conditional expression
6 // Allow us to use Warning level 4 instead of level 3
7 #pragma warning( disable : 4706)
8 #pragma warning( disable : 4786) // Debug symbols thing
9 #pragma warning( disable : 4996) // #define _CRT_SECURE_NO_WARNINGS
10 //#define _CRT_SECURE_NO_WARNINGS
11
12
13 #include <string>
14 #include <vector>
15
16 #include <fcntl.h>
17
18 #ifndef O_BINARY
19 #define O_BINARY 0
20 #endif
21
22
23 //
24 // Debugging macros
25 //
26 #ifdef _DEBUG
27 #define _BREAK_ __asm { int 3 }
28 #define _BREAK_IF_(cond) if (cond) __asm { int 3 } else ((void)0)
29 #else
30 #define _BREAK_ ((void)0)
31 #define _BREAK_IF_(cond) ((void)0)
32 #endif
33
34
35 //
36 // Argument parsing, error handling
37 //
38 void SetApplicationParameters(const char* pcApplicationName,int nVersionMajor,int nVersionMinor,const char* pcUsageMessage);
39
40 void ShowError(const char *pcMessage);
41
42
43 class ArgumentParser
44 {
45 public:
46 ArgumentParser(int argc,char *argv[]);
47 ~ArgumentParser() {}
48
49 const char* GetParameter(int nParameterIndex);
50 int GetParameterCount();
51
52 bool ProcessNextArgument();
53
54 bool IsSwitch(const char *ptr_switch);
55 bool IsParameter();
56
57 std::string GetStringValue();
58 int GetIntegerValue(int default_value);
59 bool GetBooleanValue(bool default_value);
60 bool GetSeparator(const char* ptr_separator_list);
61 const char* GetRemainingStuff();
62
63 private:
64 ArgumentParser();
65
66 private:
67 int m_argc;
68 char** m_argv;
69 long m_first_param;
70
71 int m_remaining_argc;
72 long m_nb_arg;
73 const char *m_ptr_arg;
74 };
75
76 bool get_switch(const char *&ptr_arg,const char *ptr_switch);
77 int get_value(const char *&ptr_arg,long default_value);
78 std::string get_string(const char *&ptr_arg);
79
80
81 //
82 // File loading and saving
83 //
84 bool LoadFile(const char* pcFileName,void* &pcBuffer,size_t &cBufferSize);
85 bool SaveFile(const char* pcFileName,const void* pcBuffer,size_t cBufferSize);
86 bool DeleteFile(const char* pcFileName);
87
88 bool LoadText(const char* pcFileName,std::vector<std::string>& cTextData);
89
90
91 //
92 // Preprocessing and filtering
93 //
94 int StringReplace(std::string& cMainString,const std::string& cSearchedString,const std::string& cReplaceString);
95 std::string StringTrim(const std::string& cInputString,const std::string& cFilteredOutCharacterList=" \t\f\v\n\r");
96 std::string StringFormat(const char* pFormatString,...);
97
98 int ConvertAdress(const char *ptr_value);
99
100 class TextFileGenerator
101 {
102 public:
103 enum Language_e
104 {
105 _eLanguage_Undefined_,
106 eLanguage_C,
107 eLanguage_Assembler,
108 eLanguage_BASIC
109 };
110
111 enum Endianness_e
112 {
113 _eEndianness_Undefined_,
114 _eEndianness_Little,
115 _eEndianness_Big
116 };
117
118 enum NumericBase_e
119 {
120 _eNumericBase_Undefined_,
121 _eNumericBase_Hexadecimal,
122 _eNumericBase_Decimal
123 };
124
125 public:
126 TextFileGenerator();
127 ~TextFileGenerator();
128
129 void SetDataSize(int nDataSize) { m_nDataSize=nDataSize; }
130 void SetFileType(Language_e nFileType) { m_nFileType=nFileType; }
131 void SetEndianness(Endianness_e nEndianness) { m_nEndianness=nEndianness; }
132 void SetNumericBase(NumericBase_e nNumericBase) { m_nNumericBase=nNumericBase; }
133 void SetValuesPerLine(unsigned int nValuesPerLine) { m_nValuesPerLine=nValuesPerLine; }
134 void SetLabel(const std::string& cLabel) { m_cLabelName=cLabel; }
135 void SetLineNumber(int nLineNumber) { m_nFirstLineNumber=nLineNumber; }
136 void SetIncrementLineNumber(int nIncrementLineNumber) { m_nIncrementLineNumber=nIncrementLineNumber; }
137
138 int GetDataSize() { return m_nDataSize; }
139 Language_e GetFileType() { return m_nFileType; }
140 Endianness_e GetEndianness() { return m_nEndianness; }
141 NumericBase_e GetNumericBase() { return m_nNumericBase; }
142 unsigned int GetValuesPerLine() { return m_nValuesPerLine; }
143 const std::string& GetLabel() { return m_cLabelName; }
144 int GetLineNumber() { return m_nFirstLineNumber; }
145 int GetIncrementLineNumber() { return m_nIncrementLineNumber; }
146
147 void ConvertData(std::string& cDestString,const void* pSourceData,size_t nFileSize);
148
149 private:
150 int m_nDataSize;
151 Language_e m_nFileType;
152 Endianness_e m_nEndianness;
153 NumericBase_e m_nNumericBase;
154 unsigned int m_nValuesPerLine;
155
156 bool m_bEnableLineNumber;
157 int m_nFirstLineNumber;
158 int m_nIncrementLineNumber;
159
160 std::string m_cLabelName;
161 };
162
163
164 #endif // _COMMON_H_

  ViewVC Help
Powered by ViewVC 1.1.26