2 * zones2indications: print libtonozone data as Asterisk indications.conf
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * Author: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
26 #define PROGRAM "zones2indication"
28 void print_tone_zone_sound(struct tone_zone *zone_data, const char* name,
31 for (i=0; i<ZT_TONE_MAX; i++) {
32 if (zone_data->tones[i].toneid == toneid){
33 printf("%s = %s\n", name, zone_data->tones[i].data);
39 void print_indications(struct tone_zone *zone_data) {
44 "; Source: libtonezone.\n"
47 zone_data->country, zone_data->description
54 if (zone_data->ringcadence[i] == 0)
58 printf("%d",zone_data->ringcadence[i]);
62 print_tone_zone_sound(zone_data, "dial", ZT_TONE_DIALTONE);
63 print_tone_zone_sound(zone_data, "busy", ZT_TONE_BUSY);
64 print_tone_zone_sound(zone_data, "ring", ZT_TONE_RINGTONE);
65 print_tone_zone_sound(zone_data, "congestion", ZT_TONE_CONGESTION);
66 print_tone_zone_sound(zone_data, "callwaiting", ZT_TONE_CALLWAIT);
67 print_tone_zone_sound(zone_data, "dialrecall", ZT_TONE_DIALRECALL);
68 print_tone_zone_sound(zone_data, "record", ZT_TONE_RECORDTONE);
69 print_tone_zone_sound(zone_data, "info", ZT_TONE_INFO);
70 print_tone_zone_sound(zone_data, "stutter", ZT_TONE_STUTTER);
74 int print_zone_by_id(int zone_num) {
75 struct tone_zone *zone_data = tone_zone_find_by_num(zone_num);
77 if (zone_data == NULL)
80 print_indications(zone_data);
85 int print_zone_by_country(char* country) {
86 struct tone_zone *zone_data = tone_zone_find(country);
88 if (zone_data == NULL)
91 print_indications(zone_data);
98 /* loop over all possible zones */
100 if (print_zone_by_id(i))
108 PROGRAM ": print libtonozone data as Asterisk indications.conf\n"
111 " " PROGRAM " -a Print all countries\n"
112 " " PROGRAM " -c <code> Select country by two-letter country code\n"
113 " " PROGRAM " -n <num> Select country by its internal libtonezone number\n"
114 " " PROGRAM " -h Print this text.\n"
118 int main(int argc, char* argv[]){
119 int country_code = -1;
120 int opt_print_all = 0;
124 while((opt = getopt(argc, argv, "ac:hn:")) != -1) {
129 return print_zone_by_country(optarg);
134 printf("number is %s.\n", optarg);
135 country_code = strtol(optarg, &endptr, 10);
136 return print_zone_by_id(country_code);
137 /* FIXME: what if this is not a number?
138 if (endptr != NULL) {
139 fprintf(stderr, "Error: Invalid country code %s, %d.\n",optarg, country_code);
148 /* If we got here, the user selected no option */