| 1 | /* Error handling APIs. |
| 2 | * |
| 3 | * Copyright (C) 2016 Reece H. Dunn |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, see: <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "espeak__config.h"cxx . . $ `<file>/external/espeak/espeak__config.h`/ |
| 20 | #include "melder.h"cxx . . $ `<file>/melder/melder.h`/ |
| 21 | |
| 22 | #include <errno.h> |
| 23 | #include <stdint.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | #include "espeak_ng.h"cxx . . $ `<file>/external/espeak/espeak_ng.h`/ |
| 29 | |
| 30 | #include "error.h"cxx . . $ `<file>/external/espeak/error.h`/ |
| 31 | #include "common.h"cxx . . $ `<file>/external/espeak/common.h`/ // for strncpy0 |
| 32 | |
| 33 | espeak_ng_STATUS |
| 34 | create_file_error_contextcxx . . $ create_file_error_context(155ade6f45a025c5).(espeak_ng_ERROR_CONTEXT *context, |
| 35 | espeak_ng_STATUS status, |
| 36 | const char *filename) |
| 37 | { |
| 38 | if (context) { |
| 39 | if (*context) { |
| 40 | freecxx . . $ free(bd21765a0afc8e3c).((*context)->namecxx . . $ espeak_ng_ERROR_CONTEXT_#name.); |
| 41 | } else { |
| 42 | *context = (espeak_ng_ERROR_CONTEXT) malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(espeak_ng_ERROR_CONTEXT_)); |
| 43 | if (!*context) |
| 44 | return static_cast<espeak_ng_STATUS> (ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!); |
| 45 | } |
| 46 | (*context)->typecxx . . $ espeak_ng_ERROR_CONTEXT_#type. = ERROR_CONTEXT_FILE; |
| 47 | (*context)->namecxx . . $ espeak_ng_ERROR_CONTEXT_#name. = strdup(filename); |
| 48 | (*context)->versioncxx . . $ espeak_ng_ERROR_CONTEXT_#version. = 0; |
| 49 | (*context)->expected_versioncxx . . $ espeak_ng_ERROR_CONTEXT_#expected_version. = 0; |
| 50 | } |
| 51 | return status; |
| 52 | } |
| 53 | |
| 54 | espeak_ng_STATUS |
| 55 | create_version_mismatch_error_contextcxx . . $ create_version_mismatch_error_context(fc0ecaccad9c87da).(espeak_ng_ERROR_CONTEXT *context, |
| 56 | const char *path_home, |
| 57 | int version, |
| 58 | int expected_version) |
| 59 | { |
| 60 | if (context) { |
| 61 | if (*context) { |
| 62 | freecxx . . $ free(bd21765a0afc8e3c).((*context)->namecxx . . $ espeak_ng_ERROR_CONTEXT_#name.); |
| 63 | } else { |
| 64 | *context = (espeak_ng_ERROR_CONTEXT) malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(espeak_ng_ERROR_CONTEXT_)); |
| 65 | if (!*context) |
| 66 | return static_cast<espeak_ng_STATUS> (ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!); |
| 67 | } |
| 68 | (*context)->typecxx . . $ espeak_ng_ERROR_CONTEXT_#type. = ERROR_CONTEXT_VERSION; |
| 69 | (*context)->namecxx . . $ espeak_ng_ERROR_CONTEXT_#name. = strdup(path_home); |
| 70 | (*context)->versioncxx . . $ espeak_ng_ERROR_CONTEXT_#version. = version; |
| 71 | (*context)->expected_versioncxx . . $ espeak_ng_ERROR_CONTEXT_#expected_version. = expected_version; |
| 72 | } |
| 73 | return ENS_VERSION_MISMATCH; |
| 74 | } |
| 75 | |
| 76 | #pragma GCC visibility push(default) |
| 77 | |
| 78 | ESPEAK_NG_APIcxx . . $ `external/espeak/espeak_ng.h:36:9`! void |
| 79 | espeak_ng_ClearErrorContextcxx . . $ espeak_ng_ClearErrorContext(c8a3b3c7f25f433b).(espeak_ng_ERROR_CONTEXT *context) |
| 80 | { |
| 81 | if (context && *context) { |
| 82 | freecxx . . $ free(bd21765a0afc8e3c).((*context)->namecxx . . $ espeak_ng_ERROR_CONTEXT_#name.); |
| 83 | freecxx . . $ free(bd21765a0afc8e3c).(*context); |
| 84 | *context = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | ESPEAK_NG_APIcxx . . $ `external/espeak/espeak_ng.h:36:9`! void |
| 89 | espeak_ng_GetStatusCodeMessagecxx . . $ espeak_ng_GetStatusCodeMessage(1a27eafc52415c81).(espeak_ng_STATUS status, |
| 90 | char *buffer, |
| 91 | size_t length) |
| 92 | { |
| 93 | switch (status) |
| 94 | { |
| 95 | case ENS_COMPILE_ERROR: |
| 96 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "Compile error", length); |
| 97 | break; |
| 98 | case ENS_VERSION_MISMATCH: |
| 99 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "Wrong version of espeak-ng-data", length); |
| 100 | break; |
| 101 | case ENS_FIFO_BUFFER_FULL: |
| 102 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The FIFO buffer is full", length); |
| 103 | break; |
| 104 | case ENS_NOT_INITIALIZED: |
| 105 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The espeak-ng library has not been initialized", length); |
| 106 | break; |
| 107 | case ENS_AUDIO_ERROR: |
| 108 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "Cannot initialize the audio device", length); |
| 109 | break; |
| 110 | case ENS_VOICE_NOT_FOUND: |
| 111 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The specified espeak-ng voice does not exist", length); |
| 112 | break; |
| 113 | case ENS_MBROLA_NOT_FOUND: |
| 114 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "Could not load the mbrola.dll file", length); |
| 115 | break; |
| 116 | case ENS_MBROLA_VOICE_NOT_FOUND: |
| 117 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "Could not load the specified mbrola voice file", length); |
| 118 | break; |
| 119 | case ENS_EVENT_BUFFER_FULL: |
| 120 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The event buffer is full", length); |
| 121 | break; |
| 122 | case ENS_NOT_SUPPORTED: |
| 123 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The requested functionality has not been built into espeak-ng", length); |
| 124 | break; |
| 125 | case ENS_UNSUPPORTED_PHON_FORMAT: |
| 126 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The phoneme file is not in a supported format", length); |
| 127 | break; |
| 128 | case ENS_NO_SPECT_FRAMES: |
| 129 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The spectral file does not contain any frame data", length); |
| 130 | break; |
| 131 | case ENS_EMPTY_PHONEME_MANIFEST: |
| 132 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The phoneme manifest file does not contain any phonemes", length); |
| 133 | break; |
| 134 | case ENS_UNKNOWN_PHONEME_FEATURE: |
| 135 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The phoneme feature is not recognised", length); |
| 136 | break; |
| 137 | case ENS_UNKNOWN_TEXT_ENCODING: |
| 138 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buffer, "The text encoding is not supported", length); |
| 139 | break; |
| 140 | default: |
| 141 | if ((status & ENS_GROUP_MASK) == ENS_GROUP_ERRNO) |
| 142 | #ifdef _WIN32 |
| 143 | strerror_s(buffer, length, status); |
| 144 | #else |
| 145 | strerror_r(status, buffer, length); |
| 146 | #endif |
| 147 | else |
| 148 | snprintf(buffer, length, "Unspecified error 0x%x", status); |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | ESPEAK_NG_APIcxx . . $ `external/espeak/espeak_ng.h:36:9`! void |
| 154 | espeak_ng_PrintStatusCodeMessagecxx . . $ espeak_ng_PrintStatusCodeMessage(77fbf341a7b9e563).(espeak_ng_STATUS status, |
| 155 | FILE *out, |
| 156 | espeak_ng_ERROR_CONTEXT context) |
| 157 | { |
| 158 | char error[512]; |
| 159 | espeak_ng_GetStatusCodeMessagecxx . . $ espeak_ng_GetStatusCodeMessage(1a27eafc52415c81).(status, error, sizeof(error)); |
| 160 | if (context) { |
| 161 | switch (context->typecxx . . $ espeak_ng_ERROR_CONTEXT_#type.) |
| 162 | { |
| 163 | case ERROR_CONTEXT_FILE: |
| 164 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Error processing file\"", Melder_peek8to32_u (context->name), |
| 165 | U"\":", Melder_peek8to32_u (error) |
| 166 | ); |
| 167 | break; |
| 168 | case ERROR_CONTEXT_VERSION: |
| 169 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"eSpeak error: ", Melder_peek8to32_u (error), U" at \"", |
| 170 | Melder_peek8to32_u (context->name), U"\" (expected ", context->expected_version, |
| 171 | U", got ", context->version |
| 172 | ); |
| 173 | break; |
| 174 | } |
| 175 | } else |
| 176 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"eSpeak error: ", Melder_peek8to32_u (error)); |
| 177 | } |
| 178 | |
| 179 | #pragma GCC visibility pop |