Lines Matching refs:space
63 struct space {
81 static void Perror(struct space *space, const char *fmt, ...)
85 fprintf(stderr, "%s:%i: ", space->filename, space->linenum);
96 static void free_space(struct space *space)
98 struct pair *pair = space->pairs;
108 space->pairs = NULL;
109 if (space->ctl_value) {
110 snd_ctl_elem_value_free(space->ctl_value);
111 space->ctl_value = NULL;
113 if (space->ctl_info) {
114 snd_ctl_elem_info_free(space->ctl_info);
115 space->ctl_info = NULL;
117 if (space->ctl_id) {
118 snd_ctl_elem_id_free(space->ctl_id);
119 space->ctl_id = NULL;
121 if (space->ctl_card_info) {
122 snd_ctl_card_info_free(space->ctl_card_info);
123 space->ctl_card_info = NULL;
125 if (space->ctl_handle) {
126 snd_hctl_close(space->ctl_handle);
127 space->ctl_handle = NULL;
129 if (space->rootdir)
130 free(space->rootdir);
131 if (space->program_result)
132 free(space->program_result);
133 if (space->go_to)
134 free(space->go_to);
135 free(space);
138 static struct pair *value_find(struct space *space, const char *key)
140 struct pair *pair = space->pairs;
147 static int value_set(struct space *space, const char *key, const char *value)
151 pair = value_find(space, key);
172 pair->next = space->pairs;
173 space->pairs = pair;
178 static int init_space(struct space **space, int card)
180 struct space *res;
184 res = calloc(1, sizeof(struct space));
211 *space = res;
218 static const char *cardinfo_get(struct space *space, const char *attr)
222 sprintf(res, "%u", snd_ctl_card_info_get_card(space->ctl_card_info));
226 return snd_ctl_card_info_get_id(space->ctl_card_info);
228 return snd_ctl_card_info_get_driver(space->ctl_card_info);
230 return snd_ctl_card_info_get_name(space->ctl_card_info);
232 return snd_ctl_card_info_get_longname(space->ctl_card_info);
234 return snd_ctl_card_info_get_mixername(space->ctl_card_info);
236 return snd_ctl_card_info_get_components(space->ctl_card_info);
237 Perror(space, "unknown cardinfo{} attribute '%s'", attr);
241 static int check_id_changed(struct space *space, unsigned int what)
246 if ((space->ctl_id_changed & what & 1) != 0) {
247 snd_ctl_elem_id_set_numid(space->ctl_id, 0);
248 elem = snd_hctl_find_elem(space->ctl_handle, space->ctl_id);
251 err = snd_hctl_elem_info(elem, space->ctl_info);
253 space->ctl_id_changed &= ~1;
256 if ((space->ctl_id_changed & what & 2) != 0) {
257 snd_ctl_elem_id_set_numid(space->ctl_id, 0);
258 elem = snd_hctl_find_elem(space->ctl_handle, space->ctl_id);
261 err = snd_hctl_elem_read(elem, space->ctl_value);
263 space->ctl_id_changed &= ~2;
269 static const char *get_ctl_value(struct space *space)
278 type = snd_ctl_elem_info_get_type(space->ctl_info);
279 count = snd_ctl_elem_info_get_count(space->ctl_info);
286 strlcat(res, snd_ctl_elem_value_get_boolean(space->ctl_value, idx) ? "on" : "off", sizeof(res));
293 snprintf(tmp, sizeof(tmp), "%li", snd_ctl_elem_value_get_integer(space->ctl_value, idx));
301 snprintf(tmp, sizeof(tmp), "%lli", snd_ctl_elem_value_get_integer64(space->ctl_value, idx));
309 snprintf(tmp, sizeof(tmp), "%u", snd_ctl_elem_value_get_enumerated(space->ctl_value, idx));
320 pos1 = snd_ctl_elem_value_get_bytes(space->ctl_value);
330 Perror(space, "unknown element type '%i'", type);
340 static int set_ctl_value(struct space *space, const char *value, int all)
349 type = snd_ctl_elem_info_get_type(space->ctl_info);
350 count = snd_ctl_elem_info_get_count(space->ctl_info);
362 snd_ctl_elem_value_set_boolean(space->ctl_value, idx, val);
379 val = convert_prange1(strtol(value, NULL, 0), snd_ctl_elem_info_get_min(space->ctl_info), snd_ctl_elem_info_get_max(space->ctl_info));
380 snd_ctl_elem_value_set_integer(space->ctl_value, idx, val);
396 val = snd_ctl_convert_from_dB(snd_hctl_ctl(space->ctl_handle), space->ctl_id, val, &lval, -1);
401 snd_ctl_elem_value_set_integer(space->ctl_value, idx, lval);
403 snd_ctl_elem_value_set_integer(space->ctl_value, idx, strtol(value, NULL, 0));
414 snd_ctl_elem_value_set_integer64(space->ctl_value, idx, strtoll(value, NULL, 0));
427 snd_ctl_elem_value_set_enumerated(space->ctl_value, idx, strtol(value, NULL, 0));
432 items = snd_ctl_elem_info_get_items(space->ctl_info);
434 snd_ctl_elem_info_set_item(space->ctl_info, idx2);
435 elem = snd_hctl_find_elem(space->ctl_handle, space->ctl_id);
438 val = snd_hctl_elem_info(elem, space->ctl_info);
441 if (strcasecmp(snd_ctl_elem_info_get_item_name(space->ctl_info), value) == 0) {
442 snd_ctl_elem_value_set_enumerated(space->ctl_value, idx, idx2);
447 Perror(space, "wrong enum identifier '%s'", value);
463 Perror(space, "bad ctl value hexa length (should be %u bytes)", count);
470 Perror(space, "bad ctl hexa value");
474 snd_ctl_elem_value_set_byte(space->ctl_value, idx, val);
478 Perror(space, "unknown element type '%i'", type);
483 Perror(space, "missing some ctl values (line %i)", space->linenum);
527 static const char *elemid_get(struct space *space, const char *attr)
534 val = snd_ctl_elem_id_get_numid(space->ctl_id);
539 return snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(space->ctl_id));
541 val = snd_ctl_elem_id_get_device(space->ctl_id);
545 val = snd_ctl_elem_id_get_subdevice(space->ctl_id);
549 return snd_ctl_elem_id_get_name(space->ctl_id);
551 val = snd_ctl_elem_id_get_index(space->ctl_id);
555 if (check_id_changed(space, 1))
557 return snd_ctl_elem_type_name(snd_ctl_elem_info_get_type(space->ctl_info));
560 if (check_id_changed(space, 1))
563 if (snd_ctl_elem_info_is_readable(space->ctl_info))
565 if (snd_ctl_elem_info_is_writable(space->ctl_info))
567 if (snd_ctl_elem_info_is_volatile(space->ctl_info))
569 if (snd_ctl_elem_info_is_inactive(space->ctl_info))
571 if (snd_ctl_elem_info_is_locked(space->ctl_info))
573 if (snd_ctl_elem_info_is_tlv_readable(space->ctl_info))
575 if (snd_ctl_elem_info_is_tlv_writable(space->ctl_info))
577 if (snd_ctl_elem_info_is_tlv_commandable(space->ctl_info))
579 if (snd_ctl_elem_info_is_owner(space->ctl_info))
581 if (snd_ctl_elem_info_is_user(space->ctl_info))
586 if (check_id_changed(space, 1))
588 val = snd_ctl_elem_info_get_owner(space->ctl_info);
592 if (check_id_changed(space, 1))
594 val = snd_ctl_elem_info_get_count(space->ctl_info);
598 if (check_id_changed(space, 1))
600 type = snd_ctl_elem_info_get_type(space->ctl_info);
602 val = snd_ctl_elem_info_get_min64(space->ctl_info);
604 val = snd_ctl_elem_info_get_min(space->ctl_info);
610 if (check_id_changed(space, 1))
612 type = snd_ctl_elem_info_get_type(space->ctl_info);
614 val = snd_ctl_elem_info_get_max64(space->ctl_info);
616 val = snd_ctl_elem_info_get_max(space->ctl_info);
622 if (check_id_changed(space, 1))
624 type = snd_ctl_elem_info_get_type(space->ctl_info);
626 val = snd_ctl_elem_info_get_step64(space->ctl_info);
628 val = snd_ctl_elem_info_get_step(space->ctl_info);
634 if (check_id_changed(space, 1))
636 if (snd_ctl_elem_info_get_type(space->ctl_info) == SND_CTL_ELEM_TYPE_ENUMERATED)
637 val = snd_ctl_elem_info_get_items(space->ctl_info);
646 if (check_id_changed(space, 3))
648 return get_ctl_value(space);
652 if (check_id_changed(space, 1))
654 if (snd_ctl_get_dB_range(snd_hctl_ctl(space->ctl_handle), space->ctl_id, &min, &max) < 0)
663 if (check_id_changed(space, 1))
665 if (snd_ctl_get_dB_range(snd_hctl_ctl(space->ctl_handle), space->ctl_id, &min, &max) < 0)
673 if (check_id_changed(space, 1))
675 if (snd_ctl_elem_info_get_type(space->ctl_info) != SND_CTL_ELEM_TYPE_ENUMERATED)
677 items = snd_ctl_elem_info_get_items(space->ctl_info);
680 snd_ctl_elem_info_set_item(space->ctl_info, idx);
681 elem = snd_hctl_find_elem(space->ctl_handle, space->ctl_id);
684 if (snd_hctl_elem_info(elem, space->ctl_info) < 0)
686 strlcat(res, snd_ctl_elem_info_get_item_name(space->ctl_info), sizeof(res));
701 elem = snd_hctl_first_elem(space->ctl_handle);
704 if (!ctl_match(space->ctl_id, id))
711 snd_ctl_elem_id_copy(space->ctl_id, id);
729 elem = snd_hctl_first_elem(space->ctl_handle);
732 if (ctl_match(space->ctl_id, id))
741 Perror(space, "unknown ctl{} attribute '%s'", attr);
748 static int elemid_set(struct space *space, const char *attr, const char *value)
770 snd_ctl_elem_id_clear(space->ctl_id);
773 snd_ctl_elem_id_clear(space->ctl_id);
775 snd_ctl_elem_id_set_interface(space->ctl_id, -1);
776 snd_ctl_elem_id_set_device(space->ctl_id, -1);
777 snd_ctl_elem_id_set_subdevice(space->ctl_id, -1);
778 snd_ctl_elem_id_set_name(space->ctl_id, "*");
779 snd_ctl_elem_id_set_index(space->ctl_id, -1);
783 snd_ctl_elem_id_set_interface(space->ctl_id, iface);
784 space->ctl_id_changed = ~0;
788 Perror(space, "unknown control interface name '%s'", value);
800 snd_ctl_elem_id_set_name(space->ctl_id, value);
801 space->ctl_id_changed = ~0;
810 err = check_id_changed(space, 1);
812 Perror(space, "control element not found");
815 err = set_ctl_value(space, value, strncasecmp(attr, "values", 6) == 0);
817 space->ctl_id_changed |= 2;
819 space->ctl_id_changed &= ~2;
820 snd_ctl_elem_value_set_id(space->ctl_value, space->ctl_id);
821 err = snd_ctl_elem_write(snd_hctl_ctl(space->ctl_handle), space->ctl_value);
823 Perror(space, "value write error: %s", snd_strerror(err));
829 Perror(space, "unknown CTL{} attribute '%s'", attr);
833 fcn(space->ctl_id, val);
834 space->ctl_id_changed = ~0;
942 static char *get_key_attribute(struct space *space, char *str, char *res, size_t ressize)
952 Perror(space, "missing closing brace for format");
966 static char *get_format_attribute(struct space *space, char **str)
974 Perror(space, "missing closing brace for format");
986 static int get_format_len(struct space *space, char **str)
998 Perror(space, "format parsing error '%s'", *str);
1004 static void apply_format(struct space *space, char *string, size_t maxsize)
1075 len = get_format_len(space, &tail);
1089 attr = get_format_attribute(space, &tail);
1096 Perror(space, "missing identification parametr for cardinfo");
1098 const char *value = cardinfo_get(space, attr);
1107 Perror(space, "missing identification parametr for ctl");
1109 const char *value = elemid_get(space, attr);
1117 if (space->program_result == NULL)
1125 cpos = space->program_result;
1133 Perror(space, "requested part of result string not found");
1146 strlcat(string, space->program_result, maxsize);
1147 dbg("substitute result string '%s'", space->program_result);
1152 Perror(space, "missing file parameter for attr");
1157 pair = value_find(space, "sysfs_device");
1173 Perror(space, "%i untrusted character(s) replaced" , count);
1200 pair = value_find(space, attr);
1206 Perror(space, "unknown substitution type=%i", type);
1243 int run_program1(struct space *space,
1249 const char *res = elemid_get(space, "do_search");
1255 const char *res = elemid_get(space, "do_count");
1261 Perror(space, "unknown buildin command '%s'", command0);
1265 static int parse(struct space *space, const char *filename);
1288 static int parse_line(struct space *space, char *line, size_t linesize ATTRIBUTE_UNUSED)
1308 Perror(space, "invalid LABEL operation");
1311 if (space->go_to && strcmp(space->go_to, value) == 0) {
1312 free(space->go_to);
1313 space->go_to = NULL;
1318 if (space->go_to) {
1319 dbg("skip (GOTO '%s')", space->go_to);
1324 attr = get_key_attribute(space, key + 3, string, sizeof(string));
1326 Perror(space, "error parsing CTL attribute");
1331 apply_format(space, result, sizeof(result));
1333 err = elemid_set(space, attr, result);
1334 if (space->program_result) {
1335 free(space->program_result);
1336 space->program_result = NULL;
1339 space->program_result = strdup(string);
1341 if (space->program_result == NULL)
1346 apply_format(space, result, sizeof(result));
1348 err = elemid_set(space, "values", result);
1354 temp = (char *)elemid_get(space, attr);
1360 Perror(space, "invalid CTL{} operation");
1367 if (!do_match(key, op, value, space->program_result))
1370 if (space->program_result) {
1371 free(space->program_result);
1372 space->program_result = NULL;
1375 apply_format(space, string, sizeof(string));
1376 space->program_result = strdup(string);
1377 if (space->program_result == NULL)
1380 Perror(space, "invalid RESULT operation");
1389 apply_format(space, string, sizeof(string));
1390 if (space->program_result) {
1391 free(space->program_result);
1392 space->program_result = NULL;
1394 if (run_program(space, string, result, sizeof(result), NULL, space->log_run) != 0) {
1404 space->program_result = strdup(result);
1405 if (space->program_result == NULL)
1415 attr = get_key_attribute(space, key + 8, string, sizeof(string));
1417 Perror(space, "error parsing CARDINFO attribute");
1422 temp = (char *)cardinfo_get(space, attr);
1426 Perror(space, "invalid CARDINFO{} operation");
1432 attr = get_key_attribute(space, key + 4, string, sizeof(string));
1434 Perror(space, "error parsing ATTR attribute");
1438 pair = value_find(space, "sysfs_device");
1446 Perror(space, "invalid ATTR{} operation");
1452 attr = get_key_attribute(space, key + 3, string, sizeof(string));
1454 Perror(space, "error parsing ENV attribute");
1465 apply_format(space, result, sizeof(result));
1470 Perror(space, "invalid ENV{} operation");
1477 Perror(space, "invalid GOTO operation");
1480 space->go_to = strdup(value);
1481 if (space->go_to == NULL) {
1493 Perror(space, "invalid INCLUDE operation");
1499 strlcpy(string, space->rootdir, sizeof(string));
1503 rootdir = space->rootdir;
1504 go_to = space->go_to;
1505 filename = space->filename;
1506 linenum = space->linenum;
1508 Perror(space, "invalid filename '%s'", string);
1517 Perror(space, "invalid directory '%s'", string);
1525 space->go_to = NULL;
1526 space->rootdir = new_root_dir(string);
1528 if (space->rootdir) {
1529 err = parse(space, string);
1530 free(space->rootdir);
1533 if (space->go_to) {
1534 Perror(space, "unterminated GOTO '%s'", space->go_to);
1535 free(space->go_to);
1542 space->go_to = NULL;
1543 space->rootdir = new_root_dir(string);
1544 if (space->rootdir) {
1545 err = parse(space, string);
1546 free(space->rootdir);
1549 if (space->go_to) {
1550 Perror(space, "unterminated GOTO '%s'", space->go_to);
1551 free(space->go_to);
1554 space->go_to = go_to;
1555 space->rootdir = rootdir;
1556 space->filename = filename;
1557 space->linenum = linenum;
1558 if (space->quit)
1568 apply_format(space, string, sizeof(string));
1573 strlcpy(string, space->rootdir, sizeof(string));
1579 apply_format(space, string, sizeof(string));
1588 Perror(space, "invalid ACCESS operation");
1595 Perror(space, "invalid PRINT operation");
1599 apply_format(space, string, sizeof(string));
1605 Perror(space, "invalid ERROR operation");
1609 apply_format(space, string, sizeof(string));
1615 Perror(space, "invalid EXIT operation");
1619 apply_format(space, string, sizeof(string));
1622 space->exit_code = strtol(string, NULL, 0);
1623 space->quit = 1;
1627 attr = get_key_attribute(space, key + 6, string, sizeof(string));
1629 Perror(space, "error parsing CONFIG attribute");
1633 apply_format(space, result, sizeof(result));
1635 err = value_set(space, attr, result);
1639 pair = value_find(space, attr);
1645 Perror(space, "invalid CONFIG{} operation");
1650 Perror(space, "unknown key '%s'", key);
1655 Perror(space, "invalid rule");
1659 static int parse(struct space *space, const char *filename)
1683 space->filename = filename;
1684 while (!err && pos < bufsize && !space->quit) {
1730 space->linenum = linenum;
1731 err = parse_line(space, line, linesize);
1740 space->filename = NULL;
1741 space->linenum = -1;
1744 return err ? err : -abs(space->exit_code);
1749 struct space *space;
1767 err = init_space(&space, iter.card);
1770 space->rootdir = new_root_dir(filename);
1771 if (space->rootdir != NULL) {
1772 err = parse(space, filename);
1779 free_space(space);