summaryrefslogtreecommitdiffstats
path: root/include/plmn_list.sh
blob: 0a17068b7eb1fddd5b784f70ca06589d5e3fe7c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
#
# Copyright 2012-2014 Paul Kocialkowski, GPLv3+
#
# This script is a dirty hack, keep in mind that is was written in a hurry
# and doesn't reflect our code cleanness standards.
# Any (working) replacement written in a cleaner way, such as a perl script
# would be greatly appreciated.

echo "/*"
echo " * This list was generated from:"
echo " * http://en.wikipedia.org/wiki/Mobile_country_code"
echo " *"
echo " * Date: "$( date "+%x %X" )
echo " * Copyright: Wikipedia Contributors, Creative Commons"
echo " * Attribution-ShareAlike License"
echo " */"
echo ""
echo "#ifndef _PLMN_LIST_H_"
echo "#define _PLMN_LIST_H_"
echo ""
echo "#include <stdlib.h>"
echo ""
echo "struct plmn_list_entry {"
echo "	unsigned int mcc;"
echo "	unsigned int mnc;"
echo "	char *operator_long;"
echo "	char *operator_short;"
echo "};"
echo ""
echo "struct plmn_list_entry plmn_list[] = {"

wget "http://en.wikipedia.org/w/index.php?title=Special:Export&pages=Mobile_country_code&action=submit" --quiet -O - | tr -d '\n' | sed -e "s|.*<text[^>]*>\(.*\)</text>.*|\1|g" -e "s/|-/\n|-\n/g" | sed -e "s/\(}===.*\)/\n\1/g" -e "s/===={.*/===={\n/g" -e "s/\&amp;/\&/g" -e "s/\&lt;[^\&]*\&gt;//g" -e "s/&quot;//g" -e "s#\[http[^]]*\]##g" -e "s#\[\[\([^]|]*\)|\([^]]*\)\]\]#\2#g" -e "s#\[\[\([^]]*\)\]\]#\1#g" -e "s#\[\([^] ]*\) \([^]]*\)\]#\2#g" -e "s#{{[^}]*}}##g" | tail -n +2 | sed "s|.*==== *\([^=]*\) *====.*|// \1|g" | grep -v "|-" | while read line
do
	if [ "$line" = "" ]
	then
		continue
	fi

	test=$( echo "$line" | grep -P "^//" )

	if [ ! "$test" = "" ]
	then
		echo "\n\t$line\n" | sed -e "s#[^|]*|\(.*\)#// \1#g" -e "s/^ //g" -e "s/ $//g" -e "s/  / /g"
		continue
	fi

	test=$( echo "$line" | grep "||" )

	if [ "$test" = "" ]
	then
		continue
	fi

	mcc=$( echo "$line" | sed -e "s#[^|]*|[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\).*#\1#g" -e "s/^[ |\t]*//g" -e "s/ [ |\t]*$//g" -e "s/[^1-9]*\([0-9]*\).*/\1/g")
	mnc=$( echo "$line" | sed -e "s#[^|]*|[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\).*#\2#g" -e "s/^[ |\t]*//g" -e "s/ [ |\t]*$//g" -e "s/[^1-9]*\([0-9]*\).*/\1/g")
	brand=$( echo "$line" | sed -e "s#[^|]*|[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\).*#\3#g" -e "s/^[ |\t]*//g" -e "s/ [ |\t]*$//g" )
	operator=$( echo "$line" | sed -e "s#[^|]*|[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\)[ ]*||[ ]*\([^|]*\).*#\4#g" -e "s/^[ |\t]*//g" -e "s/ [ |\t]*$//g" )

	if [ "$mcc" = "" ] || [ "$mcc" = "?" ]
	then
		continue
	fi

	if [ "$mnc" = "" ] || [ "$mnc" = "?" ]
	then
		continue
	fi

	if [ "$brand" = "" ]
	then
		if [ "$operator" = "" ]
		then
			continue
		fi

		echo "\t{ $mcc, $mnc, \"$operator\", \"$operator\" },"
	else
		echo "\t{ $mcc, $mnc, \"$brand\", \"$brand\" },"
	fi
done

echo "};"
echo ""
echo "unsigned int plmn_list_count = sizeof(plmn_list) /"
echo "\tsizeof(struct plmn_list_entry);"
echo ""
echo "#endif"