Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/ttplug.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9342 - (hide annotations) (download) (as text)
Sun Aug 1 15:32:15 2021 UTC (2 years, 8 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 9901 byte(s)
TTMessageBoxW() を TTMessageBoxA() へ改名

- 引数 uType を TTMessageBoxInfoW へ移動
- 未使用マクロ get_lang_msgT() を削除
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 zmatsuo 9227 #include <winsock2.h>
31 maya 3227 #include "teraterm.h"
32     #include "tttypes.h"
33     #include "ttlib.h"
34    
35 zmatsuo 9224 #define _CRTDBG_MAP_ALLOC
36 maya 3227 #include <stdlib.h>
37     #include <stdio.h>
38     #include <string.h>
39 zmatsuo 9224 #include <crtdbg.h>
40 maya 3227 #include "ttwinman.h"
41     #include "ttplugin.h"
42 zmatsuo 9224 #include "codeconv.h"
43 zmatsuo 9225 #include "asprintf.h"
44 maya 3227
45 zmatsuo 9225 #include "ttplug.h"
46    
47 maya 3227 static int NumExtensions = 0;
48    
49     typedef struct _ExtensionList {
50 zmatsuo 9226 TTXExports * exports;
51     HANDLE LibHandle;
52 maya 3227 } ExtensionList;
53    
54 zmatsuo 9226 static ExtensionList *Extensions;
55    
56 maya 3227 static int compareOrder(const void * e1, const void * e2) {
57     TTXExports * * exports1 = (TTXExports * *)e1;
58     TTXExports * * exports2 = (TTXExports * *)e2;
59    
60     return (*exports1)->loadOrder - (*exports2)->loadOrder;
61     }
62    
63 zmatsuo 9226 static void loadExtension(wchar_t const *fileName)
64 zmatsuo 9224 {
65     DWORD err;
66     const wchar_t *sub_message;
67     HMODULE hPlugin;
68 maya 3227
69 zmatsuo 9324 hPlugin = LoadLibraryW(fileName);
70 zmatsuo 9224 if (hPlugin != NULL) {
71     TTXBindProc bind = NULL;
72 zmatsuo 9227 FARPROC *pbind = (FARPROC *)&bind;
73 zmatsuo 7536 #if defined(_MSC_VER)
74 zmatsuo 9224 if (bind == NULL)
75 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "_TTXBind@8");
76 zmatsuo 7536 #else
77 zmatsuo 9224 if (bind == NULL)
78 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "TTXBind@8");
79 zmatsuo 7536 #endif
80 zmatsuo 9224 if (bind == NULL)
81 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "TTXBind");
82 zmatsuo 9224 if (bind != NULL) {
83 zmatsuo 9226 TTXExports * exports = (TTXExports *)malloc(sizeof(TTXExports));
84     if (exports == NULL) {
85     return;
86     }
87     memset(exports, 0, sizeof(TTXExports));
88     exports->size = sizeof(TTXExports);
89 maya 3227
90 zmatsuo 9226 if (bind(TTVERSION, exports)) {
91     ExtensionList *newExtension;
92     ExtensionList *extensions = (ExtensionList *)realloc(Extensions, sizeof(ExtensionList) * (NumExtensions + 1));
93     if (extensions == NULL) {
94     free(exports);
95     FreeLibrary(hPlugin);
96     return;
97     }
98     Extensions = extensions;
99     newExtension = &extensions[NumExtensions];
100 zmatsuo 9224 NumExtensions++;
101 zmatsuo 9226
102     newExtension->exports = exports;
103     newExtension->LibHandle = hPlugin;
104 zmatsuo 9224 return;
105     }
106     else {
107 zmatsuo 9226 free(exports);
108 zmatsuo 9224 }
109     }
110 zmatsuo 9226 FreeLibrary(hPlugin);
111 zmatsuo 9224 }
112 maya 3227
113 zmatsuo 9224 err = GetLastError();
114     switch (err) {
115     case 31:
116     sub_message = L"Unresolved dll entry";
117     break;
118     case 1114:
119     sub_message = L"tls entry exists";
120     break;
121     case 2:
122     sub_message = L"rejected by plugin";
123     break;
124     case 193:
125     sub_message = L"invalid dll image";
126     break;
127     default:
128     sub_message = L"unknown";
129     break;
130     }
131     // �����t�@�C�����������b�Z�[�W�����������s�����������A�������_����������
132     // �������������������������A���b�Z�[�W���p���������������B�v�����B
133 zmatsuo 9230 {
134 zmatsuo 9342 static const TTMessageBoxInfoW info = {
135     "Tera Term",
136     "MSG_TT_ERROR", L"Tera Term: Error",
137     "MSG_LOAD_EXT_ERROR", L"Cannot load extension %s (%d, %s)",
138     MB_OK | MB_ICONEXCLAMATION
139     };
140     TTMessageBoxA(NULL, &info, ts.UILanguageFile, fileName, err, sub_message);
141 zmatsuo 9230 }
142 maya 3227 }
143    
144 zmatsuo 9225 void PASCAL TTXInit(PTTSet ts_, PComVar cv_)
145     {
146     int i;
147     wchar_t *load_mask;
148     WIN32_FIND_DATAW fd;
149     HANDLE hFind;
150 zmatsuo 9336 wchar_t *HomeDirW = ts_->HomeDirW;
151 maya 3227
152 zmatsuo 9225 aswprintf(&load_mask, L"%s\\TTX*.DLL", HomeDirW);
153 maya 3227
154 zmatsuo 9324 hFind = FindFirstFileW(load_mask, &fd);
155 zmatsuo 9225 if (hFind != INVALID_HANDLE_VALUE) {
156     do {
157     wchar_t *filename;
158     aswprintf(&filename, L"%s\\%s", HomeDirW, fd.cFileName);
159 zmatsuo 9226 loadExtension(filename);
160 zmatsuo 9225 free(filename);
161 zmatsuo 9324 } while (FindNextFileW(hFind, &fd));
162 zmatsuo 9225 FindClose(hFind);
163     }
164     free(load_mask);
165 maya 3227
166 zmatsuo 9225 if (NumExtensions==0) return;
167 maya 3227
168 zmatsuo 9225 qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder);
169 maya 3227
170 zmatsuo 9225 for (i = 0; i < NumExtensions; i++) {
171 zmatsuo 9226 if (Extensions[i].exports->TTXInit != NULL) {
172     Extensions[i].exports->TTXInit(ts_, cv_);
173 zmatsuo 9225 }
174     }
175 maya 3227 }
176    
177 zmatsuo 9223 static void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) {
178 maya 3227 int i;
179    
180     for (i = 0; i < NumExtensions; i++) {
181 zmatsuo 9226 if (Extensions[i].exports->TTXOpenTCP != NULL) {
182     Extensions[i].exports->TTXOpenTCP(hooks);
183 maya 3227 }
184     }
185     }
186    
187 zmatsuo 9223 void PASCAL TTXOpenTCP(void)
188     {
189 zmatsuo 9226 static TTXSockHooks SockHooks = {
190     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
191     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
192     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
193     &PWSACancelAsyncRequest, &PWSAGetLastError,
194     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
195     };
196     TTXInternalOpenTCP(&SockHooks);
197 zmatsuo 9223 }
198    
199     static void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) {
200 maya 3227 int i;
201    
202     for (i = NumExtensions - 1; i >= 0; i--) {
203 zmatsuo 9226 if (Extensions[i].exports->TTXCloseTCP != NULL) {
204     Extensions[i].exports->TTXCloseTCP(hooks);
205 maya 3227 }
206     }
207     }
208    
209 zmatsuo 9223 void PASCAL TTXCloseTCP(void)
210     {
211 zmatsuo 9226 static TTXSockHooks SockHooks = {
212     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
213     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
214     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
215     &PWSACancelAsyncRequest, &PWSAGetLastError,
216     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
217     };
218     TTXInternalCloseTCP(&SockHooks);
219 zmatsuo 9223 }
220    
221     static void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) {
222 maya 3227 int i;
223    
224     for (i = 0; i < NumExtensions; i++) {
225 zmatsuo 9226 if (Extensions[i].exports->TTXOpenFile != NULL) {
226     Extensions[i].exports->TTXOpenFile(hooks);
227 maya 3227 }
228     }
229     }
230    
231 zmatsuo 9223 void PASCAL TTXOpenFile(void)
232     {
233 zmatsuo 9226 static TTXFileHooks FileHooks = {
234     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
235     };
236     TTXInternalOpenFile(&FileHooks);
237 zmatsuo 9223 }
238    
239     static void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) {
240 maya 3227 int i;
241    
242     for (i = NumExtensions - 1; i >= 0; i--) {
243 zmatsuo 9226 if (Extensions[i].exports->TTXCloseFile != NULL) {
244     Extensions[i].exports->TTXCloseFile(hooks);
245 maya 3227 }
246     }
247     }
248    
249 zmatsuo 9223 void PASCAL TTXCloseFile(void)
250     {
251 zmatsuo 9226 static TTXFileHooks FileHooks = {
252     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
253     };
254     TTXInternalCloseFile(&FileHooks);
255 zmatsuo 9223 }
256    
257     static void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) {
258 maya 3227 int i;
259    
260     for (i = 0; i < NumExtensions; i++) {
261 zmatsuo 9226 if (Extensions[i].exports->TTXGetUIHooks != NULL) {
262     Extensions[i].exports->TTXGetUIHooks(hooks);
263 maya 3227 }
264     }
265     }
266    
267 zmatsuo 9223 void PASCAL TTXGetUIHooks(void)
268     {
269 zmatsuo 9226 static TTXUIHooks UIHooks = {
270     &SetupTerminal, &SetupWin, &SetupKeyboard, &SetupSerialPort,
271     &SetupTCPIP, &GetHostName, &ChangeDirectory, &AboutDialog,
272     &ChooseFontDlg, &SetupGeneral, &WindowWindow
273     };
274     TTXInternalGetUIHooks(&UIHooks);
275 zmatsuo 9223 }
276    
277     static void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) {
278 maya 3227 int i;
279    
280     for (i = NumExtensions - 1; i >= 0; i--) {
281 zmatsuo 9226 if (Extensions[i].exports->TTXGetSetupHooks != NULL) {
282     Extensions[i].exports->TTXGetSetupHooks(hooks);
283 maya 3227 }
284     }
285     }
286    
287 zmatsuo 9223 void PASCAL TTXGetSetupHooks(void)
288     {
289 zmatsuo 9226 static TTXSetupHooks SetupHooks = {
290     &ReadIniFile, &WriteIniFile, &ReadKeyboardCnf, &CopyHostList,
291     &AddHostToList, &ParseParam
292     };
293     TTXInternalGetSetupHooks(&SetupHooks);
294 zmatsuo 9223 }
295    
296 doda 6801 void PASCAL TTXSetWinSize(int rows, int cols) {
297 maya 3227 int i;
298    
299     for (i = 0; i < NumExtensions; i++) {
300 zmatsuo 9226 if (Extensions[i].exports->TTXSetWinSize != NULL) {
301     Extensions[i].exports->TTXSetWinSize(rows, cols);
302 maya 3227 }
303     }
304     }
305    
306 doda 6801 void PASCAL TTXModifyMenu(HMENU menu) {
307 maya 3227 int i;
308    
309     for (i = 0; i < NumExtensions; i++) {
310 zmatsuo 9226 if (Extensions[i].exports->TTXModifyMenu != NULL) {
311     Extensions[i].exports->TTXModifyMenu(menu);
312 maya 3227 }
313     }
314     }
315    
316 doda 6801 void PASCAL TTXModifyPopupMenu(HMENU menu) {
317 maya 3227 int i;
318    
319     for (i = 0; i < NumExtensions; i++) {
320 zmatsuo 9226 if (Extensions[i].exports->TTXModifyPopupMenu != NULL) {
321     Extensions[i].exports->TTXModifyPopupMenu(menu);
322 maya 3227 }
323     }
324     }
325    
326 doda 6801 BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) {
327 maya 3227 int i;
328    
329     for (i = NumExtensions - 1; i >= 0; i--) {
330 zmatsuo 9226 if (Extensions[i].exports->TTXProcessCommand != NULL) {
331     if (Extensions[i].exports->TTXProcessCommand(hWin,cmd)) {
332 maya 3227 return TRUE;
333     }
334     }
335     }
336    
337     return FALSE;
338     }
339    
340 zmatsuo 9226 void PASCAL TTXEnd(void)
341     {
342     int i;
343 maya 3227
344 zmatsuo 9226 if (NumExtensions == 0)
345     return;
346 maya 3227
347 zmatsuo 9226 for (i = NumExtensions - 1; i >= 0; i--) {
348     if (Extensions[i].exports->TTXEnd != NULL) {
349     Extensions[i].exports->TTXEnd();
350     }
351     }
352 maya 3227
353 zmatsuo 9226 for (i = 0; i < NumExtensions; i++) {
354     free(Extensions[i].exports);
355     FreeLibrary(Extensions[i].LibHandle);
356     }
357 maya 3227
358 zmatsuo 9226 free(Extensions);
359     Extensions = NULL;
360     NumExtensions = 0;
361 maya 3227 }
362    
363 doda 6801 void PASCAL TTXSetCommandLine(PCHAR cmd, int cmdlen, PGetHNRec rec) {
364 maya 3227 int i;
365    
366     for (i = 0; i < NumExtensions; i++) {
367 zmatsuo 9226 if (Extensions[i].exports->TTXSetCommandLine != NULL) {
368     Extensions[i].exports->TTXSetCommandLine(cmd, cmdlen, rec);
369 maya 3227 }
370     }
371     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26