diff --git a/dahdi_cfg.c b/dahdi_cfg.c index f8ae052..cb23ae9 100644 --- a/dahdi_cfg.c +++ b/dahdi_cfg.c @@ -85,6 +85,13 @@ static struct dahdi_lineconfig lc[DAHDI_MAX_SPANS]; static struct dahdi_chanconfig cc[DAHDI_MAX_CHANNELS]; +static int current_span = 0; +static int only_span = 0; +static int restrict_channels = 0; +static int selected_channels[DAHDI_MAX_CHANNELS]; +static int chan2span[DAHDI_MAX_CHANNELS]; +static int declared_spans[DAHDI_MAX_SPANS]; + static struct dahdi_attach_echocan ae[DAHDI_MAX_CHANNELS]; static struct dahdi_dynamic_span zds[NUM_DYNAMIC]; @@ -228,6 +235,35 @@ static char *trim(char *buf) return buf; } +static int skip_channel(int x) +{ + int spanno = chan2span[x]; + + if (restrict_channels) { + if (!selected_channels[x]) + return 1; + /* sanity check */ + if (only_span) { + if (spanno != 0 && only_span != spanno) { + fprintf(stderr, + "Only span %d. Skip selected channel %d from span %d\n", + only_span, x, spanno); + return 1; + } + } + } else { + if (only_span && !declared_spans[only_span]) { + fprintf(stderr, + "Error: analog span %d given to '-S', without '-C' restriction.\n", + only_span); + exit(1); + } + if (only_span && only_span != spanno) + return 1; + } + return 0; +} + static int parseargs(char *input, char *output[], int maxargs, char sep) { char *c; @@ -311,6 +347,8 @@ int spanconfig(char *keyword, char *args) error("Span number should be a valid span number, not '%s'\n", realargs[0]); return -1; } + current_span = span; + declared_spans[span] = 1; res = sscanf(realargs[1], "%d", &timing); if ((res != 1) || (timing < 0) || (timing > MAX_TIMING)) { error("Timing should be a number from 0 to %d, not '%s'\n", @@ -482,6 +520,7 @@ static int chanconfig(char *keyword, char *args) int master=0; int dacschan = 0; char *idle; + int is_digital; bzero(chans, sizeof(chans)); strtok(args, ":"); idle = strtok(NULL, ":"); @@ -493,6 +532,7 @@ static int chanconfig(char *keyword, char *args) if (res <= 0) return -1; for (x=1;x 1) { printf("\nChannel map:\n\n"); for (x=1;x -- Only configure specified channels\n" + " -S -- Only configure specified span\n" " -v -- Verbose (more -v's means more verbose)\n" ,c); exit(exitcode); } +static int chan_restrict(char *str) +{ + if (apply_channels(selected_channels, str) < 0) + return 0; + restrict_channels = 1; + return 1; +} + +static int span_restrict(char *str) +{ + long spanno; + char *endptr; + + spanno = strtol(str, &endptr, 10); + if (endptr == str) { + fprintf(stderr, "Missing valid span number after '-S'\n"); + return 0; + } + if (*endptr != '\0') { + fprintf(stderr, "Extra garbage after span number in '-S'\n"); + return 0; + } + only_span = spanno; + return 1; +} + int main(int argc, char *argv[]) { int c; @@ -1373,7 +1464,7 @@ int main(int argc, char *argv[]) char *key, *value; int x,found; - while((c = getopt(argc, argv, "fthc:vsd::")) != -1) { + while((c = getopt(argc, argv, "fthc:vsd::C:S:")) != -1) { switch(c) { case 'c': filename=optarg; @@ -1396,6 +1487,14 @@ int main(int argc, char *argv[]) case 's': stopmode = 1; break; + case 'C': + if (!chan_restrict(optarg)) + usage(argv[0], 1); + break; + case 'S': + if (!span_restrict(optarg)) + usage(argv[0], 1); + break; case 'd': if (optarg) debug = atoi(optarg); @@ -1478,6 +1577,8 @@ finish: } if (stopmode) { for (x=0;x