use log_xxx() in opt.c, use simple list

This commit is contained in:
Alexandre Ratchov 2015-12-17 12:56:25 +01:00
parent 2009e44d9d
commit 44eae7129c
2 changed files with 21 additions and 21 deletions

View File

@ -14,8 +14,6 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dev.h"
@ -32,20 +30,27 @@ opt_new(char *name, struct dev *dev,
int pmin, int pmax, int rmin, int rmax,
int maxweight, int mmc, int dup, unsigned int mode)
{
struct opt *o, **po;
struct opt *o;
unsigned int len;
char c;
if (opt_byname(name, dev->num)) {
log_puts(name);
log_puts(": already defined\n");
return NULL;
}
for (len = 0; name[len] != '\0'; len++) {
if (len == OPT_NAMEMAX) {
fprintf(stderr, "%s: name too long\n", name);
exit(1);
log_puts(name);
log_puts(": too long\n");
return NULL;
}
c = name[len];
if ((c < 'a' || c > 'z') &&
(c < 'A' || c > 'Z')) {
fprintf(stderr, "%s: '%c' not allowed\n", name, c);
exit(1);
log_puts(name);
log_puts(": only alphabetic chars allowed\n");
return NULL;
}
}
o = xmalloc(sizeof(struct opt));
@ -63,15 +68,8 @@ opt_new(char *name, struct dev *dev,
o->mode = mode;
o->dev = dev;
memcpy(o->name, name, len + 1);
for (po = &opt_list; *po != NULL; po = &(*po)->next) {
if (o->dev->num == (*po)->dev->num &&
strcmp(o->name, (*po)->name) == 0) {
fprintf(stderr, "%s: already defined\n", o->name);
exit(1);
}
}
o->next = NULL;
*po = o;
o->next = opt_list;
opt_list = o;
if (log_level >= 2) {
dev_log(o->dev);
log_puts(".");

View File

@ -326,7 +326,7 @@ mkopt(char *path, struct dev *d,
o = opt_new(path, d, pmin, pmax, rmin, rmax,
MIDI_TO_ADATA(vol), mmc, dup, mode);
if (o == NULL)
errx(1, "%s: couldn't create subdev", path);
return NULL;
dev_adjpar(d, o->mode, o->pmin, o->pmax, o->rmin, o->rmax);
return o;
}
@ -426,8 +426,9 @@ main(int argc, char **argv)
d = mkdev(DEFAULT_DEV, &par, 0, bufsz, round,
rate, hold, autovol);
}
mkopt(optarg, d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup);
if (mkopt(optarg, d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup) == NULL)
return 1;
break;
case 'q':
mkport(optarg, hold);
@ -478,8 +479,9 @@ main(int argc, char **argv)
for (d = dev_list; d != NULL; d = d->next) {
if (opt_byname("default", d->num))
continue;
mkopt("default", d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup);
if (mkopt("default", d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup) == NULL)
return 1;
}
getbasepath(base, sizeof(base));
snprintf(path, SOCKPATH_MAX, "%s/" SOCKPATH_FILE "%u", base, unit);