help.c 797 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. return strcmp(f->prefix, s->prefix);
  12. }
  13. int help_kcompare(const void *key, const void *list_item)
  14. {
  15. const char *f = (const char *)key;
  16. const help_t *s = (const help_t *)list_item;
  17. return strcmp(f, s->prefix);
  18. }
  19. help_t *help_new(char *prefix, char *line)
  20. {
  21. help_t *help = NULL;
  22. help = faux_zmalloc(sizeof(*help));
  23. help->prefix = prefix;
  24. help->line = line;
  25. return help;
  26. }
  27. void help_free(void *ptr)
  28. {
  29. help_t *help = (help_t *)ptr;
  30. faux_free(help->prefix);
  31. faux_free(help->line);
  32. faux_free(help);
  33. }