rpc_server: Avoid casts in DBG statements
[Samba.git] / examples / validchars / validchr.c
blob415546cb84111bfc476c5fad60fa5e3aa1904321
1 /* by tino@augsburg.net
2 */
4 #include <stdio.h>
5 #include <string.h>
7 #include <dirent.h>
9 unsigned char
10 test(void)
12 DIR *dir;
13 struct dirent *dp;
14 unsigned char c;
16 if ((dir=opendir("."))==0)
18 perror("open .");
19 return 0;
21 c = 0;
22 while ((dp=readdir(dir))!=0)
24 size_t len;
26 len = strlen(dp->d_name);
27 if (len<4)
28 continue;
29 if (strcmp(dp->d_name+len-4, ".TST"))
30 continue;
31 if (len!=5)
33 fprintf(stderr, "warning: %s\n", dp->d_name);
34 printf(" length");
35 continue;
37 if (c)
38 printf(" double%d\n", c);
39 c = dp->d_name[0];
41 if (closedir(dir))
42 perror("close .");
43 return c;
46 int
47 main(void)
49 char name[256];
50 unsigned char map[256], upper[256], lower[256];
51 int i, j, c;
52 FILE *fd;
54 if (test())
56 printf("There are *.TST files, please remove\n");
57 return 0;
59 for (i=0; ++i<256; )
61 lower[i] = i;
62 upper[i] = 0;
64 for (i=256; --i; )
66 map[i] = i;
67 strcpy(name, "..TST");
68 name[0] = i;
69 printf("%d:", i);
70 if ((fd=fopen(name, "w"))==0)
71 printf(" open");
72 else
73 fclose(fd);
74 c = test();
75 if (unlink(name))
76 printf(" unlink");
77 if (c==i)
78 printf(" ok");
79 else
80 printf(" %d", c);
81 printf("\n");
82 if (c!=i)
84 upper[c]++;
85 lower[c] = i;
87 map[i] = c;
90 /* Uppercase characters are detected above on:
91 * The character is mapped to itself and there is a
92 * character which maps to it.
93 * Lowercase characters are the lowest character pointing to another one.
94 * Else it is a one way character.
96 * For this reason we have to process the list
97 * 1) for 'one way' characters
98 * 'one way' is something which is no upper and no lower character.
99 * This is an awful, crude and ugly hack due to missing Samba support.
100 * 2) for true uppercase/lowercase characters
101 * 3) for standalone characters
102 * Note that there might be characters which do not fall into 1 to 3.
104 printf("\n valid chars =");
105 for (i=0; ++i<256; )
106 if (map[i] && map[i]!=i && lower[map[i]]!=i)
108 if (!upper[i])
109 printf(" %d:%d %d:%d %d:%d", /*1*/
110 map[i], i, i, map[i], map[i], map[i]);
111 else
112 fprintf(stderr, "ignoring map %d->%d because of %d->%d\n",
113 lower[i], i, i, map[i]);
115 for (i=0; ++i<256; )
116 if (map[i] && map[i]==i)
117 if (upper[i])
118 printf(" %d:%d", lower[i], i); /*2*/
119 else
120 printf(" %d", i); /*3*/
121 printf("\n");
122 return 0;