-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFILLHD.C
258 lines (181 loc) · 3.94 KB
/
FILLHD.C
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include "stdio.h"
#include "dos.h"
#include "stdlib.h"
#include "string.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define CHDIR_ERR 0
#define RMDIR_ERR 1
#define NAME_ERR 2
#define DEL_ERR 3
#define SET_ATTR_ERR 4
uchar FA_DELETE=(FA_NORMAL|FA_ARCH);
int extended_error_info(void);
char *file_list(void);
int intro(char *directory,uchar ask);
int verify(char *directory);
int handle_error(int error_code);
int kill_dir(char *directory);
int del_star(void);
int go(char *directory);
int command(char *command[],int num_args);
main(int numargs,char *args[])
{
uchar ask;
ask=command(args,numargs);
verify(args[1]);
intro(args[1],ask);
go(args[1]);
}
int help(void)
{
printf("PRUNE.EXE Copyright (c) 1995 Bryce Lobdell\n");
printf("Command Line: PRUNE name [/all] [/s] [/h] [/r] [/u]\n");
printf("\nname: The name of the directory to delete.\n");
printf("/s,h,r: Deletes SYSTEM, HIDDEN, or READ-ONLY files.\n");
printf("/all: Performs the function of /s /h & /r.\n");
printf("/u: Doesn't ask for confirmation to delete the directory.\n\n");
exit(0);
return 0;
}
int command(char *command[],int num_args)
{
uchar def_ret=0;
uchar loop;
extern uchar FA_DELETE;
if (strstr(command[1],"?")!=NULL)
help();
for (loop=2;loop<=num_args;loop++)
{
command[loop]=strupr(command[loop]);
if (strstr(command[loop],"/ALL")!=NULL)
FA_DELETE=FA_DELETE|FA_RDONLY|FA_SYSTEM|FA_HIDDEN;
if (strstr(command[loop],"/U")!=NULL)
FA_DELETE=FA_DELETE|FA_SYSTEM;
if (strstr(command[loop],"/S")!=NULL)
FA_DELETE=FA_DELETE|FA_SYSTEM;
if (strstr(command[loop],"/H")!=NULL)
FA_DELETE=FA_DELETE|FA_HIDDEN;
if (strstr(command[loop],"/U")!=NULL)
def_ret=1;
}
return def_ret;
}
int go(char *directory)
{
int tmp;
kill_dir(directory);
tmp=chdir("..");
if (tmp!=0)
handle_error(CHDIR_ERR);
tmp=rmdir(directory);
if (tmp!=0)
handle_error(CHDIR_ERR);
return 0;
}
int kill_dir(char *directory)
{
int counter;
int tmp;
struct find_t dir;
tmp=chdir(directory);
if (tmp!=0)
handle_error(CHDIR_ERR);
printf("Pruning: %s\n",strupr(directory));
del_star();
tmp=_dos_findfirst("*.*",FA_DIREC,&dir);
while (tmp==0)
{
if ((strstr(dir.name,"..")==NULL)&&(FA_DIREC==(dir.attrib&FA_DIREC))&&(strstr(dir.name,".")==NULL))
{
kill_dir(dir.name);
tmp=chdir("..");
if (tmp!=0)
handle_error(CHDIR_ERR);
tmp=rmdir(dir.name);
if (tmp!=0)
handle_error(CHDIR_ERR);
}
tmp=_dos_findnext(&dir);
}
}
int del_star(void)
{
extern uchar FA_DELETE;
int tmp;
struct find_t file;
tmp=_dos_findfirst("*.*",FA_DELETE,&file);
while (tmp==0)
{
tmp=dos_setfileattr(file.name,FA_NORMAL);
if (tmp!=0)
handle_error(SET_ATTR_ERR);
tmp=remove(file.name);
if (tmp!=0)
handle_error(DEL_ERR);
tmp=_dos_findnext(&file);
}
if (errno!=2)
return 0;
}
int intro(char *directory,uchar ask)
{
char response[2];
puts("Tree Pruner--Copyright 1995 by Bryce Lobdell\n");
if (ask==0)
{
printf("Confirm deletion of %s. [y,N]:",strupr(directory));
fgets(response,2,stdin);
if (strstr(strupr(response),"Y")==NULL)
{
printf("Quitting\n");
exit(0);
}
}
return 0;
}
int handle_error(int error_code)
{
switch (error_code)
{
case CHDIR_ERR:
{
perror("Cannot change directory");
exit(1);
}
case RMDIR_ERR:
{
perror("Cannot remove directory");
exit(2);
}
case NAME_ERR:
{
printf("Invalid Name.");
exit(3);
}
case DEL_ERR:
{
perror("Cannot delete file");
exit(4);
}
case SET_ATTR_ERR:
{
perror("Cannot overide attribute");
exit(5);
}
}
return 0;
}
int verify(char *directory)
{
struct find_t verify_dir;
int tmp;
tmp=_dos_findfirst(directory,FA_DIREC,&verify_dir);
if (tmp!=0)
handle_error(NAME_ERR);
else
return 0;
}
void copy(FILE *infile,FILE *outfile)
{