Create an error context API.

This will allow the espeak-ng methods to provide more context
information for the errors that can then be used in things like
GUI applications.
This commit is contained in:
Reece H. Dunn
2016-01-04 10:24:38 +00:00
parent feae9a2a95
commit 378490b65f
3 changed files with 69 additions and 0 deletions
+5
View File
@@ -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,
+24
View File
@@ -24,15 +24,39 @@
#include <stdint.h>
#endif
#include <string.h>
#include <malloc.h>
#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)
+40
View File
@@ -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: <http://www.gnu.org/licenses/>.
*/
#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