Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 402 → Rev 403

/svarcom/trunk/cmd/copy.c
0,0 → 1,129
/*
* copy
*/
 
/* /A - Used to copy ASCII files. Applies to the filename preceding it and to
* all following filenames. Files will be copied until an end-of-file mark is
* encountered in the file being copied. If an end-of-file mark is encountered
* in the file, the rest of the file is not copied. DOS will append an EOF
* mark at the end of the copied file.
*
* /B - Used to copy binary files. Applies to the filename preceding it and to
* all following filenames. Copied files will be read by size (according to
* the number of bytes indicated in the file`s directory listing). An EOF mark
* is not placed at the end of the copied file.
*
* /V - Checks after the copy to assure that a file was copied correctly. If
* the copy cannot be verified, the program will display an error message.
* Using this option will result in a slower copying process.
*/
 
struct copy_setup {
const char *src[64];
unsigned short src_count; /* how many sources are declared */
const char *dst;
char src_asciimode[64];
char dst_asciimode;
char last_asciimode; /* /A or /B impacts the file preceding it and becomes the new default for all files that follow */
char verifyflag;
char lastitemwasplus;
char databuf[BUFFER_SIZE - 512];
};
 
static int cmd_copy(struct cmd_funcparam *p) {
struct copy_setup *setup = (void *)(p->BUFFER);
unsigned short i;
 
if (cmd_ishlp(p)) {
outputnl("Copies one or more files to another location.");
outputnl("");
outputnl("COPY [/A|/B] source [/A|/B] [+source [/A|/B] [+...]] [destination [/A|/B]] [/V]");
outputnl("");
outputnl("source Specifies the file or files to be copied");
outputnl("/A Indicates an ASCII text file");
outputnl("/B Indicates a binary file");
outputnl("destination Specifies the directory and/or filename for the new file(s)");
outputnl("/V Verifies that new files are written correctly");
outputnl("");
outputnl("To append files, specify a single file for destination, but multiple files");
outputnl("for source (using wildcards or file1+file2+file3 format).");
return(-1);
}
 
/* parse cmdline and fill the setup struct accordingly */
 
memset(setup, 0, sizeof(*setup));
 
for (i = 0; i < p->argc; i++) {
 
/* switch? */
if (p->argv[i][0] == '/') {
if ((imatch(p->argv[i], "/a")) || (imatch(p->argv[i], "/b"))) {
setup->last_asciimode = 'b';
if (imatch(p->argv[i], "/a")) setup->last_asciimode = 'a';
/* */
if (setup->dst != NULL) {
setup->dst_asciimode = setup->last_asciimode;
} else if (setup->src_count != 0) {
setup->src_asciimode[setup->src_count - 1] = setup->last_asciimode;
}
} else if (imatch(p->argv[i], "/v")) {
setup->verifyflag = 1;
} else {
outputnl("Invalid switch");
return(-1);
}
continue;
}
 
/* not a switch - must be either a source, a destination or a + */
if (p->argv[i][0] == '+') {
/* a plus cannot appear after destination or before first source */
if ((setup->dst != NULL) || (setup->src_count == 0)) {
outputnl("Invalid syntax");
return(-1);
}
setup->lastitemwasplus = 1;
/* a plus may be immediately followed by a filename - if so, emulate
* a new argument */
if (p->argv[i][1] != 0) {
p->argv[i] += 1;
i--;
}
continue;
}
 
/* src? (first non-switch or something that follows a +) */
if ((setup->lastitemwasplus) || (setup->src_count == 0)) {
setup->src[setup->src_count] = p->argv[i];
setup->src_asciimode[setup->src_count] = setup->last_asciimode;
setup->src_count++;
setup->lastitemwasplus = 0;
continue;
}
 
/* must be a dst then */
if (setup->dst != NULL) {
outputnl("Invalid syntax");
return(-1);
}
setup->dst = p->argv[i];
setup->dst_asciimode = setup->last_asciimode;
}
 
/* DEBUG: output setup content ("if 1" to enable) */
#if 1
printf("src: ");
for (i = 0; i < setup->src_count; i++) {
if (i != 0) printf(", ");
printf("%s [%c]", setup->src[i], setup->src_asciimode[i]);
}
printf("\r\n");
printf("dst: %s [%c]\r\n", setup->dst, setup->dst_asciimode);
printf("verify: %s\r\n", (setup->verifyflag)?"ON":"OFF");
#endif
 
/* TODO perform the operation based on setup directives */
 
return(-1);
}
/svarcom/trunk/cmd/dir.c
119,16 → 119,17
 
if ((flags & DIR_FLAG_BARE) == 0) {
unsigned char drv = p->BUFFER[0];
char *buff2 = p->BUFFER + (BUFFER_SIZE / 2);
if (drv >= 'a') {
drv -= 'a';
} else {
drv -= 'A';
}
cmd_vol_internal(drv, p->BUFFER + 1024);
sprintf(p->BUFFER + 1024, "Directory of %s", p->BUFFER);
cmd_vol_internal(drv, buff2);
sprintf(buff2, "Directory of %s", p->BUFFER);
/* trim at first '?', if any */
for (i = 0; p->BUFFER[i + 1024] != 0; i++) if (p->BUFFER[i + 1024] == '?') p->BUFFER[i + 1024] = 0;
outputnl(p->BUFFER + 1024);
for (i = 0; buff2[i] != 0; i++) if (buff2[i] == '?') buff2[i] = 0;
outputnl(buff2);
outputnl("");
}
 
/svarcom/trunk/cmd.c
12,6 → 12,8
#include "env.h"
#include "helpers.h"
 
#define BUFFER_SIZE 2048 /* make sure this is not bigger than the static buffer in command.c */
 
struct cmd_funcparam {
int argc; /* number of arguments */
const char *argv[256]; /* pointers to each argument */
18,7 → 20,7
unsigned short env_seg; /* segment of environment block */
unsigned short argoffset; /* offset of cmdline where first argument starts */
const char far *cmdline; /* original cmdline (terminated by \r) */
char BUFFER[1024]; /* a buffer for whatever is needed */
char BUFFER[BUFFER_SIZE]; /* a buffer for whatever is needed */
};
 
/* scans argv for the presence of a "/?" parameter. returns 1 if found, 0 otherwise */
32,6 → 34,7
 
#include "cmd/_notimpl.c"
#include "cmd/cd.c"
#include "cmd/copy.c"
#include "cmd/del.c"
#include "cmd/vol.c" /* must be included before dir.c due to dependency */
#include "cmd/dir.c"
61,7 → 64,7
{"CHCP", cmd_notimpl},
{"CHDIR", cmd_cd},
{"CLS", cmd_notimpl},
{"COPY", cmd_notimpl},
{"COPY", cmd_copy},
{"CTTY", cmd_notimpl},
{"DATE", cmd_notimpl},
{"DEL", cmd_del},
138,10 → 141,10
if (s[si] == 0) break;
/* set argv ptr */
argvlist[argc++] = buff + i;
/* find next space while copying arg to local buffer */
/* find next arg delimiter (spc, null, slash or plus) while copying arg to local buffer */
do {
buff[i++] = s[si++];
} while (s[si] != ' ' && s[si] != 0 && s[si] != '/');
} while (s[si] != ' ' && s[si] != 0 && s[si] != '/' && s[si] != '+');
buff[i++] = 0;
/* is this end of string? */
if (s[si] == 0) break;