Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
zones2indications.c File Reference

print libtonozone data as Asterisk indications.conf More...

#include <stdio.h>
#include <stdlib.h>
#include <dahdi/tonezone.h>
#include <unistd.h>
Include dependency graph for zones2indications.c:

Go to the source code of this file.

Macros

#define PROGRAM   "zones2indication"
 

Functions

int main (int argc, char *argv[])
 
int print_all ()
 
void print_indications (struct ind_tone_zone *zone_data)
 
void print_tone_zone_sound (struct ind_tone_zone *zone_data, const char *name, int toneid)
 
int print_zone_by_country (char *country)
 
int print_zone_by_id (int zone_num)
 
void usage ()
 

Detailed Description

print libtonozone data as Asterisk indications.conf

Definition in file zones2indications.c.

Macro Definition Documentation

◆ PROGRAM

#define PROGRAM   "zones2indication"

Definition at line 28 of file zones2indications.c.

Referenced by usage().

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 120 of file zones2indications.c.

References NULL, print_all(), print_zone_by_country(), print_zone_by_id(), and usage().

120  {
121  int country_code = -1;
122  int opt_print_all = 0;
123  int opt;
124  char* endptr = NULL;
125 
126  while((opt = getopt(argc, argv, "ac:hn:")) != -1) {
127  switch(opt) {
128  case 'a':
129  return print_all();
130  case 'c':
131  return print_zone_by_country(optarg);
132  case 'h':
133  usage();
134  return 0;
135  case 'n':
136  printf("number is %s.\n", optarg);
137  country_code = strtol(optarg, &endptr, 10);
138  return print_zone_by_id(country_code);
139  /* FIXME: what if this is not a number?
140  if (endptr != NULL) {
141  fprintf(stderr, "Error: Invalid country code %s, %d.\n",optarg, country_code);
142  usage();
143  exit(1);
144  }
145  */
146  break;
147  }
148  }
149 
150  /* If we got here, the user selected no option */
151  usage();
152  return 2;
153 }
int print_all()
#define NULL
Definition: resample.c:96
void usage()
int print_zone_by_country(char *country)
int print_zone_by_id(int zone_num)

◆ print_all()

int print_all ( )

Definition at line 98 of file zones2indications.c.

References print_zone_by_id().

Referenced by main().

98  {
99  int i;
100  /* loop over all possible zones */
101  for (i=0; ; i++) {
102  if (print_zone_by_id(i))
103  break;
104  }
105  return 0;
106 }
int print_zone_by_id(int zone_num)

◆ print_indications()

void print_indications ( struct ind_tone_zone *  zone_data)

Definition at line 41 of file zones2indications.c.

References print_tone_zone_sound().

Referenced by print_zone_by_country(), and print_zone_by_id().

41  {
42  int i;
43 
44  printf (
45  "[%s]\n"
46  "; Source: libtonezone.\n"
47  "description = %s\n"
48  "\n",
49  zone_data->country, zone_data->description
50  );
51 
52  printf(
53  "ringcadence = "
54  );
55  for(i=0; ; i++) {
56  if (zone_data->ringcadence[i] == 0)
57  break;
58  if (i != 0)
59  putchar(',');
60  printf("%d",zone_data->ringcadence[i]);
61  }
62  putchar('\n');
63 
64  print_tone_zone_sound(zone_data, "dial", DAHDI_TONE_DIALTONE);
65  print_tone_zone_sound(zone_data, "busy", DAHDI_TONE_BUSY);
66  print_tone_zone_sound(zone_data, "ring", DAHDI_TONE_RINGTONE);
67  print_tone_zone_sound(zone_data, "congestion", DAHDI_TONE_CONGESTION);
68  print_tone_zone_sound(zone_data, "callwaiting", DAHDI_TONE_CALLWAIT);
69  print_tone_zone_sound(zone_data, "dialrecall", DAHDI_TONE_DIALRECALL);
70  print_tone_zone_sound(zone_data, "record", DAHDI_TONE_RECORDTONE);
71  print_tone_zone_sound(zone_data, "info", DAHDI_TONE_INFO);
72  print_tone_zone_sound(zone_data, "stutter", DAHDI_TONE_STUTTER);
73  printf("\n\n");
74 }
void print_tone_zone_sound(struct ind_tone_zone *zone_data, const char *name, int toneid)

◆ print_tone_zone_sound()

void print_tone_zone_sound ( struct ind_tone_zone *  zone_data,
const char *  name,
int  toneid 
)

Definition at line 30 of file zones2indications.c.

Referenced by print_indications().

31  {
32  int i;
33  for (i=0; i<DAHDI_TONE_MAX; i++) {
34  if (zone_data->tones[i].toneid == toneid){
35  printf("%s = %s\n", name, zone_data->tones[i].data);
36  break;
37  }
38  }
39 }
static const char name[]
Definition: cdr_mysql.c:74

◆ print_zone_by_country()

int print_zone_by_country ( char *  country)

Definition at line 87 of file zones2indications.c.

References NULL, and print_indications().

Referenced by main().

87  {
88  struct tone_zone *zone_data = tone_zone_find(country);
89 
90  if (zone_data == NULL)
91  return 1;
92 
93  print_indications(zone_data);
94 
95  return 0;
96 }
#define NULL
Definition: resample.c:96
static char country[80]
Definition: pbx_dundi.c:205
void print_indications(struct ind_tone_zone *zone_data)

◆ print_zone_by_id()

int print_zone_by_id ( int  zone_num)

Definition at line 76 of file zones2indications.c.

References NULL, and print_indications().

Referenced by main(), and print_all().

76  {
77  struct tone_zone *zone_data = tone_zone_find_by_num(zone_num);
78 
79  if (zone_data == NULL)
80  return 1;
81 
82  print_indications(zone_data);
83 
84  return 0;
85 }
#define NULL
Definition: resample.c:96
void print_indications(struct ind_tone_zone *zone_data)

◆ usage()

void usage ( void  )

Definition at line 108 of file zones2indications.c.

References PROGRAM.

Referenced by main().

108  {
109  fprintf(stderr,
110  PROGRAM ": print libtonozone data as Asterisk indications.conf\n"
111  "\n"
112  "Usage:\n"
113  " " PROGRAM " -a Print all countries\n"
114  " " PROGRAM " -c <code> Select country by two-letter country code\n"
115  " " PROGRAM " -n <num> Select country by its internal libtonezone number\n"
116  " " PROGRAM " -h Print this text.\n"
117  );
118 }
#define PROGRAM