]>
git.saurik.com Git - apt.git/blob - apt-private/private-utils.cc
3 #include <apt-pkg/configuration.h>
4 #include <apt-pkg/fileutl.h>
6 #include <apt-private/private-utils.h>
11 // DisplayFileInPager - Display File with pager /*{{{*/
12 bool DisplayFileInPager(std::string
const &filename
)
14 pid_t Process
= ExecFork();
18 Args
[1] = filename
.c_str();
20 if (isatty(STDOUT_FILENO
) == 1)
22 // likely installed, provided by sensible-utils
23 std::string
const pager
= _config
->Find("Dir::Bin::Pager",
25 Args
[0] = pager
.c_str();
26 execvp(Args
[0],(char **)Args
);
27 // lets try some obvious alternatives
28 Args
[0] = getenv("PAGER");
30 execvp(Args
[0],(char **)Args
);
33 execvp(Args
[0],(char **)Args
);
35 // we could read the file ourselves, but… meh
37 execvp(Args
[0],(char **)Args
);
41 // Wait for the subprocess
42 return ExecWait(Process
, "pager", false);
45 // EditFileInSensibleEditor - Edit File with editor /*{{{*/
46 bool EditFileInSensibleEditor(std::string
const &filename
)
48 pid_t Process
= ExecFork();
51 // likely installed, provided by sensible-utils
52 std::string
const editor
= _config
->Find("Dir::Bin::Editor",
55 Args
[0] = editor
.c_str();
56 Args
[1] = filename
.c_str();
58 execvp(Args
[0],(char **)Args
);
59 // the usual suspects we can try as an alternative
60 Args
[0] = getenv("VISUAL");
62 execvp(Args
[0],(char **)Args
);
64 Args
[0] = getenv("EDITOR");
66 execvp(Args
[0],(char **)Args
);
69 execvp(Args
[0],(char **)Args
);
73 // Wait for the subprocess
74 return ExecWait(Process
, "editor", false);