FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MS-DOS-kernel/utils/patchobj.c at master · Programuserbash/MS-DOS-kernel · GitHub
Programuserbash
/
MS-DOS-kernel
Public
forked from
FDOS/kernel
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MS-DOS-kernel
/
utils
/
patchobj.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
204 lines (165 loc) · 4.67 KB
Breadcrumbs
MS-DOS-kernel
/
utils
/
patchobj.c
Copy path
File metadata and controls
204 lines (165 loc) · 4.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*****************************************************************************
** PATCHOBJ facility - change strings in the LNAMES record
**
** Copyright 2001 by tom ehlert
**
** GPL bla to be added, but intended as GPL
**
**
** 09/06/2001 - initial revision
** not my biggest kind of software; anyone willing to add
** comments, errormessages, usage info,...???
**
*****************************************************************************/
#include
<stdio.h>
#if
defined(
__GNUC__
)
||
defined(
__WATCOMC__
)
#include
<unistd.h>
#else
#include
<io.h>
#endif
#include
<stdlib.h>
#include
<string.h>
#include
<ctype.h>
#ifndef
TRUE
#define
TRUE
(1==1)
#define
FALSE
(0==1)
#endif
struct
{
char
*
sin
,
*
sout
;
}
repl
[
100
];
int
repl_count
;
void
go_records
(
FILE
*
fdin
,
FILE
*
fdo
);
void
quit
(
char
*
s
, ...)
{
vprintf
(
s
, (
void
*
)((
char
*
)
&
s
+
sizeof
(
s
)));
exit
(
1
);
}
void
define_replace
(
char
*
sin
)
{
char
*
s
;
if
(
repl_count
>=
99
)
quit
(
"too many replacements"
);
if
((
s
=
strchr
(
sin
,
'='
))
==
NULL
)
quit
(
"illegal replacement <%s>, missing '='"
,
sin
);
*
s
=
0
;
repl
[
repl_count
].
sin
=
sin
;
repl
[
repl_count
].
sout
=
s
+
1
;
repl_count
++
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
char
*
argptr
;
FILE
*
fd
,
*
fdo
;
char
*
inname
=
0
,
*
outname
=
"~patchob.tmp"
;
int
use_temp_file
=
TRUE;
argc
--
,
argv
++
;
for
(;
argc
!=
0
;
argc
--
,
argv
++
)
{
argptr
=
*
argv
;
if
(
*
argptr
!=
'-'
&&
*
argptr
!=
'/'
)
{
if
(
argc
==
1
)
{
inname
=
argptr
;
continue
;
}
define_replace
(
argptr
);
continue
;
}
switch
(
toupper
(
argptr
[
1
]))
{
case
'O'
:
outname
=
argptr
+
2
;
use_temp_file
=
FALSE;
break
;
default
:
quit
(
"illegal argument <%s>\n"
,
argptr
);
break
;
}
}
if
(
inname
==
0
)
quit
(
"Inputfile must be specified\n"
);
if
(
repl_count
==
0
)
quit
(
"no replacements defined"
);
if
((
fd
=
fopen
(
inname
,
"rb"
))
==
NULL
)
/* open for READ/WRITE */
quit
(
"can't read %s\n"
,
inname
);
if
((
fdo
=
fopen
(
outname
,
"wb"
))
==
NULL
)
/* open for READ/WRITE */
quit
(
"can't write %s\n"
,
outname
);
go_records
(
fd
,
fdo
);
fclose
(
fd
);
fclose
(
fdo
);
if
(
use_temp_file
)
{
unlink
(
inname
);
rename
(
outname
,
inname
);
}
return
0
;
}
#include
"algnbyte.h"
struct
record
{
unsigned
char
rectyp
;
unsigned short
datalen
;
char
buffer
[
0x2000
];
}
Record
,
Outrecord
;
#include
"algndflt.h"
struct
verify_pack1
{
char
x
[
sizeof
(
struct
record
)
==
0x2003
?
1
:
-1
];};
void
go_records
(
FILE
*
fdin
,
FILE
*
fdo
)
{
unsigned
char
stringlen
;
char
*
string
,
*
s
;
int
i
,
j
;
unsigned
char
chksum
;
do
{
if
(
fread
(
&
Record
,
1
,
3
,
fdin
)
!=
3
)
{
/* read type and reclen */
/* printf("end of fdin read\n"); */
break
;
}
if
(
Record
.
datalen
>
sizeof
(
Record
.
buffer
))
quit
(
"record to large : length %u Bytes \n"
,
Record
.
datalen
);
if
(
fread
(
Record
.
buffer
,
1
,
Record
.
datalen
,
fdin
)
!=
Record
.
datalen
)
{
printf
(
"invalid record format\n"
);
quit
(
"can't continue\n"
);
}
if
(
Record
.
rectyp
!=
0x96
&&
Record
.
rectyp
!=
0x8c
)
/* we are only interested in LNAMES */
{
fwrite
(
&
Record
,
1
,
3
+
Record
.
datalen
,
fdo
);
continue
;
}
/* printf("at %lx - record type %x len %x\n",ftell(fdin)-3,Record.rectyp,
Record.datalen);*/
Outrecord
.
rectyp
=
Record
.
rectyp
;
Outrecord
.
datalen
=
0
;
for
(
i
=
0
;
i
<
Record
.
datalen
-
1
;)
{
stringlen
=
(
unsigned
char
)
Record
.
buffer
[
i
];
i
++
;
string
=
&
Record
.
buffer
[
i
];
i
+=
stringlen
;
if
(
i
>
Record
.
datalen
)
quit
(
"invalid lnames record"
);
for
(
j
=
0
;
j
<
repl_count
;
j
++
)
if
(
memcmp
(
string
,
repl
[
j
].
sin
,
stringlen
)
==
0
&&
strlen
(
repl
[
j
].
sin
)
==
stringlen
)
{
string
=
repl
[
j
].
sout
;
stringlen
=
strlen
(
repl
[
j
].
sout
);
}
Outrecord
.
buffer
[
Outrecord
.
datalen
]
=
stringlen
;
Outrecord
.
datalen
++
;
memcpy
(
Outrecord
.
buffer
+
Outrecord
.
datalen
,
string
,
stringlen
);
Outrecord
.
datalen
+=
stringlen
;
}
chksum
=
0
;
for
(
s
=
(
char
*
)
&
Outrecord
;
s
<
&
Outrecord
.
buffer
[
Outrecord
.
datalen
];
s
++
)
chksum
+=
(
unsigned
char
)
*
s
;
Outrecord
.
buffer
[
Outrecord
.
datalen
]
=
~
chksum
;
Outrecord
.
datalen
++
;
/* printf("^sum = %02x - %02x\n",chksum,~chksum); */
fwrite
(
&
Outrecord
,
1
,
3
+
Outrecord
.
datalen
,
fdo
);
}
while
(
Record
.
rectyp
!=
0x00
/*ENDFIL*/
);
}
Back
|
FazBrowse Home
|
New Git URL