Browse Source

Support displaying error context information.

master
Reece H. Dunn 9 years ago
parent
commit
9d860cb180

+ 1
- 1
src/espeak-ng.c View File

espeak_ng_ERROR_CONTEXT context = NULL; espeak_ng_ERROR_CONTEXT context = NULL;
espeak_ng_STATUS result = espeak_ng_Initialize(&context); espeak_ng_STATUS result = espeak_ng_Initialize(&context);
if (result != ENS_OK) { if (result != ENS_OK) {
espeak_ng_PrintStatusCodeMessage(result, stderr);
espeak_ng_PrintStatusCodeMessage(result, stderr, context);
espeak_ng_ClearErrorContext(&context); espeak_ng_ClearErrorContext(&context);
exit(1); exit(1);
} }

+ 2
- 1
src/include/espeak-ng/espeak_ng.h View File



ESPEAK_NG_API void ESPEAK_NG_API void
espeak_ng_PrintStatusCodeMessage(espeak_ng_STATUS status, espeak_ng_PrintStatusCodeMessage(espeak_ng_STATUS status,
FILE *out);
FILE *out,
espeak_ng_ERROR_CONTEXT context);


ESPEAK_NG_API void ESPEAK_NG_API void
espeak_ng_InitializePath(const char *path); espeak_ng_InitializePath(const char *path);

+ 30
- 20
src/libespeak-ng/error.c View File

} else { } else {
*context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_)); *context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_));
} }
(*context)->type = ERROR_CONTEXT_FILE;
(*context)->path = strdup(filename); (*context)->path = strdup(filename);
(*context)->version = 0; (*context)->version = 0;
(*context)->expected_version = 0; (*context)->expected_version = 0;
} else { } else {
*context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_)); *context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_));
} }
(*context)->type = ERROR_CONTEXT_VERSION;
(*context)->path = strdup(path_home); (*context)->path = strdup(path_home);
(*context)->version = version; (*context)->version = version;
(*context)->expected_version = expected_version; (*context)->expected_version = expected_version;
switch (status) switch (status)
{ {
case ENS_COMPILE_ERROR: case ENS_COMPILE_ERROR:
strncpy0(buffer, "Compile error.", length);
strncpy0(buffer, "Compile error", length);
break; break;
case ENS_VERSION_MISMATCH: case ENS_VERSION_MISMATCH:
#ifdef PLATFORM_WINDOWS
sprintf(buffer, "Wrong version of espeak-data (expected 0x%x) at '%s'.", version_phdata, path_home);
#else
snprintf(buffer, length, "Wrong version of espeak-data (expected 0x%x) at '%s'.", version_phdata, path_home);
#endif
strncpy0(buffer, "Wrong version of espeak-data", length);
break; break;
case ENS_FIFO_BUFFER_FULL: case ENS_FIFO_BUFFER_FULL:
strncpy0(buffer, "The FIFO buffer is full.", length);
strncpy0(buffer, "The FIFO buffer is full", length);
break; break;
case ENS_NOT_INITIALIZED: case ENS_NOT_INITIALIZED:
strncpy0(buffer, "The espeak-ng library has not been initialized.", length);
strncpy0(buffer, "The espeak-ng library has not been initialized", length);
break; break;
case ENS_AUDIO_ERROR: case ENS_AUDIO_ERROR:
strncpy0(buffer, "Cannot initialize the audio device.", length);
strncpy0(buffer, "Cannot initialize the audio device", length);
break; break;
case ENS_VOICE_NOT_FOUND: case ENS_VOICE_NOT_FOUND:
strncpy0(buffer, "The specified espeak-ng voice does not exist.", length);
strncpy0(buffer, "The specified espeak-ng voice does not exist", length);
break; break;
case ENS_MBROLA_NOT_FOUND: case ENS_MBROLA_NOT_FOUND:
strncpy0(buffer, "Could not load the mbrola.dll file.", length);
strncpy0(buffer, "Could not load the mbrola.dll file", length);
break; break;
case ENS_MBROLA_VOICE_NOT_FOUND: case ENS_MBROLA_VOICE_NOT_FOUND:
strncpy0(buffer, "Could not load the specified mbrola voice file.", length);
strncpy0(buffer, "Could not load the specified mbrola voice file", length);
break; break;
case ENS_EVENT_BUFFER_FULL: case ENS_EVENT_BUFFER_FULL:
strncpy0(buffer, "The event buffer is full.", length);
strncpy0(buffer, "The event buffer is full", length);
break; break;
case ENS_NOT_SUPPORTED: case ENS_NOT_SUPPORTED:
strncpy0(buffer, "The requested functionality has not been built into espeak-ng.", length);
strncpy0(buffer, "The requested functionality has not been built into espeak-ng", length);
break; break;
case ENS_UNSUPPORTED_PHON_FORMAT: case ENS_UNSUPPORTED_PHON_FORMAT:
strncpy0(buffer, "The phoneme file is not in a supported format.", length);
strncpy0(buffer, "The phoneme file is not in a supported format", length);
break; break;
case ENS_NO_SPECT_FRAMES: case ENS_NO_SPECT_FRAMES:
strncpy0(buffer, "The spectral file does not contain any frame data.", length);
strncpy0(buffer, "The spectral file does not contain any frame data", length);
break; break;
default: default:
if ((status & ENS_GROUP_MASK) == ENS_GROUP_ERRNO) if ((status & ENS_GROUP_MASK) == ENS_GROUP_ERRNO)
strerror_r(status, buffer, length); strerror_r(status, buffer, length);
else { else {
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
sprintf(buffer, "Unspecified error 0x%x.", status);
sprintf(buffer, "Unspecified error 0x%x", status);
#else #else
snprintf(buffer, length, "Unspecified error 0x%x.", status);
snprintf(buffer, length, "Unspecified error 0x%x", status);
#endif #endif
} }
break; break;
} }
} }


ESPEAK_NG_API void espeak_ng_PrintStatusCodeMessage(espeak_ng_STATUS status, FILE *out)
ESPEAK_NG_API void espeak_ng_PrintStatusCodeMessage(espeak_ng_STATUS status, FILE *out, espeak_ng_ERROR_CONTEXT context)
{ {
char error[512]; char error[512];
espeak_ng_GetStatusCodeMessage(status, error, sizeof(error)); espeak_ng_GetStatusCodeMessage(status, error, sizeof(error));
fprintf(out, "%s\n", error);
if (context) {
switch (context->type)
{
case ERROR_CONTEXT_FILE:
fprintf(out, "Error processing file '%s': %s.\n", context->path, error);
break;
case ERROR_CONTEXT_VERSION:
fprintf(out, "Error: %s at '%s' (expected 0x%x, got 0x%x).\n",
error, context->path, context->expected_version, context->version);
break;
}
} else
fprintf(out, "Error: %s.\n", error);
} }


#pragma GCC visibility pop #pragma GCC visibility pop

+ 7
- 0
src/libespeak-ng/error.h View File

{ {
#endif #endif


typedef enum
{
ERROR_CONTEXT_FILE,
ERROR_CONTEXT_VERSION,
} espeak_ng_CONTEXT_TYPE;

typedef struct espeak_ng_ERROR_CONTEXT_ typedef struct espeak_ng_ERROR_CONTEXT_
{ {
espeak_ng_CONTEXT_TYPE type;
char *path; char *path;
int version; int version;
int expected_version; int expected_version;

+ 1
- 1
src/libespeak-ng/espeak_api.c View File

espeak_ng_ERROR_CONTEXT context = NULL; espeak_ng_ERROR_CONTEXT context = NULL;
espeak_ng_STATUS result = espeak_ng_Initialize(&context); espeak_ng_STATUS result = espeak_ng_Initialize(&context);
if (result != ENS_OK) { if (result != ENS_OK) {
espeak_ng_PrintStatusCodeMessage(result, stderr);
espeak_ng_PrintStatusCodeMessage(result, stderr, context);
espeak_ng_ClearErrorContext(&context); espeak_ng_ClearErrorContext(&context);
if ((options & espeakINITIALIZE_DONT_EXIT) == 0) if ((options & espeakINITIALIZE_DONT_EXIT) == 0)
exit(1); exit(1);

+ 1
- 1
src/speak-ng.c View File

espeak_ng_ERROR_CONTEXT context = NULL; espeak_ng_ERROR_CONTEXT context = NULL;
espeak_ng_STATUS result = espeak_ng_Initialize(&context); espeak_ng_STATUS result = espeak_ng_Initialize(&context);
if (result != ENS_OK) { if (result != ENS_OK) {
espeak_ng_PrintStatusCodeMessage(result, stderr);
espeak_ng_PrintStatusCodeMessage(result, stderr, context);
espeak_ng_ClearErrorContext(&context); espeak_ng_ClearErrorContext(&context);
exit(1); exit(1);
} }

Loading…
Cancel
Save