Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/examples/txt2html.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ Table Copyright MP7 1995
\ Copyright 1997,2008 HanSoft & Partners
\ Replaces IBM codes with HTML codes

[needs lib/row.4th]

table ASCII>HTML
    \ traitements signes reserves HTML
    060 , ," <"                     \ Signe inferieur a
    062 , ," >"                     \ Signe supreieur a
    038 , ," &"                    \ Ampersand
    034 , ," ""                   \ Signe double appostrophe
    \ traitement caracteres minuscules
    160 , ," á"                 \ a minuscule, accent aigu
    133 , ," à"                 \ a minuscule, accent grave
    131 , ," â"                  \ a minuscule, accent circonflexe
    134 , ," å"                  \ a minuscule, ring
    132 , ," ä"                   \ a minuscule, dieresis or umlaut mark
    145 , ," æ"                  \ a minusculee dipthong (ligature)
    135 , ," ç"                 \ c minuscule, cedille
    130 , ," é"                 \ e minuscule, accent aigu
    138 , ," è"                 \ e minuscule, accent grave
    136 , ," ê"                  \ e minuscule, accent circonflexe
    137 , ," ë"                   \ e minuscule, trema
    161 , ," í"                 \ i minuscule, accent aigu
    141 , ," ì"                 \ i minuscule, accent grave
    140 , ," î"                  \ i minuscule, accent circonflexe
    139 , ," ï"                   \ i minuscule, trema
    164 , ," ñ"                 \ n minuscule, tilde
    162 , ," ó"                 \ o minuscule, accent aigu
    149 , ," ò"                 \ o minuscule, accent grave
    147 , ," ô"                  \ o minuscule, accent circonflexe
    148 , ," ö"                   \ o minuscule, trema
    237 , ," ø"                 \ o minuscule, slash
    163 , ," ú"                 \ u minuscule, accent aigu
    151 , ," ù"                 \ u minuscule, accent grave
    150 , ," û"                  \ u minuscule, accent circonflexe
    129 , ," ü"                   \ u minuscule, dieresis or umlaut mark
    152 , ," ÿ"                   \ y minuscule, dieresis or umlaut mark
    \ traitement des caracteres majuscules
    143 , ," Å"                  \ A majuscule, ring
    142 , ," Ä"                   \ A majuscule, trema
    146 , ," Æ"                  \ AE majuscules lies
    128 , ," Ç"                 \ C majuscule, cedille
    144 , ," É"                 \ E majuscule, accent aigu
    165 , ," Ñ"                 \ N majuscule, tilde
    153 , ," Ö"                   \ O majuscule, trema
    154 , ," Ü"                   \ U majuscule, trema
    \ caracteres speciaux
    225 , ," ß"                  \ S-Zet allemand
    \ Symboles divers
    173 , ," ¡"                   \ exclamation inverse
    155 , ," ¢"                   \ signe cents americains
    156 , ," £"                   \ Livre Streling
    157 , ," ¥"                   \ Signe Yen
    124 , ," ¦"                   \ Broken vertical bar
    174 , ," «"                   \ Left angle quote, guillemotleft
    170 , ," ¬"                   \ Not sign
    248 , ," °"                   \ Degree sign
    241 , ," ±"                   \ Plus or minus
    253 , ," ²"                   \ 2 exposant
    230 , ," µ"                   \ signe Micro sign
    250 , ," ·"                   \ Middle dot
    175 , ," »"                   \ Right angle quote, guillemotright
    171 , ," ½"                   \ Fraction one-half
    168 , ," ¿"                   \ Inverted question mark
    NULL ,

: Substitute          ( n --)          \ convert codes
  dup                                  \ save original
  ASCII>HTML 2 num-key row             \ search table
  if                                   \ if HTML code drop original
    nip nip cell+ @c count type        \ output HTML code
  else                                 \ else drop dummy code
    drop drop emit                     \ emit original
  then
;

: Usage abort" Usage: ASC2HTML [ascii file] [HTML file]" ;

: PreProcess
  ." <HTML>" cr                        \ write heading
  ." <BODY>" cr
  ." <PRE>" cr
;

: Read-file pad 1 accept 0<> ;         \ get character, check EOF
: Process pad c@ Substitute ;          \ convert code

: PostProcess 
  ." </PRE>" cr
  ." </BODY>" cr
  ." </HTML>" cr                       \ write footer
;

[needs lib/convert.4th]

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.