File errno.c changed (mode: 100644) (index 872d11a..fd130c1) |
... |
... |
search(int num_words, char **words) |
100 |
100 |
} |
} |
101 |
101 |
|
|
102 |
102 |
|
|
|
103 |
|
static void |
|
104 |
|
search_all(int num_words, char **words) |
|
105 |
|
{ |
|
106 |
|
FILE *f; |
|
107 |
|
|
|
108 |
|
/* Static buffers are ugly, but they're simple. If anyone has a |
|
109 |
|
locale name longer than a kilobyte, they will suffer, and they |
|
110 |
|
will complain, and then I will fix this. */ |
|
111 |
|
char line[1024]; |
|
112 |
|
|
|
113 |
|
f = popen("locale -a", "r"); |
|
114 |
|
if (f == NULL) { |
|
115 |
|
fprintf(stderr, "ERROR: Can't execute locale -a: %d: %s\n", |
|
116 |
|
errno, strerror(errno)); |
|
117 |
|
exit(EXIT_FAILURE); |
|
118 |
|
} |
|
119 |
|
|
|
120 |
|
while (fgets(line, sizeof line, f) != NULL) { |
|
121 |
|
line[strcspn(line, "\n")] = '\0'; |
|
122 |
|
setlocale(LC_ALL, line); |
|
123 |
|
search(num_words, words); |
|
124 |
|
} |
|
125 |
|
|
|
126 |
|
fclose(f); |
|
127 |
|
} |
|
128 |
|
|
|
129 |
|
|
103 |
130 |
static struct option |
static struct option |
104 |
131 |
options[] = { |
options[] = { |
105 |
132 |
{ "help", 0, NULL, 'h' }, |
{ "help", 0, NULL, 'h' }, |
106 |
133 |
{ "list", 0, NULL, 'l' }, |
{ "list", 0, NULL, 'l' }, |
107 |
134 |
{ "search", 0, NULL, 's' }, |
{ "search", 0, NULL, 's' }, |
|
135 |
|
{ "search-all-locales", 0, NULL, 'S' }, |
108 |
136 |
}; |
}; |
109 |
137 |
|
|
110 |
138 |
|
|
111 |
139 |
static void |
static void |
112 |
140 |
usage(void) |
usage(void) |
113 |
141 |
{ |
{ |
114 |
|
printf("Usage: errno [-ls] [--list] [--search] [keyword]\n"); |
|
|
142 |
|
printf("Usage: errno [-lsS] [--list] [--search] [--search-all-locales] " |
|
143 |
|
"[keyword]\n"); |
115 |
144 |
} |
} |
116 |
145 |
|
|
117 |
146 |
|
|
|
... |
... |
main(int argc, char **argv) |
121 |
150 |
int i; |
int i; |
122 |
151 |
int exit_code; |
int exit_code; |
123 |
152 |
int index = 0; |
int index = 0; |
124 |
|
enum { lookup_mode, list_mode, search_mode } mode = lookup_mode; |
|
|
153 |
|
enum { |
|
154 |
|
lookup_mode, |
|
155 |
|
list_mode, |
|
156 |
|
search_mode, |
|
157 |
|
search_all_mode |
|
158 |
|
} mode = lookup_mode; |
125 |
159 |
|
|
126 |
160 |
setlocale(LC_ALL, ""); |
setlocale(LC_ALL, ""); |
127 |
161 |
|
|
128 |
162 |
for (;;) { |
for (;;) { |
129 |
|
int c = getopt_long(argc, argv, "hls", options, &index); |
|
|
163 |
|
int c = getopt_long(argc, argv, "hlsS", options, &index); |
130 |
164 |
if (c == -1) |
if (c == -1) |
131 |
165 |
break; |
break; |
132 |
166 |
|
|
|
... |
... |
main(int argc, char **argv) |
142 |
176 |
case 's': |
case 's': |
143 |
177 |
mode = search_mode; |
mode = search_mode; |
144 |
178 |
break; |
break; |
|
179 |
|
|
|
180 |
|
case 'S': |
|
181 |
|
mode = search_all_mode; |
|
182 |
|
break; |
145 |
183 |
|
|
146 |
184 |
case '?': |
case '?': |
147 |
185 |
break; |
break; |
|
... |
... |
main(int argc, char **argv) |
179 |
217 |
case search_mode: |
case search_mode: |
180 |
218 |
search(argc - optind, argv + optind); |
search(argc - optind, argv + optind); |
181 |
219 |
break; |
break; |
|
220 |
|
|
|
221 |
|
case search_all_mode: |
|
222 |
|
search_all(argc - optind, argv + optind); |
|
223 |
|
break; |
182 |
224 |
} |
} |
183 |
225 |
|
|
184 |
226 |
return exit_code; |
return exit_code; |