fix: add missing gettext functions

This commit is contained in:
ngn 2024-07-14 15:38:53 +03:00
parent 4420147c58
commit 879b0f5cf1
4 changed files with 26 additions and 26 deletions

View File

@ -117,7 +117,7 @@ int config_load_handler(void *data, const char *_section, const char *_key, cons
return 1;
unknown:
log_error("Unknown configuration option: %s/%s", section, key);
error(_("Unknown configuration option: %s/%s"), section, key);
return 0;
}
@ -125,25 +125,25 @@ bool config_load(char *file) {
config_options_clear();
if (!exists(file) || !can_read(file)) {
log_error("Failed to access the configuration file: %s", file);
error(_("Failed to access the configuration file: %s"), file);
return false;
}
if (ini_parse(file, config_load_handler, NULL) < 0) {
log_error("Failed to parse the configuration");
error(_("Failed to parse the configuration"));
return false;
}
pool_config_t *pool = config.pools;
while (NULL != pool) {
if (NULL == pool->host) {
log_error("Hostname not specified for the pool: %s", pool->name);
error(_("Hostname not specified for the pool: %s"), pool->name);
return false;
}
pool = pool->next;
}
log_info("Loaded the configuration");
info(_("Loaded the configuration"));
return true;
}

View File

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <time.h>
void log_error(char *fmt, ...) {
void error(char *fmt, ...) {
va_list args;
va_start(args, fmt);
@ -24,7 +24,7 @@ void log_error(char *fmt, ...) {
va_end(args);
}
void log_info(char *fmt, ...) {
void info(char *fmt, ...) {
va_list args;
va_start(args, fmt);

View File

@ -1,3 +1,3 @@
#pragma once
void log_error(char *fmt, ...);
void log_info(char *fmt, ...);
void error(char *fmt, ...);
void info(char *fmt, ...);

View File

@ -39,19 +39,19 @@ bool sync_callback(
lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state, size_t current, size_t total, void *data) {
switch (state) {
case SYNC_INFO_SUCCESS:
log_info(_("%s: successfuly loaded the pool info"), pool->name);
info(_("%s: successfuly loaded the pool info"), pool->name);
break;
case SYNC_INFO_FAIL:
log_info(_("%s: failed to load the pool info (%s)"), pool->name, lm_strerror());
info(_("%s: failed to load the pool info (%s)"), pool->name, lm_strerror());
return false;
case SYNC_LIST_SUCCESS:
log_info(_("%s: successfuly loaded the package list"), pool->name);
info(_("%s: successfuly loaded the package list"), pool->name);
break;
case SYNC_LIST_FAIL:
log_info(_("%s: failed to load the package list (%s)"), pool->name, lm_strerror());
info(_("%s: failed to load the package list (%s)"), pool->name, lm_strerror());
return false;
default:
@ -64,7 +64,7 @@ bool sync_callback(
int main(int argc, char *argv[]) {
if (argc != 2) {
log_error(_("Configuration file not specified"));
error(_("Configuration file not specified"));
return EXIT_FAILURE;
}
@ -83,7 +83,7 @@ int main(int argc, char *argv[]) {
FILE *log = fopen(logfile, "r");
if (NULL == log)
log_error(_("Failed to open the log file: %s"), strerror(errno));
error(_("Failed to open the log file: %s"), strerror(errno));
else {
dup2(fileno(log), STDERR_FILENO);
@ -95,33 +95,33 @@ int main(int argc, char *argv[]) {
addr = config_get_string("addr");
if (config_get_integer("threads") <= 0 || config_get_integer("threads") > 1000) {
log_error(_("Please specify a valid thread count (1-1000)"));
error(_("Please specify a valid thread count (1-1000)"));
goto end;
}
if ((poolsdir = config_get_string("dir")) == NULL) {
log_error(_("Pool directory not specified"));
error(_("Pool directory not specified"));
goto end;
}
if (!exists(poolsdir) && !can_read(poolsdir)) {
log_error(_("Cannot access to the pool directory: %s"), poolsdir);
error(_("Cannot access to the pool directory: %s"), poolsdir);
goto end;
}
if ((pool = config.pools) == NULL) {
log_error(_("Please specify at least one pool in the configuration"));
error(_("Please specify at least one pool in the configuration"));
goto end;
}
if (!lm_ctx_set_data(&ctx, poolsdir)) {
log_error(_("Failed to use pool directory: %s"), lm_strerror());
error(_("Failed to use pool directory: %s"), lm_strerror());
goto end;
}
while (NULL != pool) {
if (NULL == pool->host) {
log_error(_("Hostname not specified for pool, skipping: %s"), pool->name);
error(_("Hostname not specified for pool, skipping: %s"), pool->name);
goto end;
}
@ -129,7 +129,7 @@ int main(int argc, char *argv[]) {
sprintf(url, "mptp://%s", pool->host);
if (NULL == lm_ctx_pool_add(&ctx, pool->name, url)) {
log_error(_("Failed to add pool to the list: %s"), lm_strerror());
error(_("Failed to add pool to the list: %s"), lm_strerror());
goto end;
}
@ -137,19 +137,19 @@ int main(int argc, char *argv[]) {
}
if ((pool_count = lm_ctx_sync(&ctx, false, sync_callback, NULL)) < 0) {
log_error(_("Failed to sync the pools: %s"), lm_strerror());
error(_("Failed to sync the pools: %s"), lm_strerror());
goto end;
}
if (pool_count == 0) {
log_error(_("None of the pools is available for serving"));
error(_("None of the pools is available for serving"));
goto end;
}
log_info(pool_count == 1 ? _("Serving %lu pool on %s") : _("Serving %lu pools on %s"), pool_count, addr);
info(pool_count == 1 ? _("Serving %lu pool on %s") : _("Serving %lu pools on %s"), pool_count, addr);
if (!lm_ctx_serve(&ctx, addr, config_get_integer("threads"))) {
log_error(_("Failed to start the server: %s"), lm_strerror());
error(_("Failed to start the server: %s"), lm_strerror());
goto end;
}