Textonyms: Difference between revisions
m
C code modified to use GLib I/O functions to load the dictionary
m (→{{header|REXX}}: changed the output wording.) |
m (C code modified to use GLib I/O functions to load the dictionary) |
||
Line 226:
g_string_set_size(text, word->len);
for (size_t i = 0; i < word->len; ++i) {
char c = text_char(g_ascii_tolower(word->str[i]));
if (c == 0)
return false;
Line 275:
print_words(t->words);
}
g_string_truncate(line, 0);▼
while ((c = getc(in)) != EOF) {▼
++count;▼
if (c == '\n')▼
break;▼
}▼
}
Line 293 ⟶ 281:
}
bool find_textonyms(const char* filename, GError** error_ptr) {
GIOChannel* channel = g_io_channel_new_file(filename, "r", &error);
if (in == NULL) {▼
if (channel ==
g_propagate_error(error_ptr, error);
return false;
}
Line 304 ⟶ 293:
GString* text = g_string_sized_new(64);
guint count = 0;
gsize term_pos;
while (g_io_channel_read_line_string(channel, word, &term_pos,
&error) == G_IO_STATUS_NORMAL) {
if (!text_string(word, text))
continue;
Line 315 ⟶ 307:
++count;
}
g_io_channel_unref(channel);
g_string_free(word, TRUE);
g_string_free(text, TRUE);
g_propagate_error(error_ptr, error);
g_hash_table_destroy(ht);
▲ }
GArray* words = g_array_new(FALSE, FALSE, sizeof(textonym_t));
Line 323 ⟶ 321:
g_hash_table_iter_init(&iter, ht);
while (g_hash_table_iter_next(&iter, &key, &value)) {
GPtrArray* v =
if (v->len > 1) {
textonym_t textonym;
Line 354 ⟶ 352:
g_array_free(words, TRUE);
g_hash_table_destroy(ht);
return true;
}
Line 363 ⟶ 360:
return EXIT_FAILURE;
}
if (!find_textonyms(argv[1], &error)) {
fprintf(stderr, "%s: %s\n", argv[1], error->message);
g_error_free(error);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}</lang>
|