瀏覽代碼

libdpkg: Add new command_get_pager() function

Guillem Jover 14 年之前
父節點
當前提交
47d2aef60d
共有 4 個文件被更改,包括 24 次插入0 次删除
  1. 21 0
      lib/dpkg/command.c
  2. 1 0
      lib/dpkg/command.h
  3. 1 0
      lib/dpkg/dpkg.h
  4. 1 0
      lib/dpkg/libdpkg.map

+ 21 - 0
lib/dpkg/command.c

@@ -179,6 +179,27 @@ command_exec(struct command *cmd)
 	ohshite(_("unable to execute %s (%s)"), cmd->name, cmd->filename);
 }
 
+
+/**
+ * Get a suitable pager.
+ *
+ * @return A string representing a pager.
+ */
+const char *
+command_get_pager(void)
+{
+	const char *pager;
+
+	if (!isatty(1))
+		return CAT;
+
+	pager = getenv("PAGER");
+	if (str_is_unset(pager))
+		pager = DEFAULTPAGER;
+
+	return pager;
+}
+
 /**
  * Execute a shell with a possible command.
  *

+ 1 - 0
lib/dpkg/command.h

@@ -54,6 +54,7 @@ void command_add_args(struct command *cmd, ...) DPKG_ATTR_SENTINEL;
 
 void command_exec(struct command *cmd) DPKG_ATTR_NORET;
 
+const char *command_get_pager(void);
 void command_shell(const char *cmd, const char *name);
 
 /** @} */

+ 1 - 0
lib/dpkg/dpkg.h

@@ -110,6 +110,7 @@ DPKG_BEGIN_DECLS
 
 #define TAR		"tar"
 #define RM		"rm"
+#define CAT		"cat"
 #define FIND		"find"
 #define DIFF		"diff"
 

+ 1 - 0
lib/dpkg/libdpkg.map

@@ -128,6 +128,7 @@ LIBDPKG_PRIVATE {
 	command_add_argv;
 	command_add_args;
 	command_exec;
+	command_get_pager;
 	command_shell;
 	command_destroy;