Subversion Repositories SvarDOS

Rev

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

Rev 418 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
 * copy
26
 * copy
3
 */
27
 */
4
 
28
 
5
/* /A - Used to copy ASCII files. Applies to the filename preceding it and to
29
/* /A - Used to copy ASCII files. Applies to the filename preceding it and to
6
 * all following filenames. Files will be copied until an end-of-file mark is
30
 * all following filenames. Files will be copied until an end-of-file mark is
7
 * encountered in the file being copied. If an end-of-file mark is encountered
31
 * encountered in the file being copied. If an end-of-file mark is encountered
8
 * in the file, the rest of the file is not copied. DOS will append an EOF
32
 * in the file, the rest of the file is not copied. DOS will append an EOF
9
 * mark at the end of the copied file.
33
 * mark at the end of the copied file.
10
 *
34
 *
11
 * /B - Used to copy binary files. Applies to the filename preceding it and to
35
 * /B - Used to copy binary files. Applies to the filename preceding it and to
12
 * all following filenames. Copied files will be read by size (according to
36
 * all following filenames. Copied files will be read by size (according to
13
 * the number of bytes indicated in the file`s directory listing). An EOF mark
37
 * the number of bytes indicated in the file`s directory listing). An EOF mark
14
 * is not placed at the end of the copied file.
38
 * is not placed at the end of the copied file.
15
 *
39
 *
16
 * /V - Checks after the copy to assure that a file was copied correctly. If
40
 * /V - Checks after the copy to assure that a file was copied correctly. If
17
 * the copy cannot be verified, the program will display an error message.
41
 * the copy cannot be verified, the program will display an error message.
18
 * Using this option will result in a slower copying process.
42
 * Using this option will result in a slower copying process.
19
 *
43
 *
20
 * special case: "COPY A+B+C+D" means "append B, C and D files to the A file"
44
 * special case: "COPY A+B+C+D" means "append B, C and D files to the A file"
21
 * if A does not exist, then "append C and D to B", etc.
45
 * if A does not exist, then "append C and D to B", etc.
22
 */
46
 */
23
 
47
 
24
struct copy_setup {
48
struct copy_setup {
25
  const char *src[64];
49
  const char *src[64];
26
  unsigned short src_count; /* how many sources are declared */
50
  unsigned short src_count; /* how many sources are declared */
27
  char dst[256];
51
  char dst[256];
28
  unsigned short dstlen;
52
  unsigned short dstlen;
29
  char src_asciimode[64];
53
  char src_asciimode[64];
30
  char dst_asciimode;
54
  char dst_asciimode;
31
  char last_asciimode; /* /A or /B impacts the file preceding it and becomes the new default for all files that follow */
55
  char last_asciimode; /* /A or /B impacts the file preceding it and becomes the new default for all files that follow */
32
  char verifyflag;
56
  char verifyflag;
33
  char lastitemwasplus;
57
  char lastitemwasplus;
34
  char databuf[BUFFER_SIZE - 1024];
58
  char databuf[BUFFER_SIZE - 1024];
35
};
59
};
36
 
60
 
37
 
61
 
38
/* copies src to dst, overwriting or appending to the destination.
62
/* copies src to dst, overwriting or appending to the destination.
39
 * - copy is performed in ASCII mode if asciiflag set (stop at first EOF in src
63
 * - copy is performed in ASCII mode if asciiflag set (stop at first EOF in src
40
 *   and append an EOF in dst).
64
 *   and append an EOF in dst).
41
 * - returns zero on success, DOS error code on error */
65
 * - returns zero on success, DOS error code on error */
42
unsigned short cmd_copy_internal(const char *dst, char dstascii, const char *src, char srcascii, unsigned char appendflag, void *buff, unsigned short buffsz) {
66
unsigned short cmd_copy_internal(const char *dst, char dstascii, const char *src, char srcascii, unsigned char appendflag, void *buff, unsigned short buffsz) {
43
  unsigned short errcode = 0;
67
  unsigned short errcode = 0;
44
  unsigned short srch = 0xffff, dsth = 0xffff;
68
  unsigned short srch = 0xffff, dsth = 0xffff;
45
  _asm {
69
  _asm {
46
 
70
 
47
    /* open src */
71
    /* open src */
48
    OPENSRC:
72
    OPENSRC:
49
    mov ax, 0x3d00 /* DOS 2+ -- open an existing file, read access mode */
73
    mov ax, 0x3d00 /* DOS 2+ -- open an existing file, read access mode */
50
    mov dx, src    /* ASCIIZ fname */
74
    mov dx, src    /* ASCIIZ fname */
51
    int 0x21       /* CF clear on success, handle in AX */
75
    int 0x21       /* CF clear on success, handle in AX */
52
    mov [srch], ax /* store src handle in memory */
76
    mov [srch], ax /* store src handle in memory */
53
 
77
 
54
    /* check appendflag so I know if I have to try opening dst for append */
78
    /* check appendflag so I know if I have to try opening dst for append */
55
    xor al, al
79
    xor al, al
56
    or al, [appendflag]
80
    or al, [appendflag]
57
    jz CREATEDST
81
    jz CREATEDST
58
 
82
 
59
    /* try opening dst first if appendflag set */
83
    /* try opening dst first if appendflag set */
60
    mov ax, 0x3d01 /* DOS 2+ -- open an existing file, write access mode */
84
    mov ax, 0x3d01 /* DOS 2+ -- open an existing file, write access mode */
61
    mov dx, dst    /* ASCIIZ fname */
85
    mov dx, dst    /* ASCIIZ fname */
62
    int 0x21       /* CF clear on success, handle in AX */
86
    int 0x21       /* CF clear on success, handle in AX */
63
    jc CREATEDST   /* failed to open file (file does not exist) */
87
    jc CREATEDST   /* failed to open file (file does not exist) */
64
    mov [dsth], ax /* store dst handle in memory */
88
    mov [dsth], ax /* store dst handle in memory */
65
 
89
 
66
    /* got file open, LSEEK to end of it now so future data is appended */
90
    /* got file open, LSEEK to end of it now so future data is appended */
67
    mov bx, ax     /* file handle in BX (was still in AX) */
91
    mov bx, ax     /* file handle in BX (was still in AX) */
68
    mov ax, 0x4202 /* DOS 2+ -- set file pointer to end of file + CX:DX */
92
    mov ax, 0x4202 /* DOS 2+ -- set file pointer to end of file + CX:DX */
69
    xor cx, cx     /* offset zero */
93
    xor cx, cx     /* offset zero */
70
    xor dx, dx     /* offset zero */
94
    xor dx, dx     /* offset zero */
71
    int 0x21       /* CF set on error */
95
    int 0x21       /* CF set on error */
72
    jc FAIL
96
    jc FAIL
73
    jmp COPY
97
    jmp COPY
74
 
98
 
75
    /* create dst */
99
    /* create dst */
76
    CREATEDST:
100
    CREATEDST:
77
    mov ah, 0x3c   /* DOS 2+ -- create a file */
101
    mov ah, 0x3c   /* DOS 2+ -- create a file */
78
    mov dx, dst
102
    mov dx, dst
79
    xor cx, cx     /* zero out attributes */
103
    xor cx, cx     /* zero out attributes */
80
    int 0x21       /* handle in AX on success, CF set on error */
104
    int 0x21       /* handle in AX on success, CF set on error */
81
    jc FAIL
105
    jc FAIL
82
    mov [dsth], ax /* store dst handle in memory */
106
    mov [dsth], ax /* store dst handle in memory */
83
 
107
 
84
    /* perform actual copy */
108
    /* perform actual copy */
85
    COPY:
109
    COPY:
86
    /* read a block from src */
110
    /* read a block from src */
87
    mov ah, 0x3f   /* DOS 2+ -- read from file */
111
    mov ah, 0x3f   /* DOS 2+ -- read from file */
88
    mov bx, [srch]
112
    mov bx, [srch]
89
    mov cx, [buffsz]
113
    mov cx, [buffsz]
90
    mov dx, [buff] /* DX points to buffer */
114
    mov dx, [buff] /* DX points to buffer */
91
    int 0x21       /* CF set on error, bytes read in AX (0=EOF) */
115
    int 0x21       /* CF set on error, bytes read in AX (0=EOF) */
92
    jc FAIL        /* abort on error */
116
    jc FAIL        /* abort on error */
93
    /* EOF? (ax == 0) */
117
    /* EOF? (ax == 0) */
94
    test ax, ax
118
    test ax, ax
95
    jz ENDOFFILE
119
    jz ENDOFFILE
96
    /* write block of AX bytes to dst */
120
    /* write block of AX bytes to dst */
97
    mov cx, ax     /* block length */
121
    mov cx, ax     /* block length */
98
    mov ah, 0x40   /* DOS 2+ -- write to file (CX bytes from DS:DX) */
122
    mov ah, 0x40   /* DOS 2+ -- write to file (CX bytes from DS:DX) */
99
    mov bx, [dsth] /* file handle */
123
    mov bx, [dsth] /* file handle */
100
    /* mov dx, [buff] */ /* DX points to buffer already */
124
    /* mov dx, [buff] */ /* DX points to buffer already */
101
    int 0x21       /* CF clear and AX=CX on success */
125
    int 0x21       /* CF clear and AX=CX on success */
102
    jc FAIL
126
    jc FAIL
103
    cmp ax, cx     /* sould be equal, otherwise failed */
127
    cmp ax, cx     /* sould be equal, otherwise failed */
104
    mov ax, 0x08   /* preset to DOS error "Insufficient memory" */
128
    mov ax, 0x08   /* preset to DOS error "Insufficient memory" */
105
    jne FAIL
129
    jne FAIL
106
    jmp COPY
130
    jmp COPY
107
 
131
 
108
    ENDOFFILE:
132
    ENDOFFILE:
109
    /* if dst ascii mode -> add an EOF (ASCII mode not supported for the time being) */
133
    /* if dst ascii mode -> add an EOF (ASCII mode not supported for the time being) */
110
 
134
 
111
    jmp CLOSESRC
135
    jmp CLOSESRC
112
 
136
 
113
    FAIL:
137
    FAIL:
114
    mov [errcode], ax
138
    mov [errcode], ax
115
 
139
 
116
    CLOSESRC:
140
    CLOSESRC:
117
    /* close src and dst */
141
    /* close src and dst */
118
    mov bx, [srch]
142
    mov bx, [srch]
119
    cmp bx, 0xffff
143
    cmp bx, 0xffff
120
    je CLOSEDST
144
    je CLOSEDST
121
    mov ah, 0x3e   /* DOS 2+ -- close a file handle */
145
    mov ah, 0x3e   /* DOS 2+ -- close a file handle */
122
    int 0x21
146
    int 0x21
123
 
147
 
124
    CLOSEDST:
148
    CLOSEDST:
125
    mov bx, [dsth]
149
    mov bx, [dsth]
126
    cmp bx, 0xffff
150
    cmp bx, 0xffff
127
    je DONE
151
    je DONE
128
    mov ah, 0x3e   /* DOS 2+ -- close a file handle */
152
    mov ah, 0x3e   /* DOS 2+ -- close a file handle */
129
    int 0x21
153
    int 0x21
130
 
154
 
131
    DONE:
155
    DONE:
132
  }
156
  }
133
  return(errcode);
157
  return(errcode);
134
}
158
}
135
 
159
 
136
 
160
 
137
static int cmd_copy(struct cmd_funcparam *p) {
161
static int cmd_copy(struct cmd_funcparam *p) {
138
  struct copy_setup *setup = (void *)(p->BUFFER);
162
  struct copy_setup *setup = (void *)(p->BUFFER);
139
  unsigned short i;
163
  unsigned short i;
140
  unsigned short copiedcount_in = 0, copiedcount_out = 0; /* number of input/output copied files */
164
  unsigned short copiedcount_in = 0, copiedcount_out = 0; /* number of input/output copied files */
141
  struct DTA *dta = (void *)0x80; /* use DTA at default location in PSP */
165
  struct DTA *dta = (void *)0x80; /* use DTA at default location in PSP */
142
 
166
 
143
  if (cmd_ishlp(p)) {
167
  if (cmd_ishlp(p)) {
144
    outputnl("Copies one or more files to another location.");
168
    outputnl("Copies one or more files to another location.");
145
    outputnl("");
169
    outputnl("");
146
    outputnl("COPY [/A|/B] source [/A|/B] [+source [/A|/B] [+...]] [destination [/A|/B]] [/V]");
170
    outputnl("COPY [/A|/B] source [/A|/B] [+source [/A|/B] [+...]] [destination [/A|/B]] [/V]");
147
    outputnl("");
171
    outputnl("");
148
    outputnl("source       Specifies the file or files to be copied");
172
    outputnl("source       Specifies the file or files to be copied");
149
    outputnl("/A           Indicates an ASCII text file");
173
    outputnl("/A           Indicates an ASCII text file");
150
    outputnl("/B           Indicates a binary file");
174
    outputnl("/B           Indicates a binary file");
151
    outputnl("destination  Specifies the directory and/or filename for the new file(s)");
175
    outputnl("destination  Specifies the directory and/or filename for the new file(s)");
152
    outputnl("/V           Verifies that new files are written correctly");
176
    outputnl("/V           Verifies that new files are written correctly");
153
    outputnl("");
177
    outputnl("");
154
    outputnl("To append files, specify a single file for destination, but multiple files");
178
    outputnl("To append files, specify a single file for destination, but multiple files");
155
    outputnl("for source (using wildcards or file1+file2+file3 format).");
179
    outputnl("for source (using wildcards or file1+file2+file3 format).");
156
    outputnl("");
180
    outputnl("");
157
    outputnl("NOTE: /A and /B are no-ops (ignored), provided only for compatibility reasons.");
181
    outputnl("NOTE: /A and /B are no-ops (ignored), provided only for compatibility reasons.");
158
    return(-1);
182
    return(-1);
159
  }
183
  }
160
 
184
 
161
  /* parse cmdline and fill the setup struct accordingly */
185
  /* parse cmdline and fill the setup struct accordingly */
162
 
186
 
163
  memset(setup, 0, sizeof(*setup));
187
  memset(setup, 0, sizeof(*setup));
164
 
188
 
165
  for (i = 0; i < p->argc; i++) {
189
  for (i = 0; i < p->argc; i++) {
166
 
190
 
167
    /* switch? */
191
    /* switch? */
168
    if (p->argv[i][0] == '/') {
192
    if (p->argv[i][0] == '/') {
169
      if ((imatch(p->argv[i], "/a")) || (imatch(p->argv[i], "/b"))) {
193
      if ((imatch(p->argv[i], "/a")) || (imatch(p->argv[i], "/b"))) {
170
        setup->last_asciimode = 'b';
194
        setup->last_asciimode = 'b';
171
        if (imatch(p->argv[i], "/a")) setup->last_asciimode = 'a';
195
        if (imatch(p->argv[i], "/a")) setup->last_asciimode = 'a';
172
        /* */
196
        /* */
173
        if (setup->dst[0] != 0) {
197
        if (setup->dst[0] != 0) {
174
          setup->dst_asciimode = setup->last_asciimode;
198
          setup->dst_asciimode = setup->last_asciimode;
175
        } else if (setup->src_count != 0) {
199
        } else if (setup->src_count != 0) {
176
          setup->src_asciimode[setup->src_count - 1] = setup->last_asciimode;
200
          setup->src_asciimode[setup->src_count - 1] = setup->last_asciimode;
177
        }
201
        }
178
      } else if (imatch(p->argv[i], "/v")) {
202
      } else if (imatch(p->argv[i], "/v")) {
179
        setup->verifyflag = 1;
203
        setup->verifyflag = 1;
180
      } else {
204
      } else {
181
        outputnl("Invalid switch");
205
        outputnl("Invalid switch");
182
        return(-1);
206
        return(-1);
183
      }
207
      }
184
      continue;
208
      continue;
185
    }
209
    }
186
 
210
 
187
    /* not a switch - must be either a source, a destination or a + */
211
    /* not a switch - must be either a source, a destination or a + */
188
    if (p->argv[i][0] == '+') {
212
    if (p->argv[i][0] == '+') {
189
      /* a plus cannot appear after destination or before first source */
213
      /* a plus cannot appear after destination or before first source */
190
      if ((setup->dst[0] != 0) || (setup->src_count == 0)) {
214
      if ((setup->dst[0] != 0) || (setup->src_count == 0)) {
191
        outputnl("Invalid syntax");
215
        outputnl("Invalid syntax");
192
        return(-1);
216
        return(-1);
193
      }
217
      }
194
      setup->lastitemwasplus = 1;
218
      setup->lastitemwasplus = 1;
195
      /* a plus may be immediately followed by a filename - if so, emulate
219
      /* a plus may be immediately followed by a filename - if so, emulate
196
       * a new argument */
220
       * a new argument */
197
      if (p->argv[i][1] != 0) {
221
      if (p->argv[i][1] != 0) {
198
        p->argv[i] += 1;
222
        p->argv[i] += 1;
199
        i--;
223
        i--;
200
      }
224
      }
201
      continue;
225
      continue;
202
    }
226
    }
203
 
227
 
204
    /* src? (first non-switch or something that follows a +) */
228
    /* src? (first non-switch or something that follows a +) */
205
    if ((setup->lastitemwasplus) || (setup->src_count == 0)) {
229
    if ((setup->lastitemwasplus) || (setup->src_count == 0)) {
206
      setup->src[setup->src_count] = p->argv[i];
230
      setup->src[setup->src_count] = p->argv[i];
207
      setup->src_asciimode[setup->src_count] = setup->last_asciimode;
231
      setup->src_asciimode[setup->src_count] = setup->last_asciimode;
208
      setup->src_count++;
232
      setup->src_count++;
209
      setup->lastitemwasplus = 0;
233
      setup->lastitemwasplus = 0;
210
      continue;
234
      continue;
211
    }
235
    }
212
 
236
 
213
    /* must be a dst then */
237
    /* must be a dst then */
214
    if (setup->dst[0] != 0) {
238
    if (setup->dst[0] != 0) {
215
      outputnl("Invalid syntax");
239
      outputnl("Invalid syntax");
216
      return(-1);
240
      return(-1);
217
    }
241
    }
218
    if (file_truename(p->argv[i], setup->dst) != 0) {
242
    if (file_truename(p->argv[i], setup->dst) != 0) {
219
      outputnl("Invalid destination");
243
      outputnl("Invalid destination");
220
      return(-1);
244
      return(-1);
221
    }
245
    }
222
    setup->dst_asciimode = setup->last_asciimode;
246
    setup->dst_asciimode = setup->last_asciimode;
223
    /* if dst is a directory then append a backslash */
247
    /* if dst is a directory then append a backslash */
224
    setup->dstlen = path_appendbkslash_if_dir(setup->dst);
248
    setup->dstlen = path_appendbkslash_if_dir(setup->dst);
225
  }
249
  }
226
 
250
 
227
  /* DEBUG: output setup content ("if 1" to enable) */
251
  /* DEBUG: output setup content ("if 1" to enable) */
228
  #if 0
252
  #if 0
229
  printf("src: ");
253
  printf("src: ");
230
  for (i = 0; i < setup->src_count; i++) {
254
  for (i = 0; i < setup->src_count; i++) {
231
    if (i != 0) printf(", ");
255
    if (i != 0) printf(", ");
232
    printf("%s [%c]", setup->src[i], setup->src_asciimode[i]);
256
    printf("%s [%c]", setup->src[i], setup->src_asciimode[i]);
233
  }
257
  }
234
  printf("\r\n");
258
  printf("\r\n");
235
  printf("dst: %s [%c]\r\n", setup->dst, setup->dst_asciimode);
259
  printf("dst: %s [%c]\r\n", setup->dst, setup->dst_asciimode);
236
  printf("verify: %s\r\n", (setup->verifyflag)?"ON":"OFF");
260
  printf("verify: %s\r\n", (setup->verifyflag)?"ON":"OFF");
237
  #endif
261
  #endif
238
 
262
 
239
  /* must have at least one source */
263
  /* must have at least one source */
240
  if (setup->src_count == 0) {
264
  if (setup->src_count == 0) {
241
    outputnl("Required parameter missing");
265
    outputnl("Required parameter missing");
242
    return(-1);
266
    return(-1);
243
  }
267
  }
244
 
268
 
245
  /* perform the operation based on setup directives:
269
  /* perform the operation based on setup directives:
246
   * iterate over every source and copy it to dest */
270
   * iterate over every source and copy it to dest */
247
 
271
 
248
  for (i = 0; i < setup->src_count; i++) {
272
  for (i = 0; i < setup->src_count; i++) {
249
    unsigned short t;
273
    unsigned short t;
250
    unsigned short databuflen;
274
    unsigned short databuflen;
251
    unsigned short pathendoffset;
275
    unsigned short pathendoffset;
252
 
276
 
253
    /* resolve truename of src and write it to buffer */
277
    /* resolve truename of src and write it to buffer */
254
    t = file_truename(setup->src[i], setup->databuf);
278
    t = file_truename(setup->src[i], setup->databuf);
255
    if (t != 0) {
279
    if (t != 0) {
256
      output(setup->src[i]);
280
      output(setup->src[i]);
257
      output(" - ");
281
      output(" - ");
258
      outputnl(doserr(t));
282
      outputnl(doserr(t));
259
      continue;
283
      continue;
260
    }
284
    }
261
    databuflen = strlen(setup->databuf); /* remember databuf length */
285
    databuflen = strlen(setup->databuf); /* remember databuf length */
262
 
286
 
263
    /* if length zero, skip (not sure why this would be possible, though) */
287
    /* if length zero, skip (not sure why this would be possible, though) */
264
    if (databuflen == 0) continue;
288
    if (databuflen == 0) continue;
265
 
289
 
266
    /* if src does not end with a backslash AND it is a directory then append a backslash */
290
    /* if src does not end with a backslash AND it is a directory then append a backslash */
267
    databuflen = path_appendbkslash_if_dir(setup->databuf);
291
    databuflen = path_appendbkslash_if_dir(setup->databuf);
268
 
292
 
269
    /* if src ends with a '\' then append *.* */
293
    /* if src ends with a '\' then append *.* */
270
    if (setup->databuf[databuflen - 1] == '\\') {
294
    if (setup->databuf[databuflen - 1] == '\\') {
271
      strcat(setup->databuf, "*.*");
295
      strcat(setup->databuf, "*.*");
272
    }
296
    }
273
 
297
 
274
    /* remember where the path in databuf ends */
298
    /* remember where the path in databuf ends */
275
    for (t = 0; setup->databuf[t] != 0; t++) {
299
    for (t = 0; setup->databuf[t] != 0; t++) {
276
      if (setup->databuf[t] == '\\') pathendoffset = t + 1;
300
      if (setup->databuf[t] == '\\') pathendoffset = t + 1;
277
    }
301
    }
278
 
302
 
279
    /* */
303
    /* */
280
    if (findfirst(dta, setup->databuf, 0) != 0) {
304
    if (findfirst(dta, setup->databuf, 0) != 0) {
281
      continue;
305
      continue;
282
    }
306
    }
283
 
307
 
284
    do {
308
    do {
285
      char appendflag;
309
      char appendflag;
286
      if (dta->attr & DOS_ATTR_DIR) continue; /* skip directories */
310
      if (dta->attr & DOS_ATTR_DIR) continue; /* skip directories */
287
 
311
 
288
      /* compute full path/name of the file */
312
      /* compute full path/name of the file */
289
      strcpy(setup->databuf + pathendoffset, dta->fname);
313
      strcpy(setup->databuf + pathendoffset, dta->fname);
290
 
314
 
291
      /* if there was no destination, then YOU are the destination now!
315
      /* if there was no destination, then YOU are the destination now!
292
       * this handles situations like COPY a.txt+b.txt+c.txt */
316
       * this handles situations like COPY a.txt+b.txt+c.txt */
293
      if (setup->dst[0] == NULL) {
317
      if (setup->dst[0] == NULL) {
294
        strcpy(setup->dst, setup->databuf);
318
        strcpy(setup->dst, setup->databuf);
295
        setup->dstlen = strlen(setup->dst);
319
        setup->dstlen = strlen(setup->dst);
296
        copiedcount_in++;
320
        copiedcount_in++;
297
        copiedcount_out++;
321
        copiedcount_out++;
298
        continue;
322
        continue;
299
      }
323
      }
300
 
324
 
301
      /* is dst ending with a backslash? then append fname to it */
325
      /* is dst ending with a backslash? then append fname to it */
302
      if (setup->dst[setup->dstlen - 1] == '\\') strcpy(setup->dst + setup->dstlen, dta->fname);
326
      if (setup->dst[setup->dstlen - 1] == '\\') strcpy(setup->dst + setup->dstlen, dta->fname);
303
 
327
 
304
      /* now databuf contains the full source and dst contains the full dest... COPY TIME! */
328
      /* now databuf contains the full source and dst contains the full dest... COPY TIME! */
305
 
329
 
306
      /* if dst file exists already -> overwrite it or append?
330
      /* if dst file exists already -> overwrite it or append?
307
          - if dst is a dir (dstlen-1 points at a \\) -> overwrite
331
          - if dst is a dir (dstlen-1 points at a \\) -> overwrite
308
          - otherwise: if copiedcount_in==0 overwrite, else append */
332
          - otherwise: if copiedcount_in==0 overwrite, else append */
309
      output(setup->databuf);
333
      output(setup->databuf);
310
      if ((setup->dst[setup->dstlen - 1] == '\\') || (copiedcount_in == 0)) {
334
      if ((setup->dst[setup->dstlen - 1] == '\\') || (copiedcount_in == 0)) {
311
        appendflag = 0;
335
        appendflag = 0;
312
        output(" > ");
336
        output(" > ");
313
        copiedcount_out++;
337
        copiedcount_out++;
314
      } else {
338
      } else {
315
        appendflag = 1;
339
        appendflag = 1;
316
        output(" >> ");
340
        output(" >> ");
317
      }
341
      }
318
      outputnl(setup->dst);
342
      outputnl(setup->dst);
319
 
343
 
320
      t = cmd_copy_internal(setup->dst, 0, setup->databuf, 0, appendflag, setup->databuf, sizeof(setup->databuf));
344
      t = cmd_copy_internal(setup->dst, 0, setup->databuf, 0, appendflag, setup->databuf, sizeof(setup->databuf));
321
      if (t != 0) {
345
      if (t != 0) {
322
        outputnl(doserr(t));
346
        outputnl(doserr(t));
323
        return(-1);
347
        return(-1);
324
      }
348
      }
325
 
349
 
326
      copiedcount_in++;
350
      copiedcount_in++;
327
    } while (findnext(dta) == 0);
351
    } while (findnext(dta) == 0);
328
 
352
 
329
  }
353
  }
330
 
354
 
331
  sprintf(setup->databuf, "%u file(s) copied", copiedcount_out);
355
  sprintf(setup->databuf, "%u file(s) copied", copiedcount_out);
332
  outputnl(setup->databuf);
356
  outputnl(setup->databuf);
333
 
357
 
334
  return(-1);
358
  return(-1);
335
}
359
}
336
 
360