ser.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <rid.h>
  4. #include "../unfy.h"
  5. #include "../unfp.h"
  6. int
  7. main(int args, char *argv[])
  8. {
  9. Unfy_recycle rec;
  10. const char *error;
  11. size_t pos = 0;
  12. Unfy_term *term;
  13. Unfy_term *term2;
  14. unsigned char *buf = NULL;
  15. size_t size = 0;
  16. size_t len = 0;
  17. Unfy_bind *lbind = NULL;
  18. Unfy_bind *lbind2 = NULL;
  19. Unfy_bind *rbind = NULL;
  20. Unfy_bind *rbind2 = NULL;
  21. Unfy_info info;
  22. unfy_recycle_init(&rec);
  23. term = unfp_term_parse("(const man_________________ "
  24. "() "
  25. "var can_________________ "
  26. "_ "
  27. "order 1 order 2 order 2 "
  28. "(const socrates____________))",
  29. &pos, &error, &rec);
  30. unfp_term_ser(term, &buf, &size, &len);
  31. len = 0;
  32. if (unfp_term_deserable(buf, &len, size))
  33. printf("Safe to deser term!\n");
  34. len = 0;
  35. unfp_term_deser(&term2, buf, &len, &rec);
  36. unfp_term_print(term2);
  37. printf("\n");
  38. unfy_recycle_term(&rec, term2);
  39. term2 = unfp_term_parse("(var var_________________ "
  40. "() "
  41. "var tan_________________ "
  42. "const useless_____________ "
  43. "order 1 order 2 order 2 "
  44. "(const socrates____________))",
  45. &pos, &error, &rec);
  46. unfy_info_init(&info, term, term2);
  47. unfy_unify(&info, &rec);
  48. unfp_bind_ser(lbind, &buf, &size, &len);
  49. len = 0;
  50. if (unfp_bind_deserable(buf, &len, size))
  51. printf("Safe to deser lbind!\n");
  52. unfp_bind_deser(&lbind2, buf, &len, &rec);
  53. unfp_bind_print(lbind2);
  54. unfp_bind_ser(rbind, &buf, &size, &len);
  55. len = 0;
  56. if (unfp_bind_deserable(buf, &len, size))
  57. printf("Safe to deser rbind!\n");
  58. unfp_bind_deser(&rbind2, buf, &len, &rec);
  59. unfp_bind_print(rbind2);
  60. free(buf);
  61. unfy_recycle_bind(&rec, lbind);
  62. unfy_recycle_bind(&rec, lbind2);
  63. unfy_recycle_bind(&rec, rbind);
  64. unfy_recycle_bind(&rec, rbind2);
  65. unfy_recycle_term(&rec, term);
  66. unfy_recycle_term(&rec, term2);
  67. unfy_recycle_empty(&rec);
  68. return 0;
  69. }