Guest User

Untitled

a guest
May 20th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "libcamelion.h"
  5.  
  6. char test[] =
  7. {
  8.     "{\n"
  9.     "   branch1 => {\n"
  10.     "       value1 => 1,\n"
  11.     "       value2 => \"Deep into\",\n"
  12.     "   },\n"
  13.     "   branch2 => [\n"
  14.     "       'Darkness peering',"
  15.     "       'Long I \\'stood\\' there',\n"
  16.     "       \"Wondering, fearing\","
  17.     "   ],\n"
  18.     "   branch3 => {\n"
  19.     "       value3 => Dreaming,\n"
  20.     "       value4 => Dreams,\n"
  21.     "       value5 => \"No mortal ever dared to dream before\",\n"
  22.     "   },\n"
  23.     "}"
  24. };
  25.  
  26. int main(void)
  27. {
  28.     CML_Node * node;
  29.     CML_Error result = CML_StorableFromFile("./storable.txt", &node);
  30.     if (result != CML_ERROR_SUCCESS)
  31.     {
  32.         printf("%s\n", CML_HelpError(result));
  33.         exit(1);
  34.     }
  35.     CML_Node * undef;
  36.     CML_NodeCreate(CML_TYPE_UNDEF, &undef);
  37.     CML_NodeSetName(undef, "myname");
  38.     CML_NodeInsert(node, undef, 3);
  39.     //CML_NodeRemove(node, 2);
  40.  
  41.     CML_Node * first;
  42.     CML_NodeCreate(CML_TYPE_STRING, &first);
  43.     CML_NodeSetName(first, "firsty");
  44.     CML_NodeSetString(first, "things");
  45.     CML_Node * second;
  46.     CML_NodeCopy(first, &second, CML_FALSE);
  47.  
  48.     CML_NodeSetName(second, "second");
  49.     second->data.string[3] = 'A';
  50.     CML_NodeAppend(node, first);
  51.     CML_NodeAppend(node, second);
  52.  
  53.     char * printed = NULL;
  54.     result = CML_StorableToString(node, &printed);
  55.  
  56.     printf("%s\n\n\n", printed);
  57.     free(printed);
  58.  
  59.     CML_Node * clone;
  60.     CML_NodeCopy(node, &clone, CML_TRUE);
  61.  
  62.     CML_NodeFree(node);
  63.  
  64.     printed = NULL;
  65.     result = CML_StorableToString(clone, &printed);
  66.  
  67.     printf("%s\n\n\n", printed);
  68.     free(printed);
  69.  
  70.     CML_Bytes * bytes;
  71.     result = CML_NfreezeNode(clone, &bytes);
  72.     printf("%d\n", result);
  73.     printf("%s\n", CML_HelpError(result));
  74.     CML_DataToFile(bytes->data, bytes->size, "./data.frz");
  75.     free(bytes->data);
  76.     free(bytes);
  77.  
  78.     CML_NodeFree(clone);
  79.  
  80.     result = CML_NfreezeStorable(test, &bytes);
  81.     printf("%d\n", result);
  82.     printf("%s\n", CML_HelpError(result));
  83.     CML_DataToFile(bytes->data, bytes->size, "./data2.frz");
  84.     free(bytes->data);
  85.     free(bytes);
  86.  
  87.  
  88.     CML_Node * reader = NULL;
  89.     result = CML_ThawFile("./data.frz", &reader);
  90.     printf("%d\n", result);
  91.     printf("%s\n", CML_HelpError(result));
  92.     char * buff;
  93.     CML_StorableToString(reader, &buff);
  94.     printf("%s\n", buff);
  95.     free(buff);
  96.     CML_NodeFree(reader);
  97.  
  98.     return 0;
  99. }
Add Comment
Please, Sign In to add comment