1 |
twoaday |
2 |
/* wptConsole.cpp - Console interface |
2 |
|
|
* Copyright (C) 2002 Timo Schulz <[email protected]> |
3 |
|
|
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT 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 WinPT; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include <windows.h> |
22 |
|
|
#include <stdio.h> |
23 |
|
|
|
24 |
|
|
#include "wptTypes.h" |
25 |
|
|
#include "wptErrors.h" |
26 |
|
|
|
27 |
|
|
/* FIXME: Do we really need this? */ |
28 |
|
|
|
29 |
|
|
int |
30 |
|
|
tty_alloc( void ) |
31 |
|
|
{ |
32 |
|
|
return AllocConsole( ); |
33 |
|
|
} /* tty_alloc */ |
34 |
|
|
|
35 |
|
|
void |
36 |
|
|
tty_free( void ) |
37 |
|
|
{ |
38 |
|
|
FreeConsole( ); |
39 |
|
|
} /* tty_free */ |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
int |
43 |
|
|
tty_printf( const char *string ) |
44 |
|
|
{ |
45 |
|
|
HANDLE _stdout = GetStdHandle(STD_OUTPUT_HANDLE); |
46 |
|
|
DWORD nwritten = 0; |
47 |
|
|
int rc = 0; |
48 |
|
|
|
49 |
|
|
rc = WriteFile(_stdout, string, strlen(string), &nwritten, NULL); |
50 |
|
|
if (rc == TRUE) |
51 |
|
|
rc = 0; |
52 |
|
|
return rc; |
53 |
|
|
} /* tty_printf */ |
54 |
|
|
|
55 |
|
|
void |
56 |
|
|
tty_argparse_init(char *cmdline, char **r_arg) |
57 |
|
|
{ |
58 |
|
|
if (cmdline) |
59 |
|
|
*r_arg = strtok( cmdline, " " ); |
60 |
|
|
} /* tty_argparse_init */ |
61 |
|
|
|
62 |
|
|
char* |
63 |
|
|
tty_argparse_next(char **r_arg) |
64 |
|
|
{ |
65 |
|
|
|
66 |
|
|
char *arg = NULL; |
67 |
|
|
|
68 |
|
|
if( r_arg != NULL ) { |
69 |
|
|
arg = strdup( *r_arg ); |
70 |
|
|
*r_arg = strtok( NULL, " " ); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
return arg; |
74 |
|
|
} /* tty_argparse_next */ |
75 |
|
|
|
76 |
|
|
#if 0 |
77 |
|
|
void |
78 |
|
|
tty_parse_args(char *cmdline) |
79 |
|
|
{ |
80 |
|
|
char *arg; |
81 |
|
|
|
82 |
|
|
arg = strtok( cmdline, " "); |
83 |
|
|
while (arg != NULL) { |
84 |
|
|
my_printf(arg); |
85 |
|
|
my_printf("\n"); |
86 |
|
|
arg = strtok( NULL, " " ); |
87 |
|
|
} |
88 |
|
|
} |
89 |
|
|
#endif |
90 |
|
|
|
91 |
|
|
int |
92 |
|
|
tty_command_loop(char *cmdline, int cmd) |
93 |
|
|
{ |
94 |
|
|
char *args, *file; |
95 |
|
|
char err[512]; |
96 |
|
|
int rc = 0; |
97 |
|
|
|
98 |
|
|
tty_alloc(); |
99 |
|
|
tty_argparse_init(cmdline, &args); |
100 |
|
|
while ( (file = tty_argparse_next(&args)) ) { |
101 |
|
|
if ( !file ) |
102 |
|
|
continue; |
103 |
|
|
if ( (strlen(file) > 2 && *file == '-') |
104 |
|
|
|| (strlen(file) > 2 && file[0] == '-' && file[1] == '-' ) ) |
105 |
|
|
continue; |
106 |
|
|
|
107 |
|
|
switch ( cmd ) { |
108 |
|
|
case 0: /* wipe */ |
109 |
|
|
_snprintf(err, sizeof(err)-1, "Wipe '%s' ", file); |
110 |
|
|
tty_printf(err); |
111 |
|
|
rc = secure_unlink(file, WIPE_MODE_DOD); |
112 |
|
|
if (rc) { |
113 |
|
|
_snprintf(err, sizeof(err)-1, "%s", winpt_strerror(rc)); |
114 |
|
|
tty_printf(err); |
115 |
|
|
} |
116 |
|
|
tty_printf("\n"); |
117 |
|
|
break; |
118 |
|
|
} |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
Sleep(1000); |
122 |
|
|
tty_free(); |
123 |
|
|
|
124 |
|
|
return 0; |
125 |
|
|
} |