diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index a4e22f50..2966cf36 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -57,6 +57,11 @@ typedef enum { ENOUTPUT_MODE_SPEAK_AUDIO = 0x0002, } espeak_ng_OUTPUT_MODE; +typedef struct espeak_ng_ERROR_CONTEXT_ *espeak_ng_ERROR_CONTEXT; + +ESPEAK_NG_API void +espeak_ng_ClearErrorContext(espeak_ng_ERROR_CONTEXT *context); + ESPEAK_NG_API void espeak_ng_GetStatusCodeMessage(espeak_ng_STATUS status, char *buffer, diff --git a/src/libespeak-ng/error.c b/src/libespeak-ng/error.c index 37e6950b..1bfc4e15 100644 --- a/src/libespeak-ng/error.c +++ b/src/libespeak-ng/error.c @@ -24,15 +24,39 @@ #include #endif #include +#include #include "espeak_ng.h" +#include "error.h" #include "speech.h" #include "phoneme.h" #include "synthesize.h" +espeak_ng_STATUS create_file_error_context(espeak_ng_ERROR_CONTEXT *context, espeak_ng_STATUS status, const char *filename) +{ + if (context) { + if (*context) { + free((*context)->filename); + } else { + *context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_)); + } + (*context)->filename = strdup(filename); + } + return status; +} + #pragma GCC visibility push(default) +ESPEAK_NG_API void espeak_ng_ClearErrorContext(espeak_ng_ERROR_CONTEXT *context) +{ + if (context && *context) { + free((*context)->filename); + free(*context); + *context = NULL; + } +} + ESPEAK_NG_API void espeak_ng_GetStatusCodeMessage(espeak_ng_STATUS status, char *buffer, size_t length) { switch (status) diff --git a/src/libespeak-ng/error.h b/src/libespeak-ng/error.h new file mode 100644 index 00000000..f5683d04 --- /dev/null +++ b/src/libespeak-ng/error.h @@ -0,0 +1,40 @@ +/* Internal error APIs. + * + * Copyright (C) 2016 Reece H. Dunn + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see: . + */ +#ifndef ESPEAK_NG_ERROR_API +#define ESPEAK_NG_ERROR_API + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct espeak_ng_ERROR_CONTEXT_ +{ + char *filename; +} espeak_ng_ERROR_CONTEXT_; + +espeak_ng_STATUS +create_file_error_context(espeak_ng_ERROR_CONTEXT *context, + espeak_ng_STATUS status, + const char *filename); + +#ifdef __cplusplus +} +#endif + +#endif