home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cidsam.zip
/
CIDLOG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-28
|
5KB
|
115 lines
/*********************************/
/* NOTE */
/* */
/* This sample code has been */
/* provided by IBM. It is not */
/* warranted for any particular */
/* use or purpose. */
/* */
/* IBM releases this code into */
/* the public domain. You may */
/* use it, modify it, or */
/* incorporate it into other */
/* products without restriction. */
/*********************************/
/*********************************************************************/
/* */
/* MODULE NAME: cidlog.c */
/* */
/* DESCRIPTIVE NAME: Contains routine CID_log() */
/* */
/* LINKAGE: This is a linkable subroutine. It requires no other */
/* linkages. */
/* */
/*********************************************************************/
#pragma page (1)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#define INCL_BASE
#include <os2.h>
#include "cidlog.h"
/****************************************************************************/
/* C I D _ L o g */
/* */
/* Calling sequence */
/* */
/* void CID_Log(int msgno, ...); // function prototype */
/* */
/* CID_Log(12, "first arg", "second arg", "third arg"); */
/* */
/* The arguments (other than the message number) passed to this @C1a*/
/* routine must all be character pointers. @C1a*/
/****************************************************************************/
void CID_Log(UINT uiMsgno, ...)
{
va_list marker;
PCHAR apszArglist[10]; /*@C1c*/
int rc;
#ifdef I16 /*@A1a*/
USHORT i, msglen;
#else /*@A1a*/
ULONG i, msglen; /*@A1a*/
#endif /*@A1a*/
char szMsgarea[256];
char logmsgfile[CCHMAXPATH];
char logfilename[CCHMAXPATH];
char *p;
FILE *f;
va_start(marker, uiMsgno);
f = (FILE *)NULL;
for (i = 0; i < 10; apszArglist[i++] = NULL); /* initialize array */
for (i = 0; i < 10; i++)
{
apszArglist[i] = va_arg(marker, char *);
if (apszArglist[i] == NULL)
break;
}
if (i >= 10)
i = 9;
if ( (p = getenv(LOGMSGFILEEVAR)) == NULL)
strcpy(logmsgfile, DEFAULTLOGMSGFILE);
else
strcpy(logmsgfile, p);
if ( (p = getenv(LOGFILEEVAR)) == NULL)
*logfilename = '\0';
else
strcpy(logfilename, p);
if (*logfilename)
f = fopen(logfilename, "a+");
msglen = 255;
rc = DosGetMessage(apszArglist, i, (PCHAR)szMsgarea, 255, /*@C1c*/
uiMsgno, logmsgfile, &msglen); /*@C1c*/
if (rc == NO_ERROR)
{ /*@C1a*/
*(szMsgarea+msglen) = '\0'; /*@C1c*/
if (f)
fprintf(f, "%s\n", szMsgarea);
else
printf("%s\n", szMsgarea);
} /*@C1a*/
else
if (rc == ERROR_MR_UN_ACC_MSGF)
if (f)
fprintf(f, "Message file %s not found\n", logmsgfile);
else
printf("Message file %s not found\n", logmsgfile);
else
if (f)
fprintf(f, "DosGetMessage failed. rc = %d\n", rc);
else
printf("DosGetMessage failed. rc = %d\n", rc);
if (f)
fclose(f);
}