| 1 |
/* |
| 2 |
* FCML - Free Code Manipulation Library. |
| 3 |
* Copyright (C) 2010-2020 Slawomir Wojtasiak |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library 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 GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdarg.h> |
| 21 |
|
| 22 |
#include "fcml_messages.h" |
| 23 |
#include "fcml_ceh.h" |
| 24 |
#include "fcml_env_int.h" |
| 25 |
|
| 26 |
#define FCML_MAX_MESSAGE_LENGTH 512 |
| 27 |
|
| 28 |
static fcml_string error_messages[] = { |
| 29 |
/* Messages for global error codes. */ |
| 30 |
FCML_TEXT("No error."), |
| 31 |
FCML_TEXT("Out of memory."), |
| 32 |
FCML_TEXT("Invalid input."), |
| 33 |
FCML_TEXT("Internal error."), |
| 34 |
FCML_TEXT("Not initialized."), |
| 35 |
FCML_TEXT("Unexpected end of data."), |
| 36 |
FCML_TEXT("Value out of range."), |
| 37 |
FCML_TEXT("Feature not supported."), |
| 38 |
FCML_TEXT("Invalid addressing mode."), |
| 39 |
FCML_TEXT("Invalid addressing form."), |
| 40 |
FCML_TEXT("Invalid instruction form."), |
| 41 |
FCML_TEXT("Invalid operand."), |
| 42 |
FCML_TEXT("Unknown mnemonic."), |
| 43 |
FCML_TEXT("Invalid operand size."), |
| 44 |
FCML_TEXT("Invalid address size."), |
| 45 |
FCML_TEXT("Unknown instruction."), |
| 46 |
FCML_TEXT("Invalid prefix."), |
| 47 |
FCML_TEXT("Invalid register type."), |
| 48 |
FCML_TEXT("Invalid register."), |
| 49 |
FCML_TEXT("Undefined symbol."), |
| 50 |
/* Messages for message error codes. */ |
| 51 |
FCML_TEXT("Segment register can not be overridden."), |
| 52 |
FCML_TEXT("Invalid pseudo opcode value."), |
| 53 |
FCML_TEXT("HLA prefixes are not allowed for instruction."), |
| 54 |
FCML_TEXT("More than one HLA prefix."), |
| 55 |
FCML_TEXT("Segment register expected."), |
| 56 |
FCML_TEXT("Symbol already defined: %s."), |
| 57 |
FCML_TEXT("Undefined symbol: %s."), |
| 58 |
FCML_TEXT("Parsed line exceed maximum allowed length."), |
| 59 |
/* Messages for warnings. */ |
| 60 |
}; |
| 61 |
|
| 62 |
fcml_string fcml_fn_msg_get_message(fcml_en_msg_message_code code) { |
| 63 |
return error_messages[code]; |
| 64 |
} |
| 65 |
|
| 66 |
void fcml_fn_msg_add_error_message(fcml_st_ceh_error_container *errors, |
| 67 |
fcml_en_msg_message_code msg_code, fcml_ceh_error code, |
| 68 |
fcml_en_ceh_error_level level, ...) { |
| 69 |
fcml_char buffer[FCML_MAX_MESSAGE_LENGTH]; |
| 70 |
va_list args; |
| 71 |
va_start(args, level); |
| 72 |
fcml_fn_env_str_vsnprintf(buffer, sizeof(buffer), |
| 73 |
fcml_fn_msg_get_message(msg_code), args); |
| 74 |
va_end(args); |
| 75 |
fcml_fn_ceh_add_error(errors, (const fcml_string) buffer, code, level); |
| 76 |
} |