#include "nms_core.h"
+//
+// Messages generated by mc.pl (for UNIX version only)
+//
+
+#ifndef _WIN32
+extern DWORD g_dwNumMessages;
+extern char *g_szMessages[];
+#endif
+
+
//
// Static data
//
}
+//
+// Format message (UNIX version)
+//
+
+#ifndef _WIN32
+
+char *FormatMessageUX(DWORD dwMsgId, char **ppStrings)
+{
+ char *p, *pMsg;
+ int i, iSize, iLen;
+
+ if (dwMsgId >= g_dwNumMessages)
+ {
+ // No message with this ID
+ pMsg = (char *)malloc(128);
+ sprintf(pMsg, "MSG 0x%08X - Unable to find message text\n", dwMsgId);
+ }
+ else
+ {
+ iSize = strlen(g_szMessages[dwMsgId]) + 2;
+ pMsg = (char *)malloc(iSize);
+
+ for(i = 0, p = g_szMessages[dwMsgId]; *p != 0; p++)
+ if (*p == '%')
+ {
+ p++;
+ if ((*p >= '1') && (*p <= '9'))
+ {
+ iLen = strlen(ppStrings[*p - '1']);
+ iSize += iLen;
+ pMsg = (char *)realloc(pMsg, iSize);
+ strcpy(&pMsg[i], ppStrings[*p - '1']);
+ i += iLen;
+ }
+ else
+ {
+ if (*p == 0) // Handle single % character at the string end
+ break;
+ pMsg[i++] = *p;
+ }
+ }
+ else
+ {
+ pMsg[i++] = *p;
+ }
+ pMsg[i++] = '\n';
+ pMsg[i] = 0;
+ }
+
+ return pMsg;
+}
+
+#endif /* ! _WIN32 */
+
+
//
// Write log record
// Parameters:
void WriteLog(DWORD msg, WORD wType, char *format, ...)
{
va_list args;
- char *strings[16], *msgBuf;
+ char *strings[16], *pMsg;
int numStrings = 0;
DWORD error;
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error,
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), // Default language
- (LPSTR)&msgBuf,0,NULL)>0)
+ (LPSTR)&pMsg,0,NULL)>0)
{
- msgBuf[strcspn(msgBuf,"\r\n")] = 0;
- strings[numStrings]=(char *)malloc(strlen(msgBuf) + 1);
- strcpy(strings[numStrings], msgBuf);
- LocalFree(msgBuf);
+ pMsg[strcspn(msgBuf,"\r\n")] = 0;
+ strings[numStrings]=(char *)malloc(strlen(pMsg) + 1);
+ strcpy(strings[numStrings], pMsg);
+ LocalFree(pMsg);
}
else
{
}
}
#else /* _WIN32 */
-
- /* TODO: add event logging under UNIX */
-
+ pMsg = FormatMessageUX(msg, strings);
+ if (g_dwFlags & AF_USE_EVENT_LOG)
+ {
+ }
+ else
+ {
+ WriteLogToFile(pMsg);
+ }
+ free(pMsg);
#endif /* _WIN32 */
while(--numStrings >= 0)