Add VCS links
[debian-dgen.git] / dz80 / parsecmd.c
blob546c50b8d4bffeda0b073a13f9396c5b4e24ac76
1 /*
2 dZ80 Parse Command Line
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <ctype.h>
8 #include <string.h>
10 #include "types.h"
11 #include "dissz80.h"
12 #include "dz80.h"
14 static int GetDWord(char *Str, DWORD *pDW);
15 static int GetWord(char *Str, WORD *pWord);
16 static int CopyStringParam(char *dst, char *src, int maxlen);
18 int ParseCmdLine(DISZ80 *d, int startArgc, int argc, char* argv[])
20 int i, numFileNames;
21 WORD r;
22 char j, cpu[16];
24 d->flagsModified = 0;
25 d->parametersModified = 0;
26 numFileNames = 0;
28 for (i = startArgc; i < argc; i++)
30 if (argv[i][0] == '/' || argv[i][0] == '-')
32 switch (tolower(argv[i][1]))
34 case 'l':
35 d->flags |= DISFLAG_LABELLED;
36 continue;
38 case 'h':
39 if (GetDWord(&argv[i][2], &d->fileHeaderSize))
40 return TRUE;
41 continue;
44 case 'm':
45 if (GetWord(&argv[i][2], &d->fileStartAddr))
46 return TRUE;
47 continue;
50 case 's':
51 if (GetWord(&argv[i][2], &d->start))
52 return TRUE;
53 d->parametersModified |= DPM_STARTADDR;
54 continue;
57 case 'e':
58 if (GetWord(&argv[i][2], &d->end))
59 return TRUE;
60 d->parametersModified |= DPM_ENDADDR;
61 continue;
64 case 'o':
65 if (CopyStringParam(d->opMapFileName, &argv[i][2], sizeof(d->opMapFileName)) )
66 return TRUE;
67 continue;
70 case 'r':
71 if (CopyStringParam(d->refFileName, &argv[i][2], sizeof(d->refFileName)) )
72 return TRUE;
73 continue;
76 case 'a':
77 d->flags &= ~DISFLAG_ADDRDUMP;
78 continue;
81 case 'n':
82 d->flags &= ~DISFLAG_OPCODEDUMP;
83 continue;
86 case 'u':
87 d->flags |= DISFLAG_UPPER;
88 continue;
91 case 'q':
92 d->flags |= DISFLAG_QUIET;
93 continue;
96 case 'z':
97 CopyStringParam(cpu, &argv[i][2], sizeof(cpu));
100 for(j=0; j < DCPU_TOTAL; j++)
102 if (!(stricmp(cpu, dZ80CpuTypeNames[j])))
104 d->cpuType = j;
105 break;
109 if (j >= DCPU_TOTAL)
111 printf("Unknown CPU type \"%s\". Must be one of the following:\n\n", cpu);
112 for(j=0; j < DCPU_TOTAL; j++)
113 printf("%s\n", dZ80CpuTypeNames[j]);
114 return TRUE;
117 continue;
120 case 'b':
121 d->flags &= ~DISFLAG_USELABELADDRS;
122 continue;
125 case 'w':
126 d->flags &= ~DISFLAG_LINECOMMANDS;
127 continue;
129 case 'x':
130 switch (tolower(argv[i][2]))
133 case 'o':
134 d->flags |= DISFLAG_REFOUTPORT;
135 break;
138 case 'i':
139 d->flags |= DISFLAG_REFINPORT;
140 break;
143 case 'a':
144 d->flags |= DISFLAG_REFADDR;
145 break;
148 case 'n':
149 d->flags |= DISFLAG_REFINDIRECT;
150 break;
153 case 'r':
154 d->flags |= DISFLAG_REFLIMITRANGE;
155 break;
158 default:
159 printf("Unknown reference type \"%c\". Valid types are o, i, a, n and r.\n", argv[i][2]);
160 return TRUE;
162 continue;
165 case '?':
166 ShowUsage();
167 return TRUE;
169 /* Added for 1.50 */
170 case 'd':
171 if (CopyStringParam(d->layoutDefineByte, &argv[i][2], sizeof(d->layoutDefineByte)))
172 return TRUE;
173 continue;
176 case 'f':
177 if (CopyStringParam(d->layoutComment, &argv[i][2], sizeof(d->layoutComment)))
178 return TRUE;
179 continue;
182 case 'p':
183 if (CopyStringParam(reqLayoutNumberPrefix, &argv[i][2], sizeof(reqLayoutNumberPrefix)))
184 return TRUE;
185 d->parametersModified |= DPM_NUMPREFIX;
186 continue;
189 case 'y':
190 if (CopyStringParam(reqLayoutNumberSuffix, &argv[i][2], sizeof(reqLayoutNumberSuffix)))
191 return TRUE;
192 d->parametersModified |= DPM_NUMSUFFIX;
193 continue;
196 case 'i':
197 if (GetWord(&argv[i][2], &r))
198 return TRUE;
200 switch(r)
202 case 8:
203 disRadix = DRADIX_OCTAL;
204 break;
206 case 10:
207 disRadix = DRADIX_DECIMAL;
208 break;
210 case 16:
211 disRadix = DRADIX_HEX;
212 break;
214 default:
215 printf("Radix must be 8, 10 or 16\n"
216 " Use -? for help.\n");
217 return TRUE;
219 continue;
221 /* 2.0 */
222 case 'j':
223 d->flags |= DISFLAG_RELCOMMENT;
224 continue;
226 case 'k':
227 if (CopyStringParam(d->scriptFileName, &argv[i][2], sizeof(d->scriptFileName)) )
228 return TRUE;
229 continue;
231 case 'v':
232 showVersion = TRUE;
233 continue;
235 default:
236 printf("Don't know what to do with \"%s\".\n\n", argv[i]);
237 printf(" Use -? for help.\n");
238 return TRUE;
243 if (numFileNames >= 1)
245 if (numFileNames >= 2)
247 printf("Already have two file names.\n");
248 return(1);
250 else
252 strcpy(d->outFileName, argv[i]);
255 else
257 strcpy(d->srcFileName, argv[i]);
260 numFileNames++;
262 } /* for (i = 1; i < argc; i++) */
264 return FALSE;
268 static int GetDWord(char *Str, DWORD *pDW)
270 char *pEnd;
272 if (Str[0] == '=')
273 Str++;
275 *pDW = (DWORD)strtol(Str, &pEnd, 0);
277 if (pEnd == Str)
279 printf("Invalid number \"%s\".\n"
280 " Use -? for help.\n", Str);
281 return TRUE;
284 return FALSE;
287 static int GetWord(char *Str, WORD *pWord)
289 char *pEnd;
291 if (Str[0] == '=')
292 Str++;
294 *pWord = (WORD)strtol(Str, &pEnd, 0);
296 if (pEnd == Str)
298 printf("Invalid number \"%s\".\n"
299 " Use -? for help.\n", Str);
300 return TRUE;
303 return FALSE;
307 static int CopyStringParam(char *dst, char *src, int maxlen)
309 if (src[0] == '=')
310 src++;
312 if (strlen(src) == 0)
314 printf("Missing string\n"
315 " Use -? for help.\n");
316 return TRUE;
319 dZ80_SafeStringCopy(dst, src, maxlen);
320 return FALSE;