Advertisement
heinrich23

utf-8 symbol generation shell script

Mar 6th, 2024 (edited)
7,642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.00 KB | Software | 0 0
  1. #!/bin/sh
  2.  
  3. outhtml=utf8_sym16k.html
  4. outtmp=$(date +%s)".tmp"
  5. outtext=utf8_pre16k.html
  6.  
  7. chx=0
  8.  
  9. if [ $# -gt 0 ] ; then
  10.     chx=$(echo "$1 * 256 * 64" | bc);
  11.     outhtml=utf8_sym16k_ofs$chx.html
  12.     outtext=utf8_pre16k_ofs$chx.html
  13. fi
  14.  
  15. modHex=256
  16. modFF=255
  17. modZero=0
  18.  
  19. dhx=512
  20. ehx=768
  21. fhx=1024
  22. nhx=1023
  23. mhx=1024
  24. yhx=$(echo "$chx + 16384" | bc);
  25.  
  26. printf "<!DOCTYPE html>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\t<head>\n\t\t<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"/>\n\t\t<link rel=\"stylesheet\" href=\"https://area23.at/css/od.css\" />\n\t\t<title>utf-8 symbols</title>\n\t</head>\n" > $outhtml
  27. printf "\n\t<body>\n\t\t<h1>UTF-8 Symbols</h1>\n" >> $outhtml
  28. cat $outhtml > $outtext
  29.  
  30. while [ $chx -lt $yhx ] ; do   
  31.     dhx=$(echo "$chx + 256" | bc);
  32.     ehx=$(echo "$chx + 512" | bc);
  33.     fhx=$(echo "$chx + 768" | bc);
  34.     nhx=$(echo "$chx + 1023" | bc);
  35.     mhx=$(echo "$chx + 1024" | bc);
  36.        
  37.     modZero=$(echo "$chx % $modHex" | bc)
  38.     if [ $modZero -eq 0 ] ; then       
  39.         printf "hex \tx%x \t- \tx%x\tdec \t%d \t- \t%d\n"  $chx $nhx $chx $nhx
  40.        
  41.         printf "\n\t\t<h2>hex x%x - x%x &nbsp; dec %d - %d</h2>\n" $chx $nhx $chx $nhx >> $outhtml
  42.         printf "\n\t\t<h2>hex x%x - x%x &nbsp; dec %d - %d</h2>\n" $chx $nhx $chx $nhx >> $outtext
  43.        
  44.         printf "\n\t\t<table>\n\t\t\t<tr>\n" >> $outhtml
  45.         printf "\t\t\t\t<td>sym&nbsp;</td>\n\t\t\t\t<td>hex %x</td>\n\t\t\t\t<td>dec %d</td>\n\t\t\t\t<td>&nbsp;</td>\n" $chx $chx >> $outhtml
  46.         printf "\t\t\t\t<td>sym&nbsp;</td>\n\t\t\t\t<td>hex %x</td>\n\t\t\t\t<td>dec %d</td>\n\t\t\t\t<td>&nbsp;</td>\n" $dhx $dhx >> $outhtml
  47.         printf "\t\t\t\t<td>sym&nbsp;</td>\n\t\t\t\t<td>hex %x</td>\n\t\t\t\t<td>dec %d</td>\n\t\t\t\t<td>&nbsp;</td>\n" $ehx $ehx >> $outhtml
  48.         printf "\t\t\t\t<td>sym&nbsp;</td>\n\t\t\t\t<td>hex %x</td>\n\t\t\t\t<td>dec %d</td>\n" $fhx $fhx >> $outhtml
  49.         printf "\t\t\t</tr>\n" >> $outhtml
  50.        
  51.         printf "\n\t\t<pre>sym&nbsp;\thx x%x\td %d\t&nbsp;\tsym&nbsp;\thx x%x \td %d\tnbsp;" $chx $chx $dhx $dhx >> $outtext
  52.         printf "\tsym&nbsp;\thx x%x\td %d\t&nbsp;\tsym&nbsp;\thx x%x\td %d\n" $ehx $ehx $fhx $fhx >> $outtext
  53.     fi
  54.  
  55.     printf "\t\t\t<tr>\n" >> $outhtml
  56.     if [ $chx -lt 32 ] ; then
  57.         printf "\t\t\t\t<td>&nbsp;</td>\n"  >> $outhtml
  58.         printf "\t\t\t\t<td>&nbsp;</td>\n"  >> $outhtml
  59.         printf "\t\t\t\t<td>&nbsp;</td>\n"  >> $outhtml            
  60.     else
  61.         printf "\t\t\t\t<td>&#x%x;</td>\n" $chx  >> $outhtml
  62.         printf "\t\t\t\t<td>&amp;&#35;x%x;</td>\n" $chx >> $outhtml
  63.         printf "\t\t\t\t<td>&amp;&#35;%d;</td>\n" $chx >> $outhtml 
  64.     fi     
  65.  
  66.     printf "\t\t\t\t<td>&nbsp;</td>\n" >> $outhtml
  67.    
  68.     printf "\t\t\t\t<td>&#%d;</td>\n" $dhx  >> $outhtml
  69.     printf "\t\t\t\t<td>&amp;&#35;x%x;</td>\n" $dhx >> $outhtml
  70.     printf "\t\t\t\t<td>&amp;&#35;%d;</td>\n" $dhx >> $outhtml 
  71.     printf "\t\t\t\t<td>&nbsp;</td>\n" >> $outhtml
  72.    
  73.     printf "\t\t\t\t<td>&#%d;</td>\n" $ehx  >> $outhtml
  74.     printf "\t\t\t\t<td>&amp;&#35;x%x;</td>\n" $ehx >> $outhtml
  75.     printf "\t\t\t\t<td>&amp;&#35;%d;</td>\n" $ehx >> $outhtml 
  76.     printf "\t\t\t\t<td>&nbsp;</td>\n" >> $outhtml
  77.    
  78.     printf "\t\t\t\t<td>&#x%x;</td>\n" $fhx  >> $outhtml
  79.     printf "\t\t\t\t<td>&amp;&#35;x%x;</td>\n" $fhx >> $outhtml
  80.     printf "\t\t\t\t<td>&amp;&#35;%d;</td>\n" $fhx >> $outhtml 
  81.    
  82.     printf "\t\t\t</tr>\n" >>  $outhtml
  83.    
  84.    
  85.     if [ $chx -lt 32 ] ;  then
  86.         printf "&nbsp;&nbsp;&nbsp;\t&nbsp;&nbsp;&nbsp;\t&nbsp;\t&nbsp;" >> $outtext
  87.     else
  88.         printf "&#x%x;\t&amp;&#35;x%x;\t&amp;&#35;%d;\t&nbsp;" $chx $chx $chx  >> $outtext
  89.     fi
  90.     printf "\t&#%d;\t&amp;&#35;x%x;\t&amp;&#35;%d;\t&nbsp;" $dhx $dhx $dhx >> $outtext
  91.     printf "\t&#x%x;\t&amp;&#35;x%x;\t&amp;&#35;%d;\t&nbsp;" $ehx $ehx $ehx  >> $outtext
  92.     printf "\t&#%d;\t&amp;&#35;x%x;\t&amp;&#35;%d;\n" $fhx $fhx $fhx >> $outtext
  93.  
  94.     modFF=$(echo "$chx % $modHex" | bc)
  95.     if [ $modFF -eq 255 ] ; then
  96.         printf "\n\t\t</table>\n\t\t<hr />\n" >> $outhtml
  97.         printf "</pre>\n\t\t<hr />\n" >> $outtext
  98.         chx=$(echo "$chx + 768" | bc);
  99.     fi
  100.    
  101.     chx=$(echo "$chx + 1" | bc);   
  102. done
  103.    
  104. printf "\n\t</body>\n</html>\n" >> $outhtml
  105. printf "\n\t</body>\n</html>\n" >> $outtext
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement