1*c2c66affSColin Finck ///////////////////////////////////////////////////////////////////////////////
2*c2c66affSColin Finck //Telnet Win32 : an ANSI telnet client.
3*c2c66affSColin Finck //Copyright (C) 1998-2000 Paul Brannan
4*c2c66affSColin Finck //Copyright (C) 1998 I.Ioannou
5*c2c66affSColin Finck //Copyright (C) 1997 Brad Johnson
6*c2c66affSColin Finck //
7*c2c66affSColin Finck //This program is free software; you can redistribute it and/or
8*c2c66affSColin Finck //modify it under the terms of the GNU General Public License
9*c2c66affSColin Finck //as published by the Free Software Foundation; either version 2
10*c2c66affSColin Finck //of the License, or (at your option) any later version.
11*c2c66affSColin Finck //
12*c2c66affSColin Finck //This program is distributed in the hope that it will be useful,
13*c2c66affSColin Finck //but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c2c66affSColin Finck //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*c2c66affSColin Finck //GNU General Public License for more details.
16*c2c66affSColin Finck //
17*c2c66affSColin Finck //You should have received a copy of the GNU General Public License
18*c2c66affSColin Finck //along with this program; if not, write to the Free Software
19*c2c66affSColin Finck //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*c2c66affSColin Finck //
21*c2c66affSColin Finck //I.Ioannou
22*c2c66affSColin Finck //roryt@hol.gr
23*c2c66affSColin Finck //
24*c2c66affSColin Finck ///////////////////////////////////////////////////////////////////////////
25*c2c66affSColin Finck
26*c2c66affSColin Finck /////////////////////////////////////////////////////////
27*c2c66affSColin Finck // Class TkeyDef - Key Definitions //
28*c2c66affSColin Finck // - kept in an array container //
29*c2c66affSColin Finck // originally part of KeyTrans.cpp //
30*c2c66affSColin Finck /////////////////////////////////////////////////////////
31*c2c66affSColin Finck
32*c2c66affSColin Finck #include "precomp.h"
33*c2c66affSColin Finck
34*c2c66affSColin Finck // This class did not properly release memory before, and a buffer overrun
35*c2c66affSColin Finck // was apparent in operator=(char*). Fixed. (Paul Brannan Feb. 4, 1999)
36*c2c66affSColin Finck
TKeyDef()37*c2c66affSColin Finck TKeyDef::TKeyDef() {
38*c2c66affSColin Finck uKeyDef.szKeyDef = 0;
39*c2c66affSColin Finck vk_code = dwState = 0;
40*c2c66affSColin Finck }
41*c2c66affSColin Finck
TKeyDef(char * def,DWORD state,DWORD code)42*c2c66affSColin Finck TKeyDef::TKeyDef(char *def, DWORD state, DWORD code) {
43*c2c66affSColin Finck uKeyDef.szKeyDef = 0;
44*c2c66affSColin Finck if (def != NULL && *def != 0) {
45*c2c66affSColin Finck // szKeyDef = (char *) GlobalAlloc(GPTR, strlen(def) +1);
46*c2c66affSColin Finck uKeyDef.szKeyDef = new char[strlen(def)+1];
47*c2c66affSColin Finck strcpy(uKeyDef.szKeyDef, def);
48*c2c66affSColin Finck }
49*c2c66affSColin Finck dwState = state;
50*c2c66affSColin Finck vk_code = code;
51*c2c66affSColin Finck }
52*c2c66affSColin Finck
TKeyDef(optype op,DWORD state,DWORD code)53*c2c66affSColin Finck TKeyDef::TKeyDef(optype op, DWORD state, DWORD code) {
54*c2c66affSColin Finck uKeyDef.op = new optype;
55*c2c66affSColin Finck uKeyDef.op->sendstr = 0;
56*c2c66affSColin Finck uKeyDef.op->the_op = op.the_op;
57*c2c66affSColin Finck dwState = state;
58*c2c66affSColin Finck vk_code = code;
59*c2c66affSColin Finck }
60*c2c66affSColin Finck
TKeyDef(const TKeyDef & t)61*c2c66affSColin Finck TKeyDef::TKeyDef(const TKeyDef &t) {
62*c2c66affSColin Finck if(t.uKeyDef.szKeyDef == NULL) {
63*c2c66affSColin Finck uKeyDef.szKeyDef = (char *)NULL;
64*c2c66affSColin Finck } else if(t.uKeyDef.op->sendstr == 0) {
65*c2c66affSColin Finck uKeyDef.op = new optype;
66*c2c66affSColin Finck uKeyDef.op->sendstr = 0;
67*c2c66affSColin Finck uKeyDef.op->the_op = t.uKeyDef.op->the_op;
68*c2c66affSColin Finck } else {
69*c2c66affSColin Finck uKeyDef.szKeyDef = new char[strlen(t.uKeyDef.szKeyDef)+1];
70*c2c66affSColin Finck strcpy(uKeyDef.szKeyDef, t.uKeyDef.szKeyDef);
71*c2c66affSColin Finck }
72*c2c66affSColin Finck dwState = t.dwState;
73*c2c66affSColin Finck vk_code = t.vk_code;
74*c2c66affSColin Finck }
75*c2c66affSColin Finck
~TKeyDef()76*c2c66affSColin Finck TKeyDef::~TKeyDef() {
77*c2c66affSColin Finck if(uKeyDef.szKeyDef) delete[] uKeyDef.szKeyDef;
78*c2c66affSColin Finck }
79*c2c66affSColin Finck
operator =(char * def)80*c2c66affSColin Finck char * TKeyDef::operator=(char *def) {
81*c2c66affSColin Finck if(def != NULL && *def != 0) {
82*c2c66affSColin Finck if(uKeyDef.szKeyDef) delete[] uKeyDef.szKeyDef;
83*c2c66affSColin Finck uKeyDef.szKeyDef = new char[strlen(def)+1];
84*c2c66affSColin Finck strcpy(uKeyDef.szKeyDef, def);
85*c2c66affSColin Finck }
86*c2c66affSColin Finck return uKeyDef.szKeyDef;
87*c2c66affSColin Finck }
88*c2c66affSColin Finck
operator =(DWORD code)89*c2c66affSColin Finck DWORD TKeyDef::operator=(DWORD code) {
90*c2c66affSColin Finck return vk_code = code;
91*c2c66affSColin Finck }
92*c2c66affSColin Finck
operator =(const TKeyDef & t)93*c2c66affSColin Finck TKeyDef& TKeyDef::operator=(const TKeyDef &t) {
94*c2c66affSColin Finck if(t.uKeyDef.szKeyDef) {
95*c2c66affSColin Finck if(uKeyDef.szKeyDef) delete[] uKeyDef.szKeyDef;
96*c2c66affSColin Finck if(t.uKeyDef.op->sendstr) {
97*c2c66affSColin Finck uKeyDef.szKeyDef = new char[strlen(t.uKeyDef.szKeyDef)+1];
98*c2c66affSColin Finck strcpy(uKeyDef.szKeyDef, t.uKeyDef.szKeyDef);
99*c2c66affSColin Finck } else {
100*c2c66affSColin Finck uKeyDef.op = new optype;
101*c2c66affSColin Finck uKeyDef.op->sendstr = 0;
102*c2c66affSColin Finck uKeyDef.op->the_op = t.uKeyDef.op->the_op;
103*c2c66affSColin Finck }
104*c2c66affSColin Finck } else {
105*c2c66affSColin Finck uKeyDef.szKeyDef = (char *)NULL;
106*c2c66affSColin Finck }
107*c2c66affSColin Finck dwState = t.dwState;
108*c2c66affSColin Finck vk_code = t.vk_code;
109*c2c66affSColin Finck return *this;
110*c2c66affSColin Finck }
111*c2c66affSColin Finck
operator =(optype op)112*c2c66affSColin Finck const optype& TKeyDef::operator=(optype op) {
113*c2c66affSColin Finck uKeyDef.op = new optype;
114*c2c66affSColin Finck uKeyDef.op->sendstr = 0;
115*c2c66affSColin Finck uKeyDef.op->the_op = op.the_op;
116*c2c66affSColin Finck return *uKeyDef.op;
117*c2c66affSColin Finck }
118*c2c66affSColin Finck
119*c2c66affSColin Finck // STL requires that operators be friends rather than member functions
120*c2c66affSColin Finck // (Paul Brannan 5/25/98)
121*c2c66affSColin Finck #ifndef __BORLANDC__
operator ==(const TKeyDef & t1,const TKeyDef & t2)122*c2c66affSColin Finck bool operator==(const TKeyDef & t1, const TKeyDef & t2) {
123*c2c66affSColin Finck return ((t1.vk_code == t2.vk_code) && (t1.dwState == t2.dwState));
124*c2c66affSColin Finck }
125*c2c66affSColin Finck // We need this function for compatibility with STL (Paul Brannan 5/25/98)
operator <(const TKeyDef & t1,const TKeyDef & t2)126*c2c66affSColin Finck bool operator< (const TKeyDef& t1, const TKeyDef& t2) {
127*c2c66affSColin Finck if (t1.vk_code == t2.vk_code) return t1.dwState < t2.dwState;
128*c2c66affSColin Finck return t1.vk_code < t2.vk_code;
129*c2c66affSColin Finck }
130*c2c66affSColin Finck #else
operator ==(TKeyDef & t)131*c2c66affSColin Finck int TKeyDef::operator==(TKeyDef & t) {
132*c2c66affSColin Finck return ((vk_code == t.vk_code) && (dwState == t.dwState));
133*c2c66affSColin Finck }
134*c2c66affSColin Finck #endif
135*c2c66affSColin Finck
136