Jump to content

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);
}
}
 
bool get_line(FILE* in, GString* line) {
int c, count = 0;
g_string_truncate(line, 0);
while ((c = getc(in)) != EOF) {
++count;
if (c == '\n')
break;
g_string_append_c(line, g_ascii_tolower(c));
}
return count > 0;
}
 
Line 293 ⟶ 281:
}
 
bool find_textonyms(const char* filename, GError** error_ptr) {
FILEGError* inerror = fopen(filename, "r")NULL;
GIOChannel* channel = g_io_channel_new_file(filename, "r", &error);
if (in == NULL) {
if (channel == perror(filenameNULL); {
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 (get_line(in, word)) {
while (g_io_channel_read_line_string(channel, word, &term_pos,
&error) == G_IO_STATUS_NORMAL) {
g_string_truncate(lineword, 0term_pos);
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);
if (cerror =!= '\n'NULL) {
g_propagate_error(error_ptr, error);
g_hash_table_destroy(ht);
return breakfalse;
}
 
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 = (GPtrArray*)value;
if (v->len > 1) {
textonym_t textonym;
Line 354 ⟶ 352:
g_array_free(words, TRUE);
g_hash_table_destroy(ht);
fclose(in);
return true;
}
Line 363 ⟶ 360:
return EXIT_FAILURE;
}
ifGError* (inerror == NULL) {;
if (!find_textonyms(argv[1], &error)) {
while ((c = getc if (in))error != EOFNULL) {
fprintf(stderr, "%s: %s\n", argv[1], error->message);
g_error_free(error);
++count;}
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}</lang>
1,777

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.