File: php_yaml_int.h

package info (click to toggle)
php-yaml 2.2.2%2B2.1.0%2B2.0.4%2B1.3.2-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,784 kB
  • sloc: ansic: 9,085; xml: 1,793; makefile: 2
file content (177 lines) | stat: -rw-r--r-- 5,631 bytes parent folder | download | duplicates (4)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
 * YAML parser and emitter PHP extension
 *
 * Copyright (c) 2007 Ryusuke SEKIYAMA. All rights reserved.
 * Copyright (c) 2009 Keynetics Inc. All rights reserved.
 * Copyright (c) 2015 Bryan Davis and contributors. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * @package     php_yaml
 * @author      Ryusuke SEKIYAMA <rsky0711@gmail.com>
 * @author      Bryan Davis <bd808@bd808.com>
 * @copyright   2007 Ryusuke SEKIYAMA
 * @copyright   2009 Keynetics Inc
 * @copyright   2015 Bryan Davis and contributors
 * @license     http://www.opensource.org/licenses/mit-license.php  MIT License
 */


#ifndef PHP_YAML_INT_H
#define PHP_YAML_INT_H

#ifdef __cplusplus
extern "C" {
#endif

/* {{{ backcompat macros
*/
#ifndef ZVAL_OPT_DEREF
/* Taken from php-src/Zned/zend_types.h @ 95ff285 */
#define Z_OPT_ISREF(zval) (Z_OPT_TYPE(zval) == IS_REFERENCE)
#define Z_OPT_ISREF_P(zval_p) Z_OPT_ISREF(*(zval_p))
#define ZVAL_OPT_DEREF(z) do {           \
	if (UNEXPECTED(Z_OPT_ISREF_P(z))) {  \
		(z) = Z_REFVAL_P(z);             \
	}                                    \
} while (0)
#endif
/* }}} */

/* {{{ ext/yaml types
*/
typedef void (*eval_scalar_func_t)(yaml_event_t event, HashTable *callbacks, zval *retval TSRMLS_DC);

typedef struct parser_state_s {
	yaml_parser_t parser;
	yaml_event_t event;
	int have_event;
	zval aliases;
	eval_scalar_func_t eval_func;
	HashTable *callbacks;
} parser_state_t;

typedef struct y_emit_state_s {
	yaml_emitter_t *emitter;
	HashTable *recursive;
	HashTable *callbacks;
} y_emit_state_t;

/* }}} */


/* {{{ ext/yaml macros
*/
#define YAML_BINARY_TAG      "tag:yaml.org,2002:binary"
#define YAML_MERGE_TAG       "tag:yaml.org,2002:merge"
#define YAML_PHP_TAG         "!php/object"
#define YAML_NONSPECIFIC_TAG "!"

#define Y_SCALAR_IS_NOT_NUMERIC 0x00
#define Y_SCALAR_IS_INT         0x10
#define Y_SCALAR_IS_FLOAT       0x20
#define Y_SCALAR_IS_ZERO        0x00
#define Y_SCALAR_IS_BINARY      0x01
#define Y_SCALAR_IS_OCTAL       0x02
#define Y_SCALAR_IS_DECIMAL     0x03
#define Y_SCALAR_IS_HEXADECIMAL 0x04
#define Y_SCALAR_IS_SEXAGECIMAL 0x05
#define Y_SCALAR_IS_INFINITY_P  0x06
#define Y_SCALAR_IS_INFINITY_N  0x07
#define Y_SCALAR_IS_NAN         0x08
#define Y_SCALAR_FORMAT_MASK    0x0F


#if (PHP_MAJOR_VERSION > 5) || ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 3))
#	define ZEND_IS_CALLABLE(a,b,c) zend_is_callable((a), (b), (c) TSRMLS_CC)
#else
#	define ZEND_IS_CALLABLE(a,b,c) zend_is_callable((a), (b), (c))
#endif

#define STR_EQ(a, b)\
	(a != NULL && b != NULL && 0 == strcmp(a, b))

#define SCALAR_TAG_IS(event, name) \
	STR_EQ(name, (const char *)event.data.scalar.tag)

#define IS_NOT_IMPLICIT(event) \
	(!event.data.scalar.quoted_implicit && !event.data.scalar.plain_implicit)

#define IS_NOT_IMPLICIT_AND_TAG_IS(event, name) \
	(IS_NOT_IMPLICIT(event) && SCALAR_TAG_IS(event, name))

#define IS_NOT_QUOTED(event) \
	(YAML_PLAIN_SCALAR_STYLE == event.data.scalar.style || YAML_ANY_SCALAR_STYLE == event.data.scalar.style)

#define IS_NOT_QUOTED_OR_TAG_IS(event, name) \
	(IS_NOT_QUOTED(event) && (event.data.scalar.plain_implicit || SCALAR_TAG_IS(event, name)))

#define SCALAR_IS_QUOTED(event) \
	(YAML_SINGLE_QUOTED_SCALAR_STYLE == event.data.scalar.style || YAML_DOUBLE_QUOTED_SCALAR_STYLE == event.data.scalar.style)

/* }}} */

/* {{{ ext/yaml prototypes
*/
void php_yaml_read_all(parser_state_t *state, zend_long *ndocs, zval *retval TSRMLS_DC);

void php_yaml_read_partial(
		parser_state_t *state, zend_long pos, zend_long *ndocs, zval *retval TSRMLS_DC);

void eval_scalar(yaml_event_t event,
		HashTable * callbacks, zval *retval TSRMLS_DC);

void eval_scalar_with_callbacks(
		yaml_event_t event, HashTable *callbacks, zval *retval TSRMLS_DC);

const char *detect_scalar_type(
		const char *value, size_t length, const yaml_event_t *event);

int scalar_is_null(
		const char *value, size_t length, const yaml_event_t *event);

int scalar_is_bool(
		const char *value, size_t length, const yaml_event_t *event);

int scalar_is_numeric(
		const char *value, size_t length, zend_long *lval, double *dval, char **str);

int scalar_is_timestamp(const char *value, size_t length);

int php_yaml_write_impl(yaml_emitter_t *emitter, zval *data,
		yaml_encoding_t encoding, HashTable *callbacks TSRMLS_DC);

int php_yaml_write_to_buffer(
		void *data, unsigned char *buffer, size_t size);

/* }}} */

#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* PHP_YAML_INT_H */

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */