Show HN: Loop macro with user-definable clauses in C preprocessor, for Awk
By the way, for those running CGIT, here is how I have it formatting man pages on the fly.<p>The conversion of the special backspace character sequences to color is done by a TXR Lisp program manht.tl compiled to manht.tlo.<p><pre><code>  commit b3e2c86b6bfb05a103ddb83959ed6a99049e6022
  Author: Kaz Kylheku &lt;kaz@kylheku.com&gt;
  Date:   Thu Apr 7 19:10:21 2022 -0700
  
      cgit: format troff html files with man.
  
  diff --git a&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;manht.tl b&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;manht.tl
  new file mode 100755
  index 0000000..ee5cff4
  --- &#x2F;dev&#x2F;null
  +++ b&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;manht.tl
  @@ -0,0 +1,24 @@
  +#!&#x2F;usr&#x2F;bin&#x2F;env txr
  +
  +(compile-only
  +  (let ((cur-mode :norm)
  +        (closer &quot;&quot;))
  +    (flet ((output-text (str mode)
  +             (when (neq mode cur-mode)
  +               (put-string closer)
  +               (caseq (set cur-mode mode)
  +                 (:bold (put-string &quot;&lt;span style=&#x27;color: darkred&#x27;&gt;&quot;)
  +                        (set closer &quot;&lt;&#x2F;span&gt;&quot;))
  +                 (:ital (put-string &quot;&lt;span style=&#x27;color: green&#x27;&gt;&quot;)
  +                        (set closer &quot;&lt;&#x2F;span&gt;&quot;))
  +                 (:norm (set closer &quot;&quot;))))
  +             (put-string (html-encode str))))
  +      (whilet ((line (get-line)))
  +        (each ((tok (tok #&#x2F;.\b.&#x2F; t line)))
  +          (match-case tok
  +            (&quot;&quot;)
  +            (`@{x #&#x2F; +&#x2F; }` (output-text x cur-mode))
  +            (`@x\b@x` (output-text x :bold))
  +            (`_\b@x` (output-text x :ital))
  +            (@else (output-text else :norm))))
  +        (output-text &quot;\n&quot; :norm)))))
  diff --git a&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;manht.tlo b&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;manht.tlo
  new file mode 100755
  index 0000000..6733ced
  --- &#x2F;dev&#x2F;null
  +++ b&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;manht.tlo
  @@ -0,0 +1,29 @@
  +#!&#x2F;usr&#x2F;bin&#x2F;env txr
  +(7 0 nil)
  +((14 48 #b&#x27;020002040004802c 0104812c01000304 2400008c000c0000 020002000a000000
  +           020003000c00003c 000803001f000034 0600012000000108 0300802c0300072c
  +           1600003c02040700 0800012000000304 0404812c1f000034 1c00003c05040700
  +           0900012000000604 0404812c1f000034 1f00003c00040700 0104812c04000120
  +           0100020005000120 0000040005000010 07042f2c9d00004c 000002009b000038
  +           2f0000002e000020 0200000099000038 2e0000002d000320 0300080407042e00
  +           2c00012004002d00 9500004c00000b00 0f00012005002c00 940000380f000000
  +           2d00012007002c00 00002b2c12000220 08002d0001040000 9100003c00001200
  +           2d001b2c12000120 09001b0052000038 1200000018000320 0a001b0009040704
  +           1800192c12000220 0b000a0419000000 5200003812000000 2b000218000c1900
  +           0008000091000034 2d00232c12000120 0900230079000038 120000000904222c
  +           1e0003200c002300 0b0422001e00212c 2100122c77000038 210000001d000220
  +           0d0021000c040000 1c0003200a002300 220021001c001f2c 180001200f002300
  +           1600022011001f00 0000000015000320 1000230016001d00 120002200e001800
  +           1500000079000038 120000002b000218 000c1f0002040000 0704122c9100003c
  +           000012002d00292c 1200012009002900 8e00003812000000 250002200d000904
  +           0d0400002500272c 1200032010002900 0e0409048e000038 1200000024000320
  +           0a00290027000704 2b000218000c2400 0504000091000034 2b000218000c2d00
  +           000400002c000120 06002c0034000034 0b00001008000218 000c0f0400040000
  +           2700003400002f2c 270000340000022c 0200001002000010 0200001002000010&#x27;
  +  #(:norm &quot;&quot; :bold &quot;&lt;span style=&#x27;color: darkred&#x27;&gt;&quot; &quot;&lt;&#x2F;span&gt;&quot; :ital
  +    &quot;&lt;span style=&#x27;color: green&#x27;&gt;&quot; usr:t #&#x2F;.\b.&#x2F; 0 #&#x2F; +&#x2F; &quot;\b&quot; 1 2
  +    &quot;_\b&quot; &quot;\n&quot;)
  +  #(usr:put-string usr:html-encode usr:get-line usr:tok usr:iter-begin
  +    usr:iter-more usr:iter-step usr:iter-item usr:equal usr:stringp
  +    usr:sub-str usr:m^$ usr:search-str sys:b+ usr:eql usr:len usr:match-str
  +    sys:fmt-simple)))
  diff --git a&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;syntax-highlighting.sh b&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;syntax-highlighting.sh
  index 52d454d..7d944d1 100755
  --- a&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;syntax-highlighting.sh
  +++ b&#x2F;usr&#x2F;lib&#x2F;cgit&#x2F;filters&#x2F;syntax-highlighting.sh
  @@ -41,6 +41,9 @@ Makefile | makefile | MAKEFILE )
   ChangeLog | CHANGELOG | changelog )
     LANGUAGE=changelog
     ;;
  +txr.1 )
  +  LANGUAGE=none
  +  ;;
   *.[1-9] )
     LANGUAGE=troff
     ;;
  @@ -70,6 +73,9 @@ case $LANGUAGE in
       fi
       exit 0
       ;;
  +  troff )
  +    MANWIDTH=100 MAN_KEEP_FORMATTING=y man -l - | $SELFDIR&#x2F;manht.tlo
  +    ;;
     * )
       OTMPFILE=&#x2F;tmp&#x2F;file.$$.$LANGUAGE.html
       if [ $LANGUAGE == mk ] ; then</code></pre>