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 /////////////////////////////////////////////////////////
34 // This class did not properly release memory before, and a buffer overrun
35 // was apparent in operator=(char*). Fixed. (Paul Brannan Feb. 4, 1999)
39 vk_code
= dwState
= 0;
42 TKeyDef::TKeyDef(char *def
, DWORD state
, DWORD code
) {
44 if (def
!= NULL
&& *def
!= 0) {
45 // szKeyDef = (char *) GlobalAlloc(GPTR, strlen(def) +1);
46 uKeyDef
.szKeyDef
= new char[strlen(def
)+1];
47 strcpy(uKeyDef
.szKeyDef
, def
);
53 TKeyDef::TKeyDef(optype op
, DWORD state
, DWORD code
) {
54 uKeyDef
.op
= new optype
;
55 uKeyDef
.op
->sendstr
= 0;
56 uKeyDef
.op
->the_op
= op
.the_op
;
61 TKeyDef::TKeyDef(const TKeyDef
&t
) {
62 if(t
.uKeyDef
.szKeyDef
== NULL
) {
63 uKeyDef
.szKeyDef
= (char *)NULL
;
64 } else if(t
.uKeyDef
.op
->sendstr
== 0) {
65 uKeyDef
.op
= new optype
;
66 uKeyDef
.op
->sendstr
= 0;
67 uKeyDef
.op
->the_op
= t
.uKeyDef
.op
->the_op
;
69 uKeyDef
.szKeyDef
= new char[strlen(t
.uKeyDef
.szKeyDef
)+1];
70 strcpy(uKeyDef
.szKeyDef
, t
.uKeyDef
.szKeyDef
);
77 if(uKeyDef
.szKeyDef
) delete[] uKeyDef
.szKeyDef
;
80 char * TKeyDef::operator=(char *def
) {
81 if(def
!= NULL
&& *def
!= 0) {
82 if(uKeyDef
.szKeyDef
) delete[] uKeyDef
.szKeyDef
;
83 uKeyDef
.szKeyDef
= new char[strlen(def
)+1];
84 strcpy(uKeyDef
.szKeyDef
, def
);
86 return uKeyDef
.szKeyDef
;
89 DWORD
TKeyDef::operator=(DWORD code
) {
90 return vk_code
= code
;
93 TKeyDef
& TKeyDef::operator=(const TKeyDef
&t
) {
94 if(t
.uKeyDef
.szKeyDef
) {
95 if(uKeyDef
.szKeyDef
) delete[] uKeyDef
.szKeyDef
;
96 if(t
.uKeyDef
.op
->sendstr
) {
97 uKeyDef
.szKeyDef
= new char[strlen(t
.uKeyDef
.szKeyDef
)+1];
98 strcpy(uKeyDef
.szKeyDef
, t
.uKeyDef
.szKeyDef
);
100 uKeyDef
.op
= new optype
;
101 uKeyDef
.op
->sendstr
= 0;
102 uKeyDef
.op
->the_op
= t
.uKeyDef
.op
->the_op
;
105 uKeyDef
.szKeyDef
= (char *)NULL
;
112 const optype
& TKeyDef::operator=(optype op
) {
113 uKeyDef
.op
= new optype
;
114 uKeyDef
.op
->sendstr
= 0;
115 uKeyDef
.op
->the_op
= op
.the_op
;
119 // STL requires that operators be friends rather than member functions
120 // (Paul Brannan 5/25/98)
122 bool operator==(const TKeyDef
& t1
, const TKeyDef
& t2
) {
123 return ((t1
.vk_code
== t2
.vk_code
) && (t1
.dwState
== t2
.dwState
));
125 // We need this function for compatibility with STL (Paul Brannan 5/25/98)
126 bool operator< (const TKeyDef
& t1
, const TKeyDef
& t2
) {
127 if (t1
.vk_code
== t2
.vk_code
) return t1
.dwState
< t2
.dwState
;
128 return t1
.vk_code
< t2
.vk_code
;
131 int TKeyDef::operator==(TKeyDef
& t
) {
132 return ((vk_code
== t
.vk_code
) && (dwState
== t
.dwState
));