diff --git a/map.c b/map.c index 6b499b1..b686386 100644 --- a/map.c +++ b/map.c @@ -28,7 +28,7 @@ static void show_map(uint8 *drvstr) if (flags & 0x80) { /* lokal DRIVE */ path[0]= '\\'; if (j < 2){ - strcpy(path, "DISK LW"); + strcpy(path, "maps to a local disk."); } else if (getcurdir(j+1, path+1)) { strcpy(path, "LW !OK"); } @@ -41,7 +41,7 @@ static void show_map(uint8 *drvstr) strcat(servern, "\\"); } else servern[0]='\0'; } - printf("MAP %c: = %s%s\n", (char)j+'A', servern, path); + if (flags & 0x80) printf("Drive %c: %s\n", (char)j+'A', path); else printf("Drive %c: = %s%s\n", (char)j+'A', servern, path); } } } @@ -58,7 +58,7 @@ static void do_map(int drive, NWPATH *nwp) if (flags & 0x80) { /* lokal DRIVE */ path[0]= '\\'; if (drive < 2){ - strcpy(path, "DISK LW"); + strcpy(path, "maps to a local disk."); } else if (getcurdir(drive+1, path+1)) { strcpy(path, "LW !OK"); } @@ -250,6 +250,92 @@ static int show_search(uint8 *drvstr) return(0); } + +static int path_is_drive_path(uint8 *path) +{ + if (!path || !path[0] || path[1] != ':') return(0); + if (path[0] >= 'A' && path[0] <= 'Z') return(1); + if (path[0] >= 'a' && path[0] <= 'z') return(1); + return(0); +} + +static int set_search_native(uint8 *drvstr, NWPATH *nwp, int pathmode) +{ + int result = -1; + SEARCH_VECTOR drives; + SEARCH_VECTOR_ENTRY *p = drives; + int j = 0; + int entry = (*drvstr == 's') ? *(drvstr + 1) : 0; + + get_search_drive_vektor(drives); + + while (p->drivenummer != 0xff && j++ < 16) { + if (!entry && (p->drivenummer + 'A' == *drvstr)) entry = j; + + if (path_is_drive_path(nwp->path) + && p->drivenummer + 'A' == nwp->path[0] + && nwp->path[1] == ':' + && !strcmp(nwp->path + 2, p->dospath)) { + p->drivenummer = 0xfe; + *(p->dospath) = '\0'; + p->flags = 0; + } + + p++; + } + + if (entry > 0) { + if (entry > 16) entry = 16; + + if (pathmode == 2 && entry <= j && entry < 16) { /* insert modus */ + int k = j + 1 - entry; + if (j < 16) { + p++; + k++; + j++; + } + while (k--) { + memcpy(p, p - 1, sizeof(SEARCH_VECTOR_ENTRY)); + --p; + } + } + + if (--entry < j) + p = drives + entry; + else + (p + 1)->drivenummer = 0xff; + + memset(p, 0, sizeof(SEARCH_VECTOR_ENTRY)); + + if (pathmode == 1) { /* delete */ + p->drivenummer = 0xfe; + *(p->dospath) = '\0'; + result = set_search_drive_vektor(drives); + } else if (path_is_drive_path(nwp->path)) { + p->flags = 0; + p->drivenummer = (uint8)(nwp->path[0] - 'A'); + if (nwp->path[0] >= 'a' && nwp->path[0] <= 'z') + p->drivenummer = (uint8)(nwp->path[0] - 'a'); + strmaxcpy(p->dospath, nwp->path + 2, sizeof(p->dospath) - 1); + result = set_search_drive_vektor(drives); + } else { + int dhandle = alloc_permanent_dir_handle(0, nwp->path, 0, NULL); + + if (dhandle >= 0) { + p->flags = 1; /* NetWare search entry */ + p->drivenummer = 0xfe; /* no local DOS drive prefix */ + *(p->dospath) = '\0'; + p->connid = 1; /* current/default connection */ + p->dhandle = (uint8)dhandle; + result = set_search_drive_vektor(drives); + } + } + } + + return(result); +} + + static int set_search(uint8 *drvstr, NWPATH *nwp, int pathmode) { int result=-1; @@ -297,109 +383,19 @@ static int set_search(uint8 *drvstr, NWPATH *nwp, int pathmode) return(result); } - -static int path_slot_from_string(uint8 *s) -{ - if ((*s == 'S' || *s == 's') && isdigit(s[1])) { - int n = atoi((char*)s + 1); - if (n > 0 && n < 32) return(n - 1); - } - return(-1); -} - -static int path_drive_from_nwpath(NWPATH *nwp, uint8 *drvout) -{ - int j; - char wanted[256]; - - strmaxcpy(wanted, nwp->path, sizeof(wanted) - 1); - korrpath(wanted); - upstr(wanted); - - for (j = 0; j < 32; j++) { - uint8 connid = 0; - uint8 dhandle = 0; - uint8 flags = 0; - char path[256]; - - if (get_drive_info(j, &connid, &dhandle, &flags)) continue; - if (!flags || (flags & 0x80) || !connid) continue; - if (get_dir_path(dhandle, path)) continue; - - korrpath(path); - upstr(path); - - if (!strcmp(path, wanted)) { - drvout[0] = (uint8)('A' + j); - drvout[1] = ':'; - drvout[2] = '\0'; - return(0); - } - } - return(-1); -} - -static int do_search_path_native(int slot, NWPATH *nwp, int mode) -{ - uint8 dhandle = 0; - uint8 drive[3]; - - if (slot < 0 || slot >= 32) return(-1); - - if (mode == 1) { - return(del_search_drive(slot)); - } - - /* - * Common login script syntax: - * MAP INS S1:=SYS:PUBLIC - * PATHINS should understand that natively, not LOGIN. - */ - if (!path_drive_from_nwpath(nwp, drive)) { - return(set_search_drive(slot, drive[0])); - } - - if (!alloc_permanent_dir_handle(0, nwp->path, 0, &dhandle)) { - return(set_search_drive(slot, dhandle)); - } - - return(-1); -} - - int func_path(int argc, char *argv[], int mode) { - uint8 drvstr[300]; + uint8 drvstr[22]; NWPATH nwpath; - - if (!ipx_init()) argc = 1; - - if (argc < 2) { - show_map(NULL); - return(0); - } - if (!parse_argv(drvstr, &nwpath, argc, argv, 1, mode)) { - int slot = path_slot_from_string(drvstr); - - if (slot < 0) { - fprintf(stderr, "Cannot interpret line. errcode=-1\n"); - return(0); - } - - if (*(nwpath.path) || mode == 1) { - if (do_search_path_native(slot, &nwpath, mode) < 0) - fprintf(stderr, "Cannot interpret line. errcode=-1\n"); - } - + int result=0; + if (*(nwpath.path) || mode==1) + result=set_search_native(drvstr, &nwpath, mode); if (mode != 1) show_search(drvstr); - - return(0); + return(result); } - - fprintf(stderr, "Cannot interpret line. errcode=-1\n"); - return(0); + return(1); } void remove_nwpathes(void)