#ifdef UUIDGEN
# if defined __STDC__
# include <limits.h>
# include <stdlib.h>
# endif
# include <uuidmsg.h>
# define MESSAGE_VERSION UUIDGEN_MESSAGE_VERSION
# define MESSAGE_VERSION_USED UUIDGEN_MESSAGE_VERSION_USED
# define MESSAGE_CATALOG_DIR "/usr/bin/"
# define NLSCATVER UUIDGEN_NLSCATVER
# define NLSWRONG UUIDGEN_NLSWRONG
# ifdef _AIX
# define NL_VFPRINTF NLvfprintf
# else
# define NL_VFPRINTF vfprintf
# endif
# define BRANCHCHAR '/'
#else
# include <nidl.h>
# include <nidlmsg.h>
# define MESSAGE_VERSION NIDL_MESSAGE_VERSION
# define MESSAGE_VERSION_USED NIDL_MESSAGE_VERSION_USED
# define NLSCATVER NIDL_NLSCATVER
# define NLSWRONG NIDL_NLSWRONG
#endif
#include <stdio.h>
#include <string.h>
#ifdef VMS
# include <descrip.h>
# define MAX_MSG_IDENT 32
# define MAX_MSG_TEXT 256
# define MAX_FMT_TEXT 512
# define MSG_OPTS 0xF
#else
# define MAX_FMT_TEXT 512
# include <nl_types.h>
# ifdef __STDC__
# include <stdarg.h>
# define VA_START(L, A, T) va_start(L, A)
# else
# include <varargs.h>
# define VA_START(L, A, T) T A; va_start(L); A = va_arg(L,T)
# endif
#ifdef UUIDGEN
# ifndef PATH_MAX
# define PATH_MAX 256
# endif
#endif
static nl_catd cat_handle;
char *default_messages[] = {
"Internal idl compiler error: Invalid message number",
#include <default_msg.h>
};
static long max_message_number
= (long)(sizeof(default_messages)/sizeof(char *) - 1);
# define def_message(id) \
default_messages[(id<0||id>max_message_number)?0:id]
#endif
#include <message.h>
static char msg_prefix[PATH_MAX+3];
void message_open
(
char *image_name
)
#ifdef VMS
{
struct dsc$descriptor
ctrstr,
outbuf;
long flags;
unsigned short outlen;
long status;
char version_text[MAX_MSG_TEXT];
ctrstr.dsc$w_length = sizeof(version_text)-1;
ctrstr.dsc$b_dtype = DSC$K_DTYPE_T;
ctrstr.dsc$b_class = DSC$K_CLASS_S;
ctrstr.dsc$a_pointer = version_text;
strncpy(msg_prefix,image_name,PATH_MAX);
strcat(msg_prefix,": ");
#ifdef DUMPERS
status = SYS$GETMSG(MESSAGE_VERSION, &ctrstr.dsc$w_length, &ctrstr, 1, 0);
if ((status & 1) == 0)
fprintf(stderr, "%sError in error message processing!\n",msg_prefix);
version_text[ctrstr.dsc$w_length] = '\0';
if (atoi(version_text) != MESSAGE_VERSION_USED)
fprintf(stderr, "%sMessage catalog version mismatch, Expected: \"%d\", Actual: \"%s\"\n",
msg_prefix, MESSAGE_VERSION_USED, version_text );
#endif
return;
}
#else
{
char cat_name[PATH_MAX];
char *cp;
char *bcp;
strncpy(msg_prefix,image_name,PATH_MAX);
strcat(msg_prefix,": ");
cp = image_name;
while ((bcp=strrchr(cp,BRANCHCHAR)) != NULL)
{
if (bcp[1] == '\0')
bcp[0]='\0';
else
cp = bcp+1;
}
strncpy(cat_name,cp,PATH_MAX);
strcat(cat_name,".cat");
#ifdef AIX32
setlocale(LC_ALL, "");
#endif
cat_handle = catopen(cat_name, 0);
if (cat_handle != (nl_catd)-1)
{
char *version_text;
version_text = catgets(cat_handle,CAT_SET,MESSAGE_VERSION,NULL);
if (version_text != NULL && atoi(version_text) != MESSAGE_VERSION_USED)
{
fprintf(stderr, def_message(NLSCATVER),
msg_prefix, cat_name, MESSAGE_VERSION_USED, version_text);
fprintf(stderr, "\n");
fprintf(stderr, def_message(NLSWRONG), msg_prefix);
fprintf(stderr, "\n");
}
}
return;
}
#endif
void message_close
(
void
)
#ifdef VMS
{
return;
}
#else
{
catclose(cat_handle);
return;
}
#endif
void message_print
#ifdef VMS
(
long msgid,
char *arg1,
char *arg2,
char *arg3,
char *arg4,
char *arg5
)
#else
#ifdef __STDC__
(long msgid, ...)
#else
(va_alist) va_dcl
#endif
#endif
#if defined(VMS) && !defined(BROKEN_PUTMSG)
{
long status;
char *msg_vec[8];
msg_vec[0] = (char *)7;
msg_vec[1] = (char *)msgid;
msg_vec[2] = (char *)5;
msg_vec[3] = arg1;
msg_vec[4] = arg2;
msg_vec[5] = arg3;
msg_vec[6] = arg4;
msg_vec[7] = arg5;
status = SYS$PUTMSG(msg_vec, 0, 0, 0);
if ((status & 1) == 0) LIB$SIGNAL(status);
}
#else
{
va_list arglist;
char format[MAX_FMT_TEXT];
VA_START(arglist, msgid, long);
format[0]='\0';
switch (msgid)
{
#ifndef UUIDGEN
case NIDL_EOF:
case NIDL_EOFNEAR:
case NIDL_SYNTAXNEAR:
case NIDL_FILESOURCE:
case NIDL_LINEFILE:
#else
default:
#endif
strcpy(format, msg_prefix);
}
strcat(format,catgets(cat_handle, CAT_SET, msgid, def_message(msgid)));
strcat(format,"\n");
NL_VFPRINTF(stderr, format, arglist);
va_end(arglist);
}
#endif
#ifndef UUIDGEN
void message_sprint
(
char *str,
long msgid,
char *arg1,
char *arg2,
char *arg3,
char *arg4,
char *arg5
)
#ifdef VMS
{
struct dsc$descriptor
ctrstr,
outbuf;
long flags;
unsigned short outlen;
long status;
char msg_text[MAX_MSG_TEXT];
ctrstr.dsc$w_length = sizeof(msg_text)-1;
ctrstr.dsc$b_dtype = DSC$K_DTYPE_T;
ctrstr.dsc$b_class = DSC$K_CLASS_S;
ctrstr.dsc$a_pointer = msg_text;
flags = MSG_OPTS;
status = SYS$GETMSG(msgid, &ctrstr.dsc$w_length, &ctrstr, flags, 0);
if ((status & 1) == 0)
fprintf(stderr, "Error in error message processing!\n");
outbuf.dsc$w_length = MAX_FMT_TEXT-1;
outbuf.dsc$b_dtype = DSC$K_DTYPE_T;
outbuf.dsc$b_class = DSC$K_CLASS_S;
outbuf.dsc$a_pointer = str;
status = SYS$FAO(&ctrstr, &outlen, &outbuf, arg1, arg2, arg3, arg4, arg5);
if ((status & 1) == 0)
fprintf(stderr, "Error in error message processing!\n");
str[outlen] = '\0';
}
#else
{
char *msg_text;
msg_text = catgets(cat_handle, CAT_SET, msgid, def_message(msgid));
switch (msgid)
{
case NIDL_EOF:
case NIDL_EOFNEAR:
case NIDL_SYNTAXNEAR:
case NIDL_FILESOURCE:
case NIDL_LINEFILE:
strcpy(str,msg_prefix);
str += strlen(msg_prefix);
break;
}
NL_SPRINTF(str, msg_text, arg1, arg2, arg3, arg4, arg5);
}
#endif
void message_fprint
(
FILE *fid,
long msgid,
char *arg1,
char *arg2,
char *arg3,
char *arg4,
char *arg5
)
#ifdef VMS
{
char str[MAX_FMT_TEXT];
struct dsc$descriptor
ctrstr,
outbuf;
long flags;
unsigned short outlen;
long status;
char msg_text[MAX_MSG_TEXT];
ctrstr.dsc$w_length = sizeof(msg_text)-1;
ctrstr.dsc$b_dtype = DSC$K_DTYPE_T;
ctrstr.dsc$b_class = DSC$K_CLASS_S;
ctrstr.dsc$a_pointer = msg_text;
flags = 1;
status = SYS$GETMSG(msgid, &ctrstr.dsc$w_length, &ctrstr, flags, 0);
if ((status & 1) == 0)
fprintf(stderr, "Error in error message processing!\n");
outbuf.dsc$w_length = MAX_FMT_TEXT-1;
outbuf.dsc$b_dtype = DSC$K_DTYPE_T;
outbuf.dsc$b_class = DSC$K_CLASS_S;
outbuf.dsc$a_pointer = str;
status = SYS$FAO(&ctrstr, &outlen, &outbuf, arg1, arg2, arg3, arg4, arg5);
if ((status & 1) == 0)
fprintf(stderr, "Error in error message processing!\n");
str[outlen] = '\0';
fprintf(fid, "%s\n", str);
}
#else
{
char str[MAX_FMT_TEXT];
char *msg_text;
msg_text = catgets(cat_handle, CAT_SET, msgid, def_message(msgid));
NL_SPRINTF(str, msg_text, arg1, arg2, arg3, arg4, arg5);
fprintf(fid, "%s\n", str);
}
#endif
#endif