-
Notifications
You must be signed in to change notification settings - Fork 3
/
coho.h
111 lines (93 loc) · 2.35 KB
/
coho.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
111
/*
* Copyright (c) 2017-2019 Ben Cornett <[email protected]>
*
* Permission to use, copy, modify, and 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.
*/
enum coho_status {
COHO_OK,
COHO_ERROR,
COHO_NOMEM,
};
/* Compatibility functions {{{
*/
#undef strlcpy
size_t strlcpy(char *, const char *, size_t);
#undef reallocarray
void *reallocarray(void *, size_t, size_t);
/* }}} */
/* SMILES parsing {{{
*/
enum {
COHO_SMILES_BOND_UNSPECIFIED = 0,
COHO_SMILES_BOND_SINGLE = 1,
COHO_SMILES_BOND_DOUBLE = 2,
COHO_SMILES_BOND_TRIPLE = 3,
COHO_SMILES_BOND_QUAD = 4,
COHO_SMILES_BOND_AROMATIC = 5,
};
enum {
COHO_SMILES_BOND_STEREO_UNSPECIFIED,
COHO_SMILES_BOND_STEREO_UP,
COHO_SMILES_BOND_STEREO_DOWN,
};
struct coho_smiles_atom {
int atomic_number;
char symbol[4];
int isotope;
int charge;
int hydrogen_count;
int implicit_hydrogen_count;
int is_bracket;
int is_organic;
int is_aromatic;
char chirality[8];
int atom_class;
int position;
int length;
};
struct coho_smiles_bond {
int atom0;
int atom1;
int order;
int stereo;
int is_implicit;
int is_ring;
int position;
int length;
};
struct coho_smiles_paren {
int position;
struct coho_smiles_bond bond;
};
struct coho_smiles {
const char *smiles;
int position;
int end;
char error[32];
int error_position;
int atom_count;
int bond_count;
struct coho_smiles_atom *atoms;
size_t atoms_cap;
struct coho_smiles_bond *bonds;
size_t bonds_cap;
struct coho_smiles_bond ring_bonds[100];
size_t open_ring_closures;
struct coho_smiles_paren *paren_stack;
int paren_stack_count;
size_t paren_stack_cap;
};
void coho_smiles_free(struct coho_smiles *);
void coho_smiles_init(struct coho_smiles *);
int coho_smiles_read(struct coho_smiles *, const char *, size_t);
/* }}} */