Debian Codegraph @

src/ioperm-0.4-patched/admin/ioperm.c

raw
1 /*
2 * $Id: ioperm.c,v 1.4 2003/01/23 15:16:35 telka Exp $
3 *
4 * Copyright (C) 2002 ETC s.r.o.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 *
21 * Written by Marcel Telka <[email protected]>, 2002.
22 *
23 */
24
25 #include <stdio.h>
26 #ifdef __CYGWIN__
27 #define HAVE_POPT_H 1
28 #endif
29
30 #ifdef HAVE_POPT_H
31 #include <popt.h>
32 #endif
33
34 #ifndef PACKAGE
35 #define PACKAGE "ioperm"
36 #endif
37
38 #ifndef PACKAGE_STRING
39 #define PACKAGE_STRING "ioperm 0.4 modified by C.Grenier"
40 #endif
41
42 #include <windows.h>
43
44 int install( int );
45 int uninstall( int );
46
47 int
48 main( int argc, const char **argv )
49 {
50 int i = 0;
51 int u = 0;
52 int v = 0;
53 int verb = 0;
54 OSVERSIONINFO version;
55 #ifdef HAVE_POPT_H
56 poptContext popt_context;
57 int rc;
58 #endif
59
60 #ifdef HAVE_POPT_H
61 struct poptOption options_table[] = {
62 { "install", 'i', POPT_ARG_NONE, &i, 0, "Install ioperm.sys driver", NULL },
63 { "uninstall", 'u', POPT_ARG_NONE, &u, 0, "Uninstall ioperm.sys driver", NULL },
64 { "version", 'V', POPT_ARG_NONE, &v, 0, "Output version information and exit", NULL },
65 { "verbose", 'v', POPT_ARG_NONE, &verb, 0, "Verbose output", NULL },
66 POPT_AUTOHELP
67 POPT_TABLEEND
68 };
69
70 popt_context = poptGetContext( NULL, argc, argv, options_table, 0 );
71 poptSetOtherOptionHelp( popt_context, "[--help] [-V] [-v] [-i|-u]" );
72
73 rc = poptGetNextOpt( popt_context );
74 if (rc != -1) {
75 poptPrintUsage( popt_context, stderr, 0 );
76 poptFreeContext( popt_context );
77 return -1;
78 }
79 #else
80 {
81 int j;
82 for(j=0;j<argc;j++)
83 {
84 if(strcmp(argv[j],"--install")==0 || strcmp(argv[j],"-i")==0)
85 {
86 i=1;
87 }
88 else if(strcmp(argv[j],"--uninstall")==0 || strcmp(argv[j],"-u")==0)
89 {
90 u=1;
91 }
92 else if(strcmp(argv[j],"--version")==0 || strcmp(argv[j],"-V")==0)
93 {
94 v=1;
95 }
96 else if(strcmp(argv[j],"--verbose")==0 || strcmp(argv[j],"-v")==0)
97 {
98 verb=1;
99 }
100 }
101 }
102 #endif
103
104 if (v) {
105 printf(
106 "%s for Cygwin\n"
107 "Copyright (C) 2002, 2003 ETC s.r.o.\n"
108 "%s is free software, covered by the GNU General Public License, and you are\n"
109 "welcome to change it and/or distribute copies of it under certain conditions.\n"
110 "There is absolutely no warranty for %s.\n"
111 "Written by Marcel Telka\n", PACKAGE_STRING, PACKAGE, PACKAGE
112 );
113 #ifdef HAVE_POPT_H
114 poptFreeContext( popt_context );
115 #endif
116 return 0;
117 }
118
119 if (!(i ^ u)) {
120 #ifdef HAVE_POPT_H
121 poptPrintUsage( popt_context, stderr, 0 );
122 poptFreeContext( popt_context );
123 #else
124 printf("Usage: ioperm [--help] [-V] [-v] [-i|-u]\n" \
125 " -i, --install Install ioperm.sys driver\n" \
126 " -u, --uninstall Uninstall ioperm.sys driver\n" \
127 " -V, --version Output version information and exit\n" \
128 " -v, --verbose Verbose output\n" \
129 "\n" \
130 "Help options:\n" \
131 " -?, --help Show this help message\n");
132 #endif
133 return -1;
134 }
135
136 #ifdef HAVE_POPT_H
137 poptFreeContext( popt_context );
138 #endif
139
140 version.dwOSVersionInfoSize = sizeof version;
141 if (!GetVersionEx( &version )) {
142 printf( "Error: Cannot get version info from Windows.\n" );
143 return -1;
144 }
145
146 if (version.dwPlatformId != VER_PLATFORM_WIN32_NT) {
147 if (i)
148 printf( "Installation is not required for non-NT system.\n" );
149 else
150 printf( "Uninstallation is not required for non-NT system.\n" );
151 return 0;
152 }
153
154 if (i)
155 if (!install( verb )) {
156 fprintf( stderr, "Error: ioperm.sys installation failed.\n" );
157 return -1;
158 }
159
160 if (u)
161 if (!uninstall( verb )) {
162 fprintf( stderr, "Error: ioperm.sys uninstallation failed.\n" );
163 return -1;
164 }
165
166 return 0;
167 }