OpenCBM
lib/plugin/xum1541/WINDOWS/install.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2008 Spiro Trikaliotis
8 */
9 
19 #include <windows.h>
20 #include <windowsx.h>
21 
23 #define DBG_USERMODE
24 
26 #ifndef DBG_PROGNAME
27  #define DBG_PROGNAME "OPENCBM-XUM1541.DLL"
28 #endif // #ifndef DBG_PROGNAME
29 
30 #include "debug.h"
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 
35 #include <getopt.h>
36 
37 #include "cbmioctl.h"
38 #include "libmisc.h"
39 #include "version.h"
40 
41 #define OPENCBM_PLUGIN 1
43 #include "archlib.h"
44 #include "archlib-windows.h"
45 
46 
48 typedef
49 struct xu1541_parameter_s
50 {
52  osversion_t OsVersion;
53 
55 
56 
57 static const struct option longopts[] =
58 {
59  { "help", no_argument, NULL, 'h' },
60  { "version", no_argument, NULL, 'V' },
61 
62  { NULL, 0, NULL, 0 }
63 };
64 
65 static const char shortopts[] = "-hV";
66 
67 static const char usagetext[] =
68  "\n\nUsage: instcbm [options] xum1541 [plugin-options]\n"
69  "Install the XUM1541 plugin and driver on the system, or remove it.\n"
70  "\n"
71  "plugin-options is one of:\n"
72  " -h, --help display this help and exit\n"
73  " -V, --version display version information about cbm4win\n"
74  "\n";
75 
76 
77 static opencbm_plugin_install_neededfiles_t NeededFilesXUM1541[] =
78 {
79  { SYSTEM_DIR, "opencbm-xum1541.dll", NULL },
80  { LIST_END, "", NULL }
81 };
82 
85 static void
86 hint(void)
87 {
88  fprintf(stderr, "Try \"instcbm xum1541 --help\" for more information.\n");
89 }
90 
91 
94 static VOID
95 version(VOID)
96 {
97  printf("opencbm xum1541 plugin version " /* OPENCBM_VERSION */ ", built on " __DATE__ " at " __TIME__ "\n");
98 }
99 
102 static void
103 usage(void)
104 {
105  version();
106 
107  printf("%s", usagetext);
108 }
109 
110 
142 static BOOL
143 processNumber(const PCHAR Argument, PCHAR *NextChar, PBOOL ParameterGiven, PULONG ParameterValue)
144 {
145  PCHAR p;
146  BOOL error;
147  int base;
148 
149  FUNC_ENTER();
150 
151  DBG_ASSERT(ParameterValue != NULL);
152 
153  error = FALSE;
154  p = Argument;
155 
156  if (p)
157  {
158  // Find out which base to use (0***, 0x***, or anything else)
159 
160  switch (*p)
161  {
162  case 0:
163  error = TRUE;
164  break;
165 
166  case '0':
167  switch (*++p)
168  {
169  case 'x': case 'X':
170  base = 16;
171  ++p;
172  break;
173 
174  default:
175  base = 8;
176  break;
177  };
178  break;
179 
180  default:
181  base = 10;
182  break;
183  }
184 
185  // Convert the value
186 
187  if (!error)
188  {
189  *ParameterValue = strtoul(p, &p, base);
190 
191  if (NextChar)
192  {
193  error = ((*p != 0) && (*p != ',')) ? TRUE : FALSE;
194  }
195  else
196  {
197  error = *p != 0 ? TRUE : FALSE;
198  }
199 
200  if (!error)
201  {
202  if (NextChar != NULL)
203  {
204  *NextChar = p + ((*p) ? 1 : 0);
205  }
206 
207  if (ParameterGiven != NULL)
208  {
209  *ParameterGiven = TRUE;
210  }
211  }
212  }
213  }
214 
215  FUNC_LEAVE_BOOL(error);
216 }
217 
218 /*-------------------------------------------------------------------*/
219 /*--------- OPENCBM INSTALL HELPER FUNCTIONS ------------------------*/
220 
227 unsigned int CBMAPIDECL
229 {
230  int error = 0;
231  char **localOptarg = Data->OptArg;
232 
233  xu1541_parameter_t *parameter = Data->OptionMemory;
234 
235  BOOL quitLocalProcessing = FALSE;
236 
237  FUNC_ENTER();
238 
239  DBG_ASSERT(Data);
240 
241 
242  do {
243  int c;
244 
245  /* special handling for first call: Determine the length of the OptionMemory to be allocated */
246 
247  if (Data->Argc == 0) {
248  error = sizeof(xu1541_parameter_t);
249  break;
250  }
251 
252  DBG_ASSERT(Data->OptionMemory != NULL);
253  DBG_ASSERT(Data->GetoptLongCallback != NULL);
254  DBG_ASSERT(Data->OptInd != NULL);
255  DBG_ASSERT(Data->OptErr != NULL);
256  DBG_ASSERT(Data->OptOpt != NULL);
257  DBG_ASSERT(Data->InstallParameter != NULL);
258 
259  /* as we are interested in the OS version for installation, copy it */
260 
261  parameter->OsVersion = Data->InstallParameter->OsVersion;
262 
263  if (Data->Argv) {
264  while ( ! quitLocalProcessing && (c = Data->GetoptLongCallback(Data->Argc, Data->Argv, shortopts, longopts)) != -1) {
265  switch (c) {
266  case 'h':
267  usage();
268  Data->InstallParameter->NoExecute = TRUE;
269  break;
270 
271  case 'V':
272  version();
273  Data->InstallParameter->NoExecute = TRUE;
274  break;
275 
276  case 1:
277  quitLocalProcessing = 1;
278  -- * Data->OptInd;
279  break;
280 
281  default:
282  fprintf(stderr, "error...\n");
283  error = TRUE;
284  hint();
285  break;
286  }
287  }
288  }
289 
290  } while (0);
291 
292  FUNC_LEAVE_UINT(error);
293 }
294 
301 BOOL CBMAPIDECL
303 {
304  BOOL error = TRUE;
305 
306  FUNC_ENTER();
307 
308  DBG_PRINT((DBG_PREFIX "-- xum1541.install" ));
309 
310  do {
311  error = FALSE;
312  } while (0);
313 
314  FUNC_LEAVE_BOOL(error);
315 }
316 
323 BOOL CBMAPIDECL
325 {
326  BOOL error = TRUE;
327 
328  FUNC_ENTER();
329 
330  DBG_PRINT((DBG_PREFIX "-- xum1541.uninstall" ));
331 
332  do {
333  error = FALSE;
334  } while (0);
335 
336  FUNC_LEAVE_BOOL(error);
337 }
338 
347 unsigned int CBMAPIDECL
348 opencbm_plugin_install_get_needed_files(CbmPluginInstallProcessCommandlineData_t * Data, opencbm_plugin_install_neededfiles_t * Destination)
349 {
350  unsigned int size = sizeof(NeededFilesXUM1541);
351  xu1541_parameter_t *parameter = Data->OptionMemory;
352 
353  FUNC_ENTER();
354 
355  do {
356  if (NULL == Destination) {
357  break;
358  }
359 
360  memcpy(Destination, NeededFilesXUM1541, size);
361 
362  } while (0);
363 
364  FUNC_LEAVE_UINT(size);
365 }
BOOL CBMAPIDECL opencbm_plugin_install_do_install(void *Context)
@@@
Define makros for debugging purposes.
The parameter which are given on the command-line.
struct CbmPluginInstallProcessCommandlineData_s CbmPluginInstallProcessCommandlineData_t
Definition: instcbm.h:25
#define CBMAPIDECL
Definition: opencbm.h:85
Define the IOCTL codes for the opencbm driver.
#define FUNC_LEAVE_UINT(_xxx)
Definition: debug.h:360
struct xu1541_parameter_s xu1541_parameter_t
The parameter which are given on the command-line.
Definition: getopt.h:94
#define DBG_ASSERT(_xxx)
Definition: debug.h:401
#define FUNC_LEAVE_BOOL(_xxx)
Definition: debug.h:354
BOOL CBMAPIDECL opencbm_plugin_install_do_uninstall(void *Context)
@@@
Defining OpenCBM version.
#define FUNC_ENTER()
Definition: debug.h:347
#define DBG_PREFIX
Definition: debug.h:320
unsigned int CBMAPIDECL opencbm_plugin_install_process_commandline(CbmPluginInstallProcessCommandlineData_t *Data)
@@@
Some functions for string handling.
unsigned int CBMAPIDECL opencbm_plugin_install_get_needed_files(CbmPluginInstallProcessCommandlineData_t *Data, opencbm_plugin_install_neededfiles_t *Destination)
@@@
#define DBG_PRINT(_xxx)
Definition: debug.h:403