dmidecode-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dmidecode] [PATCH 01/11] dmidecode: Add helper function pr_comment


From: Jean Delvare
Subject: [dmidecode] [PATCH 01/11] dmidecode: Add helper function pr_comment
Date: Tue, 24 Mar 2020 17:37:35 +0100

Print all comments through a helper function pr_comment.

Signed-off-by: Jean Delvare <address@hidden>
---
 Makefile    |    7 +++++--
 dmidecode.c |   33 +++++++++++++++++----------------
 dmioutput.c |   35 +++++++++++++++++++++++++++++++++++
 dmioutput.h |   22 ++++++++++++++++++++++
 4 files changed, 79 insertions(+), 18 deletions(-)

--- dmidecode.orig/Makefile     2020-03-16 10:27:50.975981949 +0100
+++ dmidecode/Makefile  2020-03-24 14:59:01.996226975 +0100
@@ -61,8 +61,8 @@ all : $(PROGRAMS)
 # Programs
 #
 
-dmidecode : dmidecode.o dmiopt.o dmioem.o util.o
-       $(CC) $(LDFLAGS) dmidecode.o dmiopt.o dmioem.o util.o -o $@
+dmidecode : dmidecode.o dmiopt.o dmioem.o dmioutput.o util.o
+       $(CC) $(LDFLAGS) dmidecode.o dmiopt.o dmioem.o dmioutput.o util.o -o $@
 
 biosdecode : biosdecode.o util.o
        $(CC) $(LDFLAGS) biosdecode.o util.o -o $@
@@ -87,6 +87,9 @@ dmiopt.o : dmiopt.c config.h types.h uti
 dmioem.o : dmioem.c types.h dmidecode.h dmioem.h
        $(CC) $(CFLAGS) -c $< -o $@
 
+dmioutput.o : dmioutput.c types.h dmioutput.h
+       $(CC) $(CFLAGS) -c $< -o $@
+
 biosdecode.o : biosdecode.c version.h types.h util.h config.h 
        $(CC) $(CFLAGS) -c $< -o $@
 
--- dmidecode.orig/dmidecode.c  2020-03-24 14:58:55.311145563 +0100
+++ dmidecode/dmidecode.c       2020-03-24 14:59:01.997226987 +0100
@@ -80,6 +80,7 @@
 #include "dmidecode.h"
 #include "dmiopt.h"
 #include "dmioem.h"
+#include "dmioutput.h"
 
 #define out_of_spec "<OUT OF SPEC>"
 static const char *bad_index = "<BAD INDEX>";
@@ -5162,7 +5163,7 @@ static void dmi_table_string(const struc
 static void dmi_table_dump(const u8 *buf, u32 len)
 {
        if (!(opt.flags & FLAG_QUIET))
-               printf("# Writing %d bytes to %s.\n", len, opt.dumpfile);
+               pr_comment("Writing %d bytes to %s.", len, opt.dumpfile);
        write_dump(32, len, buf, opt.dumpfile, 0);
 }
 
@@ -5283,11 +5284,11 @@ static void dmi_table(off_t base, u32 le
 
        if (ver > SUPPORTED_SMBIOS_VER && !(opt.flags & FLAG_QUIET))
        {
-               printf("# SMBIOS implementations newer than version %u.%u.%u 
are not\n"
-                      "# fully supported by this version of dmidecode.\n",
-                      SUPPORTED_SMBIOS_VER >> 16,
-                      (SUPPORTED_SMBIOS_VER >> 8) & 0xFF,
-                      SUPPORTED_SMBIOS_VER & 0xFF);
+               pr_comment("SMBIOS implementations newer than version %u.%u.%u 
are not",
+                          SUPPORTED_SMBIOS_VER >> 16,
+                          (SUPPORTED_SMBIOS_VER >> 8) & 0xFF,
+                          SUPPORTED_SMBIOS_VER & 0xFF);
+               pr_comment("fully supported by this version of dmidecode.");
        }
 
        if (!(opt.flags & FLAG_QUIET))
@@ -5417,8 +5418,8 @@ static int smbios3_decode(u8 *buf, const
                overwrite_smbios3_address(crafted);
 
                if (!(opt.flags & FLAG_QUIET))
-                       printf("# Writing %d bytes to %s.\n", crafted[0x06],
-                              opt.dumpfile);
+                       pr_comment("Writing %d bytes to %s.", crafted[0x06],
+                                  opt.dumpfile);
                write_dump(0, crafted[0x06], crafted, opt.dumpfile, 1);
        }
 
@@ -5478,8 +5479,8 @@ static int smbios_decode(u8 *buf, const
                overwrite_dmi_address(crafted + 0x10);
 
                if (!(opt.flags & FLAG_QUIET))
-                       printf("# Writing %d bytes to %s.\n", crafted[0x05],
-                               opt.dumpfile);
+                       pr_comment("Writing %d bytes to %s.", crafted[0x05],
+                                  opt.dumpfile);
                write_dump(0, crafted[0x05], crafted, opt.dumpfile, 1);
        }
 
@@ -5507,8 +5508,8 @@ static int legacy_decode(u8 *buf, const
                overwrite_dmi_address(crafted);
 
                if (!(opt.flags & FLAG_QUIET))
-                       printf("# Writing %d bytes to %s.\n", 0x0F,
-                               opt.dumpfile);
+                       pr_comment("Writing %d bytes to %s.", 0x0F,
+                                  opt.dumpfile);
                write_dump(0, 0x0F, crafted, opt.dumpfile, 1);
        }
 
@@ -5586,8 +5587,8 @@ static int address_from_efi(off_t *addre
 #endif
 
        if (ret == 0 && !(opt.flags & FLAG_QUIET))
-               printf("# %s entry point at 0x%08llx\n",
-                      eptype, (unsigned long long)*address);
+               pr_comment("%s entry point at 0x%08llx",
+                          eptype, (unsigned long long)*address);
 
        return ret;
 }
@@ -5638,7 +5639,7 @@ int main(int argc, char * const argv[])
        }
 
        if (!(opt.flags & FLAG_QUIET))
-               printf("# dmidecode %s\n", VERSION);
+               pr_comment("dmidecode %s", VERSION);
 
        /* Read from dump if so instructed */
        if (opt.flags & FLAG_FROM_DUMP)
@@ -5783,7 +5784,7 @@ int main(int argc, char * const argv[])
 
 done:
        if (!found && !(opt.flags & FLAG_QUIET))
-               printf("# No SMBIOS nor DMI entry point found, sorry.\n");
+               pr_comment("No SMBIOS nor DMI entry point found, sorry.");
 
        free(buf);
 exit_free:
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ dmidecode/dmioutput.c       2020-03-24 14:59:01.997226987 +0100
@@ -0,0 +1,35 @@
+/*
+ * Generic output functions
+ * This file is part of the dmidecode project.
+ *
+ *   Copyright (C) 2020 Jean Delvare <address@hidden>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include "dmioutput.h"
+
+void pr_comment(const char *format, ...)
+{
+       va_list args;
+
+       printf("# ");
+       va_start(args, format);
+       vprintf(format, args);
+       va_end(args);
+       printf("\n");
+}
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ dmidecode/dmioutput.h       2020-03-24 14:59:01.997226987 +0100
@@ -0,0 +1,22 @@
+/*
+ * Generic output functions
+ * This file is part of the dmidecode project.
+ *
+ *   Copyright (C) 2020 Jean Delvare <address@hidden>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+void pr_comment(const char *format, ...);

-- 
Jean Delvare
SUSE L3 Support



reply via email to

[Prev in Thread] Current Thread [Next in Thread]