-
Notifications
You must be signed in to change notification settings - Fork 4
/
bitconvert.h
110 lines (89 loc) · 3.48 KB
/
bitconvert.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* bitconvert.h - bit decoding declarations
* This file is part of libbitconvert.
*
* Copyright (c) 2008-2009, Denver Gingerich <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*********************************************************************/
/***** THIS API IS NOT YET STABLE; FREQUENT CHANGES WILL BE MADE *****/
/*********************************************************************/
#ifndef H_BITCONVERT
#define H_BITCONVERT
#include <stddef.h> /* size_t */
#ifdef __cplusplus
extern "C" {
#endif
/* define mask to use for errors related to the formats file */
#define BCERR_MASK_FORMAT 0x80
/* when adding to this list, also add a case to the switch in bc_strerror */
#define BCERR_INVALID_INPUT 1
#define BCERR_PARITY_MISMATCH 2
/* 3 was used for BCERR_RESULT_FULL; we're using dynamic allocation now */
/* 4 was used for BCERR_INVALID_TRACK; now we accept all tracks at once */
#define BCERR_NO_FORMAT_FILE (BCERR_MASK_FORMAT | 5)
#define BCERR_PCRE_COMPILE_FAILED (BCERR_MASK_FORMAT | 6)
#define BCERR_FORMAT_MISSING_PERIOD (BCERR_MASK_FORMAT | 7)
#define BCERR_FORMAT_MISSING_NAME (BCERR_MASK_FORMAT | 8)
#define BCERR_NO_MATCHING_FORMAT (BCERR_MASK_FORMAT | 9)
#define BCERR_BAD_FORMAT_ENCODING_TYPE (BCERR_MASK_FORMAT | 10)
#define BCERR_FORMAT_MISSING_RE (BCERR_MASK_FORMAT | 11)
#define BCERR_UNIMPLEMENTED 12
#define BCERR_OUT_OF_MEMORY 13
#define BCERR_FORMAT_MISSING_TRACK (BCERR_MASK_FORMAT | 14)
#define BCERR_FORMAT_MISSING_SPACE (BCERR_MASK_FORMAT | 15)
#define BCERR_FORMAT_NAMED_SUBSTRING (BCERR_MASK_FORMAT | 16)
#define BC_ENCODING_NONE -1 /* track has no data; not the same as binary */
#define BC_ENCODING_BINARY 1
#define BC_ENCODING_BCD 4
#define BC_ENCODING_ALPHA 6
#define BC_ENCODING_ASCII 7
#define BC_TRACK_1 1
#define BC_TRACK_2 2
#define BC_TRACK_3 3
struct bc_input {
char* t1;
char* t2;
char* t3;
};
struct bc_decoded {
char* t1;
char* t2;
char* t3;
/* one of BC_ENCODING_* */
int t1_encoding;
int t2_encoding;
int t3_encoding;
/* name of the card; based on the match in the formats file */
char* name;
/* NULL-terminated array of field names */
char** field_names;
/* empty strings may be valid values; use field_names to find end */
const char** field_values;
/* one of BC_TRACK_* to represent the track the field is stored on */
int* field_tracks;
};
/* user may provide a null error_callback to ignore error messages */
void bc_init(void (*error_callback)(const char*));
int bc_decode(struct bc_input* in, struct bc_decoded* result);
int bc_find_fields(struct bc_decoded* result);
int bc_combine(struct bc_input* forward, struct bc_input* backward,
struct bc_input* combined);
const char* bc_strerror(int err);
void bc_input_free(struct bc_input* in);
void bc_decoded_free(struct bc_decoded* result);
#ifdef __cplusplus
}
#endif
#endif /* H_BITCONVERT */