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 /unsorted | |
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/Arguments.c (renamed from Arguments.c) | 85 | ||||
-rw-r--r-- | unsorted/Help.c (renamed from Help.c) | 31 | ||||
-rw-r--r-- | unsorted/IO.c | 6 | ||||
-rw-r--r-- | unsorted/OptimizerHelpers.c | 166 | ||||
-rw-r--r-- | unsorted/Option.c (renamed from Option.c) | 164 | ||||
-rw-r--r-- | unsorted/Parameter.c (renamed from Parameter.c) | 32 | ||||
-rw-r--r-- | unsorted/ParserErrors.c | 2 | ||||
-rw-r--r-- | unsorted/ParserFace.c | 28 | ||||
-rw-r--r-- | unsorted/ParserHelpers-cc.c | 22 | ||||
-rw-r--r-- | unsorted/ParserHelpers.c | 65 | ||||
-rw-r--r-- | unsorted/Projects.c | 3 | ||||
-rw-r--r-- | unsorted/StaticParserGlue.c | 3 | ||||
-rw-r--r-- | unsorted/TargetOptimizer-ppc-mach.c | 69 | ||||
-rw-r--r-- | unsorted/Targets.c | 6 | ||||
-rw-r--r-- | unsorted/ToolHelpers-cc.c | 5 | ||||
-rw-r--r-- | unsorted/ToolHelpers.c | 32 | ||||
-rw-r--r-- | unsorted/Utils.c | 174 | ||||
-rw-r--r-- | unsorted/uCOS.c | 292 | ||||
-rw-r--r-- | unsorted/uContextParser.cpp | 2 | ||||
-rw-r--r-- | unsorted/uLibImporter.c | 103 |
20 files changed, 1041 insertions, 249 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: @@ -1,4 +1,5 @@ -#include "includes/mwcc_decomp.h" +#include "parser.h" + typedef struct _Side { short offset; short width; @@ -8,12 +9,12 @@ typedef struct _Side { short indent; short vrow; short vcol; - unsigned char atEOL; - unsigned char impInd; + Boolean atEOL; + Boolean impInd; } Side; short helpExtras; -unsigned char showedHelp; +Boolean showedHelp; Side left; Side right; Side all; @@ -217,7 +218,7 @@ int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const if (!(parseopts.helpFlags & HELPFLAGS_NORMAL) && !(opt->avail & OTF_ALL_HIDDEN_BY_DEFAULT)) return 0; - if (opt->help || (opt->avail & OTF8000)) { + if (opt->help || (opt->avail & OTF_HAS_SUB_OPTIONS)) { allNoArgs = 1; lastparam = 0; if (parseopts.helpFlags & HELPFLAGS_SPACES) @@ -239,7 +240,7 @@ int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const slflags = slflags | SLFLAGS_20; break; } - if (opt->avail & OTF2) + if (opt->avail & OTF_STICKY) slflags = slflags | SLFLAGS_40; Utils_SpellList(opt->names[0] ? opt->names : "...", pfbuf, slflags); @@ -323,7 +324,7 @@ int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const Side_Print(&left, "[%s", (scan != firstparam) ? "," : subprint ? "=" : SEPOPTSTR); } } else { - Side_Print(&left, (scan != firstparam) ? "," : subprint ? "=" : ((opt->avail & OTF2) && !strchr(opt->names, '|')) ? "" : SEPOPTSTR); + Side_Print(&left, (scan != firstparam) ? "," : subprint ? "=" : ((opt->avail & OTF_STICKY) && !strchr(opt->names, '|')) ? "" : SEPOPTSTR); } Side_Print(&left, "%s", desc); if (((scan->flags & PARAMFLAGS_3) == PARAMFLAGS_2) && scan->which != PARAMWHICH_Setting && scan->which != PARAMWHICH_IfArg) { @@ -335,7 +336,7 @@ int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const else Side_Print(&right, "; if parameter specified, %s", help); } - if (defaul && !(opt->avail & OTF2000)) { + if (defaul && !(opt->avail & OTF_HIDE_DEFAULT)) { if (firstparam == scan) Side_Print(&right, "; default is %s", defaul); else @@ -347,7 +348,7 @@ int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const scan = scan->next; } - if (allNoArgs && !(opt->avail & OTF2000)) { + if (allNoArgs && !(opt->avail & OTF_HIDE_DEFAULT)) { PARAM_T *scan = opt->param; Boolean isdefault = scan ? 1 : 0; while (scan && isdefault) { @@ -363,15 +364,15 @@ int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const if (opt->avail & OTF_MEANINGLESS) Side_Print(&right, "; meaningless for this target"); - if ((opt->avail & OTF8000) && opt->sub) { + if ((opt->avail & OTF_HAS_SUB_OPTIONS) && opt->sub) { if (!allNoArgs) { Side_Print( &left, "%s", - (opt->avail & OTF10000) ? ((lastparam->flags & PARAMFLAGS_8) ? "[=" : "[,") : ((lastparam->flags & PARAMFLAGS_8) ? "," : "=") + (opt->avail & OTF_SUB_OPTIONS_OPTIONAL) ? ((lastparam->flags & PARAMFLAGS_8) ? "[=" : "[,") : ((lastparam->flags & PARAMFLAGS_8) ? "," : "=") ); - } else if (!(opt->avail & OTF2)) { - if (opt->avail & OTF10000) { + } else if (!(opt->avail & OTF_STICKY)) { + if (opt->avail & OTF_SUB_OPTIONS_OPTIONAL) { if (SEPOPTSTR[0] == ' ') Side_Print(&left, subprint ? "[=" : " ["); else @@ -380,7 +381,7 @@ int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const Side_Print(&left, "%c", subprint ? '=' : SEPOPTSTR[0]); } } else { - if (opt->avail & OTF10000) { + if (opt->avail & OTF_SUB_OPTIONS_OPTIONAL) { Side_Print(&left, subprint ? "[" : (SEPOPTSTR[0] == ' ') ? " [" : "["); } } @@ -390,7 +391,7 @@ int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const "%s%s%s", opt->sub->help ? opt->sub->help : "keyword", (opt->sub->flags & PARAMFLAGS_1) ? "" : "[,...]", - (opt->avail & OTF10000) ? "]" : "" + (opt->avail & OTF_SUB_OPTIONS_OPTIONAL) ? "]" : "" ); Side_Print(&left, "\t"); diff --git a/unsorted/IO.c b/unsorted/IO.c index 7ef3cb1..36d809b 100644 --- a/unsorted/IO.c +++ b/unsorted/IO.c @@ -1,4 +1,4 @@ -#include "mwcc_decomp.h" +#include "parser.h" void ShowTextHandle(const char *description, Handle text) { CWMemHandle mh; @@ -32,8 +32,8 @@ void ShowVersion(Boolean decorate) { } for (x = 0; x < parseopts.numPlugins; x++) { - if (parseopts.plugins[x].plugintype == CWFOURCHAR('c','l','d','r')) continue; - if (parseopts.plugins[x].plugintype == CWFOURCHAR('P','a','r','s')) continue; + if (parseopts.plugins[x].plugintype == CWDROPINDRIVERTYPE) continue; + if (parseopts.plugins[x].plugintype == CWDROPINPARSERTYPE) continue; if (pTool->TYPE == parseopts.plugins[x].plugintype) { if (!vplugin && pTool->LANG == parseopts.plugins[x].language) diff --git a/unsorted/OptimizerHelpers.c b/unsorted/OptimizerHelpers.c new file mode 100644 index 0000000..8b4bf36 --- /dev/null +++ b/unsorted/OptimizerHelpers.c @@ -0,0 +1,166 @@ +#include "parser.h" + +Boolean setOldOptimizerOptions; + +typedef struct { + Boolean commonsubs; + Boolean loopinvariants; + Boolean propagation; + Boolean deadstore; + Boolean strengthreduction; + Boolean deadcode; + Boolean lifetimes; +} PIROptimizer; // assumed name + +static PIROptimizer pIrOptimizer = {0}; + +Pragma irPragmas[] = { + &pIrOptimizer.commonsubs, "opt_common_subs", 0, + &pIrOptimizer.loopinvariants, "opt_loop_invariants", 0, + &pIrOptimizer.propagation, "opt_propagation", 0, + &pIrOptimizer.deadstore, "opt_dead_assignments", 0, + &pIrOptimizer.deadcode, "opt_dead_code", 0, + &pIrOptimizer.strengthreduction, "opt_strength_reduction", 0, + &pIrOptimizer.lifetimes, "opt_lifetimes", 0, + 0, 0, 0 +}; + +int SetPragmaOptimizationsToUnspecified(const char *opt, void *, const char *, int) { + if (setOldOptimizerOptions) + Option_Warning(CLPStr62); + + memset(&pIrOptimizer, 0, sizeof(pIrOptimizer)); + TargetSetPragmaOptimizationsToUnspecified(); + return 1; +} + +int SetOptFlags(const char *opt, void *str, const char *, int flags) { + // this is very similar to ToolHelper + // might also fail to match + unsigned char *ptr; + Boolean set; + Boolean no; + UInt16 flag; + + ptr = (unsigned char *) str; + no = (Boolean) ((flags & PARAMPARSEFLAGS_8) >> 3); + set = (Boolean) (no ^ 1); + + while (*ptr) { + if (*ptr == '+') { + set = !no; + } else if (*ptr == '-') { + set = no; + } else if (*ptr == '|') { + set = (Boolean) (no ^ 1); + } else { + flag = (ptr[0] << 8) | ptr[1]; + + if ((flag >= 'G0' && flag <= 'G4') || (flag == 'Gs') || (flag == 'Gp')) + SetPragmaOptimizationsToUnspecified(opt, NULL, NULL, 0); + + switch (flag) { + case 'Cs': + pIrOptimizer.commonsubs = set ? 1 : 2; + setOldOptimizerOptions = 1; + break; + case 'Li': + pIrOptimizer.loopinvariants = set ? 1 : 2; + setOldOptimizerOptions = 1; + break; + case 'Pr': + pIrOptimizer.propagation = set ? 1 : 2; + setOldOptimizerOptions = 1; + break; + case 'Ds': + pIrOptimizer.deadstore = set ? 1 : 2; + setOldOptimizerOptions = 1; + break; + case 'Sr': + pIrOptimizer.strengthreduction = set ? 1 : 2; + setOldOptimizerOptions = 1; + break; + case 'Dc': + pIrOptimizer.deadcode = set ? 1 : 2; + setOldOptimizerOptions = 1; + break; + case 'Lt': + pIrOptimizer.lifetimes = set ? 1 : 2; + setOldOptimizerOptions = 1; + break; + case 'G0': + pGlobalOptimizer.optimizationlevel = set ? 0 : 0; + break; + case 'G1': + pGlobalOptimizer.optimizationlevel = set ? 1 : 0; + break; + case 'G2': + pGlobalOptimizer.optimizationlevel = set ? 2 : 0; + break; + case 'G3': + pGlobalOptimizer.optimizationlevel = set ? 3 : 0; + break; + case 'G4': + pGlobalOptimizer.optimizationlevel = set ? 4 : 0; + break; + case 'Gs': + pGlobalOptimizer.optfor = set ? 1 : 0; + break; + case 'Gp': + pGlobalOptimizer.optfor = set ? 0 : 1; + break; + default: + if (!TargetSetOptFlags(flag, set)) + CLPFatalError("Bad optimizer settings in %s (%c%c)\n", str, ptr[0], ptr[1]); + } + + ++ptr; + } + + ++ptr; + } + + return 1; +} + +int DisplayOptimizationOptions() { + SInt32 oldsize; + Handle h; + + h = NewHandle(0); + if (!h) + exit(-23); + + HPrintF(h, "\t- global optimizer level %d\n", pGlobalOptimizer.optimizationlevel); + HPrintF(h, "\t- global optimize for %s\n", (pGlobalOptimizer.optfor == 0) ? "speed" : "size"); + + oldsize = GetHandleSize(h); + if (pIrOptimizer.commonsubs) + HPrintF(h, "\t- common subexpression elimination %s\n", (pIrOptimizer.commonsubs == 1) ? "on" : "off"); + if (pIrOptimizer.loopinvariants) + HPrintF(h, "\t- loop invariants %s\n", (pIrOptimizer.loopinvariants == 1) ? "on" : "off"); + if (pIrOptimizer.commonsubs) + HPrintF(h, "\t- constant propagation %s\n", (pIrOptimizer.propagation == 1) ? "on" : "off"); + if (pIrOptimizer.deadstore) + HPrintF(h, "\t- dead store elimination %s\n", (pIrOptimizer.deadstore == 1) ? "on" : "off"); + if (pIrOptimizer.deadcode) + HPrintF(h, "\t- dead code elimination %s\n", (pIrOptimizer.deadcode == 1) ? "on" : "off"); + if (pIrOptimizer.strengthreduction) + HPrintF(h, "\t- strength reduction %s\n", (pIrOptimizer.strengthreduction == 1) ? "on" : "off"); + if (pIrOptimizer.lifetimes) + HPrintF(h, "\t- variable lifetimes %s\n", (pIrOptimizer.lifetimes == 1) ? "on" : "off"); + + if (oldsize == GetHandleSize(h)) + HPrintF(h, "\t- no extra global optimizations\n"); + + HPrintF(h, "Backend-specific optimizer options:\n"); + + oldsize = GetHandleSize(h); + TargetDisplayOptimizationOptions(h); + if (oldsize == GetHandleSize(h)) + HPrintF(h, "\t- no extra backend-specific optimizations\n"); + + ShowTextHandle(NULL, h); + DisposeHandle(h); + return 1; +} 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); } diff --git a/Parameter.c b/unsorted/Parameter.c index 95bde45..b3c7367 100644 --- a/Parameter.c +++ b/unsorted/Parameter.c @@ -1,4 +1,4 @@ -#include "includes/mwcc_decomp.h" +#include "parser.h" char curparam[4096]; char *descparam = &curparam[0]; @@ -750,7 +750,7 @@ static int Param_Setting(SETTING_T *p, const char *pstr, int flags) { strncpy(savevar, pstr, sizeof(savevar)); tok = Arg_PeekToken(); - if (tok && tok->val == ATK_4) { + if (tok && tok->val == ATK_EQUALS) { Arg_UsedToken(); equals = 1; if (!Param_GetArgument((PARAM_T *) p, &vstr, flags)) @@ -1007,22 +1007,22 @@ static int Param_GetArgument(PARAM_T *param, const char **cparam, int exec) { ArgToken *tok; subparse = (exec & PARAMPARSEFLAGS_4) != 0; - nextOpt = !subparse ? ATK_1 : ATK_5; - nextParam = !subparse ? ATK_5 : ATK_4; - lastOpt = !subparse ? ATK_0 : ATK_1; + nextOpt = !subparse ? ATK_ARG_END : ATK_COMMA; + nextParam = !subparse ? ATK_COMMA : ATK_EQUALS; + lastOpt = !subparse ? ATK_END : ATK_ARG_END; tok = Arg_PeekToken(); #line 1467 OPTION_ASSERT(tok); if ((param->flags & PARAMFLAGS_3) == 0) { - if (tok->val == nextParam || tok->val == ATK_4) + if (tok->val == nextParam || tok->val == ATK_EQUALS) tok = Arg_UsedToken(); if (tok->val == nextOpt || tok->val == nextParam || tok->val == lastOpt) { Param_Error(34); return 0; } - if (tok->val != ATK_2) { + if (tok->val != ATK_ARG) { Param_Error(57, "parameter", Arg_GetTokenName(tok)); return 0; } @@ -1032,12 +1032,12 @@ static int Param_GetArgument(PARAM_T *param, const char **cparam, int exec) { if (param->flags & PARAMFLAGS_8) { tok = Arg_PeekToken(); - if (tok->val == ATK_4) + if (tok->val == ATK_EQUALS) Arg_UsedToken(); } } else if (param->flags & PARAMFLAGS_1) { *cparam = 0; - if (tok->val == ATK_4 && !subparse) { + if (tok->val == ATK_EQUALS && !subparse) { if (!(exec & PARAMPARSEFLAGS_40)) { Param_Error(37); return 0; @@ -1049,7 +1049,7 @@ static int Param_GetArgument(PARAM_T *param, const char **cparam, int exec) { *cparam = 0; } else if (tok->val == nextParam) { tok = Arg_UsedToken(); - if (tok->val == ATK_2) { + if (tok->val == ATK_ARG) { Arg_GetTokenText(tok, curparam, sizeof(curparam), 1); if ((param->flags & PARAMFLAGS_12) && Param_IsNonTextFile(curparam, !(exec & PARAMPARSEFLAGS_1))) { *cparam = 0; @@ -1060,17 +1060,17 @@ static int Param_GetArgument(PARAM_T *param, const char **cparam, int exec) { } else { *cparam = 0; } - } else if (tok->val == ATK_2 && !tok->text[0]) { + } else if (tok->val == ATK_ARG && !tok->text[0]) { tok = Arg_UsedToken(); if (tok->val == nextParam) Arg_UsedToken(); *cparam = 0; - } else if ((exec & PARAMPARSEFLAGS_4) && tok->val != ATK_4) { + } else if ((exec & PARAMPARSEFLAGS_4) && tok->val != ATK_EQUALS) { *cparam = 0; } else { - if (tok->val == ATK_4) + if (tok->val == ATK_EQUALS) tok = Arg_UsedToken(); - if (tok->val == ATK_2) { + if (tok->val == ATK_ARG) { Arg_GetTokenText(tok, curparam, sizeof(curparam), 1); if ((param->flags & PARAMFLAGS_12) && Param_IsNonTextFile(curparam, !(exec & PARAMPARSEFLAGS_1))) { *cparam = 0; @@ -1089,9 +1089,9 @@ static int Param_GetArgument(PARAM_T *param, const char **cparam, int exec) { if (pTool->TYPE == CWDROPINCOMPILERTYPE && (exec & PARAMPARSEFLAGS_2) && *cparam) { if (!(exec & PARAMPARSEFLAGS_10)) { if (subparse) - Arg_AddToToolArgs(&linkargs, ATK_4, 0); + Arg_AddToToolArgs(&linkargs, ATK_EQUALS, 0); else - Arg_AddToToolArgs(&linkargs, ATK_5, 0); + Arg_AddToToolArgs(&linkargs, ATK_COMMA, 0); } Param_PushParam(*cparam); Args_AddToToolArgs(&linkargs); diff --git a/unsorted/ParserErrors.c b/unsorted/ParserErrors.c index 172e04c..df5e67e 100644 --- a/unsorted/ParserErrors.c +++ b/unsorted/ParserErrors.c @@ -1,4 +1,4 @@ -#include "mwcc_decomp.h" +#include "parser.h" static char errorbuf[1024]; diff --git a/unsorted/ParserFace.c b/unsorted/ParserFace.c index 24f3213..a005ece 100644 --- a/unsorted/ParserFace.c +++ b/unsorted/ParserFace.c @@ -1,8 +1,8 @@ -#include "mwcc_decomp.h" +#include "parser.h" const char *failedCallback; jmp_buf exit_plugin; -struct ParseOptsType parseopts; +ParseOptsType parseopts; static CWResult SetupParamBlock(CWPluginContext context) { CWResult result; @@ -136,9 +136,9 @@ CWResult Parser_StorePanels(CWPluginContext context) { name = parseopts.panelNames[idx]; h = Parser_FindPrefPanel(name); if (h) { - result = CWParserSetNamedPreferences(parseopts.context, name, (CWMemHandle) h); + result = CWParserSetNamedPreferences(parseopts.context, name, h); if (result) { - CLPReportError(68, name); + CLPReportError(CLPStr68, name); return result; } } @@ -190,10 +190,10 @@ static CWResult StoreResults(CWPluginContext context) { return cwNoErr; } -short CWParser_GetDropInFlags(const DropInFlags **flags, SInt32 *flagsSize) { +CWPLUGIN_ENTRY (CWParser_GetDropInFlags)(const DropInFlags **flags, SInt32 *flagsSize) { static const DropInFlags sFlags = { kCurrentDropInFlagsVersion, - CWFOURCHAR('P','a','r','s'), + CWDROPINPARSERTYPE, 7, 0, 'Seep', @@ -204,19 +204,19 @@ short CWParser_GetDropInFlags(const DropInFlags **flags, SInt32 *flagsSize) { return 0; } -short CWParser_GetDropInName(const char **dropinName) { +CWPLUGIN_ENTRY (CWParser_GetDropInName)(const char **dropinName) { static const char *sDropInName = "Command-Line Parser"; *dropinName = sDropInName; return 0; } -short CWParser_GetDisplayName(const char **displayName) { +CWPLUGIN_ENTRY (CWParser_GetDisplayName)(const char **displayName) { static const char *sDisplayName = "Command-Line Parser"; *displayName = sDisplayName; return 0; } -short CWParser_GetPanelList(const CWPanelList **panelList) { +CWPLUGIN_ENTRY (CWParser_GetPanelList)(const CWPanelList **panelList) { static CWPanelList sPanelList = { kCurrentCWFamilyListVersion, 0, @@ -226,7 +226,7 @@ short CWParser_GetPanelList(const CWPanelList **panelList) { return 0; } -short CWParser_GetTargetList(const CWTargetList **targetList) { +CWPLUGIN_ENTRY (CWParser_GetTargetList)(const CWTargetList **targetList) { static CWDataType sCPU = '****'; static CWDataType sOS = '****'; static CWTargetList sTargetList = { @@ -240,7 +240,7 @@ short CWParser_GetTargetList(const CWTargetList **targetList) { return 0; } -short CWParser_GetVersionInfo(const VersionInfo **versioninfo) { +CWPLUGIN_ENTRY (CWParser_GetVersionInfo)(const VersionInfo **versioninfo) { static const VersionInfo vi = { 1, 1, 0, 0 }; @@ -248,17 +248,17 @@ short CWParser_GetVersionInfo(const VersionInfo **versioninfo) { return 0; } -short Parser_SupportsPlugin(struct CLPluginInfo *pluginfo, CWDataType cpu, CWDataType os, Boolean *isSupported) { +CWPLUGIN_ENTRY (Parser_SupportsPlugin)(const struct CLPluginInfo *pluginfo, CWDataType cpu, CWDataType os, Boolean *isSupported) { *isSupported = ParserToolMatchesPlugin(pluginfo->plugintype, pluginfo->language, cpu, os); return 0; } -short Parser_SupportsPanels(int numPanels, const char **panelNames, Boolean *isSupported) { +CWPLUGIN_ENTRY (Parser_SupportsPanels)(int numPanels, const char **panelNames, Boolean *isSupported) { *isSupported = ParserToolHandlesPanels(numPanels, panelNames); return 0; } -short parser_main(CWPluginContext context) { +CWPLUGIN_ENTRY (parser_main)(CWPluginContext context) { CWResult result; SInt32 request; diff --git a/unsorted/ParserHelpers-cc.c b/unsorted/ParserHelpers-cc.c index d56fe4d..fe081ad 100644 --- a/unsorted/ParserHelpers-cc.c +++ b/unsorted/ParserHelpers-cc.c @@ -1,8 +1,8 @@ -#include "mwcc_decomp.h" +#include "parser.h" Handle definesHandle; -int Opt_AddStringToDefines(const char *opt, void *str, const char *param) { +int Opt_AddStringToDefines(const char *opt, void *str, const char *param, int flags) { AddStringToHandle(&definesHandle, (const char *) str); if (param) AddStringToHandle(&definesHandle, param); @@ -18,7 +18,7 @@ int Opt_DefineSymbol(const char *var, const char *value) { sprintf(tmp, "{$definec %s %s}\n", var, value ? value : "1"); } else { sprintf(tmp, "Option '-D|d' is not supported with this plugin"); - CLPReportError(28, tmp); + CLPReportError(CLPStr28_WarningText, tmp); return 0; } @@ -26,7 +26,7 @@ int Opt_DefineSymbol(const char *var, const char *value) { return 1; } -int Opt_UndefineSymbol(const char *opt, void *, const char *arg) { +int Opt_UndefineSymbol(const char *opt, void *, const char *arg, int flags) { char tmp[300]; if (pTool->LANG == Lang_C_CPP || pTool->LANG == CWFOURCHAR('A','s','m',' ')) { @@ -35,7 +35,7 @@ int Opt_UndefineSymbol(const char *opt, void *, const char *arg) { sprintf(tmp, "{$undefc %s}\n", arg); } else { sprintf(tmp, "Option -%s is not supported with this plugin", opt); - CLPReportError(28, tmp); + CLPReportError(CLPStr28_WarningText, tmp); return 0; } @@ -43,7 +43,7 @@ int Opt_UndefineSymbol(const char *opt, void *, const char *arg) { return 1; } -int Opt_AddPrefixFile(const char *opt, void *handle, const char *filename) { +int Opt_AddPrefixFile(const char *opt, void *handle, const char *filename, int flags) { char tmp[300]; handle = !handle ? &definesHandle : handle; @@ -60,7 +60,7 @@ int Opt_AddPrefixFile(const char *opt, void *handle, const char *filename) { snprintf(tmp, sizeof(tmp), "{$I+}\n{$I %s}\n{$I-}\n", filename); } else { sprintf(tmp, "Option -%s is not supported with this plugin", opt); - CLPReportError(28, tmp); + CLPReportError(CLPStr28_WarningText, tmp); return 0; } @@ -86,7 +86,7 @@ int Opt_PragmaFalseTrue(const char *, void *flag, const char *, int flags) { int Opt_PragmaOnOff(const char *, void *flag, const char *arg) { if (!arg) { - CLPReportError(34); + CLPReportError(CLPStr34_ArgumentsExpected); return 0; } @@ -95,7 +95,7 @@ int Opt_PragmaOnOff(const char *, void *flag, const char *arg) { } else if (!ustrcmp(arg, "off")) { *((unsigned char *) flag) = PR_OFF; } else { - CLPReportError(12, arg); + CLPReportError(CLPStr12, arg); return 0; } @@ -104,7 +104,7 @@ int Opt_PragmaOnOff(const char *, void *flag, const char *arg) { int Opt_PragmaOffOn(const char *, void *flag, const char *arg) { if (!arg) { - CLPReportError(34); + CLPReportError(CLPStr34_ArgumentsExpected); return 0; } @@ -113,7 +113,7 @@ int Opt_PragmaOffOn(const char *, void *flag, const char *arg) { } else if (!ustrcmp(arg, "off")) { *((unsigned char *) flag) = PR_ON; } else { - CLPReportError(12, arg); + CLPReportError(CLPStr12, arg); return 0; } diff --git a/unsorted/ParserHelpers.c b/unsorted/ParserHelpers.c index c8d4c55..4cb793e 100644 --- a/unsorted/ParserHelpers.c +++ b/unsorted/ParserHelpers.c @@ -1,4 +1,5 @@ -#include "mwcc_decomp.h" +#include "parser.h" +#include "cmdline.h" #include <errno.h> SInt16 lastStage; @@ -44,7 +45,7 @@ char *GetEnvVar(const char *name, Boolean warn, const char **match) { } if (warn) - CLPReportWarning(52, last); + CLPReportWarning(CLPStr52, last); *match = 0; return 0; } @@ -82,7 +83,7 @@ static Boolean MatchesExtension(const char *list, const char *filename) { return !*list && !*ptr; } -int Opt_AddAccessPath(const char *opt, void *var, const char *arg) { +int Opt_AddAccessPath(const char *opt, void *var, const char *arg, int flags) { OSPathSpec spec; int err; @@ -93,16 +94,16 @@ int Opt_AddAccessPath(const char *opt, void *var, const char *arg) { return 1; if (strlen(arg) >= 256) { - CLPReportError(13, arg + strlen(arg) - 32, 256); + CLPReportError(CLPStr13, arg + strlen(arg) - 32, 256); return 0; } err = OS_MakePathSpec(0, arg, &spec); if (err == ENOENT || err == ENOENT) { - CLPReportWarning(45, arg); + CLPReportWarning(CLPStr45, arg); return 1; } else if (err != 0) { - CLPOSAlert(45, err, arg); + CLPOSAlert(CLPStr45, err, arg); return 1; } @@ -113,7 +114,7 @@ int Opt_AddAccessPath(const char *opt, void *var, const char *arg) { return 1; } -int Opt_AddFrameworkPath(const char *opt, void *var, const char *arg) { +int Opt_AddFrameworkPath(const char *opt, void *var, const char *arg, int flags) { OSPathSpec spec; int err; @@ -124,16 +125,16 @@ int Opt_AddFrameworkPath(const char *opt, void *var, const char *arg) { return 1; if (strlen(arg) >= 256) { - CLPReportError(13, arg + strlen(arg) - 32, 256); + CLPReportError(CLPStr13, arg + strlen(arg) - 32, 256); return 0; } err = OS_MakePathSpec(0, arg, &spec); if (err == ENOENT || err == ENOENT) { - CLPReportWarning(45, arg); + CLPReportWarning(CLPStr45, arg); return 1; } else if (err != 0) { - CLPOSAlert(45, err, arg); + CLPOSAlert(CLPStr45, err, arg); return 1; } else { Frameworks_AddPath(&spec); @@ -141,7 +142,7 @@ int Opt_AddFrameworkPath(const char *opt, void *var, const char *arg) { } } -int Opt_AddFramework(const char *opt, void *var, const char *arg) { +int Opt_AddFramework(const char *opt, void *var, const char *arg, int flags) { if (!Frameworks_AddFramework(arg ? arg : opt, 0, 0)) return 0; else @@ -190,7 +191,7 @@ int AddAccessPathList(const char *list, char sep1, char sep2, int source, char * ListParseMessage( CLPReportError_V, (source == 1) ? text : NULL, - 9, + CLPStr9, tmp, tmp + strlen(tmp) - 16, 256); @@ -202,7 +203,7 @@ int AddAccessPathList(const char *list, char sep1, char sep2, int source, char * ListParseMessage( CLPReportWarning_V, (source == 1) ? text : NULL, - 45, + CLPStr45, tmp); } else { AddAccessPath(&spec, type, position, recurse ^ recursive); @@ -218,7 +219,7 @@ int AddAccessPathList(const char *list, char sep1, char sep2, int source, char * return 1; } -int Opt_FindAndAddFile(const char *opt, void *var, const char *arg) { +int Opt_FindAndAddFile(const char *opt, void *var, const char *arg, int flags) { OSSpec spec; int err; Boolean isfile; @@ -235,11 +236,11 @@ int Opt_FindAndAddFile(const char *opt, void *var, const char *arg) { err = OS_Status(&spec); if (!err && !isfile) { - CLPReportError(47, arg); + CLPReportError(CLPStr47, arg); parseopts.unusedFiles++; return 0; } else if (err && err != ENOENT) { - CLPOSAlert(44, err, arg); + CLPOSAlert(CLPStr44, err, arg); parseopts.unusedFiles++; return 0; } else if (err && parseopts.alwaysUsePaths) { @@ -247,13 +248,13 @@ int Opt_FindAndAddFile(const char *opt, void *var, const char *arg) { } if (err) { - CLPReportError(44, arg); + CLPReportError(CLPStr44, arg); parseopts.unusedFiles++; return 0; } if (var && !MatchesExtension((const char *) var, arg)) - CLPReportWarning(76, arg, var); + CLPReportWarning(CLPStr76, arg, var); if (!AddFileToProject(&spec, lastStage, parseopts.lastoutputname, 1, -1)) { parseopts.unusedFiles++; @@ -277,14 +278,14 @@ int Opt_FindAndAddFileRef(const char *opt, void *var, const char *arg) { parseopts.userSpecifiedFiles++; if (var && !MatchesExtension((const char *) var, arg)) - CLPReportWarning(76, arg, var); + CLPReportWarning(CLPStr76, arg, var); err = OS_MakeSpec(arg, &spec, &isfile); if (!err) err = OS_Status(&spec); if (!err && !isfile) { - CLPReportError(47, arg); + CLPReportError(CLPStr47, arg); parseopts.unusedFiles++; return 0; } else if (err && parseopts.alwaysUsePaths) { @@ -307,7 +308,7 @@ int Opt_AddUnixLibraryFile(const char *opt, void *var, const char *name) { char tmpname[64]; if (strlen(name) >= 56) { - CLPReportError(13, name + strlen(name) - 32, 64); + CLPReportError(CLPStr13, name + strlen(name) - 32, 64); return 0; } @@ -336,7 +337,7 @@ int Opt_AddUnixLibraryFile(const char *opt, void *var, const char *name) { if (failed) { failed = !FindFileInPath(name, &spec); if (failed) - CLPReportError(49, name, var, name); + CLPReportError(CLPStr49, name, var, name); } if (!failed) { @@ -368,7 +369,7 @@ int AddFileList(const char *list, char sep1, char sep2, int source, char *text, ListParseMessage( CLPReportError_V, (source == 1) ? text : 0, - 9, + CLPStr9, tmp, tmp + strlen(tmp) - 16, 256 @@ -381,14 +382,14 @@ int AddFileList(const char *list, char sep1, char sep2, int source, char *text, ListParseMessage( CLPReportError_V, (source == 1) ? text : 0, - 16, + CLPStr16, tmp ); } else { ListParseMessage( CLPReportWarning_V, (source == 1) ? text : 0, - 44, + CLPStr44, tmp ); } @@ -416,18 +417,18 @@ void GetCFileNameInOutputDirectory(const char *input, char *name, int maxlen) { err = OS_MakeFileSpec(input, &spec); if (err) { - CLPOSAlert(64, err, input); + CLPOSAlert(CLPStr64, err, input); name[0] = 0; return; } if (!IsFileInOutputDirectory(&spec)) { - CLPReportWarning(61, OS_SpecToStringRelative(&spec, 0, STSbuf, sizeof(STSbuf))); + CLPReportWarning(CLPStr61, OS_SpecToStringRelative(&spec, 0, STSbuf, sizeof(STSbuf))); } OS_NameSpecToString(&spec.name, filename, 256); if (strlen(filename) >= maxlen) { - CLPReportWarning(65, filename, maxlen - 1); + CLPReportWarning(CLPStr65, filename, maxlen - 1); filename[maxlen - 1] = 0; } @@ -469,7 +470,7 @@ void AddStringToHandle(Handle *h, const char *str) { AddStringLenToHandle(h, str, strlen(str)); } -int Opt_PrintVersion(const char *opt, void *var, const char *arg) { +int Opt_PrintVersion(const char *opt, void *var, const char *arg, int flags) { ShowVersion(0); return 1; } @@ -500,7 +501,7 @@ void GetFirstSourceFilenameBase(char *buffer, char *defaul) { strcpy(buffer, defaul); } -int Opt_SavePrefs(const char *opt, void *var, const char *arg) { +int Opt_SavePrefs(const char *opt, void *var, const char *arg, int flags) { Parser_StorePanels(parseopts.context); return 1; } @@ -520,14 +521,14 @@ int ParseNumber(const char *arg, Boolean emit_error, SInt32 *ret, const char **e *endptr = end; if (*end && emit_error) { - CLPReportError(5, "", arg); + CLPReportError(CLPStr5, "", arg); return 0; } return 1; } -int Opt_MaybeMoveAccessPaths(const char *opt, void *var, const char *arg) { +int Opt_MaybeMoveAccessPaths(const char *opt, void *var, const char *arg, int flags) { if (dashIMinusMovesPaths && !usedDashIMinus) MoveSystemPathsIntoUserList(); return 1; diff --git a/unsorted/Projects.c b/unsorted/Projects.c index 72b06b1..fda92df 100644 --- a/unsorted/Projects.c +++ b/unsorted/Projects.c @@ -1,6 +1,5 @@ -#include "mwcc_decomp.h" +#include "parser.h" -// TODO: figure out who defines this extern char STSbuf[256]; int GetFileCount() { diff --git a/unsorted/StaticParserGlue.c b/unsorted/StaticParserGlue.c index 4673c27..c2e130d 100644 --- a/unsorted/StaticParserGlue.c +++ b/unsorted/StaticParserGlue.c @@ -1,4 +1,5 @@ -#include "mwcc_decomp.h" +#include "parser.h" +#include "cmdline.h" static BasePluginCallbacks cb = { parser_main, diff --git a/unsorted/TargetOptimizer-ppc-mach.c b/unsorted/TargetOptimizer-ppc-mach.c new file mode 100644 index 0000000..10fe33e --- /dev/null +++ b/unsorted/TargetOptimizer-ppc-mach.c @@ -0,0 +1,69 @@ +#include "parser.h" + +char schedule_ppc_default; + +int TargetSetOptFlags(short val, Boolean set) { + switch (val) { + case 'Pe': + pBackEnd.peephole = set; + break; + case 'Sn': + pBackEnd.schedule = 0; + break; + case 'Sh': + pBackEnd.schedule = set; + break; + case 'S?': + pBackEnd.processor = schedule_ppc_default; + break; + case 'SG': + pBackEnd.processor = schedule_ppc_default = 0; + break; + case 'S1': + pBackEnd.processor = schedule_ppc_default = 1; + break; + case 'S3': + pBackEnd.processor = schedule_ppc_default = 2; + break; + case 'S#': + pBackEnd.processor = schedule_ppc_default = 3; + break; + case 'S4': + pBackEnd.processor = schedule_ppc_default = 4; + break; + case 'S%': + pBackEnd.processor = schedule_ppc_default = 5; + break; + case 'S7': + pBackEnd.processor = schedule_ppc_default = 6; + break; + case 'SA': + pBackEnd.processor = schedule_ppc_default = 7; + break; + default: + return 0; + } + + return 1; +} + +void TargetDisplayOptimizationOptions(Handle txt) { + if (!pBackEnd.schedule) { + HPrintF(txt, "\t- no instruction scheduling\n"); + } else { + HPrintF(txt, "\t- schedule for %s\n", + (pBackEnd.processor == 0) ? "generic PPC" : + (pBackEnd.processor == 1) ? "601" : + (pBackEnd.processor == 2) ? "603" : + (pBackEnd.processor == 3) ? "603e" : + (pBackEnd.processor == 4) ? "604" : + (pBackEnd.processor == 5) ? "604e" : + (pBackEnd.processor == 6) ? "750" : + (pBackEnd.processor == 7) ? "Altivec" : + "???" + ); + } +} + +void TargetSetPragmaOptimizationsToUnspecified() { +} diff --git a/unsorted/Targets.c b/unsorted/Targets.c index b4307ff..accad8b 100644 --- a/unsorted/Targets.c +++ b/unsorted/Targets.c @@ -1,4 +1,4 @@ -#include "mwcc_decomp.h" +#include "parser.h" ParserTool *pTool; @@ -18,8 +18,8 @@ Boolean ParserToolMatchesPlugin(OSType type, OSType lang, OSType cpu, OSType os) } if ( - (type == CWFOURCHAR('*','*','*','*') || pTool->TYPE == CWFOURCHAR('*','*','*','*') || pTool->TYPE == type) && - (lang == CWFOURCHAR('*','*','*','*') || pTool->LANG == CWFOURCHAR('*','*','*','*') || pTool->LANG == lang) && + (type == CWDROPINANYTYPE || pTool->TYPE == CWDROPINANYTYPE || pTool->TYPE == type) && + (lang == Lang_Any || pTool->LANG == Lang_Any || pTool->LANG == lang) && (cpu == targetCPUAny || pTool->CPU == targetCPUAny || pTool->CPU == cpu) && (os == targetOSAny || pTool->OS == targetOSAny || pTool->OS == os) ) diff --git a/unsorted/ToolHelpers-cc.c b/unsorted/ToolHelpers-cc.c index dd0bc92..fee7517 100644 --- a/unsorted/ToolHelpers-cc.c +++ b/unsorted/ToolHelpers-cc.c @@ -1,6 +1,7 @@ -#include "mwcc_decomp.h" +#include "parser.h" +#include "cmdline.h" -int Opt_DummyLinkerRoutine(const char *opt) { +int Opt_DummyLinkerRoutine(const char *opt, void *, const char *, int) { CLPFatalError("Calling linker option '%s'\n", opt); return 0; } diff --git a/unsorted/ToolHelpers.c b/unsorted/ToolHelpers.c index 1942072..e872546 100644 --- a/unsorted/ToolHelpers.c +++ b/unsorted/ToolHelpers.c @@ -1,16 +1,16 @@ -#include "mwcc_decomp.h" +#include "parser.h" +#include "cmdline.h" #include <errno.h> -// TODO: figure out who defines this extern char STSbuf[256]; static Boolean setStage; -SInt16 outputOrdering; -Boolean setOutputDirectory; -Boolean setLinkerOutputFilename; char linkerOutputFilename[256]; +Boolean setLinkerOutputFilename; +Boolean setOutputDirectory; +SInt16 outputOrdering; -int Opt_HandleOutputName(const char *opt, void *, const char *filename) { +int Opt_HandleOutputName(const char *opt, void *, const char *filename, int flags) { OSSpec spec; int err; SInt32 result; @@ -21,7 +21,7 @@ int Opt_HandleOutputName(const char *opt, void *, const char *filename) { if ((pCmdLine.state == OptsCmdLineState_3 || (pCmdLine.state == OptsCmdLineState_0 && pTool->TYPE == CWDROPINLINKERTYPE)) && pCmdLine.toDisk != 4) { if (setLinkerOutputFilename) { - CLPReportError(41, filename); + CLPReportError(CLPStr41, filename); return 0; } setLinkerOutputFilename = 1; @@ -33,7 +33,7 @@ int Opt_HandleOutputName(const char *opt, void *, const char *filename) { Boolean isfile; err = OS_MakeSpec(filename, &spec, &isfile); if (err) { - CLPOSAlert(64, err, filename); + CLPOSAlert(CLPStr64, err, filename); return 0; } if (isfile) @@ -44,14 +44,14 @@ int Opt_HandleOutputName(const char *opt, void *, const char *filename) { } else { err = OS_MakeSpec(filename, &spec, &isfile); if (err) { - CLPOSAlert(64, err, filename); + CLPOSAlert(CLPStr64, err, filename); return 0; } if (!err && !isfile) { FSSpec ofd; if (setOutputDirectory) { - CLPReportError(59, filename); + CLPReportError(CLPStr59, filename); return 0; } setOutputDirectory = 1; @@ -67,7 +67,7 @@ int Opt_HandleOutputName(const char *opt, void *, const char *filename) { SInt32 index; CWProjectFileInfo pfi; if (parseopts.lastoutputname[0]) { - CLPReportError(41, filename); + CLPReportError(CLPStr41, filename); return 0; } strncpy(parseopts.lastoutputname, filename, 256); @@ -115,7 +115,7 @@ int ValidateToolState(Boolean mustHaveFiles) { if (!parseopts.userSpecifiedFiles) { if (!parseopts.hadAnyOutput) { if (mustHaveFiles) { - CLPReportError(70); + CLPReportError(CLPStr70); return 0; } } else { @@ -124,7 +124,7 @@ int ValidateToolState(Boolean mustHaveFiles) { return 1; } } else if (parseopts.unusedFiles > 0) { - CLPReportError(69); + CLPReportError(CLPStr69); return 0; } } @@ -195,7 +195,7 @@ int Opt_DoNotLink(const char *opt, void *var, const char *arg) { return 1; } -int Opt_IncreaseVerbosity(const char *opt, void *var, const char *arg) { +int Opt_IncreaseVerbosity(const char *opt, void *var, const char *arg, int flags) { if (pCmdLine.verbose) pCmdLine.verbose++; else @@ -275,13 +275,13 @@ int Opt_RedirectStream(const char *opt, void *file, const char *filename) { err = OS_MakeFileSpec(filename, &spec); if (err) { - CLPReportError(78, filename, OS_GetErrText(err)); + CLPReportError(CLPStr78, filename, OS_GetErrText(err)); return 0; } nw = freopen(OS_SpecToString(&spec, STSbuf, 256), "wt", (FILE *) file); if (!nw) { - CLPReportError(78, filename, strerror(errno)); + CLPReportError(CLPStr78, filename, strerror(errno)); return 0; } diff --git a/unsorted/Utils.c b/unsorted/Utils.c new file mode 100644 index 0000000..b627c4d --- /dev/null +++ b/unsorted/Utils.c @@ -0,0 +1,174 @@ +#include "parser.h" + +int my_tolower(char c) { + if (c >= 'A' && c <= 'Z') + return c | 0x20; + else + return c; +} + +int my_isdigit(char c) { + return (c >= '0' && c <= '9'); +} + +int my_isalpha(char c) { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); +} + +int my_isalnum(char c) { + return my_isdigit(c) || my_isalpha(c); +} + +int my_isxdigit(char c) { + return my_isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); +} + +char *Utils_SpellList(char *list, char *buffer, char opts) { + char *sptr; + char *eptr; + char *nptr; + char *bptr; + int pflen; + int npflen; + int undo; + char *neptr; + int cnt; + + undo = 0; + bptr = buffer; + sptr = list; + pflen = 0; + while (sptr) { + if ((opts & 1) && !pflen) + *(bptr++) = *MAINOPTCHAR; + + eptr = strchr(sptr, '|'); + if (!eptr) { + eptr = sptr + strlen(sptr); + nptr = 0; + } else if (eptr[1] == '|') { + nptr = 0; + } else { + nptr = eptr + 1; + } + + if (undo == 0 && !pflen) { + if (opts & 8) { + *(bptr++) = '['; + *(bptr++) = 'n'; + *(bptr++) = 'o'; + *(bptr++) = ']'; + } + if (opts & 0x20) { + *(bptr++) = '['; + *(bptr++) = 'n'; + *(bptr++) = 'o'; + *(bptr++) = '-'; + *(bptr++) = ']'; + } + } + + npflen = 0; + if (nptr) { + while (sptr < nptr && *nptr && *nptr != '|' && sptr[npflen] == nptr[npflen]) + npflen++; + + if (npflen) { + neptr = strchr(nptr, '|'); + if (!neptr) + neptr = nptr + strlen(nptr); + if ((neptr - nptr) < (eptr - sptr) || ((sptr[1] && sptr[1] != '|') ? (sptr[1] != nptr[1]) : 0)) + npflen = 0; + if (opts & 0x40) + npflen = 0; + } + } + + if (pflen) { + sptr += pflen; + while (sptr < eptr) { + *(bptr++) = *(sptr++); + } + if (npflen > pflen) { + *(bptr++) = '['; + undo++; + } + if (npflen < pflen) { + *(bptr++) = ']'; + undo--; + } + } else if (npflen) { + for (cnt = npflen; cnt > 0; cnt--) { + *(bptr++) = *(sptr++); + } + *(bptr++) = '['; + undo++; + } + + while (sptr < eptr) { + *(bptr++) = *(sptr++); + } + + if (opts & 0x10) { + *(bptr++) = '['; + *(bptr++) = '-'; + *(bptr++) = ']'; + } + if (opts & 0x40) { + *(bptr++) = '+'; + } + + sptr = nptr; + if (nptr && bptr[-1] != '[') { + if ((opts & 1) || (bptr[-1] == ']') || ((opts & 8) && !undo)) { + *(bptr++) = ' '; + *(bptr++) = '|'; + *(bptr++) = ' '; + } else { + *(bptr++) = '|'; + } + } + + opts &= ~0x40; + pflen = npflen; + } + + for (cnt = undo; cnt; cnt--) { + *(bptr++) = ']'; + } + + if (opts & 4) + bptr += sprintf(bptr, "=..."); + + *bptr = 0; + return bptr; +} + +int Utils_CompareOptionString(const char *a, const char *b, int cased, int sticky) { + const char *ae; + const char *be; + + for (ae = a; *ae && *ae != '|'; ae++) {} + for (be = b; *be && *be != '|'; be++) {} + + if (sticky && (be - b) < (ae - a)) + return 0; + + if (cased) { + while (a < ae && b < be) { + if (*a != *b) + break; + a++; + b++; + } + } else { + while (a < ae && b < be) { + if (my_tolower(*a) != my_tolower(*b)) + break; + a++; + b++; + } + } + + return (a == ae) && (sticky || b == be); +} diff --git a/unsorted/uCOS.c b/unsorted/uCOS.c new file mode 100644 index 0000000..5564e5b --- /dev/null +++ b/unsorted/uCOS.c @@ -0,0 +1,292 @@ +#include "cw_common.h" +#include "cos.h" + +extern Boolean systemHandles; + +static StringPtr COS_pstrcpy(StringPtr dst, ConstStringPtr src) { + short cnt; + for (cnt = src[0]; cnt >= 0; cnt--) { + *(dst++) = *(src++); + } + return dst; +} + +static StringPtr COS_pstrcat(StringPtr dst, ConstStringPtr src) { + // not matching + short as; + short bs; + + bs = *(src++); + as = dst[0]; + if ((bs + as) > 255) + bs = 255 - as; + + dst[0] += bs; + dst = &dst[as]; + dst++; + + while (bs-- > 0) { + *(dst++) = *(src++); + } + return dst; +} + +static void COS_pstrcharcat(StringPtr to, char ch) { + if (to[0] < 255) { + to[0]++; + to[to[0]] = ch; + } +} + +static short COS_pstrcmp(ConstStringPtr a, ConstStringPtr b) { + short as, bs; + if ((bs = *(b++)) != (as = *(a++))) + return 1; + while (as-- > 0) { + if (*(a++) != *(b++)) + return 1; + } + return 0; +} + +Handle COS_NewHandle(SInt32 byteCount) { + return NewHandle(byteCount); +} + +Handle COS_NewOSHandle(SInt32 logicalSize) { + OSErr err; + Handle h; + + if (systemHandles) { + h = TempNewHandle(logicalSize, &err); + if (!err) + return h; + } + + return NULL; +} + +void COS_FreeHandle(Handle handle) { + DisposeHandle(handle); +} + +Boolean COS_ResizeHandle(Handle handle, SInt32 newSize) { + SetHandleSize(handle, newSize); + return LMGetMemErr() == noErr; +} + +SInt32 COS_GetHandleSize(Handle handle) { + return GetHandleSize(handle); +} + +void COS_LockHandle(Handle handle) { + HLock(handle); +} + +void COS_LockHandleHi(Handle handle) { + HLockHi(handle); +} + +void COS_UnlockHandle(Handle handle) { + HUnlock(handle); +} + +int COS_GetHandleState(Handle handle) { + return HGetState(handle); +} + +void COS_SetHandleState(Handle handle, int state) { + HSetState(handle, state); +} + +Boolean COS_IsLockedState(int state) { + return (state & 0x80) >> 7; +} + +char *COS_NewPtr(SInt32 byteCount) { + return NewPtr(byteCount); +} + +char *COS_NewPtrClear(SInt32 byteCount) { + return NewPtrClear(byteCount); +} + +void COS_FreePtr(char *ptr) { + DisposePtr(ptr); +} + +void COS_AppendPtrToHandle(char *ptr1, Handle hand2, SInt32 size) { + PtrAndHand(ptr1, hand2, size); +} + +OSErr COS_GetMemErr() { + return LMGetMemErr(); +} + +SInt32 COS_GetTicks() { + return LMGetTicks(); +} + +SInt32 COS_GetTime() { + return LMGetTime(); +} + +void COS_GetString(char *buffer, SInt16 strListID, SInt16 index) { + GetIndString((StringPtr) buffer, strListID, index); + p2cstr((StringPtr) buffer); +} + +void COS_GetPString(StringPtr buffer, SInt16 strListID, SInt16 index) { + GetIndString((StringPtr) buffer, strListID, index); +} + +Boolean COS_IsMultiByte(const char *str, int offset) { + return OS_IsMultiByte(str, offset); +} + +OSErr COS_FileNew(const FSSpec *spec, SInt16 *refNum, OSType creator, OSType fileType) { + OSErr err; + + HDelete(spec->vRefNum, spec->parID, spec->name); + err = HCreate(spec->vRefNum, spec->parID, spec->name, creator, fileType); + if (!err) + err = HOpenDF(spec->vRefNum, spec->parID, spec->name, fsRdWrPerm, refNum); + return err; +} + +OSErr COS_FileOpen(const FSSpec *spec, SInt16 *refNum) { + return HOpenDF(spec->vRefNum, spec->parID, spec->name, fsRdPerm, refNum); +} + +OSErr COS_FileGetType(const FSSpec *spec, OSType *fileType) { + OSErr err; + FInfo fi; + + err = HGetFInfo(spec->vRefNum, spec->parID, spec->name, &fi); + *fileType = fi.fdType; + return err; +} + +OSErr COS_FileGetSize(SInt16 refNum, SInt32 *logEOF) { + return GetEOF(refNum, logEOF); +} + +OSErr COS_FileRead(SInt16 refNum, void *buffPtr, SInt32 count) { + return FSRead(refNum, &count, buffPtr); +} + +OSErr COS_FileWrite(SInt16 refNum, const void *buffPtr, SInt32 count) { + return FSWrite(refNum, &count, buffPtr); +} + +OSErr COS_FileGetPos(SInt16 refNum, SInt32 *filePos) { + return GetFPos(refNum, filePos); +} + +OSErr COS_FileSetPos(SInt16 refNum, SInt32 filePos) { + return SetFPos(refNum, fsFromStart, filePos); +} + +OSErr COS_FileClose(SInt16 refNum) { + return FSClose(refNum); +} + +void COS_FileSetFSSpec(FSSpec *spec, ConstStringPtr path) { + char buf[256]; + OSSpec ospec; + + memcpy(buf, path + 1, path[0]); + buf[path[0]] = 0; + + if (OS_MakeSpec(buf, &ospec, NULL) || OS_OSSpec_To_FSSpec(&ospec, spec)) { + spec->vRefNum = 0; + spec->parID = 0; + c2pstrcpy(spec->name, buf); + } +} + +OSErr COS_FileMakeFSSpec(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName, FSSpec *spec) { + int oerr; + OSPathSpec opspec; + char buf[256]; + OSSpec ospec; + + oerr = OS_VolDir_To_OSPathSpec(vRefNum, dirID, &opspec); + if (oerr) + return OS_MacError(oerr); + + p2cstrcpy(buf, fileName); + oerr = OS_MakeSpecWithPath(&opspec, buf, 0, &ospec); + if (oerr) { + pstrncpy(spec->name, fileName, 256); + return OS_MacError(oerr); + } else { + return OS_MacError(OS_OSSpec_To_FSSpec(&ospec, spec)); + } +} + +OSErr COS_FileMakeFSSpecWithPath(const FSSpec *inputSpec, ConstStringPtr fileName, FSSpec *spec) { + spec->vRefNum = inputSpec->vRefNum; + spec->parID = inputSpec->parID; + COS_pstrcpy(spec->name, fileName); + return noErr; +} + +OSErr COS_FileGetFileInfo(const FSSpec *spec, OSType *creator, OSType *fileType) { + OSErr err; + FInfo fi; + err = HGetFInfo(spec->vRefNum, spec->parID, spec->name, &fi); + if (fileType) + *fileType = fi.fdType; + if (creator) + *creator = fi.fdCreator; + return err; +} + +void COS_FileGetFSSpecInfo(const FSSpec *spec, SInt16 *vRefNum, SInt32 *dirID, StringPtr fileName) { + if (vRefNum) + *vRefNum = spec->vRefNum; + if (dirID) + *dirID = spec->parID; + if (fileName) + COS_pstrcpy(fileName, spec->name); +} + +static void COS_MakePath(SInt16 vRefNum, SInt32 dirID, StringPtr path) { + FSSpec fss; + OSSpec oss; + fss.vRefNum = vRefNum; + fss.parID = dirID; + COS_pstrcpy(fss.name, path); + if (!OS_FSSpec_To_OSSpec(&fss, &oss)) { + OS_SpecToString(&oss, (char *) path, 256); + c2pstr((char *) path); + } +} + +void COS_FileGetPathName(char *buffer, const FSSpec *spec, SInt32 *mdDat) { + HParamBlockRec rec; + + if (mdDat) { + rec.fileParam.ioNamePtr = (StringPtr) spec->name; + rec.fileParam.ioVRefNum = spec->vRefNum; + rec.fileParam.ioDirID = spec->parID; + rec.fileParam.ioFDirIndex = 0; + if (!PBHGetFInfoSync(&rec)) + *mdDat = rec.fileParam.ioFlMdDat; + else + *mdDat = 0; + } + + COS_pstrcpy((StringPtr) buffer, spec->name); + COS_MakePath(spec->vRefNum, spec->parID, (StringPtr) buffer); + p2cstr((StringPtr) buffer); +} + +int COS_EqualFileSpec(const FSSpec *a, const FSSpec *b) { + if (a->vRefNum != b->vRefNum) + return 0; + if (a->parID != b->parID) + return 0; + return COS_pstrcmp(a->name, b->name) == 0; +} diff --git a/unsorted/uContextParser.cpp b/unsorted/uContextParser.cpp index be1aa0a..35d6dfa 100644 --- a/unsorted/uContextParser.cpp +++ b/unsorted/uContextParser.cpp @@ -103,7 +103,7 @@ CW_CALLBACK CWParserStoreCommandLineForPlugin(CWPluginContext context, int index return cwNoErr; } -CW_CALLBACK CWParserSetNamedPreferences(CWPluginContext context, const char *panelName, CWMemHandle paneldata) { +CW_CALLBACK CWParserSetNamedPreferences(CWPluginContext context, const char *panelName, Handle paneldata) { CWParserContext *pc; if (!(pc = GetContext(context))) return cwErrInvalidCallback; diff --git a/unsorted/uLibImporter.c b/unsorted/uLibImporter.c new file mode 100644 index 0000000..3cf3475 --- /dev/null +++ b/unsorted/uLibImporter.c @@ -0,0 +1,103 @@ +#include "cw_common.h" +#include "cos.h" + +static CWPluginContext compiler_context; + +static void pstrcpy(StringPtr dst, ConstStringPtr src) { + short len = src[0]; + do { + *(dst++) = *(src++); + } while (len-- > 0); +} + +static void ReportError(int index, int osErr) { + char buf[256]; + COS_GetString(buf, 911, index); + if (osErr) + CWOSErrorMessage(compiler_context, buf, osErr); + else + CWReportMessage(compiler_context, NULL, buf, NULL, messagetypeError, 0); +} + +static CWMemHandle ImportObjectLibrary(CWFileSpec *spec, SInt32 *codesize, SInt32 *udatasize, SInt32 *idatasize) { + int err; + short ref; + CWMemHandle mh; + UInt32 *ptr; + SInt32 fsize; + + err = COS_FileOpen(spec, &ref); + if (err) { + ReportError(1, err); + return NULL; + } + + err = COS_FileGetSize(ref, &fsize); + if (err) { + COS_FileClose(ref); + ReportError(1, err); + return NULL; + } + + err = CWAllocMemHandle(compiler_context, 8, 1, &mh); + if (err) { + COS_FileClose(ref); + ReportError(1, err); + return NULL; + } + + err = CWLockMemHandle(compiler_context, mh, 0, (void **) &ptr); + if (err) { + COS_FileClose(ref); + CWFreeMemHandle(compiler_context, mh); + ReportError(1, err); + return NULL; + } + + err = COS_FileRead(ref, ptr, 8); + if (err != (short) err) { + ReportError(1, err); + return NULL; + } + + COS_FileClose(ref); + + if (ptr[0] != 0xFEEDFACE && ptr[0] != 0xCAFEBABE && ptr[0] != CWFOURCHAR('!','<','a','r') && ptr[1] != CWFOURCHAR('c','h','>','\n')) { + CWFreeMemHandle(compiler_context, mh); + ReportError(2, 0); + return NULL; + } + + CWUnlockMemHandle(compiler_context, mh); + *codesize = fsize; + *udatasize = 0; + *idatasize = 0; + return mh; +} + +CWPLUGIN_ENTRY(PPCLibImport_main)(CWPluginContext context) { + SInt32 request; + CWResult result; + CWFileSpec fss; + SInt32 fileNumber; + CWObjectData od; + + result = cwNoErr; + + CWGetPluginRequest(context, &request); + switch (request) { + case reqInitialize: + case reqTerminate: + break; + case 0: + compiler_context = context; + CWGetMainFileSpec(context, &fss); + CWGetMainFileNumber(context, &fileNumber); + memset(&od, 0, sizeof(od)); + od.objectdata = ImportObjectLibrary(&fss, &od.codesize, &od.udatasize, &od.idatasize); + result = CWDonePluginRequest(context, od.objectdata ? CWStoreObjectData(context, fileNumber, &od) : cwErrRequestFailed); + break; + } + + return result; +} |