Choose file to parse from CLI arguments
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# C JSON Parser
|
# C JSON Parser
|
||||||
|
|
||||||
Just a simple project to practice writing parsers.
|
Just a simple project to practice writing parsers.
|
||||||
Not guaranteed to be safe or efficient.
|
Not guaranteed to be safe, reliable or efficient.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ To make a debug build just run `make`.
|
|||||||
### Run
|
### Run
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./bin/{release|debug}/json_parser
|
./bin/{release|debug}/json_parser sample.json
|
||||||
```
|
```
|
||||||
|
|
||||||
## Limitations
|
## Limitations
|
||||||
|
|||||||
10
src/main.c
10
src/main.c
@@ -4,13 +4,17 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <stdlib.h> // atexit
|
#include <stdlib.h> // atexit
|
||||||
#include <unistd.h> // _exit
|
#include <err.h> // errx
|
||||||
|
|
||||||
int main()
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
if (argc != 2) {
|
||||||
|
errx(EXIT_FAILURE, "Usage: %s <file>", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
atexit(print_trace);
|
atexit(print_trace);
|
||||||
|
|
||||||
FILE* fp = fopen("sample.json", "r");
|
FILE* fp = fopen(argv[1], "r");
|
||||||
|
|
||||||
volatile struct json_value x = parse_json_value(fp);
|
volatile struct json_value x = parse_json_value(fp);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user