flashrom.c: Move print logic to print.c

This free's up flashrom.c from namespace pollution.

Change-Id: I2724f7910fa3e01bcf49b8093260a4f1643df777
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/66652
Original-Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72351
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/flashrom.c b/flashrom.c
index c7ad92c..d08c130 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -27,9 +27,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <ctype.h>
-#if HAVE_UTSNAME == 1
-#include <sys/utsname.h>
-#endif
+
 #include "flash.h"
 #include "flashchips.h"
 #include "programmer.h"
@@ -1378,86 +1376,6 @@
 	}
 }
 
-static void print_sysinfo(void)
-{
-#if IS_WINDOWS
-	SYSTEM_INFO si = { 0 };
-	OSVERSIONINFOEX osvi = { 0 };
-
-	msg_ginfo(" on Windows");
-	/* Tell Windows which version of the structure we want. */
-	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
-	if (GetVersionEx((OSVERSIONINFO*) &osvi))
-		msg_ginfo(" %lu.%lu", osvi.dwMajorVersion, osvi.dwMinorVersion);
-	else
-		msg_ginfo(" unknown version");
-	GetSystemInfo(&si);
-	switch (si.wProcessorArchitecture) {
-	case PROCESSOR_ARCHITECTURE_AMD64:
-		msg_ginfo(" (x86_64)");
-		break;
-	case PROCESSOR_ARCHITECTURE_INTEL:
-		msg_ginfo(" (x86)");
-		break;
-	default:
-		msg_ginfo(" (unknown arch)");
-		break;
-	}
-#elif HAVE_UTSNAME == 1
-	struct utsname osinfo;
-
-	uname(&osinfo);
-	msg_ginfo(" on %s %s (%s)", osinfo.sysname, osinfo.release,
-		  osinfo.machine);
-#else
-	msg_ginfo(" on unknown machine");
-#endif
-}
-
-void print_buildinfo(void)
-{
-	msg_gdbg("flashrom was built with");
-#ifdef __clang__
-	msg_gdbg(" LLVM Clang");
-#ifdef __clang_version__
-	msg_gdbg(" %s,", __clang_version__);
-#else
-	msg_gdbg(" unknown version (before r102686),");
-#endif
-#elif defined(__GNUC__)
-	msg_gdbg(" GCC");
-#ifdef __VERSION__
-	msg_gdbg(" %s,", __VERSION__);
-#else
-	msg_gdbg(" unknown version,");
-#endif
-#else
-	msg_gdbg(" unknown compiler,");
-#endif
-#if defined (__FLASHROM_LITTLE_ENDIAN__)
-	msg_gdbg(" little endian");
-#elif defined (__FLASHROM_BIG_ENDIAN__)
-	msg_gdbg(" big endian");
-#else
-#error Endianness could not be determined
-#endif
-	msg_gdbg("\n");
-}
-
-void print_version(void)
-{
-	msg_ginfo("flashrom-stable %s", flashrom_version);
-	print_sysinfo();
-	msg_ginfo("\n");
-}
-
-void print_banner(void)
-{
-	msg_ginfo("flashrom is free software, get the source code at "
-		  "https://flashrom.org\n");
-	msg_ginfo("\n");
-}
-
 int selfcheck(void)
 {
 	unsigned int i;
diff --git a/include/flash.h b/include/flash.h
index 27b3aae..38e583a 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -383,6 +383,9 @@
 void chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
 
 /* print.c */
+void print_buildinfo(void);
+void print_version(void);
+void print_banner(void);
 int print_supported(void);
 void print_supported_wiki(void);
 
@@ -418,9 +421,6 @@
 int probe_flash(struct registered_master *mst, int startchip, struct flashctx *fill_flash, int force);
 int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len);
 void emergency_help_message(void);
-void print_version(void);
-void print_buildinfo(void);
-void print_banner(void);
 void list_programmers_linebreak(int startcol, int cols, int paren);
 int selfcheck(void);
 int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename);
diff --git a/print.c b/print.c
index 1f6bece..b1511ad 100644
--- a/print.c
+++ b/print.c
@@ -20,9 +20,98 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stddef.h>
+#if HAVE_UTSNAME == 1
+#include <sys/utsname.h>
+#endif
+#if IS_WINDOWS
+#include <windows.h>
+#undef min
+#undef max
+#endif
+
 #include "flash.h"
 #include "programmer.h"
 
+static void print_sysinfo(void)
+{
+#if IS_WINDOWS
+	SYSTEM_INFO si = { 0 };
+	OSVERSIONINFOEX osvi = { 0 };
+
+	msg_ginfo(" on Windows");
+	/* Tell Windows which version of the structure we want. */
+	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+	if (GetVersionEx((OSVERSIONINFO*) &osvi))
+		msg_ginfo(" %lu.%lu", osvi.dwMajorVersion, osvi.dwMinorVersion);
+	else
+		msg_ginfo(" unknown version");
+	GetSystemInfo(&si);
+	switch (si.wProcessorArchitecture) {
+	case PROCESSOR_ARCHITECTURE_AMD64:
+		msg_ginfo(" (x86_64)");
+		break;
+	case PROCESSOR_ARCHITECTURE_INTEL:
+		msg_ginfo(" (x86)");
+		break;
+	default:
+		msg_ginfo(" (unknown arch)");
+		break;
+	}
+#elif HAVE_UTSNAME == 1
+	struct utsname osinfo;
+
+	uname(&osinfo);
+	msg_ginfo(" on %s %s (%s)", osinfo.sysname, osinfo.release,
+		  osinfo.machine);
+#else
+	msg_ginfo(" on unknown machine");
+#endif
+}
+
+void print_buildinfo(void)
+{
+	msg_gdbg("flashrom was built with");
+#ifdef __clang__
+	msg_gdbg(" LLVM Clang");
+#ifdef __clang_version__
+	msg_gdbg(" %s,", __clang_version__);
+#else
+	msg_gdbg(" unknown version (before r102686),");
+#endif
+#elif defined(__GNUC__)
+	msg_gdbg(" GCC");
+#ifdef __VERSION__
+	msg_gdbg(" %s,", __VERSION__);
+#else
+	msg_gdbg(" unknown version,");
+#endif
+#else
+	msg_gdbg(" unknown compiler,");
+#endif
+#if defined (__FLASHROM_LITTLE_ENDIAN__)
+	msg_gdbg(" little endian");
+#elif defined (__FLASHROM_BIG_ENDIAN__)
+	msg_gdbg(" big endian");
+#else
+#error Endianness could not be determined
+#endif
+	msg_gdbg("\n");
+}
+
+void print_version(void)
+{
+	msg_ginfo("flashrom-stable %s", flashrom_version);
+	print_sysinfo();
+	msg_ginfo("\n");
+}
+
+void print_banner(void)
+{
+	msg_ginfo("flashrom is free software, get the source code at "
+		  "https://flashrom.org\n");
+	msg_ginfo("\n");
+}
+
 static const char *test_state_to_text(enum test_state test_state)
 {
 	switch (test_state) {