diff --git a/src/util/print.jam b/src/util/print.jam index 9a4f722fe..ca5e02be5 100644 --- a/src/util/print.jam +++ b/src/util/print.jam @@ -30,8 +30,27 @@ rule output ( ) { type ?= plain ; - output-target = $(target) ; - output-type = $(type) ; + if $(output-target) != $(target) + { + output-target = $(target) ; + output-type = $(type) ; + if $(output-type) = html + { + text + "" + "" + "" + "" + "" + : true + : prefix ; + text + "" + "" + : + : suffix ; + } + } } # Generate a section with a description. The type of output can be @@ -48,53 +67,94 @@ rule section ( { lines [ split-at-words $(name): ] ; lines ; - local pre = ; - while $(description) + } + else if $(output-type) = html + { + name = [ escape-html $(name) ] ; + text

$(name)

; + } + local pre = ; + while $(description) + { + local paragraph = ; + while $(description) && $(description[1]) = "" { description = $(description[2-]) ; } + if $(pre) { - local paragraph = ; - while $(description) && $(description[1]) = "" { description = $(description[2-]) ; } - if $(pre) + pre = ; + while $(description) && ( $(description[1]) = "" || [ MATCH "^([ ])" : $(description[1]) ] ) + { paragraph += $(description[1]) ; description = $(description[2-]) ; } + if $(output-type) = plain { - pre = ; - while $(description) && ( $(description[1]) = "" || [ MATCH "^([ ])" : $(description[1]) ] ) - { paragraph += $(description[1]) ; description = $(description[2-]) ; } lines $(paragraph) : " " " " ; } - else + else if $(output-type) = html { - while $(description) && $(description[1]) != "" - { paragraph += $(description[1]) ; description = $(description[2-]) ; } - if $(paragraph[1]) = :: && ! $(paragraph[2]) - { - pre = yes ; - } - if $(paragraph[1]) = :: + text

; + lines $(paragraph) ; + text
; + } + } + else + { + while $(description) && $(description[1]) != "" + { paragraph += $(description[1]) ; description = $(description[2-]) ; } + if $(paragraph[1]) = :: && ! $(paragraph[2]) + { + pre = yes ; + } + if $(paragraph[1]) = :: + { + if $(output-type) = plain { lines $(paragraph[2-]) : " " " " ; lines ; } - else + else if $(output-type) = html { - local p = [ MATCH "(.*)(::)$" : $(paragraph[-1]) ] ; - local pws = [ MATCH "([ ]*)$" : $(p[1]) ] ; - p = [ MATCH "(.*)($(pws))($(p[2]))$" : $(paragraph[-1]) ] ; - if $(p[3]) = :: + text
; + lines $(paragraph[2-]) ; + text
; + } + } + else + { + local p = [ MATCH "(.*)(::)$" : $(paragraph[-1]) ] ; + local pws = [ MATCH "([ ]*)$" : $(p[1]) ] ; + p = [ MATCH "(.*)($(pws))($(p[2]))$" : $(paragraph[-1]) ] ; + if $(p[3]) = :: + { + pre = yes ; + if ! $(p[2]) || $(p[2]) = "" { paragraph = $(paragraph[1--2]) $(p[1]): ; } + else { paragraph = $(paragraph[1--2]) $(p[1]) ; } + if $(output-type) = plain { - pre = yes ; - if ! $(p[2]) || $(p[2]) = "" { paragraph = $(paragraph[1--2]) $(p[1]): ; } - else { paragraph = $(paragraph[1--2]) $(p[1]) ; } lines [ split-at-words " " $(paragraph) ] : " " " " ; lines ; } - else + else if $(output-type) = html + { + text

[ escape-html $(paragraph) ] ; + } + } + else + { + if $(output-type) = plain { lines [ split-at-words " " $(paragraph) ] : " " " " ; lines ; } + else if $(output-type) = html + { + text

[ escape-html $(paragraph) ] ; + } } } } } + if $(output-type) = html + { + text

; + } } # Generate the start of a list of items. The type of output can be @@ -107,6 +167,10 @@ rule list-start ( ) if $(output-type) = plain { } + else if $(output-type) = html + { + text ; + } } # Split the given text into separate lines, word-wrapping to a margin. @@ -211,7 +283,8 @@ rule lines ( else if $(c) = " " { c =      ; } indent = $(indent)$(c) ; } - text $(text[1])
$(indent)$(text[2-])
; + local html-text = [ escape-html $(text) :   ] ; + text $(html-text[1])
$(indent)$(html-text[2-])
; } } @@ -220,6 +293,7 @@ rule lines ( rule text ( strings * # The strings of text to output. : overwrite ? # true to overwrite the output (if it is a file) + : prefix-or-suffix ? # Indication of special prefix or suffix text. ) { if $(output-target) = console @@ -240,21 +314,28 @@ rule text ( else if $(output-target) { $(output-target).line ?= 0 ; + DEPENDS $(output-target) : $(output-target:G=body) ; + ALWAYS $(output-target:G=body) ; + NOTFILE $(output-target:G=body) ; while $(strings) { local line-v = $(output-target).line.$($(output-target).line) ; local echo-string = [ escape $(strings[1]) ] ; - $(line-v) on $(output-target) = $(echo-string) ; - NOCARE $(line-v) ; + local target = $(output-target:G=body) ; + if $(prefix-or-suffix) = suffix + { + target = $(output-target) ; + } + $(line-v) on $(target) = $(echo-string) ; NOTFILE $(line-v) ; if $(overwrite) = "true" { overwrite = false ; - text-overwrite-action $(output-target) : $(line-v) ; + text-overwrite-action $(target) : $(line-v) ; } else - { - text-action $(output-target) : $(line-v) ; + { + text-action $(target) : $(line-v) ; } strings = $(strings[2-]) ; $(output-target).line = [ numbers.increment $($(output-target).line) ] ; @@ -269,18 +350,45 @@ rule wrapped-text ( text + ) text $(lines) ; } +# Escapes text into html/xml printable equivalents. +# Does not know about tags and therefore tags fed into +# this will also be escaped. Currently escapes space, "<", ">", and "&". +# +rule escape-html ( + text + # The text to escape. + : space ? # What to replace spaces with, defaults to " ". + ) +{ + local html-text = ; + while $(text) + { + local html = $(text[1]) ; + text = $(text[2-]) ; + html = [ regex.replace $(html) "&" "&" ] ; + html = [ regex.replace $(html) "<" "<" ] ; + html = [ regex.replace $(html) ">" ">" ] ; + if $(space) + { + html = [ regex.replace $(html) " " "$(space)" ] ; + } + html-text += $(html) ; + } + return $(html-text) ; +} + # Append single line to target file. # actions quietly text-action { - echo $($(>)) >> $(<) + echo $($(>)) >> $(<:G=) } # Writes a single line to target file (overwriting or creating the # file as necessary) -actions quietly text-overwrite-action { - echo $($(>)) > $(<) +actions quietly text-overwrite-action +{ + echo $($(>)) > $(<:G=) } if [ modules.peek : NT ] @@ -307,4 +415,6 @@ local rule __test__ ( ) assert.result "one two" three : split-at-words one two three : 8 ; assert.result "one two" three : split-at-words one two three : 9 ; assert.result "one two three" : split-at-words one two three ; + assert.result "one two three" "&<>" : + escape-html "one two three" "&<>" ; }