diff options
author | Ash Wolf <ninji@wuffs.org> | 2022-10-19 21:16:13 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2022-10-19 21:16:13 +0100 |
commit | d1f153d34b023d81768f6087f67dbfff714bafc9 (patch) | |
tree | a694d470a60655d0cda15a70791fbdb90a2398cf /Option.c | |
parent | 775b6861666af36d317fb577cf489e2c6377f878 (diff) | |
download | MWCC-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/Option.c (renamed from Option.c) | 164 |
1 files changed, 81 insertions, 83 deletions
diff --git a/Option.c b/unsorted/Option.c index c7e8093..410c807 100644 --- a/Option.c +++ b/unsorted/Option.c @@ -1,19 +1,17 @@ -#include "includes/mwcc_decomp.h" +#include "parser.h" #define MAXSTACK 8 -int oStackPtr; -Opt48 oStack[8]; -char curopt[1024]; -int maxlegalset; -int numlegalset; -int numinternalset; -static OptionList legalset; -static OptionList internalset; -int numoptionlists; static OptionList *optionlists[32]; - -extern char curparam[1024]; // check me +int numoptionlists; +static OptionList internalset; +static OptionList legalset; +int numinternalset; +int numlegalset; +int maxlegalset; +char curopt[1024]; +Opt48 oStack[8]; +int oStackPtr; enum { ARGFLAG_1 = 1, @@ -55,8 +53,8 @@ static void Option_PushList(OptionList *lst) { static void Option_PushOpt(Option *opt, const char *optname) { char *cpy; short flags = ARGFLAG_2; - if (opt && (opt->avail & OTF2)) { - if (Utils_CompareOptionString(opt->names, optname, opt->avail & OTF_CASED, OTF2)) { + if (opt && (opt->avail & OTF_STICKY)) { + if (Utils_CompareOptionString(opt->names, optname, opt->avail & OTF_CASED, OTF_STICKY)) { flags |= ARGFLAG_80; } } @@ -224,11 +222,11 @@ void Options_SortOptions() { if (numinternalset > 0) { legalset.list = (Option **) xrealloc("options", legalset.list, sizeof(Option *) * (numinternalset + 1)); for (r = 0; r < numinternalset; r++) { - if (internalset.list[r]->avail & (OTF2 | OTF_CASED)) + if (internalset.list[r]->avail & (OTF_STICKY | OTF_CASED)) legalset.list[numlegalset++] = internalset.list[r]; } for (r = 0; r < numinternalset; r++) { - if (!(internalset.list[r]->avail & (OTF2 | OTF_CASED))) + if (!(internalset.list[r]->avail & (OTF_STICKY | OTF_CASED))) legalset.list[numlegalset++] = internalset.list[r]; } legalset.list[numlegalset] = 0; @@ -282,7 +280,7 @@ static void Options_Reset(OptionList *optlst) { os = optlst->list; if (os) { for (; *os; os++) { - (*os)->avail &= ~(OTF80000000 | OTF40000000); + (*os)->avail &= ~(OTF_INTERNAL_ALREADY_SEEN | OTF_INTERNAL_SEEN_CONFLICTED); } } } @@ -332,7 +330,7 @@ static void Option_SpellList(char *buffer, OptionList *conflicts, int flags) { total++; buffer += sprintf(buffer, "%s", tmp); - if ((*scan)->avail & OTF8000) + if ((*scan)->avail & OTF_HAS_SUB_OPTIONS) buffer += sprintf(buffer, " ..."); } scan++; @@ -364,14 +362,14 @@ static Boolean Option_ContinuesThisLevel(int level, ArgToken *tok) { int ret; // not in stabs but i think this exists if (level == 1) { - return (tok->val == ATK_1) || (tok->val == ATK_3) || (tok->val == ATK_2); + return (tok->val == ATK_ARG_END) || (tok->val == ATK_OPTION) || (tok->val == ATK_ARG); } else if (level == 2) { tmp = Arg_UsedToken(); - ret = (tok->val == ATK_5 && tmp->val != ATK_3) || (tok->val == ATK_2 && tmp->val != ATK_1); + ret = (tok->val == ATK_COMMA && tmp->val != ATK_OPTION) || (tok->val == ATK_ARG && tmp->val != ATK_ARG_END); Arg_UndoToken(); return ret; } else if (level == 3) { - return (tok->val == ATK_4) || (tok->val == ATK_2); + return (tok->val == ATK_EQUALS) || (tok->val == ATK_ARG); } else { return 0; } @@ -439,21 +437,21 @@ int Option_Parse(Option *opt, int oflags) { if (samelevel) { if (!(flags & PFLAGS_1)) { - if ((opt->avail & OTF80000000) && (opt->avail & OTF20000)) { - Option_Warning(30); - } else if (opt->avail & OTF40000) { + if ((opt->avail & OTF_INTERNAL_ALREADY_SEEN) && (opt->avail & OTF_ONLY_ONCE)) { + Option_Warning(CLPStr30_OptionShouldNotBeSpecifiedMultipleTimes); + } else if (opt->avail & OTF_HAS_CONFLICTS) { cscan = opt->conflicts->list; - while (*cscan && (*cscan == opt || !((*cscan)->avail & OTF80000000))) { + while (*cscan && (*cscan == opt || !((*cscan)->avail & OTF_INTERNAL_ALREADY_SEEN))) { ++cscan; } if (*cscan && *cscan != opt) { - (*cscan)->avail &= ~OTF80000000; + (*cscan)->avail &= ~OTF_INTERNAL_ALREADY_SEEN; Option_SpellList(errstr, opt->conflicts, oflags); if (opt->conflicts->help) - Option_Warning(32, (*cscan)->names, errstr, opt->conflicts->help); + Option_Warning(CLPStr32_OptionOverridesEffectWithHelp, (*cscan)->names, errstr, opt->conflicts->help); else - Option_Warning(31, (*cscan)->names, errstr); + Option_Warning(CLPStr31_OptionOverridesEffect, (*cscan)->names, errstr); } } } @@ -463,48 +461,48 @@ int Option_Parse(Option *opt, int oflags) { if (!Option_ForThisTool(opt)) flags |= PFLAGS_1; if (!subparse) - Arg_AddToToolArgs(&linkargs, ATK_1, 0); + Arg_AddToToolArgs(&linkargs, ATK_ARG_END, 0); Args_AddToToolArgs(&linkargs); } if (!(flags & PFLAGS_1)) { if (opt->avail & OTF_OBSOLETE) { if (opt->help) - Option_Error(22, opt->help); + Option_Error(CLPStr22_OptionObsoleteWithHelp, opt->help); else - Option_Error(21); + Option_Error(CLPStr21_OptionObsolete); flags |= PFLAGS_1; } if (opt->avail & OTF_IGNORED) { if (!(opt->avail & (OTF_WARNING | OTF_MEANINGLESS))) { if (opt->help) - Option_Warning(27, opt->help); + Option_Warning(CLPStr27_OptionIgnoredWithText, opt->help); else - Option_Warning(26); + Option_Warning(CLPStr26_OptionIgnored); } flags |= PFLAGS_1; } else if (opt->avail & OTF_SUBSTITUTED) { - Option_Warning(23, curopt, opt->help); + Option_Warning(CLPStr23_OptionXSubstitutedWithX, curopt, opt->help); } else if (opt->avail & OTF_DEPRECATED) { if (opt->help) - Option_Warning(25, opt->help); + Option_Warning(CLPStr25_OptionDeprecatedWithHelp, opt->help); else - Option_Warning(24); + Option_Warning(CLPStr24_OptionDeprecated); } if (opt->avail & OTF_WARNING) - Option_Warning(28, opt->help); + Option_Warning(CLPStr28_WarningText, opt->help); if (opt->avail & OTF_MEANINGLESS) - Option_Warning(29); + Option_Warning(CLPStr29_OptionHasNoEffect); } - opt->avail |= OTF80000000; - if (opt->avail & OTF40000) { + opt->avail |= OTF_INTERNAL_ALREADY_SEEN; + if (opt->avail & OTF_HAS_CONFLICTS) { scan = opt->conflicts->list; - opt->avail |= OTF40000000; + opt->avail |= OTF_INTERNAL_SEEN_CONFLICTED; while (*scan) { - (*scan)->avail |= OTF40000000; + (*scan)->avail |= OTF_INTERNAL_SEEN_CONFLICTED; scan++; } } @@ -512,12 +510,12 @@ int Option_Parse(Option *opt, int oflags) { flags |= PFLAGS_1; } - goingtosubparse = opt->avail & OTF8000; + goingtosubparse = opt->avail & OTF_HAS_SUB_OPTIONS; if (opt->param) { ret = Params_Parse(opt->param, flags | (goingtosubparse ? PFLAGS_20 : 0)); } else { tok = Arg_PeekToken(); - if (tok && tok->val == ATK_4) + if (tok && tok->val == ATK_EQUALS) Arg_UsedToken(); } @@ -528,7 +526,7 @@ int Option_Parse(Option *opt, int oflags) { | OFLAGS_2 | ((flags & PFLAGS_1) ? OFLAGS_40 : 0) | (subparse ? OFLAGS_10 : 0) - | ((opt->avail & OTF10000) ? OFLAGS_4 : 0) + | ((opt->avail & OTF_SUB_OPTIONS_OPTIONAL) ? OFLAGS_4 : 0) ); } @@ -536,7 +534,7 @@ int Option_Parse(Option *opt, int oflags) { Option_PopOpt(curopt); if (Option_ThisTool() == OTF_TOOL_COMPILER && !subparse) - Arg_AddToToolArgs(&linkargs, ATK_1, 0); + Arg_AddToToolArgs(&linkargs, ATK_ARG_END, 0); return ret; } @@ -610,7 +608,7 @@ static Option *Option_Lookup(OptionList *search, int unk, int *flags) { if (os) { while (*os) { names = (*os)->names; - if (((*os)->avail & OTF2) == OTF2) { + if (((*os)->avail & OTF_STICKY) == OTF_STICKY) { while (*names && *names != '|') ++names; if (*names) @@ -625,10 +623,10 @@ static Option *Option_Lookup(OptionList *search, int unk, int *flags) { return *os; } - if ((*os)->avail & OTF2) { + if ((*os)->avail & OTF_STICKY) { matched = Utils_CompareOptionString((*os)->names, curopt, (*os)->avail & OTF_CASED, 2); if (matched) - stickyflags |= OTF2; + stickyflags |= OTF_STICKY; } else { matched = 0; } @@ -680,11 +678,11 @@ static int Options_DoParse(OptionList *search, int flags) { starttok = Arg_PeekToken(); // i think this is starttok while ((token_r18 = Arg_PeekToken())) { parsedany = 0; - isOpt = ((mystery_r31 == 1) && (token_r18->val == ATK_3)) || ((mystery_r31 == 2) && (token_r18->val == ATK_2) && (token_r18->text[0] || search->flags & LISTFLAGS_4)) || ((mystery_r31 == 3) && (token_r18->val == ATK_4)); + isOpt = ((mystery_r31 == 1) && (token_r18->val == ATK_OPTION)) || ((mystery_r31 == 2) && (token_r18->val == ATK_ARG) && (token_r18->text[0] || search->flags & LISTFLAGS_4)) || ((mystery_r31 == 3) && (token_r18->val == ATK_EQUALS)); // 950 17CFD4 if ((mystery_r31 == 3) && isOpt) { token_r18 = Arg_UsedToken(); - isOpt = token_r18 && (token_r18->val == ATK_2); + isOpt = token_r18 && (token_r18->val == ATK_ARG); flags &= ~OFLAGS_4; } // 957 17D00C @@ -700,7 +698,7 @@ static int Options_DoParse(OptionList *search, int flags) { opttok = token_r18; if (!(matchflags & 2)) { // 972 - if (token_r18->val == ATK_3) + if (token_r18->val == ATK_OPTION) Arg_UsedToken(); token_r18 = Arg_UsedToken(); } else { @@ -717,7 +715,7 @@ static int Options_DoParse(OptionList *search, int flags) { if (!token_r18->text || !token_r18->text[0]) { Option_PushOpt(0, curopt); - Option_ParamError(34, curopt); + Option_ParamError(CLPStr34_ArgumentsExpected, curopt); Option_PopOpt(0); return 0; } @@ -739,7 +737,7 @@ static int Options_DoParse(OptionList *search, int flags) { if (opt) { if (opt->names[0]) token_r18 = Arg_UsedToken(); - if (token_r18->val == ATK_4) + if (token_r18->val == ATK_EQUALS) Arg_UsedToken(); haderrors = Option_Parse(opt, flags) == 0; parsedany = 1; @@ -760,32 +758,32 @@ static int Options_DoParse(OptionList *search, int flags) { if ((flags & OFLAGS_4) && token_r18 == starttok) return haderrors == 0; // 1072 - if (search->flags & LISTFLAGS_2) { + if (search->flags & LISTFLAGS_ALLOW_UNKNOWNS) { if (!(flags & OFLAGS_1)) { Option_SpellList(curparam, search, flags); - Option_Warning(20, token_r18->text, curparam); + Option_Warning(CLPStr20_UnknownOptionX_ExpectedOneOfX, token_r18->text, curparam); } Arg_UsedToken(); parsedany = 1; } else { // 1090 Option_SpellList(curparam, search, flags); - Option_Error(20, token_r18->text, curparam); + Option_Error(CLPStr20_UnknownOptionX_ExpectedOneOfX, token_r18->text, curparam); failed = 1; haderrors++; } } else { // 1099 - if ((search->flags & LISTFLAGS_2) || parseopts.ignoreUnknown) { + if ((search->flags & LISTFLAGS_ALLOW_UNKNOWNS) || parseopts.ignoreUnknown) { // 1101 if (!(flags & OFLAGS_1)) - Option_Warning(19, token_r18->text); + Option_Warning(CLPStr19_UnknownOptionX, token_r18->text); Arg_UsedToken(); Arg_GetToken(); parsedany = 1; } else { // 1115 - Option_Error(19, token_r18->text); + Option_Error(CLPStr19_UnknownOptionX, token_r18->text); failed = 1; haderrors++; } @@ -803,14 +801,14 @@ static int Options_DoParse(OptionList *search, int flags) { failed = 1; parsedany++; } // else: goto 1229 - } else if ((mystery_r31 == 1) && (token_r18->val == ATK_2)) { + } else if ((mystery_r31 == 1) && (token_r18->val == ATK_ARG)) { // 1142 opttok = 0; curopt[0] = 0; opt = Option_Lookup(search, 0, &matchflags); strcpy(curopt, token_r18->text); if (!opt) { - Option_Warning(33, curopt); + Option_Warning(CLPStr33_NoDefaultHandlerSetUpForX_Ignoring, curopt); failed = 1; } else { if (!(flags & OFLAGS_1)) { @@ -840,7 +838,7 @@ static int Options_DoParse(OptionList *search, int flags) { if (!opt) { // 1205 if (!(flags & OFLAGS_4)) { - Option_Error(34, saveopt); + Option_Error(CLPStr34_ArgumentsExpected, saveopt); failed = 1; haderrors++; } else { @@ -863,7 +861,7 @@ static int Options_DoParse(OptionList *search, int flags) { tok = Arg_PeekToken(); // 1231 if (!failed) { - if (tok && (tok->val == ATK_2) && (matchflags & 2)) { + if (tok && (tok->val == ATK_ARG) && (matchflags & 2)) { // 1235 ArgToken *prev; // r16 char sticky[64]; // stack 0x3C @@ -874,10 +872,10 @@ static int Options_DoParse(OptionList *search, int flags) { strcpy(sticky, opttok->text); sticky[strlen(tok->text)] = 0; Option_PushOpt(0, sticky); - Param_Error(36, Arg_GetTokenName(tok)); + Param_Error(CLPStr36_UnexpectedAdditionalArgumentX, Arg_GetTokenName(tok)); Option_PopOpt(0); } else { - CLPReportError(36, Arg_GetTokenName(tok)); + CLPReportError(CLPStr36_UnexpectedAdditionalArgumentX, Arg_GetTokenName(tok)); } // 1251 haderrors++; @@ -900,21 +898,21 @@ static int Options_DoParse(OptionList *search, int flags) { ArgToken *prev = tok; // r16 tok = Arg_UsedToken(); // 1278 - if ((mystery_r31 != 1) || (tok->val != ATK_3)) { + if ((mystery_r31 != 1) || (tok->val != ATK_OPTION)) { // 1280 if (opttok) { Option_PushOpt(0, opttok->text); - if (tok->val == ATK_2) - Param_Error(36, Arg_GetTokenName(tok)); + if (tok->val == ATK_ARG) + Param_Error(CLPStr36_UnexpectedAdditionalArgumentX, Arg_GetTokenName(tok)); else - Param_Error(35, Arg_GetTokenName(prev)); + Param_Error(CLPStr35_TokenXNotExpected, Arg_GetTokenName(prev)); Option_PopOpt(opttok->text); - } else if (tok->val == ATK_2) { + } else if (tok->val == ATK_ARG) { // 1292 - CLPReportError(36, Arg_GetTokenName(tok)); + CLPReportError(CLPStr36_UnexpectedAdditionalArgumentX, Arg_GetTokenName(tok)); } else { // 1294 - CLPReportError(35, Arg_GetTokenName(prev)); + CLPReportError(CLPStr35_TokenXNotExpected, Arg_GetTokenName(prev)); } haderrors++; failed++; @@ -924,15 +922,15 @@ static int Options_DoParse(OptionList *search, int flags) { // 1303 if (opttok) { Option_PushOpt(0, opttok->text); - if (tok->val == ATK_2) - Param_Error(36, Arg_GetTokenName(tok)); + if (tok->val == ATK_ARG) + Param_Error(CLPStr36_UnexpectedAdditionalArgumentX, Arg_GetTokenName(tok)); else - Param_Error(35, Arg_GetTokenName(tok)); + Param_Error(CLPStr35_TokenXNotExpected, Arg_GetTokenName(tok)); Option_PopOpt(opttok->text); - } else if (tok->val == ATK_2) { - CLPReportError(36, Arg_GetTokenName(tok)); + } else if (tok->val == ATK_ARG) { + CLPReportError(CLPStr36_UnexpectedAdditionalArgumentX, Arg_GetTokenName(tok)); } else { - CLPReportError(35, Arg_GetTokenName(tok)); + CLPReportError(CLPStr35_TokenXNotExpected, Arg_GetTokenName(tok)); } haderrors++; failed++; @@ -1115,11 +1113,11 @@ int Option_Help(const char *opt) { if (find) { Help_Init(); if (!Help_Option(Options_GetOptions(), find, 0, "")) - CLPReportWarning(38, opt); + CLPReportWarning(CLPStr38_NoHelpAvailableForOptionX, opt); Help_Term(); ret = 1; } else { - Option_Error(19, opt); + Option_Error(CLPStr19_UnknownOptionX, opt); ret = 0; } @@ -1130,7 +1128,7 @@ int Option_Help(const char *opt) { int Options_DisplayHelp() { if (parseopts.helpFlags & HELPFLAGS_1) - Option_Help(parseopts.helpKey); + return Option_Help(parseopts.helpKey); else - Options_Help(parseopts.helpKey); + return Options_Help(parseopts.helpKey); } |