1: #include "hd.h"
2: #include "mydir.h"
3: #include "command.h"
4:
5: #define ISDIR ((scr_stb.st_mode & S_IFMT) == S_IFDIR)
6: #define paction(arg) { \
7: atfile (file, 4);printf (action [cpage][file] ? "//" : " ");}
8:
9: /* User first indicates which files to remove by selecting them
10: with a-t keypresses. Selected files are stored in the action
11: array. When ready, the user presses R, and the files are gone.
12: */
13:
14: static char quitcmds[] = {CR, LF, EOT, 0};
15: static char dircmds [] = {"0123456789;+-uL"};
16:
17: static char *rmmsg[] = {
18: "Select the files you wish to remove, then press -R-",
19: "Press -Return- to leave with out removing files. -?- for more help"
20: };
21:
22: remove () { /* remove (unlink) files */
23:
24: register cmd, file; register char *cp;
25:
26: short starmode;
27: #define OFF 0
28: #define ON 1
29: #define UNDEF 2
30:
31: extern char *index ();
32:
33: char action [mpages][nfpp];
34:
35: if (access (DOT, 3)) {
36: myperror ("Cannot remove files");
37: return FAILURE;
38: }
39: for (cp = &action [0][0]; cp < &action [mpages-1][nfpp];) *cp++ = OFF;
40: dispaction (action);
41: disprmmsg ();
42:
43: for (;;) {
44: at (2380);
45: cmd = getch ();
46: file = cmd - 'a';
47: if (index (quitcmds, cmd) != CNULL) {
48: clearmsg (0); return NOREPLOT;
49: }
50: else if (index (dircmds, cmd) != CNULL) {
51: if (dircmd (cmd) & REPLOT) rmdispdir (action);
52: }
53: else if (cmd == '*') {
54: starmode = UNDEF;
55: for (file = 0; file < pageend; file++) {
56: cp = &action [cpage][file];
57:
58: if (compe (filename (file), DOT));
59: else if (compe (filename (file), DOTDOT));
60:
61: else if (starmode == UNDEF)
62: *cp = starmode = !*cp;
63: else *cp = starmode;
64: }
65: dispaction (action);
66: }
67:
68: else if (cmd == 'R') break;
69: else if (cmd == '?') {
70: if (help (RMHELP) & REPLOT) rmdispdir (action);
71: }
72: else if (cmd >= 'a' && cmd <= 'z' && file < pageend) {
73: if (compe (filename (file), DOT));
74: else if (compe (filename (file), DOTDOT));
75: else {
76: action [cpage][file] ^= 1;
77: paction (file);
78: }
79: }
80: }
81: act (action);
82: return REPLOT;
83: }
84:
85: dispaction (action) char action [mpages][nfpp]; {
86: register file;
87:
88: bufout ();
89: for (file = 0; file < pageend; file++)
90: paction (file);
91: unbufout ();
92: }
93:
94: rmdispdir (action) char action [mpages][nfpp]; {
95: dispdir (0);
96: dispaction (action);
97: disprmmsg ();
98: }
99:
100: disprmmsg () {
101: clearmsg (2);
102: bufout ();
103: printf ("%s\n%s", rmmsg [0], rmmsg [1]);
104: unbufout ();
105: }
106:
107: /* This does the actual removing */
108: act (action) char action [mpages][nfpp]; {
109: register page, file;
110:
111: clearmsg (1);
112: for (page = 1; page <= tpages; page ++)
113: for (file = 0; file < nfpp; file++)
114: if (action [page][file]) {
115:
116: if (page != cpage) {
117: cpage = page; dispdir (0);
118: dispaction (action); clearmsg (1);
119: }
120:
121: atfile (file, 0); printf ("->");
122: at (2301);
123: if (stat (filename (file), &scr_stb)) {
124: myperror (filename (file));
125: if (rmerror ()) return;
126: }
127: else if (ISDIR && f_exec
128: ("/bin/rmdir", "+", filename (file), 0)) {
129: if (rmerror ()) return;
130: }
131: else if (!ISDIR && unlink (filename (file))) {
132: myperror (filename (file));
133: if (rmerror ()) return;
134: }
135: else {
136: atfile (file, 0); clearline ();
137: }
138: };
139: return;
140: }
141: rmerror () { /* Error in removing file */
142: register ch;
143:
144: at (2365); printf ("Press -Return-");
145: ch = getch ();
146: clearmsg (0);
147: return (ch == EOT);
148: }
Defined functions
act
defined in line
108; used 1 times
Defined variables
rmmsg
defined in line
17; used 2 times
Defined macros
ISDIR
defined in line
5; used 2 times
OFF
defined in line
27; used 1 times
ON
defined in line
28;
never used
UNDEF
defined in line
29; used 2 times