Reactos
at master 135 lines 4.1 kB view raw
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 6// 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. 11// 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. 16// 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. 20// 21//I.Ioannou 22//roryt@hol.gr 23// 24/////////////////////////////////////////////////////////////////////////// 25 26///////////////////////////////////////////////////////// 27// Class TkeyDef - Key Definitions // 28// - kept in an array container // 29// originally part of KeyTrans.cpp // 30///////////////////////////////////////////////////////// 31 32#include "precomp.h" 33 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) 36 37TKeyDef::TKeyDef() { 38 uKeyDef.szKeyDef = 0; 39 vk_code = dwState = 0; 40} 41 42TKeyDef::TKeyDef(char *def, DWORD state, DWORD code) { 43 uKeyDef.szKeyDef = 0; 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); 48 } 49 dwState = state; 50 vk_code = code; 51} 52 53TKeyDef::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; 57 dwState = state; 58 vk_code = code; 59} 60 61TKeyDef::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; 68 } else { 69 uKeyDef.szKeyDef = new char[strlen(t.uKeyDef.szKeyDef)+1]; 70 strcpy(uKeyDef.szKeyDef, t.uKeyDef.szKeyDef); 71 } 72 dwState = t.dwState; 73 vk_code = t.vk_code; 74} 75 76TKeyDef::~TKeyDef() { 77 if(uKeyDef.szKeyDef) delete[] uKeyDef.szKeyDef; 78} 79 80char * 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); 85 } 86 return uKeyDef.szKeyDef; 87} 88 89DWORD TKeyDef::operator=(DWORD code) { 90 return vk_code = code; 91} 92 93TKeyDef& 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); 99 } else { 100 uKeyDef.op = new optype; 101 uKeyDef.op->sendstr = 0; 102 uKeyDef.op->the_op = t.uKeyDef.op->the_op; 103 } 104 } else { 105 uKeyDef.szKeyDef = (char *)NULL; 106 } 107 dwState = t.dwState; 108 vk_code = t.vk_code; 109 return *this; 110} 111 112const optype& TKeyDef::operator=(optype op) { 113 uKeyDef.op = new optype; 114 uKeyDef.op->sendstr = 0; 115 uKeyDef.op->the_op = op.the_op; 116 return *uKeyDef.op; 117} 118 119// STL requires that operators be friends rather than member functions 120// (Paul Brannan 5/25/98) 121#ifndef __BORLANDC__ 122bool operator==(const TKeyDef & t1, const TKeyDef & t2) { 123 return ((t1.vk_code == t2.vk_code) && (t1.dwState == t2.dwState)); 124} 125// We need this function for compatibility with STL (Paul Brannan 5/25/98) 126bool 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; 129} 130#else 131int TKeyDef::operator==(TKeyDef & t) { 132 return ((vk_code == t.vk_code) && (dwState == t.dwState)); 133} 134#endif 135