2 dZ80 Parse Command Line
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
[])
25 d
->parametersModified
= 0;
28 for (i
= startArgc
; i
< argc
; i
++)
30 if (argv
[i
][0] == '/' || argv
[i
][0] == '-')
32 switch (tolower(argv
[i
][1]))
35 d
->flags
|= DISFLAG_LABELLED
;
39 if (GetDWord(&argv
[i
][2], &d
->fileHeaderSize
))
45 if (GetWord(&argv
[i
][2], &d
->fileStartAddr
))
51 if (GetWord(&argv
[i
][2], &d
->start
))
53 d
->parametersModified
|= DPM_STARTADDR
;
58 if (GetWord(&argv
[i
][2], &d
->end
))
60 d
->parametersModified
|= DPM_ENDADDR
;
65 if (CopyStringParam(d
->opMapFileName
, &argv
[i
][2], sizeof(d
->opMapFileName
)) )
71 if (CopyStringParam(d
->refFileName
, &argv
[i
][2], sizeof(d
->refFileName
)) )
77 d
->flags
&= ~DISFLAG_ADDRDUMP
;
82 d
->flags
&= ~DISFLAG_OPCODEDUMP
;
87 d
->flags
|= DISFLAG_UPPER
;
92 d
->flags
|= DISFLAG_QUIET
;
97 CopyStringParam(cpu
, &argv
[i
][2], sizeof(cpu
));
100 for(j
=0; j
< DCPU_TOTAL
; j
++)
102 if (!(stricmp(cpu
, dZ80CpuTypeNames
[j
])))
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
]);
121 d
->flags
&= ~DISFLAG_USELABELADDRS
;
126 d
->flags
&= ~DISFLAG_LINECOMMANDS
;
130 switch (tolower(argv
[i
][2]))
134 d
->flags
|= DISFLAG_REFOUTPORT
;
139 d
->flags
|= DISFLAG_REFINPORT
;
144 d
->flags
|= DISFLAG_REFADDR
;
149 d
->flags
|= DISFLAG_REFINDIRECT
;
154 d
->flags
|= DISFLAG_REFLIMITRANGE
;
159 printf("Unknown reference type \"%c\". Valid types are o, i, a, n and r.\n", argv
[i
][2]);
171 if (CopyStringParam(d
->layoutDefineByte
, &argv
[i
][2], sizeof(d
->layoutDefineByte
)))
177 if (CopyStringParam(d
->layoutComment
, &argv
[i
][2], sizeof(d
->layoutComment
)))
183 if (CopyStringParam(reqLayoutNumberPrefix
, &argv
[i
][2], sizeof(reqLayoutNumberPrefix
)))
185 d
->parametersModified
|= DPM_NUMPREFIX
;
190 if (CopyStringParam(reqLayoutNumberSuffix
, &argv
[i
][2], sizeof(reqLayoutNumberSuffix
)))
192 d
->parametersModified
|= DPM_NUMSUFFIX
;
197 if (GetWord(&argv
[i
][2], &r
))
203 disRadix
= DRADIX_OCTAL
;
207 disRadix
= DRADIX_DECIMAL
;
211 disRadix
= DRADIX_HEX
;
215 printf("Radix must be 8, 10 or 16\n"
216 " Use -? for help.\n");
223 d
->flags
|= DISFLAG_RELCOMMENT
;
227 if (CopyStringParam(d
->scriptFileName
, &argv
[i
][2], sizeof(d
->scriptFileName
)) )
236 printf("Don't know what to do with \"%s\".\n\n", argv
[i
]);
237 printf(" Use -? for help.\n");
243 if (numFileNames
>= 1)
245 if (numFileNames
>= 2)
247 printf("Already have two file names.\n");
252 strcpy(d
->outFileName
, argv
[i
]);
257 strcpy(d
->srcFileName
, argv
[i
]);
262 } /* for (i = 1; i < argc; i++) */
268 static int GetDWord(char *Str
, DWORD
*pDW
)
275 *pDW
= (DWORD
)strtol(Str
, &pEnd
, 0);
279 printf("Invalid number \"%s\".\n"
280 " Use -? for help.\n", Str
);
287 static int GetWord(char *Str
, WORD
*pWord
)
294 *pWord
= (WORD
)strtol(Str
, &pEnd
, 0);
298 printf("Invalid number \"%s\".\n"
299 " Use -? for help.\n", Str
);
307 static int CopyStringParam(char *dst
, char *src
, int maxlen
)
312 if (strlen(src
) == 0)
314 printf("Missing string\n"
315 " Use -? for help.\n");
319 dZ80_SafeStringCopy(dst
, src
, maxlen
);