View Single Post
  #1  
Old 05-27-2004, 12:37 PM
maaltan
Fire Beetle
 
Join Date: May 2004
Posts: 9
Default total recall

ok i got bored so i learned how to use variable parameters. here is the updated util.cpp file

This update will let you use this exactly like printf. for example:

Code:
opcode = 55;
info_report(SEV_WARN,"Unknown opcode: %d", opcode);
will print:

Code:
Warn [20:33:18] Unknown opcode: 55
all of printf's codes should work. Please let me know if wierdness happens. this is new ground for me.

Code:
#include "stdafx.h"
#include "util.h"
#include <time.h>
#include <stdarg.h>

//severity label array 
const char* severity_lookup[] = {	{"Null"},
								{"info"},
								{"Warn"},
								{"ERRO"},
								{"FATL"} };


int info_report(int severity, char* error, ...)
// return value as defined in util.h
{
	time_t timer;
	struct tm * curtime;

	if (severity > MAX_SEVERITY)
	{
		info_report(SEV_ERRO,"INVALID SEVERITY IN INFO_REPORT:  Please use valid severity value");
		return(RET_ERROR);
	} else
	{   
			// setup for variable argument list
			va_list arglist;
			va_start(arglist, error);
			//end setup

			timer=time(NULL);
			curtime = localtime(&timer);

			printf( "%s[%.2d:%.2d:%.2d] " ,
					severity_lookup[severity],
					(*curtime).tm_hour,
					(*curtime).tm_min,
					(*curtime).tm_sec);

			vprintf( error,arglist); //its maaaaagic

			printf("\n");
                                                va_end(arglist); //close the list up
			return(RET_NORMAL);
	}
	return(RET_NORMAL);
}
you will need to change the function prototype in util.h from:

int info_report(int severity, char* error);

to

int info_report(int severity, char* error, ...);
Reply With Quote