-
Notifications
You must be signed in to change notification settings - Fork 6
/
countries.c
1012 lines (957 loc) · 50 KB
/
countries.c
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Simple MPEG/DVB parser to achieve network/service information without initial tuning data
*
* Copyright (C) 2006, 2007, 2008, 2009 Winfried Koehler
* Copyright (C) 2017 - 2020 mighty-p
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* The project's page is https://github.com/mighty-p/t2scan
*/
#include "countries.h"
#include "scan.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <locale.h>
#include <stdlib.h>
#ifdef VDRVERSNUM
#include <linux/dvb/frontend.h>
namespace COUNTRY {
#else
#include "extended_frontend.h"
#endif
/**************************************************************************************************
* FREQUENCY CALCULATION SCHEME:
* each frequency used by t2scan is calculated as follows:
*
* frequency(channellist, channel, frequency_offset_index) =
* base_offset(channel, channellist) +
* channel * freq_step(channel, channellist) +
* freq_offset(channel, channellist, frequency_offset_index);
*
*
* - channellist is choosen by user, if not choosen defaults are used.
* - channel = 0..133 (might be extended if needed)
* - frequency_offset_index = 0 (no offset) -> 1 (pos offset) -> 2 (neg offset)
*
* if base_offset(channel, channellist) returns -1 this channel will be skipped.
* if freq_offset(channel, channellist, frequency_offset_index) returns -1 this offset will be skipped.
*
* example:
* channellist = 4; channel = 12
*
* base_offset(12, 4) = 142500000
* freq_step(12, 4) = 7000000
* freq_offset(12, 4, 0) = 0
* freq_offset(12, 4, 1) = -1
* freq_offset(12, 4, 2) = -1
*
* frequency = 142500000 + 12 * 7000000 = 226500000
* since freq_offset returns -1 for frequency_offset_index = (1,2) no frequency offset is applied.
*
* 20090101 -wk
**************************************************************************************************/
/*
* User selects a country specific channellist.
* therefore we know
* - frontend type DVB or ATSC
* - used frequency list (base_offsets, freq_step)
* - other country-specific things (transmission mode, frequency offsets from center..)
* use two letter uppercase for 'country', as defined by ISO 3166-1
*/
int choose_country (const char * country,
int * atsc,
int * dvb,
uint16_t * scan_type,
int * channellist,
int * plplist,
int * plplist_length
) {
if (*channellist == USERLIST) return 0;
if (strcasecmp(country_to_short_name(txt_to_country(country)), country)) {
warning("\n\nCOUNTRY CODE IS NOT DEFINED. FALLING BACK TO \"DE\"\n\n");
sleep(10);
}
info("using settings for %s\n", country_to_full_name(txt_to_country(country)));
/*
* choose DVB or ATSC frontend type
*/
switch(txt_to_country(country)) {
case RU:
plplist[0] = -1; plplist[1] = 0; plplist[2] = 1; plplist[3] = 2; plplist[4] = 3;
*plplist_length = 5;
switch(*dvb) {
case SCAN_CABLE:
*scan_type = SCAN_CABLE;
info("DVB cable\n");
break;
default:
*scan_type = SCAN_TERRESTRIAL;
info("DVB aerial\n");
break;
}
break;
case AT: // AUSTRIA
case IT: // ITALY
plplist[0] = -1; plplist[1] = 1; plplist[2] = 0; plplist_length = 3;
case BE: // BELGIUM
case CH: // SWITZERLAND
case CO: // COLOMBIA, DVB-C + DVB-T2
case CZ: // CZECH REPUBLIC
case DE: // GERMANY
case DK: // DENMARK
case ES: // SPAIN
case FR: // FRANCE
case FI: // FINLAND
case GB: // UNITED KINGDOM
case GR: // GREECE
case HR: // CROATIA
case HK: // HONG KONG
case IL: // ISRAEL
case IS: // ICELAND
case LU: // LUXEMBOURG
case LV: // LATVIA
case NL: // NETHERLANDS
case NO: // NORWAY
case NZ: // NEW ZEALAND
case PL: // POLAND
case SE: // SWEDEN
case SK: // SLOVAKIA
case TW: // TAIWAN, DVB-T w. ATSC freq list (thanks for freqlist to mkrufky)
case AU: // AUSTRALIA, DVB-T w. 7MHz step
switch(*dvb) {
case SCAN_CABLE:
*scan_type = SCAN_CABLE;
info("DVB cable\n");
break;
default:
*scan_type = SCAN_TERRESTRIAL;
info("DVB aerial\n");
break;
}
break;
case BR: // Brazil
switch(*dvb) {
case SCAN_CABLE:
*scan_type = SCAN_CABLE;
info("DVB cable\n");
break;
default:
*scan_type = SCAN_TERRESTRIAL;
info("ISDB-T (SBTVD)\n");
break;
}
break;
case US: // UNITED STATES
case CA: // CANADA
*scan_type = SCAN_TERRCABLE_ATSC;
info("ATSC\n");
break;
default:
info("Country identifier %s not defined. Using defaults.\n", country);
return -1;
break;
}
/*
* choose channellist name
*/
switch(txt_to_country(country)) {
//**********DVB freq lists*******************************************//
case AT: // AUSTRIA
case BE: // BELGIUM
case CH: // SWITZERLAND
case DE: // GERMANY
case LU: // LUXEMBOURG
case NL: // NETHERLANDS
switch(*dvb) {
case SCAN_CABLE:
*channellist = DVBC_QAM;
info("DVB-C\n");
break;
default:
*channellist = DVBT_EU_UHF800;
info("DVB-T Europe UHF <790MHz\n");
break;
}
break;
case DK: // DENMARK
case ES: // SPAIN
case GR: // GREECE
case HR: // CROATIA
case HK: // HONG KONG
case IL: // ISRAEL
case IS: // ICELAND
case IT: // ITALY
case LV: // LATVIA
case PL: // POLAND
case NO: // NORWAY
case NZ: // NEW ZEALAND
case SE: // SWEDEN
case SK: // SLOVAKIA
switch(*dvb) {
case SCAN_CABLE:
*channellist = DVBC_QAM;
info("DVB-C\n");
break;
default:
*channellist = DVBT_EU_VHFUHF;
info("DVB-T Europe VHF and UHF\n");
break;
}
break;
case CZ: // CZECH REPUBLIC
case FI: // FINLAND
switch(*dvb) {
case SCAN_CABLE:
*channellist = DVBC_FI;
info("DVB-C FI\n");
break;
default:
*channellist = DVBT_EU_VHFUHF;
info("DVB-T Europe VHF and UHF\n");
break;
}
break;
case FR: // FRANCE
switch(*dvb) {
case SCAN_CABLE:
*channellist = DVBC_FR;
info("DVB-C FR\n");
break;
default:
*channellist = DVBT_EU_UHF800;
info("DVB-T Europe UHF <790MHz\n");
break;
}
break;
case GB: // UNITED KINGDOM
switch(*dvb) {
case SCAN_CABLE:
*channellist = DVBC_QAM;
info("DVB-C\n");
break;
default:
*channellist = DVBT_EU_UHF800;
info("DVB-T Europe UHF <790MHz\n");
break;
}
break;
case AU: // AUSTRALIA
switch(*dvb) {
case SCAN_CABLE:
info("cable australia not yet defined.\n");
break;
default:
*channellist = DVBT_AU;
info("DVB-T AU\n");
break;
}
break;
//**********ATSC freq lists******************************************//
case US: // UNITED STATES
case CA: // CANADA
case TW: // TAIWAN, DVB-T w. ATSC freq list
if (atsc_is_vsb(*atsc)) {
*channellist = ATSC_VSB;
info("VSB US/CA, DVB-T TW\n");
}
if (atsc_is_qam(*atsc)) {
*channellist = ATSC_QAM;
info("QAM US/CA\n");
}
break;
case CO: // COLOMBIA, 6MHz offs 389MHz
switch(*dvb) {
case SCAN_CABLE:
info("cable colombia not yet defined.\n");
break;
default:
*channellist = DVBT2_CO;
info("DVB-T2 CO\n");
break;
}
break;
case BR: // BRAZIL, DVB-C/ISDB-T w. ATSC freq list
switch(*dvb) {
case SCAN_CABLE:
*channellist = DVBC_BR;
info("DVB-C BR\n");
break;
default:
*channellist = ISDBT_6MHZ;
info("ISDB-T, BR\n");
break;
}
break;
//******************************************************************//
default:
info("Country identifier %s not defined. Using default freq lists.\n", country);
return -1;
break;
}
return 0; // success
}
/*
* return the base offsets for specified channellist and channel.
*/
int base_offset(int channel, int channellist) {
switch (channellist) {
case ATSC_QAM: //ATSC cable, US EIA/NCTA Std Cable center freqs + IRC list
case DVBC_BR: //BRAZIL - same range as ATSC IRC
switch (channel) {
case 2 ... 4: return 45000000;
case 5 ... 6: return 49000000;
case 7 ... 13: return 135000000;
case 14 ... 22: return 39000000;
case 23 ... 94: return 81000000;
case 95 ... 99: return -477000000;
case 100 ... 133: return 51000000;
default: return SKIP_CHANNEL;
}
case ATSC_VSB: //ATSC terrestrial, US NTSC center freqs
switch (channel) {
case 2 ... 4: return 45000000;
case 5 ... 6: return 49000000;
case 7 ... 13: return 135000000;
case 14 ... 69: return 389000000;
default: return SKIP_CHANNEL;
}
case DVBT2_CO: // DVB-T2 Colombia, 6 MHz step
switch (channel) {
//channels 21..51 are not stated as digital,
//however ch 27, 28, 43 are marked as T2 in other docs.
//scan up to ch 51 (end of band V)
case 14 ... 51: return 389000000;
default: return SKIP_CHANNEL;
}
case ISDBT_6MHZ: // ISDB-T, 6 MHz central frequencies
switch (channel) {
// Channels 7-13 are reserved but aren't used yet
//case 7 ... 13: return 135000000;
case 14 ... 69: return 389000000;
default: return SKIP_CHANNEL;
}
case DVBT_AU: //AUSTRALIA, 7MHz step list, offset 0/+125kHz
switch (channel) {
case 5 ... 12: return 142500000;
case 21 ... 69: return 333500000;
default: return SKIP_CHANNEL;
}
case DVBT_DE: //GERMANY
case DVBT_FR: //FRANCE, +/- offset 166kHz & +offset 332kHz & +offset 498kHz
case DVBT_GB: //UNITED KINGDOM, +/- offset
case DVBT_EU_UHF:
switch (channel) {
//case 5 ... 12: return 142500000; // VHF no longer used in Europe.
case 21 ... 69: return 306000000;
default: return SKIP_CHANNEL;
}
case DVBT_EU_UHF700:
switch (channel) {
//case 5 ... 12: return 142500000; // VHF no longer used in Europe.
case 21 ... 48: return 306000000;
default: return SKIP_CHANNEL;
}
case DVBT_EU_UHF800:
switch (channel) {
//case 5 ... 12: return 142500000; // VHF no longer used in Europe.
case 21 ... 60: return 306000000;
default: return SKIP_CHANNEL;
}
case DVBT_EU_VHFUHF:
switch (channel) {
case 5 ... 12: return 142500000; // VHF no longer used in Europe.
case 21 ... 69: return 306000000;
default: return SKIP_CHANNEL;
}
case DVBC_QAM: //EUROPE
switch (channel) {
case 0 ... 1:
case 5 ... 12: return 73000000;
case 22 ... 90: return 138000000;
default: return SKIP_CHANNEL;
}
case DVBC_FI: //FINLAND, QAM128
switch (channel) {
case 1 ... 90: return 138000000;
default: return SKIP_CHANNEL;
}
case DVBC_FR: //FRANCE, needs user response.
switch (channel) {
case 1 ... 39: return 107000000;
case 40 ... 89: return 138000000;
default: return SKIP_CHANNEL;
}
default:
fatal("%s: undefined channellist %d\n", __FUNCTION__, channellist);
return SKIP_CHANNEL;
}
}
/*
* return the freq step size for specified channellist
*/
int freq_step(int channel, int channellist) {
switch (channellist) {
case ATSC_QAM:
case ATSC_VSB:
case DVBC_BR:
case DVBT2_CO:
case ISDBT_6MHZ:
return 6000000; // atsc region, 6MHz step
case DVBT_AU: return 7000000; // dvb-t australia, 7MHz step
case DVBT_DE:
case DVBT_FR:
case DVBT_EU_VHFUHF:
case DVBT_EU_UHF:
case DVBT_EU_UHF800:
case DVBT_EU_UHF700:
case DVBT_GB: switch (channel) { // dvb-t europe, 7MHz VHF ch5..12, all other 8MHz
case 5 ... 12: return 7000000;
case 21 ... 69: return 8000000;
default: return 8000000; // should be never reached.
}
case DVBC_QAM:
case DVBC_FI:
case DVBC_FR: return 8000000; // dvb-c, 8MHz step
default:
fatal("%s: undefined channellist %d\n", __FUNCTION__, channellist);
return SKIP_CHANNEL;
}
}
// EN300429 v1.2.1, chapter 9 Modulation p.16:
// "I and Q signals shall be square-root raised cosine filtered. The roll-off factor shall be 0,15"
#define DVBC_ROLLOFF 0.15
#define DVBC_SYMBOL_LEN (1.0 + DVBC_ROLLOFF)
int max_dvbc_srate(int bandwidth) {
switch(bandwidth) {
case 0 ... 6:
fatal("%s %d, using old style DVB API", __FUNCTION__, __LINE__);
return SKIP_CHANNEL;
case 8000000:
case 7000000:
case 6000000:
case 5000000:
return (int) (0.5 + ((double) bandwidth) / DVBC_SYMBOL_LEN);
default:
fatal("%s: unknown channel bandwidth %d\n", __FUNCTION__, bandwidth);
return SKIP_CHANNEL;
}
}
int bandwidth(int channel, int channellist) {
return freq_step(channel, channellist);
}
/*
* some countries use constant offsets around center frequency.
* define them here.
*/
int freq_offset(int channel, int channellist, int index) {
switch (channellist) {
case USERLIST:
return 0;
case ATSC_QAM:
switch (channel) {
case 14 ... 16:
case 25 ... 53:
case 98 ... 99:
switch (index) {
case NO_OFFSET: return 0; //Incrementally Related Carriers (IRC)
case POS_OFFSET: return 12500; //US EIA/NCTA Standard Cable center frequencies
default: return STOP_OFFSET_LOOP;
}
default: // IRC = standard cable center
switch (index) {
case NO_OFFSET: return 0; //center freq
default: return STOP_OFFSET_LOOP;
}
}
case DVBT_FR:
switch (channel) {
// see http://tvignaud.pagesperso-orange.fr/tv/canaux.htm
case 5 ... 12: //VHF channels not used in FR
return STOP_OFFSET_LOOP;
default: //UHF channels. - 0,166 MHz /+ 0,166 MHz /+ 0,332 MHz /+ 0,498 MHz
switch (index) {
case NO_OFFSET: return 0; //center freq
case POS_OFFSET: return +166000; //center+offset 166kHz
case NEG_OFFSET: return -166000; //center-offset 166kHz
case POS_OFFSET_1: return +332000; //center+offset 332kHz
case POS_OFFSET_2: return +498000; //center+offset 498kHz
default: return STOP_OFFSET_LOOP;
}
}
case DVBT_GB:
switch (channel) {
case 5 ... 12: //VHF channels
switch (index) {
case NO_OFFSET: return 0; //no offset
default: return STOP_OFFSET_LOOP;
}
default: //UHF channels
switch (index) {
case NO_OFFSET: return 0; //center freq
case POS_OFFSET: return +167000; //center+offset
case NEG_OFFSET: return -167000; //center-offset
default: return STOP_OFFSET_LOOP;
}
}
case DVBT_AU :
switch (index) {
case NO_OFFSET: return 0; //center freq
case POS_OFFSET: return +125000; //center+offset
default: return STOP_OFFSET_LOOP;
}
case DVBC_FR:
switch (channel) {
case 1 ... 39:
switch (index) {
case NO_OFFSET: return 0; //center freq
case POS_OFFSET: return +125000; //center+offset
default: return STOP_OFFSET_LOOP;
}
case 40 ... 89:
default:
switch (index) {
case NO_OFFSET: return 0;
default: return STOP_OFFSET_LOOP;
}
}
case ISDBT_6MHZ: // ISDB-T, 6 MHz central frequencies
switch (channel) {
// Channels 7-13 are reserved but aren't used yet
case 7 ... 13:
case 14 ... 69:
switch (index) {
case NO_OFFSET: return SKIP_CHANNEL; //center freq
case POS_OFFSET: return +142857; //center+offset
default: return STOP_OFFSET_LOOP;
}
default: return STOP_OFFSET_LOOP;
}
default:
switch (index) {
case NO_OFFSET: return 0;
default: return STOP_OFFSET_LOOP;
}
}
}
/*
* DVB-T: default value if transmission mode AUTO
* not supported
*/
int dvbt_transmission_mode(int channel, int channellist) {
switch (channellist) {
// GB seems to use 8k since 12/2009
default: return TRANSMISSION_MODE_8K;
}
}
/*
* some countries don't use legacy delsys anymore
*/
int delsysloop_min(int channel, int channellist) {
switch (channellist) {
case DVBT2_CO: return 1; //DVB-T2 only.
default: return 0;
}
}
/*
* some countries don't use 2nd gen delsys yet
*/
int delsysloop_max(int channel, int channellist) {
switch (channellist) {
case ATSC_VSB:
case ATSC_QAM:
case DVBC_QAM:
case DVBC_FI:
case DVBC_FR:
case DVBC_BR:
case ISDBT_6MHZ:
case DAB_DE:
case USERLIST:
return 0;
default: return 1;
}
}
/*
* start/stop values for dvbc qam loop
* 0 == QAM_64, 1 == QAM_256, 2 == QAM_128
*/
int dvbc_qam_max(int channel, int channellist) {
switch(channellist) {
case DVBC_FI: return 2; //QAM128
case DVBC_BR:
case DVBC_FR:
case DVBC_QAM: return 1; //QAM256
default: return 0; //no qam loop
}
}
int dvbc_qam_min(int channel, int channellist) {
switch(channellist) {
case DVBC_FI:
case DVBC_BR:
case DVBC_FR:
case DVBC_QAM: return 0; //QAM64
default: return 0; //no qam loop
}
}
int atsc_is_vsb(int atsc) {
return (atsc & ATSC_VSB);
}
int atsc_is_qam(int atsc) {
return (atsc & ATSC_QAM);
}
/*
* two letters constants from ISO 3166-1.
* sorted alphabetically by long country name
*/
struct cCountry country_list[] = {
/*- ISO 3166-1 - unique id - long country name alpha-3 numeric */
{"AF", AF, "AFGHANISTAN"}, /*AFG, 4 },*/
{"AX", AX, "ÅLAND ISLANDS"}, /*ALA, 248},*/
{"AL", AL, "ALBANIA"}, /*ALB, 8 },*/
{"DZ", DZ, "ALGERIA"}, /*DZA, 12 },*/
{"AS", AS, "AMERICAN SAMOA"}, /*ASM, 16 },*/
{"AD", AD, "ANDORRA"}, /*AND, 20 },*/
{"AO", AO, "ANGOLA"}, /*AGO, 24 },*/
{"AI", AI, "ANGUILLA"}, /*AIA, 660},*/
{"AQ", AQ, "ANTARCTICA"}, /*ATA, 10 },*/
{"AG", AG, "ANTIGUA AND BARBUDA"}, /*ATG, 28 },*/
{"AR", AR, "ARGENTINA"}, /*ARG, 32 },*/
{"AM", AM, "ARMENIA"}, /*ARM, 51 },*/
{"AW", AW, "ARUBA"}, /*ABW, 533},*/
{"AU", AU, "AUSTRALIA"}, /*AUS, 36 },*/
{"AT", AT, "AUSTRIA"}, /*AUT, 40 },*/
{"AZ", AZ, "AZERBAIJAN"}, /*AZE, 31 },*/
{"BS", BS, "BAHAMAS"}, /*BHS, 44 },*/
{"BH", BH, "BAHRAIN"}, /*BHR, 48 },*/
{"BD", BD, "BANGLADESH"}, /*BGD, 50 },*/
{"BB", BB, "BARBADOS"}, /*BRB, 52 },*/
{"BY", BY, "BELARUS"}, /*BLR, 112},*/
{"BE", BE, "BELGIUM"}, /*BEL, 56 },*/
{"BZ", BZ, "BELIZE"}, /*BLZ, 84 },*/
{"BJ", BJ, "BENIN"}, /*BEN, 204},*/
{"BM", BM, "BERMUDA"}, /*BMU, 60 },*/
{"BT", BT, "BHUTAN"}, /*BTN, 64 },*/
{"BO", BO, "BOLIVIA"}, /*BOL, 68 },*/
{"BQ", BQ, "BONAIRE"}, /*BES, 535},*/
{"BA", BA, "BOSNIA AND HERZEGOVINA"}, /*BIH, 70 },*/
{"BW", BW, "BOTSWANA"}, /*BWA, 72 },*/
{"BV", BV, "BOUVET ISLAND"}, /*BVT, 74 },*/
{"BR", BR, "BRAZIL"}, /*BRA, 76 },*/
{"IO", IO, "BRITISH INDIAN OCEAN TERRITORY"}, /*IOT, 86 },*/
{"BN", BN, "BRUNEI DARUSSALAM"}, /*BRN, 96 },*/
{"BG", BG, "BULGARIA"}, /*BGR, 100},*/
{"BF", BF, "BURKINA FASO"}, /*BFA, 854},*/
{"BI", BI, "BURUNDI"}, /*BDI, 108},*/
{"KH", KH, "CAMBODIA"}, /*KHM, 116},*/
{"CM", CM, "CAMEROON"}, /*CMR, 120},*/
{"CA", CA, "CANADA"}, /*CAN, 124},*/
{"CV", CV, "CAPE VERDE"}, /*CPV, 132},*/
{"KY", KY, "CAYMAN ISLANDS"}, /*CYM, 136},*/
{"CF", CF, "CENTRAL AFRICAN REPUBLIC"}, /*CAF, 140},*/
{"TD", TD, "CHAD"}, /*TCD, 148},*/
{"CL", CL, "CHILE"}, /*CHL, 152},*/
{"CN", CN, "CHINA"}, /*CHN, 156},*/
{"CX", CX, "CHRISTMAS ISLAND"}, /*CXR, 162},*/
{"CC", CC, "COCOS (KEELING) ISLANDS"}, /*CCK, 166},*/
{"CO", CO, "COLOMBIA"}, /*COL, 170},*/
{"KM", KM, "COMOROS"}, /*COM, 174},*/
{"CG", CG, "CONGO"}, /*COG, 178},*/
{"CD", CD, "CONGO, THE DEMOCRATIC REPUBLIC OF THE"}, /*COD, 180},*/
{"CK", CK, "COOK ISLANDS"}, /*COK, 184},*/
{"CR", CR, "COSTA RICA"}, /*CRI, 188},*/
{"CI", CI, "CÔTE D'IVOIRE"}, /*CIV, 384},*/
{"HR", HR, "CROATIA"}, /*HRV, 191},*/
{"CU", CU, "CUBA"}, /*CUB, 192},*/
{"CW", CW, "CURAÇAO"}, /*CUW, 531},*/
{"CY", CY, "CYPRUS"}, /*CYP, 196},*/
{"CZ", CZ, "CZECH REPUBLIC"}, /*CZE, 203},*/
{"DK", DK, "DENMARK"}, /*DNK, 208},*/
{"DJ", DJ, "DJIBOUTI"}, /*DJI, 262},*/
{"DM", DM, "DOMINICA"}, /*DMA, 212},*/
{"DO", DO, "DOMINICAN REPUBLIC"}, /*DOM, 214},*/
{"EC", EC, "ECUADOR"}, /*ECU, 218},*/
{"EG", EG, "EGYPT"}, /*EGY, 818},*/
{"SV", SV, "EL SALVADOR"}, /*SLV, 222},*/
{"GQ", GQ, "EQUATORIAL GUINEA"}, /*GNQ, 226},*/
{"ER", ER, "ERITREA"}, /*ERI, 232},*/
{"EE", EE, "ESTONIA"}, /*EST, 233},*/
{"ET", ET, "ETHIOPIA"}, /*ETH, 231},*/
{"FK", FK, "FALKLAND ISLANDS (MALVINAS)"}, /*FLK, 238},*/
{"FO", FO, "FAROE ISLANDS"}, /*FRO, 234},*/
{"FJ", FJ, "FIJI"}, /*FJI, 242},*/
{"FI", FI, "FINLAND"}, /*FIN, 246},*/
{"FR", FR, "FRANCE"}, /*FRA, 250},*/
{"GF", GF, "FRENCH GUIANA"}, /*GUF, 254},*/
{"PF", PF, "FRENCH POLYNESIA"}, /*PYF, 258},*/
{"TF", TF, "FRENCH SOUTHERN TERRITORIES"}, /*ATF, 260},*/
{"GA", GA, "GABON"}, /*GAB, 266},*/
{"GM", GM, "GAMBIA"}, /*GMB, 270},*/
{"GE", GE, "GEORGIA"}, /*GEO, 268},*/
{"DE", DE, "GERMANY"}, /*DEU, 276},*/
{"GH", GH, "GHANA"}, /*GHA, 288},*/
{"GI", GI, "GIBRALTAR"}, /*GIB, 292},*/
{"GR", GR, "GREECE"}, /*GRC, 300},*/
{"GL", GL, "GREENLAND"}, /*GRL, 304},*/
{"GD", GD, "GRENADA"}, /*GRD, 308},*/
{"GP", GP, "GUADELOUPE"}, /*GLP, 312},*/
{"GU", GU, "GUAM"}, /*GUM, 316},*/
{"GT", GT, "GUATEMALA"}, /*GTM, 320},*/
{"GG", GG, "GUERNSEY"}, /*GGY, 831},*/
{"GN", GN, "GUINEA"}, /*GIN, 324},*/
{"GW", GW, "GUINEA-BISSAU"}, /*GNB, 624},*/
{"GY", GY, "GUYANA"}, /*GUY, 328},*/
{"HT", HT, "HAITI"}, /*HTI, 332},*/
{"HM", HM, "HEARD ISLAND AND MCDONALD ISLANDS"}, /*HMD, 334},*/
{"VA", VA, "HOLY SEE (VATICAN CITY STATE)"}, /*VAT, 336},*/
{"HN", HN, "HONDURAS"}, /*HND, 340},*/
{"HK", HK, "HONG KONG"}, /*HKG, 344},*/
{"HU", HU, "HUNGARY"}, /*HUN, 348},*/
{"IS", IS, "ICELAND"}, /*ISL, 352},*/
{"IN", IN, "INDIA"}, /*IND, 356},*/
{"ID", ID, "INDONESIA"}, /*IDN, 360},*/
{"IR", IR, "IRAN, ISLAMIC REPUBLIC OF"}, /*IRN, 364},*/
{"IQ", IQ, "IRAQ"}, /*IRQ, 368},*/
{"IE", IE, "IRELAND"}, /*IRL, 372},*/
{"IM", IM, "ISLE OF MAN"}, /*IMN, 833},*/
{"IL", IL, "ISRAEL"}, /*ISR, 376},*/
{"IT", IT, "ITALY"}, /*ITA, 380},*/
{"JM", JM, "JAMAICA"}, /*JAM, 388},*/
{"JP", JP, "JAPAN"}, /*JPN, 392},*/
{"JE", JE, "JERSEY"}, /*JEY, 832},*/
{"JO", JO, "JORDAN"}, /*JOR, 400},*/
{"KZ", KZ, "KAZAKHSTAN"}, /*KAZ, 398},*/
{"KE", KE, "KENYA"}, /*KEN, 404},*/
{"KI", KI, "KIRIBATI"}, /*KIR, 296},*/
{"KP", KP, "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF"}, /*PRK, 408},*/
{"KR", KR, "KOREA, REPUBLIC OF"}, /*KOR, 410},*/
{"KW", KW, "KUWAIT"}, /*KWT, 414},*/
{"KG", KG, "KYRGYZSTAN"}, /*KGZ, 417},*/
{"LA", LA, "LAO PEOPLE'S DEMOCRATIC REPUBLIC"}, /*LAO, 418},*/
{"LV", LV, "LATVIA"}, /*LVA, 428},*/
{"LB", LB, "LEBANON"}, /*LBN, 422},*/
{"LS", LS, "LESOTHO"}, /*LSO, 426},*/
{"LR", LR, "LIBERIA"}, /*LBR, 430},*/
{"LY", LY, "LIBYAN ARAB JAMAHIRIYA"}, /*LBY, 434},*/
{"LI", LI, "LIECHTENSTEIN"}, /*LIE, 438},*/
{"LT", LT, "LITHUANIA"}, /*LTU, 440},*/
{"LU", LU, "LUXEMBOURG"}, /*LUX, 442},*/
{"MO", MO, "MACAO"}, /*MAC, 446},*/
{"MK", MK, "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF"}, /*MKD, 807},*/
{"MG", MG, "MADAGASCAR"}, /*MDG, 450},*/
{"MW", MW, "MALAWI"}, /*MWI, 454},*/
{"MY", MY, "MALAYSIA"}, /*MYS, 458},*/
{"MV", MV, "MALDIVES"}, /*MDV, 462},*/
{"ML", ML, "MALI"}, /*MLI, 466},*/
{"MT", MT, "MALTA"}, /*MLT, 470},*/
{"MH", MH, "MARSHALL ISLANDS"}, /*MHL, 584},*/
{"MQ", MQ, "MARTINIQUE"}, /*MTQ, 474},*/
{"MR", MR, "MAURITANIA"}, /*MRT, 478},*/
{"MU", MU, "MAURITIUS"}, /*MUS, 480},*/
{"YT", YT, "MAYOTTE"}, /*MYT, 175},*/
{"MX", MX, "MEXICO"}, /*MEX, 484},*/
{"FM", FM, "MICRONESIA, FEDERATED STATES OF"}, /*FSM, 583},*/
{"MD", MD, "MOLDOVA"}, /*MDA, 498},*/
{"MC", MC, "MONACO"}, /*MCO, 492},*/
{"MN", MN, "MONGOLIA"}, /*MNG, 496},*/
{"ME", ME, "MONTENEGRO"}, /*MNE, 499},*/
{"MS", MS, "MONTSERRAT"}, /*MSR, 500},*/
{"MA", MA, "MOROCCO"}, /*MAR, 504},*/
{"MZ", MZ, "MOZAMBIQUE"}, /*MOZ, 508},*/
{"MM", MM, "MYANMAR"}, /*MMR, 104},*/
{"NA", NA, "NAMIBIA"}, /*NAM, 516},*/
{"NR", NR, "NAURU"}, /*NRU, 520},*/
{"NP", NP, "NEPAL"}, /*NPL, 524},*/
{"NL", NL, "NETHERLANDS"}, /*NLD, 528},*/
{"NC", NC, "NEW CALEDONIA"}, /*NCL, 540},*/
{"NZ", NZ, "NEW ZEALAND"}, /*NZL, 554},*/
{"NI", NI, "NICARAGUA"}, /*NIC, 558},*/
{"NE", NE, "NIGER"}, /*NER, 562},*/
{"NG", NG, "NIGERIA"}, /*NGA, 566},*/
{"NU", NU, "NIUE"}, /*NIU, 570},*/
{"NF", NF, "NORFOLK ISLAND"}, /*NFK, 574},*/
{"MP", MP, "NORTHERN MARIANA ISLANDS"}, /*MNP, 580},*/
{"NO", NO, "NORWAY"}, /*NOR, 578},*/
{"OM", OM, "OMAN"}, /*OMN, 512},*/
{"PK", PK, "PAKISTAN"}, /*PAK, 586},*/
{"PW", PW, "PALAU"}, /*PLW, 585},*/
{"PS", PS, "PALESTINIAN TERRITORY, OCCUPIED"}, /*PSE, 275},*/
{"PA", PA, "PANAMA"}, /*PAN, 591},*/
{"PG", PG, "PAPUA NEW GUINEA"}, /*PNG, 598},*/
{"PY", PY, "PARAGUAY"}, /*PRY, 600},*/
{"PE", PE, "PERU"}, /*PER, 604},*/
{"PH", PH, "PHILIPPINES"}, /*PHL, 608},*/
{"PN", PN, "PITCAIRN"}, /*PCN, 612},*/
{"PL", PL, "POLAND"}, /*POL, 616},*/
{"PT", PT, "PORTUGAL"}, /*PRT, 620},*/
{"PR", PR, "PUERTO RICO"}, /*PRI, 630},*/
{"QA", QA, "QATA"}, /*QAT, 634},*/
{"RE", RE, "RÉUNION"}, /*REU, 638},*/
{"RO", RO, "ROMANIA"}, /*ROU, 642},*/
{"RU", RU, "RUSSIAN FEDERATION"}, /*RUS, 643},*/
{"RW", RW, "RWANDA"}, /*RWA, 646},*/
{"BL", BL, "SAINT BARTHÉLEMY"}, /*BLM, 652},*/
{"SH", SH, "SAINT HELENA"}, /*SHN, 654},*/
{"KN", KN, "SAINT KITTS AND NEVIS"}, /*KNA, 659},*/
{"LC", LC, "SAINT LUCIA"}, /*LCA, 662},*/
{"MF", MF, "SAINT MARTIN"}, /*MAF, 663},*/
{"PM", PM, "SAINT PIERRE AND MIQUELON"}, /*SPM, 666},*/
{"VC", VC, "SAINT VINCENT AND THE GRENADINES"}, /*VCT, 670},*/
{"WS", WS, "SAMOA"}, /*WSM, 882},*/
{"SM", SM, "SAN MARINO"}, /*SMR, 674},*/
{"ST", ST, "SAO TOME AND PRINCIPE"}, /*STP, 678},*/
{"SA", SA, "SAUDI ARABIA"}, /*SAU, 682},*/
{"SN", SN, "SENEGAL"}, /*SEN, 686},*/
{"RS", RS, "SERBIA"}, /*SRB, 688},*/
{"SC", SC, "SEYCHELLES"}, /*SYC, 690},*/
{"SL", SL, "SIERRA LEONE"}, /*SLE, 694},*/
{"SX", SX, "SINT MAARTEN"}, /*SXM, 534},*/
{"SG", SG, "SINGAPORE"}, /*SGP, 702},*/
{"SK", SK, "SLOVAKIA"}, /*SVK, 703},*/
{"SI", SI, "SLOVENIA"}, /*SVN, 705},*/
{"SB", SB, "SOLOMON ISLANDS"}, /*SLB, 90 },*/
{"SO", SO, "SOMALIA"}, /*SOM, 706},*/
{"ZA", ZA, "SOUTH AFRICA"}, /*ZAF, 710},*/
{"GS", GS, "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS"}, /*SGS, 239},*/
{"ES", ES, "SPAIN"}, /*ESP, 724},*/
{"LK", LK, "SRI LANKA"}, /*LKA, 144},*/
{"SD", SD, "SUDAN"}, /*SDN, 736},*/
{"SR", SR, "SURINAME"}, /*SUR, 740},*/
{"SJ", SJ, "SVALBARD AND JAN MAYEN"}, /*SJM, 744},*/
{"SZ", SZ, "SWAZILAND"}, /*SWZ, 748},*/
{"SE", SE, "SWEDEN"}, /*SWE, 752},*/
{"CH", CH, "SWITZERLAND"}, /*CHE, 756},*/
{"SY", SY, "SYRIAN ARAB REPUBLIC"}, /*SYR, 760},*/
{"TW", TW, "TAIWAN"}, /*TWN, 158},*/
{"TJ", TJ, "TAJIKISTAN"}, /*TJK, 762},*/
{"TZ", TZ, "TANZANIA, UNITED REPUBLIC OF"}, /*TZA, 834},*/
{"TH", TH, "THAILAND"}, /*THA, 764},*/
{"TL", TL, "TIMOR-LESTE"}, /*TLS, 626},*/
{"TG", TG, "TOGO"}, /*TGO, 768},*/
{"TK", TK, "TOKELAU"}, /*TKL, 772},*/
{"TO", TO, "TONGA"}, /*TON, 776},*/
{"TT", TT, "TRINIDAD AND TOBAGO"}, /*TTO, 780},*/
{"TN", TN, "TUNISIA"}, /*TUN, 788},*/
{"TR", TR, "TURKEY"}, /*TUR, 792},*/
{"TM", TM, "TURKMENISTAN"}, /*TKM, 795},*/
{"TC", TC, "TURKS AND CAICOS ISLANDS"}, /*TCA, 796},*/
{"TV", TV, "TUVALU"}, /*TUV, 798},*/
{"UG", UG, "UGANDA"}, /*UGA, 800},*/
{"UA", UA, "UKRAINE"}, /*UKR, 804},*/
{"AE", AE, "UNITED ARAB EMIRATES"}, /*ARE, 784},*/
{"GB", GB, "UNITED KINGDOM"}, /*GBR, 826},*/
{"US", US, "UNITED STATES"}, /*USA, 840},*/
{"UM", UM, "UNITED STATES MINOR OUTLYING ISLANDS"}, /*UMI, 581},*/
{"UY", UY, "URUGUAY"}, /*URY, 858},*/
{"UZ", UZ, "UZBEKISTAN"}, /*UZB, 860},*/
{"VU", VU, "VANUATU"}, /*VUT, 548},*/
{"VE", VE, "VENEZUELA"}, /*VEN, 862},*/
{"VN", VN, "VIET NAM"}, /*VNM, 704},*/
{"VG", VG, "VIRGIN ISLANDS, BRITISH"}, /*VGB, 92 },*/
{"VI", VI, "VIRGIN ISLANDS, U.S."}, /*VIR, 850},*/
{"WF", WF, "WALLIS AND FUTUNA"}, /*WLF, 876},*/
{"EH", EH, "WESTERN SAHARA"}, /*ESH, 732},*/
{"YE", YE, "YEMEN"}, /*YEM, 887},*/
{"ZM", ZM, "ZAMBIA"}, /*ZMB, 894},*/
{"ZW", ZW, "ZIMBABWE"} /*ZWE, 716},*/
};
/* convert ISO 3166-1 two-letter constant
* to index number
*/
int txt_to_country(const char * id) {
unsigned int i;
for (i = 0; i < COUNTRY_COUNT(country_list); i++)
if (! strcasecmp(id,country_list[i].short_name))
return country_list[i].id;
return DE; // t2scan defaults to DVB-t de_DE
}
/* convert index number
* to ISO 3166-1 two-letter constant
*/
const char * country_to_short_name(int idx) {
unsigned int i;
for (i = 0; i < COUNTRY_COUNT(country_list); i++)
if (idx == country_list[i].id)
return country_list[i].short_name;
return "DE"; // t2scan defaults to DVB-t de_DE
}
/* convert index number
* to country name
*/
const char * country_to_full_name(int idx) {
unsigned int i;
for (i = 0; i < COUNTRY_COUNT(country_list); i++)
if (idx == country_list[i].id)
return country_list[i].full_name;
warning("COUNTRY CODE NOT DEFINED. PLEASE RE-CHECK WETHER YOU TYPED CORRECTLY.\n");
usleep(5000000);
return "GERMANY"; // t2scan defaults to DVB-t de_DE
}
void print_countries(void) {
unsigned int i;
for (i = 0; i < COUNTRY_COUNT(country_list); i++)
info("\t%s\t\t%s\n", country_list[i].short_name, country_list[i].full_name);
}
int country_count() {
return COUNTRY_COUNT(country_list);
}
#define MIN(X,Y) (X < Y ? X : Y)
int get_user_country(void) {
const int cats[] = { LC_CTYPE, LC_COLLATE, LC_MESSAGES };
char * buf, * pch, * pbuf;
unsigned cat, idx = 0xffff;
for (cat = 0; cat < sizeof(cats)/sizeof(cats[0]); cat++) {
// Note: program's locale is not changed here, since locale isn't given.
// the returned char * should be "C", "POSIX" or something valid.
// If valid, we can only *guess* which format is returned.
// Assume here something like "de_DE.iso8859-1@euro" or "de_DE.utf-8"
if (! (buf = setlocale(cats[cat], "")) || strlen(buf) < 2)
continue;
buf = strdup(buf);
pbuf= buf;
if (! strncmp(buf, "POSIX", MIN(strlen(buf), 5)) ||
! (strncmp(buf, "en", MIN(strlen(buf), 2)) && !isalpha(buf[2])) )
continue;
// assuming 'language_country.encoding@variant'
// country after '_', if given
if ((pch = strchr(buf, '_')))
pbuf = pch + 1;
// remove all after '@', including '@'
if ((pch = strchr(pbuf, '@')))
*pch = 0;
// remove all after '.', including '.'
if ((pch = strchr(pbuf, '.')))
*pch = 0;
if (strlen(pbuf) == 2) {
unsigned int i;
verbose("%s: lang id = %s\n", __FUNCTION__, pbuf);
for (i = 0; i < COUNTRY_COUNT(country_list); i++)
if (! strcasecmp(pbuf,country_list[i].short_name)) {
idx = country_list[i].id;
break;
}
}