return;
}
sz = PARA_MIN(((size_t)afhi->chunks_total + 1) * 4, ct->size) + 1;
- afhi->chunk_table = para_malloc(sz);
+ afhi->chunk_table = alloc(sz);
for (i = 0; i <= afhi->chunks_total && i * 4 + 3 < ct->size; i++)
afhi->chunk_table[i] = read_u32(ct->data + 4 * i);
}
static void write_filename_items(struct para_buffer *b, const char *path,
bool basename)
{
- char *val;
+ const char *slash;
if (basename) {
WRITE_STATUS_ITEM(b, SI_basename, "%s\n", path);
return;
}
WRITE_STATUS_ITEM(b, SI_path, "%s\n", path);
- val = para_basename(path);
- WRITE_STATUS_ITEM(b, SI_basename, "%s\n", val? val : "");
- val = para_dirname(path);
- WRITE_STATUS_ITEM(b, SI_directory, "%s\n", val? val : "");
- free(val);
+ slash = strrchr(path, '/');
+ WRITE_STATUS_ITEM(b, SI_basename, "%s\n", slash? slash + 1 : path);
+ WRITE_STATUS_ITEM(b, SI_directory, "%.*s\n",
+ slash? (int)(slash - path) : (int)strlen(path), path);
}
static int print_chunk_table(struct ls_data *d, struct para_buffer *b)
goto out;
}
if (opts->mode == LS_MODE_MBOX) {
- const char *bn = para_basename(d->path);
+ const char *slash = strrchr(d->path, '/');
para_printf(b,
"From foo@localhost %s\n"
"Received: from\nTo: bar\nFrom: a\n"
"Subject: %s\n\n",
last_played_time,
- bn? bn : "?");
+ slash? slash + 1 : "?");
}
write_filename_items(b, d->path, lls_opt_given(r_b));
if (lls_opt_given(r_a))
if (ret < 0)
return ret;
if (!d->hash)
- d->hash = para_malloc(HASH_SIZE);
+ d->hash = alloc(HASH_SIZE);
memcpy(d->hash, tmp_hash, HASH_SIZE);
free(d->path);
ret = get_audio_file_path_of_row(current_aft_row, &d->path);
int (*compar)(const void *, const void *);
int i;
- options->data_ptr = para_malloc(nmemb * sizeof(*options->data_ptr));
+ options->data_ptr = arr_alloc(nmemb, sizeof(*options->data_ptr));
for (i = 0; i < nmemb; i++)
options->data_ptr[i] = options->data + i;
if (options->num_matching_paths > options->array_size) {
options->array_size++;
options->array_size *= 2;
- options->data = para_realloc(options->data, options->array_size
- * sizeof(*options->data));
+ options->data = arr_realloc(options->data, options->array_size,
+ sizeof(*options->data));
}
d = options->data + tmp;
ret = get_afsi_of_row(aft_row, &d->afsi);
aca->pbout.flags = (opts->mode == LS_MODE_PARSER)? PBF_SIZE_PREFIX : 0;
if (admissible_only(opts))
- ret = admissible_file_loop(opts, prepare_ls_row);
+ ret = score_loop(prepare_ls_row, opts);
else
ret = osl(osl_rbtree_loop(audio_file_table, AFTCOL_PATH, opts,
prepare_ls_row));
ret = lls_serialize_parse_result(lpr, cmd, NULL, &query.size);
assert(ret >= 0);
query.size += sizeof(*opts);
- query.data = para_malloc(query.size);
+ query.data = alloc(query.size);
opts = query.data;
memset(opts, 0, sizeof(*opts));
slpr = query.data + sizeof(*opts);
else if (!strcmp(val, "p") || !strcmp(val, "parser-friendly"))
opts->mode = LS_MODE_PARSER;
else {
- ret = -E_AFT_SYNTAX;
+ ret = -ERRNO_TO_PARA_ERROR(EINVAL);
goto out;
}
}
else if (!strcmp(val, "h") || !strcmp(val, "hash"))
opts->sorting = LS_SORT_BY_HASH;
else {
- ret = -E_AFT_SYNTAX;
+ ret = -ERRNO_TO_PARA_ERROR(EINVAL);
goto out;
}
}
size_t afhi_size = sizeof_afhi_buf(afhi);
size_t size = CAB_PATH_OFFSET + path_len + afhi_size
+ sizeof_chunk_table(afhi) + slpr_size;
- char *buf = para_malloc(size);
+ char *buf = alloc(size);
uint32_t pos;
assert(size <= ~(uint32_t)0);
ret = afs_event(AUDIO_FILE_ADD, &aca->pbout, aft_row);
out:
if (ret < 0)
- para_printf(&aca->pbout, "could not add %s\n", path);
+ afs_error(aca, "could not add %s\n", path);
lls_free_parse_result(aca->lpr, cmd);
return ret;
}
ret = get_afsi_object_of_row(row, &obj);
if (ret < 0) {
- para_printf(&aca->pbout, "cannot touch %s\n", name);
+ afs_error(aca, "cannot touch %s\n", name);
return ret;
}
ret = load_afsi(&old_afsi, &obj);
if (ret < 0) {
- para_printf(&aca->pbout, "cannot touch %s\n", name);
+ afs_error(aca, "cannot touch %s\n", name);
return ret;
}
new_afsi = old_afsi;
uint32_t id = lls_uint32_val(0, r_i);
ret = img_get_name_by_id(id, NULL);
if (ret < 0) {
- para_printf(&aca->pbout, "invalid image ID: %u\n", id);
+ afs_error(aca, "invalid image ID: %u\n", id);
return ret;
}
}
uint32_t id = lls_uint32_val(0, r_y);
ret = lyr_get_name_by_id(id, NULL);
if (ret < 0) {
- para_printf(&aca->pbout, "invalid lyrics ID: %u\n", id);
+ afs_error(aca, "invalid lyrics ID: %u\n", id);
return ret;
}
}
return ret;
ret = osl(osl_del_row(audio_file_table, row));
if (ret < 0)
- para_printf(&aca->pbout, "cannot remove %s\n", name);
+ afs_error(aca, "cannot remove %s\n", name);
return ret;
}
goto out; /* no attribute modifier given */
goto set_atts;
}
- p = para_malloc(len);
+ p = alloc(len);
memcpy(p, arg, len - 1);
p[len - 1] = '\0';
ret = get_attribute_bitnum_by_name(p, &bitnum);
free(p);
if (ret < 0) {
- para_printf(&aca->pbout, "invalid argument: %s\n", arg);
+ afs_error(aca, "invalid argument: %s\n", arg);
goto out;
}
if (c == '+')
}
}
-/**
- * Initialize the audio file table.
- *
- * \param t Pointer to the structure to be initialized.
- */
-void aft_init(struct afs_table *t)
-{
- t->open = aft_open;
- t->close = aft_close;
- t->create = aft_create;
- t->event_handler = aft_event_handler;
-}
+/** The audio file table contains information about known audio files. */
+const struct afs_table_operations aft_ops = {
+ .open = aft_open,
+ .close = aft_close,
+ .create = aft_create,
+ .event_handler = aft_event_handler,
+};