1 /*****************************************************************************
2 
3 	ExeBSl()
4 
5 	This function executes a \ (backslash) command.
6 	\	Value of digit string in buffer
7 	n\	Convert n to digits in buffer
8 
9 	The backslash command allows the user to convert binary numbers
10 to/from their ASCII representations.  If a numeric argument precedes the
11 backslash command,  then the ASCII representation for the number is inserted
12 into the edit buffer at the current point.  If there is no preceding numeric
13 argument, then the number in it's ASCII representation in the edit buffer is
14 converted to binary,  and is returned by the backslash command.  In either
15 case,  TECO's current radix controls how the numbers are represented.  If
16 the current radix is decimal,  then a plus or minus sign can precede an
17 ASCII number being read,  and a minus sign will be generated if necessary
18 for a number being generated.  When converting a string that's in the edit
19 buffer,  the character pointer is left at the end of the string in the buffer.
20 
21 *****************************************************************************/
22 
23 #include "zport.h"		/* define portability identifiers */
24 #include "tecoc.h"		/* define general identifiers */
25 #include "defext.h"		/* define external global variables */
26 #include "chmacs.h"		/* define character processing macros */
27 
ExeBSl()28 DEFAULT ExeBSl()		/* execute a \ (backslash) command */
29 {
30     DBGFEN(1,"ExeBSl",NULL);
31 
32 /*
33  * Handle the case where there's no numeric argument:  convert the digit
34  * string in the edit buffer into a binary value and push it onto the
35  * expression stack.
36  */
37     if ((EStTop == EStBot) ||			/* if no numeric arg or */
38 	(EStack[EStTop].ElType != OPERAND)) {	/* partial expression */
39 	LONG StrVal = 0;
40 	RefLen=0;
41 	if (GapEnd != EBfEnd) {			/* if not at end of buffer */
42 	    BOOLEAN negative = FALSE;
43 	    char NxtChr;
44 
45 	    if (*(GapEnd+1) == '-') {		/* minus sign? */
46 		RefLen--;
47 		GapEnd++;			/* move forward... */
48 		*GapBeg++ = *GapEnd;		/* ... one character */
49 		negative = TRUE;
50 	    } else if (*(GapEnd+1) == '+') {	/* plus sign? */
51 		RefLen--;
52 		GapEnd++;			/* move forward... */
53 		*GapBeg++ = *GapEnd;		/* ... one character */
54 	    }
55 
56 	    while ((GapEnd != EBfEnd) && (IsRadx(*(GapEnd+1)))) {
57 		RefLen--;
58 		GapEnd++;			/* move forward... */
59 		*GapBeg++ = *GapEnd;		/* ... one character */
60 		NxtChr = *GapEnd;
61 		if (Is_Digit(NxtChr))
62 		    NxtChr -= '0';
63 		else if (Is_Upper(NxtChr))
64 		    NxtChr -= '\67';
65 		else
66 		    NxtChr -= '\127';
67 		StrVal = (StrVal * Radix) + NxtChr;
68 	    }
69 	    if (negative)
70 		StrVal = -StrVal;
71 	}
72 	CmdMod = '\0';				/* clear modifiers flags */
73 
74 #if DEBUGGING
75 	sprintf(DbgSBf,"PushEx(%ld)", StrVal);
76 	DbgFEx(1,DbgFNm,DbgSBf);
77 #endif
78 	return PushEx(StrVal,OPERAND);
79     }
80 
81 /*
82  * If we made it to here,  then there is a numeric argument
83  */
84 
85     if (GetNmA() == FAILURE) {			/* get numeric argument */
86 	DBGFEX(1,DbgFNm,"FAILURE");
87 	return FAILURE;
88     }
89 
90     MakDBf(NArgmt, Radix);			/* convert it to ASCII */
91     if (InsStr(DBfBeg, DBfPtr-DBfBeg) == FAILURE) {
92 	DBGFEX(1,DbgFNm,"FAILURE");
93 	return FAILURE;
94     }
95 
96     CmdMod = '\0';				/* clear modifiers flags */
97     EStTop = EStBot;				/* clear expression stack */
98 
99     DBGFEX(1,DbgFNm,"SUCCESS");
100     return SUCCESS;
101 }
102