help.c 687 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <klish/ktp_session.h>
  7. int help_compare(const void *first, const void *second)
  8. {
  9. const help_t *f = (const help_t *)first;
  10. const help_t *s = (const help_t *)second;
  11. int r = 0;
  12. if ((r = strcmp(f->prefix, s->prefix)) != 0)
  13. return r;
  14. return strcmp(f->line, s->line);
  15. }
  16. help_t *help_new(char *prefix, char *line)
  17. {
  18. help_t *help = NULL;
  19. help = faux_zmalloc(sizeof(*help));
  20. help->prefix = prefix;
  21. help->line = line;
  22. return help;
  23. }
  24. void help_free(void *ptr)
  25. {
  26. help_t *help = (help_t *)ptr;
  27. faux_free(help->prefix);
  28. faux_free(help->line);
  29. faux_free(help);
  30. }