1 /*****************************************************************************
2 
3 	ExeS()
4 
5 	This function executes an S command.
6 
7 	nStext$		Local search
8 	m,nStext$	Search for nth occurrance within m chars
9 	::Stext$	Compare string
10 
11 *****************************************************************************/
12 
13 #include "zport.h"		/* define portability identifiers */
14 #include "tecoc.h"		/* define general identifiers */
15 #include "defext.h"		/* define external global variables */
16 #include "dchars.h"		/* define identifiers for characters */
17 #include "deferr.h"		/* define identifiers for error messages */
18 
ExeS()19 DEFAULT ExeS()			/* execute an S command */
20 {
21 	DBGFEN(1, "ExeS", NULL);
22 
23 /*
24  * The command m,nS is illegal: the user should use m,nFB
25  */
26 	if (CmdMod & MARGIS) {			/* if it's m,nS */
27 		ErrStr(ERR_ILL, "m,nS");	/* illegal command "m,nS" */
28 		DBGFEX(1,DbgFNm,"FAILURE");
29 		return FAILURE;
30 	}
31 
32 /*
33  * If it's ::Stext$,  it's a compare,  not a search.  The text argument is
34  * compared to the characters immediately following the character pointer.
35  * It returns -1 if the strings match, else 0.  A ::Stext$ command is
36  * equivalent to a .,.+1:FBtext$ command,  so that's the way it's implemented.
37  */
38 
39 	if (CmdMod & DCOLON) {			/* if it's ::S */
40 		if (CmdMod & MARGIS) {		/* if it's m,n::S */
41 			ErrStr(ERR_ILL, "m,n::S");
42 			DBGFEX(1,DbgFNm,"FAILURE");
43 			return FAILURE;
44 		}
45 		if (EStTop > EStBot) {		/* if it's n::S */
46 			ErrStr(ERR_ILL, "n::S");
47 			DBGFEX(1,DbgFNm,"FAILURE");
48 			return FAILURE;
49 		}
50 		if (GapEnd == EBfEnd) {		/* if nothing to search */
51 			if (FindES(ESCAPE) == FAILURE) {
52 				DBGFEX(1,DbgFNm,"FAILURE");
53 				return FAILURE;
54 			}
55 			DBGFEX(1,DbgFNm,"PushEx(0)");
56 			return PushEx(0L,OPERAND);
57 		}
58 		CmdMod &= ~DCOLON;		/* clear double-colon bit */
59 		CmdMod |= COLON;		/* set colon bit */
60 		CmdMod |= MARGIS;		/* set m defined bit */
61 		MArgmt = GapBeg - EBfBeg;	/* set m */
62 		if (PushEx((LONG)((GapBeg-EBfBeg)+1),OPERAND) == FAILURE) {
63 			DBGFEX(1,DbgFNm,"FAILURE");
64 			return FAILURE;
65 		}
66 		DBGFEX(1,DbgFNm,"ExeFB()");
67 		return ExeFB();			/* execute FB command */
68 	}
69 
70 	SrcTyp = S_SEARCH;
71 
72 	if (Search(FALSE) == FAILURE) {
73 		DBGFEX(1,DbgFNm,"FAILURE");
74 		return FAILURE;
75 	}
76 
77 	CmdMod = '\0';				/* clear modifiers flags */
78 
79 	DBGFEX(1,DbgFNm,"SUCCESS");
80 	return SUCCESS;
81 }
82