public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  4:37 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  4:37 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 04:37:36

  Modified:             uname-test.c
  Log:
  sync in latest 8.24 changes

Revision  Changes    Path
1.4                  src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.4&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.4&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.3&r2=1.4

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- uname-test.c	4 Aug 2015 11:30:27 -0000	1.3
+++ uname-test.c	5 Aug 2015 04:37:36 -0000	1.4
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2014 Gentoo Foundation
+ * Copyright 2006-2015 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  */
 
@@ -29,6 +29,8 @@
 # endif
 
 const char *filename = CPUINFO_FILE;
+#undef CPUINFO_FILE
+#define CPUINFO_FILE filename
 
 # define PROCINFO_PROCESSOR      0
 # define PROCINFO_HARDWARE_PLATFORM 1
@@ -44,7 +46,16 @@
 	while (*tmp && isspace(*tmp))
 		tmp++;
 	if (tmp != buf)
-		memmove(buf, tmp, strlen(tmp) + 1);
+		memmove(buf, tmp, strlen(tmp)+1);
+	/* finally collapse whitespace */
+	tmp = buf;
+	while (tmp[0] && tmp[1]) {
+		if (isspace(tmp[0]) && isspace(tmp[1])) {
+			memmove(tmp, tmp+1, strlen(tmp));
+			continue;
+		}
+		++tmp;
+	}
 }
 
 static int __linux_procinfo (int x, char *fstr, size_t s)
@@ -88,7 +99,7 @@
 	if (verbose)
 		printf("### Looking for '%s':\n", procinfo_keys[x]);
 
-	if ((fp = fopen(filename, "r")) != NULL) {
+	if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
 		char key[65], value[257], eol, *ret = NULL;
 
 		while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:35 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:35 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:35:34

  Modified:             uname-test.c
  Log:
  switch to using GNU style for comments too

Revision  Changes    Path
1.16                 src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.16&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.16&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.15&r2=1.16

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- uname-test.c	5 Aug 2015 07:33:31 -0000	1.15
+++ uname-test.c	5 Aug 2015 07:35:34 -0000	1.16
@@ -47,17 +47,17 @@
 
 static void __eat_cpuinfo_space (char *buf)
 {
-	/* first eat trailing space */
+	/* First eat trailing space.  */
 	char *tmp = buf + strlen (buf) - 1;
 	while (tmp > buf && isspace (*tmp))
 		*tmp-- = '\0';
-	/* then eat leading space */
+	/* Then eat leading space.  */
 	tmp = buf;
 	while (*tmp && isspace (*tmp))
 		tmp++;
 	if (tmp != buf)
 		memmove (buf, tmp, strlen (tmp) + 1);
-	/* finally collapse whitespace */
+	/* Finally collapse whitespace.  */
 	tmp = buf;
 	while (tmp[0] && tmp[1]) {
 		if (isspace (tmp[0]) && isspace (tmp[1])) {
@@ -93,10 +93,9 @@
 				break;
 			}
 			if (eol != '\n') {
-				/* we need two fscanf's here in case the previous
-				 * length limit caused us to read right up to the
-				 * newline ... doing "%*[^\n]\n" wont eat the newline
-				 */
+				/* We need two fscanf's here in case the previous length limit
+				 * caused us to read right up to the newline.  Doing something
+				 * like "%*[^\n]\n" won't eat the newline.  */
 				ignore_value (fscanf (fp, "%*[^\n]"));
 				ignore_value (fscanf (fp, "\n"));
 			}





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:31 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:31 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:31:10

  Modified:             uname-test.c
  Log:
  switch to using GNU style

Revision  Changes    Path
1.14                 src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.14&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.14&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.13&r2=1.14

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- uname-test.c	5 Aug 2015 07:26:52 -0000	1.13
+++ uname-test.c	5 Aug 2015 07:31:10 -0000	1.14
@@ -24,9 +24,9 @@
 
 #define USE_PROCINFO
 
-#if defined(USE_PROCINFO)
+#if defined (USE_PROCINFO)
 
-# if defined(__s390__) || defined(__s390x__)
+# if defined (__s390__) || defined (__s390x__)
 #  define CPUINFO_FILE    "/proc/sysinfo"
 #  define CPUINFO_FORMAT  "%64[^\t :]%*[ :]%256[^\n]%c"
 # else
@@ -42,23 +42,23 @@
 # define PROCINFO_PROCESSOR      0
 # define PROCINFO_HARDWARE_PLATFORM 1
 
-static void __eat_cpuinfo_space(char *buf)
+static void __eat_cpuinfo_space (char *buf)
 {
 	/* first eat trailing space */
-	char *tmp = buf + strlen(buf) - 1;
-	while (tmp > buf && isspace(*tmp))
+	char *tmp = buf + strlen (buf) - 1;
+	while (tmp > buf && isspace (*tmp))
 		*tmp-- = '\0';
 	/* then eat leading space */
 	tmp = buf;
-	while (*tmp && isspace(*tmp))
+	while (*tmp && isspace (*tmp))
 		tmp++;
 	if (tmp != buf)
-		memmove(buf, tmp, strlen(tmp)+1);
+		memmove (buf, tmp, strlen (tmp) + 1);
 	/* finally collapse whitespace */
 	tmp = buf;
 	while (tmp[0] && tmp[1]) {
-		if (isspace(tmp[0]) && isspace(tmp[1])) {
-			memmove(tmp, tmp+1, strlen(tmp));
+		if (isspace (tmp[0]) && isspace (tmp[1])) {
+			memmove (tmp, tmp + 1, strlen (tmp));
 			continue;
 		}
 		++tmp;
@@ -75,17 +75,17 @@
 	};
 
 	if (verbose)
-		printf("### Looking for '%s':\n", procinfo_keys[x]);
+		printf ("### Looking for '%s':\n", procinfo_keys[x]);
 
-	if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
+	if ((fp = fopen (CPUINFO_FILE, "r")) != NULL) {
 		char key[65], value[257], eol, *ret = NULL;
 
-		while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
-			__eat_cpuinfo_space(key);
+		while (fscanf (fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
+			__eat_cpuinfo_space (key);
 			if (verbose)
-				printf("### \t%s -> %s\n", key, value);
-			if (!strcmp(key, procinfo_keys[x])) {
-				__eat_cpuinfo_space(value);
+				printf ("### \t%s -> %s\n", key, value);
+			if (!strcmp (key, procinfo_keys[x])) {
+				__eat_cpuinfo_space (value);
 				ret = value;
 				break;
 			}
@@ -94,14 +94,14 @@
 				 * length limit caused us to read right up to the
 				 * newline ... doing "%*[^\n]\n" wont eat the newline
 				 */
-				fscanf(fp, "%*[^\n]");
-				fscanf(fp, "\n");
+				fscanf (fp, "%*[^\n]");
+				fscanf (fp, "\n");
 			}
 		}
-		fclose(fp);
+		fclose (fp);
 
 		if (ret) {
-			strncpy(fstr, ret, s);
+			strncpy (fstr, ret, s);
 			return 0;
 		}
 	}





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:26 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:26 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:26:52

  Modified:             uname-test.c
  Log:
  add support for microblaze uname parsing

Revision  Changes    Path
1.13                 src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.13&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.13&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.12&r2=1.13

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- uname-test.c	5 Aug 2015 07:19:44 -0000	1.12
+++ uname-test.c	5 Aug 2015 07:26:52 -0000	1.13
@@ -157,6 +157,7 @@
 		{ "ia64",      "family",       "vendor" },
 		{ "hppa",      "cpu",          "model" },
 		{ "m68k",      "CPU",          "MMU" },
+		{ "microblaze","CPU-Ver",      "FPGA-Arch" },
 		{ "mips",      "cpu model",    "system type" },
 		{ "powerpc",   "cpu",          "machine" },
 		{ "s390",      "Type",         "Manufacturer" },





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:18 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:18 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:18:00

  Modified:             uname-test.c
  Log:
  support recursing into directories on the command line so we can quickly process the entire cpuinfo package

Revision  Changes    Path
1.11                 src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.11&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.11&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.10&r2=1.11

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- uname-test.c	5 Aug 2015 07:15:25 -0000	1.10
+++ uname-test.c	5 Aug 2015 07:18:00 -0000	1.11
@@ -5,6 +5,7 @@
 
 #define _GNU_SOURCE
 #include <ctype.h>
+#include <dirent.h>
 #include <err.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -12,6 +13,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 #ifndef ARRAY_SIZE
 # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
@@ -205,6 +208,56 @@
 	return ret;
 }
 
+static bool process_dir(const char *path)
+{
+	bool ret = true;
+	char *sub_path;
+
+	DIR *dir = opendir(path);
+	if (!dir)
+		err(1, "could not opendir %s", path);
+
+	struct dirent *de;
+	while ((de = readdir(dir)) != NULL) {
+		if (de->d_name[0] == '.')
+			continue;
+
+		asprintf(&sub_path, "%s/%s", path, de->d_name);
+		switch (de->d_type) {
+		case DT_REG:
+			if (!process_file(sub_path))
+				ret = false;
+			break;
+		case DT_DIR:
+			if (!process_dir(sub_path))
+				ret = false;
+			break;
+		}
+		free(sub_path);
+	}
+
+	closedir(dir);
+
+	return ret;
+}
+
+static bool process_one(const char *path)
+{
+	struct stat st;
+
+	if (stat(path, &st)) {
+		warn("could not stat %s", path);
+		return false;
+	}
+
+	if (S_ISREG(st.st_mode))
+		return process_file(path);
+	else if (S_ISDIR(st.st_mode))
+		return process_dir(path);
+	else
+		return false;
+}
+
 int main(int argc, char *argv[])
 {
 	int i, ret;
@@ -216,7 +269,7 @@
 			break;
 		default:
  usage:
-			errx(1, "Usage: uname-test [-v] <file> [files]");
+			errx(1, "Usage: uname-test [-v] <file|dir> [more paths]");
 		}
 	}
 	if (optind == argc)
@@ -224,7 +277,7 @@
 
 	ret = 0;
 	for (i = optind; i < argc; ++i)
-		if (!process_file(argv[i]))
+		if (!process_one(argv[i]))
 			ret = 1;
 
 	return ret;





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:15 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:15 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:15:25

  Modified:             uname-test.c
  Log:
  match on the basename of the file so we can pass in absolute paths to files

Revision  Changes    Path
1.10                 src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.10&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.10&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.9&r2=1.10

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- uname-test.c	5 Aug 2015 07:14:35 -0000	1.9
+++ uname-test.c	5 Aug 2015 07:15:25 -0000	1.10
@@ -3,6 +3,7 @@
  * Distributed under the terms of the GNU General Public License v2
  */
 
+#define _GNU_SOURCE
 #include <ctype.h>
 #include <err.h>
 #include <stdbool.h>
@@ -114,6 +115,8 @@
 
 static const char *procinfo_guess_arch(const char *file)
 {
+	file = basename(filename);
+
 	if (startswith(file, "blackfin"))
 		return "bfin";
 





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:14 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:14 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:14:35

  Modified:             uname-test.c
  Log:
  add support for common arch aliases so we can scan files from the cpuinfo package (and remove redundant prefixes from the look up list)

Revision  Changes    Path
1.9                  src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.9&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.9&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.8&r2=1.9

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- uname-test.c	5 Aug 2015 07:11:22 -0000	1.8
+++ uname-test.c	5 Aug 2015 07:14:35 -0000	1.9
@@ -112,6 +112,26 @@
 	return strncmp(s, prefix, strlen(prefix)) == 0 ? true : false;
 }
 
+static const char *procinfo_guess_arch(const char *file)
+{
+	if (startswith(file, "blackfin"))
+		return "bfin";
+
+	if (startswith(file, "x86"))
+		return "i386";
+
+	if (startswith(file, "parisc"))
+		return "hppa";
+
+	if (startswith(file, "ppc64"))
+		return "powerpc64";
+
+	if (startswith(file, "ppc"))
+		return "powerpc";
+
+	return file;
+}
+
 static bool procinfo_init(void)
 {
 	static const struct {
@@ -133,17 +153,16 @@
 		{ "m68k",      "CPU",          "MMU" },
 		{ "mips",      "cpu model",    "system type" },
 		{ "powerpc",   "cpu",          "machine" },
-		{ "powerpc64", "cpu",          "machine" },
 		{ "s390",      "Type",         "Manufacturer" },
-		{ "s390x",     "Type",         "Manufacturer" },
 		{ "sh",        "cpu type",     "machine" },
 		{ "sparc",     "type",         "cpu" },
 		{ "vax",       "cpu type",     "cpu" },
 	};
 
 	size_t i;
+	const char *arch = procinfo_guess_arch(filename);
 	for (i = 0; i < ARRAY_SIZE(procinfo_keys_all); ++i)
-		if (startswith(filename, procinfo_keys_all[i].arch)) {
+		if (startswith(arch, procinfo_keys_all[i].arch)) {
 			procinfo_processor = procinfo_keys_all[i].processor;
 			procinfo_platform = procinfo_keys_all[i].platform;
 			return true;





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:06 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:06 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:06:12

  Modified:             uname-test.c
  Log:
  add avr32 support that is already in the latest patchset

Revision  Changes    Path
1.7                  src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.7&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.7&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.6&r2=1.7

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- uname-test.c	5 Aug 2015 07:05:37 -0000	1.6
+++ uname-test.c	5 Aug 2015 07:06:12 -0000	1.7
@@ -123,6 +123,7 @@
 		{ "alpha",     "cpu model",    "system type" },
 		{ "amd64",     "model name",   "vendor_id" },
 		{ "arm",       "Processor",    "Hardware" },
+		{ "avr32",     "processor",    "cpu family" },
 		{ "bfin",      "CPU",          "BOARD Name" },
 		{ "cris",      "cpu",          "cpu model" },
 		{ "frv",       "CPU-Core",     "System" },





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:05 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:05 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:05:37

  Modified:             uname-test.c
  Log:
  pull procinfo init out of __linux_procinfo to try and minimize differences with real file (so it is eaiser to compare)

Revision  Changes    Path
1.6                  src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.6&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.6&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.5&r2=1.6

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- uname-test.c	5 Aug 2015 07:00:11 -0000	1.5
+++ uname-test.c	5 Aug 2015 07:05:37 -0000	1.6
@@ -30,6 +30,7 @@
 #  define CPUINFO_FORMAT  "%64[^\t:]\t:%256[^\n]%c"
 # endif
 
+const char *procinfo_processor, *procinfo_platform;
 const char *filename = CPUINFO_FILE;
 #undef CPUINFO_FILE
 #define CPUINFO_FILE filename
@@ -64,39 +65,10 @@
 {
 	FILE *fp;
 
-	static struct {
-		const char *arch;
-		const char *processor;
-		const char *platform;
-	} procinfo_keys_all[] = {
-		/* cpuname     --processor     --hardware-platform */
-		{ "alpha",     "cpu model",    "system type" },
-		{ "amd64",     "model name",   "vendor_id" },
-		{ "arm",       "Processor",    "Hardware" },
-		{ "bfin",      "CPU",          "BOARD Name" },
-		{ "cris",      "cpu",          "cpu model" },
-		{ "frv",       "CPU-Core",     "System" },
-		{ "i386",      "model name",   "vendor_id" },
-		{ "ia64",      "family",       "vendor" },
-		{ "hppa",      "cpu",          "model" },
-		{ "m68k",      "CPU",          "MMU" },
-		{ "mips",      "cpu model",    "system type" },
-		{ "powerpc",   "cpu",          "machine" },
-		{ "powerpc64", "cpu",          "machine" },
-		{ "s390",      "Type",         "Manufacturer" },
-		{ "s390x",     "Type",         "Manufacturer" },
-		{ "sh",        "cpu type",     "machine" },
-		{ "sparc",     "type",         "cpu" },
-		{ "vax",       "cpu type",     "cpu" },
+	const char * const procinfo_keys[] = {
+		/* --processor --hardware-platform */
+		procinfo_processor, procinfo_platform,
 	};
-	const char *procinfo_keys[] = { "", "" };
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(procinfo_keys_all); ++i)
-		if (!strncmp(filename, procinfo_keys_all[i].arch, strlen(procinfo_keys_all[i].arch))) {
-			procinfo_keys[PROCINFO_PROCESSOR] = procinfo_keys_all[i].processor;
-			procinfo_keys[PROCINFO_HARDWARE_PLATFORM] = procinfo_keys_all[i].platform;
-		}
 
 	if (verbose)
 		printf("### Looking for '%s':\n", procinfo_keys[x]);
@@ -135,6 +107,50 @@
 
 #endif
 
+static bool startswith(const char *s, const char *prefix)
+{
+	return strncmp(s, prefix, strlen(prefix)) == 0 ? true : false;
+}
+
+static bool procinfo_init(void)
+{
+	static const struct {
+		const char *arch;
+		const char *processor;
+		const char *platform;
+	} procinfo_keys_all[] = {
+		/* cpuname     --processor     --hardware-platform */
+		{ "alpha",     "cpu model",    "system type" },
+		{ "amd64",     "model name",   "vendor_id" },
+		{ "arm",       "Processor",    "Hardware" },
+		{ "bfin",      "CPU",          "BOARD Name" },
+		{ "cris",      "cpu",          "cpu model" },
+		{ "frv",       "CPU-Core",     "System" },
+		{ "i386",      "model name",   "vendor_id" },
+		{ "ia64",      "family",       "vendor" },
+		{ "hppa",      "cpu",          "model" },
+		{ "m68k",      "CPU",          "MMU" },
+		{ "mips",      "cpu model",    "system type" },
+		{ "powerpc",   "cpu",          "machine" },
+		{ "powerpc64", "cpu",          "machine" },
+		{ "s390",      "Type",         "Manufacturer" },
+		{ "s390x",     "Type",         "Manufacturer" },
+		{ "sh",        "cpu type",     "machine" },
+		{ "sparc",     "type",         "cpu" },
+		{ "vax",       "cpu type",     "cpu" },
+	};
+
+	size_t i;
+	for (i = 0; i < ARRAY_SIZE(procinfo_keys_all); ++i)
+		if (startswith(filename, procinfo_keys_all[i].arch)) {
+			procinfo_processor = procinfo_keys_all[i].processor;
+			procinfo_platform = procinfo_keys_all[i].platform;
+			return true;
+		}
+
+	warnx("could not detect arch with %s", filename);
+	return false;
+}
 
 int main(int argc, char *argv[])
 {
@@ -157,6 +173,10 @@
 
 	filename = argv[optind];
 	printf(">>> Parsing data out of %s\n", filename);
+
+	if (!procinfo_init())
+		return 1;
+
 	i = 0;
 
 	if (0 > __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor)) {





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-05  7:00 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-05  7:00 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/05 07:00:11

  Modified:             uname-test.c
  Log:
  use getopt to parse the command line

Revision  Changes    Path
1.5                  src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.5&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.5&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.4&r2=1.5

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- uname-test.c	5 Aug 2015 04:37:36 -0000	1.4
+++ uname-test.c	5 Aug 2015 07:00:11 -0000	1.5
@@ -3,12 +3,14 @@
  * Distributed under the terms of the GNU General Public License v2
  */
 
+#include <ctype.h>
+#include <err.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
+#include <unistd.h>
 
 #ifndef ARRAY_SIZE
 # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
@@ -140,14 +142,21 @@
 	static char hardware_platform[257];
 	int i;
 
-	for (i = 1; i < argc; ++i) {
-		if (!strcmp(argv[i], "-v"))
+	while ((i = getopt(argc, argv, "v")) != -1) {
+		switch (i) {
+		case 'v':
 			verbose = true;
-		else {
-			filename = argv[1];
-			printf(">>> Parsing data out of %s\n", filename);
+			break;
+		default:
+ usage:
+			errx(1, "Usage: uname-test [-v] <file>");
 		}
 	}
+	if (optind + 1 != argc)
+		goto usage;
+
+	filename = argv[optind];
+	printf(">>> Parsing data out of %s\n", filename);
 	i = 0;
 
 	if (0 > __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor)) {





^ permalink raw reply	[flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c
@ 2015-08-04 11:30 Mike Frysinger (vapier)
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2015-08-04 11:30 UTC (permalink / raw
  To: gentoo-commits

vapier      15/08/04 11:30:27

  Modified:             uname-test.c
  Log:
  modernize the code a bit -- no functional changes

Revision  Changes    Path
1.3                  src/patchsets/coreutils/uname-test/uname-test.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.3&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.3&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.2&r2=1.3

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- uname-test.c	24 Jun 2006 19:45:04 -0000	1.2
+++ uname-test.c	4 Aug 2015 11:30:27 -0000	1.3
@@ -1,9 +1,20 @@
+/*
+ * Copyright 2006-2014 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ */
+
+#include <stdbool.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 
-int verbose = 0;
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
+bool verbose = false;
 
 #define USE_PROCINFO
 
@@ -33,14 +44,14 @@
 	while (*tmp && isspace(*tmp))
 		tmp++;
 	if (tmp != buf)
-		memmove(buf, tmp, strlen(tmp)+1);
+		memmove(buf, tmp, strlen(tmp) + 1);
 }
 
 static int __linux_procinfo (int x, char *fstr, size_t s)
 {
 	FILE *fp;
 
-	struct {
+	static struct {
 		const char *arch;
 		const char *processor;
 		const char *platform;
@@ -68,7 +79,7 @@
 	const char *procinfo_keys[] = { "", "" };
 	int i;
 
-	for (i=0; i<sizeof(procinfo_keys_all)/sizeof(*procinfo_keys_all); ++i)
+	for (i = 0; i < ARRAY_SIZE(procinfo_keys_all); ++i)
 		if (!strncmp(filename, procinfo_keys_all[i].arch, strlen(procinfo_keys_all[i].arch))) {
 			procinfo_keys[PROCINFO_PROCESSOR] = procinfo_keys_all[i].processor;
 			procinfo_keys[PROCINFO_HARDWARE_PLATFORM] = procinfo_keys_all[i].platform;
@@ -79,7 +90,7 @@
 
 	if ((fp = fopen(filename, "r")) != NULL) {
 		char key[65], value[257], eol, *ret = NULL;
- 
+
 		while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
 			__eat_cpuinfo_space(key);
 			if (verbose)
@@ -118,9 +129,9 @@
 	static char hardware_platform[257];
 	int i;
 
-	for (i=1; i<argc; ++i) {
+	for (i = 1; i < argc; ++i) {
 		if (!strcmp(argv[i], "-v"))
-			++verbose;
+			verbose = true;
 		else {
 			filename = argv[1];
 			printf(">>> Parsing data out of %s\n", filename);





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-08-05  7:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-05  4:37 [gentoo-commits] gentoo commit in src/patchsets/coreutils/uname-test: uname-test.c Mike Frysinger (vapier)
  -- strict thread matches above, loose matches on Subject: below --
2015-08-05  7:35 Mike Frysinger (vapier)
2015-08-05  7:31 Mike Frysinger (vapier)
2015-08-05  7:26 Mike Frysinger (vapier)
2015-08-05  7:18 Mike Frysinger (vapier)
2015-08-05  7:15 Mike Frysinger (vapier)
2015-08-05  7:14 Mike Frysinger (vapier)
2015-08-05  7:06 Mike Frysinger (vapier)
2015-08-05  7:05 Mike Frysinger (vapier)
2015-08-05  7:00 Mike Frysinger (vapier)
2015-08-04 11:30 Mike Frysinger (vapier)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox