ptypes.c 691 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. *
  3. */
  4. #include <assert.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <errno.h>
  10. #include <faux/str.h>
  11. #include <faux/list.h>
  12. #include <klish/kcontext.h>
  13. #include <klish/kentry.h>
  14. int klish_ptype_COMMAND(kcontext_t *context)
  15. {
  16. kparg_t *parg = NULL;
  17. const kentry_t *entry = NULL;
  18. const char *value = NULL;
  19. const char *command_name = NULL;
  20. parg = kpargv_candidate_parg(kcontext_parent_pargv(context));
  21. entry = kparg_entry(parg);
  22. value = kparg_value(parg);
  23. command_name = kentry_value(entry);
  24. if (!command_name)
  25. command_name = kentry_name(entry);
  26. if (!command_name)
  27. return -1;
  28. return faux_str_casecmp(value, command_name);
  29. }