Finish haggis_load_node
function; Add *node related function
prototypes to haggis.h;
This commit is contained in:
parent
5b520b54e2
commit
e97feb1e3d
2 changed files with 34 additions and 5 deletions
|
@ -118,4 +118,9 @@ struct haggis_node {
|
|||
struct haggis_filetype *filetype;
|
||||
};
|
||||
|
||||
struct haggis_node* haggis_create_node(char *file);
|
||||
int haggis_extract_node(FILE *stram, struct haggis_node *node);
|
||||
int haggis_load_node(FILE *stream, struct haggis_node *node);
|
||||
int haggis_store_node(FILE *stream, struct haggis_node *node);
|
||||
|
||||
#endif // !HAGGIS_H
|
||||
|
|
30
src/haggis.c
30
src/haggis.c
|
@ -30,6 +30,7 @@
|
|||
* other than his own.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
#include <sha.h>
|
||||
#include <sha256.h>
|
||||
|
@ -374,7 +375,19 @@ int haggis_load_filetype(
|
|||
return 0;
|
||||
}
|
||||
|
||||
int haggis_store_node(FILE *stream, struct haggis_node *node) {
|
||||
enum haggis_typeflag haggis_filetype_from_mode(union u16 mode) {
|
||||
u8 mask = 07 << 5;
|
||||
int filetype = (int)((mode.bytes[0] & mask) >> 5);
|
||||
return filetype;
|
||||
}
|
||||
|
||||
struct haggis_node* haggis_create_node(char *file) {
|
||||
struct haggis_node *node = malloc(sizeof(struct haggis_node));
|
||||
// todo
|
||||
return node;
|
||||
}
|
||||
|
||||
int haggis_extract_node(FILE *stram, struct haggis_node *node) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
|
@ -382,8 +395,9 @@ int haggis_store_node(FILE *stream, struct haggis_node *node) {
|
|||
int haggis_load_node(FILE *stream, struct haggis_node *node) {
|
||||
int res;
|
||||
union u16 mode;
|
||||
enum haggis_typeflag flag;
|
||||
enum haggis_typeflag tag;
|
||||
|
||||
mode.val = 0;
|
||||
res = haggis_load_filename(stream, node->name);
|
||||
if (res)
|
||||
return res;
|
||||
|
@ -399,6 +413,16 @@ int haggis_load_node(FILE *stream, struct haggis_node *node) {
|
|||
res = load_u16(stream, mode);
|
||||
if (res != 2)
|
||||
return 2;
|
||||
//todo
|
||||
tag = haggis_filetype_from_mode(mode);
|
||||
node->mode.bytes[0] = mode.bytes[0] & 037;
|
||||
node->mode.bytes[1] = mode.bytes[1];
|
||||
res = haggis_load_filetype(stream, tag, node->filetype);
|
||||
if (res)
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int haggis_store_node(FILE *stream, struct haggis_node *node) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue