diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-06-15 15:58:20 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-06-15 15:58:20 +0000 |
commit | 7c68ef157d009f9932ac47ba21ba5d74e321623f (patch) | |
tree | 6c2442ca44cd090656ec3059ffb959f3d747e18d /tools/gencfg/lib | |
parent | 076746af63d317f8e96766b9137a65679f60463f (diff) | |
parent | e0d850113610f3efa0c0ac4946901f683e5e7332 (diff) | |
download | ChibiOS-7c68ef157d009f9932ac47ba21ba5d74e321623f.tar.gz ChibiOS-7c68ef157d009f9932ac47ba21ba5d74e321623f.tar.bz2 ChibiOS-7c68ef157d009f9932ac47ba21ba5d74e321623f.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5854 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'tools/gencfg/lib')
-rw-r--r-- | tools/gencfg/lib/libcode.ftl | 316 | ||||
-rw-r--r-- | tools/gencfg/lib/liblicense.ftl | 58 | ||||
-rw-r--r-- | tools/gencfg/lib/libstm32f4xx.ftl | 144 | ||||
-rw-r--r-- | tools/gencfg/lib/libutils.ftl | 109 |
4 files changed, 627 insertions, 0 deletions
diff --git a/tools/gencfg/lib/libcode.ftl b/tools/gencfg/lib/libcode.ftl new file mode 100644 index 000000000..45b94a320 --- /dev/null +++ b/tools/gencfg/lib/libcode.ftl @@ -0,0 +1,316 @@ +[#ftl]
+[#--
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ --]
+
+<#--
+ -- Coding style global settings.
+ -->
+[#assign indentation = " " /]
+[#assign fields_align = 24 /]
+[#assign define_value_align = 36 /]
+[#assign comments_align = 48 /]
+[#assign boundary = 80 /]
+
+[#--
+ -- This macro generates a brief description in DoxyGen format.
+ --]
+[#macro EmitDoxygenBrief object=[]]
+ [#if object.brief[0]??]
+[@utils.FormatStringAsText " * @brief "
+ " * "
+ utils.WithDot(object.brief[0]?cap_first)
+ boundary /]
+ [/#if]
+[/#macro]
+
+[#--
+ -- This macro generates a detailed description in DoxyGen format.
+ --]
+[#macro EmitDoxygenDetails object=[]]
+ [#if object.details[0]??]
+[@utils.FormatStringAsText " * @details "
+ " * "
+ utils.WithDot(object.details[0]?cap_first)
+ boundary /]
+ [/#if]
+[/#macro]
+
+[#--
+ -- This macro generates a notes list in DoxyGen format.
+ --]
+[#macro EmitDoxygenNotes object=[]]
+ [#list object.* as note]
+ [#if note?node_name == "note"]
+ [@utils.FormatStringAsText " * @note "
+ " * "
+ utils.WithDot(note[0]?cap_first)
+ boundary /]
+ [/#if]
+ [/#list]
+[/#macro]
+
+[#--
+ -- This macro generates a pre-requisites list in DoxyGen format.
+ --]
+[#macro EmitDoxygenPrerequisites object=[]]
+ [#list object.* as pre]
+ [#if pre?node_name == "pre"]
+ [@utils.FormatStringAsText " * @pre "
+ " * "
+ utils.WithDot(pre[0]?cap_first)
+ boundary /]
+ [/#if]
+ [/#list]
+[/#macro]
+
+[#--
+ -- This macro generates a post-requisites list in DoxyGen format.
+ --]
+[#macro EmitDoxygenPostrequisites object=[]]
+ [#list object.* as post]
+ [#if post?node_name == "post"]
+ [@utils.FormatStringAsText " * @post "
+ " * "
+ utils.WithDot(post[0]?cap_first)
+ boundary /]
+ [/#if]
+ [/#list]
+[/#macro]
+
+[#--
+ -- This macro generates a complete Doxygen documentation comment.
+ --]
+[#macro EmitDoxygenDocumentationComment object=[]]
+/**
+ [@code.EmitDoxygenBrief object /]
+ [@code.EmitDoxygenDetails object /]
+ [@code.EmitDoxygenPrerequisites object /]
+ [@code.EmitDoxygenPostrequisites object /]
+ [@code.EmitDoxygenNotes object /]
+ */
+[/#macro]
+
+[#--
+ -- This macro generates the parameters description in DoxyGen format.
+ --]
+[#macro EmitDoxygenParams params=[]]
+ [#list params as param]
+ [#local name = (param.@name[0]!"no-name")?trim /]
+ [#local brief = (param.@brief[0]!"")?trim /]
+ [#local dir = (param.@dir[0]!"boh")?trim?lower_case /]
+ [#if dir == "in"]
+[@utils.FormatStringAsText " * @param[in] "
+ " * "
+ utils.IntelligentDot(name + " " + brief?uncap_first)
+ boundary /]
+ [#elseif dir == "out"]
+[@utils.FormatStringAsText " * @param[out] "
+ " * "
+ utils.IntelligentDot(name + " " + brief?uncap_first)
+ boundary /]
+ [#elseif dir == "both"]
+[@utils.FormatStringAsText " * @param[in,out] "
+ " * "
+ utils.IntelligentDot(name + " " + brief?uncap_first)
+ boundary /]
+ [#elseif dir == "boh"]
+[@utils.FormatStringAsText " * @param "
+ " * "
+ utils.IntelligentDot(name + " " + brief?uncap_first)
+ boundary /]
+ [/#if]
+ [/#list]
+[/#macro]
+
+[#--
+ -- This macro generates a return description followed by a retval list
+ -- in DoxyGen format.
+ --]
+[#macro EmitDoxygenReturn return=[]]
+ [#if return[0]?? && ((return[0].@type[0]!"void")?trim != "void")]
+ [#local brief = (return[0].@brief[0]!"")?trim /]
+ [#if brief != ""]
+[@utils.FormatStringAsText " * @return "
+ " * "
+ utils.WithDot(brief?cap_first)
+ boundary /]
+ [/#if]
+ [#list return[0].value as value]
+ [#local label = (value.@name[0]!"no-val")?trim /]
+ [#local brief = (value.@brief[0]!"")?trim /]
+[@utils.FormatStringAsText " * @retval "
+ " * "
+ utils.WithDot(label + " " + brief?uncap_first)
+ boundary /]
+ [/#list]
+ [/#if]
+[/#macro]
+
+[#--
+ -- This macro generates the inner function code (if present).
+ --]
+[#macro EmitCode code=[]]
+ [#if function.code[0]?? && (function.code[0]?trim != "")]
+${indentation}${function.code[0]?trim}
+ [/#if]
+[/#macro]
+
+[#--
+ -- Returns true if the module exports some functions.
+ --]
+[#function HasPublicFunctions module=[]]
+ [#local flag = false /]
+ [#list module.function as function]
+ [#if (function.@visibility[0]!"private") == "public"]
+ [#local flag = true /]
+ [/#if]
+ [/#list]
+ [#return flag /]
+[/#function]
+
+[#--
+ -- Returns true if the module has static functions.
+ --]
+[#function HasPrivateFunctions module=[]]
+ [#local flag = false /]
+ [#list module.function as function]
+ [#if (function.@visibility[0]!"private") == "private"]
+ [#local flag = true /]
+ [/#if]
+ [/#list]
+ [#return flag /]
+[/#function]
+
+[#--
+ -- This macro generates a function prototype from an XML "function"
+ -- node passed as parameter.
+ -- @note Does not generate the final EOL.
+ --]
+[#macro GeneratePrototype function={}]
+ [#if function.return?? && function.return[0]??]
+ [#local rettype = (function.return[0].@type[0]!"void")?trim /]
+ [#else]
+ [#local rettype = "void" /]
+ [/#if]
+ [#local name = (function.@name[0]!"no-name")?trim /]
+ [#local visibility = (function.@visibility[0]!"private")?trim /]
+ [#if function.param?? && function.param[0]??]
+ [#-- If the function has parameters then generates the parameters list --]
+ [#local l1 = rettype + " " + name + "(" /]
+ [#if visibility == "private"]
+ [#local l1 = "static " + l1 /]
+ [/#if]
+ [#local ln = ""?right_pad(l1?length) /]
+ [#list function.param as param]
+ [#local type = (param.@type[0]!"no-type")?trim /]
+ [#if type?contains("$")]
+ [#local pstring = type?replace("$", (param.@name[0]!"no-name")?trim) /]
+ [#else]
+ [#local pstring = type + " " + (param.@name[0]!"no-name")?trim /]
+ [/#if]
+ [#local dir = (param.@dir[0]!"boh")?trim?lower_case /]
+ [#if dir == "in"]
+ [#local pstring = "const " + pstring /]
+ [/#if]
+ [#if param_index == 0]
+ [#local line = l1 + pstring /]
+ [#else]
+ [#if (line + ", " + pstring + " ")?length > boundary]
+${line + ","}
+ [#local line = ln + pstring /]
+ [#else]
+ [#local line = line + ", " + pstring /]
+ [/#if]
+ [/#if]
+ [/#list]
+${line + ")"}[#rt]
+ [#else]
+${rettype + " " + name}(void)[#rt]
+ [/#if]
+[/#macro]
+
+[#--
+ -- This macro generates a function (and its Doxygen documentation)
+ -- from an XML "function" node passed as parameter.
+ --]
+[#macro GenerateFunction function={}]
+/**
+[@EmitDoxygenBrief function.@brief /]
+[@EmitDoxygenDetails function.details /]
+[@EmitDoxygenParams function.param /]
+[@EmitDoxygenReturn function.return /]
+ *
+ * @note --Implementer notes here (or remove the tag)--
+ * @bug --Known problems please here (or remove the tag)--
+ * @todo --Implement this function (then remove the tag)--
+ */
+[@GeneratePrototype function /] {
+ [#if function.code[0]??]
+ [#-- Makes sure to undef the do_code macro --]
+ [#assign inline = "[#ftl][#macro do_code function][/#macro]"?interpret /]
+[@inline /]
+ [#-- Interprets the code within the code element --]
+ [#assign inline = function.code[0]?interpret /]
+[@inline /]
+[@do_code function /]
+ [#else]
+
+${indentation}/* ${function.@name[0]!"no-name"}() Implementation here! */
+ [/#if]
+}
+[/#macro]
+
+[#--
+ -- Generates the implementations for the private functions in the specified
+ -- module.
+ --]
+[#macro GeneratePrivateFunctionsImplementations module]
+ [#list module.function as function]
+ [#if (function.@visibility[0]!"private") == "private"]
+[@code.GenerateFunction function /]
+
+ [/#if]
+ [/#list]
+[/#macro]
+
+[#--
+ -- Generates the prototypes of the public functions in the specified
+ -- module.
+ --]
+[#macro GeneratePublicFunctionsPrototypes indentation module]
+ [#list module.function as function]
+ [#if (function.@visibility[0]!"private")?trim == "public"]
+${indentation}[@code.GeneratePrototype function /];
+ [/#if]
+ [/#list]
+[/#macro]
+
+[#--
+ -- Generates the implementations for the public functions in the specified
+ -- module.
+ --]
+[#macro GeneratePublicFunctionsImplementations module]
+ [#list module.function as function]
+ [#if (function.@visibility[0]!"private") == "public"]
+[@code.GenerateFunction function /]
+
+ [/#if]
+ [/#list]
+[/#macro]
diff --git a/tools/gencfg/lib/liblicense.ftl b/tools/gencfg/lib/liblicense.ftl new file mode 100644 index 000000000..18581ee29 --- /dev/null +++ b/tools/gencfg/lib/liblicense.ftl @@ -0,0 +1,58 @@ +[#ftl]
+[#--
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ --]
+
+[#--
+ -- Emits the ChibiOS/RT standard license exception text.
+ -- The license exception text is indented by 4 spaces.
+ --]
+[#macro EmitLicenseExceptionAsText]
+
+ ---
+
+ A special exception to the GPL can be applied should you wish to distribute
+ a combined work that includes ChibiOS/RT, without being obliged to provide
+ the source code for any proprietary components. See the file exception.txt
+ for full details of how and when the exception can be applied.
+[/#macro]
+
+[#--
+ -- Emits the ChibiOS/RT standard license text.
+ -- The license text is indented by 4 spaces.
+ --]
+[#macro EmitLicenseAsText]
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+[/#macro]
diff --git a/tools/gencfg/lib/libstm32f4xx.ftl b/tools/gencfg/lib/libstm32f4xx.ftl new file mode 100644 index 000000000..81b8f987c --- /dev/null +++ b/tools/gencfg/lib/libstm32f4xx.ftl @@ -0,0 +1,144 @@ +[#ftl]
+[#--
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ --]
+
+[#--
+ -- Emits the STM32F4xx ADC driver constant configuration structures.
+ --]
+[#macro EmitADCConfig config]
+ [#local cfg_name = config.name[0]?string /]
+ [@code.EmitDoxygenDocumentationComment config /]
+const ADCConfig ${cfg_name} = {0};
+
+ [#list config.groups.group as group]
+ [#local grpcfg_name = group.name[0]?string /]
+ [@code.EmitDoxygenDocumentationComment group /]
+const ADCGroupConfig ${grpcfg_name} = {
+ /* Circular conversion flag.*/
+ ${group.circular[0]?string?upper_case},
+ /* Number of channels sampled in the conversion group.*/
+ ${group.channels_sequence.channel?size},
+ /* End of conversion callback or NULL.*/
+ [#if group.conv_callback[0]?string?trim == ""]
+ NULL,
+ [#else]
+ ${group.conv_callback[0]?string?trim},
+ [/#if]
+ /* Error callback or NULL.*/
+ [#if group.error_callback[0]?string?trim == ""]
+ NULL,
+ [#else]
+ ${group.error_callback[0]?string?trim},
+ [/#if]
+ /* CR1 register initialization value.*/
+ [#local resolution = group.resolution[0]?word_list[0]?number /]
+ [#local cr1 = "ADC_CR1_RESOLUTION_N(" + resolution?string + ")" /]
+ [#local disc = group.discontinuous[0]?word_list[0]?number /]
+ [#if disc > 0]
+ [#local cr1 = cr1 + " | ADC_CR1_DISCEN" /]
+ [#local cr1 = cr1 + " | ADC_CR1_DISCNUM_N(" + (disc - 1)?string + ")" /]
+ [/#if]
+ ${cr1},
+ /* CR2 register initialization value.*/
+ [#local exten = group.trigger_mode[0]?word_list[0]?number /]
+ [#local cr2 = "ADC_CR1_EXTEN_N(" + exten?string + ")" /]
+ [#local extsel = group.trigger_source[0]?word_list[0]?number /]
+ [#local cr2 = cr2 + " | ADC_CR1_EXSEL_N(" + extsel?string + ")" /]
+ [#if group.alignment[0]?word_list[0]?number != 0]
+ [#local cr2 = cr2 + " | ADC_CR2_ALIGN" /]
+ [/#if]
+ ${cr2},
+ /* Channels sample time settings.*/
+ [#local smpr1 = "" /]
+ [#local smpr2 = "" /]
+ [#list group.sample_time.* as input]
+ [#local sinput = input?node_name]
+ [#if input_index < 9]
+ [#local smpr2 = smpr2 + "ADC_SMPR2_SMP_" + input?node_name +
+ "(" + input?string + ") | " /]
+ [#elseif input_index == 9]
+ [#local smpr2 = smpr2 + "ADC_SMPR2_SMP_" + input?node_name +
+ "(" + input?string + ")," /]
+ [#elseif input_index < 18]
+ [#local smpr1 = smpr1 + "ADC_SMPR1_SMP_" + input?node_name +
+ "(" + input?string + ") | " /]
+ [#else]
+ [#local smpr1 = smpr1 + "ADC_SMPR1_SMP_" + input?node_name +
+ "(" + input?string + ")," /]
+ [/#if]
+ [/#list]
+ [@utils.FormatStringAsText " " " " smpr1 80 /]
+ [@utils.FormatStringAsText " " " " smpr2 80 /]
+ /* Channels sequence.*/
+ [#local sqr1 = "ADC_SQR1_NUM_CH(" + group.channels_sequence?size + ")" /]
+ [#local sqr2 = "" /]
+ [#local sqr3 = "" /]
+ [#list group.channels_sequence.channel as channel]
+ [#if channel_index <= 5]
+ [#local sqr3 = sqr3 + "ADC_SQR3_SQ" + (channel_index + 1) +
+ "_N(" + channel + ")" /]
+ [#if channel_has_next && channel_index < 5]
+ [#local sqr3 = sqr3 + " | " /]
+ [/#if]
+ [#elseif channel_index <= 11]
+ [#local sqr2 = sqr2 + "ADC_SQR2_SQ" + (channel_index + 1) +
+ "_N(" + channel + ")" /]
+ [#if channel_has_next && channel_index < 11]
+ [#local sqr2 = sqr2 + " | " /]
+ [/#if]
+ [#else]
+ [#local sqr1 = sqr1 + " | ADC_SQR2_SQ" + (channel_index + 1) +
+ "_N(" + channel + ")" /]
+ [/#if]
+ [/#list]
+ [#-- SQR2 could be empty.--]
+ [#if sqr2 == ""]
+ [#local sqr2 = "0" /]
+ [/#if]
+ [#local sqr1 = sqr1 + "," /]
+ [#local sqr2 = sqr2 + "," /]
+ [@utils.FormatStringAsText " " " " sqr1 80 /]
+ [@utils.FormatStringAsText " " " " sqr2 80 /]
+ [@utils.FormatStringAsText " " " " sqr3 80 /]
+};
+ [/#list]
+[/#macro]
+
+[#--
+ -- Emits the STM32F4xx ADC driver configuration external declarations.
+ --]
+[#macro EmitADCConfigExtern config]
+ [#local cfg_name = config.name[0]?string /]
+ [#list config.groups.group as group]
+ [#local grpcfg_name = group.name[0]?string /]
+ [#-- Only emits the comment if there is at least a callback defined.--]
+ /* ADC configuration "${cfg_name}".*/
+ extern const ADCConfig ${cfg_name};
+ /* ADC conversion group "${grpcfg_name}".*/
+ extern const ADCGroupConfig ${grpcfg_name};
+ [#if group.conv_callback[0]?string?trim != ""]
+ void ${group.conv_callback[0]?string?trim}(ADCDriver *, adcsample_t *, size_t);
+ [/#if]
+ [#if group.error_callback[0]?string?trim != ""]
+ void ${group.error_callback[0]?string?trim}(ADCDriver *, adcerror_t);
+ [/#if]
+
+ [/#list]
+[/#macro]
diff --git a/tools/gencfg/lib/libutils.ftl b/tools/gencfg/lib/libutils.ftl new file mode 100644 index 000000000..03b0622a3 --- /dev/null +++ b/tools/gencfg/lib/libutils.ftl @@ -0,0 +1,109 @@ +[#ftl]
+[#--
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ --]
+
+[#--
+ -- Returns the trimmed text "s" making sure it is terminated by a dot.
+ -- The empty string is always returned as an empty string, the dot is not
+ -- added.
+ --]
+[#function WithDot s]
+ [#local s = s?trim /]
+ [#if s == ""]
+ [#return s /]
+ [/#if]
+ [#if s?ends_with(".")]
+ [#return s /]
+ [/#if]
+ [#return s + "." /]
+[/#function]
+
+[#--
+ -- Returns the trimmed text "s" making sure it is not terminated by a dot.
+ --]
+[#function WithoutDot s]
+ [#local s = s?trim /]
+ [#if s?ends_with(".")]
+ [#return s?substring(0, s?length - 2) /]
+ [/#if]
+ [#return s /]
+[/#function]
+
+[#--
+ -- Returns the trimmed text "s" making sure it is terminated by a dot if the
+ -- text is composed of multiple phrases, if the text is composed of a single
+ -- phrase then makes sure it is *not* terminated by a dot.
+ -- A phrase is recognized by the pattern ". " into the text.
+ -- The empty string is always returned as an empty string, the dot is never
+ -- added.
+ --]
+[#function IntelligentDot s]
+ [#local s = s?trim /]
+ [#if s?contains(". ")]
+ [#return WithDot(s) /]
+ [/#if]
+ [#return WithoutDot(s) /]
+[/#function]
+
+[#--
+ -- Formats a text string in a sequence of strings no longer than "len" (first
+ -- line) or "lenn" (subsequent lines).
+ -- White spaces are normalized between words, sequences of white spaces become
+ -- a single space.
+ --]
+[#function StringToText len1 lenn s]
+ [#local words=s?word_list /]
+ [#local line="" /]
+ [#local lines=[] /]
+ [#list words as word]
+ [#if lines?size == 0]
+ [#local len = len1 /]
+ [#else]
+ [#local len = lenn /]
+ [/#if]
+ [#if (line?length + word?length + 1 > len)]
+ [#local lines = lines + [line?trim] /]
+ [#local line = word + " " /]
+ [#else]
+ [#local line = line + word + " " /]
+ [/#if]
+ [/#list]
+ [#if line != ""]
+ [#local lines = lines + [line?trim] /]
+ [/#if]
+ [#return lines /]
+[/#function]
+
+[#--
+ -- Emits a string "s" as a formatted text, the first line is prefixed by the
+ -- "p1" parameter, subsequent lines are prefixed by the "pn" paramenter.
+ -- Emitted lines are no longer than the "len" parameter.
+ -- White spaces are normalized between words.
+ --]
+[#macro FormatStringAsText p1 pn s len]
+ [#local lines = StringToText(len - p1?length, len - pn?length, s) /]
+ [#list lines as line]
+ [#if line_index == 0]
+${p1}${line}
+ [#else]
+${pn}${line}
+ [/#if]
+ [/#list]
+[/#macro]
|