final step to context based macro interpreter
[nedit-bw.git] / pass-context-to-ops.patch
blob88525dc8f83a8ddaf4467412a3862a2c1b36d03f
1 ---
3 source/interpret.c | 314 +++++--------
4 source/interpret.h | 24 -
5 source/macro.c | 1265 +++++++++++++++++++++++++++++++----------------------
6 source/macro.h | 2
7 4 files changed, 898 insertions(+), 707 deletions(-)
9 diff --quilt old/source/interpret.c new/source/interpret.c
10 --- old/source/interpret.c
11 +++ new/source/interpret.c
12 @@ -81,29 +81,29 @@ static const char CVSID[] = "$Id: interp
13 enum opStatusCodes {STAT_OK=2, STAT_DONE, STAT_ERROR, STAT_PREEMPT};
15 static int addLoopAddr(Inst *addr, char **msg);
16 -static void saveContext(RestartData *context);
17 -static void restoreContext(RestartData *context);
19 /* the function prototype of a operand instruction */
20 -#define OP_FUNCTION(op) static int op(void)
21 +#define OP_FUNCTION(op) static int op(RestartData *context)
23 #define OP(name, fn) OP_FUNCTION(fn);
24 #include "ops.h"
25 #undef OP
26 -static int returnValOrNone(int valOnStack);
27 -static int branchIf(Boolean trueOrFalse);
28 -static int namedArg1orN(Boolean isFirst);
30 -static int callSubroutineFromSymbol(Symbol *sym, int nArgs);
31 -static int concatenateNwithSep(int nVals, const char *sep, char **result,
32 - int leaveParams);
33 -static int makeArrayKeyFromArgs(int nArgs, char **keyString, int leaveParams);
34 +static int returnValOrNone(RestartData *context, int valOnStack);
35 +static int branchIf(RestartData *context, Boolean trueOrFalse);
36 +static int namedArg1orN(RestartData *context, Boolean isFirst);
38 +static int callSubroutineFromSymbol(RestartData *context, Symbol *sym,
39 + int nArgs);
40 +static int concatenateNwithSep(RestartData *context, int nVals, const char *sep,
41 + char **result, int leaveParams);
42 +static int makeArrayKeyFromArgs(RestartData *context, int nArgs,
43 + char **keyString, int leaveParams);
44 static void freeSymbolList(Symbol *symList);
45 static void addToGlobalSymTab(Symbol *sym);
46 static unsigned int hashNameWith(unsigned int hash, const char *name);
47 static unsigned int hashName(const char *name);
48 -static int errCheck(const char *s);
49 -static int execError(const char *s1, const char *s2);
50 +static int errCheck(RestartData *context, const char *s);
51 +static int execError(RestartData *context, const char *s1, const char *s2);
52 static rbTreeNode *arrayEmptyAllocator(void);
53 static rbTreeNode *arrayAllocateNode(rbTreeNode *src);
54 static int arrayEntryCopyToNode(rbTreeNode *dst, rbTreeNode *src);
55 @@ -136,9 +136,9 @@ static void disasmInternal(Inst *inst, i
56 #endif /* #ifndef DEBUG_ASSEMBLY */
58 #ifdef DEBUG_STACK /* for run-time instruction and stack trace */
59 -static void stackdump(int n, int extra);
60 -static void stackdumpInternal(int n, int extra);
61 -#define STACKDUMP(n, x) stackdump(n, (x) + 10)
62 +static void stackdump(RestartData *context, int n, int extra);
63 +static void stackdumpInternal(RestartData *context, int n, int extra);
64 +#define STACKDUMP(n, x) stackdump(context, n, (x) + 10)
65 #define DISASM_RT() disasm(NULL, PC - 1, 1)
66 #else /* #ifndef DEBUG_STACK */
67 #define STACKDUMP(n, x)
68 @@ -178,16 +178,7 @@ static Inst **LoopStackPtr = LoopStack;
69 static const char *ProgramName = "";
71 /* Global data for the interpreter */
72 -static DataValue *TheStack; /* the stack */
73 -static DataValue *StackP; /* next free spot on stack */
74 -static DataValue *FrameP; /* frame pointer (start of local variables
75 - for the current subroutine invocation) */
76 -static Inst *PC; /* program counter during execution */
77 -static char *ErrMsg; /* global for returning error messages
78 - from executing functions */
79 -static WindowInfo
80 - *InitiatingWindow = NULL; /* window from which macro was run */
81 -static WindowInfo *FocusWindow; /* window on which macro commands operate */
82 +static WindowInfo *InitiatingWindow;
83 static int PreemptRequest; /* passes preemption requests from called
84 routines back up to the interpreter */
86 @@ -536,7 +527,7 @@ static int setupFrame(RestartData *conte
88 /* !OK_TO_PUSH(totalPushs) */
89 if (!((context->stackP + totalPushs) <= &context->stack[STACK_SIZE])) {
90 - return execError(StackOverflowMsg, "");
91 + return execError(context, StackOverflowMsg, "");
94 /* Push arguments and caller information onto the stack */
95 @@ -599,30 +590,30 @@ static int setupFrame(RestartData *conte
96 return STAT_OK;
99 -static Inst *rewindFrame(DataValue **frameP, DataValue **stackP)
100 +static void rewindFrame(RestartData *context)
102 /* get stored return information */
103 - int nArgs = FP_GET_ARG_COUNT(*frameP);
104 - DataValue *newFrameP = FP_GET_OLD_FP(*frameP);
105 - Inst *newPC = FP_GET_RET_PC(*frameP);
106 - Program *prog = FP_GET_PROG(*frameP);
107 + int nArgs = FP_GET_ARG_COUNT(context->frameP);
108 + DataValue *newFrameP = FP_GET_OLD_FP(context->frameP);
109 + Inst *newPC = FP_GET_RET_PC(context->frameP);
110 + Program *prog = FP_GET_PROG(context->frameP);
112 /* pop past local variables */
113 - *stackP = *frameP;
114 + context->stackP = context->frameP;
115 /* pop past arguments */
116 - *stackP -= (FP_TO_ARGS_DIST + nArgs);
117 + context->stackP -= (FP_TO_ARGS_DIST + nArgs);
119 - *frameP = newFrameP;
120 + context->frameP = newFrameP;
122 FreeProgram(prog);
124 - return newPC;
125 + context->pc = newPC;
128 static void rewindStack(RestartData *context)
130 while (context->pc) {
131 - context->pc = rewindFrame(&context->frameP, &context->stackP);
132 + rewindFrame(context);
136 @@ -665,7 +656,7 @@ int ExecuteMacro(WindowInfo *window, Pro
137 prog->name ? prog->name : "<exec-macro>");
139 if (status == STAT_ERROR) {
140 - *msg = ErrMsg;
141 + *msg = context->errMsg;
142 FreeRestartData(context);
143 return MACRO_ERROR;
145 @@ -682,25 +673,21 @@ int ContinueMacro(RestartData *continuat
147 register int status, instCount = 0;
148 register Inst *inst;
149 - RestartData oldContext;
151 - /* To allow macros to be invoked arbitrarily (such as those automatically
152 - triggered within smart-indent) within executing macros, this call is
153 - reentrant. */
154 - saveContext(&oldContext);
156 + WindowInfo *prevRunWindow = InitiatingWindow;
159 ** Execution Loop: Call the succesive routine addresses in the program
160 ** until one returns something other than STAT_OK, then take action
162 - restoreContext(continuation);
163 - ErrMsg = NULL;
164 + InitiatingWindow = continuation->runWindow;
165 + continuation->errMsg = NULL;
166 for (;;) {
168 /* Execute an instruction */
169 - inst = PC++;
170 + inst = continuation->pc++;
171 if (inst->type != OP_INST) {
172 - status = execError("Unexpected instruction of type %s",
173 + status = execError(continuation,
174 + "Unexpected instruction of type %s",
175 instTypeToStr(inst->type));
177 else {
178 @@ -708,31 +695,29 @@ int ContinueMacro(RestartData *continuat
179 #define OP(name, fn) case OP_##name:
180 #include "ops.h"
181 #undef OP
182 - status = (OpFns[inst->val.op])();
183 + status = (OpFns[inst->val.op])(continuation);
184 break;
185 default:
186 - status = execError("Illegal instruction at %8p", (char *)inst);
187 + status = execError(continuation, "Illegal instruction at %8p",
188 + (char *)inst);
192 /* If error return was not STAT_OK, return to caller */
193 if (status != STAT_OK) {
194 if (status == STAT_PREEMPT) {
195 - saveContext(continuation);
196 - restoreContext(&oldContext);
197 + InitiatingWindow = prevRunWindow;
198 return MACRO_PREEMPT;
199 } else if (status == STAT_ERROR) {
200 - *msg = ErrMsg;
201 - saveContext(continuation);
202 + *msg = continuation->errMsg;
203 FreeRestartData(continuation);
204 - restoreContext(&oldContext);
205 + InitiatingWindow = prevRunWindow;
206 return MACRO_ERROR;
207 } else if (status == STAT_DONE) {
208 *msg = "";
209 - *result = *--StackP;
210 - saveContext(continuation);
211 + *result = *--continuation->stackP;
212 FreeRestartData(continuation);
213 - restoreContext(&oldContext);
214 + InitiatingWindow = prevRunWindow;
215 return MACRO_DONE;
218 @@ -742,8 +727,7 @@ int ContinueMacro(RestartData *continuat
219 X, other macros, and other shell scripts a chance to execute */
220 instCount++;
221 if (instCount >= INSTRUCTION_LIMIT) {
222 - saveContext(continuation);
223 - restoreContext(&oldContext);
224 + InitiatingWindow = prevRunWindow;
225 return MACRO_TIME_LIMIT;
228 @@ -765,7 +749,7 @@ int RunMacroAsSubrCall(RestartData *cont
229 prog->name ? prog->name : "<run-macro>");
231 if (status == STAT_ERROR) {
232 - *msg = ErrMsg;
233 + *msg = context->errMsg;
234 FreeRestartData(context);
235 return MACRO_ERROR;
237 @@ -800,8 +784,8 @@ void PreemptMacro(void)
239 void ModifyReturnedValue(RestartData *context, DataValue dv)
241 - if ((context->pc-1)->val.op == OP_FETCH_RET_VAL)
242 - *(context->stackP-1) = dv;
243 + if ((context->pc - 1)->val.op == OP_FETCH_RET_VAL)
244 + *(context->stackP - 1) = dv;
248 @@ -814,25 +798,6 @@ WindowInfo *MacroRunWindow(void)
252 -** Called within a routine invoked from a macro, returns the window to which
253 -** the currently executing macro is focused (the window which macro commands
254 -** modify, not the window from which the macro is being run)
256 -WindowInfo *MacroFocusWindow(void)
258 - return FocusWindow;
262 -** Set the window to which macro subroutines and actions which operate on an
263 -** implied window are directed.
265 -void SetMacroFocusWindow(WindowInfo *window)
267 - FocusWindow = window;
271 ** install a list assign (multi-assign) rvalue expression holder into the local
272 ** namespace.
274 @@ -1319,29 +1284,6 @@ void GarbageCollectStrings(void)
275 #endif
279 -** Save and restore execution context to data structure "context"
281 -static void saveContext(RestartData *context)
283 - context->stack = TheStack;
284 - context->stackP = StackP;
285 - context->frameP = FrameP;
286 - context->pc = PC;
287 - context->runWindow = InitiatingWindow;
288 - context->focusWindow = FocusWindow;
291 -static void restoreContext(RestartData *context)
293 - TheStack = context->stack;
294 - StackP = context->stackP;
295 - FrameP = context->frameP;
296 - PC = context->pc;
297 - InitiatingWindow = context->runWindow;
298 - FocusWindow = context->focusWindow;
301 static void freeSymbolList(Symbol *symList)
303 Symbol *s;
304 @@ -1378,7 +1320,11 @@ static void addToGlobalSymTab(Symbol *sy
305 GlobalSymTab[idx] = sym;
308 -#define EXEC_ERROR(s1, s2) return execError(s1, s2)
309 +#define StackP (context->stackP)
310 +#define FrameP (context->frameP)
311 +#define PC (context->pc)
313 +#define EXEC_ERROR(s1, s2) return execError(context, s1, s2)
315 #define GET_SYM(s) \
316 do { \
317 @@ -1386,7 +1332,8 @@ static void addToGlobalSymTab(Symbol *sy
318 EXEC_ERROR("Unexpected instruction, expected <symbol>: %s", \
319 instTypeToStr(PC->type)); \
321 - s = PC++->val.sym; \
322 + s = PC->val.sym; \
323 + PC++; \
324 } while (0)
326 #define GET_IMMED(i) \
327 @@ -1395,7 +1342,8 @@ static void addToGlobalSymTab(Symbol *sy
328 EXEC_ERROR("Unexpected instruction, expected <immediate>: %s", \
329 instTypeToStr(PC->type)); \
331 - i = PC++->val.immed; \
332 + i = PC->val.immed; \
333 + PC++; \
334 } while (0)
336 #define GET_BRANCH(a) \
337 @@ -1437,7 +1385,7 @@ static void addToGlobalSymTab(Symbol *sy
339 /* true, if you can pop n values */
340 #define OK_TO_POP(n) \
341 - ((StackP - (n)) >= TheStack)
342 + ((context->stackP - (n)) >= context->stack)
344 #define POP_CHECK(n) \
345 do { \
346 @@ -1448,7 +1396,7 @@ static void addToGlobalSymTab(Symbol *sy
348 /* true, if you can push n values */
349 #define OK_TO_PUSH(n) \
350 - (StackP + (n) <= &TheStack[STACK_SIZE])
351 + (StackP + (n) <= &context->stack[STACK_SIZE])
353 #define PUSH_CHECK(n) \
354 do { \
355 @@ -1617,10 +1565,8 @@ OP_FUNCTION(pushSymVal)
356 symVal = FRAME_GET_ARG_N(argNum);
358 } else if (s->type == PROC_VALUE_SYM) {
359 - char *errMsg;
360 - if (!(s->value.val.subr)(FocusWindow, NULL, 0,
361 - &symVal, &errMsg)) {
362 - EXEC_ERROR(errMsg, s->name);
363 + if (!s->value.val.subr(context, NULL, 0, &symVal)) {
364 + EXEC_ERROR(context->errMsg, s->name);
366 } else if (s->type == C_FUNCTION_SYM
367 || s->type == MACRO_FUNCTION_SYM
368 @@ -1885,7 +1831,7 @@ OP_FUNCTION(anonArrayIndexVal)
369 POP(exprVal);
371 /* the next nDim stack entries form the index */
372 - errNum = makeArrayKeyFromArgs(nDim, &keyString, 0);
373 + errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0);
374 if (errNum != STAT_OK) {
375 return errNum;
377 @@ -1947,7 +1893,7 @@ OP_FUNCTION(anonArrayClose)
379 OP_FUNCTION(namedArg1)
381 - return namedArg1orN(True);
382 + return namedArg1orN(context, True);
386 @@ -1961,13 +1907,13 @@ OP_FUNCTION(namedArg1)
388 OP_FUNCTION(namedArgN)
390 - return namedArg1orN(False);
391 + return namedArg1orN(context, False);
395 ** implementation for namedArg1(), namedArgN()
397 -static int namedArg1orN(Boolean isFirst)
398 +static int namedArg1orN(RestartData *context, Boolean isFirst)
400 int errNum;
401 char *keyString = NULL;
402 @@ -1983,7 +1929,7 @@ static int namedArg1orN(Boolean isFirst)
403 POP(exprVal);
405 /* the next nDim stack entries form the index */
406 - errNum = makeArrayKeyFromArgs(nDim, &keyString, 0);
407 + errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0);
408 if (errNum != STAT_OK) {
409 return errNum;
411 @@ -2102,7 +2048,7 @@ OP_FUNCTION(arrayIndex)
412 STACKDUMP(nDim+3, 3);
414 /* the next nDim stack entries form the index */
415 - errNum = makeArrayKeyFromArgs(nDim, &keyString, False);
416 + errNum = makeArrayKeyFromArgs(context, nDim, &keyString, False);
417 if (errNum != STAT_OK) {
418 return errNum;
420 @@ -2424,8 +2370,8 @@ OP_FUNCTION(eq)
421 /* negated eq() call */
422 OP_FUNCTION(ne)
424 - eq();
425 - return not();
426 + eq(context);
427 + return not(context);
431 @@ -2616,7 +2562,7 @@ OP_FUNCTION(power)
434 PUSH_INT(n3);
435 - return errCheck("exponentiation");
436 + return errCheck(context, "exponentiation");
440 @@ -2627,8 +2573,8 @@ OP_FUNCTION(power)
441 ** stack elements. The stack elements are popped from the stack if leaveParams
442 ** is false.
444 -static int concatenateNwithSep(int nVals, const char *sep, char **result,
445 - int leaveParams)
446 +static int concatenateNwithSep(RestartData *context, int nVals, const char *sep,
447 + char **result, int leaveParams)
449 DataValue value;
450 char *res = NULL;
451 @@ -2711,7 +2657,7 @@ OP_FUNCTION(concat)
453 STACKDUMP(nExpr, 3);
455 - len = concatenateNwithSep(nExpr, "", &out, False);
456 + len = concatenateNwithSep(context, nExpr, "", &out, False);
457 if (len < 0) {
458 EXEC_ERROR("can only concatenate with string or integer", NULL);
460 @@ -2745,7 +2691,8 @@ OP_FUNCTION(concat)
461 ** or: Prog-> (in called)next, ... -- (macro code called subr)
462 ** TheStack-> symN-sym1(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ...
464 -static int callSubroutineFromSymbol(Symbol *sym, int nArgs)
465 +static int callSubroutineFromSymbol(RestartData *context, Symbol *sym,
466 + int nArgs)
468 Symbol *s;
469 int i;
470 @@ -2788,9 +2735,9 @@ static int callSubroutineFromSymbol(Symb
472 /* Call the function and check for preemption */
473 PreemptRequest = False;
474 - if (!sym->value.val.subr(FocusWindow, StackP,
475 - nArgs, &result, &errMsg))
476 - EXEC_ERROR(errMsg, sym->name);
477 + if (!sym->value.val.subr(context, StackP, nArgs, &result)) {
478 + EXEC_ERROR(context->errMsg, sym->name);
480 PUSH_RET_VAL(result);
481 return PreemptRequest ? STAT_PREEMPT : STAT_OK;
483 @@ -2803,15 +2750,10 @@ static int callSubroutineFromSymbol(Symb
484 ** values which are already there.
486 if (sym->type == MACRO_FUNCTION_SYM) {
487 - RestartData context;
488 - int status;
489 prog = sym->value.val.prog;
490 prog->refcount++;
491 /* -nArgs means 'arguments are on stack' */
492 - saveContext(&context);
493 - status = setupFrame(&context, prog, -nArgs, NULL, argArray, sym->name);
494 - restoreContext(&context);
495 - return status;
496 + return setupFrame(context, prog, -nArgs, NULL, argArray, sym->name);
500 @@ -2832,12 +2774,12 @@ static int callSubroutineFromSymbol(Symb
501 /* Create a fake event with a timestamp suitable for actions which need
502 timestamps, a marker to indicate that the call was from a macro
503 (to stop shell commands from putting up their own separate banner) */
504 - disp=XtDisplay(InitiatingWindow->shell);
505 - win=XtWindow(InitiatingWindow->shell);
506 + disp=XtDisplay(context->runWindow->shell);
507 + win=XtWindow(context->runWindow->shell);
509 key_event.type = KeyPress;
510 key_event.send_event = MACRO_EVENT_MARKER;
511 - key_event.time=XtLastTimestampProcessed(XtDisplay(InitiatingWindow->shell));
512 + key_event.time=XtLastTimestampProcessed(XtDisplay(context->runWindow->shell));
514 /* The following entries are just filled in to avoid problems
515 in strange cases, like calling "self_insert()" directly from the
516 @@ -2853,7 +2795,7 @@ static int callSubroutineFromSymbol(Symb
518 /* Call the action routine and check for preemption */
519 PreemptRequest = False;
520 - sym->value.val.xtproc(FocusWindow->lastFocus,
521 + sym->value.val.xtproc(context->focusWindow->lastFocus,
522 (XEvent *)&key_event, argList, &numArgs);
523 XtFree((char *)argList);
524 PUSH_RET_VAL(noValue);
525 @@ -2885,7 +2827,7 @@ OP_FUNCTION(callSubroutine)
527 STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3);
529 - return callSubroutineFromSymbol(sym, nArgs);
530 + return callSubroutineFromSymbol(context, sym, nArgs);
534 @@ -2920,7 +2862,7 @@ OP_FUNCTION(callSubroutineStackedN)
535 EXEC_ERROR("array argument call to %s erroneous", sym->name);
538 - return callSubroutineFromSymbol(sym, nArgs);
539 + return callSubroutineFromSymbol(context, sym, nArgs);
543 @@ -2929,8 +2871,8 @@ OP_FUNCTION(callSubroutineStackedN)
544 ** written in macro.c. If the caller has already "consumed" stack elements,
545 ** removeArgs must indicate how many.
548 -int OverlayRoutineFromSymbol(Symbol *sym, int nArgs, int removeArgs)
549 +int OverlayRoutineFromSymbol(RestartData *context, Symbol *sym, int nArgs,
550 + int removeArgs)
552 DataValue *argArray = StackP + nArgs - removeArgs;
554 @@ -2957,7 +2899,7 @@ int OverlayRoutineFromSymbol(Symbol *sym
555 assert (argArray->tag == NO_TAG);
556 StackP = argArray;
558 - return callSubroutineFromSymbol(sym, nArgs);
559 + return callSubroutineFromSymbol(context, sym, nArgs);
563 @@ -2965,8 +2907,8 @@ int OverlayRoutineFromSymbol(Symbol *sym
564 ** OverlayRoutineFromSymbol(). In this way a piece of compiled code can be
565 ** executed in the caller's context from a function in macro.c.
568 -int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs)
569 +int OverlayRoutineFromProg(RestartData *context, Program *prog, int nArgs,
570 + int removeArgs)
572 Symbol *sym;
573 int ret;
574 @@ -2983,7 +2925,7 @@ int OverlayRoutineFromProg(Program *prog
575 sym->next = NULL;
576 sym->added = 0;
578 - ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs);
579 + ret = OverlayRoutineFromSymbol(context, sym, nArgs, removeArgs);
581 free(sym);
583 @@ -3086,11 +3028,11 @@ OP_FUNCTION(fetchRetVal)
584 /* see comments for returnValOrNone() */
585 OP_FUNCTION(returnNoVal)
587 - return returnValOrNone(False);
588 + return returnValOrNone(context, False);
590 OP_FUNCTION(returnVal)
592 - return returnValOrNone(True);
593 + return returnValOrNone(context, True);
597 @@ -3100,7 +3042,7 @@ OP_FUNCTION(returnVal)
598 ** After: Prog-> next, ..., (in caller)[FETCH_RET_VAL?], ...
599 ** TheStack-> retVal?, next, ...
601 -static int returnValOrNone(int valOnStack)
602 +static int returnValOrNone(RestartData *context, int valOnStack)
604 DataValue retVal;
605 static DataValue noValue = {NO_TAG, {0}};
606 @@ -3116,7 +3058,7 @@ static int returnValOrNone(int valOnStac
607 retVal = noValue;
610 - PC = rewindFrame(&FrameP, &StackP);
611 + rewindFrame(context);
613 /* push returned value, if requsted */
614 PUSH_RET_VAL(retVal);
615 @@ -3154,13 +3096,13 @@ OP_FUNCTION(branch)
617 OP_FUNCTION(branchTrue)
619 - return branchIf(True);
620 + return branchIf(context, True);
622 OP_FUNCTION(branchFalse)
624 - return branchIf(False);
625 + return branchIf(context, False);
627 -static int branchIf(Boolean trueOrFalse)
628 +static int branchIf(RestartData *context, Boolean trueOrFalse)
630 int value;
631 Inst *addr;
632 @@ -3220,12 +3162,12 @@ int ArrayCopy(DataValue *dstArray, DataV
633 return(errNum);
635 if (!ArrayInsert(dstArray, srcIter->key, &tmpArray)) {
636 - EXEC_ERROR("array copy failed", NULL);
637 + return STAT_ERROR;
640 else {
641 if (!ArrayInsert(dstArray, srcIter->key, &srcIter->value)) {
642 - EXEC_ERROR("array copy failed", NULL);
643 + return STAT_ERROR;
646 srcIter = arrayIterateNext(srcIter);
647 @@ -3241,11 +3183,13 @@ int ArrayCopy(DataValue *dstArray, DataV
648 ** I really need to optimize the size approximation rather than assuming
649 ** a worst case size for every integer argument
651 -static int makeArrayKeyFromArgs(int nArgs, char **keyString, int leaveParams)
652 +static int makeArrayKeyFromArgs(RestartData *context, int nArgs,
653 + char **keyString, int leaveParams)
655 int len;
657 - len = concatenateNwithSep(nArgs, ARRAY_DIM_SEP, keyString, leaveParams);
658 + len = concatenateNwithSep(context, nArgs, ARRAY_DIM_SEP, keyString,
659 + leaveParams);
660 if (len < 0) {
661 EXEC_ERROR("can only index array with string or int.", NULL);
663 @@ -3561,7 +3505,7 @@ OP_FUNCTION(arrayRef)
664 STACKDUMP(nDim+1, 3);
666 if (nDim > 0) {
667 - errNum = makeArrayKeyFromArgs(nDim, &keyString, 0);
668 + errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0);
669 if (errNum != STAT_OK) {
670 return(errNum);
672 @@ -3615,7 +3559,7 @@ OP_FUNCTION(arrayAssign)
673 if (nDim > 0) {
674 POP(srcValue);
676 - errNum = makeArrayKeyFromArgs(nDim, &keyString, 0);
677 + errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0);
678 if (errNum != STAT_OK) {
679 return(errNum);
681 @@ -3671,7 +3615,7 @@ OP_FUNCTION(arrayRefAndAssignSetup)
684 if (nDim > 0) {
685 - errNum = makeArrayKeyFromArgs(nDim, &keyString, 1);
686 + errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 1);
687 if (errNum != STAT_OK) {
688 return(errNum);
690 @@ -4107,7 +4051,7 @@ OP_FUNCTION(deleteArrayElement)
691 if (nDim > 0) {
692 int errNum;
694 - errNum = makeArrayKeyFromArgs(nDim, &keyString, 0);
695 + errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0);
696 if (errNum != STAT_OK) {
697 return(errNum);
699 @@ -4251,7 +4195,7 @@ OP_FUNCTION(arrayNextNumIdx)
700 ** checks errno after operations which can set it. If an error occured,
701 ** creates appropriate error messages and returns false
703 -static int errCheck(const char *s)
704 +static int errCheck(RestartData *context, const char *s)
706 if (errno == EDOM)
707 EXEC_ERROR("%s argument out of domain", s);
708 @@ -4264,25 +4208,25 @@ static int errCheck(const char *s)
710 ** build a stack dump string, reallocating s as necessary.
712 -static char *stackDumpStr(DataValue *fp, const char *msg, char **s, int *pLen)
713 +static void stackDumpStr(RestartData *context, const char *msg, char **s, int *pLen)
715 int len;
716 const char *op;
717 char *np;
718 - DataValue *nfp = fp;
719 + DataValue *nfp = context->frameP;
720 Inst *pc;
722 #ifdef DEBUG_STACK
723 const char *dump;
724 printd("\n\n");
725 - disasmInternal(PC - 1, 1);
726 - stackdumpInternal(0, 50);
727 + disasmInternal(context->pc - 1, 1);
728 + stackdumpInternal(context, 0, 50);
729 dump = printd(NULL);
730 #endif
732 /* first measure the lengths */
733 len = strlen(msg) + 1;
734 - nfp = fp;
735 + nfp = context->frameP;
736 do {
737 len = len + FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.len + 1;
738 pc = FP_GET_RET_PC(nfp);
739 @@ -4302,7 +4246,7 @@ static char *stackDumpStr(DataValue *fp,
740 while (*op)
741 *np++ = *op++;
743 - nfp = fp;
744 + nfp = context->frameP;
745 do {
746 *np++ = '\n';
747 op = FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.rep;
748 @@ -4318,22 +4262,22 @@ static char *stackDumpStr(DataValue *fp,
749 #endif
751 *np = 0;
752 - return *s;
753 + context->errMsg = *s;
757 -** combine two strings in a static area and set ErrMsg to point to the
758 -** result. Returns false so a single return execError() statement can
759 +** combine two strings in a static area and set continuation->errMsg to point
760 +** to the result. Returns false so a single return execError() statement can
761 ** be used to both process the message and return.
763 -static int execError(const char *s1, const char *s2)
764 +static int execError(RestartData *context, const char *s1, const char *s2)
766 static char msg[MAX_ERR_MSG_LEN];
767 static char *err = NULL;
768 static int errlen = 0;
770 sprintf(msg, s1, s2);
771 - ErrMsg = stackDumpStr(FrameP, msg, &err, &errlen);
772 + stackDumpStr(context, msg, &err, &errlen);
773 return STAT_ERROR;
776 @@ -4905,31 +4849,31 @@ static void stackdumpframe(DataValue *ar
777 #endif /* #ifdef DEBUG_STACK_HEADFIRST */
780 -static void stackdumpInternal(int n, int extra)
781 +static void stackdumpInternal(RestartData *context, int n, int extra)
783 - DataValue *arrow = StackP - n;
784 - DataValue *outpt = StackP - n - extra;
785 + DataValue *arrow = context->stackP - n;
786 + DataValue *outpt = context->stackP - n - extra;
788 #ifdef DEBUG_STACK_HEADFIRST
789 printd("Stack ----->\n");
790 - stackdumpframe(arrow, outpt, FrameP, StackP, '*');
791 - if (outpt < TheStack)
792 + stackdumpframe(arrow, outpt, context->frameP, context->stackP, '*');
793 + if (outpt < context->stack)
794 printd("--------------Stack base--------------\n");
795 #else
796 - if (outpt < TheStack)
797 + if (outpt < context->stack)
798 printd("--------------Stack base--------------\n");
799 - stackdumpframe(arrow, outpt, FrameP, StackP, '*');
800 + stackdumpframe(arrow, outpt, context->frameP, context->stackP, '*');
801 printd("Stack ----->\n\n");
802 #endif /* #ifdef DEBUG_STACK_HEADFIRST */
805 -static void stackdump(int n, int extra)
806 +static void stackdump(RestartData *context, int n, int extra)
808 static int outIsTTY = -1;
809 if (outIsTTY == -1)
810 outIsTTY = isatty(fileno(stdout));
812 - stackdumpInternal(n, extra);
813 + stackdumpInternal(context, n, extra);
815 if (outIsTTY)
816 printd("\033[J\n");
817 diff --quilt old/source/interpret.h new/source/interpret.h
818 --- old/source/interpret.h
819 +++ new/source/interpret.h
820 @@ -62,6 +62,7 @@ struct DataValueTag;
821 struct SparseArrayEntryTag;
822 struct ProgramTag;
823 struct SymbolRec;
824 +struct RestartDataTag;
826 typedef struct InstTag {
827 enum instTypes type;
828 @@ -73,8 +74,8 @@ typedef struct InstTag {
829 } val;
830 } Inst;
832 -typedef int (*BuiltInSubr)(WindowInfo *window, struct DataValueTag *argList,
833 - int nArgs, struct DataValueTag *result, char **errMsg);
834 +typedef int (BuiltInSubr)(struct RestartDataTag *context,
835 + struct DataValueTag *argList, int nArgs, struct DataValueTag *result);
837 typedef struct NStringTag {
838 char *rep;
839 @@ -86,11 +87,11 @@ typedef struct DataValueTag {
840 union {
841 int n;
842 struct NStringTag str;
843 - BuiltInSubr subr;
844 - struct ProgramTag* prog;
845 + BuiltInSubr *subr;
846 + struct ProgramTag *prog;
847 XtActionProc xtproc;
848 - Inst* inst;
849 - struct DataValueTag* dataval;
850 + Inst *inst;
851 + struct DataValueTag *dataval;
852 struct SparseArrayEntryTag *arrayPtr;
853 struct SymbolRec *sym;
854 } val;
855 @@ -120,13 +121,14 @@ typedef struct ProgramTag {
856 } Program;
858 /* Information needed to re-start a preempted macro */
859 -typedef struct {
860 +typedef struct RestartDataTag {
861 DataValue *stack;
862 DataValue *stackP;
863 DataValue *frameP;
864 Inst *pc;
865 WindowInfo *runWindow;
866 WindowInfo *focusWindow;
867 + char *errMsg;
868 } RestartData;
870 /* state of the accumulator (aka compiler) */
871 @@ -183,8 +185,10 @@ int ContinueMacro(RestartData *continuat
872 int RunMacroAsSubrCall(RestartData *context, Program *prog, char **msg);
873 void PreemptMacro(void);
875 -int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs);
876 -int OverlayRoutineFromSymbol(Symbol *sym, int nArgs, int removeArgs);
877 +int OverlayRoutineFromProg(RestartData *context, Program *prog, int nArgs,
878 + int removeArgs);
879 +int OverlayRoutineFromSymbol(RestartData *context, Symbol *sym, int nArgs,
880 + int removeArgs);
882 char *AllocString(int length);
883 char *AllocStringNCpy(const char *s, int length);
884 @@ -199,8 +203,6 @@ Symbol *PromoteToGlobal(Symbol *sym);
885 void FreeProgram(Program *prog);
886 void ModifyReturnedValue(RestartData *context, DataValue dv);
887 WindowInfo *MacroRunWindow(void);
888 -WindowInfo *MacroFocusWindow(void);
889 -void SetMacroFocusWindow(WindowInfo *window);
890 /* function used for implicit conversion from string to number */
891 int StringToNum(const char *string, int *number);
892 const char *longAsStr(long val);
893 diff --quilt old/source/macro.c new/source/macro.c
894 --- old/source/macro.c
895 +++ new/source/macro.c
896 @@ -170,82 +170,82 @@ static void bannerTimeoutProc(XtPointer
897 static Boolean continueWorkProc(XtPointer clientData);
898 static int escapeStringChars(char *fromString, char *toString);
899 static int escapedStringLength(char *string);
900 -static int argsMS(WindowInfo *window, DataValue *argList, int nArgs,
901 - DataValue *result, char **errMsg);
902 -static int nArgsMS(WindowInfo *window, DataValue *argList, int nArgs,
903 - DataValue *result, char **errMsg);
904 -static int lengthMS(WindowInfo *window, DataValue *argList, int nArgs,
905 - DataValue *result, char **errMsg);
906 -static int minMS(WindowInfo *window, DataValue *argList, int nArgs,
907 - DataValue *result, char **errMsg);
908 -static int maxMS(WindowInfo *window, DataValue *argList, int nArgs,
909 - DataValue *result, char **errMsg);
910 -static int focusWindowMS(WindowInfo *window, DataValue *argList, int nArgs,
911 - DataValue *result, char **errMsg);
912 -static int getRangeMS(WindowInfo *window, DataValue *argList, int nArgs,
913 - DataValue *result, char **errMsg);
914 -static int getCharacterMS(WindowInfo *window, DataValue *argList, int nArgs,
915 - DataValue *result, char **errMsg);
916 -static int replaceRangeMS(WindowInfo *window, DataValue *argList, int nArgs,
917 - DataValue *result, char **errMsg);
918 -static int replaceSelectionMS(WindowInfo *window, DataValue *argList, int nArgs,
919 - DataValue *result, char **errMsg);
920 -static int getSelectionMS(WindowInfo *window, DataValue *argList, int nArgs,
921 - DataValue *result, char **errMsg);
922 -static int validNumberMS(WindowInfo *window, DataValue *argList, int nArgs,
923 - DataValue *result, char **errMsg);
924 -static int replaceInStringMS(WindowInfo *window, DataValue *argList, int nArgs,
925 - DataValue *result, char **errMsg);
926 -static int replaceSubstringMS(WindowInfo *window, DataValue *argList, int nArgs,
927 - DataValue *result, char **errMsg);
928 -static int fullFileNameMS(WindowInfo *window, DataValue *argList, int nArgs,
929 - DataValue *result, char **errMsg);
930 -static int readFileMS(WindowInfo *window, DataValue *argList, int nArgs,
931 - DataValue *result, char **errMsg);
932 -static int writeFileMS(WindowInfo *window, DataValue *argList, int nArgs,
933 - DataValue *result, char **errMsg);
934 -static int appendFileMS(WindowInfo *window, DataValue *argList, int nArgs,
935 - DataValue *result, char **errMsg);
936 +static int argsMS(RestartData *context, DataValue *argList, int nArgs,
937 + DataValue *result);
938 +static int nArgsMS(RestartData *context, DataValue *argList, int nArgs,
939 + DataValue *result);
940 +static int lengthMS(RestartData *context, DataValue *argList, int nArgs,
941 + DataValue *result);
942 +static int minMS(RestartData *context, DataValue *argList, int nArgs,
943 + DataValue *result);
944 +static int maxMS(RestartData *context, DataValue *argList, int nArgs,
945 + DataValue *result);
946 +static int focusWindowMS(RestartData *context, DataValue *argList, int nArgs,
947 + DataValue *result);
948 +static int getRangeMS(RestartData *context, DataValue *argList, int nArgs,
949 + DataValue *result);
950 +static int getCharacterMS(RestartData *context, DataValue *argList, int nArgs,
951 + DataValue *result);
952 +static int replaceRangeMS(RestartData *context, DataValue *argList, int nArgs,
953 + DataValue *result);
954 +static int replaceSelectionMS(RestartData *context, DataValue *argList, int nArgs,
955 + DataValue *result);
956 +static int getSelectionMS(RestartData *context, DataValue *argList, int nArgs,
957 + DataValue *result);
958 +static int validNumberMS(RestartData *context, DataValue *argList, int nArgs,
959 + DataValue *result);
960 +static int replaceInStringMS(RestartData *context, DataValue *argList, int nArgs,
961 + DataValue *result);
962 +static int replaceSubstringMS(RestartData *context, DataValue *argList, int nArgs,
963 + DataValue *result);
964 +static int fullFileNameMS(RestartData *context, DataValue *argList, int nArgs,
965 + DataValue *result);
966 +static int readFileMS(RestartData *context, DataValue *argList, int nArgs,
967 + DataValue *result);
968 +static int writeFileMS(RestartData *context, DataValue *argList, int nArgs,
969 + DataValue *result);
970 +static int appendFileMS(RestartData *context, DataValue *argList, int nArgs,
971 + DataValue *result);
972 static int writeOrAppendFile(int append, WindowInfo *window,
973 DataValue *argList, int nArgs, DataValue *result, char **errMsg);
974 -static int substringMS(WindowInfo *window, DataValue *argList, int nArgs,
975 - DataValue *result, char **errMsg);
976 -static int toupperMS(WindowInfo *window, DataValue *argList, int nArgs,
977 - DataValue *result, char **errMsg);
978 -static int tolowerMS(WindowInfo *window, DataValue *argList, int nArgs,
979 - DataValue *result, char **errMsg);
980 -static int stringToClipboardMS(WindowInfo *window, DataValue *argList, int nArgs,
981 - DataValue *result, char **errMsg);
982 -static int clipboardToStringMS(WindowInfo *window, DataValue *argList, int nArgs,
983 - DataValue *result, char **errMsg);
984 -static int searchMS(WindowInfo *window, DataValue *argList, int nArgs,
985 - DataValue *result, char **errMsg);
986 -static int searchStringMS(WindowInfo *window, DataValue *argList, int nArgs,
987 - DataValue *result, char **errMsg);
988 -static int setCursorPosMS(WindowInfo *window, DataValue *argList, int nArgs,
989 - DataValue *result, char **errMsg);
990 -static int beepMS(WindowInfo *window, DataValue *argList, int nArgs,
991 - DataValue *result, char **errMsg);
992 -static int selectMS(WindowInfo *window, DataValue *argList, int nArgs,
993 - DataValue *result, char **errMsg);
994 -static int selectRectangleMS(WindowInfo *window, DataValue *argList, int nArgs,
995 - DataValue *result, char **errMsg);
996 -static int tPrintMS(WindowInfo *window, DataValue *argList, int nArgs,
997 - DataValue *result, char **errMsg);
998 -static int getenvMS(WindowInfo *window, DataValue *argList, int nArgs,
999 - DataValue *result, char **errMsg);
1000 -static int shellCmdMS(WindowInfo *window, DataValue *argList, int nArgs,
1001 - DataValue *result, char **errMsg);
1002 -static int dialogMS(WindowInfo *window, DataValue *argList, int nArgs,
1003 - DataValue *result, char **errMsg);
1004 +static int substringMS(RestartData *context, DataValue *argList, int nArgs,
1005 + DataValue *result);
1006 +static int toupperMS(RestartData *context, DataValue *argList, int nArgs,
1007 + DataValue *result);
1008 +static int tolowerMS(RestartData *context, DataValue *argList, int nArgs,
1009 + DataValue *result);
1010 +static int stringToClipboardMS(RestartData *context, DataValue *argList, int nArgs,
1011 + DataValue *result);
1012 +static int clipboardToStringMS(RestartData *context, DataValue *argList, int nArgs,
1013 + DataValue *result);
1014 +static int searchMS(RestartData *context, DataValue *argList, int nArgs,
1015 + DataValue *result);
1016 +static int searchStringMS(RestartData *context, DataValue *argList, int nArgs,
1017 + DataValue *result);
1018 +static int setCursorPosMS(RestartData *context, DataValue *argList, int nArgs,
1019 + DataValue *result);
1020 +static int beepMS(RestartData *context, DataValue *argList, int nArgs,
1021 + DataValue *result);
1022 +static int selectMS(RestartData *context, DataValue *argList, int nArgs,
1023 + DataValue *result);
1024 +static int selectRectangleMS(RestartData *context, DataValue *argList, int nArgs,
1025 + DataValue *result);
1026 +static int tPrintMS(RestartData *context, DataValue *argList, int nArgs,
1027 + DataValue *result);
1028 +static int getenvMS(RestartData *context, DataValue *argList, int nArgs,
1029 + DataValue *result);
1030 +static int shellCmdMS(RestartData *context, DataValue *argList, int nArgs,
1031 + DataValue *result);
1032 +static int dialogMS(RestartData *context, DataValue *argList, int nArgs,
1033 + DataValue *result);
1034 static void dialogBtnCB(Widget w, XtPointer clientData, XtPointer callData);
1035 static void dialogCloseCB(Widget w, XtPointer clientData, XtPointer callData);
1036 #ifdef LESSTIF_VERSION
1037 static void dialogEscCB(Widget w, XtPointer clientData, XEvent *event,
1038 Boolean *cont);
1039 #endif /* LESSTIF_VERSION */
1040 -static int stringDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
1041 - DataValue *result, char **errMsg);
1042 +static int stringDialogMS(RestartData *context, DataValue *argList, int nArgs,
1043 + DataValue *result);
1044 static void stringDialogBtnCB(Widget w, XtPointer clientData,
1045 XtPointer callData);
1046 static void stringDialogCloseCB(Widget w, XtPointer clientData,
1047 @@ -254,122 +254,122 @@ static void stringDialogCloseCB(Widget w
1048 static void stringDialogEscCB(Widget w, XtPointer clientData, XEvent *event,
1049 Boolean *cont);
1050 #endif /* LESSTIF_VERSION */
1051 -static int calltipMS(WindowInfo *window, DataValue *argList, int nArgs,
1052 - DataValue *result, char **errMsg);
1053 -static int killCalltipMS(WindowInfo *window, DataValue *argList, int nArgs,
1054 - DataValue *result, char **errMsg);
1055 -static int highlightCTLineMS(WindowInfo *window, DataValue *argList, int nArgs,
1056 - DataValue *result, char **errMsg);
1057 +static int calltipMS(RestartData *context, DataValue *argList, int nArgs,
1058 + DataValue *result);
1059 +static int killCalltipMS(RestartData *context, DataValue *argList, int nArgs,
1060 + DataValue *result);
1061 +static int highlightCTLineMS(RestartData *context, DataValue *argList, int nArgs,
1062 + DataValue *result);
1063 /* T Balinski */
1064 -static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
1065 - DataValue *result, char **errMsg);
1066 +static int listDialogMS(RestartData *context, DataValue *argList, int nArgs,
1067 + DataValue *result);
1068 static void listDialogBtnCB(Widget w, XtPointer clientData,
1069 - XtPointer callData);
1070 + XtPointer callData);
1071 static void listDialogCloseCB(Widget w, XtPointer clientData,
1072 - XtPointer callData);
1073 + XtPointer callData);
1074 /* T Balinski End */
1075 #ifdef LESSTIF_VERSION
1076 static void listDialogEscCB(Widget w, XtPointer clientData, XEvent *event,
1077 Boolean *cont);
1078 #endif /* LESSTIF_VERSION */
1079 -static int stringCompareMS(WindowInfo *window, DataValue *argList, int nArgs,
1080 - DataValue *result, char **errMsg);
1081 -static int splitMS(WindowInfo *window, DataValue *argList, int nArgs,
1082 - DataValue *result, char **errMsg);
1083 -static int joinMS(WindowInfo *window, DataValue *argList, int nArgs,
1084 - DataValue *result, char **errMsg);
1085 +static int stringCompareMS(RestartData *context, DataValue *argList, int nArgs,
1086 + DataValue *result);
1087 +static int splitMS(RestartData *context, DataValue *argList, int nArgs,
1088 + DataValue *result);
1089 +static int joinMS(RestartData *context, DataValue *argList, int nArgs,
1090 + DataValue *result);
1091 /* DISASBLED for 5.4
1092 -static int setBacklightStringMS(WindowInfo *window, DataValue *argList,
1093 - int nArgs, DataValue *result, char **errMsg);
1094 +static int setBacklightStringMS(RestartData *context, DataValue *argList,
1095 + int nArgs, DataValue *result);
1097 -static int cursorMV(WindowInfo *window, DataValue *argList, int nArgs,
1098 - DataValue *result, char **errMsg);
1099 -static int lineMV(WindowInfo *window, DataValue *argList, int nArgs,
1100 - DataValue *result, char **errMsg);
1101 -static int columnMV(WindowInfo *window, DataValue *argList, int nArgs,
1102 - DataValue *result, char **errMsg);
1103 -static int fileNameMV(WindowInfo *window, DataValue *argList, int nArgs,
1104 - DataValue *result, char **errMsg);
1105 -static int filePathMV(WindowInfo *window, DataValue *argList, int nArgs,
1106 - DataValue *result, char **errMsg);
1107 -static int lengthMV(WindowInfo *window, DataValue *argList, int nArgs,
1108 - DataValue *result, char **errMsg);
1109 -static int selectionStartMV(WindowInfo *window, DataValue *argList, int nArgs,
1110 - DataValue *result, char **errMsg);
1111 -static int selectionEndMV(WindowInfo *window, DataValue *argList, int nArgs,
1112 - DataValue *result, char **errMsg);
1113 -static int selectionLeftMV(WindowInfo *window, DataValue *argList, int nArgs,
1114 - DataValue *result, char **errMsg);
1115 -static int selectionRightMV(WindowInfo *window, DataValue *argList, int nArgs,
1116 - DataValue *result, char **errMsg);
1117 -static int statisticsLineMV(WindowInfo *window, DataValue *argList, int nArgs,
1118 - DataValue *result, char **errMsg);
1119 -static int incSearchLineMV(WindowInfo *window, DataValue *argList, int nArgs,
1120 - DataValue *result, char **errMsg);
1121 -static int showLineNumbersMV(WindowInfo *window, DataValue *argList, int nArgs,
1122 - DataValue *result, char **errMsg);
1123 -static int autoIndentMV(WindowInfo *window, DataValue *argList, int nArgs,
1124 - DataValue *result, char **errMsg);
1125 -static int wrapTextMV(WindowInfo *window, DataValue *argList, int nArgs,
1126 - DataValue *result, char **errMsg);
1127 -static int highlightSyntaxMV(WindowInfo *window, DataValue *argList, int nArgs,
1128 - DataValue *result, char **errMsg);
1129 -static int makeBackupCopyMV(WindowInfo *window, DataValue *argList, int nArgs,
1130 - DataValue *result, char **errMsg);
1131 -static int incBackupMV(WindowInfo *window, DataValue *argList, int nArgs,
1132 - DataValue *result, char **errMsg);
1133 -static int showMatchingMV(WindowInfo *window, DataValue *argList, int nArgs,
1134 - DataValue *result, char **errMsg);
1135 -static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs,
1136 - DataValue *result, char **errMsg);
1137 -static int readOnlyMV(WindowInfo *window, DataValue *argList, int nArgs,
1138 - DataValue *result, char **errMsg);
1139 -static int lockedMV(WindowInfo *window, DataValue *argList, int nArgs,
1140 - DataValue *result, char **errMsg);
1141 -static int fileFormatMV(WindowInfo *window, DataValue *argList, int nArgs,
1142 - DataValue *result, char **errMsg);
1143 -static int fontNameMV(WindowInfo *window, DataValue *argList, int nArgs,
1144 - DataValue *result, char **errMsg);
1145 -static int fontNameItalicMV(WindowInfo *window, DataValue *argList, int nArgs,
1146 - DataValue *result, char **errMsg);
1147 -static int fontNameBoldMV(WindowInfo *window, DataValue *argList, int nArgs,
1148 - DataValue *result, char **errMsg);
1149 -static int fontNameBoldItalicMV(WindowInfo *window, DataValue *argList, int nArgs,
1150 - DataValue *result, char **errMsg);
1151 -static int subscriptSepMV(WindowInfo *window, DataValue *argList, int nArgs,
1152 - DataValue *result, char **errMsg);
1153 -static int minFontWidthMV(WindowInfo *window, DataValue *argList, int nArgs,
1154 - DataValue *result, char **errMsg);
1155 -static int maxFontWidthMV(WindowInfo *window, DataValue *argList, int nArgs,
1156 - DataValue *result, char **errMsg);
1157 -static int wrapMarginMV(WindowInfo *window, DataValue *argList, int nArgs,
1158 - DataValue *result, char **errMsg);
1159 -static int topLineMV(WindowInfo *window, DataValue *argList, int nArgs,
1160 - DataValue *result, char **errMsg);
1161 -static int numDisplayLinesMV(WindowInfo *window, DataValue *argList, int nArgs,
1162 - DataValue *result, char **errMsg);
1163 -static int displayWidthMV(WindowInfo *window, DataValue *argList, int nArgs,
1164 - DataValue *result, char **errMsg);
1165 -static int activePaneMV(WindowInfo *window, DataValue *argList, int nArgs,
1166 - DataValue *result, char **errMsg);
1167 -static int nPanesMV(WindowInfo *window, DataValue *argList, int nArgs,
1168 - DataValue *result, char **errMsg);
1169 -static int emptyArrayMV(WindowInfo *window, DataValue *argList, int nArgs,
1170 - DataValue *result, char **errMsg);
1171 -static int serverNameMV(WindowInfo *window, DataValue *argList, int nArgs,
1172 - DataValue *result, char **errMsg);
1173 -static int tabDistMV(WindowInfo *window, DataValue *argList, int nArgs,
1174 - DataValue *result, char **errMsg);
1175 -static int emTabDistMV(WindowInfo *window, DataValue *argList, int nArgs,
1176 - DataValue *result, char **errMsg);
1177 -static int useTabsMV(WindowInfo *window, DataValue *argList, int nArgs,
1178 - DataValue *result, char **errMsg);
1179 -static int modifiedMV(WindowInfo *window, DataValue *argList, int nArgs,
1180 - DataValue *result, char **errMsg);
1181 -static int languageModeMV(WindowInfo *window, DataValue *argList, int nArgs,
1182 - DataValue *result, char **errMsg);
1183 -static int calltipIDMV(WindowInfo *window, DataValue *argList, int nArgs,
1184 - DataValue *result, char **errMsg);
1185 +static int cursorMV(RestartData *context, DataValue *argList, int nArgs,
1186 + DataValue *result);
1187 +static int lineMV(RestartData *context, DataValue *argList, int nArgs,
1188 + DataValue *result);
1189 +static int columnMV(RestartData *context, DataValue *argList, int nArgs,
1190 + DataValue *result);
1191 +static int fileNameMV(RestartData *context, DataValue *argList, int nArgs,
1192 + DataValue *result);
1193 +static int filePathMV(RestartData *context, DataValue *argList, int nArgs,
1194 + DataValue *result);
1195 +static int lengthMV(RestartData *context, DataValue *argList, int nArgs,
1196 + DataValue *result);
1197 +static int selectionStartMV(RestartData *context, DataValue *argList, int nArgs,
1198 + DataValue *result);
1199 +static int selectionEndMV(RestartData *context, DataValue *argList, int nArgs,
1200 + DataValue *result);
1201 +static int selectionLeftMV(RestartData *context, DataValue *argList, int nArgs,
1202 + DataValue *result);
1203 +static int selectionRightMV(RestartData *context, DataValue *argList, int nArgs,
1204 + DataValue *result);
1205 +static int statisticsLineMV(RestartData *context, DataValue *argList, int nArgs,
1206 + DataValue *result);
1207 +static int incSearchLineMV(RestartData *context, DataValue *argList, int nArgs,
1208 + DataValue *result);
1209 +static int showLineNumbersMV(RestartData *context, DataValue *argList, int nArgs,
1210 + DataValue *result);
1211 +static int autoIndentMV(RestartData *context, DataValue *argList, int nArgs,
1212 + DataValue *result);
1213 +static int wrapTextMV(RestartData *context, DataValue *argList, int nArgs,
1214 + DataValue *result);
1215 +static int highlightSyntaxMV(RestartData *context, DataValue *argList, int nArgs,
1216 + DataValue *result);
1217 +static int makeBackupCopyMV(RestartData *context, DataValue *argList, int nArgs,
1218 + DataValue *result);
1219 +static int incBackupMV(RestartData *context, DataValue *argList, int nArgs,
1220 + DataValue *result);
1221 +static int showMatchingMV(RestartData *context, DataValue *argList, int nArgs,
1222 + DataValue *result);
1223 +static int overTypeModeMV(RestartData *context, DataValue *argList, int nArgs,
1224 + DataValue *result);
1225 +static int readOnlyMV(RestartData *context, DataValue *argList, int nArgs,
1226 + DataValue *result);
1227 +static int lockedMV(RestartData *context, DataValue *argList, int nArgs,
1228 + DataValue *result);
1229 +static int fileFormatMV(RestartData *context, DataValue *argList, int nArgs,
1230 + DataValue *result);
1231 +static int fontNameMV(RestartData *context, DataValue *argList, int nArgs,
1232 + DataValue *result);
1233 +static int fontNameItalicMV(RestartData *context, DataValue *argList, int nArgs,
1234 + DataValue *result);
1235 +static int fontNameBoldMV(RestartData *context, DataValue *argList, int nArgs,
1236 + DataValue *result);
1237 +static int fontNameBoldItalicMV(RestartData *context, DataValue *argList, int nArgs,
1238 + DataValue *result);
1239 +static int subscriptSepMV(RestartData *context, DataValue *argList, int nArgs,
1240 + DataValue *result);
1241 +static int minFontWidthMV(RestartData *context, DataValue *argList, int nArgs,
1242 + DataValue *result);
1243 +static int maxFontWidthMV(RestartData *context, DataValue *argList, int nArgs,
1244 + DataValue *result);
1245 +static int wrapMarginMV(RestartData *context, DataValue *argList, int nArgs,
1246 + DataValue *result);
1247 +static int topLineMV(RestartData *context, DataValue *argList, int nArgs,
1248 + DataValue *result);
1249 +static int numDisplayLinesMV(RestartData *context, DataValue *argList, int nArgs,
1250 + DataValue *result);
1251 +static int displayWidthMV(RestartData *context, DataValue *argList, int nArgs,
1252 + DataValue *result);
1253 +static int activePaneMV(RestartData *context, DataValue *argList, int nArgs,
1254 + DataValue *result);
1255 +static int nPanesMV(RestartData *context, DataValue *argList, int nArgs,
1256 + DataValue *result);
1257 +static int emptyArrayMV(RestartData *context, DataValue *argList, int nArgs,
1258 + DataValue *result);
1259 +static int serverNameMV(RestartData *context, DataValue *argList, int nArgs,
1260 + DataValue *result);
1261 +static int tabDistMV(RestartData *context, DataValue *argList, int nArgs,
1262 + DataValue *result);
1263 +static int emTabDistMV(RestartData *context, DataValue *argList, int nArgs,
1264 + DataValue *result);
1265 +static int useTabsMV(RestartData *context, DataValue *argList, int nArgs,
1266 + DataValue *result);
1267 +static int modifiedMV(RestartData *context, DataValue *argList, int nArgs,
1268 + DataValue *result);
1269 +static int languageModeMV(RestartData *context, DataValue *argList, int nArgs,
1270 + DataValue *result);
1271 +static int calltipIDMV(RestartData *context, DataValue *argList, int nArgs,
1272 + DataValue *result);
1273 static int readSearchArgs(DataValue *argList, int nArgs, int*searchDirection,
1274 int *searchType, int *wrap, char **errMsg);
1275 static int wrongNArgsErr(char **errMsg);
1276 @@ -379,101 +379,101 @@ static int readIntArg(DataValue dv, int
1277 static int readStringArg(DataValue dv, char **result, char *stringStorage,
1278 char **errMsg);
1279 /* DISABLED FOR 5.4
1280 -static int backlightStringMV(WindowInfo *window, DataValue *argList,
1281 - int nArgs, DataValue *result, char **errMsg);
1282 +static int backlightStringMV(RestartData *context, DataValue *argList,
1283 + int nArgs, DataValue *result);
1285 -static int rangesetListMV(WindowInfo *window, DataValue *argList,
1286 - int nArgs, DataValue *result, char **errMsg);
1287 -static int versionMV(WindowInfo* window, DataValue* argList, int nArgs,
1288 - DataValue* result, char** errMsg);
1289 -static int neditHomeMV(WindowInfo *window, DataValue *argList, int nArgs,
1290 - DataValue *result, char **errMsg);
1291 -static int transientMV(WindowInfo *window, DataValue *argList, int nArgs,
1292 - DataValue *result, char **errMsg);
1293 -static int rangesetCreateMS(WindowInfo *window, DataValue *argList, int nArgs,
1294 - DataValue *result, char **errMsg);
1295 -static int rangesetDestroyMS(WindowInfo *window, DataValue *argList, int nArgs,
1296 - DataValue *result, char **errMsg);
1297 -static int rangesetGetByNameMS(WindowInfo *window, DataValue *argList, int nArgs,
1298 - DataValue *result, char **errMsg);
1299 -static int rangesetAddMS(WindowInfo *window, DataValue *argList, int nArgs,
1300 - DataValue *result, char **errMsg);
1301 -static int rangesetSubtractMS(WindowInfo *window, DataValue *argList, int nArgs,
1302 - DataValue *result, char **errMsg);
1303 -static int rangesetInvertMS(WindowInfo *window, DataValue *argList, int nArgs,
1304 - DataValue *result, char **errMsg);
1305 -static int rangesetInfoMS(WindowInfo *window, DataValue *argList, int nArgs,
1306 - DataValue *result, char **errMsg);
1307 -static int rangesetRangeMS(WindowInfo *window, DataValue *argList, int nArgs,
1308 - DataValue *result, char **errMsg);
1309 -static int rangesetIncludesPosMS(WindowInfo *window, DataValue *argList,
1310 - int nArgs, DataValue *result, char **errMsg);
1311 -static int rangesetSetColorMS(WindowInfo *window, DataValue *argList,
1312 - int nArgs, DataValue *result, char **errMsg);
1313 -static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList,
1314 - int nArgs, DataValue *result, char **errMsg);
1315 -static int rangesetSetNameMS(WindowInfo *window, DataValue *argList,
1316 - int nArgs, DataValue *result, char **errMsg);
1317 -static int rangesetSetModeMS(WindowInfo *window, DataValue *argList,
1318 - int nArgs, DataValue *result, char **errMsg);
1319 +static int rangesetListMV(RestartData *context, DataValue *argList, int nArgs,
1320 + DataValue *result);
1321 +static int versionMV(RestartData *context, DataValue *argList, int nArgs,
1322 + DataValue *result);
1323 +static int neditHomeMV(RestartData *context, DataValue *argList, int nArgs,
1324 + DataValue *result);
1325 +static int transientMV(RestartData *context, DataValue *argList, int nArgs,
1326 + DataValue *result);
1327 +static int rangesetCreateMS(RestartData *context, DataValue *argList, int nArgs,
1328 + DataValue *result);
1329 +static int rangesetDestroyMS(RestartData *context, DataValue *argList, int nArgs,
1330 + DataValue *result);
1331 +static int rangesetGetByNameMS(RestartData *context, DataValue *argList, int nArgs,
1332 + DataValue *result);
1333 +static int rangesetAddMS(RestartData *context, DataValue *argList, int nArgs,
1334 + DataValue *result);
1335 +static int rangesetSubtractMS(RestartData *context, DataValue *argList, int nArgs,
1336 + DataValue *result);
1337 +static int rangesetInvertMS(RestartData *context, DataValue *argList, int nArgs,
1338 + DataValue *result);
1339 +static int rangesetInfoMS(RestartData *context, DataValue *argList, int nArgs,
1340 + DataValue *result);
1341 +static int rangesetRangeMS(RestartData *context, DataValue *argList, int nArgs,
1342 + DataValue *result);
1343 +static int rangesetIncludesPosMS(RestartData *context, DataValue *argList,
1344 + int nArgs, DataValue *result);
1345 +static int rangesetSetColorMS(RestartData *context, DataValue *argList,
1346 + int nArgs, DataValue *result);
1347 +static int rangesetSetUnderlineMS(RestartData *context, DataValue *argList,
1348 + int nArgs, DataValue *result);
1349 +static int rangesetSetNameMS(RestartData *context, DataValue *argList,
1350 + int nArgs, DataValue *result);
1351 +static int rangesetSetModeMS(RestartData *context, DataValue *argList,
1352 + int nArgs, DataValue *result);
1354 static int fillPatternResult(DataValue *result, char **errMsg, WindowInfo *window,
1355 char *patternName, Boolean preallocatedPatternName, Boolean includeName,
1356 char *styleName, int bufferPos);
1357 -static int getPatternByNameMS(WindowInfo *window, DataValue *argList, int nArgs,
1358 - DataValue *result, char **errMsg);
1359 -static int getPatternAtPosMS(WindowInfo *window, DataValue *argList, int nArgs,
1360 - DataValue *result, char **errMsg);
1361 +static int getPatternByNameMS(RestartData *context, DataValue *argList, int nArgs,
1362 + DataValue *result);
1363 +static int getPatternAtPosMS(RestartData *context, DataValue *argList, int nArgs,
1364 + DataValue *result);
1366 static int fillStyleResult(DataValue *result, char **errMsg,
1367 WindowInfo *window, char *styleName, Boolean preallocatedStyleName,
1368 Boolean includeName, int patCode, int bufferPos);
1369 -static int getStyleByNameMS(WindowInfo *window, DataValue *argList, int nArgs,
1370 - DataValue *result, char **errMsg);
1371 -static int getStyleAtPosMS(WindowInfo *window, DataValue *argList, int nArgs,
1372 - DataValue *result, char **errMsg);
1373 -static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs,
1374 - DataValue* result, char** errMsg);
1375 -static int callMS(WindowInfo *window, DataValue *argList,
1376 - int nArgs, DataValue *result, char **errMsg);
1377 -static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
1378 - int nArgs, DataValue *result, char **errMsg);
1379 +static int getStyleByNameMS(RestartData *context, DataValue *argList, int nArgs,
1380 + DataValue *result);
1381 +static int getStyleAtPosMS(RestartData *context, DataValue *argList, int nArgs,
1382 + DataValue *result);
1383 +static int filenameDialogMS(RestartData *context, DataValue *argList, int nArgs,
1384 + DataValue *result);
1385 +static int callMS(RestartData *context, DataValue *argList, int nArgs,
1386 + DataValue *result);
1387 +static int setWindowTitleMS(RestartData *context, DataValue *argList, int nArgs,
1388 + DataValue *result);
1390 /* Pattern Match Feature */
1391 -static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
1392 - DataValue *result, char **errMsg);
1393 +static int getMatchingMS(RestartData *context, DataValue *argList, int nArgs,
1394 + DataValue *result);
1396 -static int dictinsertMS(WindowInfo *window, DataValue *argList, int nArgs,
1397 - DataValue *result, char **errMsg);
1398 -static int dictcompleteMS(WindowInfo *window, DataValue *argList, int nArgs,
1399 - DataValue *result, char **errMsg);
1400 -static int dictsaveMS(WindowInfo *window, DataValue *argList, int nArgs,
1401 - DataValue *result, char **errMsg);
1402 -static int dictappendMS(WindowInfo *window, DataValue *argList, int nArgs,
1403 - DataValue *result, char **errMsg);
1404 -static int dictiselementMS(WindowInfo *window, DataValue *argList, int nArgs,
1405 - DataValue *result, char **errMsg);
1406 +static int dictinsertMS(RestartData *context, DataValue *argList, int nArgs,
1407 + DataValue *result);
1408 +static int dictcompleteMS(RestartData *context, DataValue *argList, int nArgs,
1409 + DataValue *result);
1410 +static int dictsaveMS(RestartData *context, DataValue *argList, int nArgs,
1411 + DataValue *result);
1412 +static int dictappendMS(RestartData *context, DataValue *argList, int nArgs,
1413 + DataValue *result);
1414 +static int dictiselementMS(RestartData *context, DataValue *argList, int nArgs,
1415 + DataValue *result);
1417 -static int defineMS(WindowInfo *window, DataValue *argList, int nArgs,
1418 - DataValue *result, char **errMsg);
1419 +static int defineMS(RestartData *context, DataValue *argList, int nArgs,
1420 + DataValue *result);
1423 * UL convertPos patch:
1424 * add "to_pos", "to_line", "to_column" macro subroutines
1426 -static int toPosMS(WindowInfo *window, DataValue *argList, int nArgs,
1427 - DataValue *result, char **errMsg);
1428 -static int toLineMS(WindowInfo *window, DataValue *argList, int nArgs,
1429 - DataValue *result, char **errMsg);
1430 -static int toColumnMS(WindowInfo *window, DataValue *argList, int nArgs,
1431 - DataValue *result, char **errMsg);
1433 -static int timerAddMS(WindowInfo *window, DataValue *argList,
1434 - int nArgs, DataValue *result, char **errMsg);
1435 -static int timerRemoveMS(WindowInfo *window, DataValue *argList,
1436 - int nArgs, DataValue *result, char **errMsg);
1437 -static int escapeLiteralMS(WindowInfo *window, DataValue *argList,
1438 - int nArgs, DataValue *result, char **errMsg);
1439 +static int toPosMS(RestartData *context, DataValue *argList, int nArgs,
1440 + DataValue *result);
1441 +static int toLineMS(RestartData *context, DataValue *argList, int nArgs,
1442 + DataValue *result);
1443 +static int toColumnMS(RestartData *context, DataValue *argList, int nArgs,
1444 + DataValue *result);
1446 +static int timerAddMS(RestartData *context, DataValue *argList,
1447 + int nArgs, DataValue *result);
1448 +static int timerRemoveMS(RestartData *context, DataValue *argList,
1449 + int nArgs, DataValue *result);
1450 +static int escapeLiteralMS(RestartData *context, DataValue *argList,
1451 + int nArgs, DataValue *result);
1453 /* Built-in subroutines and variables for the macro language */
1454 static const BuiltInSubrName MacroSubrs[] = {
1455 @@ -1189,8 +1189,9 @@ int MacroWindowCloseActions(WindowInfo *
1456 if (cmdData == NULL) {
1457 for (w=WindowList; w!=NULL; w=w->next) {
1458 mcd = (macroCmdInfo *)w->macroCmdData;
1459 - if (w == MacroRunWindow() && MacroFocusWindow() == window)
1460 - SetMacroFocusWindow(MacroRunWindow());
1461 + if (w == MacroRunWindow()
1462 + && cmdData->context->focusWindow == window)
1463 + cmdData->context->focusWindow = w;
1464 else if (mcd != NULL && mcd->context->focusWindow == window)
1465 mcd->context->focusWindow = mcd->context->runWindow;
1467 @@ -1201,7 +1202,7 @@ int MacroWindowCloseActions(WindowInfo *
1468 execution must otherwise return to the main loop to execute any
1469 commands), is running in this window, tell the caller not to close,
1470 and schedule window close on completion of macro */
1471 - if (window == MacroRunWindow()) {
1472 + if (window == cmdData->context->runWindow) {
1473 cmdData->closeOnCompletion = True;
1474 return False;
1476 @@ -1908,9 +1909,11 @@ static int escapedStringLength(char *str
1477 ** return $args
1478 ** }
1480 -static int argsMS(WindowInfo *window, DataValue *argList, int nArgs,
1481 - DataValue *result, char **errMsg)
1482 +static int argsMS(RestartData *context, DataValue *argList, int nArgs,
1483 + DataValue *result)
1485 + WindowInfo *window = context->focusWindow;
1486 + char **errMsg = &context->errMsg;
1487 DataValue *argsArray = &argList[nArgs];
1488 DataValue *argVal;
1489 int argNum;
1490 @@ -1944,9 +1947,11 @@ static int argsMS(WindowInfo *window, Da
1491 ** return i
1492 ** }
1494 -static int nArgsMS(WindowInfo *window, DataValue *argList, int nArgs,
1495 - DataValue *result, char **errMsg)
1496 +static int nArgsMS(RestartData *context, DataValue *argList, int nArgs,
1497 + DataValue *result)
1499 + WindowInfo *window = context->focusWindow;
1500 + char **errMsg = &context->errMsg;
1501 DataValue *argsArray = &argList[0];
1502 DataValue val;
1504 @@ -1970,9 +1975,11 @@ static int nArgsMS(WindowInfo *window, D
1506 ** Built-in macro subroutine for getting the length of a string
1508 -static int lengthMS(WindowInfo *window, DataValue *argList, int nArgs,
1509 - DataValue *result, char **errMsg)
1510 +static int lengthMS(RestartData *context, DataValue *argList, int nArgs,
1511 + DataValue *result)
1513 + WindowInfo *window = context->focusWindow;
1514 + char **errMsg = &context->errMsg;
1515 char *string, stringStorage[TYPE_INT_STR_SIZE(int)];
1517 if (nArgs != 1)
1518 @@ -1987,9 +1994,11 @@ static int lengthMS(WindowInfo *window,
1520 ** Built-in macro subroutines for min and max
1522 -static int minMS(WindowInfo *window, DataValue *argList, int nArgs,
1523 - DataValue *result, char **errMsg)
1524 +static int minMS(RestartData *context, DataValue *argList, int nArgs,
1525 + DataValue *result)
1527 + WindowInfo *window = context->focusWindow;
1528 + char **errMsg = &context->errMsg;
1529 int minVal, value, i;
1531 if (nArgs == 1)
1532 @@ -2005,9 +2014,11 @@ static int minMS(WindowInfo *window, Dat
1533 result->val.n = minVal;
1534 return True;
1536 -static int maxMS(WindowInfo *window, DataValue *argList, int nArgs,
1537 - DataValue *result, char **errMsg)
1538 +static int maxMS(RestartData *context, DataValue *argList, int nArgs,
1539 + DataValue *result)
1541 + WindowInfo *window = context->focusWindow;
1542 + char **errMsg = &context->errMsg;
1543 int maxVal, value, i;
1545 if (nArgs == 1)
1546 @@ -2024,9 +2035,11 @@ static int maxMS(WindowInfo *window, Dat
1547 return True;
1550 -static int focusWindowMS(WindowInfo *window, DataValue *argList, int nArgs,
1551 - DataValue *result, char **errMsg)
1552 +static int focusWindowMS(RestartData *context, DataValue *argList, int nArgs,
1553 + DataValue *result)
1555 + WindowInfo *window = context->focusWindow;
1556 + char **errMsg = &context->errMsg;
1557 char stringStorage[TYPE_INT_STR_SIZE(int)], *string;
1558 WindowInfo *w;
1559 char fullname[MAXPATHLEN];
1560 @@ -2080,7 +2093,7 @@ static int focusWindowMS(WindowInfo *win
1563 /* Change the focused window to the requested one */
1564 - SetMacroFocusWindow(w);
1565 + context->focusWindow = w;
1567 /* turn on syntax highlight that might have been deferred */
1568 if (w->highlightSyntax && w->highlightData==NULL)
1569 @@ -2097,9 +2110,11 @@ static int focusWindowMS(WindowInfo *win
1570 ** Built-in macro subroutine for getting text from the current window's text
1571 ** buffer
1573 -static int getRangeMS(WindowInfo *window, DataValue *argList, int nArgs,
1574 - DataValue *result, char **errMsg)
1575 +static int getRangeMS(RestartData *context, DataValue *argList, int nArgs,
1576 + DataValue *result)
1578 + WindowInfo *window = context->focusWindow;
1579 + char **errMsg = &context->errMsg;
1580 int from, to;
1581 textBuffer *buf = window->buffer;
1582 char *rangeText;
1583 @@ -2134,9 +2149,11 @@ static int getRangeMS(WindowInfo *window
1584 ** Built-in macro subroutine for getting a single character at the position
1585 ** given, from the current window
1587 -static int getCharacterMS(WindowInfo *window, DataValue *argList, int nArgs,
1588 - DataValue *result, char **errMsg)
1589 +static int getCharacterMS(RestartData *context, DataValue *argList, int nArgs,
1590 + DataValue *result)
1592 + WindowInfo *window = context->focusWindow;
1593 + char **errMsg = &context->errMsg;
1594 int pos;
1595 textBuffer *buf = window->buffer;
1597 @@ -2162,9 +2179,11 @@ static int getCharacterMS(WindowInfo *wi
1598 ** Built-in macro subroutine for replacing text in the current window's text
1599 ** buffer
1601 -static int replaceRangeMS(WindowInfo *window, DataValue *argList, int nArgs,
1602 - DataValue *result, char **errMsg)
1603 +static int replaceRangeMS(RestartData *context, DataValue *argList, int nArgs,
1604 + DataValue *result)
1606 + WindowInfo *window = context->focusWindow;
1607 + char **errMsg = &context->errMsg;
1608 int from, to;
1609 char stringStorage[TYPE_INT_STR_SIZE(int)], *string;
1610 textBuffer *buf = window->buffer;
1611 @@ -2212,9 +2231,11 @@ static int replaceRangeMS(WindowInfo *wi
1612 ** Built-in macro subroutine for replacing the primary-selection selected
1613 ** text in the current window's text buffer
1615 -static int replaceSelectionMS(WindowInfo *window, DataValue *argList, int nArgs,
1616 - DataValue *result, char **errMsg)
1617 +static int replaceSelectionMS(RestartData *context, DataValue *argList, int nArgs,
1618 + DataValue *result)
1620 + WindowInfo *window = context->focusWindow;
1621 + char **errMsg = &context->errMsg;
1622 char stringStorage[TYPE_INT_STR_SIZE(int)], *string;
1624 /* Validate argument and convert to string */
1625 @@ -2252,9 +2273,11 @@ static int replaceSelectionMS(WindowInfo
1626 ** the primary selection in the current window's text buffer, or in any
1627 ** part of screen if "any" argument is given
1629 -static int getSelectionMS(WindowInfo *window, DataValue *argList, int nArgs,
1630 - DataValue *result, char **errMsg)
1631 +static int getSelectionMS(RestartData *context, DataValue *argList, int nArgs,
1632 + DataValue *result)
1634 + WindowInfo *window = context->focusWindow;
1635 + char **errMsg = &context->errMsg;
1636 char *selText;
1638 /* Read argument list to check for "any" keyword, and get the appropriate
1639 @@ -2285,9 +2308,11 @@ static int getSelectionMS(WindowInfo *wi
1640 ** Built-in macro subroutine for determining if implicit conversion of
1641 ** a string to number will succeed or fail
1643 -static int validNumberMS(WindowInfo *window, DataValue *argList, int nArgs,
1644 - DataValue *result, char **errMsg)
1645 +static int validNumberMS(RestartData *context, DataValue *argList, int nArgs,
1646 + DataValue *result)
1648 + WindowInfo *window = context->focusWindow;
1649 + char **errMsg = &context->errMsg;
1650 char *string, stringStorage[TYPE_INT_STR_SIZE(int)];
1652 if (nArgs != 1) {
1653 @@ -2306,9 +2331,11 @@ static int validNumberMS(WindowInfo *win
1655 ** Built-in macro subroutine for replacing a substring within another string
1657 -static int replaceSubstringMS(WindowInfo *window, DataValue *argList, int nArgs,
1658 - DataValue *result, char **errMsg)
1659 +static int replaceSubstringMS(RestartData *context, DataValue *argList, int nArgs,
1660 + DataValue *result)
1662 + WindowInfo *window = context->focusWindow;
1663 + char **errMsg = &context->errMsg;
1664 int from, to, length, replaceLen, outLen;
1665 char stringStorage[2][TYPE_INT_STR_SIZE(int)], *string, *replStr;
1667 @@ -2345,9 +2372,11 @@ static int replaceSubstringMS(WindowInfo
1668 ** Built-in macro subroutine for getting a substring of a string.
1669 ** Called as substring(string, from [, to])
1671 -static int substringMS(WindowInfo *window, DataValue *argList, int nArgs,
1672 - DataValue *result, char **errMsg)
1673 +static int substringMS(RestartData *context, DataValue *argList, int nArgs,
1674 + DataValue *result)
1676 + WindowInfo *window = context->focusWindow;
1677 + char **errMsg = &context->errMsg;
1678 int from, to, length;
1679 char stringStorage[TYPE_INT_STR_SIZE(int)], *string;
1681 @@ -2376,9 +2405,11 @@ static int substringMS(WindowInfo *windo
1682 return True;
1685 -static int toupperMS(WindowInfo *window, DataValue *argList, int nArgs,
1686 - DataValue *result, char **errMsg)
1687 +static int toupperMS(RestartData *context, DataValue *argList, int nArgs,
1688 + DataValue *result)
1690 + WindowInfo *window = context->focusWindow;
1691 + char **errMsg = &context->errMsg;
1692 int i, length;
1693 char stringStorage[TYPE_INT_STR_SIZE(int)], *string;
1695 @@ -2397,9 +2428,11 @@ static int toupperMS(WindowInfo *window,
1696 return True;
1699 -static int tolowerMS(WindowInfo *window, DataValue *argList, int nArgs,
1700 - DataValue *result, char **errMsg)
1701 +static int tolowerMS(RestartData *context, DataValue *argList, int nArgs,
1702 + DataValue *result)
1704 + WindowInfo *window = context->focusWindow;
1705 + char **errMsg = &context->errMsg;
1706 int i, length;
1707 char stringStorage[TYPE_INT_STR_SIZE(int)], *string;
1709 @@ -2418,9 +2451,11 @@ static int tolowerMS(WindowInfo *window,
1710 return True;
1713 -static int stringToClipboardMS(WindowInfo *window, DataValue *argList, int nArgs,
1714 - DataValue *result, char **errMsg)
1715 +static int stringToClipboardMS(RestartData *context, DataValue *argList, int nArgs,
1716 + DataValue *result)
1718 + WindowInfo *window = context->focusWindow;
1719 + char **errMsg = &context->errMsg;
1720 long itemID = 0;
1721 XmString s;
1722 int stat;
1723 @@ -2450,9 +2485,11 @@ static int stringToClipboardMS(WindowInf
1724 return True;
1727 -static int clipboardToStringMS(WindowInfo *window, DataValue *argList, int nArgs,
1728 - DataValue *result, char **errMsg)
1729 +static int clipboardToStringMS(RestartData *context, DataValue *argList, int nArgs,
1730 + DataValue *result)
1732 + WindowInfo *window = context->focusWindow;
1733 + char **errMsg = &context->errMsg;
1734 unsigned long length, retLength;
1735 long id = 0;
1737 @@ -2568,9 +2605,11 @@ static char *convFilePathToAbsolute(cons
1738 ** to a full one, using the current window's directory as a base for relative
1739 ** path specifications. It does not check for file/path validity.
1741 -static int fullFileNameMS(WindowInfo *window, DataValue *argList, int nArgs,
1742 - DataValue *result, char **errMsg)
1743 +static int fullFileNameMS(RestartData *context, DataValue *argList, int nArgs,
1744 + DataValue *result)
1746 + WindowInfo *window = context->focusWindow;
1747 + char **errMsg = &context->errMsg;
1748 char stringStorage[TYPE_INT_STR_SIZE(int)], *name;
1749 size_t len;
1751 @@ -2603,9 +2642,11 @@ static int fullFileNameMS(WindowInfo *wi
1752 ** file as a string in the subroutine return value. On failure, returns
1753 ** the empty string "" and an 0 $readStatus.
1755 -static int readFileMS(WindowInfo *window, DataValue *argList, int nArgs,
1756 - DataValue *result, char **errMsg)
1757 +static int readFileMS(RestartData *context, DataValue *argList, int nArgs,
1758 + DataValue *result)
1760 + WindowInfo *window = context->focusWindow;
1761 + char **errMsg = &context->errMsg;
1762 char stringStorage[TYPE_INT_STR_SIZE(int)], *name;
1763 struct stat statbuf;
1764 FILE *fp;
1765 @@ -2672,15 +2713,19 @@ errorNoClose:
1766 ** to a file named in parameter $2. Returns 1 on successful write, or 0 if
1767 ** unsuccessful.
1769 -static int writeFileMS(WindowInfo *window, DataValue *argList, int nArgs,
1770 - DataValue *result, char **errMsg)
1771 +static int writeFileMS(RestartData *context, DataValue *argList, int nArgs,
1772 + DataValue *result)
1774 + WindowInfo *window = context->focusWindow;
1775 + char **errMsg = &context->errMsg;
1776 return writeOrAppendFile(False, window, argList, nArgs, result, errMsg);
1779 -static int appendFileMS(WindowInfo *window, DataValue *argList, int nArgs,
1780 - DataValue *result, char **errMsg)
1781 +static int appendFileMS(RestartData *context, DataValue *argList, int nArgs,
1782 + DataValue *result)
1784 + WindowInfo *window = context->focusWindow;
1785 + char **errMsg = &context->errMsg;
1786 return writeOrAppendFile(True, window, argList, nArgs, result, errMsg);
1789 @@ -2735,9 +2780,11 @@ static int writeOrAppendFile(int append,
1790 ** Returns the starting position of the match, or -1 if nothing matched.
1791 ** also returns the ending position of the match in $searchEndPos
1793 -static int searchMS(WindowInfo *window, DataValue *argList, int nArgs,
1794 - DataValue *result, char **errMsg)
1795 +static int searchMS(RestartData *context, DataValue *argList, int nArgs,
1796 + DataValue *result)
1798 + WindowInfo *window = context->focusWindow;
1799 + char **errMsg = &context->errMsg;
1800 DataValue newArgList[9];
1802 /* Use the search string routine, by adding the buffer contents as
1803 @@ -2754,7 +2801,7 @@ static int searchMS(WindowInfo *window,
1804 /* copy other arguments to the new argument list */
1805 memcpy(&newArgList[1], argList, nArgs * sizeof(DataValue));
1807 - return searchStringMS(window, newArgList, nArgs+1, result, errMsg);
1808 + return searchStringMS(context, newArgList, nArgs+1, result);
1812 @@ -2768,9 +2815,11 @@ static int searchMS(WindowInfo *window,
1813 ** Returns the starting position of the match, or -1 if nothing matched.
1814 ** also returns the ending position of the match in $searchEndPos
1816 -static int searchStringMS(WindowInfo *window, DataValue *argList, int nArgs,
1817 - DataValue *result, char **errMsg)
1818 +static int searchStringMS(RestartData *context, DataValue *argList, int nArgs,
1819 + DataValue *result)
1821 + WindowInfo *window = context->focusWindow;
1822 + char **errMsg = &context->errMsg;
1823 int beginPos, wrap, direction, found = False, foundStart, foundEnd, type;
1824 int skipSearch = False, len;
1825 char stringStorage[2][TYPE_INT_STR_SIZE(int)], *string, *searchStr;
1826 @@ -2835,9 +2884,11 @@ static int searchStringMS(WindowInfo *wi
1827 ** were performed and "copy" was specified, returns a copy of the original
1828 ** string. Otherwise returns an empty string ("").
1830 -static int replaceInStringMS(WindowInfo *window, DataValue *argList, int nArgs,
1831 - DataValue *result, char **errMsg)
1832 +static int replaceInStringMS(RestartData *context, DataValue *argList, int nArgs,
1833 + DataValue *result)
1835 + WindowInfo *window = context->focusWindow;
1836 + char **errMsg = &context->errMsg;
1837 char stringStorage[3][TYPE_INT_STR_SIZE(int)], *string, *searchStr, *replaceStr;
1838 char *argStr, *replacedStr;
1839 int searchType = SEARCH_LITERAL, copyStart, copyEnd;
1840 @@ -2929,9 +2980,11 @@ static int readSearchArgs(DataValue *arg
1841 return True;
1844 -static int setCursorPosMS(WindowInfo *window, DataValue *argList, int nArgs,
1845 - DataValue *result, char **errMsg)
1846 +static int setCursorPosMS(RestartData *context, DataValue *argList, int nArgs,
1847 + DataValue *result)
1849 + WindowInfo *window = context->focusWindow;
1850 + char **errMsg = &context->errMsg;
1851 int pos;
1853 /* Get argument and convert to int */
1854 @@ -2946,9 +2999,11 @@ static int setCursorPosMS(WindowInfo *wi
1855 return True;
1858 -static int selectMS(WindowInfo *window, DataValue *argList, int nArgs,
1859 - DataValue *result, char **errMsg)
1860 +static int selectMS(RestartData *context, DataValue *argList, int nArgs,
1861 + DataValue *result)
1863 + WindowInfo *window = context->focusWindow;
1864 + char **errMsg = &context->errMsg;
1865 int start, end, startTmp;
1867 /* Get arguments and convert to int */
1868 @@ -2976,9 +3031,11 @@ static int selectMS(WindowInfo *window,
1869 return True;
1872 -static int selectRectangleMS(WindowInfo *window, DataValue *argList, int nArgs,
1873 - DataValue *result, char **errMsg)
1874 +static int selectRectangleMS(RestartData *context, DataValue *argList, int nArgs,
1875 + DataValue *result)
1877 + WindowInfo *window = context->focusWindow;
1878 + char **errMsg = &context->errMsg;
1879 int start, end, left, right;
1881 /* Get arguments and convert to int */
1882 @@ -3002,9 +3059,11 @@ static int selectRectangleMS(WindowInfo
1884 ** Macro subroutine to ring the bell
1886 -static int beepMS(WindowInfo *window, DataValue *argList, int nArgs,
1887 - DataValue *result, char **errMsg)
1888 +static int beepMS(RestartData *context, DataValue *argList, int nArgs,
1889 + DataValue *result)
1891 + WindowInfo *window = context->focusWindow;
1892 + char **errMsg = &context->errMsg;
1893 if (nArgs != 0)
1894 return wrongNArgsErr(errMsg);
1895 XBell(XtDisplay(window->shell), 0);
1896 @@ -3012,9 +3071,11 @@ static int beepMS(WindowInfo *window, Da
1897 return True;
1900 -static int tPrintMS(WindowInfo *window, DataValue *argList, int nArgs,
1901 - DataValue *result, char **errMsg)
1902 +static int tPrintMS(RestartData *context, DataValue *argList, int nArgs,
1903 + DataValue *result)
1905 + WindowInfo *window = context->focusWindow;
1906 + char **errMsg = &context->errMsg;
1907 char stringStorage[TYPE_INT_STR_SIZE(int)], *string;
1908 int i;
1910 @@ -3033,9 +3094,11 @@ static int tPrintMS(WindowInfo *window,
1912 ** Built-in macro subroutine for getting the value of an environment variable
1914 -static int getenvMS(WindowInfo *window, DataValue *argList, int nArgs,
1915 - DataValue *result, char **errMsg)
1916 +static int getenvMS(RestartData *context, DataValue *argList, int nArgs,
1917 + DataValue *result)
1919 + WindowInfo *window = context->focusWindow;
1920 + char **errMsg = &context->errMsg;
1921 char stringStorage[1][TYPE_INT_STR_SIZE(int)];
1922 char *name;
1923 char *value;
1924 @@ -3057,9 +3120,11 @@ static int getenvMS(WindowInfo *window,
1925 return True;
1928 -static int shellCmdMS(WindowInfo *window, DataValue *argList, int nArgs,
1929 - DataValue *result, char **errMsg)
1930 +static int shellCmdMS(RestartData *context, DataValue *argList, int nArgs,
1931 + DataValue *result)
1933 + WindowInfo *window = context->focusWindow;
1934 + char **errMsg = &context->errMsg;
1935 char stringStorage[2][TYPE_INT_STR_SIZE(int)], *cmdString, *inputString = "";
1937 if (nArgs != 1 && nArgs != 2)
1938 @@ -3072,7 +3137,7 @@ static int shellCmdMS(WindowInfo *window
1940 /* Shell command execution requires that the macro be suspended, so
1941 this subroutine can't be run if macro execution can't be interrupted */
1942 - if (MacroRunWindow()->macroCmdData == NULL) {
1943 + if (context->runWindow->macroCmdData == NULL) {
1944 *errMsg = "%s can't be called from non-suspendable context";
1945 return False;
1947 @@ -3109,9 +3174,11 @@ void ReturnShellCommandOutput(WindowInfo
1948 ReturnGlobals[SHELL_CMD_STATUS]->value.val.n = status;
1951 -static int dialogMS(WindowInfo *window, DataValue *argList, int nArgs,
1952 - DataValue *result, char **errMsg)
1953 +static int dialogMS(RestartData *context, DataValue *argList, int nArgs,
1954 + DataValue *result)
1956 + WindowInfo *window = context->focusWindow;
1957 + char **errMsg = &context->errMsg;
1958 macroCmdInfo *cmdData;
1959 char stringStorage[TYPE_INT_STR_SIZE(int)];
1960 char btnStorage[TYPE_INT_STR_SIZE(int)];
1961 @@ -3125,7 +3192,7 @@ static int dialogMS(WindowInfo *window,
1963 /* Ignore the focused window passed as the function argument and put
1964 the dialog up over the window which is executing the macro */
1965 - window = MacroRunWindow();
1966 + window = context->runWindow;
1967 cmdData = window->macroCmdData;
1969 /* Dialogs require macro to be suspended and interleaved with other macros.
1970 @@ -3286,9 +3353,11 @@ static void dialogEscCB(Widget w, XtPoin
1972 #endif /* LESSTIF_VERSION */
1974 -static int stringDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
1975 - DataValue *result, char **errMsg)
1976 +static int stringDialogMS(RestartData *context, DataValue *argList, int nArgs,
1977 + DataValue *result)
1979 + WindowInfo *window = context->focusWindow;
1980 + char **errMsg = &context->errMsg;
1981 macroCmdInfo *cmdData;
1982 char stringStorage[TYPE_INT_STR_SIZE(int)];
1983 char btnStorage[TYPE_INT_STR_SIZE(int)];
1984 @@ -3302,7 +3371,7 @@ static int stringDialogMS(WindowInfo *wi
1986 /* Ignore the focused window passed as the function argument and put
1987 the dialog up over the window which is executing the macro */
1988 - window = MacroRunWindow();
1989 + window = context->runWindow;
1990 cmdData = window->macroCmdData;
1992 /* Dialogs require macro to be suspended and interleaved with other macros.
1993 @@ -3512,9 +3581,11 @@ static void stringDialogEscCB(Widget w,
1994 ** Does this need to go on IgnoredActions? I don't think so, since
1995 ** showing a calltip may be part of the action you want to learn.
1997 -static int calltipMS(WindowInfo *window, DataValue *argList, int nArgs,
1998 - DataValue *result, char **errMsg)
1999 +static int calltipMS(RestartData *context, DataValue *argList, int nArgs,
2000 + DataValue *result)
2002 + WindowInfo *window = context->focusWindow;
2003 + char **errMsg = &context->errMsg;
2004 char stringStorage[TYPE_INT_STR_SIZE(int)], *tipText, *txtArg;
2005 Boolean anchored = False, lookup = True;
2006 int mode = -1, i;
2007 @@ -3605,9 +3676,11 @@ bad_arg:
2009 ** A subroutine to kill the current calltip
2011 -static int killCalltipMS(WindowInfo *window, DataValue *argList, int nArgs,
2012 - DataValue *result, char **errMsg)
2013 +static int killCalltipMS(RestartData *context, DataValue *argList, int nArgs,
2014 + DataValue *result)
2016 + WindowInfo *window = context->focusWindow;
2017 + char **errMsg = &context->errMsg;
2018 int calltipID = 0;
2020 if (nArgs > 1) {
2021 @@ -3628,9 +3701,11 @@ static int killCalltipMS(WindowInfo *win
2023 ** highlight_calltip_line(ctID, line)
2025 -static int highlightCTLineMS(WindowInfo *window, DataValue *argList, int nArgs,
2026 - DataValue *result, char **errMsg)
2027 +static int highlightCTLineMS(RestartData *context, DataValue *argList, int nArgs,
2028 + DataValue *result)
2030 + WindowInfo *window = context->focusWindow;
2031 + char **errMsg = &context->errMsg;
2032 int calltipID = 0;
2033 int line;
2034 int highlightResult;
2035 @@ -3679,9 +3754,11 @@ static int highlightCTLineMS(WindowInfo
2037 * A subroutine to get the ID of the current calltip, or 0 if there is none.
2039 -static int calltipIDMV(WindowInfo *window, DataValue *argList,
2040 - int nArgs, DataValue *result, char **errMsg)
2041 +static int calltipIDMV(RestartData *context, DataValue *argList, int nArgs,
2042 + DataValue *result)
2044 + WindowInfo *window = context->focusWindow;
2045 + char **errMsg = &context->errMsg;
2046 result->tag = INT_TAG;
2047 result->val.n = GetCalltipID(window, 0);
2048 return True;
2049 @@ -3708,9 +3785,11 @@ static int calltipIDMV(WindowInfo *windo
2051 ** Note that defaultName doesn't work on all *tifs. :-(
2053 -static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs,
2054 - DataValue* result, char** errMsg)
2055 +static int filenameDialogMS(RestartData *context, DataValue *argList, int nArgs,
2056 + DataValue *result)
2058 + WindowInfo *window = context->focusWindow;
2059 + char **errMsg = &context->errMsg;
2060 char stringStorage[5][TYPE_INT_STR_SIZE(int)];
2061 char filename[MAXPATHLEN + 1];
2062 char* title = "Choose Filename";
2063 @@ -3724,7 +3803,7 @@ static int filenameDialogMS(WindowInfo*
2065 /* Ignore the focused window passed as the function argument and put
2066 the dialog up over the window which is executing the macro */
2067 - window = MacroRunWindow();
2068 + window = context->runWindow;
2070 /* Dialogs require macro to be suspended and interleaved with other macros.
2071 This subroutine can't be run if macro execution can't be interrupted */
2072 @@ -3811,9 +3890,11 @@ static int filenameDialogMS(WindowInfo*
2074 * call(fnname, arg, ...)
2076 -static int callMS(WindowInfo *window, DataValue *argList,
2077 - int nArgs, DataValue *result, char **errMsg)
2078 +static int callMS(RestartData *context, DataValue *argList, int nArgs,
2079 + DataValue *result)
2081 + WindowInfo *window = context->focusWindow;
2082 + char **errMsg = &context->errMsg;
2083 Symbol *sym;
2085 if (nArgs < 1) {
2086 @@ -3838,15 +3919,17 @@ static int callMS(WindowInfo *window, Da
2087 return False;
2090 - return OverlayRoutineFromSymbol(sym, nArgs, 1);
2091 + return OverlayRoutineFromSymbol(context, sym, nArgs, 1);
2095 * subr = define(func_name, func_body[, "override"])
2097 -static int defineMS(WindowInfo *window, DataValue *argList, int nArgs,
2098 - DataValue *result, char **errMsg)
2099 +static int defineMS(RestartData *context, DataValue *argList, int nArgs,
2100 + DataValue *result)
2102 + WindowInfo *window = context->focusWindow;
2103 + char **errMsg = &context->errMsg;
2104 char stringStorage[3][TYPE_INT_STR_SIZE(int)];
2105 char *name = NULL;
2106 char *body = NULL;
2107 @@ -3940,9 +4023,11 @@ static int defineMS(WindowInfo *window,
2109 * set_window_title(format[, ("text"|"format")])
2111 -static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
2112 - int nArgs, DataValue *result, char **errMsg)
2113 +static int setWindowTitleMS(RestartData *context, DataValue *argList, int nArgs,
2114 + DataValue *result)
2116 + WindowInfo *window = context->focusWindow;
2117 + char **errMsg = &context->errMsg;
2118 char stringStorage[2][TYPE_INT_STR_SIZE(int)];
2119 char *fmt = NULL;
2120 char *type = NULL;
2121 @@ -4064,9 +4149,11 @@ out:
2123 * timer_ID = timer_add(macro_name, timeout[, "global"])
2125 -static int timerAddMS(WindowInfo *window, DataValue *argList, int nArgs,
2126 - DataValue *result, char **errMsg)
2127 +static int timerAddMS(RestartData *context, DataValue *argList, int nArgs,
2128 + DataValue *result)
2130 + WindowInfo *window = context->focusWindow;
2131 + char **errMsg = &context->errMsg;
2132 int timeout;
2133 char stringStorage[2][TYPE_INT_STR_SIZE(int)];
2134 char *name = NULL;
2135 @@ -4132,9 +4219,11 @@ static int timerAddMS(WindowInfo *window
2137 * timer_remove(timer_ID)
2139 -static int timerRemoveMS(WindowInfo *window, DataValue *argList, int nArgs,
2140 - DataValue *result, char **errMsg)
2141 +static int timerRemoveMS(RestartData *context, DataValue *argList, int nArgs,
2142 + DataValue *result)
2144 + WindowInfo *window = context->focusWindow;
2145 + char **errMsg = &context->errMsg;
2146 int timerid;
2147 XtIntervalId id;
2148 TimerProcData *data, **s;
2149 @@ -4175,9 +4264,11 @@ static int timerRemoveMS(WindowInfo *win
2151 * escaped_string = escape_literal(string)
2153 -static int escapeLiteralMS(WindowInfo *window, DataValue *argList, int nArgs,
2154 - DataValue *result, char **errMsg)
2155 +static int escapeLiteralMS(RestartData *context, DataValue *argList, int nArgs,
2156 + DataValue *result)
2158 + WindowInfo *window = context->focusWindow;
2159 + char **errMsg = &context->errMsg;
2160 static const char chars_to_escape[] = "()[]<>{}.\\|^$*+?&";
2161 char stringStorage[TYPE_INT_STR_SIZE(int)];
2162 char *string = NULL;
2163 @@ -4221,9 +4312,11 @@ static int escapeLiteralMS(WindowInfo *w
2166 /* T Balinski */
2167 -static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
2168 - DataValue *result, char **errMsg)
2169 +static int listDialogMS(RestartData *context, DataValue *argList, int nArgs,
2170 + DataValue *result)
2172 + WindowInfo *window = context->focusWindow;
2173 + char **errMsg = &context->errMsg;
2174 macroCmdInfo *cmdData;
2175 char stringStorage[TYPE_INT_STR_SIZE(int)];
2176 char textStorage[TYPE_INT_STR_SIZE(int)];
2177 @@ -4245,7 +4338,7 @@ static int listDialogMS(WindowInfo *wind
2179 /* Ignore the focused window passed as the function argument and put
2180 the dialog up over the window which is executing the macro */
2181 - window = MacroRunWindow();
2182 + window = context->runWindow;
2183 cmdData = window->macroCmdData;
2185 /* Dialogs require macro to be suspended and interleaved with other macros.
2186 @@ -4568,9 +4661,11 @@ static void listDialogEscCB(Widget w, Xt
2187 #endif /* LESSTIF_VERSION */
2190 -static int stringCompareMS(WindowInfo *window, DataValue *argList, int nArgs,
2191 - DataValue *result, char **errMsg)
2192 +static int stringCompareMS(RestartData *context, DataValue *argList, int nArgs,
2193 + DataValue *result)
2195 + WindowInfo *window = context->focusWindow;
2196 + char **errMsg = &context->errMsg;
2197 char stringStorage[3][TYPE_INT_STR_SIZE(int)];
2198 char *leftStr, *rightStr, *argStr;
2199 int considerCase = True;
2200 @@ -4644,9 +4739,11 @@ static int stringCompareMS(WindowInfo *w
2201 ** array sub-scripts (unless "lastnotnull" is present)
2204 -static int splitMS(WindowInfo *window, DataValue *argList, int nArgs,
2205 - DataValue *result, char **errMsg)
2206 +static int splitMS(RestartData *context, DataValue *argList, int nArgs,
2207 + DataValue *result)
2209 + WindowInfo *window = context->focusWindow;
2210 + char **errMsg = &context->errMsg;
2211 char stringStorage[3][TYPE_INT_STR_SIZE(int)];
2212 char *sourceStr, *splitStr, *typeSplitStr;
2213 int searchType, beginPos, foundStart, foundEnd, strLength, lastEnd;
2214 @@ -4835,9 +4932,11 @@ static int splitMS(WindowInfo *window, D
2215 ** end will be one beyond the last valid integer index of a contiguous sequence
2216 ** starting at start.
2218 -static int joinMS(WindowInfo *window, DataValue *argList, int nArgs,
2219 - DataValue *result, char **errMsg)
2220 +static int joinMS(RestartData *context, DataValue *argList, int nArgs,
2221 + DataValue *result)
2223 + WindowInfo *window = context->focusWindow;
2224 + char **errMsg = &context->errMsg;
2225 char stringStorage[TYPE_INT_STR_SIZE(int)];
2226 char *sepStr;
2227 int start, end, index;
2228 @@ -4950,8 +5049,8 @@ static int joinMS(WindowInfo *window, Da
2229 ** will be cleared, turning off backlighting.
2231 /* DISABLED for 5.4
2232 -static int setBacklightStringMS(WindowInfo *window, DataValue *argList,
2233 - int nArgs, DataValue *result, char **errMsg)
2234 +static int setBacklightStringMS(RestartData *context, DataValue *argList,
2235 + int nArgs, DataValue *result)
2237 char *backlightString;
2239 @@ -4977,17 +5076,21 @@ static int setBacklightStringMS(WindowIn
2240 return True;
2241 } */
2243 -static int cursorMV(WindowInfo *window, DataValue *argList, int nArgs,
2244 - DataValue *result, char **errMsg)
2245 +static int cursorMV(RestartData *context, DataValue *argList, int nArgs,
2246 + DataValue *result)
2248 + WindowInfo *window = context->focusWindow;
2249 + char **errMsg = &context->errMsg;
2250 result->tag = INT_TAG;
2251 result->val.n = TextGetCursorPos(window->lastFocus);
2252 return True;
2255 -static int lineMV(WindowInfo *window, DataValue *argList, int nArgs,
2256 - DataValue *result, char **errMsg)
2257 +static int lineMV(RestartData *context, DataValue *argList, int nArgs,
2258 + DataValue *result)
2260 + WindowInfo *window = context->focusWindow;
2261 + char **errMsg = &context->errMsg;
2262 int line, cursorPos, colNum;
2264 result->tag = INT_TAG;
2265 @@ -4998,9 +5101,11 @@ static int lineMV(WindowInfo *window, Da
2266 return True;
2269 -static int columnMV(WindowInfo *window, DataValue *argList, int nArgs,
2270 - DataValue *result, char **errMsg)
2271 +static int columnMV(RestartData *context, DataValue *argList, int nArgs,
2272 + DataValue *result)
2274 + WindowInfo *window = context->focusWindow;
2275 + char **errMsg = &context->errMsg;
2276 textBuffer *buf = window->buffer;
2277 int cursorPos;
2279 @@ -5011,51 +5116,63 @@ static int columnMV(WindowInfo *window,
2280 return True;
2283 -static int fileNameMV(WindowInfo *window, DataValue *argList, int nArgs,
2284 - DataValue *result, char **errMsg)
2285 +static int fileNameMV(RestartData *context, DataValue *argList, int nArgs,
2286 + DataValue *result)
2288 + WindowInfo *window = context->focusWindow;
2289 + char **errMsg = &context->errMsg;
2290 result->tag = STRING_TAG;
2291 AllocNStringCpy(&result->val.str, window->filename);
2292 return True;
2295 -static int filePathMV(WindowInfo *window, DataValue *argList, int nArgs,
2296 - DataValue *result, char **errMsg)
2297 +static int filePathMV(RestartData *context, DataValue *argList, int nArgs,
2298 + DataValue *result)
2300 + WindowInfo *window = context->focusWindow;
2301 + char **errMsg = &context->errMsg;
2302 result->tag = STRING_TAG;
2303 AllocNStringCpy(&result->val.str, window->path);
2304 return True;
2307 -static int lengthMV(WindowInfo *window, DataValue *argList, int nArgs,
2308 - DataValue *result, char **errMsg)
2309 +static int lengthMV(RestartData *context, DataValue *argList, int nArgs,
2310 + DataValue *result)
2312 + WindowInfo *window = context->focusWindow;
2313 + char **errMsg = &context->errMsg;
2314 result->tag = INT_TAG;
2315 result->val.n = window->buffer->length;
2316 return True;
2319 -static int selectionStartMV(WindowInfo *window, DataValue *argList, int nArgs,
2320 - DataValue *result, char **errMsg)
2321 +static int selectionStartMV(RestartData *context, DataValue *argList, int nArgs,
2322 + DataValue *result)
2324 + WindowInfo *window = context->focusWindow;
2325 + char **errMsg = &context->errMsg;
2326 result->tag = INT_TAG;
2327 result->val.n = window->buffer->primary.selected ?
2328 window->buffer->primary.start : -1;
2329 return True;
2332 -static int selectionEndMV(WindowInfo *window, DataValue *argList, int nArgs,
2333 - DataValue *result, char **errMsg)
2334 +static int selectionEndMV(RestartData *context, DataValue *argList, int nArgs,
2335 + DataValue *result)
2337 + WindowInfo *window = context->focusWindow;
2338 + char **errMsg = &context->errMsg;
2339 result->tag = INT_TAG;
2340 result->val.n = window->buffer->primary.selected ?
2341 window->buffer->primary.end : -1;
2342 return True;
2345 -static int selectionLeftMV(WindowInfo *window, DataValue *argList, int nArgs,
2346 - DataValue *result, char **errMsg)
2347 +static int selectionLeftMV(RestartData *context, DataValue *argList, int nArgs,
2348 + DataValue *result)
2350 + WindowInfo *window = context->focusWindow;
2351 + char **errMsg = &context->errMsg;
2352 selection *sel = &window->buffer->primary;
2354 result->tag = INT_TAG;
2355 @@ -5063,9 +5180,11 @@ static int selectionLeftMV(WindowInfo *w
2356 return True;
2359 -static int selectionRightMV(WindowInfo *window, DataValue *argList, int nArgs,
2360 - DataValue *result, char **errMsg)
2361 +static int selectionRightMV(RestartData *context, DataValue *argList, int nArgs,
2362 + DataValue *result)
2364 + WindowInfo *window = context->focusWindow;
2365 + char **errMsg = &context->errMsg;
2366 selection *sel = &window->buffer->primary;
2368 result->tag = INT_TAG;
2369 @@ -5073,9 +5192,11 @@ static int selectionRightMV(WindowInfo *
2370 return True;
2373 -static int wrapMarginMV(WindowInfo *window, DataValue *argList, int nArgs,
2374 - DataValue *result, char **errMsg)
2375 +static int wrapMarginMV(RestartData *context, DataValue *argList, int nArgs,
2376 + DataValue *result)
2378 + WindowInfo *window = context->focusWindow;
2379 + char **errMsg = &context->errMsg;
2380 int margin, nCols;
2382 XtVaGetValues(window->textArea, textNcolumns, &nCols,
2383 @@ -5085,33 +5206,41 @@ static int wrapMarginMV(WindowInfo *wind
2384 return True;
2387 -static int statisticsLineMV(WindowInfo *window, DataValue *argList, int nArgs,
2388 - DataValue *result, char **errMsg)
2389 +static int statisticsLineMV(RestartData *context, DataValue *argList, int nArgs,
2390 + DataValue *result)
2392 + WindowInfo *window = context->focusWindow;
2393 + char **errMsg = &context->errMsg;
2394 result->tag = INT_TAG;
2395 result->val.n = window->showStats ? 1 : 0;
2396 return True;
2399 -static int incSearchLineMV(WindowInfo *window, DataValue *argList, int nArgs,
2400 - DataValue *result, char **errMsg)
2401 +static int incSearchLineMV(RestartData *context, DataValue *argList, int nArgs,
2402 + DataValue *result)
2404 + WindowInfo *window = context->focusWindow;
2405 + char **errMsg = &context->errMsg;
2406 result->tag = INT_TAG;
2407 result->val.n = window->showISearchLine ? 1 : 0;
2408 return True;
2411 -static int showLineNumbersMV(WindowInfo *window, DataValue *argList, int nArgs,
2412 - DataValue *result, char **errMsg)
2413 +static int showLineNumbersMV(RestartData *context, DataValue *argList, int nArgs,
2414 + DataValue *result)
2416 + WindowInfo *window = context->focusWindow;
2417 + char **errMsg = &context->errMsg;
2418 result->tag = INT_TAG;
2419 result->val.n = window->showLineNumbers ? 1 : 0;
2420 return True;
2423 -static int autoIndentMV(WindowInfo *window, DataValue *argList, int nArgs,
2424 - DataValue *result, char **errMsg)
2425 +static int autoIndentMV(RestartData *context, DataValue *argList, int nArgs,
2426 + DataValue *result)
2428 + WindowInfo *window = context->focusWindow;
2429 + char **errMsg = &context->errMsg;
2430 char *res = NULL;
2432 switch (window->indentStyle) {
2433 @@ -5135,9 +5264,11 @@ static int autoIndentMV(WindowInfo *wind
2434 return True;
2437 -static int wrapTextMV(WindowInfo *window, DataValue *argList, int nArgs,
2438 - DataValue *result, char **errMsg)
2439 +static int wrapTextMV(RestartData *context, DataValue *argList, int nArgs,
2440 + DataValue *result)
2442 + WindowInfo *window = context->focusWindow;
2443 + char **errMsg = &context->errMsg;
2444 char *res = NULL;
2446 switch (window->wrapMode) {
2447 @@ -5161,33 +5292,41 @@ static int wrapTextMV(WindowInfo *window
2448 return True;
2451 -static int highlightSyntaxMV(WindowInfo *window, DataValue *argList, int nArgs,
2452 - DataValue *result, char **errMsg)
2453 +static int highlightSyntaxMV(RestartData *context, DataValue *argList, int nArgs,
2454 + DataValue *result)
2456 + WindowInfo *window = context->focusWindow;
2457 + char **errMsg = &context->errMsg;
2458 result->tag = INT_TAG;
2459 result->val.n = window->highlightSyntax ? 1 : 0;
2460 return True;
2463 -static int makeBackupCopyMV(WindowInfo *window, DataValue *argList, int nArgs,
2464 - DataValue *result, char **errMsg)
2465 +static int makeBackupCopyMV(RestartData *context, DataValue *argList, int nArgs,
2466 + DataValue *result)
2468 + WindowInfo *window = context->focusWindow;
2469 + char **errMsg = &context->errMsg;
2470 result->tag = INT_TAG;
2471 result->val.n = window->saveOldVersion ? 1 : 0;
2472 return True;
2475 -static int incBackupMV(WindowInfo *window, DataValue *argList, int nArgs,
2476 - DataValue *result, char **errMsg)
2477 +static int incBackupMV(RestartData *context, DataValue *argList, int nArgs,
2478 + DataValue *result)
2480 + WindowInfo *window = context->focusWindow;
2481 + char **errMsg = &context->errMsg;
2482 result->tag = INT_TAG;
2483 result->val.n = window->autoSave ? 1 : 0;
2484 return True;
2487 -static int showMatchingMV(WindowInfo *window, DataValue *argList, int nArgs,
2488 - DataValue *result, char **errMsg)
2489 +static int showMatchingMV(RestartData *context, DataValue *argList, int nArgs,
2490 + DataValue *result)
2492 + WindowInfo *window = context->focusWindow;
2493 + char **errMsg = &context->errMsg;
2494 char *res = NULL;
2496 switch (window->showMatchingStyle) {
2497 @@ -5211,33 +5350,41 @@ static int showMatchingMV(WindowInfo *wi
2498 return True;
2501 -static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs,
2502 - DataValue *result, char **errMsg)
2503 +static int overTypeModeMV(RestartData *context, DataValue *argList, int nArgs,
2504 + DataValue *result)
2506 + WindowInfo *window = context->focusWindow;
2507 + char **errMsg = &context->errMsg;
2508 result->tag = INT_TAG;
2509 result->val.n = window->overstrike ? 1 : 0;
2510 return True;
2513 -static int readOnlyMV(WindowInfo *window, DataValue *argList, int nArgs,
2514 - DataValue *result, char **errMsg)
2515 +static int readOnlyMV(RestartData *context, DataValue *argList, int nArgs,
2516 + DataValue *result)
2518 + WindowInfo *window = context->focusWindow;
2519 + char **errMsg = &context->errMsg;
2520 result->tag = INT_TAG;
2521 result->val.n = (IS_ANY_LOCKED(window->lockReasons)) ? 1 : 0;
2522 return True;
2525 -static int lockedMV(WindowInfo *window, DataValue *argList, int nArgs,
2526 - DataValue *result, char **errMsg)
2527 +static int lockedMV(RestartData *context, DataValue *argList, int nArgs,
2528 + DataValue *result)
2530 + WindowInfo *window = context->focusWindow;
2531 + char **errMsg = &context->errMsg;
2532 result->tag = INT_TAG;
2533 result->val.n = (IS_USER_LOCKED(window->lockReasons)) ? 1 : 0;
2534 return True;
2537 -static int fileFormatMV(WindowInfo *window, DataValue *argList, int nArgs,
2538 - DataValue *result, char **errMsg)
2539 +static int fileFormatMV(RestartData *context, DataValue *argList, int nArgs,
2540 + DataValue *result)
2542 + WindowInfo *window = context->focusWindow;
2543 + char **errMsg = &context->errMsg;
2544 char *res = NULL;
2546 switch (window->fileFormat) {
2547 @@ -5260,130 +5407,162 @@ static int fileFormatMV(WindowInfo *wind
2548 return True;
2551 -static int fontNameMV(WindowInfo *window, DataValue *argList, int nArgs,
2552 - DataValue *result, char **errMsg)
2553 +static int fontNameMV(RestartData *context, DataValue *argList, int nArgs,
2554 + DataValue *result)
2556 + WindowInfo *window = context->focusWindow;
2557 + char **errMsg = &context->errMsg;
2558 result->tag = STRING_TAG;
2559 AllocNStringCpy(&result->val.str, window->fontName);
2560 return True;
2563 -static int fontNameItalicMV(WindowInfo *window, DataValue *argList, int nArgs,
2564 - DataValue *result, char **errMsg)
2565 +static int fontNameItalicMV(RestartData *context, DataValue *argList, int nArgs,
2566 + DataValue *result)
2568 + WindowInfo *window = context->focusWindow;
2569 + char **errMsg = &context->errMsg;
2570 result->tag = STRING_TAG;
2571 AllocNStringCpy(&result->val.str, window->italicFontName);
2572 return True;
2575 -static int fontNameBoldMV(WindowInfo *window, DataValue *argList, int nArgs,
2576 - DataValue *result, char **errMsg)
2577 +static int fontNameBoldMV(RestartData *context, DataValue *argList, int nArgs,
2578 + DataValue *result)
2580 + WindowInfo *window = context->focusWindow;
2581 + char **errMsg = &context->errMsg;
2582 result->tag = STRING_TAG;
2583 AllocNStringCpy(&result->val.str, window->boldFontName);
2584 return True;
2587 -static int fontNameBoldItalicMV(WindowInfo *window, DataValue *argList, int nArgs,
2588 - DataValue *result, char **errMsg)
2589 +static int fontNameBoldItalicMV(RestartData *context, DataValue *argList, int nArgs,
2590 + DataValue *result)
2592 + WindowInfo *window = context->focusWindow;
2593 + char **errMsg = &context->errMsg;
2594 result->tag = STRING_TAG;
2595 AllocNStringCpy(&result->val.str, window->boldItalicFontName);
2596 return True;
2599 -static int subscriptSepMV(WindowInfo *window, DataValue *argList, int nArgs,
2600 - DataValue *result, char **errMsg)
2601 +static int subscriptSepMV(RestartData *context, DataValue *argList, int nArgs,
2602 + DataValue *result)
2604 + WindowInfo *window = context->focusWindow;
2605 + char **errMsg = &context->errMsg;
2606 result->tag = STRING_TAG;
2607 result->val.str.rep = PERM_ALLOC_STR(ARRAY_DIM_SEP);
2608 result->val.str.len = strlen(result->val.str.rep);
2609 return True;
2612 -static int minFontWidthMV(WindowInfo *window, DataValue *argList, int nArgs,
2613 - DataValue *result, char **errMsg)
2614 +static int minFontWidthMV(RestartData *context, DataValue *argList, int nArgs,
2615 + DataValue *result)
2617 + WindowInfo *window = context->focusWindow;
2618 + char **errMsg = &context->errMsg;
2619 result->tag = INT_TAG;
2620 result->val.n = TextGetMinFontWidth(window->textArea, window->highlightSyntax);
2621 return True;
2624 -static int maxFontWidthMV(WindowInfo *window, DataValue *argList, int nArgs,
2625 - DataValue *result, char **errMsg)
2626 +static int maxFontWidthMV(RestartData *context, DataValue *argList, int nArgs,
2627 + DataValue *result)
2629 + WindowInfo *window = context->focusWindow;
2630 + char **errMsg = &context->errMsg;
2631 result->tag = INT_TAG;
2632 result->val.n = TextGetMaxFontWidth(window->textArea, window->highlightSyntax);
2633 return True;
2636 -static int topLineMV(WindowInfo *window, DataValue *argList, int nArgs,
2637 - DataValue *result, char **errMsg)
2638 +static int topLineMV(RestartData *context, DataValue *argList, int nArgs,
2639 + DataValue *result)
2641 + WindowInfo *window = context->focusWindow;
2642 + char **errMsg = &context->errMsg;
2643 result->tag = INT_TAG;
2644 result->val.n = TextFirstVisibleLine(window->lastFocus);
2645 return True;
2648 -static int numDisplayLinesMV(WindowInfo *window, DataValue *argList, int nArgs,
2649 - DataValue *result, char **errMsg)
2650 +static int numDisplayLinesMV(RestartData *context, DataValue *argList, int nArgs,
2651 + DataValue *result)
2653 + WindowInfo *window = context->focusWindow;
2654 + char **errMsg = &context->errMsg;
2655 result->tag = INT_TAG;
2656 result->val.n = TextNumVisibleLines(window->lastFocus);
2657 return True;
2660 -static int displayWidthMV(WindowInfo *window, DataValue *argList, int nArgs,
2661 - DataValue *result, char **errMsg)
2662 +static int displayWidthMV(RestartData *context, DataValue *argList, int nArgs,
2663 + DataValue *result)
2665 + WindowInfo *window = context->focusWindow;
2666 + char **errMsg = &context->errMsg;
2667 result->tag = INT_TAG;
2668 result->val.n = TextVisibleWidth(window->lastFocus);
2669 return True;
2672 -static int activePaneMV(WindowInfo *window, DataValue *argList, int nArgs,
2673 - DataValue *result, char **errMsg)
2674 +static int activePaneMV(RestartData *context, DataValue *argList, int nArgs,
2675 + DataValue *result)
2677 + WindowInfo *window = context->focusWindow;
2678 + char **errMsg = &context->errMsg;
2679 result->tag = INT_TAG;
2680 result->val.n = WidgetToPaneIndex(window, window->lastFocus) + 1;
2681 return True;
2684 -static int nPanesMV(WindowInfo *window, DataValue *argList, int nArgs,
2685 - DataValue *result, char **errMsg)
2686 +static int nPanesMV(RestartData *context, DataValue *argList, int nArgs,
2687 + DataValue *result)
2689 + WindowInfo *window = context->focusWindow;
2690 + char **errMsg = &context->errMsg;
2691 result->tag = INT_TAG;
2692 result->val.n = window->nPanes + 1;
2693 return True;
2696 -static int emptyArrayMV(WindowInfo *window, DataValue *argList, int nArgs,
2697 - DataValue *result, char **errMsg)
2698 +static int emptyArrayMV(RestartData *context, DataValue *argList, int nArgs,
2699 + DataValue *result)
2701 + WindowInfo *window = context->focusWindow;
2702 + char **errMsg = &context->errMsg;
2703 result->tag = ARRAY_TAG;
2704 result->val.arrayPtr = NULL;
2705 return True;
2708 -static int serverNameMV(WindowInfo *window, DataValue *argList, int nArgs,
2709 - DataValue *result, char **errMsg)
2710 +static int serverNameMV(RestartData *context, DataValue *argList, int nArgs,
2711 + DataValue *result)
2713 + WindowInfo *window = context->focusWindow;
2714 + char **errMsg = &context->errMsg;
2715 result->tag = STRING_TAG;
2716 AllocNStringCpy(&result->val.str, GetPrefServerName());
2717 return True;
2720 -static int tabDistMV(WindowInfo *window, DataValue *argList, int nArgs,
2721 - DataValue *result, char **errMsg)
2722 +static int tabDistMV(RestartData *context, DataValue *argList, int nArgs,
2723 + DataValue *result)
2725 + WindowInfo *window = context->focusWindow;
2726 + char **errMsg = &context->errMsg;
2727 result->tag = INT_TAG;
2728 result->val.n = window->buffer->tabDist;
2729 return True;
2732 -static int emTabDistMV(WindowInfo *window, DataValue *argList, int nArgs,
2733 - DataValue *result, char **errMsg)
2734 +static int emTabDistMV(RestartData *context, DataValue *argList, int nArgs,
2735 + DataValue *result)
2737 + WindowInfo *window = context->focusWindow;
2738 + char **errMsg = &context->errMsg;
2739 int dist;
2741 XtVaGetValues(window->textArea, textNemulateTabs, &dist, NULL);
2742 @@ -5392,25 +5571,31 @@ static int emTabDistMV(WindowInfo *windo
2743 return True;
2746 -static int useTabsMV(WindowInfo *window, DataValue *argList, int nArgs,
2747 - DataValue *result, char **errMsg)
2748 +static int useTabsMV(RestartData *context, DataValue *argList, int nArgs,
2749 + DataValue *result)
2751 + WindowInfo *window = context->focusWindow;
2752 + char **errMsg = &context->errMsg;
2753 result->tag = INT_TAG;
2754 result->val.n = window->buffer->useTabs;
2755 return True;
2758 -static int modifiedMV(WindowInfo *window, DataValue *argList, int nArgs,
2759 - DataValue *result, char **errMsg)
2760 +static int modifiedMV(RestartData *context, DataValue *argList, int nArgs,
2761 + DataValue *result)
2763 + WindowInfo *window = context->focusWindow;
2764 + char **errMsg = &context->errMsg;
2765 result->tag = INT_TAG;
2766 result->val.n = window->fileChanged;
2767 return True;
2770 -static int languageModeMV(WindowInfo *window, DataValue *argList, int nArgs,
2771 - DataValue *result, char **errMsg)
2772 +static int languageModeMV(RestartData *context, DataValue *argList, int nArgs,
2773 + DataValue *result)
2775 + WindowInfo *window = context->focusWindow;
2776 + char **errMsg = &context->errMsg;
2777 char *lmName = LanguageModeName(window->languageMode);
2779 if (lmName == NULL)
2780 @@ -5421,8 +5606,8 @@ static int languageModeMV(WindowInfo *wi
2783 /* DISABLED for 5.4
2784 -static int backlightStringMV(WindowInfo *window, DataValue *argList,
2785 - int nArgs, DataValue *result, char **errMsg)
2786 +static int backlightStringMV(RestartData *context, DataValue *argList,
2787 + int nArgs, DataValue *result)
2789 char *backlightString = window->backlightCharTypes;
2791 @@ -5438,9 +5623,11 @@ static int backlightStringMV(WindowInfo
2793 ** Range set macro variables and functions
2795 -static int rangesetListMV(WindowInfo *window, DataValue *argList, int nArgs,
2796 - DataValue *result, char **errMsg)
2797 +static int rangesetListMV(RestartData *context, DataValue *argList, int nArgs,
2798 + DataValue *result)
2800 + WindowInfo *window = context->focusWindow;
2801 + char **errMsg = &context->errMsg;
2802 RangesetTable *rangesetTable = window->buffer->rangesetTable;
2803 unsigned char *rangesetList;
2804 char *allocIndexStr;
2805 @@ -5484,9 +5671,11 @@ static int rangesetListMV(WindowInfo *wi
2806 ** different point revisions. This is done because the macro interface
2807 ** does not change for the same version.
2809 -static int versionMV(WindowInfo* window, DataValue* argList, int nArgs,
2810 - DataValue* result, char** errMsg)
2811 +static int versionMV(RestartData *context, DataValue *argList, int nArgs,
2812 + DataValue *result)
2814 + WindowInfo *window = context->focusWindow;
2815 + char **errMsg = &context->errMsg;
2816 static unsigned version = NEDIT_VERSION * 1000 + NEDIT_REVISION;
2818 result->tag = INT_TAG;
2819 @@ -5500,9 +5689,11 @@ static int versionMV(WindowInfo* window,
2820 ** default of ~/.nedit or $HOME. (See the online documentation for details
2821 ** about the algorithm.)
2823 -static int neditHomeMV(WindowInfo *window, DataValue *argList, int nArgs,
2824 - DataValue *result, char **errMsg)
2825 +static int neditHomeMV(RestartData *context, DataValue *argList, int nArgs,
2826 + DataValue *result)
2828 + WindowInfo *window = context->focusWindow;
2829 + char **errMsg = &context->errMsg;
2830 const char *neditRCName = GetRCFileName(NEDIT_RC);
2831 char neditHome[MAXPATHLEN];
2833 @@ -5519,9 +5710,11 @@ static int neditHomeMV(WindowInfo *windo
2835 ** Returns the transient status of the current window
2837 -static int transientMV(WindowInfo *window, DataValue *argList, int nArgs,
2838 - DataValue *result, char **errMsg)
2839 +static int transientMV(RestartData *context, DataValue *argList, int nArgs,
2840 + DataValue *result)
2842 + WindowInfo *window = context->focusWindow;
2843 + char **errMsg = &context->errMsg;
2844 result->tag = INT_TAG;
2845 result->val.n = !!window->transient;
2846 return True;
2847 @@ -5535,9 +5728,11 @@ static int transientMV(WindowInfo *windo
2848 ** If called with no arguments, returns a single rangeset label (not an array),
2849 ** or an empty string if there are no rangesets available.
2851 -static int rangesetCreateMS(WindowInfo *window, DataValue *argList, int nArgs,
2852 - DataValue *result, char **errMsg)
2853 +static int rangesetCreateMS(RestartData *context, DataValue *argList, int nArgs,
2854 + DataValue *result)
2856 + WindowInfo *window = context->focusWindow;
2857 + char **errMsg = &context->errMsg;
2858 int label;
2859 int i, nRangesetsRequired;
2860 DataValue element;
2861 @@ -5591,9 +5786,11 @@ static int rangesetCreateMS(WindowInfo *
2863 ** Built-in macro subroutine for forgetting a range set.
2865 -static int rangesetDestroyMS(WindowInfo *window, DataValue *argList, int nArgs,
2866 - DataValue *result, char **errMsg)
2867 +static int rangesetDestroyMS(RestartData *context, DataValue *argList, int nArgs,
2868 + DataValue *result)
2870 + WindowInfo *window = context->focusWindow;
2871 + char **errMsg = &context->errMsg;
2872 RangesetTable *rangesetTable = window->buffer->rangesetTable;
2873 DataValue *array;
2874 DataValue element;
2875 @@ -5654,9 +5851,11 @@ static int rangesetDestroyMS(WindowInfo
2876 ** Arguments are $1: range set name.
2877 ** return value is an array indexed 0 to n, with the rangeset labels as values;
2879 -static int rangesetGetByNameMS(WindowInfo *window, DataValue *argList, int nArgs,
2880 - DataValue *result, char **errMsg)
2881 +static int rangesetGetByNameMS(RestartData *context, DataValue *argList, int nArgs,
2882 + DataValue *result)
2884 + WindowInfo *window = context->focusWindow;
2885 + char **errMsg = &context->errMsg;
2886 char stringStorage[1][TYPE_INT_STR_SIZE(int)];
2887 Rangeset *rangeset;
2888 int label;
2889 @@ -5719,9 +5918,11 @@ static int rangesetGetByNameMS(WindowInf
2890 ** if any to specify range to add - must not be rectangular). Returns the
2891 ** index of the newly added range (cases b and c), or 0 (case a).
2893 -static int rangesetAddMS(WindowInfo *window, DataValue *argList, int nArgs,
2894 - DataValue *result, char **errMsg)
2895 +static int rangesetAddMS(RestartData *context, DataValue *argList, int nArgs,
2896 + DataValue *result)
2898 + WindowInfo *window = context->focusWindow;
2899 + char **errMsg = &context->errMsg;
2900 textBuffer *buffer = window->buffer;
2901 RangesetTable *rangesetTable = buffer->rangesetTable;
2902 Rangeset *targetRangeset, *sourceRangeset;
2903 @@ -5818,9 +6019,11 @@ static int rangesetAddMS(WindowInfo *win
2904 ** to RangesetSubtract()/RangesetSubtractBetween(), the handling of an
2905 ** undefined destination range, and that it returns no value.
2907 -static int rangesetSubtractMS(WindowInfo *window, DataValue *argList, int nArgs,
2908 - DataValue *result, char **errMsg)
2909 +static int rangesetSubtractMS(RestartData *context, DataValue *argList, int nArgs,
2910 + DataValue *result)
2912 + WindowInfo *window = context->focusWindow;
2913 + char **errMsg = &context->errMsg;
2914 textBuffer *buffer = window->buffer;
2915 RangesetTable *rangesetTable = buffer->rangesetTable;
2916 Rangeset *targetRangeset, *sourceRangeset;
2917 @@ -5897,9 +6100,11 @@ static int rangesetSubtractMS(WindowInfo
2918 ** label (one alphabetic character). Returns nothing. Fails if range set
2919 ** undefined.
2921 -static int rangesetInvertMS(WindowInfo *window, DataValue *argList, int nArgs,
2922 - DataValue *result, char **errMsg)
2923 +static int rangesetInvertMS(RestartData *context, DataValue *argList, int nArgs,
2924 + DataValue *result)
2926 + WindowInfo *window = context->focusWindow;
2927 + char **errMsg = &context->errMsg;
2929 RangesetTable *rangesetTable = window->buffer->rangesetTable;
2930 Rangeset *rangeset;
2931 @@ -5937,9 +6142,11 @@ static int rangesetInvertMS(WindowInfo *
2932 ** argument of a rangeset label. Returns an array with the following keys:
2933 ** defined, count, color, mode.
2935 -static int rangesetInfoMS(WindowInfo *window, DataValue *argList, int nArgs,
2936 - DataValue *result, char **errMsg)
2937 +static int rangesetInfoMS(RestartData *context, DataValue *argList, int nArgs,
2938 + DataValue *result)
2940 + WindowInfo *window = context->focusWindow;
2941 + char **errMsg = &context->errMsg;
2942 RangesetTable *rangesetTable = window->buffer->rangesetTable;
2943 Rangeset *rangeset = NULL;
2944 int count, defined, uline;
2945 @@ -6012,9 +6219,11 @@ static int rangesetInfoMS(WindowInfo *wi
2946 ** ranges, otherwise select the individual range specified. Returns
2947 ** an array with the keys "start" and "end" and values
2949 -static int rangesetRangeMS(WindowInfo *window, DataValue *argList, int nArgs,
2950 - DataValue *result, char **errMsg)
2951 +static int rangesetRangeMS(RestartData *context, DataValue *argList, int nArgs,
2952 + DataValue *result)
2954 + WindowInfo *window = context->focusWindow;
2955 + char **errMsg = &context->errMsg;
2956 textBuffer *buffer = window->buffer;
2957 RangesetTable *rangesetTable = buffer->rangesetTable;
2958 Rangeset *rangeset;
2959 @@ -6078,9 +6287,11 @@ static int rangesetRangeMS(WindowInfo *w
2960 ** false (zero) if not in a range, range index (1-based) if in a range;
2961 ** fails if parameters were bad.
2963 -static int rangesetIncludesPosMS(WindowInfo *window, DataValue *argList,
2964 - int nArgs, DataValue *result, char **errMsg)
2965 +static int rangesetIncludesPosMS(RestartData *context, DataValue *argList,
2966 + int nArgs, DataValue *result)
2968 + WindowInfo *window = context->focusWindow;
2969 + char **errMsg = &context->errMsg;
2970 textBuffer *buffer = window->buffer;
2971 RangesetTable *rangesetTable = buffer->rangesetTable;
2972 Rangeset *rangeset;
2973 @@ -6132,9 +6343,11 @@ static int rangesetIncludesPosMS(WindowI
2974 ** found/applied. If no color is applied, any current color is removed. Returns
2975 ** true if the rangeset is valid.
2977 -static int rangesetSetColorMS(WindowInfo *window, DataValue *argList,
2978 - int nArgs, DataValue *result, char **errMsg)
2979 +static int rangesetSetColorMS(RestartData *context, DataValue *argList,
2980 + int nArgs, DataValue *result)
2982 + WindowInfo *window = context->focusWindow;
2983 + char **errMsg = &context->errMsg;
2984 char stringStorage[1][TYPE_INT_STR_SIZE(int)];
2985 textBuffer *buffer = window->buffer;
2986 RangesetTable *rangesetTable = buffer->rangesetTable;
2987 @@ -6180,9 +6393,11 @@ static int rangesetSetColorMS(WindowInfo
2988 ** the underlineMode string, which should be specified as "leave" (let any
2989 ** syntax highlighting underlines to appear as undisturbed), "add" or "remove".
2991 -static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList,
2992 - int nArgs, DataValue *result, char **errMsg)
2993 +static int rangesetSetUnderlineMS(RestartData *context, DataValue *argList,
2994 + int nArgs, DataValue *result)
2996 + WindowInfo *window = context->focusWindow;
2997 + char **errMsg = &context->errMsg;
2998 char stringStorage[1][TYPE_INT_STR_SIZE(int)];
2999 textBuffer *buffer = window->buffer;
3000 RangesetTable *rangesetTable = buffer->rangesetTable;
3001 @@ -6232,9 +6447,11 @@ static int rangesetSetUnderlineMS(Window
3002 ** Set the name of a range set's ranges. Returns
3003 ** true if the rangeset is valid.
3005 -static int rangesetSetNameMS(WindowInfo *window, DataValue *argList,
3006 - int nArgs, DataValue *result, char **errMsg)
3007 +static int rangesetSetNameMS(RestartData *context, DataValue *argList,
3008 + int nArgs, DataValue *result)
3010 + WindowInfo *window = context->focusWindow;
3011 + char **errMsg = &context->errMsg;
3012 char stringStorage[1][TYPE_INT_STR_SIZE(int)];
3013 textBuffer *buffer = window->buffer;
3014 RangesetTable *rangesetTable = buffer->rangesetTable;
3015 @@ -6278,9 +6495,11 @@ static int rangesetSetNameMS(WindowInfo
3016 ** Change a range's modification response. Returns true if the rangeset is
3017 ** valid and the response type name is valid.
3019 -static int rangesetSetModeMS(WindowInfo *window, DataValue *argList,
3020 - int nArgs, DataValue *result, char **errMsg)
3021 +static int rangesetSetModeMS(RestartData *context, DataValue *argList,
3022 + int nArgs, DataValue *result)
3024 + WindowInfo *window = context->focusWindow;
3025 + char **errMsg = &context->errMsg;
3026 char stringStorage[1][TYPE_INT_STR_SIZE(int)];
3027 textBuffer *buffer = window->buffer;
3028 RangesetTable *rangesetTable = buffer->rangesetTable;
3029 @@ -6462,9 +6681,11 @@ static int fillStyleResult(DataValue *re
3030 ** ["italic"] '1' if style is italic, '0' otherwise
3033 -static int getStyleByNameMS(WindowInfo *window, DataValue *argList, int nArgs,
3034 - DataValue *result, char **errMsg)
3035 +static int getStyleByNameMS(RestartData *context, DataValue *argList, int nArgs,
3036 + DataValue *result)
3038 + WindowInfo *window = context->focusWindow;
3039 + char **errMsg = &context->errMsg;
3040 char stringStorage[1][TYPE_INT_STR_SIZE(int)];
3041 char *styleName;
3043 @@ -6502,9 +6723,11 @@ static int getStyleByNameMS(WindowInfo *
3044 ** ["extent"] Forward distance from position over which style applies
3047 -static int getStyleAtPosMS(WindowInfo *window, DataValue *argList, int nArgs,
3048 - DataValue *result, char **errMsg)
3049 +static int getStyleAtPosMS(RestartData *context, DataValue *argList, int nArgs,
3050 + DataValue *result)
3052 + WindowInfo *window = context->focusWindow;
3053 + char **errMsg = &context->errMsg;
3054 int patCode;
3055 int bufferPos;
3056 textBuffer *buf = window->buffer;
3057 @@ -6607,9 +6830,11 @@ static int fillPatternResult(DataValue *
3058 ** The returned array looks like this:
3059 ** ["style"] Name of style
3061 -static int getPatternByNameMS(WindowInfo *window, DataValue *argList, int nArgs,
3062 - DataValue *result, char **errMsg)
3063 +static int getPatternByNameMS(RestartData *context, DataValue *argList, int nArgs,
3064 + DataValue *result)
3066 + WindowInfo *window = context->focusWindow;
3067 + char **errMsg = &context->errMsg;
3068 char stringStorage[1][TYPE_INT_STR_SIZE(int)];
3069 char *patternName = NULL;
3070 highlightPattern *pattern;
3071 @@ -6645,9 +6870,11 @@ static int getPatternByNameMS(WindowInfo
3072 ** ["style"] Name of style
3073 ** ["extent"] Distance from position over which this pattern applies
3075 -static int getPatternAtPosMS(WindowInfo *window, DataValue *argList, int nArgs,
3076 - DataValue *result, char **errMsg)
3077 +static int getPatternAtPosMS(RestartData *context, DataValue *argList, int nArgs,
3078 + DataValue *result)
3080 + WindowInfo *window = context->focusWindow;
3081 + char **errMsg = &context->errMsg;
3082 int bufferPos = -1;
3083 textBuffer *buffer = window->buffer;
3084 int patCode = 0;
3085 @@ -6703,9 +6930,11 @@ static int getPatternAtPosMS(WindowInfo
3086 ** of "pos" holds "-1", "len" holds "0" and "direction" holds "-1".
3089 -static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
3090 - DataValue *result, char **errMsg)
3091 +static int getMatchingMS(RestartData *context, DataValue *argList, int nArgs,
3092 + DataValue *result)
3094 + WindowInfo *window = context->focusWindow;
3095 + char **errMsg = &context->errMsg;
3096 int startPos;
3097 int matchPos, matchLen;
3098 int direction;
3099 @@ -6780,9 +7009,11 @@ static int getMatchingMS(WindowInfo *win
3100 /* Insert a string into the acutal dictionary */
3101 /* Syntax : dictinsert(string) % assuming weight = 1 */
3102 /* dictinsert(string, weight) */
3103 -static int dictinsertMS(WindowInfo *window, DataValue *argList, int nArgs,
3104 - DataValue *result, char **errMsg)
3105 +static int dictinsertMS(RestartData *context, DataValue *argList, int nArgs,
3106 + DataValue *result)
3108 + WindowInfo *window = context->focusWindow;
3109 + char **errMsg = &context->errMsg;
3110 static long nr_insertions = 0;
3111 int weight = 1;
3113 @@ -6830,9 +7061,11 @@ static int dictinsertMS(WindowInfo *wind
3114 /* Test if string is an element of the acutal dictionary */
3115 /* Syntax : weight = dictiselement(string) */
3116 /* Output argument : (integer) weight of element */
3117 -static int dictiselementMS(WindowInfo *window, DataValue *argList, int nArgs,
3118 - DataValue *result, char **errMsg)
3119 +static int dictiselementMS(RestartData *context, DataValue *argList, int nArgs,
3120 + DataValue *result)
3122 + WindowInfo *window = context->focusWindow;
3123 + char **errMsg = &context->errMsg;
3124 char stringStorage[25], *string;
3125 unsigned long weight;
3127 @@ -6862,9 +7095,11 @@ static int dictiselementMS(WindowInfo *w
3129 /* Load/append file to current dictionary */
3130 /* Syntax : dict_append(filename) */
3131 -static int dictappendMS(WindowInfo *window, DataValue *argList, int nArgs,
3132 - DataValue *result, char **errMsg)
3133 +static int dictappendMS(RestartData *context, DataValue *argList, int nArgs,
3134 + DataValue *result)
3136 + WindowInfo *window = context->focusWindow;
3137 + char **errMsg = &context->errMsg;
3138 char stringStorage[25], *string;
3140 /* Validate arguments and convert to int */
3141 @@ -6887,9 +7122,11 @@ static int dictappendMS(WindowInfo *wind
3142 /* dict_save(filename) => set dictionary filename (otherwise default filename is used) */
3143 /* dict_save("") => return current filename as string */
3144 /* dict_save(autoSave, cumulSave) => autoSave = "on"/"off"/"flush", cumulSave=0,1,2,3,... */
3145 -static int dictsaveMS(WindowInfo *window, DataValue *argList, int nArgs,
3146 - DataValue *result, char **errMsg)
3147 +static int dictsaveMS(RestartData *context, DataValue *argList, int nArgs,
3148 + DataValue *result)
3150 + WindowInfo *window = context->focusWindow;
3151 + char **errMsg = &context->errMsg;
3152 int cumulSave = 0;
3154 char stringStorage[25], *string;
3155 @@ -6957,9 +7194,11 @@ static int dictsaveMS(WindowInfo *window
3157 #define MAXMATCHES 128
3159 -static int dictcompleteMS(WindowInfo *window, DataValue *argList, int nArgs,
3160 - DataValue *result, char **errMsg)
3161 +static int dictcompleteMS(RestartData *context, DataValue *argList, int nArgs,
3162 + DataValue *result)
3164 + WindowInfo *window = context->focusWindow;
3165 + char **errMsg = &context->errMsg;
3166 int minchars = 0;
3167 int maxmatches = 1;
3168 static char *s2[MAXMATCHES]; /* at max, 128 possible completions can be returned */
3169 @@ -7028,9 +7267,11 @@ static int dictcompleteMS(WindowInfo *wi
3170 ** UL convertPos patch:
3171 ** translate given line / column parameter to text buffer position.
3173 -static int toPosMS(WindowInfo *window, DataValue *argList, int nArgs,
3174 - DataValue *result, char **errMsg)
3175 +static int toPosMS(RestartData *context, DataValue *argList, int nArgs,
3176 + DataValue *result)
3178 + WindowInfo *window = context->focusWindow;
3179 + char **errMsg = &context->errMsg;
3180 char *lineStr, stringStorage1[TYPE_INT_STR_SIZE(int)];
3181 char *colStr , stringStorage2[TYPE_INT_STR_SIZE(int)];
3182 char *lineColString;
3183 @@ -7129,9 +7370,11 @@ static int toPosMS(WindowInfo *window, D
3184 ** UL convertPos patch:
3185 ** translate given text buffer position to line number.
3187 -static int toLineMS(WindowInfo *window, DataValue *argList, int nArgs,
3188 - DataValue *result, char **errMsg)
3189 +static int toLineMS(RestartData *context, DataValue *argList, int nArgs,
3190 + DataValue *result)
3192 + WindowInfo *window = context->focusWindow;
3193 + char **errMsg = &context->errMsg;
3194 int line, column;
3195 int pos;
3197 @@ -7174,9 +7417,11 @@ static int toLineMS(WindowInfo *window,
3198 ** UL convertPos patch:
3199 ** translate given text buffer position to column number.
3201 -static int toColumnMS(WindowInfo *window, DataValue *argList, int nArgs,
3202 - DataValue *result, char **errMsg)
3203 +static int toColumnMS(RestartData *context, DataValue *argList, int nArgs,
3204 + DataValue *result)
3206 + WindowInfo *window = context->focusWindow;
3207 + char **errMsg = &context->errMsg;
3208 int line, column;
3209 int pos;
3210 textBuffer *buf = window->buffer;
3211 diff --quilt old/source/macro.h new/source/macro.h
3212 --- old/source/macro.h
3213 +++ new/source/macro.h
3214 @@ -37,7 +37,7 @@
3216 typedef struct BuiltInSubrNameTag {
3217 const char *name; /* its macro identifier */
3218 - BuiltInSubr macroSubr; /* pointer to the function to call */
3219 + BuiltInSubr *macroSubr; /* pointer to the function to call */
3220 } BuiltInSubrName;
3222 /* Structure used to build an initialized static array, each entry describing a