mirror of
https://github.com/depp/syncfiles.git
synced 2024-11-25 08:30:55 +00:00
8e2efa707e
This way we don't need to expose MemError() to platform-independent code.
40 lines
877 B
C
40 lines
877 B
C
#include "convert/convert.h"
|
|
|
|
struct ConvertEngine {
|
|
ConvertBuildf build;
|
|
ConvertRunf run;
|
|
};
|
|
|
|
const struct ConvertEngine kEngines[][2] = {
|
|
{{Convert1fBuild, Convert1fRun}, {Convert1rBuild, Convert1rRun}}};
|
|
|
|
int ConverterBuild(struct Converter *c, Handle data, Size datasz,
|
|
ConvertDirection direction)
|
|
{
|
|
int engine;
|
|
const struct ConvertEngine *funcs;
|
|
Handle out;
|
|
ErrorCode err;
|
|
|
|
if (datasz == 0) {
|
|
return kErrorBadData;
|
|
}
|
|
engine = (UInt8)(**data) - 1;
|
|
if (engine < 0 || (int)(sizeof(kEngines) / sizeof(*kEngines)) <= engine) {
|
|
/* Invalid engine. */
|
|
return kErrorBadData;
|
|
}
|
|
funcs = &kEngines[engine][direction];
|
|
if (funcs->build == NULL || funcs->run == NULL) {
|
|
/* Invalid engine. */
|
|
return kErrorBadData;
|
|
}
|
|
err = funcs->build(&out, data, datasz);
|
|
if (err != 0) {
|
|
return err;
|
|
}
|
|
c->data = out;
|
|
c->run = funcs->run;
|
|
return 0;
|
|
}
|