/[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 1013 - (show annotations)
Thu Dec 12 19:35:12 2013 UTC (5 years, 11 months ago) by dbug
File MIME type: text/plain
File size: 4610 byte(s)
Modified the ShowError command to take optional parameters (makes it possible to display actual information in the error message)
FloppyBuilder 0.3: Fixed parsing of comments, added a 'OutputFloppyFile' command, validated that the number of sectors and tracks is correct in the 'SetPosition' command.
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 #ifdef _WIN32
23 #define strncasecmp _strnicmp
24 #include <io.h>
25 #else
26 #include <unistd.h>
27 #endif
28
29
30 //
31 // Debugging macros
32 //
33 #ifdef _DEBUG
34 #define _BREAK_ __asm { int 3 }
35 #define _BREAK_IF_(cond) if (cond) __asm { int 3 } else ((void)0)
36 #else
37 #define _BREAK_ ((void)0)
38 #define _BREAK_IF_(cond) ((void)0)
39 #endif
40
41
42 //
43 // Argument parsing, error handling
44 //
45 void SetApplicationParameters(const char* pcApplicationName,int nVersionMajor,int nVersionMinor,const char* pcUsageMessage);
46
47 void ShowError(const char *pcMessage,...);
48
49
50 class ArgumentParser
51 {
52 public:
53 ArgumentParser(int argc,char *argv[]);
54 ~ArgumentParser() {}
55
56 const char* GetParameter(int nParameterIndex);
57 int GetParameterCount();
58
59 bool ProcessNextArgument();
60
61 bool IsSwitch(const char *ptr_switch);
62 bool IsParameter();
63
64 std::string GetStringValue();
65 int GetIntegerValue(int default_value);
66 bool GetBooleanValue(bool default_value);
67 bool GetSeparator(const char* ptr_separator_list);
68 const char* GetRemainingStuff();
69
70 private:
71 ArgumentParser();
72
73 private:
74 int m_argc;
75 char** m_argv;
76 long m_first_param;
77
78 int m_remaining_argc;
79 long m_nb_arg;
80 const char* m_ptr_arg;
81 };
82
83 bool get_switch(const char *&ptr_arg,const char *ptr_switch);
84 int get_value(const char *&ptr_arg,long default_value);
85 std::string get_string(const char *&ptr_arg);
86
87
88 //
89 // File loading and saving
90 //
91 bool LoadFile(const char* pcFileName,void* &pcBuffer,size_t &cBufferSize);
92 bool SaveFile(const char* pcFileName,const void* pcBuffer,size_t cBufferSize);
93 bool DeleteFile(const char* pcFileName);
94
95 bool LoadText(const char* pcFileName,std::vector<std::string>& cTextData);
96
97
98 //
99 // Preprocessing and filtering
100 //
101 int StringReplace(std::string& cMainString,const std::string& cSearchedString,const std::string& cReplaceString);
102 std::string StringTrim(const std::string& cInputString,const std::string& cFilteredOutCharacterList=" \t\f\v\n\r");
103 std::string StringFormat(const char* pFormatString,...);
104
105 int ConvertAdress(const char *ptr_value);
106
107 class TextFileGenerator
108 {
109 public:
110 enum Language_e
111 {
112 _eLanguage_Undefined_,
113 eLanguage_C,
114 eLanguage_Assembler,
115 eLanguage_BASIC
116 };
117
118 enum Endianness_e
119 {
120 _eEndianness_Undefined_,
121 _eEndianness_Little,
122 _eEndianness_Big
123 };
124
125 enum NumericBase_e
126 {
127 _eNumericBase_Undefined_,
128 _eNumericBase_Hexadecimal,
129 _eNumericBase_Decimal
130 };
131
132 public:
133 TextFileGenerator();
134 ~TextFileGenerator();
135
136 void SetDataSize(int nDataSize) { m_nDataSize=nDataSize; }
137 void SetFileType(Language_e nFileType) { m_nFileType=nFileType; }
138 void SetEndianness(Endianness_e nEndianness) { m_nEndianness=nEndianness; }
139 void SetNumericBase(NumericBase_e nNumericBase) { m_nNumericBase=nNumericBase; }
140 void SetValuesPerLine(unsigned int nValuesPerLine) { m_nValuesPerLine=nValuesPerLine; }
141 void SetLabel(const std::string& cLabel) { m_cLabelName=cLabel; }
142 void SetLineNumber(int nLineNumber) { m_nFirstLineNumber=nLineNumber; }
143 void SetIncrementLineNumber(int nIncrementLineNumber) { m_nIncrementLineNumber=nIncrementLineNumber; }
144
145 int GetDataSize() { return m_nDataSize; }
146 Language_e GetFileType() { return m_nFileType; }
147 Endianness_e GetEndianness() { return m_nEndianness; }
148 NumericBase_e GetNumericBase() { return m_nNumericBase; }
149 unsigned int GetValuesPerLine() { return m_nValuesPerLine; }
150 const std::string& GetLabel() { return m_cLabelName; }
151 int GetLineNumber() { return m_nFirstLineNumber; }
152 int GetIncrementLineNumber() { return m_nIncrementLineNumber; }
153
154 std::string ConvertData(const void* pSourceData,size_t nFileSize);
155
156 private:
157 int m_nDataSize;
158 Language_e m_nFileType;
159 Endianness_e m_nEndianness;
160 NumericBase_e m_nNumericBase;
161 unsigned int m_nValuesPerLine;
162
163 bool m_bEnableLineNumber;
164 int m_nFirstLineNumber;
165 int m_nIncrementLineNumber;
166
167 std::string m_cLabelName;
168 };
169
170
171 #endif // _COMMON_H_

  ViewVC Help
Powered by ViewVC 1.1.26