/[projet1]/public/pc/tools/osdk/main/bin2txt/sources/bin2txt.cpp
Defence Force logotype

Annotation of /public/pc/tools/osdk/main/bin2txt/sources/bin2txt.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 70 - (hide annotations)
Sun May 24 19:53:20 2009 UTC (10 years, 6 months ago) by dbug
File size: 4181 byte(s)
Added the complete source code of the OSDK.
Projects files are available for Visual Studio 6 and .net, plus a Code::Blocks setup (everything works except PictConv that relies on FreeImage - which does not build correctly on mingw)
1 dbug 70 /*==============================================================================
2    
3     Bin2Txt
4    
5     ==[Description]=================================================================
6    
7     This little command line application can be use to convert binary files to a
8     text format, than can later be compiled using various languages.
9    
10     ==[History]=====================================================================
11    
12     First version Mick: Fri 13/09/96 16:16:14
13    
14     ==[ToDo]========================================================================
15    
16     * Support for Little/Big Endian
17     * Support for BASIC instructions (nnnn DATA a,b,c,d, ...)
18    
19     ==============================================================================*/
20    
21     #include <stdio.h>
22     #include <stdlib.h>
23     #include <stdarg.h>
24     #include <ctype.h>
25     #include <fcntl.h>
26     #include <io.h>
27     #include <string.h>
28    
29     #include "infos.h"
30    
31     #include "common.h"
32    
33    
34    
35    
36    
37     #define NB_ARG 3
38    
39    
40    
41    
42     int main(int argc,char *argv[])
43     {
44     //
45     // Some initialization for the common library
46     //
47     SetApplicationParameters(
48     "Bin2Txt",
49     TOOL_VERSION_MAJOR,
50     TOOL_VERSION_MINOR,
51     "{ApplicationName} - Version {ApplicationVersion} - This program is a part of the OSDK\r\n"
52     "\r\n"
53     "Author:\r\n"
54     " (c) 1998-2006 Pointier Mickael \r\n"
55     "\r\n"
56     "Purpose:\r\n"
57     " Converting a binary file to a text format that can be later reused in a program\r\n"
58     " written in C, assembly code or BASIC.\r\n"
59     "\r\n"
60     "USAGE:\r\n"
61     "{ApplicationName} -s<number> -f<number> <binary file> <txt file> <label name>\r\n"
62     " [options]:\r\n"
63     " ®-s[1|2|4] For BYTE,WORD,LONG format.\r\n"
64     " ®-e[1|2] Define endianness: 1 for little endian, 2 for big endian\r\n"
65     " ®-f[1|2|3] For C, ASM, BASIC.\r\n"
66     " ®-h[1|2] 1 for hexadecimal, 2 for decimal\r\n"
67     " ®-l[b:s] Defines line values for BASIC (-l10:10)\r\n"
68     " ®-n[16|32|..] Defines the number of entries per line.\r\n"
69     );
70    
71    
72     TextFileGenerator cTextFileGenerator;
73    
74     ArgumentParser cArgumentParser(argc,argv);
75    
76     while (cArgumentParser.ProcessNextArgument())
77     {
78     if (cArgumentParser.IsSwitch("-s"))
79     {
80     cTextFileGenerator.SetDataSize(cArgumentParser.GetIntegerValue(1));
81     }
82     else
83     if (cArgumentParser.IsSwitch("-e"))
84     {
85     cTextFileGenerator.SetEndianness((TextFileGenerator::Endianness_e)cArgumentParser.GetIntegerValue(TextFileGenerator::_eEndianness_Undefined_));
86     }
87     else
88     if (cArgumentParser.IsSwitch("-f"))
89     {
90     cTextFileGenerator.SetFileType((TextFileGenerator::Language_e)cArgumentParser.GetIntegerValue(TextFileGenerator::_eLanguage_Undefined_));
91     }
92     else
93     if (cArgumentParser.IsSwitch("-h"))
94     {
95     cTextFileGenerator.SetNumericBase((TextFileGenerator::NumericBase_e)cArgumentParser.GetIntegerValue(TextFileGenerator::_eNumericBase_Undefined_));
96     }
97     else
98     if (cArgumentParser.IsSwitch("-l"))
99     {
100     cTextFileGenerator.SetLineNumber(cArgumentParser.GetIntegerValue(10));
101     if (cArgumentParser.GetSeparator(":"))
102     {
103     cTextFileGenerator.SetIncrementLineNumber(cArgumentParser.GetIntegerValue(10));
104     }
105     }
106     else
107     if (cArgumentParser.IsSwitch("-n"))
108     {
109     cTextFileGenerator.SetValuesPerLine(cArgumentParser.GetIntegerValue(16));
110     }
111     }
112    
113     if (cArgumentParser.GetParameterCount()!=NB_ARG)
114     {
115     ShowError(0);
116     }
117    
118     std::string NameSrc(cArgumentParser.GetParameter(0));
119     std::string NameDst(cArgumentParser.GetParameter(1));
120     cTextFileGenerator.SetLabel(cArgumentParser.GetParameter(2));
121    
122     printf("Converting <%s> to <%s> with label <%s>\n",NameSrc.c_str(),NameDst.c_str(),cTextFileGenerator.GetLabel().c_str());
123    
124     void* ptr_buffer_void;
125     size_t file_size;
126     if (!LoadFile(NameSrc.c_str(),ptr_buffer_void,file_size))
127     {
128     ShowError("Unable to load the source file");
129     }
130     printf("Size Read:%d\n",file_size);
131     unsigned char *BigBuffer=(unsigned char*)ptr_buffer_void;
132    
133     std::string cDestString;
134     cTextFileGenerator.ConvertData(cDestString,BigBuffer,file_size);
135    
136     if (!SaveFile(NameDst.c_str(),cDestString.c_str(),cDestString.size()))
137     {
138     ShowError("Unable to save the destination file");
139     }
140    
141     free(BigBuffer);
142    
143     exit(0);
144     }
145    
146    
147    
148    

  ViewVC Help
Powered by ViewVC 1.1.26