1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <case.h>
6 #include <err.h>
7 
8 #define MAX_STR_LEN 64
9 #define NUM_STRS 6
10 
11 #define STR0 "this string should NEVER show up"
12 #define STR1 ""
13 #define STR2 "az3o%\tW@^#\\\n\r[]{}|\() '\""
14 #define STR3 "az3o%\tw@^#\\\n\r[]{}|\() '\""
15 #define STR4 "AZ3O%\tW@^#\\\n\r[]{}|\() '\""
16 #define STR5 "AZ3O%\tw@^#\\\n\r[]{}|\() '\""
17 
18 
19 int
main(int argc,char ** argv)20 main(int argc, char **argv)
21 {
22     int cmp;
23     char *n1 = NULL;
24     char *n2 = NULL;
25 
26     char s1[MAX_STR_LEN];
27     char s2[MAX_STR_LEN];
28 
29     char strs[NUM_STRS][MAX_STR_LEN] = { STR0,
30         STR1,
31         STR2,
32         STR3,
33         STR4,
34         STR5
35     };
36 
37     if (argc < 2 ||
38         3 == argc ||
39         argc > 4 ||
40         (strcmp(argv[1], "lcase") &&
41          strcmp(argv[1], "ucase") && strcmp(argv[1], "strcmp_nocase")
42         )) {
43         /*printf("INVALID PARAMETERS to chgCase\n"); */
44         exit(1);
45     }
46 
47 
48     if (2 == argc) {
49         if (0 == strcmp(argv[1], "ucase")) {
50             ucase(n1);
51         }
52         else if (0 == strcmp(argv[1], "lcase")) {
53             lcase(n1);
54         }
55         else {
56             strcmp_nocase(n1, n2);
57         }
58         /*
59            if we're still alive we obviously didn't segfault
60          */
61         exit(0);
62     }
63 
64     if (4 == argc) {
65 
66         if (0 >= atoi(argv[2]) ||
67             atoi(argv[2]) >= NUM_STRS ||
68             0 >= atoi(argv[3]) || atoi(argv[3]) >= NUM_STRS) {
69             E_INFO("INVALID PARAMS TO chkCase\n");
70             exit(1);
71         }
72 
73         strcpy(s1, strs[atoi(argv[2])]);
74         strcpy(s2, strs[atoi(argv[3])]);
75 
76         if (0 == strcmp(argv[1], "ucase")) {
77             ucase(s1);
78             cmp = strcmp(s1, s2);
79         }
80         else if (0 == strcmp(argv[1], "lcase")) {
81             lcase(s1);
82             cmp = strcmp(s1, s2);
83         }
84         else {
85             cmp = strcmp_nocase(s1, s2);
86         }
87 
88         /*    E_INFO("Value of cmp %d\n", cmp); */
89         if (0 != cmp) {
90             E_FATAL("test failed\nstr1:|%s|\nstr2:|%s|\n", s1, s2);
91         }
92 
93         return (cmp != 0);
94     }
95 
96     /*somehow we got here and we shouldn't have */
97 
98     exit(1);
99 }
100