From cfacba5230f2e6bb88a1949505843ac22ed342d5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 25 Nov 2013 08:36:57 +0100 Subject: add basic "edit-sources" command --- apt-private/makefile | 2 +- apt-private/private-utils.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++ apt-private/private-utils.h | 11 ++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 apt-private/private-utils.cc create mode 100644 apt-private/private-utils.h (limited to 'apt-private') diff --git a/apt-private/makefile b/apt-private/makefile index 1d179f0b2..b3d764097 100644 --- a/apt-private/makefile +++ b/apt-private/makefile @@ -17,7 +17,7 @@ MAJOR=0.0 MINOR=0 SLIBS=$(PTHREADLIB) -lapt-pkg -PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main +PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main utils SOURCE += $(foreach private, $(PRIVATES), private-$(private).cc) HEADERS += $(foreach private, $(PRIVATES), private-$(private).h) diff --git a/apt-private/private-utils.cc b/apt-private/private-utils.cc new file mode 100644 index 000000000..813f19329 --- /dev/null +++ b/apt-private/private-utils.cc @@ -0,0 +1,50 @@ +#include + +#include +#include +#include "private-utils.h" + + +// DisplayFileInPager - Display File with pager /*{{{*/ +void DisplayFileInPager(std::string filename) +{ + std::string pager = _config->Find("Dir::Bin::Pager", + "/usr/bin/sensible-pager"); + + pid_t Process = ExecFork(); + if (Process == 0) + { + const char *Args[3]; + Args[0] = pager.c_str(); + Args[1] = filename.c_str(); + Args[2] = 0; + execvp(Args[0],(char **)Args); + exit(100); + } + + // Wait for the subprocess + ExecWait(Process, "sensible-pager", false); +} + /*}}}*/ + +// EditFileInSensibleEditor - Edit File with editor /*{{{*/ +void EditFileInSensibleEditor(std::string filename) +{ + std::string editor = _config->Find("Dir::Bin::Editor", + "/usr/bin/sensible-editor"); + + pid_t Process = ExecFork(); + if (Process == 0) + { + const char *Args[3]; + Args[0] = editor.c_str(); + Args[1] = filename.c_str(); + Args[2] = 0; + execvp(Args[0],(char **)Args); + exit(100); + } + + // Wait for the subprocess + ExecWait(Process, "sensible-editor", false); +} + /*}}}*/ diff --git a/apt-private/private-utils.h b/apt-private/private-utils.h new file mode 100644 index 000000000..258dd06a8 --- /dev/null +++ b/apt-private/private-utils.h @@ -0,0 +1,11 @@ +#ifndef APT_PRIVATE_UTILS_H +#define APT_PRIVATE_UTILS_H + +#include + +void DisplayFileInPager(std::string filename); +void EditFileInSensibleEditor(std::string filename); + + + +#endif -- cgit v1.2.3