Subversion Repositories SvarDOS

Rev

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

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