This commit is contained in:
Mario Fetka
2026-05-22 20:21:08 +02:00
parent 4d01fbd118
commit b42b0e2a58

113
map.c
View File

@@ -188,11 +188,124 @@ static int parse_argv(uint8 *drvstr, NWPATH *nwpath,
return(0);
}
static int map_same_arg(char *a, char *b)
{
while (*a || *b) {
int ca = *a++;
int cb = *b++;
if (ca >= 'a' && ca <= 'z') ca -= 32;
if (cb >= 'a' && cb <= 'z') cb -= 32;
if (ca != cb) return(0);
}
return(1);
}
static int map_is_drive_arg(char *s)
{
if (!s || !s[0] || s[1] != ':' || s[2]) return(0);
if (s[0] >= 'A' && s[0] <= 'Z') return(1);
if (s[0] >= 'a' && s[0] <= 'z') return(1);
return(0);
}
static int map_drive_index(char *s)
{
if (s[0] >= 'a' && s[0] <= 'z') return(s[0] - 'a');
return(s[0] - 'A');
}
static void map_drive_name(char *dst, char *src)
{
dst[0] = src[0];
if (dst[0] >= 'a' && dst[0] <= 'z') dst[0] -= 32;
dst[1] = ':';
dst[2] = '\0';
}
static int map_handle_path_command(int argc, char *argv[], int pathmode)
{
uint8 drvstr[22];
NWPATH nwpath;
int rc;
rc = parse_pathins_arg(drvstr, &nwpath, argc, argv, pathmode);
if (!rc) {
int result = 0;
if (*(nwpath.path) || pathmode == 1)
result = set_search_native(drvstr, &nwpath, pathmode);
if (result < 0)
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
else if (pathmode != 1)
show_search(drvstr);
else
fprintf(stdout, "The search mapping for drive S%d: was deleted\n",
(int)drvstr[1]);
return(result);
}
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(-1);
}
int func_map(int argc, char *argv[], int mode)
{
uint8 drvstr[22];
NWPATH nwpath;
if (!ipx_init()) argc = 1;
/*
* Novell MAP accepts subcommands through MAP itself:
* MAP DEL H:
* MAP INS S1:=SYS:PUBLIC
* MAP DEL S1:
* The original mars-dosutils exposed those mainly as MAPDEL/PATHINS/PATHDEL,
* so handle the Novell syntax here and then reuse the existing primitives.
*/
if (argc > 1) {
if (map_same_arg(argv[1], "/?") || map_same_arg(argv[1], "-?") ||
map_same_arg(argv[1], "?")) {
fprintf(stderr, "Directory \"/?\" is not locatable.\n");
return(1);
}
if (map_same_arg(argv[1], "INS") || map_same_arg(argv[1], "INSERT")) {
if (argc < 3) {
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(1);
}
return(map_handle_path_command(argc - 1, argv + 1, 2));
}
if (map_same_arg(argv[1], "DEL") || map_same_arg(argv[1], "DELETE")) {
if (argc < 3) {
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(1);
}
if (map_is_drive_arg(argv[2])) {
char dname[3];
int drive = map_drive_index(argv[2]);
if (do_map(drive, &nwpath, 1) < 0) {
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(1);
}
map_drive_name(dname, argv[2]);
fprintf(stdout, "The mapping for drive %s has been deleted.\n", dname);
return(0);
}
return(map_handle_path_command(argc - 1, argv + 1, 1));
}
}
if (!parse_argv(drvstr, &nwpath, argc, argv, 0, mode)) {
if (*(nwpath.path) || mode==1) {
if (do_map(*drvstr - 'A', &nwpath, mode)< 0)