1 /*****************************************************************************
2
3 PshMac()
4
5 This function is called when TECO needs to execute a macro. It saves
6 several variables which define the "current" command string environment on
7 the macro stack. It then defines the environment for the macro command
8 string, so that the macro command can be executed when this function exits.
9 The PopMac function reverses the effects of this function, redefining the
10 "current" command string environment.
11
12 *****************************************************************************/
13
14 #include "zport.h" /* define portability identifiers */
15 #include "tecoc.h" /* define general identifiers */
16 #include "defext.h" /* define external global variables */
17 #include "deferr.h" /* define identifiers for error messages */
18
PshMac(Start,End)19 DEFAULT PshMac(Start, End) /* push environment for a macro call */
20 charptr Start; /* start of new command string */
21 charptr End; /* end of new command string, plus one */
22 {
23 MSptr MSp; /* pointer into the macro stack */
24 BOOLEAN NumArg; /* TRUE if there is a number on the stack */
25
26 DBGFEN(1,"PshMac",NULL);
27
28 if (++MStTop >= MCS_SIZE) { /* if macro stack is full */
29 ErrMsg(ERR_PDO); /* push-down list overflow */
30 DBGFEX(1,DbgFNm,"FAILURE, macro stack is full");
31 return FAILURE;
32 }
33
34 NumArg = (EStTop != EStBot) && /* if numeric arg and */
35 (EStack[EStTop].ElType == OPERAND); /* not a partial expression */
36 if (NumArg) { /* if numeric argument */
37 if (GetNmA() == FAILURE) { /* get the numeric argument */
38 DBGFEX(1,DbgFNm,"FAILURE, GetNmA() failed");
39 return FAILURE;
40 }
41 }
42
43 /*
44 * save current environment
45 */
46
47 MSp = &MStack[MStTop];
48 MSp->CStBeg = CStBeg; /* save command string beginning */
49 MSp->CBfPtr = CBfPtr; /* save command string pointer */
50 MSp->CStEnd = CStEnd; /* save command string end */
51 MSp->EStBot = EStBot; /* save expression stack bottom */
52 MSp->EStTop = EStTop; /* save expression stack top */
53 MSp->LStBot = LStBot; /* save loop stack bottom */
54 MSp->LStTop = LStTop; /* save loop stack top */
55 MSp->QRgstr = NULL; /* no local q-reg table (yet) */
56
57 /*
58 * setup new environment
59 */
60
61 CStBeg = CBfPtr = Start; /* set up the new command string */
62 CStEnd = End - 1; /* set up the new command string */
63 EStBot = EStTop; /* set new expression stack bottom */
64 LStBot = LStTop; /* set new loop stack bottom */
65
66 if (NumArg) { /* if we had a numeric argument */
67 if (PushEx(NArgmt, OPERAND) == FAILURE) {
68 DBGFEX(1,DbgFNm,"FAILURE");
69 return FAILURE;
70 }
71 }
72 DBGFEX(1,DbgFNm,"SUCCESS");
73 return SUCCESS;
74 }
75