This source file includes following definitions.
- read_file
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include <config.h>
27
28
29 #include "unicase.h"
30
31 #define FUNC u8_totitle
32 #define UNIT uint8_t
33 #define U_CT_TOTITLE u8_ct_totitle
34 #include "u-totitle.h"
35
36
37 #ifdef TEST
38
39 #include <locale.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43
44
45
46 char *
47 read_file (FILE *stream)
48 {
49 #define BUFSIZE 4096
50 char *buf = NULL;
51 int alloc = 0;
52 int size = 0;
53 int count;
54
55 while (! feof (stream))
56 {
57 if (size + BUFSIZE > alloc)
58 {
59 alloc = alloc + alloc / 2;
60 if (alloc < size + BUFSIZE)
61 alloc = size + BUFSIZE;
62 buf = realloc (buf, alloc);
63 if (buf == NULL)
64 {
65 fprintf (stderr, "out of memory\n");
66 exit (1);
67 }
68 }
69 count = fread (buf + size, 1, BUFSIZE, stream);
70 if (count == 0)
71 {
72 if (ferror (stream))
73 {
74 perror ("fread");
75 exit (1);
76 }
77 }
78 else
79 size += count;
80 }
81 buf = realloc (buf, size + 1);
82 if (buf == NULL)
83 {
84 fprintf (stderr, "out of memory\n");
85 exit (1);
86 }
87 buf[size] = '\0';
88 return buf;
89 #undef BUFSIZE
90 }
91
92 int
93 main (int argc, char * argv[])
94 {
95 setlocale (LC_ALL, "");
96 if (argc == 1)
97 {
98
99 char *input = read_file (stdin);
100 int length = strlen (input);
101 size_t output_length;
102 uint8_t *output =
103 u8_toupper ((uint8_t *) input, length, uc_locale_language (),
104 NULL,
105 NULL, &output_length);
106
107 fwrite (output, 1, output_length, stdout);
108
109 return 0;
110 }
111 else
112 return 1;
113 }
114
115 #endif