ptype_dump.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * ptype_dump.c
  3. */
  4. #include "private.h"
  5. #include "lub/xml2c.h"
  6. #ifdef DEBUG
  7. #include "lub/dump.h"
  8. /*--------------------------------------------------------- */
  9. void clish_ptype_dump(clish_ptype_t * this)
  10. {
  11. lub_dump_printf("ptype(%p)\n", this);
  12. lub_dump_indent();
  13. lub_dump_printf("name : %s\n", clish_ptype__get_name(this));
  14. lub_dump_printf("text : %s\n", LUB_DUMP_STR(clish_ptype__get_text(this)));
  15. lub_dump_printf("pattern : %s\n", LUB_DUMP_STR(this->pattern));
  16. lub_dump_printf("method : %s\n",
  17. clish_ptype_method__get_name(this->method));
  18. lub_dump_printf("postprocess: %s\n",
  19. clish_ptype_preprocess__get_name(this->preprocess));
  20. lub_dump_undent();
  21. }
  22. /*--------------------------------------------------------- */
  23. #endif /* DEBUG */
  24. static const char *method_macros[] = {
  25. "CLISH_PTYPE_REGEXP",
  26. "CLISH_PTYPE_INTEGER",
  27. "CLISH_PTYPE_UNSIGNEDINTEGER",
  28. "CLISH_PTYPE_SELECT"
  29. };
  30. static const char *preprocess_macros[] = {
  31. "CLISH_PTYPE_NONE",
  32. "CLISH_PTYPE_TOUPPER",
  33. "CLISH_PTYPE_TOLOWER"
  34. };
  35. void clish_ptype_xml2c(clish_ptype_t *this)
  36. {
  37. char *esc_name = xml2c_esc(clish_ptype__get_name(this));
  38. char *esc_help = xml2c_esc(clish_ptype__get_text(this));
  39. char *esc_pattern = xml2c_esc(this->pattern);
  40. printf("clish_shell_find_create_ptype(shell,\n");
  41. printf("\t\"%s\",\n", XML2C_STR(esc_name)); /* name */
  42. printf("\t\"%s\",\n", XML2C_STR(esc_help)); /* help */
  43. printf("\t\"%s\",\n", XML2C_STR(esc_pattern)); /* pattern */
  44. printf("\t%s,\n", xml2c_enum(this->method, method_macros)); /* method */
  45. printf("\t%s\n", xml2c_enum(this->preprocess, preprocess_macros)); /* preprocess */
  46. printf(");\n\n");
  47. lub_string_free(esc_name);
  48. lub_string_free(esc_help);
  49. lub_string_free(esc_pattern);
  50. }