-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGIXrm.c
189 lines (165 loc) · 5.19 KB
/
GIXrm.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
/********************************************************************************************
*
* Remove a list of .db databases
* Delete all the files for the given data bases <name>.db ... (there are a couple
* of hidden . files for each DB, and these are removed too.) Do not use "rm" to
* remove a database.
*
* Author: Gene Myers
* Date : July 2013
*
********************************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "gene_core.h"
static char *Usage = "[-vifg] <source:path>[.1gdb|.gix] ... ";
int main(int argc, char *argv[])
{ int VERBOSE;
int ASK;
int FORCE;
int GDB_TOO;
char *command;
// Process arguments
{ int i, j, k;
int flags[128];
ARG_INIT("GIXrm")
j = 1;
for (i = 1; i < argc; i++)
if (argv[i][0] == '-')
{ ARG_FLAGS("vifg") }
else
argv[j++] = argv[i];
argc = j;
VERBOSE = flags['v'];
ASK = flags['i'];
FORCE = flags['f'];
GDB_TOO = flags['g'];
if (argc <= 1)
{ fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
fprintf(stderr,"\n");
fprintf(stderr," -v: Verbose mode, list what is being deleted.\n");
fprintf(stderr," -i: prompt for each (stub) deletion\n");
fprintf(stderr," -f: force operation quietly\n");
fprintf(stderr," -g: Also delete the associated GDB.\n");
exit (1);
}
if (FORCE)
ASK = VERBOSE = 0;
}
// Determine source and target root names, paths, and extensions
{ char *PATH, *ROOT, *GEXTN;
int HAS_GDB, HAS_GIX;
char *p, *com;
FILE *input;
int c, a, yes;
if (FORCE)
com = "rm -f";
else
com = "rm";
for (c = 1; c < argc; c++)
{ HAS_GDB = HAS_GIX = 0;
PATH = argv[c];
p = rindex(PATH,'/');
if (p == NULL)
{ ROOT = PATH;
PATH = ".";
}
else
{ *p++ = '\0';
ROOT = p;
}
input = fopen(Catenate(PATH,"/",ROOT,".1gdb"),"r");
if (input != NULL)
{ fclose(input);
HAS_GDB = 1;
GEXTN = ".1gdb";
}
else if (strcmp(ROOT+(strlen(ROOT)-5),".1gdb") == 0)
{ HAS_GDB = 1;
ROOT[strlen(ROOT)-5] = '\0';
GEXTN = ".1gdb";
}
else
{ input = fopen(Catenate(PATH,"/",ROOT,".gdb"),"r");
if (input != NULL)
{ fclose(input);
HAS_GDB = 1;
GEXTN = ".gdb";
}
else if (strcmp(ROOT+(strlen(ROOT)-4),".gdb") == 0)
{ HAS_GDB = 1;
ROOT[strlen(ROOT)-4] = '\0';
GEXTN = ".gdb";
}
}
input = fopen(Catenate(PATH,"/",ROOT,".gix"),"r");
if (input != NULL)
{ fclose(input);
HAS_GIX = 1;
}
else if (strcmp(ROOT+(strlen(ROOT)-4),".gix") == 0)
{ HAS_GIX = 1;
ROOT[strlen(ROOT)-4] = '\0';
}
command = Malloc(4*(strlen(PATH)+strlen(ROOT))+100,"Allocating command buffer");
if (HAS_GIX + HAS_GDB * GDB_TOO == 0)
{ if (GDB_TOO)
fprintf(stderr," Warning: there is no GDB or GIX with root %s/%s\n",PATH,ROOT);
else
fprintf(stderr," Warning: there is no GIX with root %s/%s\n",PATH,ROOT);
}
if (HAS_GIX)
{ yes = 1;
if (ASK)
{ printf("Remove %s/%s.gix? ",PATH,ROOT);
fflush(stdout);
yes = 0;
while ((a = getc(stdin)) != '\n')
if (a == 'y' || a == 'Y')
yes = 1;
else if (a == 'n' || a == 'N')
yes = 0;
fflush(stdout);
}
if (yes)
{ if (VERBOSE)
{ fprintf(stderr," Removing %s/%s.gix\n",PATH,ROOT);
fflush(stderr);
}
sprintf(command,"%s %s/%s.gix %s/.%s.ktab.* %s/.%s.post.*",
com,PATH,ROOT,PATH,ROOT,PATH,ROOT);
if (system(command) != 0) goto sys_error;
}
}
if (HAS_GDB && GDB_TOO)
{ yes = 1;
if (ASK)
{ printf("Remove %s/%s%s? ",PATH,ROOT,GEXTN);
fflush(stdout);
yes = 0;
while ((a = getc(stdin)) != '\n')
if (a == 'y' || a == 'Y')
yes = 1;
else if (a == 'n' || a == 'N')
yes = 0;
fflush(stdout);
}
if (yes)
{ if (VERBOSE)
{ fprintf(stderr," Removing %s/%s%s\n",PATH,ROOT,GEXTN);
fflush(stderr);
}
sprintf(command,"%s %s/%s%s %s/.%s.bps",com,PATH,ROOT,GEXTN,PATH,ROOT);
if (system(command) != 0) goto sys_error;
}
}
free(command);
}
}
exit (0);
sys_error:
fprintf(stderr,"%s: Cannot execute command '%s'\n",Prog_Name,command);
exit (1);
}