]> www.ginac.de Git - cln.git/blob - digit_header
6a210127a08fad2a9e7e30621dc5ad20a639c1da
[cln.git] / digit_header
1 #!/bin/sh
2 # Usage: digit_header < pi.h.in > pi.h
3 #        converts a file containing the digits of pi (in hex) to
4 #        a header file suitable for inclusion.
5
6 bytes=''
7 while true; do
8   IFS='@' read line || break
9   bytes="$bytes "`echo "$line" | sed -e 's,//.*$,,' -e 's,[{};], ,g' -e 's,D(, ,g' -e 's/[,)]/ /g' -e 's,0x, ,g'`
10 done
11 bytes=`echo "$bytes" | sed -e 's,  *, ,g'`
12
13 blocks1=`echo " $bytes" | sed -e 's/ \([0-9A-Za-z]\+\)/ D1(0x\1),/g'`
14 blocks2=`echo " $bytes" | sed -e 's/ \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\)/ D2(0x\1,0x\2),/g'`
15 blocks4=`echo " $bytes" | sed -e 's/ \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\)/ D4(0x\1,0x\2,0x\3,0x\4),/g'`
16 blocks8=`echo " $bytes" | sed -e 's/ \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\) \([0-9A-Za-z]\+\)/ D8(0x\1,0x\2,0x\3,0x\4,0x\5,0x\6,0x\7,0x\8),/g'`
17
18 reverse () {
19   eval "l=\$$1"
20   r=''; for word in $l; do r="$word $r"; done
21   eval "$2=\$r"
22 }
23
24 reverse blocks1 revblocks1
25 reverse blocks2 revblocks2
26 reverse blocks4 revblocks4
27 reverse blocks8 revblocks8
28
29 echo "{"
30 echo "#if CL_DS_BIG_ENDIAN_P"
31 echo "  #if (intDsize==8)"
32 echo "    "`echo "$blocks1" | sed -e 's/, *$//'`
33 echo "  #endif"
34 echo "  #if (intDsize==16)"
35 echo "    "`echo "$blocks2" | sed -e 's/, *$//'`
36 echo "  #endif"
37 echo "  #if (intDsize==32)"
38 echo "    "`echo "$blocks4" | sed -e 's/, *$//'`
39 echo "  #endif"
40 echo "  #if (intDsize==64)"
41 echo "    "`echo "$blocks8" | sed -e 's/, *$//'`
42 echo "  #endif"
43 echo "#else"
44 echo "  #if (intDsize==8)"
45 echo "    "`echo "$revblocks1" | sed -e 's/, *$//'`
46 echo "  #endif"
47 echo "  #if (intDsize==16)"
48 echo "    "`echo "$revblocks2" | sed -e 's/, *$//'`
49 echo "  #endif"
50 echo "  #if (intDsize==32)"
51 echo "    "`echo "$revblocks4" | sed -e 's/, *$//'`
52 echo "  #endif"
53 echo "  #if (intDsize==64)"
54 echo "    "`echo "$revblocks8" | sed -e 's/, *$//'`
55 echo "  #endif"
56 echo "#endif"
57 echo "} ;"