sndiod: Use chronological order for {dev,port}_list

This commit is contained in:
Alexandre Ratchov 2021-03-08 10:25:31 +01:00
parent d6a1624f29
commit 1649f75532
3 changed files with 26 additions and 19 deletions

View File

@ -917,7 +917,7 @@ dev_new(char *path, struct aparams *par,
unsigned int mode, unsigned int bufsz, unsigned int round,
unsigned int rate, unsigned int hold, unsigned int autovol)
{
struct dev *d;
struct dev *d, **pd;
if (dev_sndnum == DEV_NMAX) {
if (log_level >= 1)
@ -944,8 +944,10 @@ dev_new(char *path, struct aparams *par,
d->master = MIDI_MAXCTL;
d->master_enabled = 0;
snprintf(d->name, CTL_NAMEMAX, "%u", d->num);
d->next = dev_list;
dev_list = d;
for (pd = &dev_list; *pd != NULL; pd = &(*pd)->next)
;
d->next = *pd;
*pd = d;
return d;
}

View File

@ -483,7 +483,7 @@ port_exit(void *arg)
struct port *
port_new(char *path, unsigned int mode, int hold)
{
struct port *c;
struct port *c, **pc;
c = xmalloc(sizeof(struct port));
c->path_list = NULL;
@ -492,8 +492,10 @@ port_new(char *path, unsigned int mode, int hold)
c->hold = hold;
c->midi = midi_new(&port_midiops, c, mode);
c->num = midi_portnum++;
c->next = port_list;
port_list = c;
for (pc = &port_list; *pc != NULL; pc = &(*pc)->next)
;
c->next = *pc;
*pc = c;
return c;
}

View File

@ -366,7 +366,7 @@ mkopt(char *path, struct dev *d,
int
main(int argc, char **argv)
{
int c, i, background, unit, devindex;
int c, i, background, unit;
int pmin, pmax, rmin, rmax;
char base[SOCKPATH_MAX], path[SOCKPATH_MAX];
unsigned int mode, dup, mmc, vol;
@ -404,7 +404,8 @@ main(int argc, char **argv)
aparams_init(&par);
mode = MODE_PLAY | MODE_REC;
tcpaddr_list = NULL;
devindex = 0;
d = NULL;
p = NULL;
slot_array_init();
@ -455,21 +456,24 @@ main(int argc, char **argv)
errx(1, "%s: volume is %s", optarg, str);
break;
case 's':
if ((d = dev_list) == NULL) {
d = mkdev(default_devs[devindex++], &par, 0,
bufsz, round, rate, hold, autovol);
if (d == NULL) {
for (i = 0; default_devs[i] != NULL; i++) {
mkdev(default_devs[i], &par, 0,
bufsz, round, rate, 0, autovol);
}
d = dev_list;
}
if (mkopt(optarg, d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup) == NULL)
return 1;
break;
case 'q':
mkport(optarg, hold);
p = mkport(optarg, hold);
break;
case 'Q':
if (port_list == NULL)
if (p == NULL)
errx(1, "-Q %s: no ports defined", optarg);
namelist_add(&port_list->path_list, optarg);
namelist_add(&p->path_list, optarg);
break;
case 'a':
hold = opt_onoff();
@ -488,12 +492,11 @@ main(int argc, char **argv)
errx(1, "%s: block size is %s", optarg, str);
break;
case 'f':
mkdev(optarg, &par, 0, bufsz, round,
d = mkdev(optarg, &par, 0, bufsz, round,
rate, hold, autovol);
devindex = -1;
break;
case 'F':
if ((d = dev_list) == NULL)
if (d == NULL)
errx(1, "-F %s: no devices defined", optarg);
if (!dev_addname(d, optarg))
exit(1);
@ -513,8 +516,8 @@ main(int argc, char **argv)
for (i = 0; default_ports[i] != NULL; i++)
mkport(default_ports[i], 0);
}
if (devindex != -1) {
for (i = devindex; default_devs[i] != NULL; i++) {
if (dev_list == NULL) {
for (i = 0; default_devs[i] != NULL; i++) {
mkdev(default_devs[i], &par, 0,
bufsz, round, rate, 0, autovol);
}