| 1 |
|
| static |
| 2 |
1140 |
| int get_escape_option(struct tmplpro_state *state, PSTRING OptEscape) |
| 3 |
|
| { |
| 4 |
|
| /* int escape = HTML_TEMPLATE_OPT_ESCAPE_NO; */ |
| 5 |
1140 |
| int escape = state->param->default_escape; |
| 6 |
1140 |
▶ | if (OptEscape.begin<OptEscape.endnext) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (OptEscape.begin<OptEscape.endnext) { |
90 |
1050 |
1140 |
|
| 7 |
90 |
| switch (*OptEscape.begin) { |
| 8 |
60 |
| case '1': case 'H': case 'h': /* HTML*/ |
| 9 |
60 |
| escape = HTML_TEMPLATE_OPT_ESCAPE_HTML; |
| 10 |
60 |
| break; |
| 11 |
13 |
| case 'U': case 'u': /* URL */ |
| 12 |
13 |
| escape = HTML_TEMPLATE_OPT_ESCAPE_URL; |
| 13 |
13 |
| break; |
| 14 |
9 |
| case 'J': case 'j': /* JS */ |
| 15 |
9 |
| escape = HTML_TEMPLATE_OPT_ESCAPE_JS; |
| 16 |
9 |
| break; |
| 17 |
8 |
| case '0': case 'N': case 'n': /* 0 or NONE */ |
| 18 |
8 |
| escape = HTML_TEMPLATE_OPT_ESCAPE_NO; |
| 19 |
8 |
| break; |
| 20 |
0 |
| default: |
| 21 |
0 |
| state->param->found_syntax_error=1; |
| 22 |
0 |
| log_state(state,TMPL_LOG_ERROR, " unsupported value of ESCAPE=%.*s\n",(int)(OptEscape.endnext-OptEscape.begin),OptEscape.begin); |
| 23 |
|
| } |
| 24 |
|
| } |
| 25 |
1140 |
| return escape; |
| 26 |
|
| } |
| 27 |
|
| |
| 28 |
|
| static |
| 29 |
1393 |
| void init_tmpl_var_case_buffers (struct tmplpro_param *param) { |
| 30 |
1393 |
| param->lowercase_varname.begin = NULL; |
| 31 |
1393 |
| param->lowercase_varname.endnext = NULL; |
| 32 |
1393 |
| param->uppercase_varname.begin = NULL; |
| 33 |
1393 |
| param->uppercase_varname.endnext = NULL; |
| 34 |
1393 |
| } |
| 35 |
|
| |
| 36 |
|
| static |
| 37 |
1444 |
| ABSTRACT_VALUE* get_abstract_value (struct tmplpro_param *param, int scope_level, PSTRING name) { |
| 38 |
1444 |
| ABSTRACT_VALUE* retval = NULL; |
| 39 |
1444 |
| ABSTRACT_MAP* param_HV = getScope(¶m->var_scope_stack, scope_level)->param_HV; |
| 40 |
1444 |
| ABSTRACT_DATASTATE* data_state = param->ext_data_state; |
| 41 |
1444 |
| get_ABSTRACT_VALUE_functype getval_func = param->GetAbstractValFuncPtr; |
| 42 |
1444 |
| int tmpl_var_case = param->tmpl_var_case; |
| 43 |
1444 |
▶ | if ((tmpl_var_case & ASK_NAME_MASK) == ASK_NAME_DEFAULT |
Branch: 1 branch
| Branch | True | False | Total |
| if ((tmpl_var_case & ASK_NAME_MASK) == ASK_NAME_DEFAULT |
1425 |
19 |
1444 |
|
| 44 |
1425 |
▶ | || tmpl_var_case & ASK_NAME_AS_IS) { |
Branch: 1 branch
| Branch | True | False | Total |
| || tmpl_var_case & ASK_NAME_AS_IS) { |
44 |
1381 |
1425 |
|
| 45 |
63 |
| retval = getval_func(data_state, param_HV, name); |
| 46 |
63 |
▶ | if (retval != NULL) return retval; |
Branch: 1 branch
| Branch | True | False | Total |
| if (retval != NULL) return retval; |
33 |
30 |
63 |
|
| 47 |
|
| } |
| 48 |
1411 |
▶ | if (tmpl_var_case & ASK_NAME_LOWERCASE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tmpl_var_case & ASK_NAME_LOWERCASE) { |
985 |
426 |
1411 |
|
| 49 |
985 |
▶ | if (param->lowercase_varname.begin == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->lowercase_varname.begin == NULL) { |
934 |
51 |
985 |
|
| 50 |
934 |
| param->lowercase_varname=lowercase_pstring(¶m->lowercase_varname_buffer, name); |
| 51 |
|
| } |
| 52 |
985 |
| retval = getval_func(data_state, param_HV, param->lowercase_varname); |
| 53 |
985 |
▶ | if (retval != NULL) return retval; |
Branch: 1 branch
| Branch | True | False | Total |
| if (retval != NULL) return retval; |
788 |
197 |
985 |
|
| 54 |
|
| } |
| 55 |
623 |
▶ | if (tmpl_var_case & ASK_NAME_UPPERCASE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tmpl_var_case & ASK_NAME_UPPERCASE) { |
426 |
197 |
623 |
|
| 56 |
426 |
▶ | if (param->uppercase_varname.begin == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->uppercase_varname.begin == NULL) { |
426 |
0 |
426 |
|
| 57 |
426 |
| param->uppercase_varname=uppercase_pstring(¶m->uppercase_varname_buffer, name); |
| 58 |
|
| } |
| 59 |
426 |
| retval = getval_func(data_state, param_HV, param->uppercase_varname); |
| 60 |
426 |
▶ | if (retval != NULL) return retval; |
Branch: 1 branch
| Branch | True | False | Total |
| if (retval != NULL) return retval; |
288 |
138 |
426 |
|
| 61 |
|
| } |
| 62 |
335 |
| return retval; |
| 63 |
|
| } |
| 64 |
|
| |
| 65 |
|
| static |
| 66 |
1393 |
| ABSTRACT_VALUE* walk_through_nested_loops (struct tmplpro_param *param, PSTRING name) { |
| 67 |
|
| int CurLevel; |
| 68 |
|
| ABSTRACT_VALUE* valptr; |
| 69 |
1393 |
| init_tmpl_var_case_buffers (param); |
| 70 |
|
| /* Shigeki Morimoto path_like_variable_scope extension */ |
| 71 |
1393 |
▶ | if (param->path_like_variable_scope) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->path_like_variable_scope) { |
13 |
1380 |
1393 |
|
| 72 |
13 |
▶ | if(*(name.begin) == '/' || strncmp(name.begin, "../", 3) == 0){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(*(name.begin) == '/' || strncmp(name.begin, "../", 3) == 0){ |
9 |
4 |
13 |
| if(*(name.begin) == '/' || strncmp(name.begin, "../", 3) == 0){ |
2 |
7 |
9 |
|
| 73 |
|
| PSTRING tmp_name; |
| 74 |
|
| int GoalHash; |
| 75 |
6 |
▶ | if(*(name.begin) == '/'){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(*(name.begin) == '/'){ |
4 |
2 |
6 |
|
| 76 |
4 |
| tmp_name.begin = name.begin+1; // skip '/' |
| 77 |
4 |
| tmp_name.endnext = name.endnext; |
| 78 |
4 |
| GoalHash = 0; |
| 79 |
|
| }else{ |
| 80 |
2 |
| tmp_name.begin = name.begin; |
| 81 |
2 |
| tmp_name.endnext = name.endnext; |
| 82 |
2 |
| GoalHash = curScopeLevel(¶m->var_scope_stack); |
| 83 |
4 |
▶ | while(strncmp(tmp_name.begin, "../", 3) == 0){ |
Branch: 1 branch
| Branch | True | False | Total |
| while(strncmp(tmp_name.begin, "../", 3) == 0){ |
2 |
2 |
4 |
|
| 84 |
2 |
| tmp_name.begin = tmp_name.begin + 3; // skip '../' |
| 85 |
2 |
| GoalHash --; |
| 86 |
|
| } |
| 87 |
|
| } |
| 88 |
6 |
| return get_abstract_value(param, GoalHash, tmp_name); |
| 89 |
|
| } |
| 90 |
|
| } |
| 91 |
|
| /* end Shigeki Morimoto path_like_variable_scope extension */ |
| 92 |
|
| |
| 93 |
1387 |
| CurLevel = curScopeLevel(¶m->var_scope_stack); |
| 94 |
1387 |
| valptr = get_abstract_value(param, CurLevel, name); |
| 95 |
1387 |
▶ | if (valptr) return valptr; |
Branch: 1 branch
| Branch | True | False | Total |
| if (valptr) return valptr; |
1066 |
321 |
1387 |
|
| 96 |
|
| /* optional strict scoping; does it have much sence? |
| 97 |
|
| if ((STRICT_SCOPING==param->global_vars)) return NULL; |
| 98 |
|
| */ |
| 99 |
|
| |
| 100 |
|
| /* loop-bounded scoping; */ |
| 101 |
321 |
▶ | if (0==param->global_vars) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (0==param->global_vars) { |
285 |
36 |
321 |
|
| 102 |
285 |
▶ | while (isScopeMap(getScope(¶m->var_scope_stack,CurLevel)) && --CurLevel>=0) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (isScopeMap(getScope(¶m->var_scope_stack,CurLevel)) && --CurLevel>=0) { |
204 |
81 |
285 |
| while (isScopeMap(getScope(¶m->var_scope_stack,CurLevel)) && --CurLevel>=0) { |
1 |
203 |
204 |
|
| 103 |
1 |
| valptr = get_abstract_value(param, CurLevel, name); |
| 104 |
1 |
▶ | if (valptr!=NULL) return valptr; |
Branch: 1 branch
| Branch | True | False | Total |
| if (valptr!=NULL) return valptr; |
1 |
0 |
1 |
|
| 105 |
|
| } |
| 106 |
284 |
| return NULL; |
| 107 |
|
| } |
| 108 |
|
| |
| 109 |
50 |
▶ | while (--CurLevel>=0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (--CurLevel>=0) { |
50 |
0 |
50 |
|
| 110 |
50 |
| valptr = get_abstract_value(param, CurLevel, name); |
| 111 |
50 |
▶ | if (valptr!=NULL) return valptr; |
Branch: 1 branch
| Branch | True | False | Total |
| if (valptr!=NULL) return valptr; |
36 |
14 |
50 |
|
| 112 |
|
| } |
| 113 |
0 |
| return NULL; |
| 114 |
|
| } |
| 115 |
|
| |
| 116 |
|
| TMPLPRO_LOCAL |
| 117 |
1027 |
| PSTRING _get_variable_value (struct tmplpro_param *param, PSTRING name) { |
| 118 |
1027 |
| PSTRING varvalue ={NULL, NULL}; |
| 119 |
|
| ABSTRACT_VALUE* abstrval; |
| 120 |
1027 |
▶ | if (param->loop_context_vars) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->loop_context_vars) { |
768 |
259 |
1027 |
|
| 121 |
768 |
| varvalue=get_loop_context_vars_value(param, name); |
| 122 |
|
| } |
| 123 |
1027 |
▶ | if (varvalue.begin==NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (varvalue.begin==NULL) { |
856 |
171 |
1027 |
|
| 124 |
856 |
| abstrval=walk_through_nested_loops(param, name); |
| 125 |
856 |
▶ | if (abstrval!=NULL) varvalue=(param->AbstractVal2pstringFuncPtr)(param->ext_data_state, abstrval); |
Branch: 1 branch
| Branch | True | False | Total |
| if (abstrval!=NULL) varvalue=(param->AbstractVal2pstringFuncPtr)(param->ext_data_state, abstrval); |
730 |
126 |
856 |
|
| 126 |
|
| } |
| 127 |
1027 |
▶ | if (debuglevel>=TMPL_LOG_DEBUG2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel>=TMPL_LOG_DEBUG2) { |
0 |
1027 |
1027 |
|
| 128 |
0 |
▶ | if (name.begin!=NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (name.begin!=NULL) { |
0 |
0 |
0 |
|
| 129 |
0 |
| tmpl_log(TMPL_LOG_DEBUG2,"_get_variable_value: name = %.*s ",(int)(name.endnext-name.begin),name.begin); |
| 130 |
|
| } else { |
| 131 |
0 |
| tmpl_log(TMPL_LOG_DEBUG2,"_get_variable_value: name = NULL "); |
| 132 |
|
| } |
| 133 |
0 |
▶ | if (varvalue.begin!=NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (varvalue.begin!=NULL) { |
0 |
0 |
0 |
|
| 134 |
0 |
| tmpl_log(TMPL_LOG_DEBUG2,"value = %.*s\n",(int)(varvalue.endnext-varvalue.begin),varvalue.begin); |
| 135 |
|
| } else { |
| 136 |
0 |
| tmpl_log(TMPL_LOG_DEBUG2,"value = UNDEF\n"); |
| 137 |
|
| } |
| 138 |
|
| } |
| 139 |
1027 |
| return varvalue; |
| 140 |
|
| } |
| 141 |
|
| |
| 142 |
|
| static |
| 143 |
1140 |
| PSTRING get_variable_option (struct tmplpro_state *state, const PSTRING* const TagOptVal) { |
| 144 |
1140 |
| PSTRING varvalue ={NULL, NULL}; |
| 145 |
1140 |
| PSTRING defvalue = TagOptVal[TAG_OPT_DEFAULT]; |
| 146 |
1140 |
▶ | if (TagOptVal[TAG_OPT_EXPR].begin!=NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (TagOptVal[TAG_OPT_EXPR].begin!=NULL) { |
477 |
663 |
1140 |
|
| 147 |
477 |
| varvalue=parse_expr(TagOptVal[TAG_OPT_EXPR], state); |
| 148 |
|
| } else { |
| 149 |
663 |
| varvalue=_get_variable_value(state->param, TagOptVal[TAG_OPT_NAME]); |
| 150 |
|
| } |
| 151 |
1140 |
▶ | if (varvalue.begin==NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (varvalue.begin==NULL) { |
120 |
1020 |
1140 |
|
| 152 |
120 |
▶ | if (defvalue.begin!=defvalue.endnext) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (defvalue.begin!=defvalue.endnext) { |
27 |
93 |
120 |
|
| 153 |
27 |
| varvalue=defvalue; |
| 154 |
|
| } |
| 155 |
|
| } |
| 156 |
1140 |
| return varvalue; |
| 157 |
|
| } |
| 158 |
|
| |
| 159 |
|
| |
| 160 |
|
| static |
| 161 |
|
| void |
| 162 |
1421 |
| tag_handler_var (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 163 |
|
| { |
| 164 |
|
| PSTRING varvalue; |
| 165 |
|
| int escapeopt; |
| 166 |
|
| /* |
| 167 |
|
| if (debuglevel>=TMPL_LOG_DEBUG2) { |
| 168 |
|
| log_state(state,TMPL_LOG_DEBUG2,"Entered tag_handler_var\n"); |
| 169 |
|
| }*/ |
| 170 |
1514 |
▶ | if (! state->is_visible) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (! state->is_visible) return; |
281 |
1140 |
1421 |
|
| 171 |
1140 |
| varvalue = get_variable_option(state, TagOptVal); |
| 172 |
1140 |
| escapeopt = get_escape_option(state,TagOptVal[TAG_OPT_ESCAPE]); |
| 173 |
1140 |
▶ | if (varvalue.begin==NULL) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (varvalue.begin==NULL) return; |
93 |
1047 |
1140 |
|
| 174 |
|
| |
| 175 |
1047 |
▶ | if (escapeopt!=HTML_TEMPLATE_OPT_ESCAPE_NO) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (escapeopt!=HTML_TEMPLATE_OPT_ESCAPE_NO) { |
94 |
953 |
1047 |
|
| 176 |
94 |
| varvalue=escape_pstring(&state->param->escape_pstring_buffer, varvalue, escapeopt); |
| 177 |
|
| } |
| 178 |
1047 |
| (state->param->WriterFuncPtr)(state->param->ext_writer_state,varvalue.begin,varvalue.endnext); |
| 179 |
|
| } |
| 180 |
|
| |
| 181 |
|
| static |
| 182 |
|
| void |
| 183 |
83 |
| tag_handler_include (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 184 |
|
| { |
| 185 |
|
| struct tmplpro_param* param; |
| 186 |
|
| char* filename; |
| 187 |
|
| int x; |
| 188 |
|
| PSTRING varvalue; |
| 189 |
|
| PSTRING defvalue; |
| 190 |
|
| |
| 191 |
83 |
▶ | if (! state->is_visible) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (! state->is_visible) return; |
4 |
79 |
83 |
|
| 192 |
79 |
| param=state->param; |
| 193 |
79 |
▶ | if (param->no_includes) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->no_includes) { |
0 |
79 |
79 |
|
| 194 |
0 |
| log_state(state,TMPL_LOG_ERROR, "HTML::Template::Pro : Illegal attempt to use TMPL_INCLUDE in template file : (no_includes => 1)\n"); |
| 195 |
0 |
| return; |
| 196 |
|
| } |
| 197 |
79 |
▶ | if (param->max_includes && param->max_includes < param->cur_includes) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (param->max_includes && param->max_includes < param->cur_includes) { |
79 |
0 |
79 |
| if (param->max_includes && param->max_includes < param->cur_includes) { |
2 |
77 |
79 |
|
| 198 |
2 |
| log_state(state,TMPL_LOG_INFO, "HTML::Template::Pro : TMPL_INCLUDE: max_includes exceeded.\n"); |
| 199 |
2 |
| return; |
| 200 |
|
| } |
| 201 |
77 |
| param->cur_includes++; |
| 202 |
|
| |
| 203 |
77 |
| varvalue=TagOptVal[TAG_OPT_NAME]; |
| 204 |
77 |
| defvalue = TagOptVal[TAG_OPT_DEFAULT]; |
| 205 |
|
| |
| 206 |
77 |
▶ | if (TagOptVal[TAG_OPT_EXPR].begin!=NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (TagOptVal[TAG_OPT_EXPR].begin!=NULL) { |
4 |
73 |
77 |
|
| 207 |
4 |
| varvalue=parse_expr(TagOptVal[TAG_OPT_EXPR], state); |
| 208 |
|
| }; |
| 209 |
77 |
▶ | if (varvalue.begin==varvalue.endnext && defvalue.begin!=defvalue.endnext) varvalue=defvalue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (varvalue.begin==varvalue.endnext && defvalue.begin!=defvalue.endnext) varvalue=defvalue; |
0 |
77 |
77 |
| if (varvalue.begin==varvalue.endnext && defvalue.begin!=defvalue.endnext) varvalue=defvalue; |
0 |
0 |
0 |
|
| 210 |
|
| /* pstrdup */ |
| 211 |
|
| { |
| 212 |
77 |
| const long len = varvalue.endnext-varvalue.begin; |
| 213 |
77 |
| filename =(char*) malloc(len+1); |
| 214 |
1138 |
▶ | for (x=0;x<len;x++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (x=0;x<len;x++) { |
1061 |
77 |
1138 |
|
| 215 |
1061 |
| *(filename+x)=*(varvalue.begin+x); |
| 216 |
|
| } |
| 217 |
77 |
| *(filename+len)=0; |
| 218 |
|
| } |
| 219 |
|
| /* end pstrdup */ |
| 220 |
77 |
| tmplpro_exec_tmpl_filename (param,filename); |
| 221 |
77 |
| free (filename); |
| 222 |
77 |
| param->cur_includes--; |
| 223 |
77 |
| return; |
| 224 |
|
| } |
| 225 |
|
| |
| 226 |
|
| static |
| 227 |
|
| int |
| 228 |
506 |
| is_var_true(struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 229 |
|
| { |
| 230 |
506 |
| register int ifval=-1; /*not yet defined*/ |
| 231 |
506 |
▶ | if (TagOptVal[TAG_OPT_EXPR].begin!=NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (TagOptVal[TAG_OPT_EXPR].begin!=NULL) { |
70 |
436 |
506 |
|
| 232 |
|
| /* |
| 233 |
|
| if (debuglevel>=TMPL_LOG_DEBUG2) { |
| 234 |
|
| tmpl_log(TMPL_LOG_DEBUG2,"is_var_true: expr = %.*s\n",(int)(TagOptVal[TAG_OPT_EXPR].endnext-TagOptVal[TAG_OPT_EXPR].begin),TagOptVal[TAG_OPT_EXPR].begin); |
| 235 |
|
| }*/ |
| 236 |
70 |
| ifval=is_pstring_true(parse_expr(TagOptVal[TAG_OPT_EXPR], state)); |
| 237 |
|
| } else |
| 238 |
436 |
▶ | if (state->param->loop_context_vars) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->param->loop_context_vars) { |
220 |
216 |
436 |
|
| 239 |
220 |
| PSTRING loop_var=get_loop_context_vars_value(state->param, TagOptVal[TAG_OPT_NAME]); |
| 240 |
220 |
▶ | if (loop_var.begin!=NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (loop_var.begin!=NULL) { |
20 |
200 |
220 |
|
| 241 |
20 |
| ifval=is_pstring_true(loop_var); |
| 242 |
|
| } |
| 243 |
|
| } |
| 244 |
506 |
▶ | if (ifval==-1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ifval==-1) { |
416 |
90 |
506 |
|
| 245 |
|
| is_ABSTRACT_VALUE_true_functype userSuppliedIsTrueFunc; |
| 246 |
416 |
| ABSTRACT_VALUE* abstrval=walk_through_nested_loops(state->param, TagOptVal[TAG_OPT_NAME]); |
| 247 |
416 |
▶ | if (abstrval==NULL) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (abstrval==NULL) return 0; |
112 |
304 |
416 |
|
| 248 |
304 |
| userSuppliedIsTrueFunc = state->param->IsAbstractValTrueFuncPtr; |
| 249 |
304 |
▶ | if (userSuppliedIsTrueFunc!=NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (userSuppliedIsTrueFunc!=NULL) { |
304 |
0 |
304 |
|
| 250 |
304 |
| ifval=(userSuppliedIsTrueFunc)(state->param->ext_data_state, abstrval); |
| 251 |
|
| } else { |
| 252 |
0 |
| ifval=is_pstring_true((state->param->AbstractVal2pstringFuncPtr)(state->param->ext_data_state, abstrval)); |
| 253 |
|
| } |
| 254 |
|
| } |
| 255 |
394 |
| return ifval; |
| 256 |
|
| } |
| 257 |
|
| |
| 258 |
|
| static |
| 259 |
|
| void |
| 260 |
502 |
| tag_handler_if (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 261 |
|
| { |
| 262 |
|
| struct tagstack_entry iftag; |
| 263 |
502 |
| iftag.tag=HTML_TEMPLATE_TAG_IF; |
| 264 |
502 |
| iftag.vcontext=state->is_visible; |
| 265 |
502 |
| iftag.position=state->cur_pos; /* unused */ |
| 266 |
|
| /* state->is_visible && means that we do not evaluate variable in shadow */ |
| 267 |
502 |
▶ | if (state->is_visible && is_var_true(state,TagOptVal)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state->is_visible && is_var_true(state,TagOptVal)) { |
454 |
48 |
502 |
| if (state->is_visible && is_var_true(state,TagOptVal)) { |
216 |
238 |
454 |
|
| 268 |
216 |
| iftag.value=1; |
| 269 |
|
| /* state->is_visible is not touched */ |
| 270 |
|
| } else { |
| 271 |
286 |
| iftag.value=0; |
| 272 |
286 |
| state->is_visible=0; |
| 273 |
|
| } |
| 274 |
502 |
| tagstack_push(&(state->tag_stack), iftag); |
| 275 |
502 |
▶ | if (debuglevel>=TMPL_LOG_DEBUG2) log_state(state,TMPL_LOG_DEBUG2,"tag_handler_if:visible context =%d value=%d ",iftag.vcontext,iftag.value); |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel>=TMPL_LOG_DEBUG2) log_state(state,TMPL_LOG_DEBUG2,"tag_handler_if:visible context =%d value=%d ",iftag.vcontext,iftag.value); |
0 |
502 |
502 |
|
| 276 |
502 |
| } |
| 277 |
|
| |
| 278 |
|
| static |
| 279 |
|
| void |
| 280 |
50 |
| tag_handler_unless (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 281 |
|
| { |
| 282 |
|
| struct tagstack_entry iftag; |
| 283 |
50 |
| iftag.tag=HTML_TEMPLATE_TAG_UNLESS; |
| 284 |
50 |
| iftag.vcontext=state->is_visible; |
| 285 |
50 |
| iftag.position=state->cur_pos; /* unused */ |
| 286 |
|
| /* state->is_visible && means that we do not evaluate variable in shadow */ |
| 287 |
50 |
▶ | if (state->is_visible && !is_var_true(state,TagOptVal)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state->is_visible && !is_var_true(state,TagOptVal)) { |
48 |
2 |
50 |
| if (state->is_visible && !is_var_true(state,TagOptVal)) { |
29 |
19 |
48 |
|
| 288 |
29 |
| iftag.value=1; |
| 289 |
|
| /* state->is_visible is not touched */ |
| 290 |
|
| } else { |
| 291 |
21 |
| iftag.value=0; |
| 292 |
21 |
| state->is_visible=0; |
| 293 |
|
| } |
| 294 |
50 |
| tagstack_push(&(state->tag_stack), iftag); |
| 295 |
50 |
▶ | if (debuglevel>=TMPL_LOG_DEBUG2) log_state(state,TMPL_LOG_DEBUG2,"tag_handler_unless:visible context =%d value=%d ",iftag.vcontext,iftag.value); |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel>=TMPL_LOG_DEBUG2) log_state(state,TMPL_LOG_DEBUG2,"tag_handler_unless:visible context =%d value=%d ",iftag.vcontext,iftag.value); |
0 |
50 |
50 |
|
| 296 |
50 |
| } |
| 297 |
|
| |
| 298 |
|
| static |
| 299 |
|
| INLINE |
| 300 |
|
| int |
| 301 |
1212 |
| test_stack (int tag) |
| 302 |
|
| { |
| 303 |
|
| // return (tagstack_notempty(&(state->tag_stack)) && (tagstack_top(&(state->tag_stack))->tag==tag)); |
| 304 |
1212 |
| return 1; |
| 305 |
|
| } |
| 306 |
|
| |
| 307 |
|
| static |
| 308 |
|
| void |
| 309 |
0 |
| tag_stack_debug (struct tmplpro_state *state, int stack_tag_type) |
| 310 |
|
| { |
| 311 |
0 |
▶ | if (stack_tag_type) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (stack_tag_type) { |
0 |
0 |
0 |
|
| 312 |
0 |
▶ | if (tagstack_notempty(&(state->tag_stack))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tagstack_notempty(&(state->tag_stack))) { |
0 |
0 |
0 |
|
| 313 |
0 |
| struct tagstack_entry* iftag=tagstack_top(&(state->tag_stack)); |
| 314 |
0 |
▶ | if (iftag->tag!=stack_tag_type) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (iftag->tag!=stack_tag_type) { |
0 |
0 |
0 |
|
| 315 |
0 |
| log_state(state,TMPL_LOG_ERROR, "ERROR: tag mismatch with %s\n",TAGNAME[iftag->tag]); |
| 316 |
|
| } |
| 317 |
|
| } else { |
| 318 |
0 |
| log_state(state,TMPL_LOG_ERROR, "ERROR: opening tag %s not found\n",TAGNAME[stack_tag_type]); |
| 319 |
|
| } |
| 320 |
|
| } |
| 321 |
0 |
| } |
| 322 |
|
| |
| 323 |
|
| static |
| 324 |
678 |
| struct tagstack_entry tagstack_smart_pop(struct tmplpro_state *state) |
| 325 |
|
| { |
| 326 |
678 |
| int is_underflow=0; |
| 327 |
678 |
| struct tagstack_entry curtag=tagstack_pop(&(state->tag_stack), &is_underflow); |
| 328 |
678 |
▶ | if (is_underflow) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_underflow) { |
1 |
677 |
678 |
|
| 329 |
1 |
| log_state(state,TMPL_LOG_ERROR,"stack underflow:tag stack is empty. Cased by closing tag w/o matching opening tag.\n"); |
| 330 |
|
| } |
| 331 |
678 |
| return curtag; |
| 332 |
|
| } |
| 333 |
|
| |
| 334 |
|
| static |
| 335 |
|
| void |
| 336 |
506 |
| tag_handler_closeif (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 337 |
|
| { |
| 338 |
|
| struct tagstack_entry iftag; |
| 339 |
506 |
▶ | if (! test_stack(HTML_TEMPLATE_TAG_IF)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (! test_stack(HTML_TEMPLATE_TAG_IF)) { |
0 |
506 |
506 |
|
| 340 |
0 |
| tag_stack_debug(state,HTML_TEMPLATE_TAG_IF); |
| 341 |
0 |
| return; |
| 342 |
|
| } |
| 343 |
506 |
| iftag=tagstack_smart_pop(state); |
| 344 |
506 |
▶ | if (0==state->is_visible) state->last_processed_pos=state->cur_pos; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0==state->is_visible) state->last_processed_pos=state->cur_pos; |
248 |
258 |
506 |
|
| 345 |
506 |
| state->is_visible=iftag.vcontext; |
| 346 |
|
| } |
| 347 |
|
| |
| 348 |
|
| static |
| 349 |
|
| void |
| 350 |
46 |
| tag_handler_closeunless (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 351 |
|
| { |
| 352 |
|
| struct tagstack_entry iftag; |
| 353 |
46 |
▶ | if (! test_stack(HTML_TEMPLATE_TAG_UNLESS)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (! test_stack(HTML_TEMPLATE_TAG_UNLESS)) { |
0 |
46 |
46 |
|
| 354 |
0 |
| tag_stack_debug(state,HTML_TEMPLATE_TAG_UNLESS); |
| 355 |
0 |
| return; |
| 356 |
|
| } |
| 357 |
46 |
| iftag=tagstack_smart_pop(state); |
| 358 |
46 |
▶ | if (0==state->is_visible) state->last_processed_pos=state->cur_pos; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0==state->is_visible) state->last_processed_pos=state->cur_pos; |
22 |
24 |
46 |
|
| 359 |
46 |
| state->is_visible=iftag.vcontext; |
| 360 |
|
| } |
| 361 |
|
| |
| 362 |
|
| static |
| 363 |
|
| void |
| 364 |
406 |
| tag_handler_else (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 365 |
|
| { |
| 366 |
|
| struct tagstack_entry* iftag; |
| 367 |
406 |
| if (! test_stack(HTML_TEMPLATE_TAG_IF) && |
| 368 |
0 |
| ! test_stack(HTML_TEMPLATE_TAG_UNLESS)) { |
| 369 |
0 |
| tag_stack_debug(state,HTML_TEMPLATE_TAG_ELSE); |
| 370 |
0 |
| return; |
| 371 |
|
| } |
| 372 |
406 |
| iftag=tagstack_top(&(state->tag_stack)); |
| 373 |
406 |
▶ | if (0==state->is_visible) state->last_processed_pos=state->cur_pos; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0==state->is_visible) state->last_processed_pos=state->cur_pos; |
236 |
170 |
406 |
|
| 374 |
406 |
▶ | if (iftag->value) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (iftag->value) { |
174 |
232 |
406 |
|
| 375 |
174 |
| state->is_visible=0; |
| 376 |
232 |
▶ | } else if (1==iftag->vcontext) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (1==iftag->vcontext) { |
206 |
26 |
232 |
|
| 377 |
206 |
| state->is_visible=1; |
| 378 |
|
| } |
| 379 |
406 |
▶ | if (debuglevel>=TMPL_LOG_DEBUG2) log_state(state,TMPL_LOG_DEBUG2,"else:(pos " MOD_TD ") visible:context =%d, set to %d ", |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel>=TMPL_LOG_DEBUG2) log_state(state,TMPL_LOG_DEBUG2,"else:(pos " MOD_TD ") visible:context =%d, set to %d ", |
0 |
406 |
406 |
|
| 380 |
0 |
| TO_PTRDIFF_T(iftag->position - state->top),iftag->vcontext,state->is_visible); |
| 381 |
|
| } |
| 382 |
|
| |
| 383 |
|
| static |
| 384 |
|
| void |
| 385 |
8 |
| tag_handler_elsif (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 386 |
|
| { |
| 387 |
|
| struct tagstack_entry *iftag; |
| 388 |
8 |
| if (! test_stack(HTML_TEMPLATE_TAG_IF) && |
| 389 |
0 |
| ! test_stack(HTML_TEMPLATE_TAG_UNLESS)) { |
| 390 |
0 |
| tag_stack_debug(state,HTML_TEMPLATE_TAG_ELSIF); |
| 391 |
0 |
| return; |
| 392 |
|
| } |
| 393 |
8 |
| iftag=tagstack_top(&(state->tag_stack)); |
| 394 |
8 |
▶ | if (0==state->is_visible) state->last_processed_pos=state->cur_pos; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0==state->is_visible) state->last_processed_pos=state->cur_pos; |
4 |
4 |
8 |
|
| 395 |
8 |
▶ | if (iftag->value) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (iftag->value) { |
4 |
4 |
8 |
|
| 396 |
4 |
| state->is_visible=0; |
| 397 |
4 |
▶ | } else if (1==iftag->vcontext) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (1==iftag->vcontext) { |
4 |
0 |
4 |
|
| 398 |
|
| /* test only if vcontext==true; if the whole tag if..endif itself is invisible, skip the is_var_true test */ |
| 399 |
|
| /*TODO: it is reasonable to skip is_var_true test in if/unless too */ |
| 400 |
4 |
▶ | if (is_var_true(state,TagOptVal)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_var_true(state,TagOptVal)) { |
4 |
0 |
4 |
|
| 401 |
4 |
| iftag->value=1; |
| 402 |
4 |
| state->is_visible=1; |
| 403 |
|
| } else { |
| 404 |
0 |
| iftag->value=0; |
| 405 |
0 |
| state->is_visible=0; |
| 406 |
|
| } |
| 407 |
|
| } |
| 408 |
8 |
▶ | if (debuglevel>=TMPL_LOG_DEBUG2) log_state(state,TMPL_LOG_DEBUG2,"elsif:(pos " MOD_TD ") visible:context =%d, set to %d ", |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel>=TMPL_LOG_DEBUG2) log_state(state,TMPL_LOG_DEBUG2,"elsif:(pos " MOD_TD ") visible:context =%d, set to %d ", |
0 |
8 |
8 |
|
| 409 |
0 |
| TO_PTRDIFF_T(iftag->position - state->top), iftag->vcontext, state->is_visible); |
| 410 |
|
| } |
| 411 |
|
| |
| 412 |
|
| static |
| 413 |
|
| int |
| 414 |
254 |
| next_loop (struct tmplpro_state* state) { |
| 415 |
|
| #ifdef DEBUG |
| 416 |
|
| log_state(state,TMPL_LOG_DEBUG2,"next_loop:before NextLoopFuncPtr\n"); |
| 417 |
|
| #endif |
| 418 |
254 |
| struct ProScopeEntry* currentScope = getCurrentScope(&state->param->var_scope_stack); |
| 419 |
254 |
▶ | if (!isScopeLoop(currentScope)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!isScopeLoop(currentScope)) { |
0 |
254 |
254 |
|
| 420 |
0 |
| log_state(state,TMPL_LOG_ERROR, "next_loop:at scope level %d: internal error - loop is null\n", curScopeLevel(&state->param->var_scope_stack)); |
| 421 |
0 |
| return 0; |
| 422 |
|
| } |
| 423 |
254 |
▶ | if (++currentScope->loop < currentScope->loop_count || currentScope->loop_count< 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (++currentScope->loop < currentScope->loop_count || currentScope->loop_count< 0) { |
67 |
187 |
254 |
| if (++currentScope->loop < currentScope->loop_count || currentScope->loop_count< 0) { |
0 |
67 |
67 |
|
| 424 |
187 |
| ABSTRACT_MAP* arrayvalptr=(state->param->GetAbstractMapFuncPtr)(state->param->ext_data_state, currentScope->loops_AV,currentScope->loop); |
| 425 |
187 |
▶ | if ((arrayvalptr!=NULL)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((arrayvalptr!=NULL)) { |
187 |
0 |
187 |
|
| 426 |
187 |
| currentScope->param_HV=arrayvalptr; |
| 427 |
187 |
| return 1; |
| 428 |
|
| } else { |
| 429 |
|
| /* either undefined loop ended normally or defined loop ended ubnormally */ |
| 430 |
0 |
▶ | if (currentScope->loop_count>0) log_state(state,TMPL_LOG_ERROR, "PARAM:LOOP:next_loop(%d): callback returned null scope\n", currentScope->loop); |
Branch: 1 branch
| Branch | True | False | Total |
| if (currentScope->loop_count>0) log_state(state,TMPL_LOG_ERROR, "PARAM:LOOP:next_loop(%d): callback returned null scope\n", currentScope->loop); |
0 |
0 |
0 |
|
| 431 |
|
| } |
| 432 |
|
| } |
| 433 |
67 |
▶ | if (state->param->ExitLoopScopeFuncPtr) state->param->ExitLoopScopeFuncPtr(state->param->ext_data_state, currentScope->loops_AV); |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->param->ExitLoopScopeFuncPtr) state->param->ExitLoopScopeFuncPtr(state->param->ext_data_state, currentScope->loops_AV); |
0 |
67 |
67 |
|
| 434 |
67 |
| popScope(&state->param->var_scope_stack); |
| 435 |
67 |
| return 0; |
| 436 |
|
| } |
| 437 |
|
| |
| 438 |
|
| static |
| 439 |
121 |
| int init_loop (struct tmplpro_state *state, const PSTRING* const TagOptVal) { |
| 440 |
|
| int loop_count; |
| 441 |
121 |
| ABSTRACT_ARRAY* loopptr=(ABSTRACT_ARRAY*) walk_through_nested_loops(state->param,TagOptVal[TAG_OPT_NAME]); |
| 442 |
121 |
▶ | if (loopptr==NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (loopptr==NULL) { |
46 |
75 |
121 |
|
| 443 |
46 |
| return 0; |
| 444 |
|
| } else { |
| 445 |
|
| /* set loop array */ |
| 446 |
75 |
| loopptr = (*state->param->AbstractVal2abstractArrayFuncPtr)(state->param->ext_data_state, loopptr); |
| 447 |
75 |
▶ | if (loopptr == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (loopptr == NULL) |
0 |
75 |
75 |
|
| 448 |
|
| { |
| 449 |
0 |
| log_state(state,TMPL_LOG_ERROR, "PARAM:LOOP:loop argument:loop was expected but not found.\n"); |
| 450 |
0 |
| return 0; |
| 451 |
|
| } |
| 452 |
75 |
| loop_count = (*state->param->GetAbstractArrayLengthFuncPtr)(state->param->ext_data_state, loopptr); |
| 453 |
|
| /* 0 is an empty array; <0 is an undefined array (iterated until next_loop==NULL */ |
| 454 |
75 |
▶ | if (0==loop_count) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0==loop_count) return 0; |
8 |
67 |
75 |
|
| 455 |
67 |
| pushScopeLoop(&state->param->var_scope_stack, loop_count, loopptr); |
| 456 |
67 |
| return 1; |
| 457 |
|
| } |
| 458 |
|
| } |
| 459 |
|
| |
| 460 |
|
| static |
| 461 |
|
| void |
| 462 |
126 |
| tag_handler_loop (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 463 |
|
| { |
| 464 |
|
| struct tagstack_entry iftag; |
| 465 |
126 |
| iftag.tag=HTML_TEMPLATE_TAG_LOOP; |
| 466 |
126 |
| iftag.vcontext=state->is_visible; |
| 467 |
126 |
| iftag.value=0; |
| 468 |
126 |
| iftag.position=state->cur_pos; /* loop start - to restore in </tmpl_loop> */ |
| 469 |
|
| #ifdef DEBUG |
| 470 |
|
| log_state(state,TMPL_LOG_DEBUG2,"tag_handler_loop:before InitLoopFuncPtr\n"); |
| 471 |
|
| #endif |
| 472 |
126 |
▶ | if (state->is_visible && init_loop(state,TagOptVal) && next_loop(state)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (state->is_visible && init_loop(state,TagOptVal) && next_loop(state)) { |
121 |
5 |
126 |
| if (state->is_visible && init_loop(state,TagOptVal) && next_loop(state)) { |
67 |
54 |
121 |
| if (state->is_visible && init_loop(state,TagOptVal) && next_loop(state)) { |
67 |
0 |
67 |
|
| 473 |
67 |
| iftag.value=1; /* the loop is non - empty */ |
| 474 |
|
| } else { |
| 475 |
|
| /* empty loop is equal to <if false> ... </if> */ |
| 476 |
59 |
| state->is_visible=0; |
| 477 |
|
| } |
| 478 |
|
| #ifdef DEBUG |
| 479 |
|
| log_state(state,TMPL_LOG_DEBUG2,"tag_handler_loop:after InitLoopFuncPtr\n"); |
| 480 |
|
| #endif |
| 481 |
126 |
| tagstack_push(&(state->tag_stack), iftag); |
| 482 |
126 |
| } |
| 483 |
|
| |
| 484 |
|
| static |
| 485 |
|
| void |
| 486 |
246 |
| tag_handler_closeloop (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 487 |
|
| { |
| 488 |
|
| struct tagstack_entry* iftag_ptr; |
| 489 |
246 |
▶ | if (! test_stack(HTML_TEMPLATE_TAG_LOOP)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (! test_stack(HTML_TEMPLATE_TAG_LOOP)) { |
0 |
246 |
246 |
|
| 490 |
0 |
| tag_stack_debug(state,HTML_TEMPLATE_TAG_LOOP); |
| 491 |
0 |
| return; |
| 492 |
|
| } |
| 493 |
246 |
| iftag_ptr=tagstack_top(&(state->tag_stack)); |
| 494 |
246 |
▶ | if (iftag_ptr->value==1 && next_loop(state)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (iftag_ptr->value==1 && next_loop(state)) { |
187 |
59 |
246 |
| if (iftag_ptr->value==1 && next_loop(state)) { |
120 |
67 |
187 |
|
| 495 |
|
| /* continue loop */ |
| 496 |
120 |
| state->cur_pos=iftag_ptr->position; |
| 497 |
120 |
| state->last_processed_pos=iftag_ptr->position; |
| 498 |
120 |
| return; |
| 499 |
|
| } else { |
| 500 |
|
| /* finish loop */ |
| 501 |
|
| struct tagstack_entry iftag; |
| 502 |
126 |
| iftag=tagstack_smart_pop(state); |
| 503 |
126 |
| state->is_visible=iftag.vcontext; |
| 504 |
126 |
| state->last_processed_pos=state->cur_pos; |
| 505 |
|
| } |
| 506 |
|
| } |
| 507 |
|
| |
| 508 |
|
| static |
| 509 |
|
| void |
| 510 |
0 |
| tag_handler_unknown (struct tmplpro_state *state, const PSTRING* const TagOptVal) |
| 511 |
|
| { |
| 512 |
0 |
| log_state(state,TMPL_LOG_ERROR,"tag_handler_unknown: unknown tag\n"); |
| 513 |
0 |
| } |
| 514 |
|
| |
| 515 |
|
| /* |
| 516 |
|
| * Local Variables: |
| 517 |
|
| * mode: c |
| 518 |
|
| * End: |
| 519 |
|
| */ |