Browse Source

phonemes: show the invalid phoneme feature on unrecognised feature names

master
Reece H. Dunn 8 years ago
parent
commit
442a503986
3 changed files with 59 additions and 15 deletions
  1. 50
    12
      src/libespeak-ng/error.c
  2. 7
    1
      src/libespeak-ng/error.h
  3. 2
    2
      src/libespeak-ng/phoneme.c

+ 50
- 12
src/libespeak-ng/error.c View File

#include "phoneme.h" #include "phoneme.h"
#include "synthesize.h" #include "synthesize.h"


espeak_ng_STATUS create_file_error_context(espeak_ng_ERROR_CONTEXT *context, espeak_ng_STATUS status, const char *filename)
espeak_ng_STATUS
create_file_error_context(espeak_ng_ERROR_CONTEXT *context,
espeak_ng_STATUS status,
const char *filename)
{ {
if (context) { if (context) {
if (*context) { if (*context) {
free((*context)->path);
free((*context)->name);
} else { } else {
*context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_)); *context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_));
if (!*context) if (!*context)
return ENOMEM; return ENOMEM;
} }
(*context)->type = ERROR_CONTEXT_FILE; (*context)->type = ERROR_CONTEXT_FILE;
(*context)->path = strdup(filename);
(*context)->name = strdup(filename);
(*context)->version = 0; (*context)->version = 0;
(*context)->expected_version = 0; (*context)->expected_version = 0;
} }
return status; return status;
} }


espeak_ng_STATUS create_version_mismatch_error_context(espeak_ng_ERROR_CONTEXT *context, const char *path_home, int version, int expected_version)
espeak_ng_STATUS
create_version_mismatch_error_context(espeak_ng_ERROR_CONTEXT *context,
const char *path_home,
int version,
int expected_version)
{ {
if (context) { if (context) {
if (*context) { if (*context) {
free((*context)->path);
free((*context)->name);
} else { } else {
*context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_)); *context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_));
if (!*context) if (!*context)
return ENOMEM; return ENOMEM;
} }
(*context)->type = ERROR_CONTEXT_VERSION; (*context)->type = ERROR_CONTEXT_VERSION;
(*context)->path = strdup(path_home);
(*context)->name = strdup(path_home);
(*context)->version = version; (*context)->version = version;
(*context)->expected_version = expected_version; (*context)->expected_version = expected_version;
} }
return ENS_VERSION_MISMATCH; return ENS_VERSION_MISMATCH;
} }


espeak_ng_STATUS
create_name_error_context(espeak_ng_ERROR_CONTEXT *context,
espeak_ng_STATUS status,
const char *name)
{
if (context) {
if (*context) {
free((*context)->name);
} else {
*context = malloc(sizeof(espeak_ng_ERROR_CONTEXT_));
if (!*context)
return ENOMEM;
}
(*context)->type = ERROR_CONTEXT_NAME;
(*context)->name = strdup(name);
(*context)->version = 0;
(*context)->expected_version = 0;
}
return status;
}

#pragma GCC visibility push(default) #pragma GCC visibility push(default)


ESPEAK_NG_API void espeak_ng_ClearErrorContext(espeak_ng_ERROR_CONTEXT *context)
ESPEAK_NG_API void
espeak_ng_ClearErrorContext(espeak_ng_ERROR_CONTEXT *context)
{ {
if (context && *context) { if (context && *context) {
free((*context)->path);
free((*context)->name);
free(*context); free(*context);
*context = NULL; *context = NULL;
} }
} }


ESPEAK_NG_API void espeak_ng_GetStatusCodeMessage(espeak_ng_STATUS status, char *buffer, size_t length)
ESPEAK_NG_API void
espeak_ng_GetStatusCodeMessage(espeak_ng_STATUS status,
char *buffer,
size_t length)
{ {
switch (status) switch (status)
{ {
} }
} }


ESPEAK_NG_API void espeak_ng_PrintStatusCodeMessage(espeak_ng_STATUS status, FILE *out, espeak_ng_ERROR_CONTEXT context)
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));
switch (context->type) switch (context->type)
{ {
case ERROR_CONTEXT_FILE: case ERROR_CONTEXT_FILE:
fprintf(out, "Error processing file '%s': %s.\n", context->path, error);
fprintf(out, "Error processing file '%s': %s.\n", context->name, error);
break; break;
case ERROR_CONTEXT_VERSION: case ERROR_CONTEXT_VERSION:
fprintf(out, "Error: %s at '%s' (expected 0x%x, got 0x%x).\n", fprintf(out, "Error: %s at '%s' (expected 0x%x, got 0x%x).\n",
error, context->path, context->expected_version, context->version);
error, context->name, context->expected_version, context->version);
break;
case ERROR_CONTEXT_NAME:
fprintf(out, "Error: %s (got \"%s\").\n", error, context->name);
break; break;
} }
} else } else

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

{ {
ERROR_CONTEXT_FILE, ERROR_CONTEXT_FILE,
ERROR_CONTEXT_VERSION, ERROR_CONTEXT_VERSION,
ERROR_CONTEXT_NAME,
} espeak_ng_CONTEXT_TYPE; } espeak_ng_CONTEXT_TYPE;


typedef struct espeak_ng_ERROR_CONTEXT_ typedef struct espeak_ng_ERROR_CONTEXT_
{ {
espeak_ng_CONTEXT_TYPE type; espeak_ng_CONTEXT_TYPE type;
char *path;
char *name;
int version; int version;
int expected_version; int expected_version;
} espeak_ng_ERROR_CONTEXT_; } espeak_ng_ERROR_CONTEXT_;
int version, int version,
int expected_version); int expected_version);


espeak_ng_STATUS
create_name_error_context(espeak_ng_ERROR_CONTEXT *context,
espeak_ng_STATUS status,
const char *name);

#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

+ 2
- 2
src/libespeak-ng/phoneme.c View File

const char *feature, const char *feature,
espeak_ng_ERROR_CONTEXT *context) espeak_ng_ERROR_CONTEXT *context)
{ {
if (!phoneme || !feature) return -EINVAL;
if (!phoneme || !feature) return EINVAL;


switch (LookupMnem(features, feature)) switch (LookupMnem(features, feature))
{ {
default: default:
return ENS_UNKNOWN_PHONEME_FEATURE;
return create_name_error_context(context, ENS_UNKNOWN_PHONEME_FEATURE, feature);
} }
return ENS_OK; return ENS_OK;
} }

Loading…
Cancel
Save