-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathmsym_error.c
More file actions
72 lines (63 loc) · 2.37 KB
/
msym_error.c
File metadata and controls
72 lines (63 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// msym_error.c
// libmsym
//
// Created by Marcus Johansson on 30/01/15.
// Copyright (c) 2015 Marcus Johansson.
//
// Distributed under the MIT License ( See LICENSE file or copy at http://opensource.org/licenses/MIT )
//
#include <stdio.h>
#include <stdarg.h>
#include "msym_error.h"
#define MSYM_ERROR_DETAILS_MAX_LENGTH 1024
const char * invalid = "Invalid error code";
char err_details[MSYM_ERROR_DETAILS_MAX_LENGTH];
char err_details_ext[MSYM_ERROR_DETAILS_MAX_LENGTH];
const struct _errordesc {
msym_error_t code;
char *message;
} error_desc[] = {
{ MSYM_SUCCESS, "Success" },
{ MSYM_INVALID_INPUT, "Invalid input" },
{ MSYM_INVALID_CONTEXT, "Invalid context" },
{ MSYM_INVALID_THRESHOLD, "Invalid threshold" },
{ MSYM_INVALID_ELEMENTS, "Invalid elements" },
{ MSYM_INVALID_BASIS_FUNCTIONS, "Invalid basis functions" },
{ MSYM_INVALID_POINT_GROUP, "Invalid point group" },
{ MSYM_INVALID_PERMUTATION, "Invalid permutation" },
{ MSYM_INVALID_EQUIVALENCE_SET, "Invalid equivalence set" },
{ MSYM_INVALID_GEOMETRY, "Invalid geometry" },
{ MSYM_INVALID_CHARACTER_TABLE, "Invalid character table" },
{ MSYM_INVALID_SUBSPACE, "Invalid subspace" },
{ MSYM_INVALID_SUBGROUPS, "Invalid subgroups" },
{ MSYM_INVALID_AXES, "Invalid axes" },
{ MSYM_SYMMETRY_ERROR, "Error determining symmetry operations" },
{ MSYM_PERMUTATION_ERROR, "Error determining permutation" },
{ MSYM_POINT_GROUP_ERROR, "Error determining point group" },
{ MSYM_SYMMETRIZATION_ERROR, "Error symmetrizing molecule/orbitals" },
{ MSYM_SUBSPACE_ERROR, "Error generating subspaces" },
{ MSYM_MEMORY_ERROR, "Error allocating memory" }
};
void msymSetErrorDetails(const char *format, ...){
va_list args;
va_start(args, format);
vsnprintf(err_details, sizeof(err_details), format, args);
va_end(args);
}
const char MSYM_EXPORT *msymGetErrorDetails(void){
snprintf(err_details_ext, sizeof(err_details_ext), "%s",err_details); // Not really necessary
msymSetErrorDetails("");
return err_details_ext;
}
const char MSYM_EXPORT *msymErrorString(msym_error_t error){
const char *ret = invalid;
int length = sizeof(error_desc) / sizeof(error_desc[0]);
for(int i = 0; i < length;i++){
if(error == error_desc[i].code){
ret = error_desc[i].message;
break;
}
}
return ret;
}