| 1 |
doda |
6806 |
/* |
| 2 |
|
|
* Copyright (C) 1994-1998 T. Teranishi |
| 3 |
|
|
* (C) Robert O'Callahan |
| 4 |
nmaya |
9048 |
* (C) 2004- TeraTerm Project |
| 5 |
doda |
6806 |
* All rights reserved. |
| 6 |
|
|
* |
| 7 |
doda |
6841 |
* Redistribution and use in source and binary forms, with or without |
| 8 |
|
|
* modification, are permitted provided that the following conditions |
| 9 |
|
|
* are met: |
| 10 |
doda |
6806 |
* |
| 11 |
doda |
6841 |
* 1. Redistributions of source code must retain the above copyright |
| 12 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 13 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 15 |
|
|
* documentation and/or other materials provided with the distribution. |
| 16 |
|
|
* 3. The name of the author may not be used to endorse or promote products |
| 17 |
|
|
* derived from this software without specific prior written permission. |
| 18 |
doda |
6806 |
* |
| 19 |
doda |
6841 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 20 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 21 |
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 |
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 24 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 |
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 |
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 |
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
doda |
6806 |
*/ |
| 30 |
maya |
3227 |
#include "teraterm.h" |
| 31 |
|
|
#include "tttypes.h" |
| 32 |
|
|
#include "ttlib.h" |
| 33 |
|
|
|
| 34 |
|
|
// #include <windows.h> |
| 35 |
|
|
#include <stdlib.h> |
| 36 |
|
|
#include <stdio.h> |
| 37 |
|
|
#include <string.h> |
| 38 |
|
|
/* for _findXXXX() functions */ |
| 39 |
|
|
#include <io.h> |
| 40 |
|
|
#include "ttwinman.h" |
| 41 |
|
|
#include "ttplugin.h" |
| 42 |
|
|
#include "ttplug.h" |
| 43 |
|
|
#undef TTXOpenTCP |
| 44 |
|
|
#undef TTXCloseTCP |
| 45 |
|
|
#undef TTXOpenFile |
| 46 |
|
|
#undef TTXCloseFile |
| 47 |
|
|
#undef TTXGetUIHooks |
| 48 |
|
|
#undef TTXGetSetupHooks |
| 49 |
|
|
|
| 50 |
doda |
4087 |
#define MAXNUMEXTENSIONS 32 |
| 51 |
maya |
3227 |
static HANDLE LibHandle[MAXNUMEXTENSIONS]; |
| 52 |
|
|
static int NumExtensions = 0; |
| 53 |
|
|
static TTXExports * * Extensions; |
| 54 |
|
|
|
| 55 |
|
|
typedef struct _ExtensionList { |
| 56 |
|
|
TTXExports * exports; |
| 57 |
|
|
struct _ExtensionList * next; |
| 58 |
|
|
} ExtensionList; |
| 59 |
|
|
|
| 60 |
|
|
static int compareOrder(const void * e1, const void * e2) { |
| 61 |
|
|
TTXExports * * exports1 = (TTXExports * *)e1; |
| 62 |
|
|
TTXExports * * exports2 = (TTXExports * *)e2; |
| 63 |
|
|
|
| 64 |
|
|
return (*exports1)->loadOrder - (*exports2)->loadOrder; |
| 65 |
|
|
} |
| 66 |
|
|
|
| 67 |
|
|
static void loadExtension(ExtensionList * * extensions, char const * fileName) { |
| 68 |
|
|
char buf[1024]; |
| 69 |
|
|
DWORD err; |
| 70 |
|
|
char uimsg[MAX_UIMSG]; |
| 71 |
|
|
|
| 72 |
|
|
if (NumExtensions>=MAXNUMEXTENSIONS) return; |
| 73 |
|
|
LibHandle[NumExtensions] = LoadLibrary(fileName); |
| 74 |
|
|
if (LibHandle[NumExtensions] != NULL) { |
| 75 |
zmatsuo |
7536 |
#if defined(_MSC_VER) |
| 76 |
|
|
const char *TTXBIND = "_TTXBind@8"; |
| 77 |
|
|
#else |
| 78 |
|
|
const char *TTXBIND = "TTXBind@8"; |
| 79 |
|
|
#endif |
| 80 |
|
|
TTXBindProc bind = (TTXBindProc)GetProcAddress(LibHandle[NumExtensions], TTXBIND); |
| 81 |
maya |
3227 |
if (bind==NULL) |
| 82 |
|
|
bind = (TTXBindProc)GetProcAddress(LibHandle[NumExtensions], "TTXBind"); |
| 83 |
|
|
if (bind != NULL) { |
| 84 |
|
|
ExtensionList * newExtension = |
| 85 |
|
|
(ExtensionList *)malloc(sizeof(ExtensionList)); |
| 86 |
|
|
|
| 87 |
|
|
newExtension->exports = (TTXExports *)malloc(sizeof(TTXExports)); |
| 88 |
|
|
memset(newExtension->exports, 0, sizeof(TTXExports)); |
| 89 |
|
|
newExtension->exports->size = sizeof(TTXExports); |
| 90 |
doda |
6801 |
if (bind(TTVERSION,(TTXExports *)newExtension->exports)) { |
| 91 |
maya |
3227 |
newExtension->next = *extensions; |
| 92 |
|
|
*extensions = newExtension; |
| 93 |
|
|
NumExtensions++; |
| 94 |
|
|
return; |
| 95 |
|
|
} else { |
| 96 |
|
|
free(newExtension->exports); |
| 97 |
|
|
free(newExtension); |
| 98 |
|
|
} |
| 99 |
|
|
} |
| 100 |
|
|
FreeLibrary(LibHandle[NumExtensions]); |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
err = GetLastError(); |
| 104 |
doda |
6787 |
// �����t�@�C�����������b�Z�[�W�����������s�����������A�������_���������� |
| 105 |
|
|
// �������������������������A���b�Z�[�W���p���������������B�v�����B |
| 106 |
maya |
3227 |
get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts.UILanguageFile); |
| 107 |
|
|
get_lang_msg("MSG_LOAD_EXT_ERROR", ts.UIMsg, sizeof(ts.UIMsg), "Cannot load extension %s (%d)", ts.UILanguageFile); |
| 108 |
|
|
_snprintf_s(buf, sizeof(buf), _TRUNCATE, ts.UIMsg, fileName, err); |
| 109 |
|
|
MessageBox(NULL, buf, uimsg, MB_OK | MB_ICONEXCLAMATION); |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
doda |
6801 |
void PASCAL TTXInit(PTTSet ts, PComVar cv) { |
| 113 |
maya |
3227 |
ExtensionList * extensionList = NULL; |
| 114 |
|
|
int i; |
| 115 |
|
|
|
| 116 |
|
|
// ���������������L�������������ATTX���L���������B |
| 117 |
|
|
//if (getenv("TERATERM_EXTENSIONS") != NULL) { |
| 118 |
|
|
if (1) { |
| 119 |
|
|
char buf[1024]; |
| 120 |
|
|
struct _finddata_t searchData; |
| 121 |
zmatsuo |
7896 |
intptr_t searchHandle; |
| 122 |
maya |
3227 |
|
| 123 |
doda |
6791 |
_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s\\TTX*.DLL", ts->HomeDir); |
| 124 |
maya |
3227 |
|
| 125 |
doda |
6791 |
searchHandle = _findfirst(buf, &searchData); |
| 126 |
maya |
3227 |
if (searchHandle != -1L) { |
| 127 |
doda |
6791 |
do { |
| 128 |
|
|
_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s\\%s", ts->HomeDir, searchData.name); |
| 129 |
|
|
loadExtension(&extensionList, buf); |
| 130 |
|
|
} while (_findnext(searchHandle, &searchData)==0); |
| 131 |
maya |
3227 |
_findclose(searchHandle); |
| 132 |
|
|
} |
| 133 |
|
|
|
| 134 |
|
|
if (NumExtensions==0) return; |
| 135 |
|
|
|
| 136 |
|
|
Extensions = (TTXExports * *)malloc(sizeof(TTXExports *)*NumExtensions); |
| 137 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 138 |
|
|
ExtensionList * old; |
| 139 |
|
|
|
| 140 |
|
|
Extensions[i] = extensionList->exports; |
| 141 |
|
|
old = extensionList; |
| 142 |
|
|
extensionList = extensionList->next; |
| 143 |
|
|
free(old); |
| 144 |
|
|
} |
| 145 |
|
|
|
| 146 |
|
|
qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder); |
| 147 |
|
|
|
| 148 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 149 |
|
|
if (Extensions[i]->TTXInit != NULL) { |
| 150 |
|
|
Extensions[i]->TTXInit(ts, cv); |
| 151 |
|
|
} |
| 152 |
|
|
} |
| 153 |
|
|
} |
| 154 |
|
|
} |
| 155 |
|
|
|
| 156 |
doda |
6801 |
void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) { |
| 157 |
maya |
3227 |
int i; |
| 158 |
|
|
|
| 159 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 160 |
|
|
if (Extensions[i]->TTXOpenTCP != NULL) { |
| 161 |
|
|
Extensions[i]->TTXOpenTCP(hooks); |
| 162 |
|
|
} |
| 163 |
|
|
} |
| 164 |
|
|
} |
| 165 |
|
|
|
| 166 |
doda |
6801 |
void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) { |
| 167 |
maya |
3227 |
int i; |
| 168 |
|
|
|
| 169 |
|
|
for (i = NumExtensions - 1; i >= 0; i--) { |
| 170 |
|
|
if (Extensions[i]->TTXCloseTCP != NULL) { |
| 171 |
|
|
Extensions[i]->TTXCloseTCP(hooks); |
| 172 |
|
|
} |
| 173 |
|
|
} |
| 174 |
|
|
} |
| 175 |
|
|
|
| 176 |
doda |
6801 |
void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) { |
| 177 |
maya |
3227 |
int i; |
| 178 |
|
|
|
| 179 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 180 |
|
|
if (Extensions[i]->TTXOpenFile != NULL) { |
| 181 |
|
|
Extensions[i]->TTXOpenFile(hooks); |
| 182 |
|
|
} |
| 183 |
|
|
} |
| 184 |
|
|
} |
| 185 |
|
|
|
| 186 |
doda |
6801 |
void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) { |
| 187 |
maya |
3227 |
int i; |
| 188 |
|
|
|
| 189 |
|
|
for (i = NumExtensions - 1; i >= 0; i--) { |
| 190 |
|
|
if (Extensions[i]->TTXCloseFile != NULL) { |
| 191 |
|
|
Extensions[i]->TTXCloseFile(hooks); |
| 192 |
|
|
} |
| 193 |
|
|
} |
| 194 |
|
|
} |
| 195 |
|
|
|
| 196 |
doda |
6801 |
void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) { |
| 197 |
maya |
3227 |
int i; |
| 198 |
|
|
|
| 199 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 200 |
|
|
if (Extensions[i]->TTXGetUIHooks != NULL) { |
| 201 |
|
|
Extensions[i]->TTXGetUIHooks(hooks); |
| 202 |
|
|
} |
| 203 |
|
|
} |
| 204 |
|
|
} |
| 205 |
|
|
|
| 206 |
doda |
6801 |
void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) { |
| 207 |
maya |
3227 |
int i; |
| 208 |
|
|
|
| 209 |
|
|
for (i = NumExtensions - 1; i >= 0; i--) { |
| 210 |
|
|
if (Extensions[i]->TTXGetSetupHooks != NULL) { |
| 211 |
|
|
Extensions[i]->TTXGetSetupHooks(hooks); |
| 212 |
|
|
} |
| 213 |
|
|
} |
| 214 |
|
|
} |
| 215 |
|
|
|
| 216 |
doda |
6801 |
void PASCAL TTXSetWinSize(int rows, int cols) { |
| 217 |
maya |
3227 |
int i; |
| 218 |
|
|
|
| 219 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 220 |
|
|
if (Extensions[i]->TTXSetWinSize != NULL) { |
| 221 |
|
|
Extensions[i]->TTXSetWinSize(rows, cols); |
| 222 |
|
|
} |
| 223 |
|
|
} |
| 224 |
|
|
} |
| 225 |
|
|
|
| 226 |
doda |
6801 |
void PASCAL TTXModifyMenu(HMENU menu) { |
| 227 |
maya |
3227 |
int i; |
| 228 |
|
|
|
| 229 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 230 |
|
|
if (Extensions[i]->TTXModifyMenu != NULL) { |
| 231 |
|
|
Extensions[i]->TTXModifyMenu(menu); |
| 232 |
|
|
} |
| 233 |
|
|
} |
| 234 |
|
|
} |
| 235 |
|
|
|
| 236 |
doda |
6801 |
void PASCAL TTXModifyPopupMenu(HMENU menu) { |
| 237 |
maya |
3227 |
int i; |
| 238 |
|
|
|
| 239 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 240 |
|
|
if (Extensions[i]->TTXModifyPopupMenu != NULL) { |
| 241 |
|
|
Extensions[i]->TTXModifyPopupMenu(menu); |
| 242 |
|
|
} |
| 243 |
|
|
} |
| 244 |
|
|
} |
| 245 |
|
|
|
| 246 |
doda |
6801 |
BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) { |
| 247 |
maya |
3227 |
int i; |
| 248 |
|
|
|
| 249 |
|
|
for (i = NumExtensions - 1; i >= 0; i--) { |
| 250 |
|
|
if (Extensions[i]->TTXProcessCommand != NULL) { |
| 251 |
|
|
if (Extensions[i]->TTXProcessCommand(hWin,cmd)) { |
| 252 |
|
|
return TRUE; |
| 253 |
|
|
} |
| 254 |
|
|
} |
| 255 |
|
|
} |
| 256 |
|
|
|
| 257 |
|
|
return FALSE; |
| 258 |
|
|
} |
| 259 |
|
|
|
| 260 |
doda |
6801 |
void PASCAL TTXEnd(void) { |
| 261 |
maya |
3227 |
int i; |
| 262 |
|
|
|
| 263 |
|
|
if (NumExtensions==0) return; |
| 264 |
|
|
|
| 265 |
|
|
for (i = NumExtensions - 1; i >= 0; i--) { |
| 266 |
|
|
if (Extensions[i]->TTXEnd != NULL) { |
| 267 |
|
|
Extensions[i]->TTXEnd(); |
| 268 |
|
|
} |
| 269 |
|
|
} |
| 270 |
|
|
|
| 271 |
|
|
for (i=0; i<NumExtensions; i++) |
| 272 |
|
|
FreeLibrary(LibHandle[i]); |
| 273 |
|
|
|
| 274 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 275 |
|
|
free(Extensions[i]); |
| 276 |
|
|
} |
| 277 |
|
|
|
| 278 |
|
|
free(Extensions); |
| 279 |
|
|
NumExtensions = 0; |
| 280 |
|
|
} |
| 281 |
|
|
|
| 282 |
doda |
6801 |
void PASCAL TTXSetCommandLine(PCHAR cmd, int cmdlen, PGetHNRec rec) { |
| 283 |
maya |
3227 |
int i; |
| 284 |
|
|
|
| 285 |
|
|
for (i = 0; i < NumExtensions; i++) { |
| 286 |
|
|
if (Extensions[i]->TTXSetCommandLine != NULL) { |
| 287 |
|
|
Extensions[i]->TTXSetCommandLine(cmd, cmdlen, rec); |
| 288 |
|
|
} |
| 289 |
|
|
} |
| 290 |
|
|
} |