Subversion Repositories SvarDOS

Rev

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

Rev 538 Rev 990
Line 1... Line 1...
1
/* This file is part of the SvarCOM project and is published under the terms
1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
2
 * of the MIT license.
3
 *
3
 *
4
 * Copyright (C) 2021 Mateusz Viste
4
 * Copyright (C) 2021-2022 Mateusz Viste
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Line 166... Line 166...
166
  unsigned short i;
166
  unsigned short i;
167
  unsigned short copiedcount_in = 0, copiedcount_out = 0; /* number of input/output copied files */
167
  unsigned short copiedcount_in = 0, copiedcount_out = 0; /* number of input/output copied files */
168
  struct DTA *dta = (void *)0x80; /* use DTA at default location in PSP */
168
  struct DTA *dta = (void *)0x80; /* use DTA at default location in PSP */
169
 
169
 
170
  if (cmd_ishlp(p)) {
170
  if (cmd_ishlp(p)) {
171
    outputnl("Copies one or more files to another location.");
171
    nls_outputnl(38,0); /* "Copies one or more files to another location." */
172
    outputnl("");
172
    outputnl("");
173
    outputnl("COPY [/A|/B] source [/A|/B] [+source [/A|/B] [+...]] [destination [/A|/B]] [/V]");
173
    nls_outputnl(38,1); /* "COPY [/A|/B] source [/A|/B] [+source [/A|/B] [+...]] [destination [/A|/B]] [/V]" */
174
    outputnl("");
174
    outputnl("");
175
    outputnl("source       Specifies the file or files to be copied");
175
    nls_outputnl(38,2); /* "source       Specifies the file or files to be copied" */
176
    outputnl("/A           Indicates an ASCII text file");
176
    nls_outputnl(38,3); /* "/A           Indicates an ASCII text file" */
177
    outputnl("/B           Indicates a binary file");
177
    nls_outputnl(38,4); /* "/B           Indicates a binary file" */
178
    outputnl("destination  Specifies the directory and/or filename for the new file(s)");
178
    nls_outputnl(38,5); /* "destination  Specifies the directory and/or filename for the new file(s)" */
179
    outputnl("/V           Verifies that new files are written correctly");
179
    nls_outputnl(38,6); /* "/V           Verifies that new files are written correctly" */
180
    outputnl("");
180
    outputnl("");
181
    outputnl("To append files, specify a single file for destination, but multiple files");
181
    nls_outputnl(38,7); /* "To append files, specify a single file for destination, but multiple (...)" */
182
    outputnl("for source (using wildcards or file1+file2+file3 format).");
-
 
183
    outputnl("");
182
    outputnl("");
184
    outputnl("NOTE: /A and /B are no-ops (ignored), provided only for compatibility reasons.");
183
    nls_outputnl(38,8); /* "NOTE: /A and /B are no-ops, provided only for compatibility reasons" */
185
    return(CMD_OK);
184
    return(CMD_OK);
186
  }
185
  }
187
 
186
 
188
  /* parse cmdline and fill the setup struct accordingly */
187
  /* parse cmdline and fill the setup struct accordingly */
189
 
188
 
Line 204... Line 203...
204
          setup->src_asciimode[setup->src_count - 1] = setup->last_asciimode;
203
          setup->src_asciimode[setup->src_count - 1] = setup->last_asciimode;
205
        }
204
        }
206
      } else if (imatch(p->argv[i], "/v")) {
205
      } else if (imatch(p->argv[i], "/v")) {
207
        setup->verifyflag = 1;
206
        setup->verifyflag = 1;
208
      } else {
207
      } else {
209
        outputnl("Invalid switch");
208
        nls_outputnl(0,2); /* "Invalid switch" */
210
        return(CMD_FAIL);
209
        return(CMD_FAIL);
211
      }
210
      }
212
      continue;
211
      continue;
213
    }
212
    }
214
 
213
 
215
    /* not a switch - must be either a source, a destination or a + */
214
    /* not a switch - must be either a source, a destination or a + */
216
    if (p->argv[i][0] == '+') {
215
    if (p->argv[i][0] == '+') {
217
      /* a plus cannot appear after destination or before first source */
216
      /* a plus cannot appear after destination or before first source */
218
      if ((setup->dst[0] != 0) || (setup->src_count == 0)) {
217
      if ((setup->dst[0] != 0) || (setup->src_count == 0)) {
219
        outputnl("Invalid syntax");
218
        nls_outputnl(0,1); /* "Invalid syntax" */
220
        return(CMD_FAIL);
219
        return(CMD_FAIL);
221
      }
220
      }
222
      setup->lastitemwasplus = 1;
221
      setup->lastitemwasplus = 1;
223
      /* a plus may be immediately followed by a filename - if so, emulate
222
      /* a plus may be immediately followed by a filename - if so, emulate
224
       * a new argument */
223
       * a new argument */
Line 238... Line 237...
238
      continue;
237
      continue;
239
    }
238
    }
240
 
239
 
241
    /* must be a dst then */
240
    /* must be a dst then */
242
    if (setup->dst[0] != 0) {
241
    if (setup->dst[0] != 0) {
243
      outputnl("Invalid syntax");
242
      nls_outputnl(0,1); /* "Invalid syntax" */
244
      return(CMD_FAIL);
243
      return(CMD_FAIL);
245
    }
244
    }
246
    if (file_truename(p->argv[i], setup->dst) != 0) {
245
    if (file_truename(p->argv[i], setup->dst) != 0) {
247
      outputnl("Invalid destination");
246
      nls_outputnl(0,8); /* "Invalid destination" */
248
      return(CMD_FAIL);
247
      return(CMD_FAIL);
249
    }
248
    }
250
    setup->dst_asciimode = setup->last_asciimode;
249
    setup->dst_asciimode = setup->last_asciimode;
251
    /* if dst is a directory then append a backslash */
250
    /* if dst is a directory then append a backslash */
252
    setup->dstlen = path_appendbkslash_if_dir(setup->dst);
251
    setup->dstlen = path_appendbkslash_if_dir(setup->dst);
Line 264... Line 263...
264
  printf("verify: %s\r\n", (setup->verifyflag)?"ON":"OFF");
263
  printf("verify: %s\r\n", (setup->verifyflag)?"ON":"OFF");
265
  #endif
264
  #endif
266
 
265
 
267
  /* must have at least one source */
266
  /* must have at least one source */
268
  if (setup->src_count == 0) {
267
  if (setup->src_count == 0) {
269
    outputnl("Required parameter missing");
268
    nls_outputnl(0,7); /* "Required parameter missing" */
270
    return(CMD_FAIL);
269
    return(CMD_FAIL);
271
  }
270
  }
272
 
271
 
273
  /* perform the operation based on setup directives:
272
  /* perform the operation based on setup directives:
274
   * iterate over every source and copy it to dest */
273
   * iterate over every source and copy it to dest */
Line 354... Line 353...
354
      copiedcount_in++;
353
      copiedcount_in++;
355
    } while (findnext(dta) == 0);
354
    } while (findnext(dta) == 0);
356
 
355
 
357
  }
356
  }
358
 
357
 
359
  sprintf(setup->databuf, "%u file(s) copied", copiedcount_out);
358
  sprintf(setup->databuf, svarlang_str(38,9)/*"%u file(s) copied"*/, copiedcount_out);
360
  outputnl(setup->databuf);
359
  outputnl(setup->databuf);
361
 
360
 
362
  return(CMD_OK);
361
  return(CMD_OK);
363
}
362
}