forked from RealDeuce/OpenDoors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathODGraph.c
More file actions
247 lines (207 loc) · 7.72 KB
/
Copy pathODGraph.c
File metadata and controls
247 lines (207 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/* OpenDoors Online Software Programming Toolkit
* (C) Copyright 1991 - 1999 by Brian Pirie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* File: ODGraph.c
*
* Description: Implements special ANSI/AVATAR control functions.
*
* Revisions: Date Ver Who Change
* ---------------------------------------------------------------
* Oct 13, 1994 6.00 BP New file header format.
* Dec 09, 1994 6.00 BP Standardized coding style.
* Aug 19, 1995 6.00 BP 32-bit portability.
* Nov 11, 1995 6.00 BP Removed register keyword.
* Nov 14, 1995 6.00 BP Added include of odscrn.h.
* Nov 16, 1995 6.00 BP Removed oddoor.h, added odcore.h.
* Nov 16, 1995 6.00 BP Moved local vars here from odcore.c.
* Dec 12, 1995 6.00 BP Added entry, exit and kernel macros.
* Dec 30, 1995 6.00 BP Added ODCALL for calling convention.
* Feb 19, 1996 6.00 BP Changed version number to 6.00.
* Mar 03, 1996 6.10 BP Begin version 6.10.
* Mar 13, 1996 6.10 BP Added od_get_cursor().
* Aug 10, 2003 6.23 SH *nix support
*/
#define BUILDING_OPENDOORS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "OpenDoor.h"
#include "ODCore.h"
#include "ODGen.h"
#include "ODScrn.h"
#include "ODKrnl.h"
/* Local private variables. */
static char szANSIClearLine[3] = {27, '[', 'K'};
static char szAvatarClearLine[2] = {22, 7};
/* ----------------------------------------------------------------------------
* od_clr_line()
*
* Clears the contents of the current line, from the current cursor position
* to the end of the line. This function affects both local and remote
* screens.
*
* Parameters: None.
*
* Return: void
*/
ODAPIDEF void ODCALL od_clr_line(void)
{
char *pchLine;
INT nCharsLeft;
INT nCount;
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_clr_line()");
/* Ensure that OpenDoors has been initialized. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Obtain the current cursor position. */
ODScrnGetTextInfo(&ODTextInfo);
/* Calculate the number of columns that are to be erased. */
nCharsLeft = 80 - ODTextInfo.curx;
/* If either ANSI or AVATAR mode is available, then we first */
/* clear the line on the local screen without affecting the */
/* remote screen. */
if(od_control.user_avatar || od_control.user_ansi)
{
pchLine = (char *)szODWorkString;
for(nCount = 0; nCount <= nCharsLeft; ++nCount) *pchLine++ = ' ';
*pchLine = '\0';
ODScrnEnableScrolling(0);
ODScrnDisplayString(szODWorkString);
ODScrnEnableScrolling(1);
ODScrnSetCursorPos(ODTextInfo.curx, ODTextInfo.cury);
}
/* If AVATAR mode is active. */
if(od_control.user_avatar)
{
/* Transmit the two-character AVATAR clear to end of line sequence. */
od_disp(szAvatarClearLine, 2, FALSE);
}
/* If ANSI mode is active. */
else if(od_control.user_ansi)
{
/* Transmit the three-character ANSI clear to end of line sequence. */
od_disp(szANSIClearLine, 3, FALSE);
}
/* If we are operating in plain-ASCII mode. */
else
{
/* Generate a sequence of space characters followed by backspace */
/* characters. */
pchLine = (char *)szODWorkString;
for(nCount = 0; nCount < nCharsLeft; ++nCount) *pchLine++ = ' ';
for(nCount = 0; nCount < nCharsLeft; ++nCount) *pchLine++ = 8;
*pchLine='\0';
/* Send this sequence to both the local and remote screens. */
od_disp(szODWorkString, strlen(szODWorkString), TRUE);
}
OD_API_EXIT();
}
/* ----------------------------------------------------------------------------
* od_set_cursor()
*
* Moves the position of the cursor on both local and remote screens. This
* function is available in all display modes other than plain-ASCII.
*
* Parameters: nRow - 1-based index of the row to position the cursor in.
*
* nColumn - Index of the column to position the cursor in.
*
* Return: void
*/
ODAPIDEF void ODCALL od_set_cursor(INT nRow, INT nColumn)
{
static char szControlSequence[40];
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_set_cursor()");
/* Ensure that OpenDoors has been initialized. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Check validity of parameters. */
if(nRow < 1 || nColumn < 1)
{
od_control.od_error = ERR_PARAMETER;
return;
}
/* If AVATAR mode is on. */
if(od_control.user_avatar)
{
/* Position the local cursor. */
ODScrnSetCursorPos((BYTE)nColumn, (BYTE)nRow);
/* Generate the AVATAR control sequence to position the remote cursor. */
szControlSequence[0] = 22;
szControlSequence[1] = 8;
szControlSequence[2] = nRow;
szControlSequence[3] = nColumn;
/* Transmit the AVATAR control sequence to the remote terminal. */
od_disp(szControlSequence, 4, FALSE);
}
/* If ANSI mode is on. */
else if(od_control.user_ansi)
{
/* Generate the ANSI control sequence to position the remote cursor. */
sprintf(szControlSequence, "x[%d;%dH", nRow, nColumn);
szControlSequence[0] = 27;
/* Transmit the ANSI control seequence to the remote terminal. */
od_disp(szControlSequence, strlen(szControlSequence), FALSE);
/* Position the cursor on the local screen. */
ODScrnSetCursorPos((BYTE)nColumn, (BYTE)nRow);
}
else
{
/* If neither ANSI nor AVATAR modes are available, indicate this */
/* in the error code in od_control. */
od_control.od_error = ERR_NOGRAPHICS;
}
OD_API_EXIT();
}
/* ----------------------------------------------------------------------------
* od_get_cursor()
*
* Returns our best estimate of the current position of the cursor on the
* remote screen.
*
* Parameters: pnRow - 1-based index of the row to position the cursor in.
*
* pnColumn - Index of the column to position the cursor in.
*
* Return: void
*/
ODAPIDEF void ODCALL od_get_cursor(INT *pnRow, INT *pnColumn)
{
tODScrnTextInfo TextInfo;
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_get_cursor()");
/* Ensure that OpenDoors has been initialized. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Check for parameter validity. */
if(pnRow == NULL && pnColumn == NULL)
{
od_control.od_error = ERR_PARAMETER;
OD_API_EXIT();
return;
}
/* Obtain current state of local screen. */
ODScrnGetTextInfo(&TextInfo);
/* Set the caller's parameters to the current row and column, if each */
/* of these parameters were supplied. */
if(pnRow != NULL) *pnRow = (INT)TextInfo.cury;
if(pnColumn != NULL) *pnColumn = (INT)TextInfo.curx;
OD_API_EXIT();
}