75 lines
No EOL
1.7 KiB
C
75 lines
No EOL
1.7 KiB
C
#include "bmg.h"
|
|
|
|
|
|
BmgFile* bmgFileNew() {
|
|
// allocate the memory for the object
|
|
BmgFile* file = (BmgFile*)malloc(sizeof(BmgFile));
|
|
file->_internal = (bmg_t*)malloc(sizeof(bmg_t));
|
|
|
|
// initialize the internal structure
|
|
InitializeBMG(file->_internal);
|
|
|
|
return file;
|
|
}
|
|
|
|
void bmgFileFree(BmgFile* file) {
|
|
// deallocate the memory of the object
|
|
free(file->_internal);
|
|
free(file);
|
|
}
|
|
|
|
BmgFile* bmgFileLoad(const char* path) {
|
|
// create a new bmg file
|
|
BmgFile* file = bmgFileNew();
|
|
|
|
// load the bmg file
|
|
LoadBMG(
|
|
file->_internal,
|
|
false,
|
|
NULL,
|
|
path,
|
|
FM_MODIFY
|
|
);
|
|
|
|
return file;
|
|
}
|
|
|
|
BmgRecord* bmgRecordNew(bmg_item_t* internal_record) {
|
|
// allocate memory for the record
|
|
BmgRecord* record = (BmgRecord*)malloc(sizeof(BmgRecord));
|
|
record->_internal = internal_record;
|
|
|
|
return record;
|
|
}
|
|
|
|
void bmgRecordFree(BmgRecord* record) {
|
|
// free the memory used for the record
|
|
free(record);
|
|
}
|
|
|
|
BmgRecord* bmgRecordGet(BmgFile* file, u32 id) {
|
|
// find the corresponding bmg record
|
|
bmg_item_t* internal_record = FindItemBMG(file->_internal, id);
|
|
// wrap it with our structure
|
|
BmgRecord* record = bmgRecordNew(internal_record);
|
|
|
|
return record;
|
|
}
|
|
|
|
BmgRecord* bmgRecordInsert(BmgFile* file, u32 id, const char* text) {
|
|
// insert the data into the bmg file
|
|
bmg_item_t* internal_record = InsertItemBMG(
|
|
file->_internal,
|
|
id,
|
|
NULL,
|
|
0,
|
|
NULL
|
|
);
|
|
|
|
// internal_record->text = strdup(text);
|
|
|
|
// wrap it with our structure
|
|
BmgRecord* record = bmgRecordNew(internal_record);
|
|
|
|
return record;
|
|
} |