Skip to content

Commit e284afe

Browse files
committed
Add --strip option to languagetool
1 parent 96b821b commit e284afe

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

cmake-scripts/BuildLanguages.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ foreach(LANG ${OMF_LANGS})
8282
DEPENDS "${TXT2}" "${BASE_TXT}" "${BASE_DAT}"
8383
BYPRODUCTS "${LNG}"
8484
COMMAND ${CMAKE_COMMAND} -E echo_append "${LANG}, "
85-
COMMAND ${OMF_COMMAND_WRAPPER} "$<TARGET_FILE:languagetool>" --import "${BASE_TXT}" --import "${TXT2}" --base "${BASE_DAT}" --base-count "${OMF_STR_COUNT}" --output "${LNG}" --check-count ${Lang_Count}
85+
COMMAND ${OMF_COMMAND_WRAPPER} "$<TARGET_FILE:languagetool>" --import "${BASE_TXT}" --import "${TXT2}" --base "${BASE_DAT}" --base-count "${OMF_STR_COUNT}" --strip --output "${LNG}" --check-count ${Lang_Count}
8686
)
8787
install(FILES "${LNG}" DESTINATION "${LANGUAGE_INSTALL_PATH}")
8888
endforeach()
@@ -94,7 +94,7 @@ foreach(LANG ${OPENOMF_LANGS})
9494
DEPENDS "${TXT}"
9595
BYPRODUCTS "{LNG}"
9696
COMMAND ${CMAKE_COMMAND} -E echo_append "${LANG}, "
97-
COMMAND ${OMF_COMMAND_WRAPPER} "$<TARGET_FILE:languagetool>" --import "${TXT}" --output "${LNG}" --check-count ${Lang_Count}
97+
COMMAND ${OMF_COMMAND_WRAPPER} "$<TARGET_FILE:languagetool>" --import "${TXT}" --strip --output "${LNG}" --check-count ${Lang_Count}
9898
)
9999
install(FILES "${LNG}" DESTINATION "${LANGUAGE_INSTALL_PATH}")
100100
endforeach()

src/utils/str.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static size_t _strip_size(const str *src, bool left) {
197197
const char *ptr = str_c(src);
198198
for(size_t i = 0; i < src->len; i++) {
199199
pos = left ? i : src->len - i - 1;
200-
if(!isspace(ptr[pos])) {
200+
if(!isspace((unsigned char)ptr[pos])) {
201201
return pos;
202202
}
203203
}

tools/languagetool/main.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,12 @@ int main(int argc, char *argv[]) {
380380
struct arg_int *base_count =
381381
arg_int0(NULL, "base-count", "<file>", "Check and ensure base language has this many strings");
382382
struct arg_int *str = arg_int0("s", "string", "<value>", "display language string number");
383+
struct arg_lit *strip = arg_lit0(NULL, "strip", "strip leading and trailing whitespace");
383384
struct arg_file *output = arg_file0("o", "output", "<file>", "compile output language file");
384385
struct arg_int *check_count =
385386
arg_int0("c", "check-count", "<NUM>", "Check that language file has this many entries, or bail.");
386387
struct arg_end *end = arg_end(20);
387-
void *argtable[] = {help, vers, file, input, base, base_count, output, str, check_count, end};
388+
void *argtable[] = {help, vers, file, input, base, base_count, strip, output, str, check_count, end};
388389
const char *progname = "languagetool";
389390

390391
bool language_is_utf8 = false;
@@ -432,10 +433,7 @@ int main(int argc, char *argv[]) {
432433
goto exit_0;
433434
}
434435

435-
if(file->count > 1) {
436-
fprintf(stderr, "Too many input files provided! please supply one --file.\n");
437-
goto exit_0;
438-
} else if(file->count > 1 && input->count > 1) {
436+
if(file->count > 1 && input->count > 1) {
439437
fprintf(stderr, "--import and --file arguments are incompatible.\n");
440438
goto exit_0;
441439
} else if(file->count + input->count < 1) {
@@ -446,16 +444,10 @@ int main(int argc, char *argv[]) {
446444
if(base->count > 0 && input->count == 0) {
447445
fprintf(stderr, "Unexpected --base argument: it is meaningless without --import.\n");
448446
goto exit_0;
449-
} else if(base->count > 1) {
450-
fprintf(stderr, "Too many --base arguments: please supply only one.\n");
451-
goto exit_0;
452447
}
453448
if(base_count->count > 0 && base->count == 0) {
454449
fprintf(stderr, "Unexpected --base-count argument: it is meaningless without --base.\n");
455450
goto exit_0;
456-
} else if(base_count->count > 1) {
457-
fprintf(stderr, "Too many --base-count arguments: please supply only one.\n");
458-
goto exit_0;
459451
}
460452

461453
int ret;
@@ -529,6 +521,16 @@ int main(int argc, char *argv[]) {
529521
goto exit_0;
530522
}
531523

524+
if(strip->count) {
525+
struct str s;
526+
for(unsigned int id = 0; id < language.count; id++) {
527+
str_from_c(&s, language.strings[id].data);
528+
str_strip(&s);
529+
memcpy(language.strings[id].data, str_c(&s), str_size(&s) + 1);
530+
str_free(&s);
531+
}
532+
}
533+
532534
// Print
533535
const sd_lang_string *ds;
534536
if(str->count > 0) {

0 commit comments

Comments
 (0)