summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp
blob: 19b7dabe67fd9c4049e18531d44483433b2f58b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#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<shellContextType *>(context->shellContext)->systemAccessPathsChanged = 1;
    else
        static_cast<shellContextType *>(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() {
}