-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprntosym.c
268 lines (178 loc) · 4.62 KB
/
prntosym.c
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/* prntosym.c
Extract symbols from a PRN file (from ZSM v2.8).
(C) 2015 FloppySoftware (Miguel I. Garcia Lopez, Spain).
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
CONTACT:
www.floppysoftware.vacau.com
cpm-connections.blogspot.com
USAGE:
prntosym source [> destination]
TO COMPILE WITH MESCC:
cc prntosym
ccopt prntosym.zsm
zsm prntosym
hextocom prntosym
REVISIONS:
20 Aug 2015 : v1.00 : Initial version.
21 Aug 2015 : v1.01 : Added SKIP_INTERNAL and SKIP_SAMARUX defines.
Added EXIT to skipped symbol names in SamaruX.
24 Aug 2015 : v1.02 : Minor changes in file output.
04 Sep 2015 : v1.03 : Modified some comments and messages.
NOTES:
It was developed to support SamaruX external commands, but it can be useful on other matters too.
It skips some symbol names, if you define:
SKIP_INTERNAL : To skip symbols finishing with a decimal digit, like 'a32' (MESCC internal ones).
SKIP_SAMARUX : To skip following symbols:
CCFREEMEM
EXIT
MAIN
*/
/* MESCC DEFs
*/
#define CC_STDIO /* Support for stdin, stdout, stderr */
#define CC_REDIR /* Support for command line redirection */
#define CC_NO_SWITCH /* No switch */
/* MESCC libraries
*/
#include <mescc.h>
#include <conio.h>
#include <ctype.h>
#include <fileio.h>
#include <fprintf.h>
#include <string.h>
#include <mem.h>
#include <redir.h>
/* DEFs and globals
*/
#define SKIP_INTERNAL
#define SKIP_SAMARUX
#define VERSION "1.03 / 04 Sep 2015\n\n(c) 2015 FloppySoftware"
#define BUF_LEN 127 /* Max. lenght for input buffer */
#define BUF_SIZ 128 /* Size for input buffer */
FILE *fp; /* Input file FP */
char buf[BUF_SIZ]; /* Input buffer */
/* Main
*/
main(argc, argv)
int argc, argv[];
{
/* Show banner */
fprintf(stderr, "PrnToSym v%s\n\n", VERSION);
/* Check arguments */
if(argc != 2)
{
fprintf(stderr, "Usage: prntosym inputfile [> outputfile]\n");
exit(1);
}
/* Process input file */
procfile(argv[1]);
/* End */
fprintf(stderr, "Done.\n");
}
/* Process input file
*/
procfile(fn)
char *fn;
{
int k, flag;
/* Open file */
if((fp = fopen(fn, "r")) == NULL)
error("Opening input file");
/* Process file */
flag = 0;
while(1)
{
/* Read line */
if(fgets(buf, BUF_SIZ, fp) == NULL)
break;
/* Check EOL */
k = strlen(buf);
if(buf[--k] != '\n')
error("Line too long or missing newline");
/* Clear LF and put a ZERO instead */
buf[k] = 0;
/* Process line */
if(flag)
procline();
else if(!memcmp(buf, "Next", 4)) /* ie: Next address: CE05H */
++flag;
}
/* Close file */
fclose(fp);
}
/* Process input line
*/
procline()
{
char *p, name[12], adr[5];
int k, x;
/* Link to line */
p = buf;
/* Can be an empty or title line */
if(*p == 12 || !(*p))
return;
/* Each line can hold up to 4 symbols: */
/* NUMBER 52C5 NXTLAB BC5D OPFNAME BC7C ORFN 6144 */
while(isalpha(*p) || *p == '_')
{
/* Symbol name */
k = 0;
do {
name[k++] = *p++;
if(k == 12)
error("Symbol name too long");
} while(isalpha(*p) || *p == '_' || isdigit(*p));
name[k] = 0;
/* Skip blanks */
while(*p == ' ' || *p == '\t')
++p;
/* Address */
x = 0;
while(isxdigit(*p)) {
adr[x++] = *p++;
if(x == 5)
error("Bad symbol address");
}
adr[x] = 0;
/* Skip blanks */
while(*p == ' ' || *p == '\t')
++p;
#ifdef SKIP_INTERNAL
/* Skip symbols finishing with a decimal digit (MESCC internal ones) */
if(isdigit(name[k - 1]))
continue;
#endif
#ifdef SKIP_SAMARUX
/* Skip some symbols for SamaruX external commands */
if(!strcmp(name, "CCFREEMEM"))
continue;
if(!strcmp(name, "EXIT"))
continue;
if(!strcmp(name, "MAIN"))
continue;
#endif
/* Print symbol and address */
fprintf(stdout, "%-12s equ 0%sH\n", name, adr);
}
/* Check EOL */
if(*p)
error("Bad line format");
}
/* Print error and exit
*/
error(txt)
char *txt;
{
fprintf(stderr, "ERROR: %s.\n", txt); exit(1);
}