aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2010-12-08 01:16:01 +0000
committerMike Frysinger <vapier@gentoo.org>2010-12-08 01:16:01 +0000
commit4f205d1636b75df36cd24e8d85a51c0254d0df42 (patch)
tree9671658237e4ecb39f83880bfca28c10732af82e
parentchange to simpler const argv0 string (diff)
downloadpax-utils-4f205d1636b75df36cd24e8d85a51c0254d0df42.tar.gz
pax-utils-4f205d1636b75df36cd24e8d85a51c0254d0df42.tar.bz2
pax-utils-4f205d1636b75df36cd24e8d85a51c0254d0df42.zip
add a -C/--nocolor option and respect env $NOCOLOR #332289
-rw-r--r--paxinc.c19
-rw-r--r--paxinc.h9
-rw-r--r--pspax.c8
-rw-r--r--scanelf.c12
-rw-r--r--scanmacho.c12
5 files changed, 43 insertions, 17 deletions
diff --git a/paxinc.c b/paxinc.c
index 61939a7..12fc43b 100644
--- a/paxinc.c
+++ b/paxinc.c
@@ -1,7 +1,7 @@
/*
* Copyright 2003-2007 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.13 2009/03/15 08:52:59 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.14 2010/12/08 01:16:01 vapier Exp $
*
* Copyright 2005-2007 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2007 Mike Frysinger - <vapier@gentoo.org>
@@ -143,3 +143,20 @@ const char *strfileperms(const char *fname)
return buf + 2;
}
+
+/* Color helpers */
+#define COLOR(c,b) "\e[" c ";" b "m"
+const char *NORM = COLOR("00", "00");
+const char *RED = COLOR("31", "01");
+const char *YELLOW = COLOR("33", "01");
+
+void color_init(bool disable)
+{
+ if (!disable) {
+ const char *nocolor = getenv("NOCOLOR");
+ if (nocolor)
+ disable = !strcmp(nocolor, "yes") || !strcmp(nocolor, "true");
+ }
+ if (disable)
+ NORM = RED = YELLOW = "";
+}
diff --git a/paxinc.h b/paxinc.h
index b054f15..62c9900 100644
--- a/paxinc.h
+++ b/paxinc.h
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2007 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.h,v 1.15 2010/12/08 00:54:40 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.h,v 1.16 2010/12/08 01:16:01 vapier Exp $
*
* Copyright 2005-2007 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2007 Mike Frysinger - <vapier@gentoo.org>
@@ -92,11 +92,8 @@ const char *strfileperms(const char *fname);
} while (0)
/* helper functions for showing errors */
-#define color 1
-#define COLOR(c,b) (color ? "\e[" c ";" b "m" : "")
-#define NORM COLOR("00", "00")
-#define RED COLOR("31", "01")
-#define YELLOW COLOR("33", "01")
+extern const char *NORM, *RED, *YELLOW;
+void color_init(bool disable);
/* constant pointer to a constant buffer ... each program needs to set this */
extern const char argv0[];
diff --git a/pspax.c b/pspax.c
index 8aad5d0..a6839f7 100644
--- a/pspax.c
+++ b/pspax.c
@@ -12,7 +12,7 @@
* cc -o pspax pspax.c -DWANT_SYSCAP -lcap
*/
-static const char *rcsid = "$Id: pspax.c,v 1.47 2010/12/08 00:54:40 vapier Exp $";
+static const char *rcsid = "$Id: pspax.c,v 1.48 2010/12/08 01:16:01 vapier Exp $";
const char argv0[] = "pspax";
#include "paxinc.h"
@@ -416,7 +416,7 @@ static void pspax(const char *find_name)
}
/* usage / invocation handling functions */
-#define PARSE_FLAGS "aeip:u:g:nwWvBhV"
+#define PARSE_FLAGS "aeip:u:g:nwWvCBhV"
#define a_argument required_argument
static struct option const long_opts[] = {
{"all", no_argument, NULL, 'a'},
@@ -429,6 +429,7 @@ static struct option const long_opts[] = {
{"wx", no_argument, NULL, 'w'},
{"wide", no_argument, NULL, 'W'},
{"verbose", no_argument, NULL, 'v'},
+ {"nocolor", no_argument, NULL, 'C'},
{"nobanner", no_argument, NULL, 'B'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
@@ -446,6 +447,7 @@ static const char *opts_help[] = {
"Only display w|x processes",
"Wide output display of cmdline",
"Be verbose about executable mappings",
+ "Don't emit color in output",
"Don't display the header",
"Print this help and exit",
"Print version and exit",
@@ -489,6 +491,7 @@ static void parseargs(int argc, char *argv[])
break;
case 'h': usage(EXIT_SUCCESS); break;
+ case 'C': color_init(true); break;
case 'B': show_banner = 0; break;
case 'a': show_all = 1; break;
case 'e': show_phdr = 1; break;
@@ -534,6 +537,7 @@ int main(int argc, char *argv[])
{
char *name = NULL;
+ color_init(false);
parseargs(argc, argv);
if ((optind < argc) && (show_pid == 0))
diff --git a/scanelf.c b/scanelf.c
index 96995f1..4ce1647 100644
--- a/scanelf.c
+++ b/scanelf.c
@@ -1,13 +1,13 @@
/*
* Copyright 2003-2007 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.220 2010/12/08 00:54:40 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.221 2010/12/08 01:16:01 vapier Exp $
*
* Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
* Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org>
*/
-static const char *rcsid = "$Id: scanelf.c,v 1.220 2010/12/08 00:54:40 vapier Exp $";
+static const char *rcsid = "$Id: scanelf.c,v 1.221 2010/12/08 01:16:01 vapier Exp $";
const char argv0[] = "scanelf";
#include "paxinc.h"
@@ -1731,8 +1731,8 @@ static void scanelf_envpath(void)
free(path);
}
-/* usage / invocation handling functions */ /* Free Flags: c d j u w C G H J K P Q U W */
-#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DIYO:ZBhV"
+/* usage / invocation handling functions */ /* Free Flags: c d j u w G H J K P Q U W */
+#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DIYO:ZCBhV"
#define a_argument required_argument
static struct option const long_opts[] = {
{"path", no_argument, NULL, 'p'},
@@ -1770,6 +1770,7 @@ static struct option const long_opts[] = {
{"format", a_argument, NULL, 'F'},
{"from", a_argument, NULL, 'f'},
{"file", a_argument, NULL, 'o'},
+ {"nocolor", no_argument, NULL, 'C'},
{"nobanner", no_argument, NULL, 'B'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
@@ -1812,6 +1813,7 @@ static const char *opts_help[] = {
"Use specified format for output",
"Read input stream from a filename",
"Write output stream to a filename",
+ "Don't emit color in output",
"Don't display the header",
"Print this help and exit",
"Print version and exit",
@@ -1956,6 +1958,7 @@ static int parseargs(int argc, char *argv[])
case 'L': use_ldcache = 1; break;
case 'y': scan_symlink = 0; break;
case 'A': scan_archives = 1; break;
+ case 'C': color_init(true); break;
case 'B': show_banner = 0; break;
case 'l': scan_ldpath = 1; break;
case 'p': scan_envpath = 1; break;
@@ -2121,6 +2124,7 @@ static char **get_split_env(const char *envvar)
static void parseenv(void)
{
+ color_init(false);
qa_textrels = get_split_env("QA_TEXTRELS");
qa_execstack = get_split_env("QA_EXECSTACK");
qa_wx_load = get_split_env("QA_WX_LOAD");
diff --git a/scanmacho.c b/scanmacho.c
index 5b89a03..009cfe5 100644
--- a/scanmacho.c
+++ b/scanmacho.c
@@ -1,7 +1,7 @@
/*
* Copyright 2008 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanmacho.c,v 1.19 2010/12/08 00:54:40 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanmacho.c,v 1.20 2010/12/08 01:16:01 vapier Exp $
*
* based on scanelf by:
* Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
@@ -10,7 +10,7 @@
* 2008-2010 Fabian Groffen - <grobian@gentoo.org>
*/
-static const char *rcsid = "$Id: scanmacho.c,v 1.19 2010/12/08 00:54:40 vapier Exp $";
+static const char *rcsid = "$Id: scanmacho.c,v 1.20 2010/12/08 01:16:01 vapier Exp $";
const char argv0[] = "scanmacho";
#include "paxinc.h"
@@ -497,8 +497,8 @@ static void scanmacho_envpath(void)
free(path);
}
-/* usage / invocation handling functions */ /* Free Flags: c d e j k l r s t u w x z C G H I J K L P Q T U W X Y */
-#define PARSE_FLAGS "pRmyAnibSN:gE:M:DO:ZaqvF:f:o:BhV"
+/* usage / invocation handling functions */ /* Free Flags: c d e j k l r s t u w x z G H I J K L P Q T U W X Y */
+#define PARSE_FLAGS "pRmyAnibSN:gE:M:DO:ZaqvF:f:o:CBhV"
#define a_argument required_argument
static struct option const long_opts[] = {
{"path", no_argument, NULL, 'p'},
@@ -523,6 +523,7 @@ static struct option const long_opts[] = {
{"format", a_argument, NULL, 'F'},
{"from", a_argument, NULL, 'f'},
{"file", a_argument, NULL, 'o'},
+ {"nocolor", no_argument, NULL, 'C'},
{"nobanner", no_argument, NULL, 'B'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
@@ -553,6 +554,7 @@ static const char *opts_help[] = {
"Use specified format for output",
"Read input stream from a filename",
"Write output stream to a filename",
+ "Don't emit color in output",
"Don't display the header",
"Print this help and exit",
"Print version and exit",
@@ -629,6 +631,7 @@ static int parseargs(int argc, char *argv[])
case 'g': g_match = 1; break;
case 'y': scan_symlink = 0; break;
case 'A': scan_archives = 1; break;
+ case 'C': color_init(true); break;
case 'B': show_banner = 0; break;
case 'p': scan_envpath = 1; break;
case 'R': dir_recurse = 1; break;
@@ -724,6 +727,7 @@ int main(int argc, char *argv[])
int ret;
if (argc < 2)
usage(EXIT_FAILURE);
+ color_init(false);
ret = parseargs(argc, argv);
fclose(stdout);
return ret;