1 /*****************************************************************************
2
3 ExeM()
4
5 This function executes an M command.
6 Mq Execute string in Q-register q
7
8 *****************************************************************************/
9
10 #include "zport.h" /* define portability identifiers */
11 #include "tecoc.h" /* define general identifiers */
12 #include "defext.h" /* define external global variables */
13 #include "deferr.h" /* define identifiers for error messages */
14
ExeM()15 DEFAULT ExeM() /* execute an M command */
16 {
17 DEFAULT status;
18 BOOLEAN islocal;
19
20 DBGFEN(1,"ExeM",NULL);
21
22 if (IncCBP() == FAILURE) { /* if no character after M */
23 DBGFEX(1,DbgFNm,"FAILURE, no Q-register specified");
24 return FAILURE;
25 }
26
27 islocal = (*CBfPtr=='.'); /* TAA Addition */
28
29 if (FindQR() == FAILURE) { /* find q-register */
30 DBGFEX(1,DbgFNm,"FAILURE, FindQR() failed");
31 return FAILURE;
32 }
33
34 if (QR->Start == NULL) { /* if q-register is empty */
35 DBGFEX(1,DbgFNm,"SUCCESS, Q-register is empty");
36 return SUCCESS;
37 }
38
39 /*
40 * Save the current execution state and make the text in the Q-register be
41 * the command string to execute.
42 */
43
44 if (PshMac(QR->Start, QR->End_P1) == FAILURE) {
45 DBGFEX(1,DbgFNm,"FAILURE, PshMac() failed");
46 return FAILURE;
47 }
48
49 /*
50 * If the M command is not colon-modified, create a new set of local
51 * q-registers and zero them out.
52 */
53 if ((CmdMod & COLON) == 0&&!islocal) { /* if not colon-modified */
54 QRptr QRp;
55 WORD i;
56 QRp = (QRptr)ZAlloc(36 * sizeof(struct QReg));
57 if (QRp == NULL) {
58 ErrMsg(ERR_MEM);
59 DBGFEX(3,DbgFNm,"FAILURE");
60 return FAILURE;
61 }
62 MStack[MStTop].QRgstr = QRp;
63 for (i = 0; i < 36; ++i, ++QRp) {
64 QRp->Start = QRp->End_P1 = NULL;
65 QRp->Number = 0;
66 }
67 }
68 else CmdMod &= ~COLON; /* clear colon flag TAA Mod */
69
70 /*
71 * execute command string in Q-register
72 */
73 status = ExeCSt();
74 #if DEBUGGING
75 if (status == FAILURE) {
76 DbgFMs(1,DbgFNm,"ExeCSt() failed");
77 }
78 #endif
79
80 /*
81 * restore old execution state
82 */
83
84 if (PopMac() == FAILURE) {
85 DBGFEX(1,DbgFNm,"FAILURE, PopMac() failed");
86 return FAILURE;
87 }
88
89 DBGFEX(1,DbgFNm,(status == FAILURE) ? "FAILURE" : "SUCCESS");
90 return status;
91 }
92