-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook.h
86 lines (64 loc) · 1.4 KB
/
book.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef BOOK_H
#define BOOK_H
#include <stdbool.h>
/*
* Internal e-book format.
*/
typedef enum
{
EPUB = 0,
MOBI = 1,
INVALID,
} book_type;
typedef struct
{
unsigned id;
char *title;
char *author;
char *body;
unsigned body_size;
} ebook;
typedef unsigned bookid;
extern ebook *books;
extern int num_books;
extern int max_books;
bool file_exists (char *filename);
const char *get_file_extension (const char *filename);
book_type get_file_type (char *filename);
/*
*
*/
ebook *new_book ();
void remove_book (bookid id);
/*
* id is set to the id of the loaded book
*/
int load_book (char *filename, unsigned *id);
/*
* Initialise a new ebook and give its id.
* Returns 0 on success.
*/
int init_ebook (unsigned *id);
/*
* Gives a pointer to an ebook.
* Returns 0 on success.
*/
int get_ebook (unsigned id, ebook *book);
int add_section (bookid book, char *text, unsigned length);
/*
* Copies a page of length <length> into <text> with offset <page> * <length>
* length: in characters
* page: starts from 1
* Returns 0 on success.
*/
int get_page (bookid book, char **text, int offset, int length);
int set_title (bookid id, const char *text);
const char *get_title (bookid id);
const char *get_body (bookid id);
unsigned get_num_books ();
/*
* Returns title of book.
*/
const char *book_title (bookid id);
void books_cleanup ();
#endif