]> git.saurik.com Git - apt.git/blame - apt-private/private-utils.cc
add volatile sources support in libapt-pkg
[apt.git] / apt-private / private-utils.cc
CommitLineData
453b82a3 1#include <config.h>
cfacba52
MV
2
3#include <apt-pkg/configuration.h>
4#include <apt-pkg/fileutl.h>
cfacba52 5
453b82a3
DK
6#include <apt-private/private-utils.h>
7
8#include <cstdlib>
9#include <unistd.h>
cfacba52 10
22da5c13
DK
11// DisplayFileInPager - Display File with pager /*{{{*/
12void DisplayFileInPager(std::string const &filename)
cfacba52 13{
cfacba52
MV
14 pid_t Process = ExecFork();
15 if (Process == 0)
16 {
17 const char *Args[3];
cfacba52 18 Args[1] = filename.c_str();
22da5c13
DK
19 Args[2] = NULL;
20 if (isatty(STDOUT_FILENO) == 1)
21 {
22 // likely installed, provided by sensible-utils
23 std::string const pager = _config->Find("Dir::Bin::Pager",
24 "sensible-pager");
25 Args[0] = pager.c_str();
26 execvp(Args[0],(char **)Args);
27 // lets try some obvious alternatives
28 Args[0] = getenv("PAGER");
29 if (Args[0] != NULL)
30 execvp(Args[0],(char **)Args);
31
32 Args[0] = "pager";
33 execvp(Args[0],(char **)Args);
34 }
35 // we could read the file ourselves, but… meh
36 Args[0] = "cat";
cfacba52
MV
37 execvp(Args[0],(char **)Args);
38 exit(100);
39 }
22da5c13 40
cfacba52 41 // Wait for the subprocess
22da5c13 42 ExecWait(Process, "pager", false);
cfacba52
MV
43}
44 /*}}}*/
22da5c13
DK
45// EditFileInSensibleEditor - Edit File with editor /*{{{*/
46void EditFileInSensibleEditor(std::string const &filename)
cfacba52 47{
cfacba52
MV
48 pid_t Process = ExecFork();
49 if (Process == 0)
50 {
22da5c13
DK
51 // likely installed, provided by sensible-utils
52 std::string const editor = _config->Find("Dir::Bin::Editor",
53 "sensible-editor");
cfacba52
MV
54 const char *Args[3];
55 Args[0] = editor.c_str();
56 Args[1] = filename.c_str();
22da5c13
DK
57 Args[2] = NULL;
58 execvp(Args[0],(char **)Args);
59 // the usual suspects we can try as an alternative
60 Args[0] = getenv("VISUAL");
61 if (Args[0] != NULL)
62 execvp(Args[0],(char **)Args);
63
64 Args[0] = getenv("EDITOR");
65 if (Args[0] != NULL)
66 execvp(Args[0],(char **)Args);
67
68 Args[0] = "editor";
cfacba52
MV
69 execvp(Args[0],(char **)Args);
70 exit(100);
71 }
22da5c13 72
cfacba52 73 // Wait for the subprocess
22da5c13 74 ExecWait(Process, "editor", false);
cfacba52
MV
75}
76 /*}}}*/