1 ///////////////////////////////////////////////////////////////////////////////
2 //Telnet Win32 : an ANSI telnet client.
3 //Copyright (C) 1998-2000 Paul Brannan
4 //Copyright (C) 1998 I.Ioannou
5 //Copyright (C) 1997 Brad Johnson
7 //This program is free software; you can redistribute it and/or
8 //modify it under the terms of the GNU General Public License
9 //as published by the Free Software Foundation; either version 2
10 //of the License, or (at your option) any later version.
12 //This program is distributed in the hope that it will be useful,
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 //GNU General Public License for more details.
17 //You should have received a copy of the GNU General Public License
18 //along with this program; if not, write to the Free Software
19 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 ///////////////////////////////////////////////////////////////////////////
26 /////////////////////////////////////////////////////////
27 // Class TkeyDef - Key Definitions //
28 // - kept in an array container //
29 // originally part of KeyTrans.cpp //
30 /////////////////////////////////////////////////////////
35 // This class did not properly release memory before, and a buffer overrun
36 // was apparent in operator=(char*). Fixed. (Paul Brannan Feb. 4, 1999)
40 vk_code
= dwState
= 0;
43 TKeyDef::TKeyDef(char *def
, DWORD state
, DWORD code
) {
45 if (def
!= NULL
&& *def
!= 0) {
46 // szKeyDef = (char *) GlobalAlloc(GPTR, strlen(def) +1);
47 uKeyDef
.szKeyDef
= new char[strlen(def
)+1];
48 strcpy(uKeyDef
.szKeyDef
, def
);
54 TKeyDef::TKeyDef(optype op
, DWORD state
, DWORD code
) {
55 uKeyDef
.op
= new optype
;
56 uKeyDef
.op
->sendstr
= 0;
57 uKeyDef
.op
->the_op
= op
.the_op
;
62 TKeyDef::TKeyDef(const TKeyDef
&t
) {
63 if(t
.uKeyDef
.szKeyDef
== NULL
) {
64 uKeyDef
.szKeyDef
= (char *)NULL
;
65 } else if(t
.uKeyDef
.op
->sendstr
== 0) {
66 uKeyDef
.op
= new optype
;
67 uKeyDef
.op
->sendstr
= 0;
68 uKeyDef
.op
->the_op
= t
.uKeyDef
.op
->the_op
;
70 uKeyDef
.szKeyDef
= new char[strlen(t
.uKeyDef
.szKeyDef
)+1];
71 strcpy(uKeyDef
.szKeyDef
, t
.uKeyDef
.szKeyDef
);
78 if(uKeyDef
.szKeyDef
) delete[] uKeyDef
.szKeyDef
;
81 char * TKeyDef::operator=(char *def
) {
82 if(def
!= NULL
&& *def
!= 0) {
83 if(uKeyDef
.szKeyDef
) delete[] uKeyDef
.szKeyDef
;
84 uKeyDef
.szKeyDef
= new char[strlen(def
)+1];
85 strcpy(uKeyDef
.szKeyDef
, def
);
87 return uKeyDef
.szKeyDef
;
90 DWORD
TKeyDef::operator=(DWORD code
) {
91 return vk_code
= code
;
94 TKeyDef
& TKeyDef::operator=(const TKeyDef
&t
) {
95 if(t
.uKeyDef
.szKeyDef
) {
96 if(uKeyDef
.szKeyDef
) delete[] uKeyDef
.szKeyDef
;
97 if(t
.uKeyDef
.op
->sendstr
) {
98 uKeyDef
.szKeyDef
= new char[strlen(t
.uKeyDef
.szKeyDef
)+1];
99 strcpy(uKeyDef
.szKeyDef
, t
.uKeyDef
.szKeyDef
);
101 uKeyDef
.op
= new optype
;
102 uKeyDef
.op
->sendstr
= 0;
103 uKeyDef
.op
->the_op
= t
.uKeyDef
.op
->the_op
;
106 uKeyDef
.szKeyDef
= (char *)NULL
;
113 const optype
& TKeyDef::operator=(optype op
) {
114 uKeyDef
.op
= new optype
;
115 uKeyDef
.op
->sendstr
= 0;
116 uKeyDef
.op
->the_op
= op
.the_op
;
120 // STL requires that operators be friends rather than member functions
121 // (Paul Brannan 5/25/98)
123 bool operator==(const TKeyDef
& t1
, const TKeyDef
& t2
) {
124 return ((t1
.vk_code
== t2
.vk_code
) && (t1
.dwState
== t2
.dwState
));
126 // We need this function for compatibility with STL (Paul Brannan 5/25/98)
127 bool operator< (const TKeyDef
& t1
, const TKeyDef
& t2
) {
128 if (t1
.vk_code
== t2
.vk_code
) return t1
.dwState
< t2
.dwState
;
129 return t1
.vk_code
< t2
.vk_code
;
132 int TKeyDef::operator==(TKeyDef
& t
) {
133 return ((vk_code
== t
.vk_code
) && (dwState
== t
.dwState
));