From 775b6861666af36d317fb577cf489e2c6377f878 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Fri, 14 Oct 2022 23:15:32 +0100 Subject: add tons of stuff --- unsorted/IO.c | 83 +++++++ unsorted/ParserErrors.c | 119 ++++++++++ unsorted/ParserFace.c | 298 ++++++++++++++++++++++++ unsorted/ParserHelpers-cc.c | 158 +++++++++++++ unsorted/ParserHelpers.c | 534 ++++++++++++++++++++++++++++++++++++++++++++ unsorted/Projects.c | 242 ++++++++++++++++++++ unsorted/StaticParserGlue.c | 28 +++ unsorted/Targets.c | 66 ++++++ unsorted/ToolHelpers-cc.c | 35 +++ unsorted/ToolHelpers.c | 289 ++++++++++++++++++++++++ unsorted/uContext1.cpp | 513 ++++++++++++++++++++++++++++++++++++++++++ unsorted/uContextCL.cpp | 501 +++++++++++++++++++++++++++++++++++++++++ unsorted/uContextParser.cpp | 207 +++++++++++++++++ unsorted/uContextSecret.cpp | 39 ++++ 14 files changed, 3112 insertions(+) create mode 100644 unsorted/IO.c create mode 100644 unsorted/ParserErrors.c create mode 100644 unsorted/ParserFace.c create mode 100644 unsorted/ParserHelpers-cc.c create mode 100644 unsorted/ParserHelpers.c create mode 100644 unsorted/Projects.c create mode 100644 unsorted/StaticParserGlue.c create mode 100644 unsorted/Targets.c create mode 100644 unsorted/ToolHelpers-cc.c create mode 100644 unsorted/ToolHelpers.c create mode 100644 unsorted/uContext1.cpp create mode 100644 unsorted/uContextCL.cpp create mode 100644 unsorted/uContextParser.cpp create mode 100644 unsorted/uContextSecret.cpp (limited to 'unsorted') diff --git a/unsorted/IO.c b/unsorted/IO.c new file mode 100644 index 0000000..7ef3cb1 --- /dev/null +++ b/unsorted/IO.c @@ -0,0 +1,83 @@ +#include "mwcc_decomp.h" + +void ShowTextHandle(const char *description, Handle text) { + CWMemHandle mh; + + if (!text) + return; + + if (description) + CLPStatus(71, description); + CWSecretAttachHandle(parseopts.context, text, &mh); + CWParserDisplayTextHandle(parseopts.context, description, mh); +} + +void ShowVersion(Boolean decorate) { + char *vplugin; + char *valtplugin; + const char *bdate; + const char *btime; + Handle txt; + int x; + + vplugin = 0; + valtplugin = 0; + if (parseopts.printedVersion) + return; + + txt = NewHandle(0); + if (!txt) { + fprintf(stderr, "\n*** Out of memory\n"); + exit(-23); + } + + 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 (pTool->TYPE == parseopts.plugins[x].plugintype) { + if (!vplugin && pTool->LANG == parseopts.plugins[x].language) + vplugin = parseopts.plugins[x].version; + else + valtplugin = parseopts.plugins[x].version; + } + } + + CWParserGetBuildDate(parseopts.context, &bdate, &btime); + HPrintF(txt, "\n"); + if (parseopts.toolVersion) { + HPrintF( + txt, + "%s.\n%s, %s\nAll rights reserved.\n%s\n", + pTool->toolInfo, + parseopts.toolVersion->copyright, + parseopts.toolVersion->company, + parseopts.toolVersion->version + ); + } else { + HPrintF( + txt, + "%s.\nCopyright (c)%s Metrowerks, Inc.\nAll rights reserved.\n%s\n", + pTool->toolInfo, + pTool->copyright, + vplugin ? vplugin : valtplugin ? valtplugin : "" + ); + } + + HPrintF(txt, "Runtime Built: %s %s\n", bdate, btime); + HPrintF(txt, "\n"); + + if (decorate) { + HPrintF( + txt, + "Please enter '%s %chelp' for information about options.\n\n", + OS_GetFileNamePtr(parseopts.args->argv[0]), + MAINOPTCHAR[0] + ); + } + + ShowTextHandle(0, txt); + DisposeHandle(txt); + + parseopts.printedVersion = 1; +} diff --git a/unsorted/ParserErrors.c b/unsorted/ParserErrors.c new file mode 100644 index 0000000..172e04c --- /dev/null +++ b/unsorted/ParserErrors.c @@ -0,0 +1,119 @@ +#include "mwcc_decomp.h" + +static char errorbuf[1024]; + +void CLPReportError_V(const char *format, va_list ap) { + vsprintf(errorbuf, format, ap); + CWReportMessage(parseopts.context, NULL, errorbuf, NULL, messagetypeError, 0); + parseopts.hadErrors = 1; +} + +void CLPReportWarning_V(const char *format, va_list ap) { + vsprintf(errorbuf, format, ap); + CWReportMessage(parseopts.context, NULL, errorbuf, NULL, messagetypeWarning, 0); +} + +void CLPReport_V(const char *format, va_list ap) { + vsprintf(errorbuf, format, ap); + CWReportMessage(parseopts.context, NULL, errorbuf, NULL, messagetypeInfo, 0); +} + +void CLPStatus_V(const char *format, va_list ap) { + vsprintf(errorbuf, format, ap); + CWShowStatus(parseopts.context, errorbuf, NULL); +} + +void CLPAlert_V(const char *format, va_list ap) { + vsprintf(errorbuf, format, ap); + CWAlert(parseopts.context, errorbuf, NULL, NULL, NULL); + parseopts.hadErrors = 1; +} + +void CLPOSAlert_V(const char *format, SInt32 err, va_list ap) { + vsprintf(errorbuf, format, ap); + CWAlert(parseopts.context, errorbuf, "Operating system error:", OS_GetErrText(err), NULL); +} + +char *CLPGetErrorString(SInt16 errid, char *buffer) { + getindstring(buffer, 12010, errid); + return buffer; +} + +void CLPReportError(SInt16 errid, ...) { + char format[256]; + va_list va; + + CLPGetErrorString(errid, format); + va_start(va, errid); + CLPReportError_V(format, va); + va_end(va); +} + +void CLPReportWarning(SInt16 errid, ...) { + char format[256]; + va_list va; + + CLPGetErrorString(errid, format); + va_start(va, errid); + CLPReportWarning_V(format, va); + va_end(va); +} + +void CLPReport(SInt16 errid, ...) { + char format[256]; + va_list va; + + CLPGetErrorString(errid, format); + va_start(va, errid); + CLPReport_V(format, va); + va_end(va); +} + +void CLPAlert(SInt16 errid, ...) { + char format[256]; + va_list va; + + CLPGetErrorString(errid, format); + va_start(va, errid); + CLPAlert_V(format, va); + va_end(va); +} + +void CLPOSAlert(SInt16 errid, SInt16 err, ...) { + char format[256]; + va_list va; + + CLPGetErrorString(errid, format); + va_start(va, err); + CLPOSAlert_V(format, err, va); + va_end(va); +} + +void CLPProgress(SInt16 errid, ...) { + char format[256]; + va_list va; + + CLPGetErrorString(errid, format); + va_start(va, errid); + CLPStatus_V(format, va); + va_end(va); +} + +void CLPStatus(SInt16 errid, ...) { + char format[256]; + va_list va; + + CLPGetErrorString(errid, format); + va_start(va, errid); + CLPStatus_V(format, va); + va_end(va); +} + +void CLPFatalError(const char *format, ...) { + va_list va; + + va_start(va, format); + CLPAlert_V(format, va); + va_end(va); + longjmp(exit_plugin, -123); +} diff --git a/unsorted/ParserFace.c b/unsorted/ParserFace.c new file mode 100644 index 0000000..24f3213 --- /dev/null +++ b/unsorted/ParserFace.c @@ -0,0 +1,298 @@ +#include "mwcc_decomp.h" + +const char *failedCallback; +jmp_buf exit_plugin; +struct ParseOptsType parseopts; + +static CWResult SetupParamBlock(CWPluginContext context) { + CWResult result; + int x; + Handle h; + PCmdLineEnvir cle; + + memset(&parseopts, 0, sizeof(parseopts)); + parseopts.context = context; + + result = CWSecretGetNamedPreferences(context, "CmdLine Environment", &h); + if (result) + return result; + + cle = **((PCmdLineEnvir **) h); + parseopts.underIDE = cle.underIDE; + parseopts.ioRows = cle.rows; + parseopts.ioCols = cle.cols; + + result = CWParserGetCommandLine(context, &parseopts.args); + if (result) + return result; + + result = CWParserGetToolInfo(context, &parseopts.toolVersion); + if (result) + return result; + + result = CWParserGetTargetInfo(context, &parseopts.cpu, &parseopts.os); + if (result) + return result; + + result = CWParserGetPanels(context, &parseopts.numPanels, &parseopts.panelNames); + if (result) + return result; + + result = CWParserGetPlugins(context, &parseopts.numPlugins, &parseopts.plugins); + if (result) + return result; + + parseopts.passingArgs = 0; + for (x = 0; x < parseopts.numPlugins; x++) { + if (parseopts.plugins[x].storeCommandLine) + parseopts.passingArgs = 1; + } + + return 0; +} + +static CWResult SetupOptions(CWPluginContext context) { + if (!pTool) { + return 2; + } else { + SetupParserToolOptions(); + return 0; + } +} + +static CWResult Parse(CWPluginContext context) { + CWResult result; + + parseopts.success = 1; + parseopts.currentSegment = 1; + parseopts.currentOverlayGroup = 0; + parseopts.currentOverlay = 0; + + Arg_InitToolArgs(&linkargs); + Arg_InitToolArgs(&prelinkargs); + Arg_InitToolArgs(&postlinkargs); + + if (pTool->PreParse) + parseopts.success &= pTool->PreParse(); + + Arg_Init(parseopts.args->argc, parseopts.args->argv); + parseopts.noOptions = Arg_IsEmpty(); + parseopts.success &= Options_Parse(Options_GetOptions(), OFLAGS_1) && !parseopts.hadErrors; + Arg_Reset(); + + result = Parser_StorePanels(context); + if (result) + return result; + + if (pTool->MidParse && parseopts.success) + parseopts.success &= pTool->MidParse(); + + result = Parser_StorePanels(context); + if (result) + return result; + + if (parseopts.showHelp && parseopts.success) + parseopts.success &= Options_DisplayHelp(); + + Arg_Reset(); + if (parseopts.success) + parseopts.success &= Options_Parse(Options_GetOptions(), 0) && !parseopts.hadErrors; + + if (pTool->PostParse && parseopts.success) + parseopts.success &= pTool->PostParse(); + + Arg_Terminate(); + + return (parseopts.success && !parseopts.hadErrors) ? cwNoErr : cwErrRequestFailed; +} + +Handle Parser_FindPrefPanel(const char *name) { + int idx; + Handle h; + + for (idx = 0; idx < pTool->numPrefDataPanels; idx++) { + if (!ustrcmp(name, pTool->prefDataPanels[idx].name)) { + h = NewHandle(pTool->prefDataPanels[idx].size); + if (!h) + return NULL; + + HLock(h); + memcpy(*h, pTool->prefDataPanels[idx].ptr, pTool->prefDataPanels[idx].size); + HUnlock(h); + return h; + } + } + + return NULL; +} + +CWResult Parser_StorePanels(CWPluginContext context) { + int idx; + CWResult result; + const char *name; + Handle h; + + for (idx = 0; idx < parseopts.numPanels; idx++) { + name = parseopts.panelNames[idx]; + h = Parser_FindPrefPanel(name); + if (h) { + result = CWParserSetNamedPreferences(parseopts.context, name, (CWMemHandle) h); + if (result) { + CLPReportError(68, name); + return result; + } + } + } + + return cwNoErr; +} + +static CWResult StoreResults(CWPluginContext context) { + int idx; // r25 + CWResult result; + CWCommandLineArgs args; + UInt32 id; // r8 + UInt32 lg; // r10 + + result = Parser_StorePanels(context); + if (result) + return result; + + for (idx = 0; idx < parseopts.numPlugins; idx++) { + if (parseopts.plugins[idx].plugintype == CWDROPINLINKERTYPE && parseopts.plugins[idx].storeCommandLine) { + if (parseopts.plugins[idx].dropinflags & isPreLinker) { + Arg_ToolArgsForPlugin(&prelinkargs, &args); + } else if (parseopts.plugins[idx].dropinflags & isPostLinker) { + Arg_ToolArgsForPlugin(&postlinkargs, &args); + } else { + Arg_ToolArgsForPlugin(&linkargs, &args); + } + result = CWParserStoreCommandLineForPlugin(parseopts.context, idx, &args); + if (result) + return result; + } else if (parseopts.plugins[idx].storeCommandLine) { + id = parseopts.plugins[idx].plugintype; + lg = parseopts.plugins[idx].language; + fprintf(stderr, + "*** No support for %c%c%c%c/%c%c%c%c tool\n", + (id & 0xFF000000) >> 24, + (id & 0x00FF0000) >> 16, + (id & 0x0000FF00) >> 8, + (id & 0x000000FF), + (lg & 0xFF000000) >> 24, + (lg & 0x00FF0000) >> 16, + (lg & 0x0000FF00) >> 8, + (lg & 0x000000FF) + ); + } + } + + return cwNoErr; +} + +short CWParser_GetDropInFlags(const DropInFlags **flags, SInt32 *flagsSize) { + static const DropInFlags sFlags = { + kCurrentDropInFlagsVersion, + CWFOURCHAR('P','a','r','s'), + 7, + 0, + 'Seep', + 12 + }; + *flags = &sFlags; + *flagsSize = sizeof(sFlags); + return 0; +} + +short CWParser_GetDropInName(const char **dropinName) { + static const char *sDropInName = "Command-Line Parser"; + *dropinName = sDropInName; + return 0; +} + +short CWParser_GetDisplayName(const char **displayName) { + static const char *sDisplayName = "Command-Line Parser"; + *displayName = sDisplayName; + return 0; +} + +short CWParser_GetPanelList(const CWPanelList **panelList) { + static CWPanelList sPanelList = { + kCurrentCWFamilyListVersion, + 0, + 0 + }; + *panelList = &sPanelList; + return 0; +} + +short CWParser_GetTargetList(const CWTargetList **targetList) { + static CWDataType sCPU = '****'; + static CWDataType sOS = '****'; + static CWTargetList sTargetList = { + kCurrentCWTargetListVersion, + 1, + &sCPU, + 1, + &sOS + }; + *targetList = &sTargetList; + return 0; +} + +short CWParser_GetVersionInfo(const VersionInfo **versioninfo) { + static const VersionInfo vi = { + 1, 1, 0, 0 + }; + *versioninfo = &vi; + return 0; +} + +short Parser_SupportsPlugin(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) { + *isSupported = ParserToolHandlesPanels(numPanels, panelNames); + return 0; +} + +short parser_main(CWPluginContext context) { + CWResult result; + SInt32 request; + + CWGetPluginRequest(context, &request); + result = setjmp(exit_plugin); + if (result == 0) { + switch (request) { + case reqInitialize: + result = 0; + break; + case 0: + break; + case 1: + result = SetupParamBlock(context); + if (!result) + result = Parser_StorePanels(context); + break; + case 2: + result = SetupParamBlock(context); + if (!result) { + result = SetupOptions(context); + if (!result) { + result = Parse(context); + if (!result) + result = StoreResults(context); + } + } + break; + } + } else { + if (failedCallback && result != 1) + fprintf(stderr, "Unexpected error in %s [%d]\n", failedCallback, result); + } + CWDonePluginRequest(context, result); + + return result; +} diff --git a/unsorted/ParserHelpers-cc.c b/unsorted/ParserHelpers-cc.c new file mode 100644 index 0000000..d56fe4d --- /dev/null +++ b/unsorted/ParserHelpers-cc.c @@ -0,0 +1,158 @@ +#include "mwcc_decomp.h" + +Handle definesHandle; + +int Opt_AddStringToDefines(const char *opt, void *str, const char *param) { + AddStringToHandle(&definesHandle, (const char *) str); + if (param) + AddStringToHandle(&definesHandle, param); + return 1; +} + +int Opt_DefineSymbol(const char *var, const char *value) { + char tmp[1024]; + + if (pTool->LANG == Lang_C_CPP || pTool->LANG == CWFOURCHAR('A','s','m',' ') || pTool->LANG == Lang_Rez) { + sprintf(tmp, "#define %s %s\n", var, value ? value : "1"); + } else if (pTool->LANG == Lang_Pascal) { + 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); + return 0; + } + + AddStringToHandle(&definesHandle, tmp); + return 1; +} + +int Opt_UndefineSymbol(const char *opt, void *, const char *arg) { + char tmp[300]; + + if (pTool->LANG == Lang_C_CPP || pTool->LANG == CWFOURCHAR('A','s','m',' ')) { + sprintf(tmp, "#undef %s\n", arg); + } else if (pTool->LANG == Lang_Pascal) { + sprintf(tmp, "{$undefc %s}\n", arg); + } else { + sprintf(tmp, "Option -%s is not supported with this plugin", opt); + CLPReportError(28, tmp); + return 0; + } + + AddStringToHandle(&definesHandle, tmp); + return 1; +} + +int Opt_AddPrefixFile(const char *opt, void *handle, const char *filename) { + char tmp[300]; + + handle = !handle ? &definesHandle : handle; + if (!filename[0]) + return 1; + + if (pTool->LANG == Lang_C_CPP || pTool->LANG == CWFOURCHAR('A','s','m',' ')) { + if (filename[0] == '<' && filename[strlen(filename) - 1] == '>') { + snprintf(tmp, sizeof(tmp), "#include %s\n", filename); + } else { + snprintf(tmp, sizeof(tmp), "#include \"%s\"\n", filename); + } + } else if (pTool->LANG == Lang_Pascal) { + 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); + return 0; + } + + AddStringToHandle((Handle *) handle, tmp); + return 1; +} + +int Opt_PragmaTrueFalse(const char *, void *flag, const char *, int flags) { + if (flags & PARAMPARSEFLAGS_8) + *((unsigned char *) flag) = PR_OFF; + else + *((unsigned char *) flag) = PR_ON; + return 1; +} + +int Opt_PragmaFalseTrue(const char *, void *flag, const char *, int flags) { + if (flags & PARAMPARSEFLAGS_8) + *((unsigned char *) flag) = PR_ON; + else + *((unsigned char *) flag) = PR_OFF; + return 1; +} + +int Opt_PragmaOnOff(const char *, void *flag, const char *arg) { + if (!arg) { + CLPReportError(34); + return 0; + } + + if (!ustrcmp(arg, "on")) { + *((unsigned char *) flag) = PR_ON; + } else if (!ustrcmp(arg, "off")) { + *((unsigned char *) flag) = PR_OFF; + } else { + CLPReportError(12, arg); + return 0; + } + + return 1; +} + +int Opt_PragmaOffOn(const char *, void *flag, const char *arg) { + if (!arg) { + CLPReportError(34); + return 0; + } + + if (!ustrcmp(arg, "on")) { + *((unsigned char *) flag) = PR_OFF; + } else if (!ustrcmp(arg, "off")) { + *((unsigned char *) flag) = PR_ON; + } else { + CLPReportError(12, arg); + return 0; + } + + return 1; +} + +int SetupPragmas(const Pragma *pragmas) { + const char *set; + char on; + char off; + char tmp[300]; + + while (pragmas->pragma) { + if (pragmas->flags == PRAGMA_FLAGS_0 || pragmas->flags == PRAGMA_FLAGS_1) { + set = 0; + on = !(pragmas->flags == PRAGMA_FLAGS_1) ? PR_ON : PR_OFF; + off = !(pragmas->flags == PRAGMA_FLAGS_1) ? PR_OFF : PR_ON; + if (*((char *)pragmas->value) == on) + set = "on"; + else if (*((char *)pragmas->value) == off) + set = "off"; + else if (*((char *)pragmas->value) == PR_AUTO) + set = "auto"; + else if (*((char *)pragmas->value) == PR_RESET) + set = "reset"; + else +#line 186 + OPTION_ASSERT(*((char *)pragmas->value) == PR_UNSET); + + if (set) { + snprintf(tmp, sizeof(tmp), "#pragma %s %s\n", pragmas->pragma, set); + AddStringToHandle(&definesHandle, tmp); + } + } else { +#line 195 + OPTION_ASSERT(!"Can't handle pragma"); + } + pragmas++; + } + + return 1; +} diff --git a/unsorted/ParserHelpers.c b/unsorted/ParserHelpers.c new file mode 100644 index 0000000..c8d4c55 --- /dev/null +++ b/unsorted/ParserHelpers.c @@ -0,0 +1,534 @@ +#include "mwcc_decomp.h" +#include + +SInt16 lastStage; +Boolean dashIMinusMovesPaths; +Boolean usedDashIMinus; +Boolean namingSysPaths; +static char STSbuf[256]; + +int FindFileInPath(const char *filename, OSSpec *fss) { + CWFileInfo fi; + CWResult result; + + fi.fullsearch = 1; + fi.dependencyType = 0; + fi.suppressload = 1; + fi.isdependentoffile = kCurrentCompiledFile; + + result = CWFindAndLoadFile(parseopts.context, filename, &fi); + if (!result) { + OS_FSSpec_To_OSSpec(&fi.filespec, fss); + return 1; + } else { + return 0; + } +} + +char *GetEnvVar(const char *name, Boolean warn, const char **match) { + const char *nptr; + const char *last; + char *ret; + + nptr = name; + last = name; + while (*nptr) { + ret = getenv(nptr); + if (ret) { + if (match) + *match = nptr; + return ret; + } + last = nptr; + nptr = &nptr[1 + strlen(nptr)]; + } + + if (warn) + CLPReportWarning(52, last); + *match = 0; + return 0; +} + +static Boolean MatchesExtension(const char *list, const char *filename) { + char *fn; + const char *eptr; + const char *ptr; + + fn = OS_GetFileNamePtr((char *) filename); + eptr = strrchr(fn, '.'); + if (!eptr) + return 0; + if (!list) + return 1; + + ptr = eptr; + while (*list) { + if (*list == '|' && !*ptr) + return 1; + + if (my_tolower(*list) == my_tolower(*ptr)) { + list++; + ptr++; + continue; + } + + while (*list && *list != '|') + list++; + if (*list) + list++; + ptr = eptr; + } + + return !*list && !*ptr; +} + +int Opt_AddAccessPath(const char *opt, void *var, const char *arg) { + OSPathSpec spec; + int err; + + arg = arg ? arg : opt; + if (!arg) + return 0; + if (!arg[0]) + return 1; + + if (strlen(arg) >= 256) { + CLPReportError(13, arg + strlen(arg) - 32, 256); + return 0; + } + + err = OS_MakePathSpec(0, arg, &spec); + if (err == ENOENT || err == ENOENT) { + CLPReportWarning(45, arg); + return 1; + } else if (err != 0) { + CLPOSAlert(45, err, arg); + return 1; + } + + // this 'if' gets optimised unnecessarily + if (!AddAccessPath(&spec, namingSysPaths, 0, var != NULL)) + return 0; + else + return 1; +} + +int Opt_AddFrameworkPath(const char *opt, void *var, const char *arg) { + OSPathSpec spec; + int err; + + arg = arg ? arg : opt; + if (!arg) + return 0; + if (!arg[0]) + return 1; + + if (strlen(arg) >= 256) { + CLPReportError(13, arg + strlen(arg) - 32, 256); + return 0; + } + + err = OS_MakePathSpec(0, arg, &spec); + if (err == ENOENT || err == ENOENT) { + CLPReportWarning(45, arg); + return 1; + } else if (err != 0) { + CLPOSAlert(45, err, arg); + return 1; + } else { + Frameworks_AddPath(&spec); + return 1; + } +} + +int Opt_AddFramework(const char *opt, void *var, const char *arg) { + if (!Frameworks_AddFramework(arg ? arg : opt, 0, 0)) + return 0; + else + return 1; +} + +void ListParseMessage(void (*errprint)(const char *, va_list), const char *envvar, SInt16 id, ...) { + char buf[1024]; + va_list ap; + + if (envvar && envvar[0]) + sprintf(buf, "In environment variable '%s':\n", envvar); + else + buf[0] = 0; + + CLPGetErrorString(id, buf + strlen(buf)); + va_start(ap, id); + errprint(buf, ap); + va_end(ap); +} + +int AddAccessPathList(const char *list, char sep1, char sep2, int source, char *text, Boolean system, SInt32 position, Boolean recursive) { + char tmp[256]; + Boolean recurse; + OSPathSpec spec; + int err; + short type; + char *ptr; + + type = (Boolean) ((system == 1) ? 1 : 0) | (!source ? 0 : 2); + recurse = (list[0] == '+'); + if (recurse) + ++list; + + if (!strchr(list, sep1)) + sep1 = sep2; + + while (*list) { + ptr = tmp; + while (*list && *list != sep1 && (ptr + 1) < &tmp[256]) { + *(ptr++) = *(list++); + } + *ptr = 0; + + if ((ptr + 1) >= &tmp[256]) { + ListParseMessage( + CLPReportError_V, + (source == 1) ? text : NULL, + 9, + tmp, + tmp + strlen(tmp) - 16, + 256); + return 0; + } + + err = OS_MakePathSpec(0, tmp, &spec); + if (err) { + ListParseMessage( + CLPReportWarning_V, + (source == 1) ? text : NULL, + 45, + tmp); + } else { + AddAccessPath(&spec, type, position, recurse ^ recursive); + } + + if (*list) + ++list; + recurse = *list == '+'; + if (recurse) + ++list; + } + + return 1; +} + +int Opt_FindAndAddFile(const char *opt, void *var, const char *arg) { + OSSpec spec; + int err; + Boolean isfile; + + arg = arg ? arg : opt; + if (!arg) + return 0; + if (!*arg) + return 1; + + parseopts.userSpecifiedFiles++; + err = OS_MakeSpec(arg, &spec, &isfile); + if (!err) + err = OS_Status(&spec); + + if (!err && !isfile) { + CLPReportError(47, arg); + parseopts.unusedFiles++; + return 0; + } else if (err && err != ENOENT) { + CLPOSAlert(44, err, arg); + parseopts.unusedFiles++; + return 0; + } else if (err && parseopts.alwaysUsePaths) { + err = FindFileInPath(arg, &spec) ? 0 : ENOENT; + } + + if (err) { + CLPReportError(44, arg); + parseopts.unusedFiles++; + return 0; + } + + if (var && !MatchesExtension((const char *) var, arg)) + CLPReportWarning(76, arg, var); + + if (!AddFileToProject(&spec, lastStage, parseopts.lastoutputname, 1, -1)) { + parseopts.unusedFiles++; + return 0; + } else { + parseopts.lastoutputname[0] = 0; + return 1; + } +} + +int Opt_FindAndAddFileRef(const char *opt, void *var, const char *arg) { + OSSpec spec; + int err; + Boolean isfile; + + arg = arg ? arg : opt; + if (!arg) + return 0; + if (!*arg) + return 1; + + parseopts.userSpecifiedFiles++; + if (var && !MatchesExtension((const char *) var, arg)) + CLPReportWarning(76, arg, var); + + err = OS_MakeSpec(arg, &spec, &isfile); + if (!err) + err = OS_Status(&spec); + + if (!err && !isfile) { + CLPReportError(47, arg); + parseopts.unusedFiles++; + return 0; + } else if (err && parseopts.alwaysUsePaths) { + err = FindFileInPath(arg, &spec) ? 0 : ENOENT; + } + + if (!AddFileToProject(&spec, 0, 0, err == 0, -1)) { + parseopts.unusedFiles++; + return 0; + } else { + return AddAccessPath(&spec.path, 1, -1, 0) != 0; + } +} + +int Opt_AddUnixLibraryFile(const char *opt, void *var, const char *name) { + OSSpec spec; + Boolean failed; + const char *eptr; + const char *eend; + char tmpname[64]; + + if (strlen(name) >= 56) { + CLPReportError(13, name + strlen(name) - 32, 64); + return 0; + } + + failed = 1; + if (!var) + var = ".lib|.a"; + + eptr = (const char *) var; + while (eptr && *eptr) { + eend = eptr; + while (*eend && *eend != '|') + ++eend; + + sprintf(tmpname, "lib%s%*.*s", name, eend - eptr, eend - eptr, eptr); + if (FindFileInPath(tmpname, &spec)) { + failed = 0; + break; + } + + if (*eend) + eptr = eend + 1; + else + eptr = eend; + } + + if (failed) { + failed = !FindFileInPath(name, &spec); + if (failed) + CLPReportError(49, name, var, name); + } + + if (!failed) { + if (!AddFileToProject(&spec, 0, 0, 1, -1)) { + parseopts.unusedFiles++; + failed = 1; + } + } + + return !failed; +} + +int AddFileList(const char *list, char sep1, char sep2, int source, char *text, SInt32 position) { + char tmp[256]; + OSSpec spec; + char *ptr; + + if (!strchr(list, sep1)) + sep1 = sep2; + + while (*list) { + ptr = tmp; + while (*list && *list != sep1 && (ptr + 1) < &tmp[256]) { + *(ptr++) = *(list++); + } + *ptr = 0; + + if ((ptr + 1) >= &tmp[256]) { + ListParseMessage( + CLPReportError_V, + (source == 1) ? text : 0, + 9, + tmp, + tmp + strlen(tmp) - 16, + 256 + ); + return 0; + } + + if (!FindFileInPath(tmp, &spec)) { + if (OS_IsDir(&spec)) { + ListParseMessage( + CLPReportError_V, + (source == 1) ? text : 0, + 16, + tmp + ); + } else { + ListParseMessage( + CLPReportWarning_V, + (source == 1) ? text : 0, + 44, + tmp + ); + } + } else { + AddFileToProject(&spec, 0, 0, 1, position); + } + + if (*list) + ++list; + } + + return 1; +} + +int IsFileInOutputDirectory(const OSSpec *file) { + OSPathSpec outdir; + GetOutputFileDirectory(&outdir); + return OS_EqualPathSpec(&outdir, &file->path); +} + +void GetCFileNameInOutputDirectory(const char *input, char *name, int maxlen) { + char filename[64]; + OSSpec spec; + int err; + + err = OS_MakeFileSpec(input, &spec); + if (err) { + CLPOSAlert(64, err, input); + name[0] = 0; + return; + } + + if (!IsFileInOutputDirectory(&spec)) { + CLPReportWarning(61, OS_SpecToStringRelative(&spec, 0, STSbuf, sizeof(STSbuf))); + } + + OS_NameSpecToString(&spec.name, filename, 256); + if (strlen(filename) >= maxlen) { + CLPReportWarning(65, filename, maxlen - 1); + filename[maxlen - 1] = 0; + } + + strcpy(name, filename); +} + +void GetPFileNameInOutputDirectory(const char *input, unsigned char *name, int len) { + GetCFileNameInOutputDirectory(input, (char *) name, len); + c2pstr((char *) name); +} + +void AddStringLenToHandle(Handle *h, const char *str, int len) { + SInt32 old; + + if (!*h) { + if ((*h = NewHandle(len + 1))) { + HLock(*h); + memcpy(**h, str, len); + (**h)[len] = 0; + HUnlock(*h); + } else { + exit(-23); + } + } else { + old = GetHandleSize(*h) - 1; + SetHandleSize(*h, old + len + 1); + if (MemError() == noErr) { + HLock(*h); + memcpy(**h + old, str, len); + (**h)[old + len] = 0; + HUnlock(*h); + } else { + exit(-23); + } + } +} + +void AddStringToHandle(Handle *h, const char *str) { + AddStringLenToHandle(h, str, strlen(str)); +} + +int Opt_PrintVersion(const char *opt, void *var, const char *arg) { + ShowVersion(0); + return 1; +} + +void GetFirstSourceFilenameBase(char *buffer, char *defaul) { + int cnt; + OSSpec spec; + char compiler[32]; + int x; + char *ext; + + cnt = GetFileCount(); + for (x = 0; x < cnt; x++) { + if (GetFileInfo(x, &spec, compiler)) { + if (compiler[0]) { + if (!strstr(compiler, "Lib")) { + OS_NameSpecToString(&spec.name, buffer, 256); + ext = strrchr(buffer, '.'); + if (ext) + *ext = 0; + memmove(buffer, buffer, strlen(buffer) + 1); + return; + } + } + } + } + + strcpy(buffer, defaul); +} + +int Opt_SavePrefs(const char *opt, void *var, const char *arg) { + Parser_StorePanels(parseopts.context); + return 1; +} + +int ParseNumber(const char *arg, Boolean emit_error, SInt32 *ret, const char **endptr) { + char *end; + + if (arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X')) { + *ret = strtol(arg + 2, &end, 16); + } else if (arg[0] == '0') { + *ret = strtol(arg + 1, &end, 8); + } else { + *ret = strtol(arg, &end, 10); + } + + if (endptr) + *endptr = end; + + if (*end && emit_error) { + CLPReportError(5, "", arg); + return 0; + } + + return 1; +} + +int Opt_MaybeMoveAccessPaths(const char *opt, void *var, const char *arg) { + if (dashIMinusMovesPaths && !usedDashIMinus) + MoveSystemPathsIntoUserList(); + return 1; +} diff --git a/unsorted/Projects.c b/unsorted/Projects.c new file mode 100644 index 0000000..72b06b1 --- /dev/null +++ b/unsorted/Projects.c @@ -0,0 +1,242 @@ +#include "mwcc_decomp.h" + +// TODO: figure out who defines this +extern char STSbuf[256]; + +int GetFileCount() { + SInt32 num; + CWGetProjectFileCount(parseopts.context, &num); + return num; +} + +void SetFileOutputName(SInt32 position, SInt16 which, char *outfilename) { + CWResult result; + if (outfilename && outfilename[0]) { + result = CWParserSetFileOutputName(parseopts.context, position, which ? which : 1, outfilename); + if (result) { + failedCallback = "CWParserSetFileOutputName"; + longjmp(exit_plugin, result); + } + } +} + +int AddFileToProject(OSSpec *oss, SInt16 which, char *outfilename, Boolean exists, SInt32 position) { + CWFileSpec cws; + CWNewProjectEntryInfo pei; + CWResult result; + int err; + + err = OS_OSSpec_To_FSSpec(oss, &cws); + if (err) { + CLPOSAlert(44, err, OS_SpecToStringRelative(oss, 0, STSbuf, sizeof(STSbuf))); + return 0; + } + + if (position == -2) { + pei.position = 0; + } else if (position == -1) { + CWGetProjectFileCount(parseopts.context, &pei.position); + } else if (position == 0) { + pei.position = -1; + } else { + pei.position = position; + } + + pei.segment = parseopts.currentSegment; + pei.overlayGroup = parseopts.currentOverlayGroup; + pei.overlay = parseopts.currentOverlay; + pei.groupPath = NULL; + pei.mergeintooutput = parseopts.mergeIntoOutput; + pei.weakimport = parseopts.weakImport; + pei.initbefore = parseopts.initBefore; + result = CWAddProjectEntry(parseopts.context, &cws, exists == 0, &pei, &position); + if (result) { + failedCallback = "CWAddProjectEntry"; + longjmp(exit_plugin, result); + } + parseopts.initBefore = 0; + parseopts.weakImport = 0; + parseopts.mergeIntoOutput = 0; + SetFileOutputName(position, which, outfilename); + return 1; +} + +Boolean GetFileInfo(SInt32 position, OSSpec *spec, char *plugin) { + CWProjectFileInfo pfi; + if (CWGetFileInfo(parseopts.context, position, 1, &pfi)) + return 0; + + OS_FSSpec_To_OSSpec(&pfi.filespec, spec); + strncpy(plugin, pfi.dropinname, 32); + plugin[31] = 0; + return 1; +} + +int AddAccessPath(OSPathSpec *oss, SInt16 type, SInt32 position, Boolean recursive) { + CWNewAccessPathInfo api; + CWResult result; + OSSpec spec; + int err; + CWAccessPathListInfo apli; + + if ((err = OS_MakeSpecWithPath(oss, NULL, 0, &spec)) || (err = OS_OSSpec_To_FSSpec(&spec, &api.pathSpec))) { + CLPOSAlert(45, err, OS_PathSpecToString(&spec.path, STSbuf, sizeof(STSbuf))); + return 0; + } + + if (position == -2) { + api.position = 0; + } else if (position == -1 || position == 0) { + api.position = -1; + } else if (position == -1) { + result = CWGetAccessPathListInfo(parseopts.context, &apli); + if (result) { + failedCallback = "CWGetAccessPathListInfo"; + longjmp(exit_plugin, result); + } + if ((type & 1) == 1) { + api.position = apli.systemPathCount; + } else { + api.position = apli.userPathCount; + } + } else { + api.position = position; + } + + api.type = (type & 1) ? cwSystemPath : cwUserPath; + api.type = api.type | (CWAccessPathType) ((type & 2) ? cwAccessPathTypeFlag2 : 0); + api.recursive = recursive; + + result = CWParserAddAccessPath(parseopts.context, &api); + if (result) { + failedCallback = "CWParserAddAccessPath"; + longjmp(exit_plugin, result); + } + + return 1; +} + +int MoveSystemPathsIntoUserList() { + CWResult result = CWParserSwapAccessPaths(parseopts.context); + return result == cwNoErr; +} + +void AddVirtualFile(const char *filename, Handle *text) { + CWResult result; + CWMemHandle mh; + + if (*text) { + CWSecretAttachHandle(parseopts.context, *text, &mh); + result = CWParserCreateVirtualFile(parseopts.context, filename, mh); + if (result) { + failedCallback = "CWParserCreateVirtualFile"; + longjmp(exit_plugin, result); + } + DisposeHandle(*text); + *text = NULL; + } +} + +void GetOutputFileDirectory(OSPathSpec *dir) { + CWResult result; + CWFileSpec idefss; + OSSpec spec; + + result = CWGetOutputFileDirectory(parseopts.context, &idefss); + if (result) { + failedCallback = "CWGetOutputFileDirectory"; + longjmp(exit_plugin, result); + } + + OS_FSSpec_To_OSSpec(&idefss, &spec); + *dir = spec.path; +} + +void SetOutputFileDirectory(OSPathSpec *dir) { + CWResult result; + CWFileSpec idefss; + OSSpec spec; + + OS_MakeSpecWithPath(dir, NULL, 0, &spec); + OS_OSSpec_To_FSSpec(&spec, &idefss); + + result = CWParserSetOutputFileDirectory(parseopts.context, &idefss); + if (result) { + failedCallback = "CWParserSetOutputFileDirectory"; + longjmp(exit_plugin, result); + } +} + +void AddOverlayGroup(const char *name, CWAddr64 *addr, SInt32 *groupnum, SInt32 *overlaynum) { + CWResult result; + + *overlaynum = -1; + result = CWParserAddOverlay1Group(parseopts.context, name, addr, groupnum); + if (result) { + if (result == cwErrInvalidCallback) { + CLPReportError(72); + } else { + failedCallback = "CWParserAddOverlay1Group"; + longjmp(exit_plugin, result); + } + } +} + +void AddOverlay(SInt32 groupnum, const char *name, SInt32 *overlaynum) { + CWResult result; + + result = CWParserAddOverlay1(parseopts.context, name, groupnum, overlaynum); + if (result) { + if (result == cwErrInvalidCallback) { + CLPReportError(72); + } else { + failedCallback = "CWParserAddOverlay1"; + longjmp(exit_plugin, result); + } + } +} + +void AddSegment(const char *name, SInt16 attrs, SInt32 *segmentnum) { + CWResult result; + + result = CWParserAddSegment(parseopts.context, name, attrs, segmentnum); + if (result) { + if (result == cwErrInvalidCallback) { + CLPReportError(73); + } else { + failedCallback = "CWParserAddSegment"; + longjmp(exit_plugin, result); + } + } +} + +void ChangeSegment(SInt32 segmentnum, const char *name, SInt16 attrs) { + CWResult result; + + result = CWParserSetSegment(parseopts.context, segmentnum, name, attrs); + if (result) { + if (result == cwErrInvalidCallback) { + CLPReportError(73); + } else { + failedCallback = "CWParserSetSegment"; + longjmp(exit_plugin, result); + } + } +} + +int GetSegment(SInt32 segmentnum, char *name, SInt16 *attrs) { + CWResult result; + CWProjectSegmentInfo psi; + + result = CWGetSegmentInfo(parseopts.context, segmentnum, &psi); + if (result) { + if (result == cwErrInvalidCallback) { + CLPReportError(73); + } + return 0; + } + + strcpy(name, psi.name); + *attrs = psi.attributes; + return 1; +} diff --git a/unsorted/StaticParserGlue.c b/unsorted/StaticParserGlue.c new file mode 100644 index 0000000..4673c27 --- /dev/null +++ b/unsorted/StaticParserGlue.c @@ -0,0 +1,28 @@ +#include "mwcc_decomp.h" + +static BasePluginCallbacks cb = { + parser_main, + CWParser_GetDropInFlags, + CWParser_GetDisplayName, + CWParser_GetDropInName, + CWParser_GetPanelList, + NULL, + NULL, + CWParser_GetVersionInfo, + NULL +}; + +static ParserPluginCallbacks pr_cb = { + Parser_SupportsPlugin, + Parser_SupportsPanels +}; + +int RegisterStaticParserPlugins() { + return RegisterStaticParserPlugin(&cb, &pr_cb); +} + +#include "ParserErrors.r" + +int RegisterStaticParserResources() { + return RegisterResource("Parser Strings", 12010, STR12010); +} diff --git a/unsorted/Targets.c b/unsorted/Targets.c new file mode 100644 index 0000000..b4307ff --- /dev/null +++ b/unsorted/Targets.c @@ -0,0 +1,66 @@ +#include "mwcc_decomp.h" + +ParserTool *pTool; + +int SetParserToolInfo(ParserTool *tool) { + pTool = tool; + +#line 16 + OPTION_ASSERT(pTool->toolInfo && (parseopts.toolVersion || pTool->copyright)); + + return 1; +} + +Boolean ParserToolMatchesPlugin(OSType type, OSType lang, OSType cpu, OSType os) { + if (!pTool) { + CLPFatalError("No options loaded for command line\n"); + return 0; + } + + if ( + (type == CWFOURCHAR('*','*','*','*') || pTool->TYPE == CWFOURCHAR('*','*','*','*') || pTool->TYPE == type) && + (lang == CWFOURCHAR('*','*','*','*') || pTool->LANG == CWFOURCHAR('*','*','*','*') || pTool->LANG == lang) && + (cpu == targetCPUAny || pTool->CPU == targetCPUAny || pTool->CPU == cpu) && + (os == targetOSAny || pTool->OS == targetOSAny || pTool->OS == os) + ) + { + return 1; + } else { + return 0; + } +} + +Boolean ParserToolHandlesPanels(int numPanels, const char **panelNames) { + int idx; + int scan; + + if (!pTool) + CLPFatalError("No options loaded for command line\n"); + + for (idx = 0; idx < numPanels; idx++) { + for (scan = 0; scan < pTool->numPrefPanels; scan++) { + if (!ustrcmp(pTool->prefPanels[scan], panelNames[idx])) + break; + } + + if (scan >= pTool->numPrefPanels) + break; + } + + if (idx >= numPanels) + return 1; + else + return 0; +} + +Boolean SetupParserToolOptions() { + int idx; + + Options_Init(); + for (idx = 0; idx < pTool->numOptionLists; idx++) { + Options_AddList(pTool->optionLists[idx]); + } + Options_SortOptions(); + + return 1; +} diff --git a/unsorted/ToolHelpers-cc.c b/unsorted/ToolHelpers-cc.c new file mode 100644 index 0000000..dd0bc92 --- /dev/null +++ b/unsorted/ToolHelpers-cc.c @@ -0,0 +1,35 @@ +#include "mwcc_decomp.h" + +int Opt_DummyLinkerRoutine(const char *opt) { + CLPFatalError("Calling linker option '%s'\n", opt); + return 0; +} + +int Opt_DummyLinkerSettingRoutine(const char *var, const char *val) { + CLPFatalError("Calling linker settings option '%s'='%s'\n", var, val ? val : ""); + return 0; +} + +void FinishCompilerTool() { + SInt32 numfiles; + + if (parseopts.lastoutputname[0]) { + numfiles = GetFileCount(); + + if (pCmdLine.stages == CmdLineStageMask_Dp) { + strcpy(pCmdLineCompiler.outMakefile, parseopts.lastoutputname); + } else if (outputOrdering == OutputOrdering2) { + if (parseopts.possibleFiles > 0 || parseopts.userSpecifiedFiles > 0) + CLPReportError(41, parseopts.lastoutputname); + else + CLPReportError(42, parseopts.lastoutputname); + } else { + SetFileOutputName(numfiles - 1, lastStage, parseopts.lastoutputname); + } + + parseopts.lastoutputname[0] = 0; + } + + if (setOutputDirectory) + pCmdLineCompiler.relPathInOutputDir = 0; +} diff --git a/unsorted/ToolHelpers.c b/unsorted/ToolHelpers.c new file mode 100644 index 0000000..1942072 --- /dev/null +++ b/unsorted/ToolHelpers.c @@ -0,0 +1,289 @@ +#include "mwcc_decomp.h" +#include + +// TODO: figure out who defines this +extern char STSbuf[256]; + +static Boolean setStage; +SInt16 outputOrdering; +Boolean setOutputDirectory; +Boolean setLinkerOutputFilename; +char linkerOutputFilename[256]; + +int Opt_HandleOutputName(const char *opt, void *, const char *filename) { + OSSpec spec; + int err; + SInt32 result; + Boolean isfile; + + if (!filename) + filename = opt; + + if ((pCmdLine.state == OptsCmdLineState_3 || (pCmdLine.state == OptsCmdLineState_0 && pTool->TYPE == CWDROPINLINKERTYPE)) && pCmdLine.toDisk != 4) { + if (setLinkerOutputFilename) { + CLPReportError(41, filename); + return 0; + } + setLinkerOutputFilename = 1; + if (pTool->TYPE == CWDROPINCOMPILERTYPE) { + strncpy(linkerOutputFilename, filename, 256); + } else { + OSSpec spec; + int err; + Boolean isfile; + err = OS_MakeSpec(filename, &spec, &isfile); + if (err) { + CLPOSAlert(64, err, filename); + return 0; + } + if (isfile) + OS_NameSpecToString(&spec.name, linkerOutputFilename, 256); + SetOutputFileDirectory(&spec.path); + } + return 1; + } else { + err = OS_MakeSpec(filename, &spec, &isfile); + if (err) { + CLPOSAlert(64, err, filename); + return 0; + } + + if (!err && !isfile) { + FSSpec ofd; + if (setOutputDirectory) { + CLPReportError(59, filename); + return 0; + } + setOutputDirectory = 1; + + OS_OSSpec_To_FSSpec(&spec, &ofd); + result = CWParserSetOutputFileDirectory(parseopts.context, &ofd); + if (result) { + failedCallback = "CWParserSetOutputFileDirectory"; + longjmp(exit_plugin, result); + } + return 1; + } else { + SInt32 index; + CWProjectFileInfo pfi; + if (parseopts.lastoutputname[0]) { + CLPReportError(41, filename); + return 0; + } + strncpy(parseopts.lastoutputname, filename, 256); + if (pCmdLine.stages == CmdLineStageMask_Dp) + return 1; + + if (outputOrdering == OutputOrdering0 || outputOrdering == OutputOrdering1) { + CWGetProjectFileCount(parseopts.context, &index); + while (index-- > 0) { + if (!CWGetFileInfo(parseopts.context, index, 0, &pfi) && pfi.filetype == CWFOURCHAR('T','E','X','T')) { + outputOrdering = OutputOrdering1; + break; + } + } + + if (index <= 0) { + CWGetProjectFileCount(parseopts.context, &index); + if (index > 0) + outputOrdering = OutputOrdering1; + --index; + } + + if (outputOrdering == OutputOrdering0) { + outputOrdering = OutputOrdering2; + return 1; + } + + SetFileOutputName(index, lastStage, parseopts.lastoutputname); + parseopts.lastoutputname[0] = 0; + } + + return 1; + } + } +} + +int ValidateToolState(Boolean mustHaveFiles) { + if (parseopts.noOptions) { + pCmdLine.state = OptsCmdLineState_1; + ShowVersion(1); + return 1; + } + + if (parseopts.success) { + if (!parseopts.userSpecifiedFiles) { + if (!parseopts.hadAnyOutput) { + if (mustHaveFiles) { + CLPReportError(70); + return 0; + } + } else { + if (mustHaveFiles) + pCmdLine.state = OptsCmdLineState_1; + return 1; + } + } else if (parseopts.unusedFiles > 0) { + CLPReportError(69); + return 0; + } + } + + if (pCmdLine.state == OptsCmdLineState_0 || (parseopts.userSpecifiedFiles > 0 && pCmdLine.state == OptsCmdLineState_1)) + pCmdLine.state = OptsCmdLineState_3; + + if (!setStage) { + pCmdLine.stages = CmdLineStageMask_Cg; + if (pCmdLine.state == OptsCmdLineState_2) + pCmdLine.toDisk |= 2; + } + + if (pCmdLine.state == OptsCmdLineState_3 && !(pCmdLine.stages & CmdLineStageMask_Cg)) + pCmdLine.state = OptsCmdLineState_2; + + return 1; +} + +void ToolReportMessage(SInt16 errid, SInt16 type, va_list va) { + char str[256]; + char buf[1024]; + + GetIndString((StringPtr) str, 13000, errid); + p2cstr((StringPtr) str); + vsprintf(buf, str, va); + CWReportMessage(parseopts.context, 0, buf, 0, type, 0); +} + +void ToolReportWarning(SInt16 id, ...) { + va_list va; + va_start(va, id); + ToolReportMessage(id, messagetypeWarning, va); + va_end(va); +} + +void ToolReportError(SInt16 id, ...) { + va_list va; + va_start(va, id); + ToolReportMessage(id, messagetypeError, va); + va_end(va); + parseopts.hadErrors = 1; +} + +void ToolReportOSError(SInt16 id, int err, ...) { + char str[256]; + char buf[1024]; + va_list va; + + GetIndString((StringPtr) str, 13000, id); + p2cstr((StringPtr) str); + va_start(va, err); + vsprintf(buf, str, va); + va_end(va); + CWAlert(parseopts.context, buf, OS_GetErrText(err), 0, 0); +} + +void ToolReportInfo(SInt16 id, ...) { + va_list va; + va_start(va, id); + ToolReportMessage(id, messagetypeInfo, va); + va_end(va); +} + +int Opt_DoNotLink(const char *opt, void *var, const char *arg) { + if (pCmdLine.state == OptsCmdLineState_3 || pCmdLine.state == OptsCmdLineState_0 || pCmdLine.state == OptsCmdLineState_1) + pCmdLine.state = OptsCmdLineState_2; + return 1; +} + +int Opt_IncreaseVerbosity(const char *opt, void *var, const char *arg) { + if (pCmdLine.verbose) + pCmdLine.verbose++; + else + pCmdLine.verbose = 2; + + Parser_StorePanels(parseopts.context); + return 1; +} + +int Opt_SetStage(const char *opt, void *str, const char *arg, int flags) { + unsigned char *ptr; + Boolean set; + Boolean no; + UInt16 flag; + + ptr = (unsigned char *) str; + // doesn't match - type issue with 'no' + 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]; + setStage = 1; + + switch (flag) { + case 'Cg': + if (set) + pCmdLine.stages |= CmdLineStageMask_Cg; + else + pCmdLine.stages &= ~CmdLineStageMask_Cg; + lastStage = CmdLineStage_Cg; + break; + case 'Ds': + if (set) + pCmdLine.stages |= CmdLineStageMask_Ds; + else + pCmdLine.stages &= ~CmdLineStageMask_Ds; + lastStage = CmdLineStage_Ds; + break; + case 'Pp': + if (set) + pCmdLine.stages |= CmdLineStageMask_Pp; + else + pCmdLine.stages &= ~CmdLineStageMask_Pp; + lastStage = CmdLineStage_Pp; + break; + case 'Dp': + if (set) + pCmdLine.stages |= CmdLineStageMask_Dp; + else + pCmdLine.stages &= ~CmdLineStageMask_Dp; + break; + default: + CLPFatalError("Bad stage settings in %s (%c%c)\n", str, ptr[0], ptr[1]); + } + + ++ptr; + } + + ++ptr; + } + + return 1; +} + +int Opt_RedirectStream(const char *opt, void *file, const char *filename) { + OSSpec spec; + int err; + FILE *nw; + + err = OS_MakeFileSpec(filename, &spec); + if (err) { + CLPReportError(78, filename, OS_GetErrText(err)); + return 0; + } + + nw = freopen(OS_SpecToString(&spec, STSbuf, 256), "wt", (FILE *) file); + if (!nw) { + CLPReportError(78, filename, strerror(errno)); + return 0; + } + + return 1; +} diff --git a/unsorted/uContext1.cpp b/unsorted/uContext1.cpp new file mode 100644 index 0000000..7ac712d --- /dev/null +++ b/unsorted/uContext1.cpp @@ -0,0 +1,513 @@ +#include "plugin_internal.h" + +// Forward declarations +CWResult OSErrtoCWResult(OSErr err); + +static Boolean ValidateContext(CWPluginContext context) { + return context + && (context->shellSignature == CWFOURCHAR('C','W','I','E')) + && (context->request != reqInitialize) + && (context->request != reqTerminate) + && (context->request != reqIdle); +} + +static Boolean ValidateInitTermContext(CWPluginContext context) { + return context + && (context->shellSignature == CWFOURCHAR('C','W','I','E')) + && ((context->request == reqInitialize) + || (context->request == reqTerminate) + || (context->request == reqIdle)); +} + +static Boolean IsVCSContext(CWPluginContext context) { + return context && (context->pluginType == CWDROPINVCSTYPE); +} + +CW_CALLBACK CWGetPluginRequest(CWPluginContext context, SInt32 *request) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (request == NULL) + return cwErrInvalidParameter; + + *request = context->request; + return cwNoErr; +} + +CW_CALLBACK CWGetAPIVersion(CWPluginContext context, SInt32 *version) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (version == NULL) + return cwErrInvalidParameter; + + *version = context->apiVersion; + return cwNoErr; +} + +CW_CALLBACK CWGetIDEInfo(CWPluginContext context, CWIDEInfo *info) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (info == NULL) + return cwErrInvalidParameter; + + *info = *context->shellInfo; + return cwNoErr; +} + +CW_CALLBACK CWGetCallbackOSError(CWPluginContext context, CWOSResult *error) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (error == NULL) + return cwErrInvalidParameter; + + *error = context->callbackOSError; + return cwNoErr; +} + +CW_CALLBACK CWSetPluginOSError(CWPluginContext context, CWOSResult error) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + + context->pluginOSError = error; + return cwNoErr; +} + +CW_CALLBACK CWGetProjectFile(CWPluginContext context, CWFileSpec *projectSpec) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (projectSpec == NULL) + return cwErrInvalidParameter; + + *projectSpec = context->projectFile; + return cwNoErr; +} + +CW_CALLBACK CWGetTargetDataDirectory(CWPluginContext context, CWFileSpec *targetDataDirectorySpec) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (targetDataDirectorySpec == NULL) + return cwErrInvalidParameter; + if (context->targetDataDirectorySpec == NULL) + return cwErrInvalidCallback; + + *targetDataDirectorySpec = *context->targetDataDirectorySpec; + return cwNoErr; +} + +CW_CALLBACK CWGetTargetName(CWPluginContext context, char *name, short maxLength) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + + if (context->apiVersion >= 8) + return context->callbacks->cbGetTargetName(context, name, maxLength); + else + return cwErrRequestFailed; +} + +CW_CALLBACK CWGetProjectFileCount(CWPluginContext context, SInt32 *count) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (count == NULL) + return cwErrInvalidParameter; + + *count = context->numFiles; + return cwNoErr; +} + +CW_CALLBACK CWGetOutputFileDirectory(CWPluginContext context, CWFileSpec *outputFileDirectory) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (outputFileDirectory == NULL) + return cwErrInvalidParameter; + + *outputFileDirectory = context->outputFileDirectory; + return cwNoErr; +} + +CW_CALLBACK CWGetOverlay1GroupsCount(CWPluginContext context, SInt32 *count) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (count == NULL) + return cwErrInvalidParameter; + + *count = context->numOverlayGroups; + return cwNoErr; +} + +CW_CALLBACK CWGetFileInfo(CWPluginContext context, SInt32 whichfile, Boolean checkFileLocation, CWProjectFileInfo *fileinfo) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (fileinfo == NULL) + return cwErrInvalidParameter; + + return context->callbacks->cbGetFileInfo(context, whichfile, checkFileLocation, fileinfo); +} + +CW_CALLBACK CWFindAndLoadFile(CWPluginContext context, const char *filename, CWFileInfo *fileinfo) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (filename == NULL) + return cwErrInvalidParameter; + if (fileinfo == NULL) + return cwErrInvalidParameter; + + return context->callbacks->cbFindAndLoadFile(context, filename, fileinfo); +} + +static CWResult EnsureCachedAccessPaths(CWPluginContext context) { + if (!context->accessPathList) { + CWResult res = context->callbacks->cbCacheAccessPathList(context); + if (res) + return res; + if (!context->accessPathList) + return cwErrRequestFailed; + } + return cwNoErr; +} + +CW_CALLBACK CWGetAccessPathListInfo(CWPluginContext context, CWAccessPathListInfo *pathListInfo) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + if (pathListInfo == NULL) + return cwErrInvalidParameter; + if (context->apiVersion < 10) + return cwErrInvalidCallback; + CWResult res = EnsureCachedAccessPaths(context); + if (res) + return res; + pathListInfo->systemPathCount = context->accessPathList->systemPathCount; + pathListInfo->userPathCount = context->accessPathList->userPathCount; + pathListInfo->alwaysSearchUserPaths = context->accessPathList->alwaysSearchUserPaths; + pathListInfo->convertPaths = context->accessPathList->convertPaths; + return cwNoErr; +} + +CW_CALLBACK CWGetAccessPathInfo(CWPluginContext context, CWAccessPathType pathType, SInt32 whichPath, CWAccessPathInfo *pathInfo) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + if (pathInfo == NULL) + return cwErrInvalidParameter; + if (context->apiVersion < 10) + return cwErrInvalidCallback; + CWResult res = EnsureCachedAccessPaths(context); + if (res) + return res; + + IDEAccessPath *paths; + SInt32 count; + switch (pathType) { + case cwSystemPath: + paths = context->accessPathList->systemPaths; + count = context->accessPathList->systemPathCount; + break; + case cwUserPath: + paths = context->accessPathList->userPaths; + count = context->accessPathList->userPathCount; + break; + default: + return cwErrInvalidParameter; + } + + if (whichPath < 0 || whichPath >= count) + return cwErrInvalidParameter; + + IDEAccessPath *path = &paths[whichPath]; + pathInfo->pathSpec = path->pathSpec; + pathInfo->recursive = path->recursive; + pathInfo->subdirectoryCount = path->subdirectoryCount; + return cwNoErr; +} + +CW_CALLBACK CWGetAccessPathSubdirectory(CWPluginContext context, CWAccessPathType pathType, SInt32 whichPath, + SInt32 whichSubdirectory, CWFileSpec *subdirectory) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + if (subdirectory == NULL) + return cwErrInvalidParameter; + if (context->apiVersion < 10) + return cwErrInvalidCallback; + CWResult res = EnsureCachedAccessPaths(context); + if (res) + return res; + + IDEAccessPath *paths; + SInt32 count; + switch (pathType) { + case cwSystemPath: + paths = context->accessPathList->systemPaths; + count = context->accessPathList->systemPathCount; + break; + case cwUserPath: + paths = context->accessPathList->userPaths; + count = context->accessPathList->userPathCount; + break; + default: + return cwErrInvalidParameter; + } + + if (whichPath < 0 || whichPath >= count) + return cwErrInvalidParameter; + + IDEAccessPath *path = &paths[whichPath]; + if (whichSubdirectory < 0 || whichSubdirectory >= path->subdirectoryCount) + return cwErrInvalidParameter; + + *subdirectory = path->subdirectories[whichSubdirectory]; + return cwNoErr; +} + +CW_CALLBACK CWGetFileText(CWPluginContext context, const CWFileSpec *filespec, const char **text, SInt32 *textLength, + short *filedatatype) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + if (!filespec) + return cwErrInvalidParameter; + if (!text) + return cwErrInvalidParameter; + if (!textLength) + return cwErrInvalidParameter; + if (!filedatatype) + return cwErrInvalidParameter; + return context->callbacks->cbGetFileText(context, filespec, text, textLength, filedatatype); +} + +CW_CALLBACK CWReleaseFileText(CWPluginContext context, const char *text) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + + if (text) + return context->callbacks->cbReleaseFileText(context, text); + else + return cwNoErr; +} + +CW_CALLBACK CWGetSegmentInfo(CWPluginContext context, SInt32 whichsegment, CWProjectSegmentInfo *segmentinfo) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (!segmentinfo) + return cwErrInvalidParameter; + return context->callbacks->cbGetSegmentInfo(context, whichsegment, segmentinfo); +} + +CW_CALLBACK CWGetOverlay1GroupInfo(CWPluginContext context, SInt32 whichgroup, CWOverlay1GroupInfo *groupinfo) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (!groupinfo) + return cwErrInvalidParameter; + return context->callbacks->cbGetOverlay1GroupInfo(context, whichgroup, groupinfo); +} + +CW_CALLBACK +CWGetOverlay1Info(CWPluginContext context, SInt32 whichgroup, SInt32 whichoverlay, CWOverlay1Info *overlayinfo) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (!overlayinfo) + return cwErrInvalidParameter; + return context->callbacks->cbGetOverlay1Info(context, whichgroup, whichoverlay, overlayinfo); +} + +CW_CALLBACK CWGetOverlay1FileInfo(CWPluginContext context, SInt32 whichgroup, SInt32 whichoverlay, SInt32 whichoverlayfile, + CWOverlay1FileInfo *fileinfo) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (!fileinfo) + return cwErrInvalidParameter; + return context->callbacks->cbGetOverlay1FileInfo(context, whichgroup, whichoverlay, whichoverlayfile, fileinfo); +} + +CW_CALLBACK CWReportMessage(CWPluginContext context, const CWMessageRef *msgRef, const char *line1, const char *line2, + short errorlevel, SInt32 errorNumber) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbReportMessage(context, msgRef, line1, line2, errorlevel, errorNumber); +} + +CW_CALLBACK CWAlert(CWPluginContext context, const char *msg1, const char *msg2, const char *msg3, const char *msg4) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbAlert(context, msg1, msg2, msg3, msg4); +} + +CW_CALLBACK CWShowStatus(CWPluginContext context, const char *line1, const char *line2) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbShowStatus(context, line1, line2); +} + +CW_CALLBACK CWUserBreak(CWPluginContext context) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbUserBreak(context); +} + +CW_CALLBACK CWGetNamedPreferences(CWPluginContext context, const char *prefsname, CWMemHandle *prefsdata) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + if (!prefsname) + return cwErrInvalidParameter; + if (!prefsdata) + return cwErrInvalidParameter; + return context->callbacks->cbGetNamedPreferences(context, prefsname, prefsdata); +} + +CW_CALLBACK CWStorePluginData(CWPluginContext context, SInt32 whichfile, CWDataType type, CWMemHandle prefsdata) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbStorePluginData(context, whichfile, type, prefsdata); +} + +CW_CALLBACK CWGetPluginData(CWPluginContext context, SInt32 whichfile, CWDataType type, CWMemHandle *prefsdata) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbGetPluginData(context, whichfile, type, prefsdata); +} + +CW_CALLBACK CWSetModDate(CWPluginContext context, const CWFileSpec *filespec, CWFileTime *moddate, Boolean isGenerated) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (!filespec) + return cwErrInvalidParameter; + return context->callbacks->cbSetModDate(context, filespec, moddate, isGenerated); +} + +CW_CALLBACK CWAddProjectEntry(CWPluginContext context, const CWFileSpec *fileSpec, Boolean isGenerated, + const CWNewProjectEntryInfo *projectEntryInfo, SInt32 *whichfile) { + if (IsVCSContext(context) || !ValidateContext(context)) + return cwErrInvalidParameter; + if (!fileSpec) + return cwErrInvalidParameter; + if (context->apiVersion < 8) + return cwErrRequestFailed; + return context->callbacks->cbAddProjectEntry(context, fileSpec, isGenerated, projectEntryInfo, whichfile); +} + +CW_CALLBACK CWCreateNewTextDocument(CWPluginContext context, const CWNewTextDocumentInfo *docinfo) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + if (!docinfo) + return cwErrInvalidParameter; + return context->callbacks->cbCreateNewTextDocument(context, docinfo); +} + +CW_CALLBACK CWAllocateMemory(CWPluginContext context, SInt32 size, Boolean isPermanent, void **ptr) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (!ptr) + return cwErrInvalidParameter; + return context->callbacks->cbAllocateMemory(context, size, isPermanent, ptr); +} + +CW_CALLBACK CWFreeMemory(CWPluginContext context, void *ptr, Boolean isPermanent) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (!ptr) + return cwNoErr; + return context->callbacks->cbFreeMemory(context, ptr, isPermanent); +} + +CW_CALLBACK CWAllocMemHandle(CWPluginContext context, SInt32 size, Boolean useTempMemory, CWMemHandle *handle) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (!handle) + return cwErrInvalidParameter; + return context->callbacks->cbAllocMemHandle(context, size, useTempMemory, handle); +} + +CW_CALLBACK CWFreeMemHandle(CWPluginContext context, CWMemHandle handle) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbFreeMemHandle(context, handle); +} + +CW_CALLBACK CWGetMemHandleSize(CWPluginContext context, CWMemHandle handle, SInt32 *size) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (!size) + return cwErrInvalidParameter; + return context->callbacks->cbGetMemHandleSize(context, handle, size); +} + +CW_CALLBACK CWResizeMemHandle(CWPluginContext context, CWMemHandle handle, SInt32 newSize) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbResizeMemHandle(context, handle, newSize); +} + +CW_CALLBACK CWLockMemHandle(CWPluginContext context, CWMemHandle handle, Boolean moveHi, void **ptr) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + if (!ptr) + return cwErrInvalidParameter; + return context->callbacks->cbLockMemHandle(context, handle, moveHi, ptr); +} + +CW_CALLBACK CWUnlockMemHandle(CWPluginContext context, CWMemHandle handle) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbUnlockMemHandle(context, handle); +} + +CW_CALLBACK CWDonePluginRequest(CWPluginContext, CWResult resultCode) { + return resultCode; +} + +CW_CALLBACK CWPreDialog(CWPluginContext context) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbPreDialog(context); +} + +CW_CALLBACK CWPostDialog(CWPluginContext context) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbPostDialog(context); +} + +CW_CALLBACK CWPreFileAction(CWPluginContext context, const CWFileSpec *theFile) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbPreFileAction(context, theFile); +} + +CW_CALLBACK CWPostFileAction(CWPluginContext context, const CWFileSpec *theFile) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbPostFileAction(context, theFile); +} + +CW_CALLBACK CWCheckoutLicense(CWPluginContext context, const char *a, const char *b, SInt32 c, void *d, SInt32 *cookiePtr) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbCheckoutLicense(context, a, b, c, d, cookiePtr); +} + +CW_CALLBACK CWCheckinLicense(CWPluginContext context, SInt32 cookie) { + if (!ValidateContext(context) && !ValidateInitTermContext(context)) + return cwErrInvalidParameter; + return context->callbacks->cbCheckinLicense(context, cookie); +} + +CW_CALLBACK CWResolveRelativePath(CWPluginContext context, const CWRelativePath *relativePath, CWFileSpec *fileSpec, Boolean create) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + if (relativePath == NULL) + return cwErrInvalidParameter; + if (fileSpec == NULL) + return cwErrInvalidParameter; + return context->callbacks->cbResolveRelativePath(context, relativePath, fileSpec, create); +} + +CW_CALLBACK CWMacOSErrToCWResult(CWPluginContext context, OSErr err) { + return OSErrtoCWResult(err); +} + +CWResult OSErrtoCWResult(OSErr err) { + switch (err) { + case noErr: return cwNoErr; + case userCanceledErr: return cwErrUserCanceled; + case paramErr: return cwErrInvalidParameter; + case memFullErr: return cwErrOutOfMemory; + case fnfErr: return cwErrFileNotFound; + default: return cwErrRequestFailed; + } +} + diff --git a/unsorted/uContextCL.cpp b/unsorted/uContextCL.cpp new file mode 100644 index 0000000..2c0a0c7 --- /dev/null +++ b/unsorted/uContextCL.cpp @@ -0,0 +1,501 @@ +#include "plugin_internal.h" + +static CWCompilerLinkerContext *GetContext(CWPluginContext context) { + if (context && (context->pluginType == CWDROPINCOMPILERTYPE || context->pluginType == CWDROPINLINKERTYPE)) + return static_cast(context); + else + return 0; +} + +CW_CALLBACK CWIsPrecompiling(CWPluginContext context, Boolean* isPrecompiling) { + CWCompilerLinkerContext *cl; + if (!isPrecompiling) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *isPrecompiling = cl->precompile; + return cwNoErr; +} + +CW_CALLBACK CWIsAutoPrecompiling(CWPluginContext context, Boolean* isAutoPrecompiling) { + CWCompilerLinkerContext *cl; + if (!isAutoPrecompiling) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *isAutoPrecompiling = cl->autoprecompile; + return cwNoErr; +} + +CW_CALLBACK CWIsPreprocessing(CWPluginContext context, Boolean* isPreprocessing) { + CWCompilerLinkerContext *cl; + if (!isPreprocessing) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *isPreprocessing = cl->preprocess; + return cwNoErr; +} + +CW_CALLBACK CWIsGeneratingDebugInfo(CWPluginContext context, Boolean* isGenerating) { + CWCompilerLinkerContext *cl; + if (!isGenerating) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *isGenerating = cl->debuginfo; + return cwNoErr; +} + +CW_CALLBACK CWIsCachingPrecompiledHeaders(CWPluginContext context, Boolean* isCaching) { + CWCompilerLinkerContext *cl; + if (!isCaching) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *isCaching = cl->cachingPCH; + return cwNoErr; +} + +CW_CALLBACK CWGetBrowseOptions(CWPluginContext context, CWBrowseOptions* browseOptions) { + CWCompilerLinkerContext *cl; + if (!browseOptions) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *browseOptions = cl->browseoptions; + return cwNoErr; +} + +CW_CALLBACK CWGetBuildSequenceNumber(CWPluginContext context, SInt32* sequenceNumber) { + CWCompilerLinkerContext *cl; + if (!sequenceNumber) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *sequenceNumber = cl->sequenceID; + return cwNoErr; +} + +CW_CALLBACK CWGetTargetInfo(CWPluginContext context, CWTargetInfo* targetInfo) { + CWCompilerLinkerContext *cl; + if (!targetInfo) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion >= 10) { + *targetInfo = *cl->targetinfo; + } else if (cl->apiVersion >= 8) { + CWTargetInfo *ti = cl->targetinfo; + targetInfo->outputType = ti->outputType; + targetInfo->outfile = ti->outfile; + targetInfo->symfile = ti->symfile; + targetInfo->runfile = ti->runfile; + targetInfo->linkType = ti->linkType; + targetInfo->canRun = ti->canRun; + targetInfo->canDebug = ti->canDebug; + targetInfo->targetCPU = ti->targetCPU; + targetInfo->targetOS = ti->targetOS; +#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS + targetInfo->outfileCreator = ti->outfileCreator; + targetInfo->outfileType = ti->outfileType; + targetInfo->debuggerCreator = ti->debuggerCreator; + targetInfo->runHelperCreator = ti->runHelperCreator; +#endif + } else { + memset(targetInfo, 0, sizeof(CWTargetInfo)); + if (CWFileSpecNotEmpty(&cl->targetinfo_V7.outfile)) + targetInfo->outputType = linkOutputFile; + else + targetInfo->outputType = linkOutputNone; + targetInfo->outfile = cl->targetinfo_V7.outfile; + targetInfo->symfile = cl->targetinfo_V7.symfile; + targetInfo->runfile = cl->targetinfo_V7.outfile; + targetInfo->linkType = cl->targetinfo_V7.linkType; + targetInfo->canRun = cl->targetinfo_V7.canRun; + targetInfo->canDebug = cl->targetinfo_V7.canDebug; +#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS + targetInfo->debuggerCreator = cl->targetinfo_V7.debuggerCreator; + targetInfo->runHelperCreator = cl->targetinfo_V7.runHelperCreator; +#endif + } + return cwNoErr; +} + +CW_CALLBACK CWSetTargetInfo(CWPluginContext context, CWTargetInfo* targetInfo) { + CWCompilerLinkerContext *cl; + if (!targetInfo) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion >= 10) { + *cl->targetinfo = *targetInfo; + } else if (cl->apiVersion >= 8) { + CWTargetInfo *ti = cl->targetinfo; + ti->outputType = targetInfo->outputType; + ti->outfile = targetInfo->outfile; + ti->symfile = targetInfo->symfile; + ti->runfile = targetInfo->runfile; + ti->linkType = targetInfo->linkType; + ti->canRun = targetInfo->canRun; + ti->canDebug = targetInfo->canDebug; + ti->targetCPU = targetInfo->targetCPU; + ti->targetOS = targetInfo->targetOS; +#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS + ti->outfileCreator = targetInfo->outfileCreator; + ti->outfileType = targetInfo->outfileType; + ti->debuggerCreator = targetInfo->debuggerCreator; + ti->runHelperCreator = targetInfo->runHelperCreator; +#endif + } else { + cl->targetinfo_V7.outfile = targetInfo->outfile; + cl->targetinfo_V7.symfile = targetInfo->symfile; + cl->targetinfo_V7.linkType = targetInfo->linkType; + cl->targetinfo_V7.canRun = targetInfo->canRun; + cl->targetinfo_V7.canDebug = targetInfo->canDebug; +#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS + cl->targetinfo_V7.useRunHelperApp = targetInfo->runHelperCreator != 0; + cl->targetinfo_V7.debuggerCreator = targetInfo->debuggerCreator; + cl->targetinfo_V7.runHelperCreator = targetInfo->runHelperCreator; +#endif + } + return cwNoErr; +} + +CW_CALLBACK CWGetMainFileNumber(CWPluginContext context, SInt32* fileNumber) { + CWCompilerLinkerContext *cl; + if (!fileNumber) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *fileNumber = cl->whichfile; + return cwNoErr; +} + +CW_CALLBACK CWGetMainFileID(CWPluginContext context, short* fileID) { + CWCompilerLinkerContext *cl; + if (!fileID) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *fileID = cl->fileID; + return cwNoErr; +} + +CW_CALLBACK CWGetMainFileSpec(CWPluginContext context, CWFileSpec* fileSpec) { + CWCompilerLinkerContext *cl; + if (!fileSpec) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *fileSpec = cl->sourcefile; + return cwNoErr; +} + +CW_CALLBACK CWGetMainFileText(CWPluginContext context, const char** text, SInt32* textLength) { + CWCompilerLinkerContext *cl; + if (!text) + return cwErrInvalidParameter; + if (!textLength) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + *text = cl->sourcetext; + *textLength = cl->sourcetextsize; + return cwNoErr; +} + +CW_CALLBACK CWLoadObjectData(CWPluginContext context, SInt32 whichfile, CWMemHandle* objectdata) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbLoadObjectData(cl, whichfile, objectdata); +} + +CW_CALLBACK CWStoreObjectData(CWPluginContext context, SInt32 whichfile, CWObjectData* object) { + CWCompilerLinkerContext *cl; + if (!object) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbStoreObjectData(cl, whichfile, object); +} + +CW_CALLBACK CWFreeObjectData(CWPluginContext context, SInt32 whichfile, CWMemHandle objectdata) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbFreeObjectData(cl, whichfile, objectdata); +} + +CW_CALLBACK CWGetSuggestedObjectFileSpec(CWPluginContext context, SInt32 whichfile, CWFileSpec* fileSpec) { + CWCompilerLinkerContext *cl; + if (!fileSpec) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (context->apiVersion < 10) + return cwErrInvalidCallback; + return cl->callbacks->cbGetSuggestedObjectFileSpec(cl, whichfile, fileSpec); +} + +CW_CALLBACK CWGetStoredObjectFileSpec(CWPluginContext context, SInt32 whichfile, CWFileSpec* fileSpec) { + CWCompilerLinkerContext *cl; + if (!fileSpec) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (context->apiVersion < 10) + return cwErrInvalidCallback; + return cl->callbacks->cbGetStoredObjectFileSpec(cl, whichfile, fileSpec); +} + +CW_CALLBACK CWDisplayLines(CWPluginContext context, SInt32 nlines) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbDisplayLines(cl, nlines); +} + +CW_CALLBACK CWGetResourceFile(CWPluginContext context, CWFileSpec* filespec) { + CWCompilerLinkerContext *cl; + if (!filespec) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbGetResourceFile(cl, filespec); +} + +CW_CALLBACK CWPutResourceFile(CWPluginContext context, const char* prompt, const char* name, CWFileSpec* filespec) { + CWCompilerLinkerContext *cl; + if (!prompt) + return cwErrInvalidParameter; + if (!name) + return cwErrInvalidParameter; + if (!filespec) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbPutResourceFile(cl, prompt, name, filespec); +} + +CW_CALLBACK CWCachePrecompiledHeader(CWPluginContext context, const CWFileSpec* filespec, CWMemHandle pchhandle) { + CWCompilerLinkerContext *cl; + if (!filespec) + return cwErrInvalidParameter; + if (!pchhandle) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbCachePrecompiledHeader(cl, filespec, pchhandle); +} + +CW_CALLBACK CWGetPrecompiledHeaderSpec(CWPluginContext context, CWFileSpec *pchspec, const char *target) { + CWCompilerLinkerContext *cl; + if (!pchspec) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbGetPrecompiledHeaderSpec(cl, pchspec, target); +} + +CW_CALLBACK CWBeginSubCompile(CWPluginContext context, SInt32 whichfile, CWPluginContext* subContext) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbBeginSubCompile(cl, whichfile, subContext); +} + +CW_CALLBACK CWEndSubCompile(CWPluginContext subContext) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(subContext))) + return cwErrInvalidCallback; + return cl->callbacks->cbEndSubCompile(subContext); +} + +CW_CALLBACK CWLookUpUnit(CWPluginContext context, const char* name, Boolean isdependency, const void** unitdata, SInt32* unitdatalength) { + CWCompilerLinkerContext *cl; + if (!name) + return cwErrInvalidParameter; + if (!unitdata) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbLookUpUnit(cl, name, isdependency, unitdata, unitdatalength); +} + +CW_CALLBACK CWSBMfiles(CWPluginContext context, short libref) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbSBMfiles(cl, libref); +} + +CW_CALLBACK CWStoreUnit(CWPluginContext context, const char* unitname, CWMemHandle unitdata, CWDependencyTag dependencytag) { + CWCompilerLinkerContext *cl; + if (!unitname) + return cwErrInvalidParameter; + if (!unitdata) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbStoreUnit(cl, unitname, unitdata, dependencytag); +} + +CW_CALLBACK CWReleaseUnit(CWPluginContext context, void* unitdata) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbReleaseUnit(cl, unitdata); +} + +CW_CALLBACK CWUnitNameToFileName(CWPluginContext context, const char* unitname, char* filename) { + CWCompilerLinkerContext *cl; + if (!unitname) + return cwErrInvalidParameter; + if (!filename) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbUnitNameToFileName(cl, unitname, filename); +} + +CW_CALLBACK CWGetTargetStorage(CWPluginContext context, void** storage) { + CWCompilerLinkerContext *cl; + if (!storage) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion >= 8) { + *storage = cl->targetStorage; + return cwNoErr; + } else { + return cwErrRequestFailed; + } +} + +CW_CALLBACK CWSetTargetStorage(CWPluginContext context, void* storage) { + CWCompilerLinkerContext *cl; + if (!storage) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion >= 8) { + cl->targetStorage = storage; + return cwNoErr; + } else { + return cwErrRequestFailed; + } +} + +CW_CALLBACK CWOSErrorMessage(CWPluginContext context, const char *msg, OSErr errorcode) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbOSErrorMessage(cl, msg, errorcode); +} + +CW_CALLBACK CWOSAlert(CWPluginContext context, const char* message, OSErr errorcode) { + CWCompilerLinkerContext *cl; + if (!message) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + return cl->callbacks->cbOSAlert(cl, message, errorcode); +} + +CW_CALLBACK CWGetModifiedFiles(CWPluginContext context, SInt32* modifiedFileCount, const SInt32** modifiedFiles) { + CWCompilerLinkerContext *cl; + if (!modifiedFileCount) + return cwErrInvalidParameter; + if (!modifiedFiles) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (context->apiVersion < 9) + return cwErrInvalidCallback; + return cl->callbacks->cbGetModifiedFiles(cl, modifiedFileCount, modifiedFiles); +} + +CW_CALLBACK CWGetCommandLineArgs(CWPluginContext context, const char** commandLineArgs) { + CWCompilerLinkerContext *cl; + if (!commandLineArgs) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion < 11) + return cwErrInvalidCallback; + if (!cl->commandLineArgs && cl->callbacks->cbGetRuntimeSettings(cl)) + return cwErrRequestFailed; + *commandLineArgs = cl->commandLineArgs; + return cwNoErr; +} + +CW_CALLBACK CWGetWorkingDirectory(CWPluginContext context, CWFileSpec* workingDirectorySpec) { + CWCompilerLinkerContext *cl; + if (!workingDirectorySpec) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion < 11) + return cwErrInvalidCallback; + if (!cl->commandLineArgs && cl->callbacks->cbGetRuntimeSettings(cl)) + return cwErrRequestFailed; + *workingDirectorySpec = *cl->workingDirectorySpec; + return cwNoErr; +} + +CW_CALLBACK CWGetEnvironmentVariableCount(CWPluginContext context, SInt32* count) { + CWCompilerLinkerContext *cl; + if (!count) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion < 11) + return cwErrInvalidCallback; + if (!cl->commandLineArgs && cl->callbacks->cbGetRuntimeSettings(cl)) + return cwErrRequestFailed; + *count = cl->numEnvironmentVariables; + return cwNoErr; +} + +CW_CALLBACK CWGetEnvironmentVariable(CWPluginContext context, SInt32 index, const char** name, const char** value) { + CWCompilerLinkerContext *cl; + if (!name) + return cwErrInvalidParameter; + if (!value) + return cwErrInvalidParameter; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion < 11) + return cwErrInvalidCallback; + if (!cl->commandLineArgs && cl->callbacks->cbGetRuntimeSettings(cl)) + return cwErrRequestFailed; + if (index < 0 || index >= cl->numEnvironmentVariables) + return cwErrInvalidParameter; + *name = cl->environmentVariables[index].name; + *value = cl->environmentVariables[index].value; + return cwNoErr; +} + +CW_CALLBACK CWGetFrameworkCount(CWPluginContext context, SInt32* frameworkCount) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion < 11) + return cwErrInvalidCallback; + if (!cl->commandLineArgs && cl->callbacks->cbGetFrameworkCount(cl, frameworkCount)) + return cwErrRequestFailed; + return cwNoErr; +} + +CW_CALLBACK CWGetFrameworkInfo(CWPluginContext context, SInt32 whichFramework, CWFrameworkInfo* frameworkInfo) { + CWCompilerLinkerContext *cl; + if (!(cl = GetContext(context))) + return cwErrInvalidCallback; + if (cl->apiVersion < 11) + return cwErrInvalidCallback; + if (!cl->commandLineArgs && cl->callbacks->cbGetFrameworkInfo(cl, whichFramework, frameworkInfo)) + return cwErrRequestFailed; + return cwNoErr; +} diff --git a/unsorted/uContextParser.cpp b/unsorted/uContextParser.cpp new file mode 100644 index 0000000..be1aa0a --- /dev/null +++ b/unsorted/uContextParser.cpp @@ -0,0 +1,207 @@ +#include "plugin_internal.h" + +static CWParserContext *GetContext(CWPluginContext context) { + if (context && (context->pluginType == CWDROPINPARSERTYPE)) + return static_cast(context); + else + return 0; +} + +CW_CALLBACK CWParserGetBuildDate(CWPluginContext context, const char **buildDate, const char **buildTime) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!buildDate) + return cwErrInvalidParameter; + if (!buildTime) + return cwErrInvalidParameter; + *buildDate = pc->build_date; + *buildTime = pc->build_time; + return cwNoErr; +} + +CW_CALLBACK CWParserGetCommandLine(CWPluginContext context, CWCommandLineArgs **args) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!args) + return cwErrInvalidParameter; + *args = pc->args; + return cwNoErr; +} + +CW_CALLBACK CWParserGetTargetInfo(CWPluginContext context, CWDataType *cpu, CWDataType *os) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!cpu) + return cwErrInvalidParameter; + if (!os) + return cwErrInvalidParameter; + *cpu = pc->cpu; + *os = pc->os; + return cwNoErr; +} + +CW_CALLBACK CWParserGetToolInfo(CWPluginContext context, const ToolVersionInfo **toolVersionInfo) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!toolVersionInfo) + return cwErrInvalidParameter; + *toolVersionInfo = pc->build_tool; + return cwNoErr; +} + +CW_CALLBACK CWParserGetPlugins(CWPluginContext context, int *numPlugins, const CLPluginInfo **pluginInfo) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!numPlugins) + return cwErrInvalidParameter; + if (!pluginInfo) + return cwErrInvalidParameter; + *numPlugins = pc->numPlugins; + *pluginInfo = pc->plugins; + return cwNoErr; +} + +CW_CALLBACK CWParserGetPanels(CWPluginContext context, int *numPanels, const char ***panelNames) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!numPanels) + return cwErrInvalidParameter; + if (!panelNames) + return cwErrInvalidParameter; + *numPanels = pc->numPanels; + *panelNames = pc->panelNames; + return cwNoErr; +} + +CW_CALLBACK CWParserStoreCommandLineForPanel(CWPluginContext context, int index, const CWCommandLineArgs *args) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (index < 0 || index >= pc->numPanels) + return cwErrInvalidParameter; + if (!args) + return cwErrInvalidParameter; + pc->panel_args[index] = *args; + return cwNoErr; +} + +CW_CALLBACK CWParserStoreCommandLineForPlugin(CWPluginContext context, int index, const CWCommandLineArgs *args) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (index < 0 || index >= pc->numPlugins) + return cwErrInvalidParameter; + if (!args) + return cwErrInvalidParameter; + pc->plugin_args[index] = *args; + return cwNoErr; +} + +CW_CALLBACK CWParserSetNamedPreferences(CWPluginContext context, const char *panelName, CWMemHandle paneldata) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!panelName) + return cwErrInvalidParameter; + return pc->callbacks->cbParserSetNamedPreferences(pc, panelName, paneldata); +} + +CW_CALLBACK CWParserAddAccessPath(CWPluginContext context, const CWNewAccessPathInfo *api) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!api) + return cwErrInvalidParameter; + return pc->callbacks->cbParserAddAccessPath(pc, api); +} + +CW_CALLBACK CWParserSwapAccessPaths(CWPluginContext context) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + return pc->callbacks->cbParserSwapAccessPaths(pc); +} + +CW_CALLBACK CWParserSetOutputFileDirectory(CWPluginContext context, const CWFileSpec *idefss) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!idefss) + return cwErrInvalidParameter; + return pc->callbacks->cbParserSetOutputFileDirectory(pc, idefss); +} + +CW_CALLBACK CWParserSetFileOutputName(CWPluginContext context, SInt32 position, short which, const char *outfilename) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!outfilename) + return cwErrInvalidParameter; + return pc->callbacks->cbParserSetFileOutputName(pc, position, which, outfilename); +} + +CW_CALLBACK CWParserAddOverlay1Group(CWPluginContext context, const char *name, const CWAddr64 *addr, SInt32 *newGroupNumber) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!name) + return cwErrInvalidParameter; + if (!addr) + return cwErrInvalidParameter; + if (!newGroupNumber) + return cwErrInvalidParameter; + return pc->callbacks->cbParserAddOverlay1Group(pc, name, addr, newGroupNumber); +} + +CW_CALLBACK CWParserAddOverlay1(CWPluginContext context, const char *name, SInt32 groupNumber, SInt32 *newOverlayNumber) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!name) + return cwErrInvalidParameter; + if (!newOverlayNumber) + return cwErrInvalidParameter; + return pc->callbacks->cbParserAddOverlay1(pc, name, groupNumber, newOverlayNumber); +} + +CW_CALLBACK CWParserAddSegment(CWPluginContext context, const char *name, short attrs, SInt32 *newSegmentNumber) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!name) + return cwErrInvalidParameter; + if (!newSegmentNumber) + return cwErrInvalidParameter; + return pc->callbacks->cbParserAddSegment(pc, name, attrs, newSegmentNumber); +} + +CW_CALLBACK CWParserSetSegment(CWPluginContext context, SInt32 segmentNumber, const char *name, short attrs) { + CWParserContext *pc; + if (!(pc = GetContext(context))) + return cwErrInvalidCallback; + if (!name) + return cwErrInvalidParameter; + return pc->callbacks->cbParserSetSegment(pc, segmentNumber, name, attrs); +} + +CW_CALLBACK CWParserCreateVirtualFile(CWPluginContext context, const char *name, CWMemHandle text) { + CWNewTextDocumentInfo info; + info.documentname = name; + info.text = text; + info.markDirty = 1; + return CWCreateNewTextDocument(context, &info); +} + +CW_CALLBACK CWParserDisplayTextHandle(CWPluginContext context, const char *name, CWMemHandle text) { + CWNewTextDocumentInfo info; + info.documentname = name; + info.text = text; + info.markDirty = 0; + return CWCreateNewTextDocument(context, &info); +} diff --git a/unsorted/uContextSecret.cpp b/unsorted/uContextSecret.cpp new file mode 100644 index 0000000..b33ca81 --- /dev/null +++ b/unsorted/uContextSecret.cpp @@ -0,0 +1,39 @@ +#include "plugin_internal.h" + +static Boolean ValidateContext(CWPluginContext context) { + return context && (context->shellSignature == CWFOURCHAR('C','W','I','E')); +} + +typedef CWResult (*cbSecretAttachHandleType)(CWPluginContext, Handle, CWMemHandle *); +typedef CWResult (*cbSecretDetachHandleType)(CWPluginContext, CWMemHandle, Handle *); +typedef CWResult (*cbSecretPeekHandleType)(CWPluginContext, CWMemHandle, Handle *); +typedef CWResult (*cbSecretGetNamedPreferencesType)(CWPluginContext, const char *, Handle *); + +CW_CALLBACK CWSecretAttachHandle(CWPluginContext context, Handle handle, CWMemHandle *memHandle) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return ((cbSecretAttachHandleType) context->callbacks->cbInternal[0])(context, handle, memHandle); +} + +CW_CALLBACK CWSecretDetachHandle(CWPluginContext context, CWMemHandle memHandle, Handle *handle) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return ((cbSecretDetachHandleType) context->callbacks->cbInternal[1])(context, memHandle, handle); +} + +CW_CALLBACK CWSecretPeekHandle(CWPluginContext context, CWMemHandle memHandle, Handle *handle) { + if (!ValidateContext(context)) + return cwErrInvalidParameter; + return ((cbSecretPeekHandleType) context->callbacks->cbInternal[2])(context, memHandle, handle); +} + +CW_CALLBACK CWSecretGetNamedPreferences(CWPluginContext context, const char *prefsname, Handle *prefsdata) { + if (!prefsdata) + return cwErrInvalidParameter; + + CWMemHandle memHandle; + CWResult res = CWGetNamedPreferences(context, prefsname, &memHandle); + if (!res) + res = CWSecretDetachHandle(context, memHandle, prefsdata); + return res; +} -- cgit v1.2.3