Blame SOURCES/0009-dmidecode-Add-helper-function-pr_comment.patch

f877e3
From 2241f1dd232fe8e1d57fdb2482ad417ebe23279e Mon Sep 17 00:00:00 2001
f877e3
From: Jean Delvare <jdelvare@suse.de>
f877e3
Date: Wed, 1 Apr 2020 09:51:46 +0200
f877e3
Subject: [PATCH 09/23] dmidecode: Add helper function pr_comment
f877e3
f877e3
Print all comments through a helper function pr_comment.
f877e3
f877e3
Signed-off-by: Jean Delvare <jdelvare@suse.de>
f877e3
---
f877e3
 Makefile    |  7 +++++--
f877e3
 dmidecode.c | 33 +++++++++++++++++----------------
f877e3
 dmioutput.c | 35 +++++++++++++++++++++++++++++++++++
f877e3
 dmioutput.h | 22 ++++++++++++++++++++++
f877e3
 4 files changed, 79 insertions(+), 18 deletions(-)
f877e3
 create mode 100644 dmioutput.c
f877e3
 create mode 100644 dmioutput.h
f877e3
f877e3
diff --git a/Makefile b/Makefile
f877e3
index 77c931091b0f..5d58266ef2de 100644
f877e3
--- a/Makefile
f877e3
+++ b/Makefile
f877e3
@@ -61,8 +61,8 @@ all : $(PROGRAMS)
f877e3
 # Programs
f877e3
 #
f877e3
 
f877e3
-dmidecode : dmidecode.o dmiopt.o dmioem.o util.o
f877e3
-	$(CC) $(LDFLAGS) dmidecode.o dmiopt.o dmioem.o util.o -o $@
f877e3
+dmidecode : dmidecode.o dmiopt.o dmioem.o dmioutput.o util.o
f877e3
+	$(CC) $(LDFLAGS) dmidecode.o dmiopt.o dmioem.o dmioutput.o util.o -o $@
f877e3
 
f877e3
 biosdecode : biosdecode.o util.o
f877e3
 	$(CC) $(LDFLAGS) biosdecode.o util.o -o $@
f877e3
@@ -87,6 +87,9 @@ dmiopt.o : dmiopt.c config.h types.h util.h dmidecode.h dmiopt.h
f877e3
 dmioem.o : dmioem.c types.h dmidecode.h dmioem.h
f877e3
 	$(CC) $(CFLAGS) -c $< -o $@
f877e3
 
f877e3
+dmioutput.o : dmioutput.c types.h dmioutput.h
f877e3
+	$(CC) $(CFLAGS) -c $< -o $@
f877e3
+
f877e3
 biosdecode.o : biosdecode.c version.h types.h util.h config.h 
f877e3
 	$(CC) $(CFLAGS) -c $< -o $@
f877e3
 
f877e3
diff --git a/dmidecode.c b/dmidecode.c
f877e3
index 8ec1d6b9597a..2939b2d307fc 100644
f877e3
--- a/dmidecode.c
f877e3
+++ b/dmidecode.c
f877e3
@@ -80,6 +80,7 @@
f877e3
 #include "dmidecode.h"
f877e3
 #include "dmiopt.h"
f877e3
 #include "dmioem.h"
f877e3
+#include "dmioutput.h"
f877e3
 
f877e3
 #define out_of_spec "<OUT OF SPEC>"
f877e3
 static const char *bad_index = "<BAD INDEX>";
f877e3
@@ -5162,7 +5163,7 @@ static void dmi_table_string(const struct dmi_header *h, const u8 *data, u16 ver
f877e3
 static void dmi_table_dump(const u8 *buf, u32 len)
f877e3
 {
f877e3
 	if (!(opt.flags & FLAG_QUIET))
f877e3
-		printf("# Writing %d bytes to %s.\n", len, opt.dumpfile);
f877e3
+		pr_comment("Writing %d bytes to %s.", len, opt.dumpfile);
f877e3
 	write_dump(32, len, buf, opt.dumpfile, 0);
f877e3
 }
f877e3
 
f877e3
@@ -5283,11 +5284,11 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
f877e3
 
f877e3
 	if (ver > SUPPORTED_SMBIOS_VER && !(opt.flags & FLAG_QUIET))
f877e3
 	{
f877e3
-		printf("# SMBIOS implementations newer than version %u.%u.%u are not\n"
f877e3
-		       "# fully supported by this version of dmidecode.\n",
f877e3
-		       SUPPORTED_SMBIOS_VER >> 16,
f877e3
-		       (SUPPORTED_SMBIOS_VER >> 8) & 0xFF,
f877e3
-		       SUPPORTED_SMBIOS_VER & 0xFF);
f877e3
+		pr_comment("SMBIOS implementations newer than version %u.%u.%u are not",
f877e3
+			   SUPPORTED_SMBIOS_VER >> 16,
f877e3
+			   (SUPPORTED_SMBIOS_VER >> 8) & 0xFF,
f877e3
+			   SUPPORTED_SMBIOS_VER & 0xFF);
f877e3
+		pr_comment("fully supported by this version of dmidecode.");
f877e3
 	}
f877e3
 
f877e3
 	if (!(opt.flags & FLAG_QUIET))
f877e3
@@ -5417,8 +5418,8 @@ static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
f877e3
 		overwrite_smbios3_address(crafted);
f877e3
 
f877e3
 		if (!(opt.flags & FLAG_QUIET))
f877e3
-			printf("# Writing %d bytes to %s.\n", crafted[0x06],
f877e3
-			       opt.dumpfile);
f877e3
+			pr_comment("Writing %d bytes to %s.", crafted[0x06],
f877e3
+				   opt.dumpfile);
f877e3
 		write_dump(0, crafted[0x06], crafted, opt.dumpfile, 1);
f877e3
 	}
f877e3
 
f877e3
@@ -5478,8 +5479,8 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
f877e3
 		overwrite_dmi_address(crafted + 0x10);
f877e3
 
f877e3
 		if (!(opt.flags & FLAG_QUIET))
f877e3
-			printf("# Writing %d bytes to %s.\n", crafted[0x05],
f877e3
-				opt.dumpfile);
f877e3
+			pr_comment("Writing %d bytes to %s.", crafted[0x05],
f877e3
+				   opt.dumpfile);
f877e3
 		write_dump(0, crafted[0x05], crafted, opt.dumpfile, 1);
f877e3
 	}
f877e3
 
f877e3
@@ -5507,8 +5508,8 @@ static int legacy_decode(u8 *buf, const char *devmem, u32 flags)
f877e3
 		overwrite_dmi_address(crafted);
f877e3
 
f877e3
 		if (!(opt.flags & FLAG_QUIET))
f877e3
-			printf("# Writing %d bytes to %s.\n", 0x0F,
f877e3
-				opt.dumpfile);
f877e3
+			pr_comment("Writing %d bytes to %s.", 0x0F,
f877e3
+				   opt.dumpfile);
f877e3
 		write_dump(0, 0x0F, crafted, opt.dumpfile, 1);
f877e3
 	}
f877e3
 
f877e3
@@ -5586,8 +5587,8 @@ static int address_from_efi(off_t *address)
f877e3
 #endif
f877e3
 
f877e3
 	if (ret == 0 && !(opt.flags & FLAG_QUIET))
f877e3
-		printf("# %s entry point at 0x%08llx\n",
f877e3
-		       eptype, (unsigned long long)*address);
f877e3
+		pr_comment("%s entry point at 0x%08llx",
f877e3
+			   eptype, (unsigned long long)*address);
f877e3
 
f877e3
 	return ret;
f877e3
 }
f877e3
@@ -5638,7 +5639,7 @@ int main(int argc, char * const argv[])
f877e3
 	}
f877e3
 
f877e3
 	if (!(opt.flags & FLAG_QUIET))
f877e3
-		printf("# dmidecode %s\n", VERSION);
f877e3
+		pr_comment("dmidecode %s", VERSION);
f877e3
 
f877e3
 	/* Read from dump if so instructed */
f877e3
 	if (opt.flags & FLAG_FROM_DUMP)
f877e3
@@ -5783,7 +5784,7 @@ int main(int argc, char * const argv[])
f877e3
 
f877e3
 done:
f877e3
 	if (!found && !(opt.flags & FLAG_QUIET))
f877e3
-		printf("# No SMBIOS nor DMI entry point found, sorry.\n");
f877e3
+		pr_comment("No SMBIOS nor DMI entry point found, sorry.");
f877e3
 
f877e3
 	free(buf);
f877e3
 exit_free:
f877e3
diff --git a/dmioutput.c b/dmioutput.c
f877e3
new file mode 100644
f877e3
index 000000000000..e762a035f39d
f877e3
--- /dev/null
f877e3
+++ b/dmioutput.c
f877e3
@@ -0,0 +1,35 @@
f877e3
+/*
f877e3
+ * Generic output functions
f877e3
+ * This file is part of the dmidecode project.
f877e3
+ *
f877e3
+ *   Copyright (C) 2020 Jean Delvare <jdelvare@suse.de>
f877e3
+ *
f877e3
+ *   This program is free software; you can redistribute it and/or modify
f877e3
+ *   it under the terms of the GNU General Public License as published by
f877e3
+ *   the Free Software Foundation; either version 2 of the License, or
f877e3
+ *   (at your option) any later version.
f877e3
+ *
f877e3
+ *   This program is distributed in the hope that it will be useful,
f877e3
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
f877e3
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f877e3
+ *   GNU General Public License for more details.
f877e3
+ *
f877e3
+ *   You should have received a copy of the GNU General Public License
f877e3
+ *   along with this program; if not, write to the Free Software
f877e3
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
f877e3
+ */
f877e3
+
f877e3
+#include <stdarg.h>
f877e3
+#include <stdio.h>
f877e3
+#include "dmioutput.h"
f877e3
+
f877e3
+void pr_comment(const char *format, ...)
f877e3
+{
f877e3
+	va_list args;
f877e3
+
f877e3
+	printf("# ");
f877e3
+	va_start(args, format);
f877e3
+	vprintf(format, args);
f877e3
+	va_end(args);
f877e3
+	printf("\n");
f877e3
+}
f877e3
diff --git a/dmioutput.h b/dmioutput.h
f877e3
new file mode 100644
f877e3
index 000000000000..b6cf5ee8b60e
f877e3
--- /dev/null
f877e3
+++ b/dmioutput.h
f877e3
@@ -0,0 +1,22 @@
f877e3
+/*
f877e3
+ * Generic output functions
f877e3
+ * This file is part of the dmidecode project.
f877e3
+ *
f877e3
+ *   Copyright (C) 2020 Jean Delvare <jdelvare@suse.de>
f877e3
+ *
f877e3
+ *   This program is free software; you can redistribute it and/or modify
f877e3
+ *   it under the terms of the GNU General Public License as published by
f877e3
+ *   the Free Software Foundation; either version 2 of the License, or
f877e3
+ *   (at your option) any later version.
f877e3
+ *
f877e3
+ *   This program is distributed in the hope that it will be useful,
f877e3
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
f877e3
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f877e3
+ *   GNU General Public License for more details.
f877e3
+ *
f877e3
+ *   You should have received a copy of the GNU General Public License
f877e3
+ *   along with this program; if not, write to the Free Software
f877e3
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
f877e3
+ */
f877e3
+
f877e3
+void pr_comment(const char *format, ...);
f877e3
-- 
f877e3
2.17.1
f877e3