-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHACKING
64 lines (40 loc) · 2.06 KB
/
HACKING
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
HACKING
=======
yyyy/mm/dd <till \n>
<till double space> <sign|commodity|quantity>\n
...\n
...\n\n // mark posting on \n\n
payredo can be bulit as a standalone library(libpayredo) or can be built as an executable.
make libpayredo.a
make libpayredo.so
make payredo
You can control what you want to build by invoking it separately. By default builds everything.
commit.c
------
The original ledger-cli does not do edits, to make the runtime simple but since the database is completely ASCII and unorganized, consequent and programmatic writes creates a stress on the CPU and RAM, making it unsuitable for building touch friendly GUIs or general clients on top of it without comprosing UX.
To prevent this, payredo exposes a commit API which can be used by text editors and other frontends to validate added content before saving it to the file.
Once you are done with the changes in the text editor or other GUI, you can commit the data to payredo using the APIs
int ledger_commit_text(new_text, new_text_len)
int ledger_commit_post(timestamp, comment, comment_len, entries**)
The first variant can be used by text editors where the structure of the parsed text is not understood.
The second variant can be used when frontend is a GUI or other UI where the user input is controlled.
RETURN VALUE
------------
Both variants return PARSE_OK if suceeded, and -1 on failure.
payredo.c
---------
Similar to ledger-cli
payredo follows the UNIX style option arguments to make the parsing easy and to combine multiple options
parse.c
-------
There are two parsers written for the
* main ledger file
* price history file
The parser is written entirely by hand to reduce dependencies.
The `state` variable at any given time holds the information 'what we are trying to parse'. If the `state` has the value `DATE`, it means we are in a condition where we expect DATE to occur such as when starting the parser or when a posting is parsed.
There aren't as many states as the ledger format itself is quite minimal. These are currently the states,
DATE
COMMENT
ENTRY_WHO
ENTRY_AMOUNT
ENTRY_END