Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/quicknes/fex/blargg_errors.cpp
2 views
1
// File_Extractor 1.0.0. http://www.slack.net/~ant/
2
3
#include "blargg_errors.h"
4
5
/* Copyright (C) 2009 Shay Green. This module is free software; you
6
can redistribute it and/or modify it under the terms of the GNU Lesser
7
General Public License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version. This
9
module is distributed in the hope that it will be useful, but WITHOUT ANY
10
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12
details. You should have received a copy of the GNU Lesser General Public
13
License along with this module; if not, write to the Free Software Foundation,
14
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
15
16
#include "blargg_source.h"
17
18
blargg_err_def_t blargg_err_generic = BLARGG_ERR_GENERIC;
19
blargg_err_def_t blargg_err_memory = BLARGG_ERR_MEMORY;
20
blargg_err_def_t blargg_err_caller = BLARGG_ERR_CALLER;
21
blargg_err_def_t blargg_err_internal = BLARGG_ERR_INTERNAL;
22
blargg_err_def_t blargg_err_limitation = BLARGG_ERR_LIMITATION;
23
24
blargg_err_def_t blargg_err_file_missing = BLARGG_ERR_FILE_MISSING;
25
blargg_err_def_t blargg_err_file_read = BLARGG_ERR_FILE_READ;
26
blargg_err_def_t blargg_err_file_write = BLARGG_ERR_FILE_WRITE;
27
blargg_err_def_t blargg_err_file_io = BLARGG_ERR_FILE_IO;
28
blargg_err_def_t blargg_err_file_full = BLARGG_ERR_FILE_FULL;
29
blargg_err_def_t blargg_err_file_eof = BLARGG_ERR_FILE_EOF;
30
31
blargg_err_def_t blargg_err_file_type = BLARGG_ERR_FILE_TYPE;
32
blargg_err_def_t blargg_err_file_feature = BLARGG_ERR_FILE_FEATURE;
33
blargg_err_def_t blargg_err_file_corrupt = BLARGG_ERR_FILE_CORRUPT;
34
35
const char* blargg_err_str( blargg_err_t err )
36
{
37
if ( !err )
38
return "";
39
40
if ( *err == BLARGG_ERR_TYPE("")[0] )
41
return err + 1;
42
43
return err;
44
}
45
46
bool blargg_is_err_type( blargg_err_t err, const char type [] )
47
{
48
if ( err )
49
{
50
// True if first strlen(type) characters of err match type
51
char const* p = err;
52
while ( *type && *type == *p )
53
{
54
type++;
55
p++;
56
}
57
58
if ( !*type )
59
return true;
60
}
61
62
return false;
63
}
64
65
const char* blargg_err_details( blargg_err_t err )
66
{
67
const char* p = err;
68
if ( !p )
69
{
70
p = "";
71
}
72
else if ( *p == BLARGG_ERR_TYPE("")[0] )
73
{
74
while ( *p && *p != ';' )
75
p++;
76
77
// Skip ; and space after it
78
if ( *p )
79
{
80
p++;
81
82
check( *p == ' ' );
83
if ( *p )
84
p++;
85
}
86
}
87
return p;
88
}
89
90
int blargg_err_to_code( blargg_err_t err, blargg_err_to_code_t const codes [] )
91
{
92
if ( !err )
93
return 0;
94
95
while ( codes->str && !blargg_is_err_type( err, codes->str ) )
96
codes++;
97
98
return codes->code;
99
}
100
101
blargg_err_t blargg_code_to_err( int code, blargg_err_to_code_t const codes [] )
102
{
103
if ( !code )
104
return blargg_ok;
105
106
while ( codes->str && codes->code != code )
107
codes++;
108
109
if ( !codes->str )
110
return blargg_err_generic;
111
112
return codes->str;
113
}
114
115