summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2020-04-01 09:51:46 +0200
committerJean Delvare <jdelvare@suse.de>2020-04-01 09:51:46 +0200
commit2241f1dd232fe8e1d57fdb2482ad417ebe23279e (patch)
tree38d615cdb312adc63ab00b892dc9d31665b19b05
parent26a66d708c6caef09912245c93371ec96c1e0cbd (diff)
downloaddmidecode-git-2241f1dd232fe8e1d57fdb2482ad417ebe23279e.tar.gz
dmidecode: Add helper function pr_comment
Print all comments through a helper function pr_comment. Signed-off-by: Jean Delvare <jdelvare@suse.de>
-rw-r--r--Makefile7
-rw-r--r--dmidecode.c33
-rw-r--r--dmioutput.c35
-rw-r--r--dmioutput.h22
4 files changed, 79 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 77c9310..5d58266 100644
--- a/Makefile
+++ b/Makefile
@@ -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 util.h dmidecode.h dmiopt.h
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 $@
diff --git a/dmidecode.c b/dmidecode.c
index 8ec1d6b..2939b2d 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -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 struct dmi_header *h, const u8 *data, u16 ver
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 len, u16 num, u32 ver, const char *devmem,
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 char *devmem, u32 flags)
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 char *devmem, u32 flags)
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 char *devmem, u32 flags)
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 *address)
#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 @@ memory_scan:
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:
diff --git a/dmioutput.c b/dmioutput.c
new file mode 100644
index 0000000..e762a03
--- /dev/null
+++ b/dmioutput.c
@@ -0,0 +1,35 @@
+/*
+ * Generic output functions
+ * This file is part of the dmidecode project.
+ *
+ * Copyright (C) 2020 Jean Delvare <jdelvare@suse.de>
+ *
+ * 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");
+}
diff --git a/dmioutput.h b/dmioutput.h
new file mode 100644
index 0000000..b6cf5ee
--- /dev/null
+++ b/dmioutput.h
@@ -0,0 +1,22 @@
+/*
+ * Generic output functions
+ * This file is part of the dmidecode project.
+ *
+ * Copyright (C) 2020 Jean Delvare <jdelvare@suse.de>
+ *
+ * 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, ...);