forked from probonopd/MakeHex
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakeHex.cpp
More file actions
95 lines (83 loc) · 1.85 KB
/
MakeHex.cpp
File metadata and controls
95 lines (83 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
///////////////////////////////////////////////////////////////////////////////
// MakeHex version 4 Copyright 2004 John S. Fine
//
// You may use, copy, modify and/or distribute this program for private or
// commercial use provided that:
//
// 1) You do not hold me responsible for any damage or negative consequences
// resulting from those activities.
//
// 2) You include this copyright notice and disclaimer in any copy of any part
// or all of this program.
//
// I do not provide any warranty of the correctness, safety, or suitibility of
// this program for any purpose.
//
// If you do not agree to these conditions, you have no permission to use, copy,
// modify or distribute this program.
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "irp.h"
int main(int argc, char** argv)
{
if (argc<2)
{
usage:
printf("Usage MakeHex IrpFile {OutFile}\n");
return -1;
}
IRP Irp;
char* arg1=*(++argv);
if (arg1[0]=='-' && arg1[2]==0)
{
char s = toupper(arg1[1]);
if (s=='H')
Irp.m_numberFormat = 1;
else if (s=='B')
Irp.m_numberFormat = 2;
else
goto usage;
arg1 = *(++argv);
if (--argc == 1)
goto usage;
}
if (argc>3)
goto usage;
FILE *InFile = fopen(arg1, "r");
if (!InFile)
{
printf("Unable to open \"%s\"\n", arg1);
return -1;
}
if (! Irp.readIrpFile(InFile) )
{
printf("IRP file \"%s\" not processed\n");
return -1;
}
char *OutName;
if (argc==3)
{
OutName = argv[1];
}
else
{
char *tmp = strrchr(arg1, '.');
if (!tmp)
{
tmp = arg1 + strlen(arg1);
}
int len = tmp - arg1;
OutName = new char [len+5];
memcpy(OutName, arg1, len);
strcpy(OutName+len, ".hex");
}
FILE *OutFile = fopen(OutName, "w");
if (!OutFile)
{
printf("Unable to create \"%s\"\n", OutName);
return -1;
}
Irp.writeHex(OutFile);
fclose(OutFile);
return 0;
}