iptype.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/iptype.h>
  8. char *iptype_to_text(const iptype_t *iptype, int level)
  9. {
  10. char *str = NULL;
  11. char *tmp = NULL;
  12. tmp = faux_str_sprintf("%*cPTYPE {\n", level, ' ');
  13. faux_str_cat(&str, tmp);
  14. faux_str_free(tmp);
  15. attr2ctext(&str, "name", iptype->name, level + 1);
  16. attr2ctext(&str, "help", iptype->help, level + 1);
  17. // ACTION list
  18. if (iptype->actions) {
  19. iaction_t **p_iaction = NULL;
  20. tmp = faux_str_sprintf("\n%*cACTION_LIST\n\n", level + 1, ' ');
  21. faux_str_cat(&str, tmp);
  22. faux_str_free(tmp);
  23. for (p_iaction = *iptype->actions; *p_iaction; p_iaction++) {
  24. iaction_t *iaction = *p_iaction;
  25. tmp = iaction_to_text(iaction, level + 2);
  26. faux_str_cat(&str, tmp);
  27. faux_str_free(tmp);
  28. }
  29. tmp = faux_str_sprintf("%*cEND_ACTION_LIST,\n", level + 1, ' ');
  30. faux_str_cat(&str, tmp);
  31. faux_str_free(tmp);
  32. }
  33. tmp = faux_str_sprintf("%*c},\n\n", level, ' ');
  34. faux_str_cat(&str, tmp);
  35. faux_str_free(tmp);
  36. return str;
  37. }