Imported Upstream version 1.15.1
[platform/upstream/krb5.git] / src / windows / leashdll / winerr.c
1 /*  WINERR.C
2
3     Jason Hunter
4     8/2/94
5     DCNS/IS MIT
6
7
8   Contains the error functions for leash and kerberos.  Prints out keen windows
9   error messages in english.
10
11 */
12
13 #include <stdio.h>
14 #include "conf.h"
15
16 // Private Include files
17 #include "leashdll.h"
18 #include <leashwin.h>
19
20 // Global Variables.
21 static long lsh_errno;
22 static char *err_context;       /* error context */
23 extern int (*Lcom_err)(LPSTR,long,LPSTR,...);
24 extern LPSTR (*Lerror_message)(long);
25 extern LPSTR (*Lerror_table_name)(long);
26
27 #ifdef WIN16
28 #define UNDERSCORE "_"
29 #else
30 #define UNDERSCORE
31 #endif
32
33 HWND GetRootParent (HWND Child)
34 {
35     HWND Last;
36     while (Child)
37     {
38         Last = Child;
39         Child = GetParent (Child);
40     }
41     return Last;
42 }
43
44
45 LPSTR err_describe(LPSTR buf, long code)
46 {
47     LPSTR cp, com_err_msg;
48     int offset;
49     long table_num;
50     char *etype;
51
52     offset = (int) (code & 255);
53     table_num = code - offset;
54     com_err_msg = Lerror_message(code);
55
56     lstrcpy(buf, com_err_msg);
57     return buf;
58
59
60 ////Is this needed at all after the return above?
61     cp = buf;
62     if(com_err_msg != buf)
63         lstrcpy(buf, com_err_msg);
64     cp = buf + lstrlen(buf);
65     *cp++ = '\n';
66     etype = Lerror_table_name(table_num);
67     wsprintf((LPSTR) cp, (LPSTR) "(%s error %d"
68 #ifdef DEBUG_COM_ERR
69              " (absolute error %ld)"
70 #endif
71              ")", etype, offset
72              //")\nPress F1 for help on this error.", etype, offset
73 #ifdef DEBUG_COM_ERR
74              , code
75 #endif
76         );
77
78     return (LPSTR)buf;
79 }
80
81 int _export lsh_com_err_proc (LPSTR whoami, long code,
82                               LPSTR fmt, va_list args)
83 {
84 #ifdef USE_MESSAGE_BOX
85     int retval;
86     HWND hOldFocus;
87     char buf[1024], *cp; /* changed to 512 by jms 8/23/93 */
88     WORD mbformat = MB_OK | MB_ICONEXCLAMATION;
89
90     cp = buf;
91     memset(buf, '\0', sizeof(buf));
92     cp[0] = '\0';
93
94     if (code)
95     {
96         err_describe(buf, code);
97         while (*cp)
98             cp++;
99     }
100
101     if (fmt)
102     {
103         if (fmt[0] == '%' && fmt[1] == 'b')
104         {
105             fmt += 2;
106             mbformat = va_arg(args, WORD);
107             /* if the first arg is a %b, we use it for the message
108                box MB_??? flags. */
109         }
110         if (code)
111         {
112             *cp++ = '\n';
113             *cp++ = '\n';
114         }
115         wvsprintf((LPSTR)cp, fmt, args);
116     }
117     hOldFocus = GetFocus();
118     retval = MessageBox(/*GetRootParent(hOldFocus)*/NULL, buf, whoami,
119                         mbformat | MB_ICONHAND | MB_TASKMODAL);
120     SetFocus(hOldFocus);
121     return retval;
122 #else
123     return IDOK;
124 #endif /* USE_MESSAGE_BOX */
125 }