Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/ttplug.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9223 - (hide annotations) (download) (as text)
Tue Apr 27 16:09:59 2021 UTC (2 years, 11 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/ttplug.c
File MIME type: text/x-csrc
File size: 10397 byte(s)
ttplugin.h のマクロ展開を関数呼び出しに変更

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

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