line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
static |
2
|
|
|
|
|
|
|
const char* const innerloopname[]={ |
3
|
|
|
|
|
|
|
"", "first__", "last__", "inner__", "odd__", "counter__" |
4
|
|
|
|
|
|
|
}; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
static |
7
|
|
|
|
|
|
|
const char* const INNERLOOPNAME[]={ |
8
|
|
|
|
|
|
|
"", "FIRST__", "LAST__", "INNER__", "ODD__", "COUNTER__" |
9
|
|
|
|
|
|
|
}; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#define HTML_TEMPLATE_INNER_LOOP_VAR_FIRST 1 |
12
|
|
|
|
|
|
|
#define HTML_TEMPLATE_INNER_LOOP_VAR_LAST 2 |
13
|
|
|
|
|
|
|
#define HTML_TEMPLATE_INNER_LOOP_VAR_INNER 3 |
14
|
|
|
|
|
|
|
#define HTML_TEMPLATE_INNER_LOOP_VAR_ODD 4 |
15
|
|
|
|
|
|
|
#define HTML_TEMPLATE_INNER_LOOP_VAR_COUNTER 5 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#define HTML_TEMPLATE_FIRST_INNER_LOOP 1 |
18
|
|
|
|
|
|
|
#define HTML_TEMPLATE_LAST_INNER_LOOP 5 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
static |
22
|
|
|
|
|
|
|
int |
23
|
191
|
|
|
|
|
|
try_inner_loop_variable (PSTRING name) |
24
|
|
|
|
|
|
|
{ |
25
|
|
|
|
|
|
|
int i; |
26
|
|
|
|
|
|
|
const char* cur_pos; |
27
|
|
|
|
|
|
|
const char* pattern; |
28
|
|
|
|
|
|
|
const char* PATTERN; |
29
|
589
|
50
|
|
|
|
|
for (i=HTML_TEMPLATE_FIRST_INNER_LOOP; i<=HTML_TEMPLATE_LAST_INNER_LOOP; i++) { |
30
|
589
|
|
|
|
|
|
cur_pos=name.begin; |
31
|
589
|
|
|
|
|
|
pattern=innerloopname[i]; |
32
|
589
|
|
|
|
|
|
PATTERN=INNERLOOPNAME[i]; |
33
|
1891
|
100
|
|
|
|
|
while (*pattern && cur_pos
|
|
|
50
|
|
|
|
|
|
34
|
1700
|
100
|
|
|
|
|
if (*pattern == *cur_pos || *PATTERN == *cur_pos) { |
|
|
100
|
|
|
|
|
|
35
|
1302
|
|
|
|
|
|
pattern++; |
36
|
1302
|
|
|
|
|
|
PATTERN++; |
37
|
1302
|
|
|
|
|
|
cur_pos++; |
38
|
|
|
|
|
|
|
} else { |
39
|
|
|
|
|
|
|
break; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
589
|
100
|
|
|
|
|
if (cur_pos==name.endnext) { |
43
|
191
|
|
|
|
|
|
return i; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
return 0; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
static |
50
|
|
|
|
|
|
|
PSTRING |
51
|
988
|
|
|
|
|
|
get_loop_context_vars_value (struct tmplpro_param *param, PSTRING name) { |
52
|
|
|
|
|
|
|
static const char* const FalseString="0"; |
53
|
|
|
|
|
|
|
static const char* const TrueString ="1"; |
54
|
|
|
|
|
|
|
int loop; |
55
|
988
|
|
|
|
|
|
PSTRING retval={NULL,NULL}; |
56
|
988
|
|
|
|
|
|
const struct ProScopeEntry* const currentScope = getCurrentScope(¶m->var_scope_stack); |
57
|
988
|
100
|
|
|
|
|
if (isScopeLoop(currentScope) |
58
|
380
|
100
|
|
|
|
|
&& name.endnext-name.begin>4 |
59
|
319
|
100
|
|
|
|
|
&& '_'==*(name.begin) |
60
|
191
|
50
|
|
|
|
|
&& '_'==*(name.begin+1) |
61
|
|
|
|
|
|
|
) { |
62
|
|
|
|
|
|
|
/* we can meet loop variables here -- try it first */ |
63
|
|
|
|
|
|
|
/* length of its name >4 */ |
64
|
|
|
|
|
|
|
/* __first__ __last__ __inner__ __odd__ __counter__ */ |
65
|
|
|
|
|
|
|
PSTRING shiftedname; /* (PSTRING) {name.begin+2,name.endnext} */ |
66
|
191
|
|
|
|
|
|
shiftedname.begin=name.begin+2; |
67
|
191
|
|
|
|
|
|
shiftedname.endnext=name.endnext; |
68
|
191
|
|
|
|
|
|
switch (try_inner_loop_variable(shiftedname)) { |
69
|
0
|
|
|
|
|
|
case 0: break; |
70
|
|
|
|
|
|
|
case HTML_TEMPLATE_INNER_LOOP_VAR_FIRST: |
71
|
33
|
100
|
|
|
|
|
if (currentScope->loop==0) { /* first__ */ |
72
|
9
|
|
|
|
|
|
retval.begin=TrueString; retval.endnext=TrueString+1; |
73
|
|
|
|
|
|
|
} else { |
74
|
24
|
|
|
|
|
|
retval.begin=FalseString; retval.endnext=FalseString+1; |
75
|
33
|
|
|
|
|
|
}; break; |
76
|
|
|
|
|
|
|
case HTML_TEMPLATE_INNER_LOOP_VAR_LAST: |
77
|
43
|
100
|
|
|
|
|
if (currentScope->loop==(currentScope->loop_count-1)) { |
78
|
11
|
|
|
|
|
|
retval.begin=TrueString; retval.endnext=TrueString+1; |
79
|
|
|
|
|
|
|
} else { |
80
|
32
|
|
|
|
|
|
retval.begin=FalseString; retval.endnext=FalseString+1; |
81
|
43
|
|
|
|
|
|
}; break; |
82
|
|
|
|
|
|
|
case HTML_TEMPLATE_INNER_LOOP_VAR_ODD: |
83
|
39
|
100
|
|
|
|
|
if ((currentScope->loop%2)==0) { |
84
|
20
|
|
|
|
|
|
retval.begin=TrueString; retval.endnext=TrueString+1; |
85
|
|
|
|
|
|
|
} else { |
86
|
19
|
|
|
|
|
|
retval.begin=FalseString; retval.endnext=FalseString+1; |
87
|
39
|
|
|
|
|
|
}; break; |
88
|
|
|
|
|
|
|
case HTML_TEMPLATE_INNER_LOOP_VAR_INNER: |
89
|
33
|
100
|
|
|
|
|
if (currentScope->loop>0 && |
|
|
50
|
|
|
|
|
|
90
|
24
|
|
|
|
|
|
(currentScope->loop_count<0 /* loop_count < 0 if number of loops is unknown/undefined */ |
91
|
24
|
100
|
|
|
|
|
|| currentScope->loop < (currentScope->loop_count-1))) { |
92
|
16
|
|
|
|
|
|
retval.begin=TrueString; retval.endnext=TrueString+1; |
93
|
|
|
|
|
|
|
} else { |
94
|
17
|
|
|
|
|
|
retval.begin=FalseString; retval.endnext=FalseString+1; |
95
|
33
|
|
|
|
|
|
}; break; |
96
|
|
|
|
|
|
|
case HTML_TEMPLATE_INNER_LOOP_VAR_COUNTER: |
97
|
|
|
|
|
|
|
{ |
98
|
43
|
|
|
|
|
|
char* const buffer = param->loopvarbuf; |
99
|
43
|
|
|
|
|
|
loop=currentScope->loop+1; |
100
|
43
|
|
|
|
|
|
snprintf(buffer,sizeof(param->loopvarbuf),"%d",loop); |
101
|
43
|
|
|
|
|
|
retval.begin=buffer; retval.endnext=buffer+strlen(buffer); |
102
|
|
|
|
|
|
|
} |
103
|
191
|
|
|
|
|
|
break; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
988
|
|
|
|
|
|
return retval; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
/* |
110
|
|
|
|
|
|
|
* Local Variables: |
111
|
|
|
|
|
|
|
* mode: c |
112
|
|
|
|
|
|
|
* End: |
113
|
|
|
|
|
|
|
*/ |