[svn-upgrade] Integrating new upstream version, libhtml-template-pro-perl (0.92)
Jonathan Yu
14 years ago
41 | 41 | parse_expr.h |
42 | 42 | pbuffer.c |
43 | 43 | pbuffer.h |
44 | pconst.h | |
44 | 45 | perl-HTML-Template-Pro.spec |
45 | 46 | pmiscdef.h |
46 | 47 | pparam.h |
0 | 0 | --- #YAML:1.0 |
1 | 1 | name: HTML-Template-Pro |
2 | version: 0.91 | |
2 | version: 0.92 | |
3 | 3 | abstract: Perl/XS module to use HTML Templates from CGI scripts |
4 | 4 | license: perl or LGPL2+ |
5 | 5 | author: |
24 | 24 | } |
25 | 25 | |
26 | 26 | my %DEF=( |
27 | MAINTAINER => $^O eq 'linux' && -d '.git' ? 1 : 0, | |
27 | 28 | PCRE => 1, |
28 | 29 | DEBUG => 0, |
29 | 30 | MMAP => 1, |
77 | 78 | ); |
78 | 79 | |
79 | 80 | sub MY::postamble { |
81 | return '' unless $DEF{MAINTAINER}; | |
80 | 82 | return <<'MAKE_FRAG'; |
81 | 83 | expr.c: calc.inc exprtool.inc exprpstr.inc |
82 | 84 | procore\$(OBJ_EXT): loadfile.inc tagstack.inc |
0 | HTML-Template-Pro version 0.91 | |
0 | HTML-Template-Pro version 0.92 | |
1 | 1 | ============================== |
2 | 2 | |
3 | 3 | DESCRIPTION |
168 | 168 | } |
169 | 169 | /* old prev_slash_next now current, so we need to recalculate it */ |
170 | 170 | /* first find a 'slash' char */ |
171 | while (!IS_FILE_SEP(*prev_slash_next) && prev_slash_next>=slash_begin) prev_slash_next--; | |
171 | while (prev_slash_next>=slash_begin && !IS_FILE_SEP(*prev_slash_next)) prev_slash_next--; | |
172 | 172 | if (prev_slash_next>slash_begin) prev_slash_next++;/* step next to slash */ |
173 | 173 | } else { |
174 | 174 | prev_slash_next=pos+1; |
2 | 2 | #include "pabidecl.h" |
3 | 3 | #include "pabstract.h" |
4 | 4 | #include "pparam.h" |
5 | #include "procore.h" | |
5 | #include "pconst.h" | |
6 | 6 | |
7 | 7 | API_IMPL |
8 | 8 | int |
0 | 0 | #include "pabidecl.h" |
1 | 1 | #include "pabstract.h" |
2 | 2 | #include "pparam.h" |
3 | #include "procore.h" | |
3 | #include "pconst.h" | |
4 | 4 | |
5 | 5 | API_IMPL |
6 | 6 | int |
0 | 0 | #include "pabidecl.h" |
1 | 1 | #include "pabstract.h" |
2 | 2 | #include "pparam.h" |
3 | #include "procore.h" | |
3 | #include "pconst.h" | |
4 | 4 | |
5 | 5 | API_IMPL |
6 | 6 | int |
11 | 11 | use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); |
12 | 12 | @ISA = qw(DynaLoader Exporter); |
13 | 13 | |
14 | $VERSION = '0.91'; | |
14 | $VERSION = '0.92'; | |
15 | 15 | |
16 | 16 | @EXPORT_OK = qw/ASK_NAME_DEFAULT ASK_NAME_AS_IS ASK_NAME_LOWERCASE ASK_NAME_UPPERCASE ASK_NAME_MASK/; |
17 | 17 | %EXPORT_TAGS = (const => [qw/ASK_NAME_DEFAULT ASK_NAME_AS_IS ASK_NAME_LOWERCASE ASK_NAME_UPPERCASE ASK_NAME_MASK/]); |
0 | #ifndef _PCONST_H | |
1 | #define _PCONST_H 1 | |
2 | ||
3 | /* internal constants */ | |
4 | ||
5 | #define ERR_PRO_INVALID_ARGUMENT 1 | |
6 | #define ERR_PRO_FILE_NOT_FOUND 2 | |
7 | #define ERR_PRO_CANT_OPEN_FILE 3 | |
8 | #define ERR_PRO_TEMPLATE_SYNTAX_ERROR 4 | |
9 | ||
10 | #endif /* pconst.h */ | |
11 | ||
12 | /* | |
13 | * Local Variables: | |
14 | * mode: c | |
15 | * End: | |
16 | */ |
5 | 5 | %define module HTML-Template-Pro |
6 | 6 | |
7 | 7 | Name: perl-%module |
8 | Version: 0.91 | |
8 | Version: 0.92 | |
9 | 9 | Release: alt1 |
10 | 10 | |
11 | 11 | Packager: Igor Yu. Vlasenko <viy@altlinux.org> |
53 | 53 | %perl_vendor_man3dir/* |
54 | 54 | |
55 | 55 | %changelog |
56 | * Tue Sep 29 2009 Igor Vlasenko <viy@altlinux.ru> 0.92-alt1 | |
57 | - new version; see Changes | |
58 | ||
56 | 59 | * Tue Sep 22 2009 Igor Vlasenko <viy@altlinux.ru> 0.91-alt1 |
57 | 60 | - new version; see Changes |
58 | 61 |
21 | 21 | # define MOD_TD "%ld" |
22 | 22 | #endif |
23 | 23 | |
24 | #if ! HAVE_STRDUP && ! defined strdup | |
25 | # if HAVE__STRDUP | |
24 | #if ! defined HAVE_STRDUP && ! defined strdup | |
25 | # if defined HAVE__STRDUP | |
26 | 26 | # define strdup _strdup |
27 | 27 | # else |
28 | 28 | # define strdup(str) strcpy(malloc(strlen(str) + 1), str) |
3 | 3 | #include <ctype.h> |
4 | 4 | |
5 | 5 | #include "tmplpro.h" |
6 | #include "pconst.h" | |
6 | 7 | #include "procore.h" |
7 | 8 | #include "prostate.h" |
8 | 9 | #include "provalue.h" |
83 | 84 | { 0, 0, 0, 0, 0, 0 }, /**/ |
84 | 85 | }; |
85 | 86 | |
86 | /* max offset to ensure we are not out of file when try <!--/ */ | |
87 | #define TAG_WIDTH_OFFSET 4 | |
87 | typedef void (*tag_handler_func)(struct tmplpro_state *state, const PSTRING* const TagOptVal); | |
88 | ||
89 | static const tag_handler_func const output_closetag_handler[]={ | |
90 | tag_handler_unknown, /*Bad or unsupported tag*/ | |
91 | tag_handler_unknown, /*VAR*/ | |
92 | tag_handler_unknown, /*INCLUDE*/ | |
93 | tag_handler_closeloop, /*LOOP*/ | |
94 | tag_handler_closeif, /*IF*/ | |
95 | tag_handler_unknown, /*ELSE*/ | |
96 | tag_handler_closeunless, /*UNLESS*/ | |
97 | tag_handler_unknown, /*ELSIF*/ | |
98 | tag_handler_unknown, /**/ | |
99 | }; | |
100 | static const tag_handler_func const output_opentag_handler[]={ | |
101 | tag_handler_unknown, /*Bad or unsupported tag*/ | |
102 | tag_handler_var, /*VAR*/ | |
103 | tag_handler_include, /*INCLUDE*/ | |
104 | tag_handler_loop, /*LOOP*/ | |
105 | tag_handler_if, /*IF*/ | |
106 | tag_handler_else, /*ELSE*/ | |
107 | tag_handler_unless, /*UNLESS*/ | |
108 | tag_handler_elsif, /*ELSIF*/ | |
109 | tag_handler_unknown, /**/ | |
110 | }; | |
88 | 111 | |
89 | 112 | static |
90 | 113 | int |
320 | 343 | (state->param->WriterFuncPtr)(state->param->ext_writer_state,state->last_processed_pos,state->tag_start); |
321 | 344 | state->last_processed_pos=state->cur_pos; |
322 | 345 | } |
323 | /* TODO: call tag_specific handler by array of handlers | |
324 | var_tag_handler(..) */ | |
325 | 346 | if (is_tag_closed) { |
326 | switch (tag_type) { | |
327 | case HTML_TEMPLATE_TAG_IF: tag_handler_closeif(state);break; | |
328 | case HTML_TEMPLATE_TAG_UNLESS: tag_handler_closeunless(state);break; | |
329 | case HTML_TEMPLATE_TAG_LOOP: tag_handler_closeloop(state);break; | |
330 | default: tag_handler_unknown(state);break; | |
331 | } | |
347 | output_closetag_handler[tag_type](state,TagOptVal); | |
332 | 348 | } else { |
333 | switch (tag_type) { | |
334 | case HTML_TEMPLATE_TAG_VAR: tag_handler_var(state,TagOptVal); break; | |
335 | case HTML_TEMPLATE_TAG_IF: tag_handler_if(state,TagOptVal); break; | |
336 | case HTML_TEMPLATE_TAG_UNLESS: tag_handler_unless(state,TagOptVal); break; | |
337 | case HTML_TEMPLATE_TAG_ELSE: tag_handler_else(state,TagOptVal); break; | |
338 | case HTML_TEMPLATE_TAG_ELSIF: tag_handler_elsif(state,TagOptVal); break; | |
339 | case HTML_TEMPLATE_TAG_LOOP: tag_handler_loop(state,TagOptVal); break; | |
340 | case HTML_TEMPLATE_TAG_INCLUDE: tag_handler_include(state,TagOptVal);break; | |
341 | default: tag_handler_unknown(state);break; | |
342 | } | |
343 | } | |
344 | } | |
345 | ||
349 | output_opentag_handler[tag_type](state,TagOptVal); | |
350 | } | |
351 | } | |
352 | ||
353 | ||
354 | /* max offset to ensure we are not out of file when try <!--/ */ | |
355 | #define TAG_WIDTH_OFFSET 4 | |
346 | 356 | static |
347 | 357 | void |
348 | 358 | process_state (struct tmplpro_state * state) |
0 | #define ERR_PRO_INVALID_ARGUMENT 1 | |
1 | #define ERR_PRO_FILE_NOT_FOUND 2 | |
2 | #define ERR_PRO_CANT_OPEN_FILE 3 | |
3 | #define ERR_PRO_TEMPLATE_SYNTAX_ERROR 4 | |
4 | ||
5 | 0 | #include "pstring.h" |
6 | 1 | #include "tmpllog.h" |
7 | 2 | #include "pabstract.h" |
70 | 70 | } else return 1; |
71 | 71 | } |
72 | 72 | |
73 | #define MAX_ESCAPE_SEQ sizeof(""") | |
73 | 74 | static |
74 | 75 | PSTRING |
75 | 76 | htmlencode_pstring (pbuffer* StrBuffer, PSTRING pstring) { |
76 | char* buf=pbuffer_resize(StrBuffer, pstring.endnext-pstring.begin+1); | |
77 | char* buf=pbuffer_resize(StrBuffer, pstring.endnext-pstring.begin+1+MAX_ESCAPE_SEQ); | |
77 | 78 | const char* curpos=pstring.begin; |
78 | 79 | size_t offset=0; |
79 | 80 | size_t buflen=pbuffer_size(StrBuffer); |
81 | 82 | while (curpos<pstring.endnext) { |
82 | 83 | unsigned char curchar=*curpos++; |
83 | 84 | int bufdelta=1; |
84 | if (offset>=buflen) { | |
85 | buf=pbuffer_resize(StrBuffer, 2*offset); | |
85 | if (offset>=buflen-MAX_ESCAPE_SEQ) { | |
86 | buf=pbuffer_resize(StrBuffer, 2*(offset+MAX_ESCAPE_SEQ)); | |
86 | 87 | buflen=pbuffer_size(StrBuffer); |
87 | 88 | } |
88 | 89 | switch (curchar) { |
104 | 105 | static |
105 | 106 | PSTRING |
106 | 107 | jsencode_pstring (pbuffer* StrBuffer, PSTRING pstring) { |
107 | char* buf=pbuffer_resize(StrBuffer, pstring.endnext-pstring.begin+1); | |
108 | char* buf=pbuffer_resize(StrBuffer, pstring.endnext-pstring.begin+1+MAX_ESCAPE_SEQ); | |
108 | 109 | const char* curpos=pstring.begin; |
109 | 110 | size_t offset=0; |
110 | 111 | size_t buflen=pbuffer_size(StrBuffer); |
112 | 113 | while (curpos<pstring.endnext) { |
113 | 114 | unsigned char curchar=*curpos++; |
114 | 115 | int bufdelta=1; |
115 | if (offset>=buflen) { | |
116 | buf=pbuffer_resize(StrBuffer, 2*offset); | |
116 | if (offset>=buflen-MAX_ESCAPE_SEQ) { | |
117 | buf=pbuffer_resize(StrBuffer, 2*(offset+MAX_ESCAPE_SEQ)); | |
117 | 118 | buflen=pbuffer_size(StrBuffer); |
118 | 119 | } |
119 | 120 | switch (curchar) { |
134 | 135 | static |
135 | 136 | PSTRING |
136 | 137 | urlencode_pstring (pbuffer* StrBuffer, PSTRING pstring) { |
137 | char* buf=pbuffer_resize(StrBuffer, pstring.endnext-pstring.begin+1); | |
138 | char* buf=pbuffer_resize(StrBuffer, pstring.endnext-pstring.begin+1+MAX_ESCAPE_SEQ); | |
138 | 139 | const char* curpos=pstring.begin; |
139 | 140 | size_t offset=0; |
140 | 141 | size_t buflen=pbuffer_size(StrBuffer); |
142 | 143 | while (curpos<pstring.endnext) { |
143 | 144 | unsigned char curchar=*curpos++; |
144 | 145 | int bufdelta=1; |
145 | if (offset>=buflen) { | |
146 | buf=pbuffer_resize(StrBuffer, 2*offset); | |
146 | if (offset>=buflen-MAX_ESCAPE_SEQ) { | |
147 | buf=pbuffer_resize(StrBuffer, 2*(offset+MAX_ESCAPE_SEQ)); | |
147 | 148 | buflen=pbuffer_size(StrBuffer); |
148 | 149 | } |
149 | 150 | /* |
2 | 2 | #include "pabidecl.h" |
3 | 3 | #include "pabstract.h" |
4 | 4 | #include "pparam.h" |
5 | #include "procore.h" | |
5 | #include "pconst.h" | |
6 | 6 | |
7 | 7 | API_IMPL |
8 | 8 | int |
0 | 0 | #include "pabidecl.h" |
1 | 1 | #include "pabstract.h" |
2 | 2 | #include "pparam.h" |
3 | #include "procore.h" | |
3 | #include "pconst.h" | |
4 | 4 | |
5 | 5 | API_IMPL |
6 | 6 | int |
0 | 0 | #include "pabidecl.h" |
1 | 1 | #include "pabstract.h" |
2 | 2 | #include "pparam.h" |
3 | #include "procore.h" | |
3 | #include "pconst.h" | |
4 | 4 | |
5 | 5 | API_IMPL |
6 | 6 | int |
317 | 317 | |
318 | 318 | static |
319 | 319 | void |
320 | tag_handler_closeif (struct tmplpro_state *state) | |
320 | tag_handler_closeif (struct tmplpro_state *state, const PSTRING* const TagOptVal) | |
321 | 321 | { |
322 | 322 | struct tagstack_entry iftag; |
323 | 323 | if (! test_stack(HTML_TEMPLATE_TAG_IF)) { |
331 | 331 | |
332 | 332 | static |
333 | 333 | void |
334 | tag_handler_closeunless (struct tmplpro_state *state) | |
334 | tag_handler_closeunless (struct tmplpro_state *state, const PSTRING* const TagOptVal) | |
335 | 335 | { |
336 | 336 | struct tagstack_entry iftag; |
337 | 337 | if (! test_stack(HTML_TEMPLATE_TAG_UNLESS)) { |
467 | 467 | |
468 | 468 | static |
469 | 469 | void |
470 | tag_handler_closeloop (struct tmplpro_state *state) | |
470 | tag_handler_closeloop (struct tmplpro_state *state, const PSTRING* const TagOptVal) | |
471 | 471 | { |
472 | 472 | struct tagstack_entry* iftag_ptr; |
473 | 473 | if (! test_stack(HTML_TEMPLATE_TAG_LOOP)) { |
491 | 491 | |
492 | 492 | static |
493 | 493 | void |
494 | tag_handler_unknown (struct tmplpro_state *state) | |
494 | tag_handler_unknown (struct tmplpro_state *state, const PSTRING* const TagOptVal) | |
495 | 495 | { |
496 | 496 | log_state(state,TMPL_LOG_ERROR,"tag_handler_unknown: unknown tag\n"); |
497 | 497 | } |