| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
#include <stdlib.h> |
|---|
| 21 |
#include "libswish3.h" |
|---|
| 22 |
|
|---|
| 23 |
int SWISH_DEBUG = 0; |
|---|
| 24 |
int SWISH_WARNINGS = 1; |
|---|
| 25 |
|
|---|
| 26 |
swish_3 * |
|---|
| 27 |
swish_init_swish3( |
|---|
| 28 |
void (*handler) (swish_ParserData *), |
|---|
| 29 |
void *stash |
|---|
| 30 |
) |
|---|
| 31 |
{ |
|---|
| 32 |
swish_3 *s3; |
|---|
| 33 |
s3 = swish_xmalloc(sizeof(swish_3)); |
|---|
| 34 |
s3->ref_cnt = 0; |
|---|
| 35 |
s3->config = swish_init_config(); |
|---|
| 36 |
s3->config->ref_cnt++; |
|---|
| 37 |
swish_config_set_default(s3->config); |
|---|
| 38 |
s3->analyzer = swish_init_analyzer(s3->config); |
|---|
| 39 |
s3->analyzer->ref_cnt++; |
|---|
| 40 |
s3->parser = swish_init_parser(handler); |
|---|
| 41 |
s3->parser->ref_cnt++; |
|---|
| 42 |
s3->stash = stash; |
|---|
| 43 |
|
|---|
| 44 |
if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { |
|---|
| 45 |
SWISH_DEBUG_MSG("s3 ptr 0x%x", (int)s3); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
return s3; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
void |
|---|
| 52 |
swish_free_swish3( |
|---|
| 53 |
swish_3 *s3 |
|---|
| 54 |
) |
|---|
| 55 |
{ |
|---|
| 56 |
s3->parser->ref_cnt--; |
|---|
| 57 |
if (s3->parser->ref_cnt < 1) { |
|---|
| 58 |
swish_free_parser(s3->parser); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
s3->analyzer->ref_cnt--; |
|---|
| 62 |
if (s3->analyzer->ref_cnt < 1) { |
|---|
| 63 |
swish_free_analyzer(s3->analyzer); |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
s3->config->ref_cnt--; |
|---|
| 67 |
if (s3->config->ref_cnt < 1) { |
|---|
| 68 |
swish_free_config(s3->config); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
if (s3->ref_cnt != 0) { |
|---|
| 72 |
SWISH_WARN("s3 ref_cnt != 0: %d\n", s3->ref_cnt); |
|---|
| 73 |
} |
|---|
| 74 |
swish_xfree(s3); |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
void |
|---|
| 79 |
swish_init( |
|---|
| 80 |
) |
|---|
| 81 |
{ |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
setenv("SWISH3", "1", 0); |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
setenv("SWISH_DEBUG", "0", 0); |
|---|
| 89 |
setenv("SWISH_DEBUG_MEMORY", "0", 0); |
|---|
| 90 |
setenv("SWISH_DEBUG_CONFIG", "0", 0); |
|---|
| 91 |
setenv("SWISH_DEBUG_DOCINFO", "0", 0); |
|---|
| 92 |
setenv("SWISH_DEBUG_TOKENLIST", "0", 0); |
|---|
| 93 |
setenv("SWISH_DEBUG_TOKENIZER", "0", 0); |
|---|
| 94 |
setenv("SWISH_DEBUG_PARSER", "0", 0); |
|---|
| 95 |
setenv("SWISH_DEBUG_NAMEDBUFFER", "0", 0); |
|---|
| 96 |
setenv("SWISH_WARNINGS", "1", 0); |
|---|
| 97 |
if (!SWISH_DEBUG) { |
|---|
| 98 |
|
|---|
| 99 |
SWISH_DEBUG += swish_string_to_int(getenv("SWISH_DEBUG")); |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
if (swish_string_to_int(getenv("SWISH_DEBUG_MEMORY"))) { |
|---|
| 104 |
SWISH_DEBUG += SWISH_DEBUG_MEMORY; |
|---|
| 105 |
} |
|---|
| 106 |
if (swish_string_to_int(getenv("SWISH_DEBUG_CONFIG"))) { |
|---|
| 107 |
SWISH_DEBUG += SWISH_DEBUG_CONFIG; |
|---|
| 108 |
} |
|---|
| 109 |
if (swish_string_to_int(getenv("SWISH_DEBUG_DOCINFO"))) { |
|---|
| 110 |
SWISH_DEBUG += SWISH_DEBUG_DOCINFO; |
|---|
| 111 |
} |
|---|
| 112 |
if (swish_string_to_int(getenv("SWISH_DEBUG_TOKENLIST"))) { |
|---|
| 113 |
SWISH_DEBUG += SWISH_DEBUG_TOKENLIST; |
|---|
| 114 |
} |
|---|
| 115 |
if (swish_string_to_int(getenv("SWISH_DEBUG_TOKENIZER"))) { |
|---|
| 116 |
SWISH_DEBUG += SWISH_DEBUG_TOKENIZER; |
|---|
| 117 |
} |
|---|
| 118 |
if (swish_string_to_int(getenv("SWISH_DEBUG_PARSER"))) { |
|---|
| 119 |
SWISH_DEBUG += SWISH_DEBUG_PARSER; |
|---|
| 120 |
} |
|---|
| 121 |
if (swish_string_to_int(getenv("SWISH_DEBUG_NAMEDBUFFER"))) { |
|---|
| 122 |
SWISH_DEBUG += SWISH_DEBUG_NAMEDBUFFER; |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
SWISH_WARNINGS = swish_string_to_int(getenv("SWISH_WARNINGS")); |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
LIBXML_TEST_VERSION swish_init_memory(); |
|---|
| 134 |
swish_verify_utf8_locale(); |
|---|
| 135 |
|
|---|
| 136 |
} |
|---|