-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplugins.c
More file actions
186 lines (150 loc) · 5.02 KB
/
plugins.c
File metadata and controls
186 lines (150 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
#include "plugins.h"
//*****************************************************************************
//define the plugin callback funtion type
typedef void WINAPI (TLDDPCallBack) (char *strCBCompleteText, char *strCBSelText);
//define the two plugin funtion types
typedef void WINAPI __declspec(dllimport) (CALLBACK *PLUGIN_INFO)(unsigned char CaseID, char *buffer, unsigned char maxlength);
typedef void WINAPI __declspec(dllexport) (CALLBACK *PROCESS_TEXT)(unsigned char *CompleteText, unsigned char *SelText, unsigned long *SelStart, unsigned long *SelLength, unsigned long *CursoRow, unsigned long *CursorColum, TLDDPCallBack myCallback);
static int plugoutnum = 0;
static char plugoutfilename[512];
//*****************************************************************************
void WINAPI plugCallBack (char *strCBCompleteText, char *strCBSelText)
{
FILE *fp;
printf("Results:\n%s\n", strCBCompleteText);
printf("selected:\n%s\n", strCBSelText);
if ((!strCBCompleteText || !strlen(strCBCompleteText)) &&
(!strCBSelText || !strlen(strCBSelText)))
{
// Got nothing back from the plugin, so skip the temp file.
strcpy(plugoutfilename, "");
return;
}
fp = fopen(plugoutfilename, "w+");
if (!fp)
{
strcpy(plugoutfilename, "");
return;
}
// Note: I probably should do this line by line and strip out \r chars.
fprintf(fp, strCBCompleteText);
fprintf(fp, "\n");
fprintf(fp, strCBSelText);
fclose(fp);
printf("wrote: %s\n", plugoutfilename);
}
//*****************************************************************************
char *plugin(plugstruct *plug,
unsigned char *CompleteText,
unsigned char *SelText,
unsigned long *SelStart,
unsigned long *SelLength,
unsigned long *CursoRow,
unsigned long *CursorColum)
{
HANDLE hTME=NULL; //DLL handle
PROCESS_TEXT ProcessText;
char *p;
//ensure we are where the DLL will be found
//SetCurrentDirectory(szDLLInThisDirectory);
//load up the DLL
hTME=LoadLibrary(plug->dllname);
if (hTME == NULL)
{
printf("LoadLibrary(%s) == NULL\n", plug->dllname);
return NULL;
}
//get the function we want and lock to our function pointer
ProcessText = (PROCESS_TEXT) GetProcAddress(hTME,"ProcessText");
//error check
if(ProcessText == NULL)
{
FreeLibrary(hTME); //free library after use
printf("ProcessText == NULL\n");
return NULL;
}
strcpy(plugoutfilename, plug->dllname + strlen("plugins\\plugin"));
if ((p = strrchr(plugoutfilename, '.')) != NULL)
*p = 0;
sprintf(plugoutfilename + strlen(plugoutfilename), "%d", ++plugoutnum);
strcat(plugoutfilename, ".ldr");
ProcessText(CompleteText, SelText, SelStart, SelLength,
CursoRow, CursorColum, plugCallBack);
FreeLibrary(hTME); //free library after use
_fpreset(); // Borland DLL fix.
if (strlen(plugoutfilename))
return plugoutfilename;
else
return NULL;
}
//*****************************************************************************
plugstruct *pluginfo(char *dllname)
{
HANDLE hTME=NULL; //DLL handle
PLUGIN_INFO PluginInfo;
plugstruct *plug;
char buffer[256];
//ensure we are where the DLL will be found
//SetCurrentDirectory(szDLLInThisDirectory);
//load up the DLL
hTME=LoadLibrary(dllname);
if (hTME == NULL)
{
printf("LoadLibrary(%s) == NULL\n", dllname);
return NULL;
}
//get the function we want and lock to our function pointer
PluginInfo = (PLUGIN_INFO) GetProcAddress(hTME,"Plugin_Info");
if (PluginInfo == NULL)
{
FreeLibrary(hTME); //free library after use
printf("PluginInfo == NULL\n");
return NULL;
}
plug = (plugstruct *) calloc(sizeof(plugstruct), 1);
if (!plug)
{
FreeLibrary(hTME); //free library after use
return NULL;
}
plug->dllname = strdup(dllname);
buffer[0] = 0;
PluginInfo('\0', buffer, 100);
printf("PluginInfo(0) = %s\n", buffer);
plug->name = strdup(buffer);
buffer[0] = 0;
PluginInfo('\1', buffer, 100);
printf("PluginInfo(1) = %s\n", buffer);
plug->menuentry = strdup(buffer);
buffer[0] = 0;
PluginInfo('\2', buffer, 100);
printf("PluginInfo(2) = %s\n", buffer);
plug->version = strdup(buffer);
buffer[0] = 0;
PluginInfo('\3', buffer, 100);
printf("PluginInfo(3) = %s\n", buffer);
plug->description = strdup(buffer);
buffer[0] = 0;
PluginInfo('\4', buffer, 100);
printf("PluginInfo(4) = %s\n", buffer);
plug->author = strdup(buffer);
buffer[0] = 0;
PluginInfo('\5', buffer, 100);
printf("PluginInfo(5) = %s\n", buffer);
plug->comment = strdup(buffer);
buffer[0] = 0;
PluginInfo('\6', buffer, 100);
printf("PluginInfo(6) = %s\n", buffer);
plug->plugtype = strdup(buffer);
// Plugintype can be one of the following values
// 0 = Plugin can be called always
// 1 = Plugin can only be called if no text is selected
// 2 = Plugin can only be called if a portion of text is selected
FreeLibrary(hTME); //free library after use
_fpreset(); // Borland DLL fix.
return plug;
}