summaryrefslogtreecommitdiff
path: root/Arguments.c
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2022-10-19 21:16:13 +0100
committerAsh Wolf <ninji@wuffs.org>2022-10-19 21:16:13 +0100
commitd1f153d34b023d81768f6087f67dbfff714bafc9 (patch)
treea694d470a60655d0cda15a70791fbdb90a2398cf /Arguments.c
parent775b6861666af36d317fb577cf489e2c6377f878 (diff)
downloadMWCC-d1f153d34b023d81768f6087f67dbfff714bafc9.tar.gz
MWCC-d1f153d34b023d81768f6087f67dbfff714bafc9.zip
let's commit all this before my VM blows up and nukes my work
Diffstat (limited to '')
-rw-r--r--unsorted/Arguments.c (renamed from Arguments.c)85
1 files changed, 36 insertions, 49 deletions
diff --git a/Arguments.c b/unsorted/Arguments.c
index 324965a..c427a5a 100644
--- a/Arguments.c
+++ b/unsorted/Arguments.c
@@ -1,4 +1,4 @@
-#include "includes/mwcc_decomp.h"
+#include "parser.h"
char compat;
char *MAINOPTCHAR;
@@ -27,19 +27,6 @@ anon0_50 linkargs;
anon0_50 prelinkargs;
anon0_50 postlinkargs;
-// TODO move me
-/*extern int OS_MakeFileSpec(const char *name, struct OSSpec *spec);
-extern int OS_NewFileHandle(struct OSSpec *spec, int a, int b, OSFileHandle *fh);
-extern int OS_AppendHandle(struct OSHandle *h, const void *, long);
-extern int OS_LockFileHandle(OSFileHandle *fh, char **h, unsigned long *size);
-extern void OS_FreeFileHandle(OSFileHandle *fh);
-extern void CLPOSAlert(short code, short code2, ...);
-extern void CLPReportError(short code, ...);
-extern void CLPReportWarning(short code, ...);
-extern void CLPFatalError(const char *format, ...);
-extern int ustrncmp(const char *a, const char *b, int len);*/
-// TODO move me
-
static void Arg_AddToken(short val, char *text);
static void Arg_Setup(int argc, char **argv);
static void Arg_SkipRespFileWS();
@@ -64,7 +51,7 @@ static void Arg_AddToken(short val, char *text) {
else
prev = 0;
- if (prev && prev->val == ATK_2 && prev->text[0] == 0) {
+ if (prev && prev->val == ATK_ARG && prev->text[0] == 0) {
pppprev = ppprev = pprev = 0;
if (numargtoks > 3)
pppprev = &argtoks[numargtoks - 4];
@@ -74,12 +61,12 @@ static void Arg_AddToken(short val, char *text) {
pprev = &argtoks[numargtoks - 2];
if (pprev) {
- if ((int) val == ATK_1 && (pprev->val == ATK_5 || pprev->val == ATK_4) && (ppprev->val != ATK_2 || pppprev->val != ATK_3)) {
+ if ((int) val == ATK_ARG_END && (pprev->val == ATK_COMMA || pprev->val == ATK_EQUALS) && (ppprev->val != ATK_ARG || pppprev->val != ATK_OPTION)) {
if (parserDebug)
printf("Coalescing args with '%s'\n", Arg_GetTokenName(pprev));
val = pprev->val;
numargtoks -= 2;
- } else if (pprev->val == ATK_1 && ((int) val == ATK_5 || (int) val == ATK_4)) {
+ } else if (pprev->val == ATK_ARG_END && ((int) val == ATK_COMMA || (int) val == ATK_EQUALS)) {
if (parserDebug)
printf("Coalescing args, removing '%s'\n", Arg_GetTokenName(pprev));
numargtoks -= 2;
@@ -142,7 +129,7 @@ static unsigned char Arg_OpenRespFile(const char *name) {
|| (err = OS_AppendHandle(&respfilehandle.hand, "", 1))
|| (err = OS_LockFileHandle(&respfilehandle, &respfile, &respfilesize))
) {
- CLPOSAlert(74, (short) err, "response ", name);
+ CLPOSAlert(CLPStr74, (short) err, "response ", name);
return 0;
} else {
respfilestart = respfile;
@@ -255,7 +242,7 @@ static void Arg_Parse() {
if (arg[0] && arg[1] && strchr(MAINOPTCHAR, arg[0])) {
if (isOpt)
- Arg_AddToken(ATK_1, 0);
+ Arg_AddToken(ATK_ARG_END, 0);
buffer[0] = arg[1];
buffer[1] = 0;
isOpt = 1;
@@ -279,19 +266,19 @@ static void Arg_Parse() {
ch &= 0x7F;
*(bufptr++) = ch;
if (bufptr >= &buffer[sizeof(buffer)]) {
- CLPReportError(2, argstart, argstart + strlen(argstart) - 15, sizeof(buffer));
+ CLPReportError(CLPStr2, argstart, argstart + strlen(argstart) - 15, sizeof(buffer));
}
*bufptr = 0;
} else {
if (isOpt) {
- Arg_AddToken(ATK_3, buffer);
- Arg_AddToken(ATK_2, buffer);
+ Arg_AddToken(ATK_OPTION, buffer);
+ Arg_AddToken(ATK_ARG, buffer);
} else {
- Arg_AddToken(ATK_2, buffer);
+ Arg_AddToken(ATK_ARG, buffer);
}
Arg_AddToken(
- (unsigned char) ((ch == ',') ? ATK_5 : (((ch == '=') || (ch == SEP3)) ? ATK_4 : ATK_0)),
+ (unsigned char) ((ch == ',') ? ATK_COMMA : (((ch == '=') || (ch == SEP3)) ? ATK_EQUALS : ATK_END)),
0
);
@@ -308,17 +295,17 @@ static void Arg_Parse() {
// 1799C8
if (isOpt && bufptr > &buffer[0]) {
- Arg_AddToken(ATK_3, buffer + (isList && strchr(MAINOPTCHAR, buffer[0])));
- Arg_AddToken(ATK_2, buffer + (isList && strchr(MAINOPTCHAR, buffer[0])) + 1);
+ Arg_AddToken(ATK_OPTION, buffer + (isList && strchr(MAINOPTCHAR, buffer[0])));
+ Arg_AddToken(ATK_ARG, buffer + (isList && strchr(MAINOPTCHAR, buffer[0])) + 1);
} else {
- Arg_AddToken(ATK_2, buffer);
- Arg_AddToken(ATK_1, 0);
+ Arg_AddToken(ATK_ARG, buffer);
+ Arg_AddToken(ATK_ARG_END, 0);
}
}
if (isOpt || isList)
- Arg_AddToken(ATK_1, 0);
- Arg_AddToken(ATK_0, 0);
+ Arg_AddToken(ATK_ARG_END, 0);
+ Arg_AddToken(ATK_END, 0);
}
enum {
@@ -423,12 +410,12 @@ void Arg_Stop(ArgToken *where) {
cur = &argtoks[--numargtoks];
if (cur->text)
free(cur->text);
- cur->val = ATK_0;
+ cur->val = ATK_END;
cur->text = 0;
}
- argtoks[numargtoks++].val = ATK_1;
- argtoks[numargtoks++].val = ATK_0;
+ argtoks[numargtoks++].val = ATK_ARG_END;
+ argtoks[numargtoks++].val = ATK_END;
scantok = numargtoks - 2;
}
@@ -449,7 +436,7 @@ int Arg_IsEmpty() {
ArgToken *tok;
tok = Arg_PeekToken();
- return (tok == 0 || tok->val == ATK_0);
+ return (tok == 0 || tok->val == ATK_END);
}
ArgToken *Arg_GetToken() {
@@ -471,16 +458,16 @@ ArgToken *Arg_UndoToken() {
}
const char *Arg_GetTokenName(ArgToken *tok) {
- if ((int) tok->val == ATK_2)
+ if ((int) tok->val == ATK_ARG)
return tok->text;
return
- ((int) tok->val == ATK_3) ? "option" :
- ((int) tok->val == ATK_5) ? "comma" :
- (((int) compat == COMPAT_1 && (int) tok->val == ATK_4)) ? "colon or equals" :
- (((int) compat != COMPAT_1 && (int) tok->val == ATK_4)) ? "equals" :
- ((int) tok->val == ATK_1) ? "end of argument" :
- ((int) tok->val == ATK_0) ? "end of command line" :
+ ((int) tok->val == ATK_OPTION) ? "option" :
+ ((int) tok->val == ATK_COMMA) ? "comma" :
+ (((int) compat == COMPAT_1 && (int) tok->val == ATK_EQUALS)) ? "colon or equals" :
+ (((int) compat != COMPAT_1 && (int) tok->val == ATK_EQUALS)) ? "equals" :
+ ((int) tok->val == ATK_ARG_END) ? "end of argument" :
+ ((int) tok->val == ATK_END) ? "end of command line" :
"<error>";
}
@@ -491,7 +478,7 @@ const char *Arg_GetTokenText(ArgToken *tok, char *buffer, int maxlen, unsigned c
bptr = buffer;
curlen = 0;
- if (tok->val == ATK_2 || tok->val == ATK_3)
+ if (tok->val == ATK_ARG || tok->val == ATK_OPTION)
ptr = tok->text;
else
ptr = Arg_GetTokenName(tok);
@@ -505,7 +492,7 @@ const char *Arg_GetTokenText(ArgToken *tok, char *buffer, int maxlen, unsigned c
} else {
bptr[-1] = 0;
if (warn)
- CLPReportWarning(56, buffer, ptr + strlen(ptr) - ((maxlen <= 32) ? maxlen : 32), maxlen);
+ CLPReportWarning(CLPStr56, buffer, ptr + strlen(ptr) - ((maxlen <= 32) ? maxlen : 32), maxlen);
}
return buffer;
@@ -550,23 +537,23 @@ void Arg_InitToolArgs(anon0_50 *ta) {
void Arg_AddToToolArgs(anon0_50 *ta, short tokval, char *toktxt) {
switch (tokval) {
- case ATK_0:
+ case ATK_END:
Arg_FinishToolArgs(ta);
break;
- case ATK_1:
+ case ATK_ARG_END:
if (ta->argv && ta->argv[ta->argc])
Arg_GrowArgs(ta);
break;
- case ATK_2:
+ case ATK_ARG:
Arg_GrowArg(ta, toktxt);
break;
- case ATK_3:
+ case ATK_OPTION:
Arg_GrowArg(ta, "-");
break;
- case ATK_4:
+ case ATK_EQUALS:
Arg_GrowArg(ta, "=");
break;
- case ATK_5:
+ case ATK_COMMA:
Arg_GrowArg(ta, ",");
break;
default: