ReactOS 0.4.15-dev-8241-g63935f8
tnmain.cpp File Reference
#include "precomp.h"
#include "tnmain.h"
Include dependency graph for tnmain.cpp:

Go to the source code of this file.

Classes

struct  command
 

Macros

#define MAX_PARM_COUNT   3
 
#define MAX_TOKEN_COUNT   (MAX_PARM_COUNT+2)
 
#define HISTLENGTH   25
 

Enumerations

enum  {
  BAD_USAGE = -3 , EMPTY_LINE = -2 , INVALID_CMD = -1 , __FIRST_COMMAND = 0 ,
  OPEN = __FIRST_COMMAND , CLOSE , KEYS , QUIT ,
  HELP , HELP2 , K_LOAD , K_SWITCH ,
  K_DISPLAY , SET , SUSPEND , FASTQUIT ,
  CMD_HISTORY , CLEAR_HISTORY , ALIASES , __COMMAND_LIST_SIZE
}
 

Functions

int telCommandLine (Telnet &MyConnection)
 
void waitforkey ()
 
struct cmdHistorycfgets (char *buf, unsigned int length, struct cmdHistory *cmdhist)
 
int main (int ArgC, char *ArgV[])
 
static int cmdMatch (const char *cmd, const char *token, int tokenLen, int minM)
 
static void printUsage (int cmd)
 
int tokenizeCommand (char *szCommand, int &argc, char **argv)
 

Variables

command cmdList [__COMMAND_LIST_SIZE]
 

Macro Definition Documentation

◆ HISTLENGTH

#define HISTLENGTH   25

◆ MAX_PARM_COUNT

#define MAX_PARM_COUNT   3

Definition at line 463 of file tnmain.cpp.

◆ MAX_TOKEN_COUNT

#define MAX_TOKEN_COUNT   (MAX_PARM_COUNT+2)

Definition at line 464 of file tnmain.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
BAD_USAGE 
EMPTY_LINE 
INVALID_CMD 
__FIRST_COMMAND 
OPEN 
CLOSE 
KEYS 
QUIT 
HELP 
HELP2 
K_LOAD 
K_SWITCH 
K_DISPLAY 
SET 
SUSPEND 
FASTQUIT 
CMD_HISTORY 
CLEAR_HISTORY 
ALIASES 
__COMMAND_LIST_SIZE 

Definition at line 396 of file tnmain.cpp.

396 {
397 BAD_USAGE = -3,
398 EMPTY_LINE = -2,
399 INVALID_CMD = -1,
400 __FIRST_COMMAND = 0,
401
403 CLOSE,
404 KEYS,
405 QUIT,
406 HELP,
407 HELP2, // there is way for synonims
408 K_LOAD, // subcommand of 'keys'
409 K_SWITCH, // subcommand of 'keys'
410 K_DISPLAY, // subcommand of 'keys'
411
412 SET, // Paul Brannan 5/30/98
413
414 SUSPEND,
415 FASTQUIT, // Thomas Briggs 8/11/98
416 CMD_HISTORY, // crn@ozemail.com.au
417 CLEAR_HISTORY, // crn@ozemail.com.au
418
419 ALIASES, // Paul Brannan 1/1/99
420
421 __COMMAND_LIST_SIZE // must be last
422};
@ OPEN
Definition: tnmain.cpp:402
@ K_DISPLAY
Definition: tnmain.cpp:410
@ BAD_USAGE
Definition: tnmain.cpp:397
@ EMPTY_LINE
Definition: tnmain.cpp:398
@ SUSPEND
Definition: tnmain.cpp:414
@ FASTQUIT
Definition: tnmain.cpp:415
@ ALIASES
Definition: tnmain.cpp:419
@ CLOSE
Definition: tnmain.cpp:403
@ __COMMAND_LIST_SIZE
Definition: tnmain.cpp:421
@ QUIT
Definition: tnmain.cpp:405
@ CLEAR_HISTORY
Definition: tnmain.cpp:417
@ __FIRST_COMMAND
Definition: tnmain.cpp:400
@ INVALID_CMD
Definition: tnmain.cpp:399
@ HELP
Definition: tnmain.cpp:406
@ KEYS
Definition: tnmain.cpp:404
@ SET
Definition: tnmain.cpp:412
@ HELP2
Definition: tnmain.cpp:407
@ K_SWITCH
Definition: tnmain.cpp:409
@ K_LOAD
Definition: tnmain.cpp:408
@ CMD_HISTORY
Definition: tnmain.cpp:416

Function Documentation

◆ cfgets()

struct cmdHistory * cfgets ( char buf,
unsigned int  length,
struct cmdHistory cmdhist 
)

Definition at line 69 of file tnmain.cpp.

69 {
70
72 unsigned int current=0, cursor =0, iEraseLength=0, i;
73 char chr;
74 char temp[2];
75 char temp1[80];
76
77 INPUT_RECORD InputRecord;
78 BOOL done = FALSE;
79
80 temp[1] = 0;
81 buf[0] = '\0';
82
83 if(!ini.get_input_redir()) {
84 while (!done) {
85 DWORD dwInput;
86 int MustRefresh = 0;
87 WaitForSingleObject( hConsole, INFINITE );
88 if (!ReadConsoleInput(hConsole, &InputRecord, 1, &dwInput)){
89 done = TRUE;
90 continue;
91 }
92 MustRefresh = 0;
93 if (InputRecord.EventType == KEY_EVENT &&
94 InputRecord.Event.KeyEvent.bKeyDown ) {
95
96 if(InputRecord.Event.KeyEvent.dwControlKeyState &
98
99 switch(InputRecord.Event.KeyEvent.wVirtualKeyCode) {
100 case 'D': // Thomas Briggs 8/11/98
101 buf[0] = '\04';
102 buf[1] = '\0';
103 current = 1;
104 done = true;
105 continue;
106 case 'U': // Paul Brannan 8/11/98
107 buf[0] = '\0';
108 current = 0;
109 cursor = 0;
110 MustRefresh = 1;
111 break;
112 }
113 }
114
115 switch (InputRecord.Event.KeyEvent.wVirtualKeyCode) {
116 case VK_UP:
117 // crn@ozemail.com.au
118 if (cmdhist != NULL) {
119 if (!strcmp(buf, ""))
120 strncpy(buf, cmdhist->cmd, 79);
121 else if (cmdhist->prev != NULL) {
122 cmdhist = cmdhist->prev;
123 strncpy(buf, cmdhist->cmd, 79);
124 }
125 current = strlen(buf);
126 }
128 MustRefresh = 1;
129 break;
130 case VK_DOWN:
131 // crn@ozemail.com.au
132 if (cmdhist != NULL) {
133 if (cmdhist->next != NULL) {
134 cmdhist = cmdhist->next;
135 strncpy(buf, cmdhist->cmd, 79);
136 } else {
137 strncpy(buf, "", 79);
138 }
139 current = strlen(buf);
140 }
142 MustRefresh = 1;
143 break;
144 case VK_RIGHT: //crn@ozemail.com.au (added ctrl+arrow)
145 if (cursor < current) {
146 if (InputRecord.Event.KeyEvent.dwControlKeyState &
148 unsigned int j, k;
149 for (j = cursor; j <= current; j++)
150 {
151 if (buf[j + 1] == ' ' || (j + 1) == current)
152 break;
153 for (k = ++j; k <= current; k++)
154 {
155 if (buf[k] != ' ' || k == current) {
156 cursor = k == current ? --k : k;
157 break;
158 }
159 }
160 }
161 } else
162 cursor++;
163 MustRefresh = 1;
164 break;
165 }
166 case VK_LEFT: //crn@ozemail.com.au (added ctrl+arrow)
167 if (cursor > 0) {
168 if(InputRecord.Event.KeyEvent.dwControlKeyState &
170 int j, k;
171 for (j = cursor; j >= 0; j--)
172 {
173 if (buf[j - 1] != ' ')
174 break;
175 for (k = --j; k >= 0; k--)
176 {
177 if (buf[k] == ' ' || k == 0) {
178 cursor = !k ? k : ++k;
179 break;
180 }
181 }
182 }
183 } else
184 cursor--;
185 MustRefresh = 1;
186 break;
187 }
188 case VK_HOME:
189 if (cursor>0) cursor = 0;
190 MustRefresh = 1;
191 break;
192 case VK_END:
194 MustRefresh = 1;
195 break;
196 case VK_DELETE:
197 if (current > 0 && current > cursor) {
198 strcpy(&buf[cursor],&buf[cursor+1]);
199 current--;
200 buf[current] = 0;
201 printit("\r");
202 for (i = 0; i < current+strlen("telnet>")+1 ;i++)
203 printit(" ");
204 }
205 MustRefresh = 1;
206 break;
207 case VK_BACK:
208 if (cursor > 0 ) {
209 strcpy(&buf[cursor-1],&buf[cursor]);
210 current--;
211 cursor--;
212 buf[current] = 0;
213 printit("\r");
214 for (i = 0; i < current+strlen("telnet>")+1 ;i++)
215 printit(" ");
216 }
217 MustRefresh = 1;
218 break;
219
220 default:
221 chr = InputRecord.Event.KeyEvent.uChar.AsciiChar;
222 if (chr == '\r') {
223 done = TRUE;
224 continue;
225 }
226 if (current >= length-1){
227 done = TRUE;
228 continue;
229 }
230 if ( isprint (chr) ){
231 strncpy(temp1,&buf[cursor],79);
232 strncpy(&buf[cursor+1],temp1,79-(cursor+1));
233 buf[cursor++]=chr;
234 current++;
235 buf[current] = 0;
236 MustRefresh = 1;
237 }
238 break;
239 }
240 if (MustRefresh == 1)
241 {
242 printit("\rtelnet");
243 for (i = 0; i <= iEraseLength ;i++)
244 printit(" ");
245 printit("\rtelnet>");
246 printit(buf);
247 iEraseLength = strlen(buf);
248 for (i = 0; i < current-cursor; i++)
249 printit("\b");
250 }
251 }
252 }
253 buf[current] = 0;
254 if (strcmp(buf, "")) {
255 if (cmdhist == NULL) {
256 cmdhist = new struct cmdHistory;
257 if (cmdhist == NULL) {
258 printit ("\nUnable to allocate memory for history buffer -- use the \"flush\" command to clear the buffer.\n");
259 return cmdhist;
260 }
261 strncpy(cmdhist->cmd, buf, 79);
262 cmdhist->next = NULL;
263 cmdhist->prev = NULL;
264 } else {
265 while (cmdhist->next != NULL) // move to the end of the list
266 cmdhist = cmdhist->next;
267 cmdhist->next = new struct cmdHistory;
268 if (cmdhist->next == NULL) {
269 printit ("\nUnable to allocate memory for history buffer -- use the \"flush\" command to clear the buffer.\n");
270 return cmdhist;
271 }
272 cmdhist->next->prev = cmdhist; // previous is where we are now
273 cmdhist = cmdhist->next;
274 strncpy(cmdhist->cmd, buf, 79);
275 cmdhist->next = NULL;
276 }
277 while (cmdhist->next)
278 cmdhist = cmdhist->next;
279 }
280 return cmdhist;
282 } else {
283 WaitForSingleObject( hConsole, INFINITE );
284 DWORD dwInput;
285 DWORD OldMode;
286 GetConsoleMode(hConsole, &OldMode);
287 SetConsoleMode(hConsole,
288 OldMode &~ (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT) );
289 while (ReadFile(hConsole, &chr, 1, &dwInput, NULL)) {
290 if (chr == '\r') {
291 temp[0] = chr;
292 printit(&temp[0]);
293 break;
294 }
295 if (chr == '\b' && current > 0) {
296 current--;
297 printit("\b \b");
298 }
299 if (current >= length-1){
300 break;
301 }
302 if ( isprint (chr) ){
303 temp[0] = chr;
304 printit(&temp[0]);
305 buf[current++]=chr;
306 }
307 }
308 buf[current] = 0;
309 SetConsoleMode(hConsole, OldMode);
310 return NULL;
311 }
312}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define isprint(c)
Definition: acclib.h:73
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
int get_input_redir() const
Definition: tnconfig.h:42
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1569
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1606
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
const char cursor[]
Definition: icontest.c:13
struct task_struct * current
Definition: linux.c:32
int k
Definition: mpi.c:3369
static calc_node_t temp
Definition: rpn_ieee.c:38
union _INPUT_RECORD::@3303 Event
WORD EventType
Definition: wincon.h:273
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:275
DWORD dwControlKeyState
Definition: wincon.h:248
WORD wVirtualKeyCode
Definition: wincon.h:242
union _KEY_EVENT_RECORD::@3302 uChar
char cmd[80]
Definition: tnmain.h:14
struct cmdHistory * next
Definition: tnmain.h:15
struct cmdHistory * prev
Definition: tnmain.h:16
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
TConfig ini
Definition: tnconfig.cpp:45
int printit(const char *it)
Definition: tnerror.cpp:58
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define ReadConsoleInput
Definition: wincon.h:778
#define ENABLE_ECHO_INPUT
Definition: wincon.h:80
#define KEY_EVENT
Definition: wincon.h:128
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
#define ENABLE_LINE_INPUT
Definition: wincon.h:79
#define VK_UP
Definition: winuser.h:2225
#define VK_END
Definition: winuser.h:2222
#define VK_HOME
Definition: winuser.h:2223
#define VK_BACK
Definition: winuser.h:2198
#define VK_LEFT
Definition: winuser.h:2224
#define VK_RIGHT
Definition: winuser.h:2226
#define VK_DOWN
Definition: winuser.h:2227
#define VK_DELETE
Definition: winuser.h:2233

Referenced by telCommandLine().

◆ cmdMatch()

static int cmdMatch ( const char cmd,
const char token,
int  tokenLen,
int  minM 
)
static

Definition at line 466 of file tnmain.cpp.

466 {
467 if ( tokenLen < minM ) return 0;
468 // The (unsigned) gets rid of a compiler warning (Paul Brannan 5/25/98)
469 if ( (unsigned)tokenLen > strlen(cmd) ) return 0;
470 if ( strcmp(cmd,token) == 0 ) return 1;
471
472 int i;
473 for ( i = 0; i < minM; i++ ) if ( cmd[i] != token[i] ) return 0;
474
475 for ( i = minM; i < tokenLen; i++ ) if ( cmd[i] != token[i] ) return 0;
476
477 return 1;
478};
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
Definition: ftp_var.h:139

Referenced by tokenizeCommand().

◆ main()

int main ( int  ArgC,
char ArgV[] 
)

Definition at line 317 of file tnmain.cpp.

317 {
318
319 CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo;
322 &ConsoleScreenBufferInfo
323 );
324
325 char *k;
326 char startdir[MAX_PATH*2];
327 char exename[MAX_PATH];
328
329 // strncpy(startdir, ArgV[0],MAX_PATH);
330 // This should be more accurate than using argv[0] (Paul Brannan 9/16/98)
331 GetModuleFileName(NULL, startdir, sizeof(startdir));
332
333 // Get the current console title so it can be set later
334 // ("Pedro A. Aranda Gutiérrez" <paag@coppi.tid.es>)
335 TCHAR ConsoleTitle[255];
336 GetConsoleTitle(ConsoleTitle, sizeof(ConsoleTitle));
337
338 k = strrchr(startdir, '\\');
339 if (k == NULL){ // if the \ character is not found...
340 strcpy(exename, startdir);
341 strcpy(startdir,""); // set the path to nothing
342 } else {
343 // end the string after the last '\' to get rid of the file name
344 strcpy(exename, k+1);
345 k[1] = 0;
346 }
347
350
351 // set up the ini class
352 ini.init(startdir, exename);
353
354 // Process the command line arguments and connect to a host if necessary
355 if(ini.Process_Params(ArgC, ArgV)) {
356 const char *szHost = ini.get_host();
357 const char *strPort = ini.get_port();
358 if(!*szHost) {
359 Telnet MyConnection;
360 while(telCommandLine(MyConnection));
361 } else {
362 Telnet MyConnection;
363 if(MyConnection.Open(szHost, strPort) == TNPROMPT) {
364 // still connected
365 printit("\n");
366 telCommandLine(MyConnection);
367 }
368 }
369 }
371
372 if(ini.get_term_width() != -1 || ini.get_term_height() != -1) {
374 GetStdHandle(STD_OUTPUT_HANDLE), // handle of console screen buffer
375 ConsoleScreenBufferInfo.dwSize // new size in character rows and cols.
376 );
378 GetStdHandle(STD_OUTPUT_HANDLE), // handle of console screen buffer
379 TRUE, // coordinate type flag
380 &ConsoleScreenBufferInfo.srWindow // address of new window rectangle
381 );
382 }
384 GetStdHandle(STD_OUTPUT_HANDLE), // handle of console screen buffer
385 ConsoleScreenBufferInfo.wAttributes // text and background colors
386 );
387
388 // Restore the original console title
389 // ("Pedro A. Aranda Gutiérrez" <paag@coppi.tid.es>)
390 SetConsoleTitle(ConsoleTitle);
391
392 return 0;
393}
#define MSG_COPYRIGHT_1
Definition: resource.h:4
#define MSG_COPYRIGHT
Definition: resource.h:3
BOOL WINAPI SetConsoleTextAttribute(IN HANDLE hConsoleOutput, IN WORD wAttributes)
Definition: console.c:672
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
int get_term_height() const
Definition: tnconfig.h:57
bool Process_Params(int argc, char *argv[])
Definition: tnconfig.cpp:619
int get_term_width() const
Definition: tnconfig.h:56
void init(char *dirname, char *exename)
Definition: tnconfig.cpp:282
const char * get_host() const
Definition: tnconfig.h:102
const char * get_port() const
Definition: tnconfig.h:103
Definition: tnclass.h:16
int Open(const char *szHost, const char *strPort="23")
Definition: tnclass.cpp:160
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI SetConsoleWindowInfo(HANDLE hConsoleOutput, BOOL bAbsolute, CONST SMALL_RECT *lpConsoleWindow)
Definition: console.c:1970
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize)
Definition: console.c:1855
static char * exename
Definition: process.c:101
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
@ TNPROMPT
Definition: tncon.h:16
int printm(LPTSTR szModule, BOOL fSystem, DWORD dwMessageId,...)
Definition: tnerror.cpp:84
int telCommandLine(Telnet &MyConnection)
Definition: tnmain.cpp:567
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define GetModuleFileName
Definition: winbase.h:3831
#define SetConsoleTitle
Definition: wincon.h:783
#define GetConsoleTitle
Definition: wincon.h:775
char TCHAR
Definition: xmlstorage.h:189

◆ printUsage()

static void printUsage ( int  cmd)
static

Definition at line 480 of file tnmain.cpp.

480 {
481 if ( cmdList[cmd].usage != NULL ) {
483 return;
484 };
485 if ( cmdList[cmd].isSubCmd >= 0 ) {
486 printUsage(cmdList[cmd].isSubCmd);
487 return;
488 }
490};
#define MSG_BADUSAGE
Definition: resource.h:27
void printUsage()
Definition: main.cpp:782
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
command cmdList[__COMMAND_LIST_SIZE]
Definition: tnmain.cpp:435

◆ telCommandLine()

int telCommandLine ( Telnet MyConnection)

Definition at line 567 of file tnmain.cpp.

567 {
568#define HISTLENGTH 25
569 int i, retval;
570 char* Parms[MAX_PARM_COUNT];
571 char szCommand[80];
572 int bDone = 0;
573 char *extitle, *newtitle;
574 struct cmdHistory *cmdhist;
575 cmdhist = NULL;
576
577 // printit("\n"); // crn@ozemail.com.au 14/12/98
578 while (!bDone){
579 // printit("\n"); // Paul Brannan 5/25/98
580 printit( "telnet>");
581 cmdhist = cfgets (szCommand, 79, cmdhist);
582 printit( "\n");
583
584 strlwr(szCommand); // convert command line to lower
585 // i = sscanf(szCommand,"%80s %80s %80s %80s", szCmd, szArg1, szArg2, szArg3);
586 switch ( tokenizeCommand(szCommand, i, Parms) ) {
587 case BAD_USAGE: break;
588 case EMPTY_LINE:
589 if(MyConnection.Resume() == TNPROMPT) {
590 printit("\n");
591 break;
592 }
593 else
594 return 1;
595 case INVALID_CMD:
597 break;
598 case OPEN:
599 if (i == 1)
600 retval = MyConnection.Open(Parms[0], "23");
601 else
602 retval = MyConnection.Open(Parms[0], Parms[1]);
603 if(retval != TNNOCON && retval != TNPROMPT) return 1;
604 if(retval == TNPROMPT) printit("\n");
605 break;
606 case CLOSE:
607 MyConnection.Close();
608 break;
609 case FASTQUIT: // Thomas Briggs 8/11/98
610 case QUIT:
611 MyConnection.Close();
612 bDone = 1;
613 break;
614 case HELP:
615 case HELP2:
616 printm(0, FALSE, MSG_HELP);
618 break;
619 // case KEYS: we should never get it
620 case K_LOAD:
621 if ( i == 1 ) {
622 // Ioannou : changed to ini.get_keyfile()
623 if(MyConnection.LoadKeyMap( ini.get_keyfile(), Parms[0]) != 1)
624 printit("Error loading keymap.\n");
625 break;
626 };
627 if(MyConnection.LoadKeyMap( Parms[1], Parms[0]) != 1)
628 printit("Error loading keymap.\n");
629 break;
630 case K_DISPLAY:
631 MyConnection.DisplayKeyMap();
632 break;
633 case K_SWITCH:
634 MyConnection.SwitchKeyMap(atoi(Parms[0]));
635 break;
636
637 // Paul Brannan 5/30/98
638 case SET:
639 if(i == 0) {
640 printit("Available groups:\n"); // Print out groups
641 ini.print_groups(); // (Paul Brannan 9/3/98)
642 } else if(i == 1) {
643 ini.print_vars(Parms[0]);
644 } else if(i >= 2) {
645 ini.set_value(Parms[0], Parms[1]);
646 // FIX ME !!! Ioannou: here we must call the parser routine for
647 // wrap line, not the ini.set_value
648 // something like Parser.ConLineWrap(Wrap_Line);
649 }
650 break;
651
652 case SUSPEND: // Thomas Briggs 8/11/98
653
654 // remind the user we're suspended -crn@ozemail.com.au 15/12/98
655 extitle = new char[128];
656 GetConsoleTitle (extitle, 128);
657
658 newtitle = new char[128+sizeof("[suspended]")];
659 strcpy(newtitle, extitle);
660 strncat(newtitle, "[suspended]", 128+sizeof("[suspended]"));
661 if(ini.get_set_title()) SetConsoleTitle (newtitle);
662 delete[] newtitle;
663
664 if (getenv("comspec") == NULL) {
665 switch (GetWin32Version()) {
666 case 2: // 'cmd' is faster than 'command' in NT -crn@ozemail.com.au
667 system ("cmd");
668 break;
669 default:
670 system ("command");
671 break;
672 }
673 } else {
674 system(getenv("comspec"));
675 }
676
677 if(ini.get_set_title()) SetConsoleTitle (extitle);
678 delete[] extitle;
680
681 break;
682
683 case CMD_HISTORY: //crn@ozemail.com.au
684 if (cmdhist != NULL) {
685 while (cmdhist->prev != NULL)
686 cmdhist = cmdhist->prev; //rewind
687 printf ("Command history:\n");
688 while (1) {
689 printf ("\t%s\n", cmdhist->cmd);
690
691 if (cmdhist->next != NULL)
692 cmdhist = cmdhist->next;
693 else
694 break;
695 }
696 } else
697 printf ("No command history available.\n");
698
699 break;
700
701 case CLEAR_HISTORY: //crn@ozemail.com.au
702 if (cmdhist != NULL) {
703 while (cmdhist->next != NULL)
704 cmdhist = cmdhist->next; //fast forward
705 while (cmdhist->prev != NULL) {
706 cmdhist = cmdhist->prev;
707 delete cmdhist->next;
708 }
709 delete cmdhist;
710 cmdhist = NULL;
711 printf ("Command history cleared.\n");
712 } else
713 printf ("No command history available.\n");
714
715 case ALIASES: // Paul Brannan 1/1/99
717 break;
718
719 default: // paranoik
721 break;
722 }
723
724 }
725
726 return 0;
727}
char * strncat(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:605
#define MSG_HELP_1
Definition: resource.h:8
#define MSG_HELP
Definition: resource.h:7
#define MSG_INVCMD
Definition: resource.h:9
void print_groups()
Definition: tnconfig.cpp:426
bool set_value(const char *var, const char *value)
Definition: tnconfig.cpp:442
bool get_set_title() const
Definition: tnconfig.h:55
void print_vars()
Definition: tnconfig.cpp:383
const char * get_keyfile() const
Definition: tnconfig.h:34
void print_aliases()
Definition: tnconfig.cpp:366
int SwitchKeyMap(int)
Definition: tnclass.cpp:149
int Resume()
Definition: tnclass.cpp:259
int Close()
Definition: tnclass.cpp:226
int LoadKeyMap(const char *file, const char *name)
Definition: tnclass.cpp:139
void DisplayKeyMap()
Definition: tnclass.cpp:145
#define printf
Definition: freeldr.h:97
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
int __cdecl system(_In_opt_z_ const char *_Command)
_CRTIMP char *__cdecl strlwr(_Inout_z_ char *_Str)
@ TNNOCON
Definition: tncon.h:15
int tokenizeCommand(char *szCommand, int &argc, char **argv)
Definition: tnmain.cpp:492
#define MAX_PARM_COUNT
Definition: tnmain.cpp:463
struct cmdHistory * cfgets(char *buf, unsigned int length, struct cmdHistory *cmdhist)
Definition: tnmain.cpp:69
int GetWin32Version(void)
Definition: tnmisc.cpp:98

Referenced by main().

◆ tokenizeCommand()

int tokenizeCommand ( char szCommand,
int argc,
char **  argv 
)

Definition at line 492 of file tnmain.cpp.

492 {
493 char* tokens[MAX_TOKEN_COUNT];
494 char* p;
495 int args = 0;
496
497 if(!szCommand || !*szCommand) return EMPTY_LINE;
498
499 // Removed strtok to handle tokens with spaces; this is handled with
500 // quotes. (Paul Brannan 3/18/99)
501 char *token_start = szCommand;
502 for(p = szCommand;; p++) {
503 if(*p == '\"') {
504 char *tmp = p;
505 for(p++; *p != '\"' && *p != 0; p++); // Find the next quote
506 if(*p != 0) strcpy(p, p + 1); // Remove quote#2
507 strcpy(tmp, tmp + 1); // Remove quote#1
508 }
509 if(*p == 0 || *p == ' ' || *p == '\t') {
510 tokens[args] = token_start;
511 args++;
512 if(args >= MAX_TOKEN_COUNT) break; // Break if too many args
513 token_start = p + 1;
514 if(*p == 0) break;
515 *p = 0;
516 }
517 }
518 // while ( (p = strtok((args?NULL:szCommand), " \t")) != NULL && args < MAX_TOKEN_COUNT ) {
519 // tokens[args] = p;
520 // args++;
521 // };
522
523 if ( !args ) return EMPTY_LINE;
524 argc = args - 1;
525 args = 0;
526 int curCmd = -1;
527 int ok = -1;
528 while ( ok < 0 ) {
529 int tokenLen = strlen(tokens[args]);
530 int match = 0;
531 for ( int i = 0; i<__COMMAND_LIST_SIZE; i++ ) {
532 if ( cmdMatch(cmdList[i].cmd, tokens[args], tokenLen, cmdList[i].minLen) ) {
533 if (argc < cmdList[i].minParms || argc > cmdList[i].maxParms) {
534 printUsage(i);
535 return BAD_USAGE;
536 };
537 if ( cmdList[i].haveSubCmd && curCmd == cmdList[i].isSubCmd) {
538 curCmd = i;
539 args++;
540 argc--;
541 match = 1;
542 break;
543 };
544 if ( curCmd == cmdList[i].isSubCmd ) {
545 ok = i;
546 match = 1;
547 break;
548 };
549 printUsage(i);
550 return BAD_USAGE;
551 };
552 };
553 if ( !match ) {
554 if ( curCmd < 0 ) return INVALID_CMD;
555 printUsage(curCmd);
556 return -3;
557 };
558 };
559
560 for ( int i = 0; i<argc; i++ ) {
561 argv[i] = tokens[i+args+1];
562 };
563 return ok;
564
565};
static int argc
Definition: ServiceArgs.c:12
#define ok(value,...)
Definition: atltest.h:57
GLfloat GLfloat p
Definition: glext.h:8902
#define argv
Definition: mplay32.c:18
#define args
Definition: format.c:66
Definition: match.c:390
Definition: match.c:28
static int cmdMatch(const char *cmd, const char *token, int tokenLen, int minM)
Definition: tnmain.cpp:466
#define MAX_TOKEN_COUNT
Definition: tnmain.cpp:464

Referenced by telCommandLine().

◆ waitforkey()

void waitforkey ( )

Definition at line 51 of file tnmain.cpp.

51 {
53 INPUT_RECORD InputRecord;
54 DWORD dwInput;
55 BOOL done = FALSE;
56 while (!done){
57 WaitForSingleObject( hConsole, INFINITE );
58 if (!ReadConsoleInput(hConsole, &InputRecord, 1, &dwInput)){
59 done = TRUE;
60 continue;
61 }
62 if (InputRecord.EventType == KEY_EVENT &&
63 InputRecord.Event.KeyEvent.bKeyDown )
64 done = TRUE;
65 }
66}

Variable Documentation

◆ cmdList

Initial value:
= {
{"open", 1, 1, 2, -1, 0, "o[pen] host [port]\n"},
{"close", 2, 0, 0, -1, 0, NULL},
{"keys", 2, 1, 3, -1, 1, "ke[ys] l[oad] keymapname [file]\n"
"ke[ys] d[isplay]\n"
"ke[ys] s[witch] number\n"},
{"quit", 1, 0, 0, -1, 0, NULL},
{"?", 1, 0, 0, -1, 0, NULL},
{"help", 1, 0, 0, -1, 0, NULL},
{"load", 1, 1, 2, KEYS, 0, NULL},
{"switch", 1, 1, 1, KEYS, 0, NULL},
{"display", 1, 0, 0, KEYS, 0, NULL},
{"set", 3, 0, 2, -1, 0, "set will display available groups.\n"
"set groupname will display all variables/values in a group.\n"
"set [variable [value]] will set variable to value.\n"},
{"z", 1, 0, 0, -1, 0, "suspend telnet\n"},
{"\04", 1, 0, 0, -1, 0, NULL},
{"history", 2, 0, 0, -1, 0, "show command history"},
{"flush", 2, 0, 0, -1, 0, "flush history buffer"},
{"aliases", 5, 0, 0, -1, 0, NULL}
}

Definition at line 435 of file tnmain.cpp.

Referenced by printUsage(), and tokenizeCommand().