author | Michael Krelin <hacker@klever.net> | 2005-08-06 13:47:13 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-08-06 13:47:13 (UTC) |
commit | fc7dc5278f4590c74e41b3ce89d093a05550ec44 (patch) (side-by-side diff) | |
tree | 0c51dff7fad22caddab72ff125e2d7ace9c7e813 /kinsole.cpp | |
parent | c71a33aff5d0bbe32dc9d0f732c11a87e5909d47 (diff) | |
download | kinsole-master.zip kinsole-master.tar.gz kinsole-master.tar.bz2 |
git-svn-id: http://svn.klever.net/kin/kinsole/trunk@132 fe716a7a-6dde-0310-88d9-d003556173a8
-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 @@ #include <stdio.h>
#ifdef _DEBUG
#include <afxwin.h>
#else
#define ASSERT(f) ((void)0)
#define VERIFY(f) ((void)(f))
#define TRACE0(sz)
#define TRACE1(sz, p1)
#define TRACE2(sz, p1, p2)
#define TRACE3(sz, p1, p2, p3)
#endif
#include <winsock.h>
#include "resource.h"
#include "windowsx.h"
#define DAMN_KIN_NAME "KINSole"
-#define DAMN_KIN_VERSION "1.1"
+#define DAMN_KIN_VERSION "1.1.1"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
enum {
WM_USERSOCKET = WM_USER+16,
WM_USERKEY,
WM_USERNOP
};
enum {
tnIAC = 255,
tnSE = 240,
tnNOP = 241,
tnDM = 242,
tnBreak = 243,
tnIP = 244,
tnAO = 245,
tnAYT = 246,
tnEC = 247,
tnEL = 248,
tnGA = 249,
tnSB = 250,
tnWILL = 251,
tnWONT = 252,
tnDO = 253,
tnDONT = 254
};
WSADATA wsaData;
ATOM wsaWC = NULL;
HWND wsaW = NULL;
CHAR remoteHost[256];
CHAR remoteProt[256];
sockaddr_in remoteSIN;
SOCKET telnetSocket;
HANDLE hConsoleInput;
HANDLE hConsoleOutput;
HWND hConsoleWindow;
HANDLE hConsoleThread;
DWORD consoleThreadID;
HANDLE hDispatchThread;
DWORD dispatchThreadID;
@@ -505,97 +505,97 @@ WNDCLASS wc; printf("Failed to initialize winsock services\n");
return FALSE;
}
return TRUE;
}
void DeinitializeWinsock()
{
if(wsaW)
::DestroyWindow(wsaW);
wsaW=NULL;
if(wsaWC)
::UnregisterClass("_WSTFWC_",::GetModuleHandle(NULL));
wsaWC=NULL;
WSACleanup();
}
HWND GetThisConsoleWnd()
{
DWORD pid = GetCurrentProcessId();
CHAR title[512];
CHAR* t = title;
if(!GetConsoleTitle(title,sizeof(title)))
t = NULL;
HWND hrv = FindWindowEx(NULL,NULL,"tty",t);
HWND nopro = NULL;
UINT nopros=0;
do{
DWORD wpid;
if(!GetWindowThreadProcessId(hrv,&wpid))
continue;
if(wpid==pid)
return hrv;
nopro=hrv;
nopros++;
hrv = FindWindowEx(NULL,hrv,"tty",t);
}while(hrv);
if(nopros==1){
ASSERT(nopro);
return nopro;
}
return NULL;
}
main(int argc,char*argv[])
{
if(argc<2){
usagebye:
printf(
- DAMN_KIN_NAME " " DAMN_KIN_VERSION ", Copyright (c) 1998-2004 Klever Group (http://www.klever.net/)\n\n"
+ DAMN_KIN_NAME " " DAMN_KIN_VERSION ", Copyright (c) 1998-2005 Klever Group (http://www.klever.net/)\n\n"
"Usage:\t" DAMN_KIN_NAME " [<options> ]<host-name/ip-address>[ <port>]\n\n"
"Options are:\n"
"-r## or -##\tSet number of rows in console screenbuffer\n"
"-c##\t\tSet number of columns in console screenbuffer\n"
"\tnote: changing console screenbuffer size may not work properly\n"
"\twhen in full-screen mode\n"
"-l<user>\tPass username to remote server in environment\n"
"-e<var>=<val>\tPass environment variable to remote server\n"
"-v<var>=<val>\tPass user environment variable to remote server\n"
"-t<termtype>\tChange preferred terminal type\n"
"\tnote: there are only two different terminal emulations in this\n"
"\trelease - one for dumb terminal and one for vt terminal\n"
);
CleanEnvars();
return 1;
}
if(!InitializeWinsock()){
DeinitializeWinsock();
return 2;
}
CONSOLE_SCREEN_BUFFER_INFO csbi;
int ac = 0;
CHAR *ho = NULL, *po = NULL;
HANDLE hConsole = CreateFile("CONOUT$",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,OPEN_EXISTING,0,NULL);
ASSERT(hConsole);
// *** GetStdHandle(STD_OUTPUT_HANDLE); // *?*?* Do something about redirections and not only here.
VERIFY(GetConsoleScreenBufferInfo(hConsole,&csbi));
BOOL bSized=FALSE;
bTermPulled=FALSE;
for(int tmp=1;tmp<argc;tmp++){
char* v = argv[tmp];
ASSERT(v && *v);
if((*v)=='/' || (*v)=='-'){
int lines = atoi(&v[1]);
if(lines){
if(lines<csbi.dwSize.Y){
SMALL_RECT wi = {0,0,csbi.dwSize.X-1,lines-1};
VERIFY(SetConsoleWindowInfo(hConsole,TRUE,&wi));
}
COORD ns = {csbi.dwSize.X,lines};
if(SetConsoleScreenBufferSize(hConsole,ns))
bSized=TRUE;
}else if(v[1]=='r'){
int lines = atoi(&v[2]);
if(lines){
if(lines<csbi.dwSize.Y){
SMALL_RECT wi = {0,0,csbi.dwSize.X-1,lines-1};
|