version 1.19, 2008/06/26 05:42:20 |
version 1.20, 2009/11/12 07:32:26 |
|
|
const char *name; |
const char *name; |
void *valp; |
void *valp; |
int format; |
int format; |
|
u_int oldval; |
#define STRING 1 |
#define STRING 1 |
#define INT 2 |
#define INT 2 |
#define UINT 3 |
#define UINT 3 |
#define P_R 4 |
#define P_R 4 |
#define ULONG 5 |
|
#define UCHAR 6 |
#define UCHAR 6 |
#define ENC 7 |
#define ENC 7 |
#define PROPS 8 |
#define PROPS 8 |
|
|
} |
} |
|
|
void |
void |
prfield(struct field *p, const char *sep) |
prval(u_int format, void *valp) |
{ |
{ |
u_int v; |
u_int v; |
const char *cm; |
const char *cm; |
int i; |
int i; |
|
|
if (sep) |
switch (format) { |
fprintf(out, "%s%s", p->name, sep); |
|
switch (p->format) { |
|
case STRING: |
case STRING: |
fprintf(out, "%s", (char*)p->valp); |
fprintf(out, "%s", (char *)valp); |
break; |
break; |
case INT: |
case INT: |
fprintf(out, "%d", *(int*)p->valp); |
fprintf(out, "%d", *(int *)valp); |
break; |
break; |
case UINT: |
case UINT: |
fprintf(out, "%u", *(u_int*)p->valp); |
fprintf(out, "%u", *(u_int *)valp); |
break; |
break; |
case XINT: |
case XINT: |
fprintf(out, "0x%x", *(u_int*)p->valp); |
fprintf(out, "0x%x", *(u_int *)valp); |
break; |
break; |
case UCHAR: |
case UCHAR: |
fprintf(out, "%u", *(u_char*)p->valp); |
fprintf(out, "%u", *(u_char *)valp); |
break; |
break; |
case ULONG: |
|
fprintf(out, "%lu", *(u_long*)p->valp); |
|
break; |
|
case P_R: |
case P_R: |
v = *(u_int*)p->valp; |
v = *(u_int *)valp; |
cm = ""; |
cm = ""; |
if (v & AUMODE_PLAY) { |
if (v & AUMODE_PLAY) { |
if (v & AUMODE_PLAY_ALL) |
if (v & AUMODE_PLAY_ALL) |
|
|
fprintf(out, "%srecord", cm); |
fprintf(out, "%srecord", cm); |
break; |
break; |
case ENC: |
case ENC: |
v = *(u_int*)p->valp; |
v = *(u_int *)valp; |
for (i = 0; encs[i].ename; i++) |
for (i = 0; encs[i].ename; i++) |
if (encs[i].eno == v) |
if (encs[i].eno == v) |
break; |
break; |
|
|
fprintf(out, "%u", v); |
fprintf(out, "%u", v); |
break; |
break; |
case PROPS: |
case PROPS: |
v = *(u_int*)p->valp; |
v = *(u_int *)valp; |
for (cm = "", i = 0; props[i].name; i++) { |
for (cm = "", i = 0; props[i].name; i++) { |
if (v & props[i].prop) { |
if (v & props[i].prop) { |
fprintf(out, "%s%s", cm, props[i].name); |
fprintf(out, "%s%s", cm, props[i].name); |
|
|
} |
} |
|
|
void |
void |
|
prfield(struct field *p, const char *sep) |
|
{ |
|
if (sep) { |
|
fprintf(out, "%s", p->name); |
|
if (p->flags & SET) { |
|
fprintf(out, "%s", ": "); |
|
prval(p->format, &p->oldval); |
|
fprintf(out, " -> "); |
|
} else |
|
fprintf(out, "%s", sep); |
|
} |
|
prval(p->format, p->valp); |
|
fprintf(out, "\n"); |
|
} |
|
|
|
void |
rdfield(struct field *p, char *q) |
rdfield(struct field *p, char *q) |
{ |
{ |
int i; |
int i; |
|
|
|
|
switch (p->format) { |
switch (p->format) { |
case UINT: |
case UINT: |
if (sscanf(q, "%u", (unsigned int *)p->valp) != 1) |
p->oldval = *(u_int *)p->valp; |
|
if (sscanf(q, "%u", (unsigned int *)p->valp) != 1) { |
warnx("Bad number %s", q); |
warnx("Bad number %s", q); |
|
return; |
|
} |
break; |
break; |
case UCHAR: |
case UCHAR: |
if (sscanf(q, "%u", &u) != 1) |
*(char *)&p->oldval = *(u_char *)p->valp; |
|
if (sscanf(q, "%u", &u) != 1) { |
warnx("Bad number %s", q); |
warnx("Bad number %s", q); |
else |
return; |
*(u_char *)p->valp = u; |
} |
|
*(u_char *)p->valp = u; |
break; |
break; |
case XINT: |
case XINT: |
|
p->oldval = *(u_int *)p->valp; |
if (sscanf(q, "0x%x", (unsigned int *)p->valp) != 1 && |
if (sscanf(q, "0x%x", (unsigned int *)p->valp) != 1 && |
sscanf(q, "%x", (unsigned int *)p->valp) != 1) |
sscanf(q, "%x", (unsigned int *)p->valp) != 1) { |
warnx("Bad number %s", q); |
warnx("Bad number %s", q); |
|
return; |
|
} |
break; |
break; |
case ENC: |
case ENC: |
|
p->oldval = *(u_int *)p->valp; |
for (i = 0; encs[i].ename; i++) |
for (i = 0; encs[i].ename; i++) |
if (strcmp(encs[i].ename, q) == 0) |
if (strcmp(encs[i].ename, q) == 0) |
break; |
break; |
if (encs[i].ename) |
if (encs[i].ename) |
*(u_int*)p->valp = encs[i].eno; |
*(u_int*)p->valp = encs[i].eno; |
else |
else { |
warnx("Unknown encoding: %s", q); |
warnx("Unknown encoding: %s", q); |
|
return; |
|
} |
break; |
break; |
default: |
default: |
errx(1, "Invalid read format."); |
errx(1, "Invalid read format."); |
|
|
for (i = 0; fields[i].name; i++) { |
for (i = 0; fields[i].name; i++) { |
if (!(fields[i].flags & ALIAS)) { |
if (!(fields[i].flags & ALIAS)) { |
prfield(&fields[i], sep); |
prfield(&fields[i], sep); |
fprintf(out, "\n"); |
|
} |
} |
} |
} |
} else { |
} else { |
|
|
warnx("field %s does not exist", *argv); |
warnx("field %s does not exist", *argv); |
else { |
else { |
prfield(p, sep); |
prfield(p, sep); |
fprintf(out, "\n"); |
|
} |
} |
} |
} |
argv++; |
argv++; |
} |
} |
if (writeinfo && ioctl(fd, AUDIO_SETINFO, &info) < 0) |
if (writeinfo && ioctl(fd, AUDIO_SETINFO, &info) < 0) |
err(1, "set failed"); |
err(1, "set failed"); |
if (sep) { |
getinfo(fd); |
getinfo(fd); |
for (i = 0; fields[i].name; i++) { |
for (i = 0; fields[i].name; i++) { |
if (fields[i].flags & SET) { |
if (fields[i].flags & SET) { |
prfield(&fields[i], sep); |
fprintf(out, "%s: -> ", fields[i].name); |
|
prfield(&fields[i], 0); |
|
fprintf(out, "\n"); |
|
} |
|
} |
} |
} |
} |
} |
} |