]> git.saurik.com Git - apt.git/blob - apt-private/private-utils.cc
more sensible default text in pot files
[apt.git] / apt-private / private-utils.cc
1 #include <config.h>
2
3 #include <apt-pkg/configuration.h>
4 #include <apt-pkg/fileutl.h>
5
6 #include <apt-private/private-utils.h>
7
8 #include <cstdlib>
9 #include <unistd.h>
10
11 // DisplayFileInPager - Display File with pager /*{{{*/
12 void DisplayFileInPager(std::string const &filename)
13 {
14 pid_t Process = ExecFork();
15 if (Process == 0)
16 {
17 const char *Args[3];
18 Args[1] = filename.c_str();
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";
37 execvp(Args[0],(char **)Args);
38 exit(100);
39 }
40
41 // Wait for the subprocess
42 ExecWait(Process, "pager", false);
43 }
44 /*}}}*/
45 // EditFileInSensibleEditor - Edit File with editor /*{{{*/
46 void EditFileInSensibleEditor(std::string const &filename)
47 {
48 pid_t Process = ExecFork();
49 if (Process == 0)
50 {
51 // likely installed, provided by sensible-utils
52 std::string const editor = _config->Find("Dir::Bin::Editor",
53 "sensible-editor");
54 const char *Args[3];
55 Args[0] = editor.c_str();
56 Args[1] = filename.c_str();
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";
69 execvp(Args[0],(char **)Args);
70 exit(100);
71 }
72
73 // Wait for the subprocess
74 ExecWait(Process, "editor", false);
75 }
76 /*}}}*/