/***********************************************************************
* FILENAME :        fmcompres.c             DESIGN REF: FMCM00
*
* DESCRIPTION :
*       File compression and decompression routines. 
*
* PUBLIC FUNCTIONS :
*       key_value_node   parse_json_file( char *filename )
*       int              FM_DecompressFile( key_value_node *root, unsigned short iscompact )
*
* NOTES :
*       These functions are a part of the Json-Parse;
*       See ERD EJ0252 for detailed description.
*
*       Copyright S.P.Other Co. 1990, 1995.  All rights reserved.
* AUTHOR :    Sem Postma Other        START DATE :    16 Jan 99
*
* CHANGES :
*
* REF NO  VERSION DATE    WHO     DETAIL
* F21/33  A.03.04 22Jan99 JR      Function parse_json corrected
*

#include "helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

key_value_node *parse_json_file(char *filename) {
    char *str = NULL;
    long length;
    FILE *f = fopen(filename, "r");
    if (f == NULL) return NULL;
    else {
        if (fseek(f, 0, SEEK_END)) return NULL;
        length = ftell(f);
        if (fseek(f, 0, SEEK_SET)) return NULL;
        str = malloc(length + sizeof(char));
        if (str) fread(str, 1, length, f);
        else return NULL;
        str[length] = '\0';
        if (fclose(f)) return NULL;
    }
    key_value_node *root = parse_json(str);
    free(str);
    return root;
}

int print_key_value_tree(key_value_node *root, unsigned short iscompact) {
    iscompact ? print_compact_key_value_tree_rec(root, 0) : print_key_value_tree_rec(root, 0);
    return 0;
}