#!/bin/bash
# Unicode Character Table Generator for HTML. A CGI Script.
# ©2024 J. S. Gilstrap - All Rights Reserved.
# Creative Commons (CC BY-SA 4.0)
# Copyright notice must remain at bottom of page.

# Detect Mobile Platform.
Col=14 ; Wdth=1232  # Desktop Defaults.
case "$HTTP_USER_AGENT" in
	*Mobile*|*Android*) Col=5 ; Wdth=720 ;;
	*) ;;
esac

# Set default range if not specified.
if [ -n "$1" ]
then
	strt=${1%-*}
	 end=${1#*-}

	# Test for NANs & ranges. Exit if invald.
	[ "$strt" -eq "$end" ] && unset end
	s=$strt ; ((s++)) || { printf "Content-Type: text/plain\n\nMin is NAN." ; exit 1 ; }
	e=$end  ; ((e++)) || { printf "Content-Type: text/plain\n\nMax is NAN." ; exit 1 ; }
	[ "$strt" -lt 32 ] && \
		{ printf "Content-Type: text/plain\n\nMin is Out of Range." ; exit 1 ; }
	[ "$end" -gt 155063 ] && \
		{ printf "Content-Type: text/plain\n\nMax is Out of Range." ; exit 1 ; }
	[ "$end" -lt "$strt" ] && \
		{ printf "Content-Type: text/plain\n\nMax value is less than the Min value." ; exit 1 ; }
	rng=$(($end - $strt)) ; [ "$rng" -gt 2000 ] && \
		{ printf "Content-Type: text/plain\n\nRange is Too Large. Use 2000 or Less." ; exit 1 ; }

	range="From $strt to $end"

	case "$1" in
		       32-591) Title="Latin" ;;
		      592-767) Title="Phonetic" ;;
		      768-879) Title="Combining Marks" ;;
		     880-1023) Title="Greek &amp; Coptic" ;;
		    7936-8190) Title="Extended Greek" ;;
		    1024-1279) Title="Cyrillic" ;;
		    1328-1423) Title="Armenian" ;;
		    1424-1535) Title="Hebrew" ;;
		  64285-64335) Title="Hebrew 2" ;;
		    1536-1791) Title="Arabic" ;;
		    1792-1871) Title="Syriac" ;;
		    1920-1983) Title="Thaana" ;;
		    2048-2111) Title="Samaritan" ;;
		    2112-2143) Title="Mandiac" ;;
		    2144-2159) Title="Syriac 2" ;;
		    2304-2583) Title="Brahmic" ;;
		    4256-4351) Title="Georgian" ;;
		    4608-4988) Title="African" ;;
		    5120-5759) Title="American" ;;
		    6144-6344) Title="Mongolian" ;;
		    7248-7295) Title="Ol Ckiki" ;;
		    8192-8303) Title="General Punctuation" ;;
		    8211-8266) Title="Unicode Symbols" ;;
		    8304-8348) Title="Super &amp; Sub Scripts" ;;
		    8352-8384) Title="Currency" ;;
		    8448-8527) Title="Letterlike" ;;
		    8528-8587) Title="Number Forms" ;;
		    8592-8688) Title="Arrows" ;;
		    8704-8959) Title="Mathematical" ;;
		    8960-9215) Title="Misc.Tech" ;;
		    9216-9257) Title="Ctrl.Pictures" ;;
		    9280-9290) Title="OCR" ;;
		    9312-9471) Title="Enclosed Alpha" ;;
		    9472-9599) Title="Box&nbspDraw" ;;
		    9600-9631) Title="Block Elements" ;;
		    9632-9727) Title="Geometric" ;;
		    9728-9983) Title="Misc.Symbol" ;;
		   9984-10175) Title="Dingbats" ;;
		  43264-43311) Title="Kaya Li" ;;
		  69840-69887) Title="Sora Sompeng" ;;
		  71840-71935) Title="Warang Citi" ;;
		  72640-72703) Title="Sunuwar" ;;
		  72960-73055) Title="Masaram Gondi" ;;
		  73056-73135) Title="Gunjala Gondi" ;;
		  92736-92783) Title="Mro" ;;
		  92784-92879) Title="Tangsa" ;;
		  92928-93071) Title="Pahawh Hmong" ;;
		119808-120831) Title="Various Latin &amp; Greek Font Sets" ;;
		123536-123583) Title="Toto" ;;
		124112-124159) Title="Nag Mundari" ;;
		124368-124415) Title="Ol Onal" ;;
		  68864-68927) Title="Hanaifi Rohingya" ;;
		  72384-72447) Title="Pau Cin Hau" ;;
	esac 
else
	Title="Emojis &amp; More<br>e.g: &#128721;! &#128483;&#128075;, &#128065;&#128683;&#128066;!"
fi

RLE() { local IFS=$'\n' ; while read line ; do echo "$line" ; done ; }

Print()
	{
	[ "$ptr" = y ] && { ptr=n ; printf "<tr bgcolor=\"#ffffff\">\n" ; colc=1 ; }
	printf "\t<td align=\"center\"><font size=\"7\">&#${c};</font><br><font size=\"4\">${c}<br>0x"
	printf '%x' "$c" ; printf "</font></td>\n"
	[ "$colc" -ge $Col ] && { printf "</tr>\n" ; ptr=y ; }
	((colc++))
	}

colc=1
# Print header.
#while read line ; do echo "$line" ; done
RLE << EoF
Content-Type: text/html; charset=utf-8

<html>
<head>
	<meta name="author" content="J. S. Gilstrap">
	<meta http-equiv="Content-Type" content="text/html"; charset="utf-8">
	<meta name="keywords" content="Unicode, Emoji">
	<meta name="viewport" cortent="width=device-width, initial-scale=0.60, maxium-scale=1.5, minimum-scale=0.60">
	<style>
		body { width:${Wdth}px; }
		a {text-decoration:none; }
	</style>
</head>
<body text="#000000" bgcolor="#ffffff" link="#0000ff" alink="#ff002c" vlink="#9600ff">
<center>
<font face="Arial,Helvetica,Sans">
<br>
<font size="7" face="BookmanJFPro-Regular,'Comic Sans MS','Arial Rounded MT Bold',Arial,Helvetica,Sans">
<b>Unicode Character<br>Table Generator<br>
</font>
<br>

<font size="6">
${Title}<br>
</font>
<font size="5">
${range}</b><br>
<br>
For a custom range specify as the argument.
Minimum is 32 and maximum is 155063.
Specifying the minimum and maximum values
will take a longer time to display and a much
longer time for you to sort through. It is better
to specify small ranges. For html  use: &#??????;
where ? are the Code's digits.<br>
<br>
Ex: /cgi-bin/unicode?1234-5678<br>
<br>

<a href="/cgi-bin/unicode"><b>Emojis&nbsp;&amp;&nbsp;More</b></a><br>
<a href="/cgi-bin/unicode?32-591">Latin</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?592-767">Phonetic</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?768-879">Combining&nbsp;Marks</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?880-1023">Greek&nbsp;&amp;&nbsp;Coptic</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?7936-8190">Extended&nbsp;Greek</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?1024-1279">Cyrillic</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?1328-1423">Armenian</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?1424-1535">Hebrew</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?64285-64335">Hebrew&nbsp;2</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?1536-1791">Arabic</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?1792-1871">Syriac</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?1920-1983">Thaana</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?2048-2111">Samaritan</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?2112-2143">Mandiac</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?2144-2159">Syriac&nbsp;2</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?2304-2583">Brahmic</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?4256-4351">Georgian</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?4608-4988">African</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?5120-5759">American</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?6144-6344">Mongolian</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?7248-7295">Ol&nbsp;Ckiki</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8192-8303">General&nbsp;Punctuation</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8211-8266">Unicode&nbsp;Symbols</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8304-8348">Super&nbsp;&amp;&nbsp;Sub&nbsp;Scripts</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8352-8384">Currency</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8448-8527">Letterlike</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8528-8587">Number&nbsp;Forms</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8592-8688">Arrows</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8704-8959">Mathematical</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?8960-9215">Misc.Tech</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?9216-9257">Ctrl.Pictures</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?9280-9290">OCR</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?9312-9471">Enclosed&nbsp;Alpha</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?9472-9599">Box&nbspDraw</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?9600-9631">Block&nbsp;Elements</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?9632-9727">Geometric</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?9728-9983">Misc.Symbol</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?9984-10175">Dingbats</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?43264-43311">Kaya&nbsp;Li</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?68864-68927">Hanaifi&nbsp;Rohingya</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?69840-69887">Sora&nbsp;Sompeng</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?71840-71935">Warang&nbsp;Citi</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?72384-72447">Pau&nbsp;Cin&nbsp;Hau</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?72640-72703">Sunuwar</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?72960-73055">Masaram&nbsp;Gondi</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?73056-73135">Gunjala&nbsp;Gondi</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?92736-92783">Mro</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?92784-92879">Tangsa</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?92928-93071">Pahawh&nbsp;Hmong</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?119808-120831">Various&nbsp;Latin&nbsp;&amp;&nbsp;Greek&nbsp;Font&nbsp;Sets</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?123536-123583">Toto</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?124112-124159">Nag&nbsp;Mundari</a>&nbsp;&nbsp;
<a href="/cgi-bin/unicode?124368-124415">Ol&nbsp;Onal</a>&nbsp;&nbsp;
<br></font>
<br>
<hr>

<br>
<table border="0" cellspacing="1" cellpadding="5" bgcolor="#c0c0c0">
<tr bgcolor="#ffffff">
EoF

# Generate characters.
if [ -n "$1" ]
then
	c=$strt
	while [ $c -le $end ]
	do
		Print
		((c++))
	done 2> /dev/null
else
	for n in 128 131 134 135 153 161 162 {163..169} 174 {177..182} 186 {188..191} 198 214 215 216 220 223 228 230 231 232 233 235 239 241 {246..248} 252 330 331 402 632 650 915 916 931 937 945 946 952 955 960 964 969 1769 8240 8252 8269 8356 8359 8361 8457 8470 8471 8478 8480 8481 8482 8486 8487 8505 8507 {8528..8543} {8592..8618} {8656..8660} 8710 8711 8721 8723 {8730..8732} 8741 8743 8767 8776 8800 {8853..8856} {8982..8984} 8986 8987 8988 9000 9003 9004 9021 9022 9166 9167 9187 9189 9190 {9193..9203} {9208..9210} {9216..9249} 9252 {9372..9423} 9642 9643 9654 9664 9678 {9723..9775} {9784..9794} {9795..9811} {9812..9823} {9824..9831} 9832 {9833..9839} {9840..9855} {9856..9861} {9862..9871} {9872..9884} {9890..9897} 9898 9899 {9900..9906} 9917 9918 9924 9925  9928 9934 9935 9937 9939 9940 9954 9961 9962 {9968..9978} 9981 {9985..9999} {10000..10078} {10081..10100} {10101..10132} {10133..10175} {10229..10239} {10548..10561} {10710..10715} {10752..10754} {11008..11055} {11088..11093} 11152 11153 11569 11570 12951 12953 12292 12320 {64256..64262} 126980 127183 {127184..127199} {127232..127242} {127248..127273} {127280..127305} {127311..127337}  {127344..127386} {127462..127487} 127489 127490 {127504..127514} 127535 {127538..127546} 127568 127569 {127744..128317} {128329..128359} 128367 128368 {128371..128378} 128391 {128394..128397} 128400 128405 128406 128420 128421 128424 128433 128434 128444 {128450..128452} {128465..128467} {128476..128478} 128481 128483 128488 128495 128499 {128506..128591} {128640..128709} {128716..128722} {128725..128727} {128732..128741} {128745..128748} 128752 {128755..128764} {128992..129003} 129008 {129292..129535} {129648..129670} {129680..129733} {129744..129753} {129760..129767} {129776..129782}
	do
		for c in $n
		do
			Print
		done
	done
fi

while [ "$colc" -le $Col ]
do
	printf "\t<td></td>\n"
	((colc++))
done

# Print footer.
RLE << EoF
</tr>
</table>
<ibr><br>

<font size="5">
<a href="https://www.amstzone.org/Home/unicode" title="A CGI Script">
Download and run <b>unicode</b> script on your server.</a><br>
<br>
<a href="https://www.muquit.com/muquit/software/Count/Count.html">
<img src="https://www.amstzone.org/cgi-bin/Count.cgi?df=unicode.dat&pad=F&frgb=e80028&dd=C"></A><br>
<b>Visitors</b><br><br>
</font>

<font size="5">
©2024 J. S. Gilstrap<br>
All Rights Reserved.<br>
<a href="https://creativecommons.org/licenses">(CC BY-ND 4.0)</a><br>
</font>

<font size="7">
&#129410;&#128167;&#128005;<br>
<br>
</font>

</font>
</center>
</body>
</html>

EoF

