dvitomp fix from Akira
[mplib] / src / texk / kpathsea / error.c
1 /* 
2
3 Error messages for fpTeX.
4
5 Copyright (C) 1998-2000 Free Software Foundation, Inc.
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #ifdef __MINGW32__
22
23 #include <kpathsea/config.h>
24 #include <kpathsea/c-proto.h>
25 #include <kpathsea/win32lib.h>
26 #include <kpathsea/lib.h>
27 #include <kpathsea/progname.h>
28
29 extern KPSEDLL char *kpathsea_version_string; /* from kpathsea/version.c */
30
31 /*
32   Various messages to display error messages, either from Windows
33   or on the console.
34 */
35
36 /* Last error message in a MessageBox. */
37 void Win32Error(char *caller)
38 {
39   LPVOID lpMsgBuf;
40   DWORD errCode;
41   if (errCode = GetLastError()) {
42     if (FormatMessage(
43                       FORMAT_MESSAGE_ALLOCATE_BUFFER 
44                       | FORMAT_MESSAGE_FROM_SYSTEM
45                       | FORMAT_MESSAGE_IGNORE_INSERTS,
46                       NULL,
47                       errCode,
48                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
49                       (LPTSTR) &lpMsgBuf,
50                       0,
51                       NULL 
52                       )) {
53       /* Display the string. */
54       MessageBox( NULL, lpMsgBuf, caller, MB_OK|MB_ICONINFORMATION );
55       /* Free the buffer. */
56       LocalFree( lpMsgBuf );
57     }
58     else {
59       char szBuf[24];
60       wsprintf(szBuf, "%d", errCode);
61       MessageBox( NULL, szBuf, caller, MB_OK|MB_ICONINFORMATION );
62     }    
63   }
64 }
65
66 void Win32Msg(char *msg)
67 {
68   char *program = "(unknown)";
69   char *caller = NULL;
70
71   if (kpse_program_name && *kpse_program_name) {
72     program = kpse_program_name;
73   }
74
75   caller = concat3(program, "\r\n", kpathsea_version_string);
76   
77   MessageBox(NULL, msg, caller, MB_OK|MB_ICONINFORMATION);
78
79   free(program);
80 }
81
82 #endif