ptypes.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Implementation of standard PTYPEs
  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 = kcontext_candidate_parg(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. }
  30. int klish_ptype_COMMAND_CASE(kcontext_t *context)
  31. {
  32. kparg_t *parg = NULL;
  33. const kentry_t *entry = NULL;
  34. const char *value = NULL;
  35. const char *command_name = NULL;
  36. parg = kcontext_candidate_parg(context);
  37. entry = kparg_entry(parg);
  38. value = kparg_value(parg);
  39. command_name = kentry_value(entry);
  40. if (!command_name)
  41. command_name = kentry_name(entry);
  42. if (!command_name)
  43. return -1;
  44. return strcmp(value, command_name);
  45. }