test structure too
[tridge/junkcode.git] / lowcase.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    Copyright (C) Andrew Tridgell 2001
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19    
20 */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <fcntl.h>
25 #include <errno.h>
26
27 /* 
28    given an upcase table file, create a lowcase table file
29 */
30
31 typedef unsigned short smb_ucs2_t;
32
33 static smb_ucs2_t upcase[0x10000], lowcase[0x10000];
34
35 int main(void)
36 {
37         int fd, i;
38         char *fname = "upcase.dat";
39
40         fd = open(fname, O_RDONLY, 0);
41         if (fd == -1) {
42                 perror(fname);
43                 exit(1);
44         }
45
46         if (read(fd, upcase, 0x20000) != 0x20000) {
47                 printf("%s is too short\n", fname);
48                 exit(1);
49         }
50
51         for (i=0;i<0x10000;i++) {
52                 if (upcase[i] != i) lowcase[upcase[i]] = i;
53         }
54
55         for (i=0;i<0x10000;i++) {
56                 if (lowcase[i] == 0) lowcase[i] = i;
57         }
58
59         close(fd);
60
61         fname = "lowcase.dat";
62
63         fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
64         if (fd == -1) {
65                 perror(fname);
66                 exit(1);
67         }
68
69         write(fd, lowcase, 0x20000);
70         close(fd);
71         return 0;
72 }