iparam.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/kparam.h>
  9. char *iparam_to_text(const iparam_t *iparam, int level)
  10. {
  11. char *str = NULL;
  12. char *tmp = NULL;
  13. tmp = faux_str_sprintf("%*cPARAM {\n", level, ' ');
  14. faux_str_cat(&str, tmp);
  15. faux_str_free(tmp);
  16. attr2ctext(&str, "name", iparam->name, level + 1);
  17. attr2ctext(&str, "help", iparam->help, level + 1);
  18. attr2ctext(&str, "ptype", iparam->ptype, level + 1);
  19. // PARAM list
  20. if (iparam->params) {
  21. iparam_t **p_iparam = NULL;
  22. tmp = faux_str_sprintf("\n%*cPARAM_LIST\n\n", level + 1, ' ');
  23. faux_str_cat(&str, tmp);
  24. faux_str_free(tmp);
  25. for (p_iparam = *iparam->params; *p_iparam; p_iparam++) {
  26. iparam_t *niparam = *p_iparam;
  27. tmp = iparam_to_text(niparam, level + 2);
  28. faux_str_cat(&str, tmp);
  29. faux_str_free(tmp);
  30. }
  31. tmp = faux_str_sprintf("%*cEND_PARAM_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. }