dosutils: use shared case-insensitive string helper
Replace local case-insensitive argument comparison helpers in MAP, SLIST, WHOAMI and NWTESTS with the shared tool_strsame() helper. This removes small duplicate helpers without changing command parsing behavior. Trustee-specific wrappers and the experimental NCOPY code are intentionally left untouched.
This commit is contained in:
20
map.c
20
map.c
@@ -213,18 +213,6 @@ static int parse_pathins_arg(uint8 *drvstr, NWPATH *nwp,
|
||||
static int set_search_native(uint8 *drvstr, NWPATH *nwp, int pathmode);
|
||||
static int show_search(uint8 *drvstr);
|
||||
|
||||
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);
|
||||
@@ -372,13 +360,13 @@ int func_map(int argc, char *argv[], int mode)
|
||||
* 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], "?")) {
|
||||
if (tool_strsame(argv[1], "/?") || tool_strsame(argv[1], "-?") ||
|
||||
tool_strsame(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 (tool_strsame(argv[1], "INS") || tool_strsame(argv[1], "INSERT")) {
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
|
||||
return(1);
|
||||
@@ -386,7 +374,7 @@ int func_map(int argc, char *argv[], int mode)
|
||||
return(map_handle_path_command(argc - 1, argv + 1, 2));
|
||||
}
|
||||
|
||||
if (map_same_arg(argv[1], "DEL") || map_same_arg(argv[1], "DELETE")) {
|
||||
if (tool_strsame(argv[1], "DEL") || tool_strsame(argv[1], "DELETE")) {
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
|
||||
return(1);
|
||||
|
||||
64
nwtests.c
64
nwtests.c
@@ -44,18 +44,6 @@
|
||||
#define TEST_NCP_RIGHT_MODIFY 0x0080
|
||||
#define TEST_NCP_RIGHT_SUPER 0x0100
|
||||
|
||||
static int tests_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 void tests_usage(void)
|
||||
{
|
||||
fprintf(stdout, "Usage: TESTS [NCP87C32ATTR|NCP87C32AUTO|EFFRIGHT path|NCP22S4 path [mask]|NCP23MAP path|NCP22REN old new|RENDIR parent]\n");
|
||||
@@ -207,12 +195,12 @@ static int tests_parse_irm_mask(char *s, uint8 *mask_out)
|
||||
if (!s || !*s || !mask_out)
|
||||
return(-1);
|
||||
|
||||
if (tests_same_arg(s, "ALL")) {
|
||||
if (tool_strsame(s, "ALL")) {
|
||||
*mask_out = 0xff;
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (tests_same_arg(s, "NONE") || tests_same_arg(s, "N")) {
|
||||
if (tool_strsame(s, "NONE") || tool_strsame(s, "N")) {
|
||||
*mask_out = 0x00;
|
||||
return(0);
|
||||
}
|
||||
@@ -1823,7 +1811,7 @@ static void tests_join_child(char *out, int outlen, char *parent, char *child)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (!parent || !*parent || tests_same_arg(parent, ".")) {
|
||||
if (!parent || !*parent || tool_strsame(parent, ".")) {
|
||||
strmaxcpy(out, child, outlen - 1);
|
||||
return;
|
||||
}
|
||||
@@ -2662,27 +2650,27 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return(1);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP87C32ATTR"))
|
||||
if (tool_strsame(argv[1], "NCP87C32ATTR"))
|
||||
return tests_ncp87c32attr();
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP87C32AUTO"))
|
||||
if (tool_strsame(argv[1], "NCP87C32AUTO"))
|
||||
return tests_ncp87c32auto();
|
||||
|
||||
if (tests_same_arg(argv[1], "EFFRIGHT")) {
|
||||
if (tool_strsame(argv[1], "EFFRIGHT")) {
|
||||
if (argc < 3)
|
||||
return tests_effright(".");
|
||||
return tests_effright(argv[2]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP23MAP") ||
|
||||
tests_same_arg(argv[1], "NCP23F")) {
|
||||
if (tool_strsame(argv[1], "NCP23MAP") ||
|
||||
tool_strsame(argv[1], "NCP23F")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp23map(".");
|
||||
return tests_ncp23map(argv[2]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP22REN") ||
|
||||
tests_same_arg(argv[1], "NCP22S2E")) {
|
||||
if (tool_strsame(argv[1], "NCP22REN") ||
|
||||
tool_strsame(argv[1], "NCP22S2E")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp22ren(NULL, NULL);
|
||||
if (argc < 4)
|
||||
@@ -2690,22 +2678,22 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return tests_ncp22ren(argv[2], argv[3]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "RENDIR") ||
|
||||
tests_same_arg(argv[1], "DIRREN") ||
|
||||
tests_same_arg(argv[1], "NCP22RENDIR") ||
|
||||
tests_same_arg(argv[1], "NCP22DIRREN")) {
|
||||
if (tool_strsame(argv[1], "RENDIR") ||
|
||||
tool_strsame(argv[1], "DIRREN") ||
|
||||
tool_strsame(argv[1], "NCP22RENDIR") ||
|
||||
tool_strsame(argv[1], "NCP22DIRREN")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp22rendir(".");
|
||||
return tests_ncp22rendir(argv[2]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP2225MISS")) {
|
||||
if (tool_strsame(argv[1], "NCP2225MISS")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp2225miss(NULL);
|
||||
return tests_ncp2225miss(argv[2]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP2225ATTR")) {
|
||||
if (tool_strsame(argv[1], "NCP2225ATTR")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp2225attr(NULL, NULL);
|
||||
if (argc < 4)
|
||||
@@ -2713,7 +2701,7 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return tests_ncp2225attr(argv[2], argv[3]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP2225TIME")) {
|
||||
if (tool_strsame(argv[1], "NCP2225TIME")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp2225time(NULL, NULL, NULL);
|
||||
if (argc < 5)
|
||||
@@ -2721,7 +2709,7 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return tests_ncp2225time(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP2225ADATE")) {
|
||||
if (tool_strsame(argv[1], "NCP2225ADATE")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp2225adate(NULL, NULL);
|
||||
if (argc < 4)
|
||||
@@ -2729,7 +2717,7 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return tests_ncp2225adate(argv[2], argv[3]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP2225MAXSPACE")) {
|
||||
if (tool_strsame(argv[1], "NCP2225MAXSPACE")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp2225maxspace(NULL, NULL);
|
||||
if (argc < 4)
|
||||
@@ -2737,13 +2725,13 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return tests_ncp2225maxspace(argv[2], argv[3]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP221EINFO")) {
|
||||
if (tool_strsame(argv[1], "NCP221EINFO")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp221einfo(".");
|
||||
return tests_ncp221einfo(argv[2]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP2225MODID")) {
|
||||
if (tool_strsame(argv[1], "NCP2225MODID")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp2225modid(NULL, NULL);
|
||||
if (argc < 4)
|
||||
@@ -2751,7 +2739,7 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return tests_ncp2225modid(argv[2], argv[3]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP2225CREATE")) {
|
||||
if (tool_strsame(argv[1], "NCP2225CREATE")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp2225create(NULL, NULL, NULL, NULL);
|
||||
if (argc < 6)
|
||||
@@ -2759,7 +2747,7 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return tests_ncp2225create(argv[2], argv[3], argv[4], argv[5]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP2225ARCH")) {
|
||||
if (tool_strsame(argv[1], "NCP2225ARCH")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp2225arch(NULL, NULL, NULL, NULL);
|
||||
if (argc < 6)
|
||||
@@ -2767,9 +2755,9 @@ int func_tests(int argc, char *argv[], int mode)
|
||||
return tests_ncp2225arch(argv[2], argv[3], argv[4], argv[5]);
|
||||
}
|
||||
|
||||
if (tests_same_arg(argv[1], "NCP22S4") ||
|
||||
tests_same_arg(argv[1], "MAXRIGHT") ||
|
||||
tests_same_arg(argv[1], "IRM")) {
|
||||
if (tool_strsame(argv[1], "NCP22S4") ||
|
||||
tool_strsame(argv[1], "MAXRIGHT") ||
|
||||
tool_strsame(argv[1], "IRM")) {
|
||||
if (argc < 3)
|
||||
return tests_ncp22s4(".", NULL);
|
||||
if (argc < 4)
|
||||
|
||||
18
slist.c
18
slist.c
@@ -34,22 +34,10 @@ static int usage(void)
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int 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 is_help_arg(char *s)
|
||||
{
|
||||
if (!s) return(0);
|
||||
return(same_arg(s, "/?") || same_arg(s, "-?") || same_arg(s, "?"));
|
||||
return(tool_strsame(s, "/?") || tool_strsame(s, "-?") || tool_strsame(s, "?"));
|
||||
}
|
||||
|
||||
static unsigned long node_to_number(uint8 *addr)
|
||||
@@ -91,8 +79,8 @@ int func_slist(int argc, char *argv[], int mode)
|
||||
if (is_help_arg(argv[i])) return(usage());
|
||||
|
||||
if (argv[i][0] == '/' || argv[i][0] == '-') {
|
||||
if (same_arg(argv[i], "/C") || same_arg(argv[i], "/CONTINUE") ||
|
||||
same_arg(argv[i], "-C") || same_arg(argv[i], "-CONTINUE")) {
|
||||
if (tool_strsame(argv[i], "/C") || tool_strsame(argv[i], "/CONTINUE") ||
|
||||
tool_strsame(argv[i], "-C") || tool_strsame(argv[i], "-CONTINUE")) {
|
||||
continuous = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
27
whoami.c
27
whoami.c
@@ -41,11 +41,6 @@ typedef struct who_nwtime {
|
||||
uint8 wday;
|
||||
} WHO_NWTIME;
|
||||
|
||||
static int who_same(char *a, char *b)
|
||||
{
|
||||
return(tool_strsame(a, b));
|
||||
}
|
||||
|
||||
static int who_usage(void)
|
||||
{
|
||||
fprintf(stdout, "\nUsage:\n");
|
||||
@@ -314,26 +309,26 @@ int func_whoami(int argc, char *argv[], int mode)
|
||||
return(who_usage());
|
||||
|
||||
if (argv[i][0] == '/' || argv[i][0] == '-') {
|
||||
if (who_same(argv[i], "/SECURITY") || who_same(argv[i], "-SECURITY")) {
|
||||
if (tool_strsame(argv[i], "/SECURITY") || tool_strsame(argv[i], "-SECURITY")) {
|
||||
do_security = 1;
|
||||
} else if (who_same(argv[i], "/GROUPS") || who_same(argv[i], "-GROUPS")) {
|
||||
} else if (tool_strsame(argv[i], "/GROUPS") || tool_strsame(argv[i], "-GROUPS")) {
|
||||
do_groups = 1;
|
||||
} else if (who_same(argv[i], "/WORKGROUPS") || who_same(argv[i], "-WORKGROUPS")) {
|
||||
} else if (tool_strsame(argv[i], "/WORKGROUPS") || tool_strsame(argv[i], "-WORKGROUPS")) {
|
||||
do_work = 1;
|
||||
} else if (who_same(argv[i], "/RIGHTS") || who_same(argv[i], "-RIGHTS")) {
|
||||
} else if (tool_strsame(argv[i], "/RIGHTS") || tool_strsame(argv[i], "-RIGHTS")) {
|
||||
do_rights = 1;
|
||||
} else if (who_same(argv[i], "/SYSTEM") || who_same(argv[i], "-SYSTEM") ||
|
||||
who_same(argv[i], "/SYS") || who_same(argv[i], "-SYS")) {
|
||||
} else if (tool_strsame(argv[i], "/SYSTEM") || tool_strsame(argv[i], "-SYSTEM") ||
|
||||
tool_strsame(argv[i], "/SYS") || tool_strsame(argv[i], "-SYS")) {
|
||||
do_system = 1;
|
||||
} else if (who_same(argv[i], "/OBJECT") || who_same(argv[i], "-OBJECT")) {
|
||||
} else if (tool_strsame(argv[i], "/OBJECT") || tool_strsame(argv[i], "-OBJECT")) {
|
||||
do_object = 1;
|
||||
} else if (who_same(argv[i], "/ALL") || who_same(argv[i], "-ALL")) {
|
||||
} else if (tool_strsame(argv[i], "/ALL") || tool_strsame(argv[i], "-ALL")) {
|
||||
do_security = 1;
|
||||
do_groups = 1;
|
||||
do_work = 1;
|
||||
do_rights = 1;
|
||||
} else if (who_same(argv[i], "/CONTINUOUS") || who_same(argv[i], "-CONTINUOUS") ||
|
||||
who_same(argv[i], "/CONTINUE") || who_same(argv[i], "-CONTINUE")) {
|
||||
} else if (tool_strsame(argv[i], "/CONTINUOUS") || tool_strsame(argv[i], "-CONTINUOUS") ||
|
||||
tool_strsame(argv[i], "/CONTINUE") || tool_strsame(argv[i], "-CONTINUE")) {
|
||||
/* accepted for Novell compatibility; paging is not needed here */
|
||||
} else {
|
||||
return(who_usage());
|
||||
@@ -373,7 +368,7 @@ int func_whoami(int argc, char *argv[], int mode)
|
||||
strmaxcpy(s2, server, sizeof(s2) - 1);
|
||||
upstr(s1);
|
||||
upstr(s2);
|
||||
if (!who_same(s1, s2)) {
|
||||
if (!tool_strsame(s1, s2)) {
|
||||
fprintf(stdout, "You are not attached to server %s.\a\n", s1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user