This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.
Peter Stuge peter at stuge.seIvan Kluchnikov wrote:
> > Ivan Kluchnikov wrote:
> > > This is new version of patch for review and merge:
> > >
> > > - more user-friendly interface for command:
> > > rach access-control-class 2 barred
> > > rach access-control-class 11 allowed
> >
> > Yes, much better than before, but perhaps spend the half hour it
> > takes to write that %d-%d parser using sscanf?
>
> You are welcome :)
> If you implement %d-%d parser, I will change style of this VTY command.
Here you go.
//Peter
-------------- next part --------------
#include <stdio.h>
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif /* MIN */
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif /* MAX */
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof (a) / sizeof (a)[0])
#endif /* ARRAY_SIZE */
int main(int argc,const char *argv[]) {
int i,val[16];
int a,b,n1,n2;
const char *p;
if(argc<2) {
fprintf(stderr,"usage: %s int[-int][,...]\n",*argv);
return 1;
}
for(i=0;i<ARRAY_SIZE(val);i++)
val[i]=0;
p = argv[1];
do {
switch (sscanf(p, "%d%n-%d%n", &a, &n1, &b, &n2)) {
case 0:
fprintf(stderr, "invalid input\n");
return 2;
case -1:
perror("sscanf");
return 3;
case 1:
if (a < ARRAY_SIZE(val))
val[a] = 1;
p += n1;
break;
case 2:
b = MIN(MAX(a, b), ARRAY_SIZE(val));
for (i = MIN(a, b); i <= b; i++)
val[i] = 1;
p += n2;
break;
}
if (',' == *p)
p++;
} while (*p);
for (i = 0; i < ARRAY_SIZE(val); i++)
printf("val[%d]=%d\n", i, val[i]);
return 0;
}