updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -353,6 +353,57 @@ filters.o: ../../winix/core/sessioncontainer.h
|
||||
filters.o: ../../winix/core/ipbancontainer.h ../../winix/core/system.h
|
||||
filters.o: ../../winix/core/htmlfilter.h ../../winix/core/misc.h
|
||||
filters.o: ../../winix/core/winix_const.h
|
||||
generic.o: templates.h ../../ezc/src/ezc.h ../../ezc/src/generator.h
|
||||
generic.o: ../../ezc/src/blocks.h ../../ezc/src/item.h
|
||||
generic.o: ../../ezc/src/funinfo.h ../../ezc/src/functions.h
|
||||
generic.o: ../../pikotools/utf8/utf8.h ../../ezc/src/cache.h
|
||||
generic.o: ../../ezc/src/pattern.h ../../ezc/src/patternparser.h misc.h
|
||||
generic.o: localefilter.h locale.h ../../pikotools/space/spaceparser.h
|
||||
generic.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
|
||||
generic.o: ../../pikotools/textstream/textstream.h
|
||||
generic.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
|
||||
generic.o: ../../pikotools/convert/convert.h
|
||||
generic.o: ../../pikotools/convert/inttostr.h
|
||||
generic.o: ../../pikotools/membuffer/membuffer.h
|
||||
generic.o: ../../pikotools/textstream/types.h htmltextstream.h
|
||||
generic.o: ../../winix/core/textstream.h patterncacher.h
|
||||
generic.o: ../../winix/core/item.h indexpatterns.h patterns.h
|
||||
generic.o: changepatterns.h ../../winix/core/config.h
|
||||
generic.o: ../../winix/core/htmlfilter.h ../../winix/core/cur.h
|
||||
generic.o: ../../winix/core/request.h ../../winix/core/requesttypes.h
|
||||
generic.o: ../../winix/core/error.h ../../winix/core/config.h
|
||||
generic.o: ../../winix/core/textstream.h
|
||||
generic.o: ../../winix/templates/htmltextstream.h
|
||||
generic.o: ../../pikotools/space/spacetojson.h ../../winix/core/session.h
|
||||
generic.o: ../../winix/core/user.h ../../winix/core/plugindata.h
|
||||
generic.o: ../../winix/core/rebus.h ../../winix/core/ipban.h
|
||||
generic.o: ../../winix/core/mount.h ../../winix/core/system.h
|
||||
generic.o: ../../winix/core/job.h ../../winix/core/basethread.h
|
||||
generic.o: ../../winix/core/synchro.h ../../winix/core/dirs.h
|
||||
generic.o: ../../winix/core/dircontainer.h ../../winix/db/db.h
|
||||
generic.o: ../../winix/db/dbbase.h ../../winix/db/dbconn.h
|
||||
generic.o: ../../winix/db/dbtextstream.h ../../winix/core/error.h
|
||||
generic.o: ../../winix/db/dbitemquery.h ../../winix/db/dbitemcolumns.h
|
||||
generic.o: ../../winix/core/user.h ../../winix/core/group.h
|
||||
generic.o: ../../winix/core/dircontainer.h ../../winix/core/ugcontainer.h
|
||||
generic.o: ../../winix/core/log.h ../../winix/core/logmanipulators.h
|
||||
generic.o: ../../winix/core/slog.h ../../winix/core/cur.h
|
||||
generic.o: ../../winix/templates/locale.h ../../winix/notify/notify.h
|
||||
generic.o: ../../winix/notify/notifypool.h ../../winix/templates/patterns.h
|
||||
generic.o: ../../winix/notify/notifythread.h ../../winix/core/basethread.h
|
||||
generic.o: ../../winix/notify/templatesnotify.h ../../winix/core/users.h
|
||||
generic.o: ../../winix/core/ugcontainer.h ../../winix/core/lastcontainer.h
|
||||
generic.o: ../../winix/core/mounts.h ../../winix/core/mountparser.h
|
||||
generic.o: ../../winix/core/crypt.h ../../winix/core/run.h
|
||||
generic.o: ../../winix/core/users.h ../../winix/core/groups.h
|
||||
generic.o: ../../winix/core/group.h ../../winix/core/loadavg.h
|
||||
generic.o: ../../winix/core/image.h ../../winix/core/threadmanager.h
|
||||
generic.o: ../../winix/core/timezones.h ../../winix/core/timezone.h
|
||||
generic.o: ../../winix/core/sessionmanager.h
|
||||
generic.o: ../../winix/core/sessioncontainer.h
|
||||
generic.o: ../../winix/core/ipbancontainer.h ../../winix/core/system.h
|
||||
generic.o: ../../winix/core/htmlfilter.h ../../winix/core/request.h
|
||||
generic.o: ../../winix/core/misc.h ../../winix/core/winix_const.h
|
||||
htmltextstream.o: htmltextstream.h ../../winix/core/textstream.h misc.h
|
||||
htmltextstream.o: localefilter.h locale.h ../../pikotools/space/spaceparser.h
|
||||
htmltextstream.o: ../../pikotools/space/space.h
|
||||
|
||||
@@ -1 +1 @@
|
||||
o = adduser.o changepatterns.o config.o dir.o doc.o env.o filters.o htmltextstream.o indexpatterns.o insert.o ipban.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o passwd.o patterncacher.o patterns.o priv.o rebus.o slog.o stat.o sys.o template.o templates.o textextstream.o upload.o uptime.o user.o who.o winix.o
|
||||
o = adduser.o changepatterns.o config.o dir.o doc.o env.o filters.o generic.o htmltextstream.o indexpatterns.o insert.o ipban.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o passwd.o patterncacher.o patterns.o priv.o rebus.o slog.o stat.o sys.o template.o templates.o textextstream.o upload.o uptime.o user.o who.o winix.o
|
||||
|
||||
237
templates/generic.cpp
Normal file
237
templates/generic.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void ezc_false(Info & i)
|
||||
{
|
||||
i.res = false;
|
||||
}
|
||||
|
||||
|
||||
void ezc_true(Info & i)
|
||||
{
|
||||
i.res = true;
|
||||
}
|
||||
|
||||
|
||||
void ezc_and(Info & i)
|
||||
{
|
||||
if( !i.params.empty() )
|
||||
{
|
||||
i.res = true;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
if( !i.params[a].res )
|
||||
{
|
||||
i.res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ezc_any(Info & i)
|
||||
{
|
||||
ezc_and(i);
|
||||
}
|
||||
|
||||
|
||||
void ezc_or(Info & i)
|
||||
{
|
||||
i.res = false;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
if( i.params[a].res )
|
||||
{
|
||||
i.res = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ezc_one(Info & i)
|
||||
{
|
||||
ezc_or(i);
|
||||
}
|
||||
|
||||
|
||||
void ezc_not(Info & i)
|
||||
{
|
||||
if( !i.params.empty() )
|
||||
i.res = !i.params[0].res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* compare strings
|
||||
*/
|
||||
void cmp(Info & i)
|
||||
{
|
||||
if( i.params.size() >= 2 )
|
||||
{
|
||||
i.res = true;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() - 1 ; ++a)
|
||||
{
|
||||
if( i.params[a].str != i.params[a+1].str )
|
||||
{
|
||||
i.res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// IMPROVE ME !! may we need such a filter too?
|
||||
void trim(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
// trimming with new lines too
|
||||
TrimWhite(i.params[a].str, true);
|
||||
i.out << R(i.params[a].str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void to_lower(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
for(size_t z=0 ; z < i.params[a].str.size() ; ++z)
|
||||
i.out << R(locale.ToSmall(i.params[a].str[z]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void to_upper(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
for(size_t z=0 ; z < i.params[a].str.size() ; ++z)
|
||||
i.out << R(locale.ToCapital(i.params[a].str[z]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool index_find_last_for_statement(Info & i, size_t & last_for_index)
|
||||
{
|
||||
last_for_index = i.stack_index;
|
||||
|
||||
do
|
||||
{
|
||||
if( i.stack_tab[last_for_index].is_for )
|
||||
return true;
|
||||
}
|
||||
while( last_for_index-- > 0 );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void index(Info & i)
|
||||
{
|
||||
size_t for_index;
|
||||
|
||||
if( !index_find_last_for_statement(i, for_index) )
|
||||
return;
|
||||
|
||||
if( i.params.size() != 1 )
|
||||
{
|
||||
i.out << i.stack_tab[for_index].iter;
|
||||
return;
|
||||
}
|
||||
|
||||
if( i.par == L"odd" )
|
||||
{
|
||||
i.res = (i.stack_tab[for_index].iter & 1) == 1;
|
||||
}
|
||||
else
|
||||
if( i.par == L"even" )
|
||||
{
|
||||
i.res = (i.stack_tab[for_index].iter & 1) == 0;
|
||||
}
|
||||
else
|
||||
if( i.par == L"first" )
|
||||
{
|
||||
i.res = i.stack_tab[for_index].iter == 0;
|
||||
}
|
||||
else
|
||||
if( IsSize(i.par, true) )
|
||||
{
|
||||
|
||||
size_t number = static_cast<size_t>(Tol(SkipWhite(i.par.c_str(), true)));
|
||||
i.res = (i.stack_tab[for_index].iter == number);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void str(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
i.out << R(i.params[a].str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
@@ -307,6 +307,24 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("fil_html_newline", fil_html_newline);
|
||||
|
||||
|
||||
/*
|
||||
generic functions
|
||||
*/
|
||||
ezc_functions.Insert("false", ezc_false);
|
||||
ezc_functions.Insert("true", ezc_true);
|
||||
ezc_functions.Insert("and", ezc_and);
|
||||
ezc_functions.Insert("any", ezc_any);
|
||||
ezc_functions.Insert("or", ezc_or);
|
||||
ezc_functions.Insert("one", ezc_one);
|
||||
ezc_functions.Insert("not", ezc_not);
|
||||
ezc_functions.Insert("cmp", cmp);
|
||||
ezc_functions.Insert("trim", trim);
|
||||
ezc_functions.Insert("to_lower", to_lower);
|
||||
ezc_functions.Insert("to_upper", to_upper);
|
||||
ezc_functions.Insert("index", index);
|
||||
ezc_functions.Insert("str", str);
|
||||
|
||||
|
||||
/*
|
||||
insert
|
||||
*/
|
||||
@@ -644,8 +662,6 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("winix_req_per_sec_5", winix_req_per_sec_5);
|
||||
ezc_functions.Insert("winix_req_per_sec_15", winix_req_per_sec_15);
|
||||
ezc_functions.Insert("winix_show_content_in_full_window", winix_show_content_in_full_window);
|
||||
ezc_functions.Insert("false", winix_false);
|
||||
ezc_functions.Insert("true", winix_true);
|
||||
ezc_functions.Insert("winix_has_postvar", winix_has_postvar);
|
||||
ezc_functions.Insert("winix_postvar", winix_postvar);
|
||||
ezc_functions.Insert("winix_postvar_value_is", winix_postvar_value_is);
|
||||
@@ -654,7 +670,6 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("winix_subdomain_is_empty", winix_subdomain_is_empty);
|
||||
ezc_functions.Insert("winix_subdomain_is_not_empty", winix_subdomain_is_not_empty);
|
||||
ezc_functions.Insert("winix_subdomain_is", winix_subdomain_is);
|
||||
ezc_functions.Insert("str", str);
|
||||
ezc_functions.Insert("winix_tz_tab", winix_tz_tab);
|
||||
ezc_functions.Insert("winix_tz_tab_id", winix_tz_tab_id);
|
||||
ezc_functions.Insert("winix_tz_tab_name", winix_tz_tab_name);
|
||||
|
||||
@@ -220,6 +220,24 @@ namespace TemplatesFunctions
|
||||
void fil_html_newline(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
generic functions
|
||||
*/
|
||||
void ezc_false(Info & i);
|
||||
void ezc_true(Info & i);
|
||||
void ezc_and(Info & i);
|
||||
void ezc_any(Info & i);
|
||||
void ezc_or(Info & i);
|
||||
void ezc_one(Info & i);
|
||||
void ezc_not(Info & i);
|
||||
void cmp(Info & i);
|
||||
void trim(Info & i);
|
||||
void to_lower(Info & i);
|
||||
void to_upper(Info & i);
|
||||
void index(Info & i);
|
||||
void str(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
insert
|
||||
*/
|
||||
@@ -560,8 +578,6 @@ namespace TemplatesFunctions
|
||||
void winix_req_per_sec_5(Info & i);
|
||||
void winix_req_per_sec_15(Info & i);
|
||||
void winix_show_content_in_full_window(Info & i);
|
||||
void winix_false(Info & i);
|
||||
void winix_true(Info & i);
|
||||
void winix_has_postvar(Info & i);
|
||||
void winix_postvar(Info & i);
|
||||
void winix_postvar_value_is(Info & i);
|
||||
@@ -570,7 +586,6 @@ namespace TemplatesFunctions
|
||||
void winix_subdomain_is_empty(Info & i);
|
||||
void winix_subdomain_is_not_empty(Info & i);
|
||||
void winix_subdomain_is(Info & i);
|
||||
void str(Info & i);
|
||||
void winix_tz_tab(Info & i);
|
||||
void winix_tz_tab_id(Info & i);
|
||||
void winix_tz_tab_name(Info & i);
|
||||
|
||||
@@ -233,21 +233,6 @@ void winix_show_content_in_full_window(Info & i)
|
||||
|
||||
|
||||
|
||||
// the ezc function name is "false"
|
||||
// ezc_functions.Insert("false", winix_false);
|
||||
void winix_false(Info & i)
|
||||
{
|
||||
i.res = false;
|
||||
}
|
||||
|
||||
|
||||
// the ezc function name is "true"
|
||||
// ezc_functions.Insert("true", winix_true);
|
||||
void winix_true(Info & i)
|
||||
{
|
||||
i.res = true;
|
||||
}
|
||||
|
||||
|
||||
void winix_has_postvar(Info & i)
|
||||
{
|
||||
@@ -301,13 +286,6 @@ void winix_subdomain_is(Info & i)
|
||||
|
||||
|
||||
|
||||
// these functions are to be used with [is...] statements
|
||||
void str(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a<i.params.size() ; ++a)
|
||||
i.out << i.params[a].str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user