- size_t len;
- struct osl_object obj;
- struct osl_row *row;
-
- for (p = query->data; p < (char *)query->data + query->size; p += len + 1) {
- char c;
-
- len = strlen(p);
- if (!*p)
- return -E_ATTR_SYNTAX;
- c = p[len - 1];
- if (c != '+' && c != '-')
- break;
- p[len - 1] = '\0';
- obj.data = p;
- obj.size = len + 1;
- ret = osl_get_row(attribute_table, ATTCOL_NAME, &obj, &row);
- if (ret < 0)
- return ret;
- ret = osl_get_object(attribute_table, row, ATTCOL_BITNUM,
- &obj);
- if (ret < 0)
- return ret;
- if (c == '+')
- add_mask |= (1UL << *(unsigned char *)obj.data);
- else
- del_mask |= (1UL << *(unsigned char *)obj.data);
- }
- if (!add_mask && !del_mask)
- return -E_ATTR_SYNTAX;
- PARA_DEBUG_LOG("masks: %llx:%llx\n",(long long unsigned)add_mask,
- (long long unsigned)del_mask);
- for (; p < (char *)query->data + query->size; p += len + 1) { /* TODO: fnmatch */
- struct afs_info old_afsi, new_afsi;
- struct osl_row *aft_row;
-
- len = strlen(p);
- ret = aft_get_row_of_path(p, &aft_row);
- if (ret < 0)
- return ret;
- ret = get_afsi_object_of_row(p, &obj);
- if (ret < 0)
- return ret;
- ret = load_afsi(&old_afsi, &obj);
- if (ret < 0)
- return ret;
- new_afsi = old_afsi;
- new_afsi.attributes |= add_mask;
- new_afsi.attributes &= ~del_mask;
- save_afsi(&new_afsi, &obj); /* in-place update */
- ret = mood_update_audio_file(aft_row, &old_afsi);
- if (ret < 0)
- return ret;
- }
- return 1;
+ struct pattern_match_data pmd = {
+ .table = attribute_table,
+ .loop_col_num = ATTCOL_NAME,
+ .match_col_num = ATTCOL_NAME,
+ .pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING,
+ .data = aca,
+ .action = print_attribute
+ };
+
+ ret = lls(lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr));
+ assert(ret >= 0);
+ pmd.lpr = aca->lpr;
+ i_given = SERVER_CMD_OPT_GIVEN(LSATT, ID_SORT, aca->lpr);
+ r_given = SERVER_CMD_OPT_GIVEN(LSATT, REVERSE, aca->lpr);
+
+ if (i_given)
+ pmd.loop_col_num = ATTCOL_BITNUM;
+ if (r_given)
+ pmd.pm_flags |= PM_REVERSE_LOOP;
+ ret = for_each_matching_row(&pmd);
+ if (ret < 0)
+ goto out;
+ if (pmd.num_matches == 0)
+ ret = -E_NO_MATCH;
+out:
+ lls_free_parse_result(aca->lpr, cmd);
+ return ret;