From d1f153d34b023d81768f6087f67dbfff714bafc9 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 19 Oct 2022 21:16:13 +0100 Subject: let's commit all this before my VM blows up and nukes my work --- .../CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp | 233 +++++++++++++++++++-- 1 file changed, 220 insertions(+), 13 deletions(-) (limited to 'command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp') diff --git a/command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp b/command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp index 5dbd4d8..19b7dab 100644 --- a/command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp +++ b/command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp @@ -1,13 +1,220 @@ -/* - P 9C50 | _UCBParserAddAccessPath - P 9DE4 | _UCBParserSwapAccessPaths - P 9E90 | _UCBParserSetNamedPreferences - P 9F50 | _UCBParserSetFileOutputName - P A03C | _UCBParserSetOutputFileDirectory - P A110 | _UCBParserAddOverlay1Group - P A1EC | _UCBParserAddOverlay1 - P A2D0 | _UCBParserAddSegment - P A364 | _UCBParserSetSegment - P A400 | ___ct__15CWParserContextFv - P A480 | ___dt__15CWParserContextFv - */ \ No newline at end of file +#include "cmdline.h" +#include "plugin_internal.h" + +extern char STSbuf[256]; + +CWResult UCBParserAddAccessPath(CWPluginContext context, const CWNewAccessPathInfo *api) { + OSSpec oss; + Paths *paths; + Path *path; + int err; + + if ((err = OS_FSSpec_To_OSSpec(&api->pathSpec, &oss))) { + context->callbackOSError = OS_MacError(err); + return cwErrInvalidParameter; + } + + if (optsCmdLine.verbose > 2) + CLReport(CLStr77, " search path", OS_PathSpecToString(&oss.path, STSbuf, sizeof(STSbuf))); + + if ((api->type & cwAccessPathTypeFlag1) == 0) + paths = &gTarg->sysPaths; + else + paths = &gTarg->userPaths; + path = Path_New(&oss.path); + + path->flags = api->type & cwAccessPathTypeFlag2; + if ((api->position >= 0) ? (Paths_InsertPath(paths, api->position, path) == 0) : (Paths_AddPath(paths, path) == 0)) + return cwErrRequestFailed; + + if (api->recursive) { + Paths_GatherRecurse(path); + if (CheckForUserBreak()) + return cwErrUserCanceled; + } + + if (!(api->type & cwAccessPathTypeFlag1)) + static_cast(context->shellContext)->systemAccessPathsChanged = 1; + else + static_cast(context->shellContext)->userAccessPathsChanged = 1; + + return cwNoErr; +} + +CWResult UCBParserSwapAccessPaths(CWPluginContext context) { + Path *tmp; + UInt16 idx; + + for (idx = 0; idx < Paths_Count(&gTarg->sysPaths); idx++) { + tmp = Paths_GetPath(&gTarg->sysPaths, idx); + if (!(tmp->flags & cwAccessPathTypeFlag2)) { + Paths_AddPath(&gTarg->userPaths, tmp); + Paths_RemovePath(&gTarg->sysPaths, idx); + idx--; + } + } + + return cwNoErr; +} + +int (*PrefPanelsChangedCallback)(const char *); + +CWResult UCBParserSetNamedPreferences(CWPluginContext context, const char *panelName, Handle paneldata) { + PrefPanel *panel; + + panel = Prefs_FindPanel(panelName); + if (!panel) { + panel = PrefPanel_New(panelName, *paneldata, GetHandleSize(paneldata)); + if (!panel || !Prefs_AddPanel(panel)) + return cwErrRequestFailed; + } else { + if (!PrefPanel_PutHandle(panel, paneldata)) + return cwErrRequestFailed; + } + + if (PrefPanelsChangedCallback) + PrefPanelsChangedCallback(panelName); + + return cwNoErr; +} + +CWResult UCBParserSetFileOutputName(CWPluginContext context, SInt32 position, short which, const char *outfilename) { + if (position < 0) + return cwErrInvalidParameter; + + File *file = Files_GetFile(&gTarg->files, position); + if (!file) + return cwErrUnknownFile; + + if (file->outfileowner) + CLReportError(CLStr103, file->srcfilename, file->outfilename); + + strcpy(file->outfilename, outfilename); + if (which == 1) + file->outfileowner = CmdLineStageMask_Cg; + else if (which == 2) + file->outfileowner = CmdLineStageMask_Pp; + else if (which == 3) + file->outfileowner = CmdLineStageMask_Ds; + else + return cwErrInvalidParameter; + + return cwNoErr; +} + +CWResult UCBParserSetOutputFileDirectory(CWPluginContext context, const CWFileSpec *idefss) { + OSSpec fss; + int err; + + if ((err = OS_FSSpec_To_OSSpec(idefss, &fss))) { + context->callbackOSError = OS_MacError(err); + return cwErrInvalidParameter; + } + + gTarg->outputDirectory = fss.path; + context->outputFileDirectory = *idefss; + + return cwNoErr; +} + +CWResult UCBParserAddOverlay1Group(CWPluginContext context, const char *name, const CWAddr64 *addr, SInt32 *newGroupNumber) { + if (gTarg->linkmodel != LinkModel2) + return cwErrInvalidCallback; + + OvlGroup *grp; + OvlAddr oaddr; + oaddr.hi = addr->hi; + oaddr.lo = addr->lo; + + grp = OvlGroup_New(name, oaddr); + if (!grp) + return cwErrRequestFailed; + if (!Overlays_AddOvlGroup(&gTarg->linkage.overlays, grp, newGroupNumber)) + return cwErrRequestFailed; + + ++context->numOverlayGroups; + if (optsCmdLine.verbose > 2) + CLReport(CLStr79, name, oaddr.hi, oaddr.lo); + + return cwNoErr; +} + +CWResult UCBParserAddOverlay1(CWPluginContext context, const char *name, SInt32 groupNumber, SInt32 *newOverlayNumber) { + if (gTarg->linkmodel != LinkModel2) + return cwErrInvalidCallback; + + OvlGroup *grp; + Overlay *ovl; + + grp = Overlays_GetOvlGroup(&gTarg->linkage.overlays, groupNumber); + if (!grp) + return cwErrRequestFailed; + ovl = Overlay_New(name); + if (!ovl) + return cwErrOutOfMemory; + if (!OvlGroup_AddOverlay(grp, ovl, newOverlayNumber)) + return cwErrOutOfMemory; + + if (optsCmdLine.verbose > 2) + CLReport(CLStr78, name, grp->name); + + return cwNoErr; +} + +CWResult UCBParserAddSegment(CWPluginContext context, const char *name, short attrs, SInt32 *newSegmentNumber) { + if (gTarg->linkmodel != LinkModel1) + return cwErrInvalidCallback; + + Segment *seg; + UInt16 index; + + seg = Segment_New(name, attrs); + if (!Segments_AddSegment(&gTarg->linkage.segs, seg, &index)) + return cwErrRequestFailed; + + *newSegmentNumber = index; + return cwNoErr; +} + +CWResult UCBParserSetSegment(CWPluginContext context, SInt32 segmentNumber, const char *name, short attrs) { + if (gTarg->linkmodel != LinkModel1) + return cwErrInvalidCallback; + + Segment *seg = Segments_GetSegment(&gTarg->linkage.segs, segmentNumber); + if (!seg) + return cwErrUnknownSegment; + + strncpy(seg->name, name, sizeof(seg->name)); + seg->name[sizeof(seg->name) - 1] = 0; + seg->attrs = attrs; + + return cwNoErr; +} + +static CWParserCallbacks parser_cb = { + UCBParserAddAccessPath, + UCBParserSwapAccessPaths, + UCBParserSetNamedPreferences, + UCBParserSetFileOutputName, + UCBParserSetOutputFileDirectory, + UCBParserAddOverlay1Group, + UCBParserAddOverlay1, + UCBParserAddSegment, + UCBParserSetSegment +}; + +CWParserContext::CWParserContext() : CWPluginPrivateContext(CWDROPINPARSERTYPE, -1) { + args = NULL; + os = 0; + cpu = 0; + numPlugins = 0; + plugins = NULL; + numPanels = 0; + panelNames = NULL; + panel_args = NULL; + plugin_args = NULL; + callbacks = &parser_cb; +} + +CWParserContext::~CWParserContext() { +} -- cgit v1.2.3