private-utils.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <config.h>
  2. #include <apt-pkg/configuration.h>
  3. #include <apt-pkg/fileutl.h>
  4. #include <apt-private/private-utils.h>
  5. #include <cstdlib>
  6. #include <unistd.h>
  7. // DisplayFileInPager - Display File with pager /*{{{*/
  8. void DisplayFileInPager(std::string filename)
  9. {
  10. std::string pager = _config->Find("Dir::Bin::Pager",
  11. "/usr/bin/sensible-pager");
  12. pid_t Process = ExecFork();
  13. if (Process == 0)
  14. {
  15. const char *Args[3];
  16. Args[0] = pager.c_str();
  17. Args[1] = filename.c_str();
  18. Args[2] = 0;
  19. execvp(Args[0],(char **)Args);
  20. exit(100);
  21. }
  22. // Wait for the subprocess
  23. ExecWait(Process, "sensible-pager", false);
  24. }
  25. /*}}}*/
  26. // EditFileInSensibleEditor - Edit File with editor /*{{{*/
  27. void EditFileInSensibleEditor(std::string filename)
  28. {
  29. std::string editor = _config->Find("Dir::Bin::Editor",
  30. "/usr/bin/sensible-editor");
  31. pid_t Process = ExecFork();
  32. if (Process == 0)
  33. {
  34. const char *Args[3];
  35. Args[0] = editor.c_str();
  36. Args[1] = filename.c_str();
  37. Args[2] = 0;
  38. execvp(Args[0],(char **)Args);
  39. exit(100);
  40. }
  41. // Wait for the subprocess
  42. ExecWait(Process, "sensible-editor", false);
  43. }
  44. /*}}}*/