Changeset aaf962e6 in mainline for uspace/lib/riff/src/chunk.c


Ignore:
Timestamp:
2020-09-21T21:41:53Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ea459d4
Parents:
d145ecb
Message:

Need to be able to skip unknown chunks easily

This is, afterall the whole point of having a self-describing format:
new (optional) chunks types can be inserted without having to modify the
reader.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/riff/src/chunk.c

    rd145ecb raaf962e6  
    3939#include <macros.h>
    4040#include <riff/chunk.h>
     41#include <stdbool.h>
    4142#include <stdlib.h>
    4243
     
    271272 * @param rchunk RIFF chunk
    272273 * @param v  Place to store value
    273  * @return EOK on success, EIO on error.
     274 * @return EOK on success, ELIMIT if at the end of parent chunk, EIO on error.
    274275 */
    275276errno_t riff_read_uint32(riff_rchunk_t *rchunk, uint32_t *v)
     
    295296 * @param rchunk Pointer to chunk structure to fill in
    296297 *
    297  * @return EOK on success, EIO on error.
     298 * @return EOK on success, ELIMIT if at the end of parent chunk,
     299 *         EIO on error.
    298300 */
    299301errno_t riff_rchunk_start(riff_rchunk_t *parent, riff_rchunk_t *rchunk)
     
    320322error:
    321323        return rc;
     324}
     325
     326/** Find and start reading RIFF chunk of with specific chunk ID.
     327 * Other types of chunks are skipped.
     328 *
     329 * @param parent Parent chunk
     330 * @param rchunk Pointer to chunk structure to fill in
     331 *
     332 * @return EOK on success, ENOENT chunk was not found and end was reached
     333 *         EIO on error.
     334 */
     335errno_t riff_rchunk_match(riff_rchunk_t *parent, riff_ckid_t ckid,
     336    riff_rchunk_t *rchunk)
     337{
     338        errno_t rc;
     339
     340        while (true) {
     341                rc = riff_rchunk_start(parent, rchunk);
     342                if (rc == ELIMIT)
     343                        return ENOENT;
     344                if (rc != EOK)
     345                        return rc;
     346
     347                if (rchunk->ckid == ckid)
     348                        break;
     349
     350                rc = riff_rchunk_end(rchunk);
     351                if (rc != EOK)
     352                        return rc;
     353        }
     354
     355        return EOK;
     356}
     357
     358/** Find and start reading RIFF LIST chunk of specified type.
     359 * Other chunks or LIST chunks of other type are skipped.
     360 *
     361 * @param parent Parent chunk
     362 * @param rchunk Pointer to chunk structure to fill in
     363 *
     364 * @return EOK on success, ENOENT chunk was not found and end was reached
     365 *         EIO on error.
     366 */
     367errno_t riff_rchunk_list_match(riff_rchunk_t *parent, riff_ltype_t ltype,
     368    riff_rchunk_t *rchunk)
     369{
     370        errno_t rc;
     371        riff_ltype_t rltype;
     372
     373        while (true) {
     374                rc = riff_rchunk_match(parent, CKID_LIST, rchunk);
     375                if (rc == ELIMIT)
     376                        return ENOENT;
     377                if (rc != EOK)
     378                        return rc;
     379
     380                rc = riff_read_uint32(parent, &rltype);
     381                if (rc != EOK)
     382                        return rc;
     383
     384                if (rltype == ltype)
     385                        break;
     386
     387                rc = riff_rchunk_end(rchunk);
     388                if (rc != EOK)
     389                        return rc;
     390        }
     391
     392        return EOK;
    322393}
    323394
Note: See TracChangeset for help on using the changeset viewer.