Subversion Repositories SvarDOS

Rev

Rev 397 | Rev 518 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 397 Rev 421
-
 
1
/* This file is part of the SvarCOM project and is published under the terms
-
 
2
 * of the MIT license.
-
 
3
 *
-
 
4
 * Copyright (C) 2021 Mateusz Viste
-
 
5
 *
-
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a
-
 
7
 * copy of this software and associated documentation files (the "Software"),
-
 
8
 * to deal in the Software without restriction, including without limitation
-
 
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
-
 
10
 * and/or sell copies of the Software, and to permit persons to whom the
-
 
11
 * Software is furnished to do so, subject to the following conditions:
-
 
12
 *
-
 
13
 * The above copyright notice and this permission notice shall be included in
-
 
14
 * all copies or substantial portions of the Software.
-
 
15
 *
-
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-
 
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-
 
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-
 
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-
 
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-
 
22
 * DEALINGS IN THE SOFTWARE.
-
 
23
 */
-
 
24
 
1
/*
25
/*
2
 * del/erase
26
 * del/erase
3
 */
27
 */
4
 
28
 
5
static int cmd_del(struct cmd_funcparam *p) {
29
static int cmd_del(struct cmd_funcparam *p) {
6
  const char *delspec = NULL;
30
  const char *delspec = NULL;
7
  unsigned short err = 0;
31
  unsigned short err = 0;
8
  unsigned short confirmflag = 0;
32
  unsigned short confirmflag = 0;
9
  unsigned short i;
33
  unsigned short i;
10
  unsigned short pathlimit = 0;
34
  unsigned short pathlimit = 0;
11
  char *buff = p->BUFFER;
35
  char *buff = p->BUFFER;
12
 
36
 
13
  struct DTA *dta = (void *)0x80; /* use the default DTA at location 80h in PSP */
37
  struct DTA *dta = (void *)0x80; /* use the default DTA at location 80h in PSP */
14
  char *fname = dta->fname;
38
  char *fname = dta->fname;
15
 
39
 
16
  if (cmd_ishlp(p)) {
40
  if (cmd_ishlp(p)) {
17
    outputnl("Deletes one or more files.");
41
    outputnl("Deletes one or more files.");
18
    outputnl("");
42
    outputnl("");
19
    outputnl("DEL [drive:][path]filename [/P]");
43
    outputnl("DEL [drive:][path]filename [/P]");
20
    outputnl("ERASE [drive:][path]filename [/P]");
44
    outputnl("ERASE [drive:][path]filename [/P]");
21
    outputnl("");
45
    outputnl("");
22
    outputnl("[drive:][path]filename  Specifies the file(s) to delete.");
46
    outputnl("[drive:][path]filename  Specifies the file(s) to delete.");
23
    outputnl("/P  Prompts for confirmation before deleting each file.");
47
    outputnl("/P  Prompts for confirmation before deleting each file.");
24
    return(-1);
48
    return(-1);
25
  }
49
  }
26
 
50
 
27
  if (p->argc == 0) {
51
  if (p->argc == 0) {
28
    outputnl("Required parameter missing");
52
    outputnl("Required parameter missing");
29
    return(-1);
53
    return(-1);
30
  }
54
  }
31
 
55
 
32
  /* scan argv for delspec and possible /p or /v */
56
  /* scan argv for delspec and possible /p or /v */
33
  for (i = 0; i < p->argc; i++) {
57
  for (i = 0; i < p->argc; i++) {
34
    /* delspec? */
58
    /* delspec? */
35
    if (p->argv[i][0] == '/') {
59
    if (p->argv[i][0] == '/') {
36
      if (imatch(p->argv[i], "/p")) {
60
      if (imatch(p->argv[i], "/p")) {
37
        confirmflag = 1;
61
        confirmflag = 1;
38
      } else {
62
      } else {
39
        output("Invalid switch:");
63
        output("Invalid switch:");
40
        output(" ");
64
        output(" ");
41
        outputnl(p->argv[i]);
65
        outputnl(p->argv[i]);
42
        return(-1);
66
        return(-1);
43
      }
67
      }
44
    } else if (delspec != NULL) { /* otherwise its a delspec */
68
    } else if (delspec != NULL) { /* otherwise its a delspec */
45
      outputnl("Too many parameters");
69
      outputnl("Too many parameters");
46
      return(-1);
70
      return(-1);
47
    } else {
71
    } else {
48
      delspec = p->argv[i];
72
      delspec = p->argv[i];
49
    }
73
    }
50
  }
74
  }
51
 
75
 
52
  /* convert path to canonical form */
76
  /* convert path to canonical form */
53
  file_truename(delspec, buff);
77
  file_truename(delspec, buff);
54
 
78
 
55
  /* is delspec pointing at a directory? if so, add a \*.* */
79
  /* is delspec pointing at a directory? if so, add a \*.* */
56
  { int attr = file_getattr(delspec);
80
  { int attr = file_getattr(delspec);
57
    if ((attr > 0) && (attr & DOS_ATTR_DIR)) strcat(buff, "\\????????.???");
81
    if ((attr > 0) && (attr & DOS_ATTR_DIR)) strcat(buff, "\\????????.???");
58
  }
82
  }
59
 
83
 
60
  /* parse delspec in buff and remember where last backslash or slash is */
84
  /* parse delspec in buff and remember where last backslash or slash is */
61
  for (i = 0; buff[i] != 0; i++) if (buff[i] == '\\') pathlimit = i + 1;
85
  for (i = 0; buff[i] != 0; i++) if (buff[i] == '\\') pathlimit = i + 1;
62
 
86
 
63
  /* is this about deleting all content inside a directory? if no per-file
87
  /* is this about deleting all content inside a directory? if no per-file
64
   * confirmation set, ask for a global confirmation */
88
   * confirmation set, ask for a global confirmation */
65
  if ((confirmflag == 0) && (imatch(buff + pathlimit, "????????.???"))) {
89
  if ((confirmflag == 0) && (imatch(buff + pathlimit, "????????.???"))) {
66
    outputnl("All files in directory will be deleted!");
90
    outputnl("All files in directory will be deleted!");
67
    if (askchoice("Are you sure (Y/N)?", "YN") != 0) return(-1);
91
    if (askchoice("Are you sure (Y/N)?", "YN") != 0) return(-1);
68
  }
92
  }
69
 
93
 
70
  for (i = 0;; i = 1) {
94
  for (i = 0;; i = 1) {
71
 
95
 
72
    /* exec FindFirst or FindNext */
96
    /* exec FindFirst or FindNext */
73
    if (i == 0) {
97
    if (i == 0) {
74
      err = findfirst(dta, buff, DOS_ATTR_RO | DOS_ATTR_SYS | DOS_ATTR_HID);
98
      err = findfirst(dta, buff, DOS_ATTR_RO | DOS_ATTR_SYS | DOS_ATTR_HID);
75
    } else {
99
    } else {
76
      err = findnext(dta);
100
      err = findnext(dta);
77
    }
101
    }
78
 
102
 
79
    if (err != 0) break;
103
    if (err != 0) break;
80
 
104
 
81
    /* ask if confirmation required: PLIK.TXT  Delete (Y/N)? */
105
    /* ask if confirmation required: PLIK.TXT  Delete (Y/N)? */
82
    if (confirmflag) {
106
    if (confirmflag) {
83
      strcpy(buff + pathlimit, fname); /* note: buff contained the search pattern but it no longer needed so I can reuse it now */
107
      strcpy(buff + pathlimit, fname); /* note: buff contained the search pattern but it no longer needed so I can reuse it now */
84
      output(buff);
108
      output(buff);
85
      output(" \t");
109
      output(" \t");
86
      if (askchoice("Delete (Y/N)?", "YN") != 0) continue;
110
      if (askchoice("Delete (Y/N)?", "YN") != 0) continue;
87
    }
111
    }
88
 
112
 
89
    /* del found file */
113
    /* del found file */
90
    _asm {
114
    _asm {
91
      mov ah, 0x41      /* delete a file, DS:DX points to an ASCIIZ filespec (no wildcards allowed) */
115
      mov ah, 0x41      /* delete a file, DS:DX points to an ASCIIZ filespec (no wildcards allowed) */
92
      mov dx, fname
116
      mov dx, fname
93
      int 0x21
117
      int 0x21
94
      jnc DONE
118
      jnc DONE
95
      mov [err], ax
119
      mov [err], ax
96
      DONE:
120
      DONE:
97
    }
121
    }
98
 
122
 
99
    if (err != 0) {
123
    if (err != 0) {
100
      output(fname);
124
      output(fname);
101
      output(": ");
125
      output(": ");
102
      outputnl(doserr(err));
126
      outputnl(doserr(err));
103
      break;
127
      break;
104
    }
128
    }
105
  }
129
  }
106
  return(-1);
130
  return(-1);
107
}
131
}
108
 
132