--- var.h 2002/02/27 13:44:16 1.23
+++ var.h 2002/02/28 08:08:16 1.24
@@ -77,46 +77,42 @@
VAR_ERR_INVALID_HEX = -3,
VAR_ERR_INCOMPLETE_HEX = -2,
VAR_ERR_INCOMPLETE_NAMED_CHARACTER = -1,
- VAR_OK = 0
+ VAR_OK = 0
} var_rc_t;
-/* Expand quoted pairs to their binary representation. */
-var_rc_t var_unescape(const char *src, size_t len, char *dst, int unescape_all);
+struct var_st;
+typedef struct var_st var_t;
-/* Prototype for the lookup callback used in var_expand(). */
-typedef var_rc_t (*var_cb_t)(
- void *context,
- const char *varname, size_t name_len, int idx,
- const char **data, size_t *data_len,
- size_t *buffer_size
-);
-
-/* Configure the var_expand() parser's tokens. */
-typedef struct {
- char varinit; /* '$' */
- char startdelim; /* '{' */
- char enddelim; /* '}' */
- char startindex; /* '[' */
- char endindex; /* ']' */
- char current_index; /* '#' */
- char escape; /* '\' */
- char *namechars; /* 'a-zA-Z0-9_' */
+typedef enum {
+ VAR_CONFIG_SYNTAX,
+ VAR_CONFIG_CB_VALUE
} var_config_t;
-/* The default configuration */
-extern const var_config_t var_config_default;
-
-/* Expand variable expressions in a text buffer. */
-var_rc_t var_expand(const char *input, size_t input_len,
- char **result, size_t *result_len,
- var_cb_t lookup, void *lookup_context,
- const var_config_t *config, int force_expand);
-
-/* Map an error code to a text message. */
-const char *var_strerror(var_rc_t rc);
+typedef struct {
+ char escape; /* default: '\' */
+ char delim_init; /* default: '$' */
+ char delim_open; /* default: '{' */
+ char delim_close; /* default: '}' */
+ char index_open; /* default: '[' */
+ char index_close; /* default: ']' */
+ char index_mark; /* default: '#' */
+ char *name_chars; /* default: "a-zA-Z0-9_" */
+} var_syntax_t;
+
+typedef var_rc_t (*var_cb_value_t)(
+ void *ctx,
+ const char *var_ptr, size_t var_len, int var_idx,
+ const char **val_ptr, size_t *val_len, size_t *val_size
+);
-/* Unique library identifier. */
extern const char var_id[];
+var_rc_t var_create (var_t **var);
+var_rc_t var_destroy (var_t *var);
+var_rc_t var_config (var_t *var, var_config_t mode, ...);
+var_rc_t var_unescape (var_t *var, const char *src_ptr, size_t src_len, char *dst_ptr, size_t dst_len, int all);
+var_rc_t var_expand (var_t *var, const char *src_ptr, size_t src_len, char **dst_ptr, size_t *dst_len, int force_expand);
+var_rc_t var_strerror (var_t *var, var_rc_t rc, char **str);
+
#endif /* __VAR_H__ */
|