⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log.c

📁 内存检测程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  MSS -- Memory Supervision System version 1.2 *  Copyright (C) 1998  Juan Jesus Alcolea Picazo and Peter Palotas * *  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., 675 Mass Ave, Cambridge, MA 02139, USA. * *  You can contact the authors of this library at the following e-mail *  addreses. For more information, look in the documentation that came *  with this library. * *  Juan Jesus Alcolea Picazo, a920101@zipi.fi.upm.es *  Peter Palotas, blizzar@hem1.passagen.se * */#define __mss_internal__#include <stdio.h>#include <time.h>#include <stdarg.h>#include "internal.h"#include "mss.h"/* Temporary string used by some functions... Not reentrant, but   multi-threading is disabled in all of them anyway...   If that is possible. */static char tmpstr[1024];const char mss_separator[] = "------------------------------------------------------------------------------\n";const char mss_separator2[] = "******************************************************************************\n";FILE *mss_logfile = NULL;         /* output file */FILE *mss_slogfile = NULL;	  /* Special logfile *//* get_time():   This function will return a string representating the current time, just   a little helper function for the rest of the functions. */static char *get_time(void){	time_t now;	time(&now);	return ctime(&now);}/* mss_log_header():   This function will write some start information to the logfile.  It's only   called by mss_startup(), and doesn't need any further explanation! ;) */void mss_log_header(void){	int i = 0;	char *s;	mss_disable_threading();	fprintf(mss_logfile, "%s", mss_separator);	fprintf(mss_logfile, "MSS -- Memory Supervision System version %s\n", MSS_VERSION);	fprintf(mss_logfile, "Copyright (C) 1998  Juan Jesus Alcolea Picazo and Peter Palotas\n\n");	fprintf(mss_logfile, "MSS Normal Logfile.\n\n");	mss_slog("VERSION: MSS=\"" MSS_VERSION "\"\n");	mss_slog("INIT: ENVVAR=\"%s\" ", getenv(MSS_CONFIG_ENVVAR) == NULL ? "" : getenv(MSS_CONFIG_ENVVAR));	if (MSS_CFG_STATUS & MSS_CFG_STATUS_NO_ENVVAR)	{		fprintf(mss_logfile, mss_word_wrap("WARNING", "Environment variable `MSS_CFG' not set. Unable to use global configuration file.\n"));	}	if (MSS_CFG_STATUS & MSS_CFG_STATUS_NO_GLOBAL_FILE)	{		mss_slog("GLOBAL=\"False\" ");		if (!(MSS_CFG_STATUS & MSS_CFG_STATUS_NO_ENVVAR))		{	 		fprintf(mss_logfile, mss_word_wrap("WARNING", "Environment variable `MSS_CFG' does not point to an existing file. No global configuration file could be loaded.\n"));		}	}	else /* Global exists */	{	 	mss_slog("GLOBAL=\"True\" ");	}	if (MSS_CFG_STATUS & MSS_CFG_STATUS_NO_LOCAL_FILE)	{		mss_slog("LOCAL=\"False\" ");		if (MSS_CFG_STATUS & MSS_CFG_STATUS_NO_GLOBAL_FILE)		{		 	fprintf(mss_logfile, mss_word_wrap("WARNING", "No local configuration file found either, using hard-coded default values only.\n"));		}		else /* Global exists, local doesn't */		{		 	fprintf(mss_logfile, mss_word_wrap("WARNING", "No local configuration file found, using options from global configuration file to override hard-coded values.\n"));		}	}	else /* Local exists */	{	 	mss_slog("LOCAL=\"True\" ");		if (!(MSS_CFG_STATUS & MSS_CFG_STATUS_NO_GLOBAL_FILE))		{ /* Global exists too :) */			fprintf(mss_logfile, mss_word_wrap("NOTE", "Using global configuration file pointed to by environment variable `MSS_CFG', and local configuration file in current directory to override hard-coded default values.\n"));		}	}	mss_slog("LOCALCFGFILE=\"%s\"\n", MSS_LOCAL_CONFIG_FILENAME);	fprintf(mss_logfile, "\nOption List:\n\n");	while (mss_config_options[i].type != MSS_CONFIG_TYPE_END)	{		mss_slog("OPTION: NAME=\"%s\" ", mss_config_options[i].name);		switch (mss_config_options[i].type)		{			case MSS_CONFIG_TYPE_BOOL:				mss_slog("VALUE=\"%s\" ", *((int *)mss_config_options[i].value) == 0 ? "No" : "Yes");				fprintf(mss_logfile, "%-35s %-14s", mss_config_options[i].name, *((int *)mss_config_options[i].value) == 0 ? "No" : "Yes");				break;			case MSS_CONFIG_TYPE_INT:				mss_slog("VALUE=\"%i\" ", *((int *)mss_config_options[i].value));				fprintf(mss_logfile, "%-35s %-14i", mss_config_options[i].name, *((int *)mss_config_options[i].value));				break;			case MSS_CONFIG_TYPE_HEX:				mss_slog("VALUE=\"%i\" ", *((int *)mss_config_options[i].value));				fprintf(mss_logfile, "%-35s 0x%-12X", mss_config_options[i].name, *((int *)mss_config_options[i].value));				break;			case MSS_CONFIG_TYPE_STRING:				mss_slog("VALUE=\"%s\" ", (char *)mss_config_options[i].value);				fprintf(mss_logfile, "%-35s %-14s", mss_config_options[i].name, (char *)mss_config_options[i].value);				break;		};		mss_slog("FROM=\"%s\"\n", mss_config_options[i].where == MSS_CONFIG_WHERE_DEFAULT ? "Default" : mss_config_options[i].where == MSS_CONFIG_WHERE_LOCAL ? "Local" : "Global");		fprintf(mss_logfile, " %s\n", mss_config_options[i].where == MSS_CONFIG_WHERE_DEFAULT ? "(default)" : mss_config_options[i].where == MSS_CONFIG_WHERE_LOCAL ? "(local file)" : "(global file)");		i++;	};	/* Check for errors during configuration, and print those to the	   logfile. */	fprintf(mss_logfile, "\n");	dcflist_rewind(&mss_config_error);	while ( (s = dcflist_get_item(&mss_config_error)) != NULL)	{	 	fprintf(mss_logfile, "WARNING: %s\n", s);		dcflist_go_forward(&mss_config_error);	};	dcflist_destroy(&mss_config_error);#ifdef MSS_DEBUG	fprintf(mss_logfile, "MSS_DEBUG was defined.\n");#endif /* !MSS_DEBUG */	fprintf(mss_logfile, "%s", mss_separator);	fprintf(mss_logfile, "Logging started at %s\n", get_time());	mss_enable_threading();}void mss_slog(char *format, ...){ 	va_list arg;	if (MSS_DO_SPECIAL_LOG)	{		mss_disable_threading();		va_start(arg, format);		vsprintf(tmpstr, format, arg);		va_end(arg);		fprintf(mss_slogfile, tmpstr);		mss_enable_threading();	}}/* mss_log():   This function will output the specified message to the logfile, word   wrapping its contents and so on. Really nice function really! ;) */void mss_log(int mode, const char *label, const char *format, ...){	va_list arg;	if ((!(mss_options & MSS_SHOW_LOGS)) && (!(mode & MSS_LOG_MODE_ALWAYS)))		return;	mss_disable_threading();	va_start(arg, format);	vsprintf(tmpstr, format, arg);	va_end(arg);	if (mode & MSS_LOG_MODE_START_SEPARATOR)		fputs(mss_separator, mss_logfile);	fprintf(mss_logfile, "%s", label == NULL ? tmpstr : mss_word_wrap(label, tmpstr));	if (mode & MSS_LOG_MODE_END_SEPARATOR)		fputs(mss_separator, mss_logfile);	if (!(mode & MSS_LOG_MODE_NO_EXTRA_NEWLINE) && MSS_DO_EXTRA_NEWLINE)		fprintf(mss_logfile, "\n");	mss_enable_threading();}/* mss_warn():   Internal helper function to print a warning to the logfile, and exit   the program if EXIT_ON_WARNING was defined. */void mss_warn(int options, char *format, ...){	va_list arg;	va_start(arg, format);	if (((options & MSS_WARN_IF_SHOW) && !MSS_DO_EXIT_ON_WARNING) || MSS_DO_EXIT_ON_WARNING		|| !(options & MSS_WARN_IF_SHOW))	{		if (((mss_options & MSS_SHOW_WARNINGS) && !MSS_DO_EXIT_ON_WARNING) || MSS_DO_EXIT_ON_WARNING)		{			mss_disable_threading();			if (options & MSS_WARN_SEPARATOR)				fprintf(mss_logfile, mss_separator);			vsprintf(tmpstr, format, arg);			fprintf(mss_logfile, "%s", mss_word_wrap("WARNING", tmpstr));			if (options & MSS_WARN_SEPARATOR)				fputs(mss_separator, mss_logfile);			if (MSS_DO_EXTRA_NEWLINE)				fprintf(mss_logfile, "\n");			mss_enable_threading();		}		if (!(options & MSS_WARN_NO_EXIT) && MSS_DO_EXIT_ON_WARNING)		{			mss_abort();		}	}	va_end(arg);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -