Subversion Repositories SvarDOS

Rev

Rev 502 | Rev 538 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 502 Rev 503
Line 46... Line 46...
46
 */
46
 */
47
 
47
 
48
struct copy_setup {
48
struct copy_setup {
49
  const char *src[64];
49
  const char *src[64];
50
  unsigned short src_count; /* how many sources are declared */
50
  unsigned short src_count; /* how many sources are declared */
-
 
51
  char cursrc[256];         /* buffer for currently processed src */
51
  char dst[256];
52
  char dst[256];
52
  unsigned short dstlen;
53
  unsigned short dstlen;
53
  char src_asciimode[64];
54
  char src_asciimode[64];
54
  char dst_asciimode;
55
  char dst_asciimode;
55
  char last_asciimode; /* /A or /B impacts the file preceding it and becomes the new default for all files that follow */
56
  char last_asciimode; /* /A or /B impacts the file preceding it and becomes the new default for all files that follow */
Line 272... Line 273...
272
  /* perform the operation based on setup directives:
273
  /* perform the operation based on setup directives:
273
   * iterate over every source and copy it to dest */
274
   * iterate over every source and copy it to dest */
274
 
275
 
275
  for (i = 0; i < setup->src_count; i++) {
276
  for (i = 0; i < setup->src_count; i++) {
276
    unsigned short t;
277
    unsigned short t;
277
    unsigned short databuflen;
278
    unsigned short cursrclen;
278
    unsigned short pathendoffset;
279
    unsigned short pathendoffset;
279
 
280
 
280
    /* resolve truename of src and write it to buffer */
281
    /* resolve truename of src and write it to buffer */
281
    t = file_truename(setup->src[i], setup->databuf);
282
    t = file_truename(setup->src[i], setup->cursrc);
282
    if (t != 0) {
283
    if (t != 0) {
283
      output(setup->src[i]);
284
      output(setup->src[i]);
284
      output(" - ");
285
      output(" - ");
285
      outputnl(doserr(t));
286
      outputnl(doserr(t));
286
      continue;
287
      continue;
287
    }
288
    }
288
    databuflen = strlen(setup->databuf); /* remember databuf length */
289
    cursrclen = strlen(setup->cursrc); /* remember cursrc length */
289
 
290
 
290
    /* if length zero, skip (not sure why this would be possible, though) */
291
    /* if length zero, skip (not sure why this would be possible, though) */
291
    if (databuflen == 0) continue;
292
    if (cursrclen == 0) continue;
292
 
293
 
293
    /* if src does not end with a backslash AND it is a directory then append a backslash */
294
    /* if src does not end with a backslash AND it is a directory then append a backslash */
294
    databuflen = path_appendbkslash_if_dir(setup->databuf);
295
    cursrclen = path_appendbkslash_if_dir(setup->cursrc);
295
 
296
 
296
    /* if src ends with a '\' then append *.* */
297
    /* if src ends with a '\' then append *.* */
297
    if (setup->databuf[databuflen - 1] == '\\') {
298
    if (setup->cursrc[cursrclen - 1] == '\\') {
298
      strcat(setup->databuf, "*.*");
299
      strcat(setup->cursrc, "*.*");
299
    }
300
    }
300
 
301
 
301
    /* remember where the path in databuf ends */
302
    /* remember where the path in cursrc ends */
302
    for (t = 0; setup->databuf[t] != 0; t++) {
303
    for (t = 0; setup->cursrc[t] != 0; t++) {
303
      if (setup->databuf[t] == '\\') pathendoffset = t + 1;
304
      if (setup->cursrc[t] == '\\') pathendoffset = t + 1;
304
    }
305
    }
305
 
306
 
306
    /* */
307
    /* */
307
    if (findfirst(dta, setup->databuf, 0) != 0) {
308
    if (findfirst(dta, setup->cursrc, 0) != 0) {
308
      continue;
309
      continue;
309
    }
310
    }
310
 
311
 
311
    do {
312
    do {
312
      char appendflag;
313
      char appendflag;
313
      if (dta->attr & DOS_ATTR_DIR) continue; /* skip directories */
314
      if (dta->attr & DOS_ATTR_DIR) continue; /* skip directories */
314
 
315
 
315
      /* compute full path/name of the file */
316
      /* compute full path/name of the file */
316
      strcpy(setup->databuf + pathendoffset, dta->fname);
317
      strcpy(setup->cursrc + pathendoffset, dta->fname);
317
 
318
 
318
      /* if there was no destination, then YOU are the destination now!
319
      /* if there was no destination, then YOU are the destination now!
319
       * this handles situations like COPY a.txt+b.txt+c.txt */
320
       * this handles situations like COPY a.txt+b.txt+c.txt */
320
      if (setup->dst[0] == NULL) {
321
      if (setup->dst[0] == NULL) {
321
        strcpy(setup->dst, setup->databuf);
322
        strcpy(setup->dst, setup->cursrc);
322
        setup->dstlen = strlen(setup->dst);
323
        setup->dstlen = strlen(setup->dst);
323
        copiedcount_in++;
324
        copiedcount_in++;
324
        copiedcount_out++;
325
        copiedcount_out++;
325
        continue;
326
        continue;
326
      }
327
      }
327
 
328
 
328
      /* is dst ending with a backslash? then append fname to it */
329
      /* is dst ending with a backslash? then append fname to it */
329
      if (setup->dst[setup->dstlen - 1] == '\\') strcpy(setup->dst + setup->dstlen, dta->fname);
330
      if (setup->dst[setup->dstlen - 1] == '\\') strcpy(setup->dst + setup->dstlen, dta->fname);
330
 
331
 
331
      /* now databuf contains the full source and dst contains the full dest... COPY TIME! */
332
      /* now cursrc contains the full source and dst contains the full dest... COPY TIME! */
332
 
333
 
333
      /* if dst file exists already -> overwrite it or append?
334
      /* if dst file exists already -> overwrite it or append?
334
          - if dst is a dir (dstlen-1 points at a \\) -> overwrite
335
          - if dst is a dir (dstlen-1 points at a \\) -> overwrite
335
          - otherwise: if copiedcount_in==0 overwrite, else append */
336
          - otherwise: if copiedcount_in==0 overwrite, else append */
336
      output(setup->databuf);
337
      output(setup->cursrc);
337
      if ((setup->dst[setup->dstlen - 1] == '\\') || (copiedcount_in == 0)) {
338
      if ((setup->dst[setup->dstlen - 1] == '\\') || (copiedcount_in == 0)) {
338
        appendflag = 0;
339
        appendflag = 0;
339
        output(" > ");
340
        output(" > ");
340
        copiedcount_out++;
341
        copiedcount_out++;
341
      } else {
342
      } else {
342
        appendflag = 1;
343
        appendflag = 1;
343
        output(" >> ");
344
        output(" >> ");
344
      }
345
      }
345
      outputnl(setup->dst);
346
      outputnl(setup->dst);
346
 
347
 
347
      // TODO: reusing setup->databuf not good idea: when 2+ files are being copied, the content of the first one overwrites the pathname of the second one!
-
 
348
      t = cmd_copy_internal(setup->dst, 0, setup->databuf, 0, appendflag, setup->databuf, setup->databufsz);
348
      t = cmd_copy_internal(setup->dst, 0, setup->cursrc, 0, appendflag, setup->databuf, setup->databufsz);
349
      if (t != 0) {
349
      if (t != 0) {
350
        outputnl(doserr(t));
350
        outputnl(doserr(t));
351
        return(-1);
351
        return(-1);
352
      }
352
      }
353
 
353