iparam.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <klish/khelper.h>
  7. #include <klish/iparam.h>
  8. char *iparam_to_text(const iparam_t *iparam, int level)
  9. {
  10. char *str = NULL;
  11. char *tmp = NULL;
  12. tmp = faux_str_sprintf("%*cPARAM {\n", level, ' ');
  13. faux_str_cat(&str, tmp);
  14. faux_str_free(tmp);
  15. attr2ctext(&str, "name", iparam->name, level + 1);
  16. attr2ctext(&str, "help", iparam->help, level + 1);
  17. attr2ctext(&str, "ptype", iparam->ptype, level + 1);
  18. // PARAM list
  19. if (iparam->params) {
  20. iparam_t **p_iparam = NULL;
  21. tmp = faux_str_sprintf("\n%*cPARAM_LIST\n\n", level + 1, ' ');
  22. faux_str_cat(&str, tmp);
  23. faux_str_free(tmp);
  24. for (p_iparam = *iparam->params; *p_iparam; p_iparam++) {
  25. iparam_t *niparam = *p_iparam;
  26. tmp = iparam_to_text(niparam, level + 2);
  27. faux_str_cat(&str, tmp);
  28. faux_str_free(tmp);
  29. }
  30. tmp = faux_str_sprintf("%*cEND_PARAM_LIST,\n", level + 1, ' ');
  31. faux_str_cat(&str, tmp);
  32. faux_str_free(tmp);
  33. }
  34. tmp = faux_str_sprintf("%*c},\n\n", level, ' ');
  35. faux_str_cat(&str, tmp);
  36. faux_str_free(tmp);
  37. return str;
  38. }