-rw-r--r-- | kinsole.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/kinsole.cpp b/kinsole.cpp index 01286f3..7fa3f8b 100644 --- a/kinsole.cpp +++ b/kinsole.cpp | |||
@@ -1,67 +1,67 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | 2 | ||
3 | #ifdef_DEBUG | 3 | #ifdef_DEBUG |
4 | #include <afxwin.h> | 4 | #include <afxwin.h> |
5 | #else | 5 | #else |
6 | #define ASSERT(f) ((void)0) | 6 | #define ASSERT(f) ((void)0) |
7 | #define VERIFY(f) ((void)(f)) | 7 | #define VERIFY(f) ((void)(f)) |
8 | #define TRACE0(sz) | 8 | #define TRACE0(sz) |
9 | #define TRACE1(sz, p1) | 9 | #define TRACE1(sz, p1) |
10 | #define TRACE2(sz, p1, p2) | 10 | #define TRACE2(sz, p1, p2) |
11 | #define TRACE3(sz, p1, p2, p3) | 11 | #define TRACE3(sz, p1, p2, p3) |
12 | #endif | 12 | #endif |
13 | 13 | ||
14 | #include <winsock.h> | 14 | #include <winsock.h> |
15 | #include "resource.h" | 15 | #include "resource.h" |
16 | #include "windowsx.h" | 16 | #include "windowsx.h" |
17 | 17 | ||
18 | #define DAMN_KIN_NAME "KINSole" | 18 | #define DAMN_KIN_NAME "KINSole" |
19 | #define DAMN_KIN_VERSION"1.1" | 19 | #define DAMN_KIN_VERSION"1.1.1" |
20 | 20 | ||
21 | #ifdef _DEBUG | 21 | #ifdef _DEBUG |
22 | #define new DEBUG_NEW | 22 | #define new DEBUG_NEW |
23 | #undef THIS_FILE | 23 | #undef THIS_FILE |
24 | static char THIS_FILE[] = __FILE__; | 24 | static char THIS_FILE[] = __FILE__; |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | enum { | 27 | enum { |
28 | WM_USERSOCKET = WM_USER+16, | 28 | WM_USERSOCKET = WM_USER+16, |
29 | WM_USERKEY, | 29 | WM_USERKEY, |
30 | WM_USERNOP | 30 | WM_USERNOP |
31 | }; | 31 | }; |
32 | enum { | 32 | enum { |
33 | tnIAC = 255, | 33 | tnIAC = 255, |
34 | tnSE = 240, | 34 | tnSE = 240, |
35 | tnNOP = 241, | 35 | tnNOP = 241, |
36 | tnDM = 242, | 36 | tnDM = 242, |
37 | tnBreak = 243, | 37 | tnBreak = 243, |
38 | tnIP = 244, | 38 | tnIP = 244, |
39 | tnAO = 245, | 39 | tnAO = 245, |
40 | tnAYT = 246, | 40 | tnAYT = 246, |
41 | tnEC = 247, | 41 | tnEC = 247, |
42 | tnEL = 248, | 42 | tnEL = 248, |
43 | tnGA = 249, | 43 | tnGA = 249, |
44 | tnSB = 250, | 44 | tnSB = 250, |
45 | tnWILL = 251, | 45 | tnWILL = 251, |
46 | tnWONT = 252, | 46 | tnWONT = 252, |
47 | tnDO = 253, | 47 | tnDO = 253, |
48 | tnDONT = 254 | 48 | tnDONT = 254 |
49 | }; | 49 | }; |
50 | 50 | ||
51 | WSADATA wsaData; | 51 | WSADATA wsaData; |
52 | ATOM wsaWC = NULL; | 52 | ATOM wsaWC = NULL; |
53 | HWND wsaW = NULL; | 53 | HWND wsaW = NULL; |
54 | 54 | ||
55 | CHAR remoteHost[256]; | 55 | CHAR remoteHost[256]; |
56 | CHAR remoteProt[256]; | 56 | CHAR remoteProt[256]; |
57 | sockaddr_in remoteSIN; | 57 | sockaddr_in remoteSIN; |
58 | 58 | ||
59 | 59 | ||
60 | SOCKET telnetSocket; | 60 | SOCKET telnetSocket; |
61 | HANDLE hConsoleInput; | 61 | HANDLE hConsoleInput; |
62 | HANDLE hConsoleOutput; | 62 | HANDLE hConsoleOutput; |
63 | HWND hConsoleWindow; | 63 | HWND hConsoleWindow; |
64 | HANDLE hConsoleThread; | 64 | HANDLE hConsoleThread; |
65 | DWORD consoleThreadID; | 65 | DWORD consoleThreadID; |
66 | HANDLE hDispatchThread; | 66 | HANDLE hDispatchThread; |
67 | DWORD dispatchThreadID; | 67 | DWORD dispatchThreadID; |
@@ -505,97 +505,97 @@ WNDCLASS wc; | |||
505 | printf("Failed to initialize winsock services\n"); | 505 | printf("Failed to initialize winsock services\n"); |
506 | return FALSE; | 506 | return FALSE; |
507 | } | 507 | } |
508 | return TRUE; | 508 | return TRUE; |
509 | } | 509 | } |
510 | void DeinitializeWinsock() | 510 | void DeinitializeWinsock() |
511 | { | 511 | { |
512 | if(wsaW) | 512 | if(wsaW) |
513 | ::DestroyWindow(wsaW); | 513 | ::DestroyWindow(wsaW); |
514 | wsaW=NULL; | 514 | wsaW=NULL; |
515 | if(wsaWC) | 515 | if(wsaWC) |
516 | ::UnregisterClass("_WSTFWC_",::GetModuleHandle(NULL)); | 516 | ::UnregisterClass("_WSTFWC_",::GetModuleHandle(NULL)); |
517 | wsaWC=NULL; | 517 | wsaWC=NULL; |
518 | WSACleanup(); | 518 | WSACleanup(); |
519 | } | 519 | } |
520 | 520 | ||
521 | HWND GetThisConsoleWnd() | 521 | HWND GetThisConsoleWnd() |
522 | { | 522 | { |
523 | DWORD pid = GetCurrentProcessId(); | 523 | DWORD pid = GetCurrentProcessId(); |
524 | CHAR title[512]; | 524 | CHAR title[512]; |
525 | CHAR* t = title; | 525 | CHAR* t = title; |
526 | if(!GetConsoleTitle(title,sizeof(title))) | 526 | if(!GetConsoleTitle(title,sizeof(title))) |
527 | t = NULL; | 527 | t = NULL; |
528 | HWND hrv = FindWindowEx(NULL,NULL,"tty",t); | 528 | HWND hrv = FindWindowEx(NULL,NULL,"tty",t); |
529 | HWND nopro = NULL; | 529 | HWND nopro = NULL; |
530 | UINT nopros=0; | 530 | UINT nopros=0; |
531 | do{ | 531 | do{ |
532 | DWORD wpid; | 532 | DWORD wpid; |
533 | if(!GetWindowThreadProcessId(hrv,&wpid)) | 533 | if(!GetWindowThreadProcessId(hrv,&wpid)) |
534 | continue; | 534 | continue; |
535 | if(wpid==pid) | 535 | if(wpid==pid) |
536 | return hrv; | 536 | return hrv; |
537 | nopro=hrv; | 537 | nopro=hrv; |
538 | nopros++; | 538 | nopros++; |
539 | hrv = FindWindowEx(NULL,hrv,"tty",t); | 539 | hrv = FindWindowEx(NULL,hrv,"tty",t); |
540 | }while(hrv); | 540 | }while(hrv); |
541 | if(nopros==1){ | 541 | if(nopros==1){ |
542 | ASSERT(nopro); | 542 | ASSERT(nopro); |
543 | return nopro; | 543 | return nopro; |
544 | } | 544 | } |
545 | return NULL; | 545 | return NULL; |
546 | } | 546 | } |
547 | 547 | ||
548 | main(int argc,char*argv[]) | 548 | main(int argc,char*argv[]) |
549 | { | 549 | { |
550 | if(argc<2){ | 550 | if(argc<2){ |
551 | usagebye: | 551 | usagebye: |
552 | printf( | 552 | printf( |
553 | DAMN_KIN_NAME " " DAMN_KIN_VERSION ", Copyright (c) 1998-2004 Klever Group (http://www.klever.net/)\n\n" | 553 | DAMN_KIN_NAME " " DAMN_KIN_VERSION ", Copyright (c) 1998-2005 Klever Group (http://www.klever.net/)\n\n" |
554 | "Usage:\t" DAMN_KIN_NAME " [<options> ]<host-name/ip-address>[ <port>]\n\n" | 554 | "Usage:\t" DAMN_KIN_NAME " [<options> ]<host-name/ip-address>[ <port>]\n\n" |
555 | "Options are:\n" | 555 | "Options are:\n" |
556 | "-r## or -##\tSet number of rows in console screenbuffer\n" | 556 | "-r## or -##\tSet number of rows in console screenbuffer\n" |
557 | "-c##\t\tSet number of columns in console screenbuffer\n" | 557 | "-c##\t\tSet number of columns in console screenbuffer\n" |
558 | "\tnote: changing console screenbuffer size may not work properly\n" | 558 | "\tnote: changing console screenbuffer size may not work properly\n" |
559 | "\twhen in full-screen mode\n" | 559 | "\twhen in full-screen mode\n" |
560 | "-l<user>\tPass username to remote server in environment\n" | 560 | "-l<user>\tPass username to remote server in environment\n" |
561 | "-e<var>=<val>\tPass environment variable to remote server\n" | 561 | "-e<var>=<val>\tPass environment variable to remote server\n" |
562 | "-v<var>=<val>\tPass user environment variable to remote server\n" | 562 | "-v<var>=<val>\tPass user environment variable to remote server\n" |
563 | "-t<termtype>\tChange preferred terminal type\n" | 563 | "-t<termtype>\tChange preferred terminal type\n" |
564 | "\tnote: there are only two different terminal emulations in this\n" | 564 | "\tnote: there are only two different terminal emulations in this\n" |
565 | "\trelease - one for dumb terminal and one for vt terminal\n" | 565 | "\trelease - one for dumb terminal and one for vt terminal\n" |
566 | ); | 566 | ); |
567 | CleanEnvars(); | 567 | CleanEnvars(); |
568 | return 1; | 568 | return 1; |
569 | } | 569 | } |
570 | if(!InitializeWinsock()){ | 570 | if(!InitializeWinsock()){ |
571 | DeinitializeWinsock(); | 571 | DeinitializeWinsock(); |
572 | return 2; | 572 | return 2; |
573 | } | 573 | } |
574 | CONSOLE_SCREEN_BUFFER_INFO csbi; | 574 | CONSOLE_SCREEN_BUFFER_INFO csbi; |
575 | int ac = 0; | 575 | int ac = 0; |
576 | CHAR *ho = NULL, *po = NULL; | 576 | CHAR *ho = NULL, *po = NULL; |
577 | HANDLE hConsole = CreateFile("CONOUT$",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE, | 577 | HANDLE hConsole = CreateFile("CONOUT$",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE, |
578 | NULL,OPEN_EXISTING,0,NULL); | 578 | NULL,OPEN_EXISTING,0,NULL); |
579 | ASSERT(hConsole); | 579 | ASSERT(hConsole); |
580 | // *** GetStdHandle(STD_OUTPUT_HANDLE);// *?*?* Do something about redirections and not only here. | 580 | // *** GetStdHandle(STD_OUTPUT_HANDLE);// *?*?* Do something about redirections and not only here. |
581 | VERIFY(GetConsoleScreenBufferInfo(hConsole,&csbi)); | 581 | VERIFY(GetConsoleScreenBufferInfo(hConsole,&csbi)); |
582 | BOOL bSized=FALSE; | 582 | BOOL bSized=FALSE; |
583 | bTermPulled=FALSE; | 583 | bTermPulled=FALSE; |
584 | for(int tmp=1;tmp<argc;tmp++){ | 584 | for(int tmp=1;tmp<argc;tmp++){ |
585 | char* v = argv[tmp]; | 585 | char* v = argv[tmp]; |
586 | ASSERT(v && *v); | 586 | ASSERT(v && *v); |
587 | if((*v)=='/' || (*v)=='-'){ | 587 | if((*v)=='/' || (*v)=='-'){ |
588 | int lines = atoi(&v[1]); | 588 | int lines = atoi(&v[1]); |
589 | if(lines){ | 589 | if(lines){ |
590 | if(lines<csbi.dwSize.Y){ | 590 | if(lines<csbi.dwSize.Y){ |
591 | SMALL_RECT wi = {0,0,csbi.dwSize.X-1,lines-1}; | 591 | SMALL_RECT wi = {0,0,csbi.dwSize.X-1,lines-1}; |
592 | VERIFY(SetConsoleWindowInfo(hConsole,TRUE,&wi)); | 592 | VERIFY(SetConsoleWindowInfo(hConsole,TRUE,&wi)); |
593 | } | 593 | } |
594 | COORD ns = {csbi.dwSize.X,lines}; | 594 | COORD ns = {csbi.dwSize.X,lines}; |
595 | if(SetConsoleScreenBufferSize(hConsole,ns)) | 595 | if(SetConsoleScreenBufferSize(hConsole,ns)) |
596 | bSized=TRUE; | 596 | bSized=TRUE; |
597 | }else if(v[1]=='r'){ | 597 | }else if(v[1]=='r'){ |
598 | int lines = atoi(&v[2]); | 598 | int lines = atoi(&v[2]); |
599 | if(lines){ | 599 | if(lines){ |
600 | if(lines<csbi.dwSize.Y){ | 600 | if(lines<csbi.dwSize.Y){ |
601 | SMALL_RECT wi = {0,0,csbi.dwSize.X-1,lines-1}; | 601 | SMALL_RECT wi = {0,0,csbi.dwSize.X-1,lines-1}; |