2022-10-19 20:16:13 +00:00
|
|
|
#include "parser.h"
|
2022-10-07 19:02:27 +00:00
|
|
|
|
2022-10-14 22:15:32 +00:00
|
|
|
const char *failedCallback;
|
|
|
|
jmp_buf exit_plugin;
|
2022-10-19 20:16:13 +00:00
|
|
|
ParseOptsType parseopts;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
static CWResult SetupParamBlock(CWPluginContext context) {
|
|
|
|
CWResult result;
|
2022-10-14 22:15:32 +00:00
|
|
|
int x;
|
|
|
|
Handle h;
|
|
|
|
PCmdLineEnvir cle;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
memset(&parseopts, 0, sizeof(parseopts));
|
|
|
|
parseopts.context = context;
|
|
|
|
|
|
|
|
result = CWSecretGetNamedPreferences(context, "CmdLine Environment", &h);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
2022-10-14 22:15:32 +00:00
|
|
|
cle = **((PCmdLineEnvir **) h);
|
2022-10-07 19:02:27 +00:00
|
|
|
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;
|
|
|
|
|
2022-10-14 22:15:32 +00:00
|
|
|
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;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 22:15:32 +00:00
|
|
|
Handle Parser_FindPrefPanel(const char *name) {
|
2022-10-07 19:02:27 +00:00
|
|
|
int idx;
|
2022-10-14 22:15:32 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2022-10-07 19:02:27 +00:00
|
|
|
|
2022-10-14 22:15:32 +00:00
|
|
|
return NULL;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CWResult Parser_StorePanels(CWPluginContext context) {
|
|
|
|
int idx;
|
|
|
|
CWResult result;
|
2022-10-14 22:15:32 +00:00
|
|
|
const char *name;
|
2022-10-07 19:02:27 +00:00
|
|
|
Handle h;
|
|
|
|
|
|
|
|
for (idx = 0; idx < parseopts.numPanels; idx++) {
|
|
|
|
name = parseopts.panelNames[idx];
|
|
|
|
h = Parser_FindPrefPanel(name);
|
|
|
|
if (h) {
|
2022-10-19 20:16:13 +00:00
|
|
|
result = CWParserSetNamedPreferences(parseopts.context, name, h);
|
2022-10-07 19:02:27 +00:00
|
|
|
if (result) {
|
2022-10-19 20:16:13 +00:00
|
|
|
CLPReportError(CLPStr68, name);
|
2022-10-07 19:02:27 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 22:15:32 +00:00
|
|
|
return cwNoErr;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static CWResult StoreResults(CWPluginContext context) {
|
2022-10-14 22:15:32 +00:00
|
|
|
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;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (CWParser_GetDropInFlags)(const DropInFlags **flags, SInt32 *flagsSize) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static const DropInFlags sFlags = {
|
|
|
|
kCurrentDropInFlagsVersion,
|
2022-10-19 20:16:13 +00:00
|
|
|
CWDROPINPARSERTYPE,
|
2022-10-07 19:02:27 +00:00
|
|
|
7,
|
|
|
|
0,
|
|
|
|
'Seep',
|
|
|
|
12
|
|
|
|
};
|
|
|
|
*flags = &sFlags;
|
|
|
|
*flagsSize = sizeof(sFlags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (CWParser_GetDropInName)(const char **dropinName) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static const char *sDropInName = "Command-Line Parser";
|
|
|
|
*dropinName = sDropInName;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (CWParser_GetDisplayName)(const char **displayName) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static const char *sDisplayName = "Command-Line Parser";
|
|
|
|
*displayName = sDisplayName;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (CWParser_GetPanelList)(const CWPanelList **panelList) {
|
2022-10-14 22:15:32 +00:00
|
|
|
static CWPanelList sPanelList = {
|
2022-10-07 19:02:27 +00:00
|
|
|
kCurrentCWFamilyListVersion,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
*panelList = &sPanelList;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (CWParser_GetTargetList)(const CWTargetList **targetList) {
|
2022-10-14 22:15:32 +00:00
|
|
|
static CWDataType sCPU = '****';
|
|
|
|
static CWDataType sOS = '****';
|
|
|
|
static CWTargetList sTargetList = {
|
2022-10-07 19:02:27 +00:00
|
|
|
kCurrentCWTargetListVersion,
|
|
|
|
1,
|
|
|
|
&sCPU,
|
|
|
|
1,
|
|
|
|
&sOS
|
|
|
|
};
|
|
|
|
*targetList = &sTargetList;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (CWParser_GetVersionInfo)(const VersionInfo **versioninfo) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static const VersionInfo vi = {
|
|
|
|
1, 1, 0, 0
|
|
|
|
};
|
|
|
|
*versioninfo = &vi;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (Parser_SupportsPlugin)(const struct CLPluginInfo *pluginfo, CWDataType cpu, CWDataType os, Boolean *isSupported) {
|
2022-10-07 19:02:27 +00:00
|
|
|
*isSupported = ParserToolMatchesPlugin(pluginfo->plugintype, pluginfo->language, cpu, os);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (Parser_SupportsPanels)(int numPanels, const char **panelNames, Boolean *isSupported) {
|
2022-10-07 19:02:27 +00:00
|
|
|
*isSupported = ParserToolHandlesPanels(numPanels, panelNames);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
CWPLUGIN_ENTRY (parser_main)(CWPluginContext context) {
|
2022-10-07 19:02:27 +00:00
|
|
|
CWResult result;
|
2022-10-14 22:15:32 +00:00
|
|
|
SInt32 request;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|