Commits

Palmer, 2E0EOL committed 43bfe38 Draft

Define Log(), which accepts options and log level for the current message.

Comments (0)

Files changed (1)

 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <unistd.h>
 
 #include "dlhomesym.h"
 );
 static unsigned short int IsExcludedHome(const char *HomeEnt);
 static int LinkCleanup(
+	const struct s_opts *const Opts,
 	const char *HomeRootLnk,
 	char **UserList, const int UserListMarker
 );
 static int ProcessOptions(struct s_opts *Opts, int ArgC, char **ArgV);
+static void Log(
+	const struct s_opts *const Opts,
+	const unsigned int Level,
+	const char *Format, ...
+);
 /*-------------------------------------------------------------------------*/
 static int EnumHomes(
 	char **Homes, const int MaxHomes,
 }
 /*-------------------------------------------------------------------------*/
 static int LinkCleanup(
+	const struct s_opts *const Opts,
 	const char *HomeRootLnk,
 	char **UserList, const int UserListMarker
 ) {
 			fullLinkPath = GluePath(HomeRootLnk, ent->d_name);
 			if ( !fullLinkPath ) continue;
 
-			fprintf(stderr, "Doing stat on %s\n", fullLinkPath);
+			Log(Opts, 10, "Doing stat on %s", fullLinkPath);
 			if ( lstat(fullLinkPath, &statEnt) == 0 ) {
 				if ( !S_ISLNK(statEnt.st_mode) )
 					continue;
 	return 0;
 }
 /*-------------------------------------------------------------------------*/
+static void Log(
+	const struct s_opts *const Opts,
+	const unsigned int Level,
+	const char *Format, ...
+) {
+	va_list args;
+
+	va_start(args, Format);
+	if ( Opts->debug_level >= Level ) {
+		vfprintf(stderr, Format, args);
+		fputs("\n", stderr);
+	}
+	va_end(args);
+	return;
+}
+/*-------------------------------------------------------------------------*/
 int main(int argc, char *argv[])
 {
 	static struct s_opts opts;
 	}
 	/* Just debug to see what the userList consists of */
 	DumpUserList(userList, userListMarker);
-	nCleanup = LinkCleanup(homeRootLnk, userList, userListMarker);
+	nCleanup = LinkCleanup(&opts, homeRootLnk, userList, userListMarker);
 	if ( nCleanup < 0 ) {
 		fprintf(
 			stderr, "Error cleaning links from %s\n",