iptype.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <faux/conv.h>
  7. #include <klish/khelper.h>
  8. #include <klish/kptype.h>
  9. #include <klish/kaction.h>
  10. char *iptype_to_text(const iptype_t *iptype, int level)
  11. {
  12. char *str = NULL;
  13. char *tmp = NULL;
  14. tmp = faux_str_sprintf("%*cPTYPE {\n", level, ' ');
  15. faux_str_cat(&str, tmp);
  16. faux_str_free(tmp);
  17. attr2ctext(&str, "name", iptype->name, level + 1);
  18. attr2ctext(&str, "help", iptype->help, level + 1);
  19. // ACTION list
  20. if (iptype->actions) {
  21. iaction_t **p_iaction = NULL;
  22. tmp = faux_str_sprintf("\n%*cACTION_LIST\n\n", level + 1, ' ');
  23. faux_str_cat(&str, tmp);
  24. faux_str_free(tmp);
  25. for (p_iaction = *iptype->actions; *p_iaction; p_iaction++) {
  26. iaction_t *iaction = *p_iaction;
  27. tmp = iaction_to_text(iaction, level + 2);
  28. faux_str_cat(&str, tmp);
  29. faux_str_free(tmp);
  30. }
  31. tmp = faux_str_sprintf("%*cEND_ACTION_LIST,\n", level + 1, ' ');
  32. faux_str_cat(&str, tmp);
  33. faux_str_free(tmp);
  34. }
  35. tmp = faux_str_sprintf("%*c},\n\n", level, ' ');
  36. faux_str_cat(&str, tmp);
  37. faux_str_free(tmp);
  38. return str;
  39. }