source: trunk/src/kernel32/dbglog.cpp@ 9322

Last change on this file since 9322 was 9322, checked in by sandervl, 23 years ago

small performance update

File size: 26.0 KB
Line 
1/* $Id: dbglog.cpp,v 1.3 2002-10-03 13:05:55 sandervl Exp $ */
2
3/*
4 * Project Odin Software License can be found in LICENSE.TXT
5 * Debug Logging procedures
6 *
7 * Copyright 1998-2002 Sander van Leeuwen (sandervl@xs4all.nl)
8 * Copyright 1998 Joel Troster
9 * Copyright 1998 Peter FitzSimmons
10 *
11 */
12
13
14/*******************************************************************************
15* Internal Functions *
16*******************************************************************************/
17
18#define INCL_BASE
19#define INCL_WIN
20#define INCL_WINERRORS
21#define INCL_DOSFILEMGR
22#include <os2wrap.h> //Odin32 OS/2 api wrappers
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <stdarg.h>
27#include <win32type.h>
28#include <win32api.h>
29#include <dbglog.h>
30#include "initterm.h"
31#include "logging.h"
32#include "exceptutil.h"
33#include <wprocess.h>
34#include <versionos2.h>
35#include "odinbuild.h"
36#include <cpuhlp.h>
37
38/*****************************************************************************
39 * PMPRINTF Version *
40 *****************************************************************************/
41
42#ifdef PMPRINTF
43
44/* ----- Customization variables ----- */
45#define PRINTFID ""
46#define PRINTFMAXLEN 300
47#define PRINTFLINELEN 100
48#define PRINTFTHREADS 54
49#define PRINTFQNAME "\\QUEUES\\PRINTF32"
50
51/* ----- Includes and externals ----- */
52#include <stddef.h> /* .. */
53#include <time.h> /* .. */
54
55extern ULONG flAllocMem; /*Tue 03.03.1998: knut */
56
57/* ----- Local defines ----- */
58#define PRINTFIDSIZE sizeof(PRINTFID)
59#define PRINTFMAXBUF PRINTFIDSIZE+PRINTFLINELEN
60
61
62/*****************************************************************************
63 * Structures *
64 *****************************************************************************/
65
66/* ----- Per-thread output buffer and current indices into line ---- */
67struct perthread {
68 LONG lineindex; /* where next char */
69 LONG tidemark; /* rightmost char */
70 int bell; /* TRUE if line has bell */
71 UCHAR line[PRINTFMAXBUF]; /* accumulator */
72 };
73
74/* ----- Local static variables ----- */
75static ULONG ourpid=0; /* our process ID */
76static ULONG servepid=0; /* process IDs of the server */
77static HQUEUE qhandle=0; /* handle for the queue */
78static struct perthread *tps[PRINTFTHREADS+1]; /* -> per-thread data */
79
80/* ----- Local subroutine ----- */
81static int printf_(struct perthread *);
82
83
84/* ----------------------------------------------------------------- */
85/* The "printf" function. Note this has a variable number of */
86/* arguments. */
87/* ----------------------------------------------------------------- */
88int SYSTEM WriteLog(char *f, ...)
89 {
90 TIB *ptib; /* process/thread id structures */
91 PIB *ppib; /* .. */
92 TID ourtid; /* thread ID */
93 struct perthread *tp; /* pointer to per-thread data */
94 int rc; /* returncode */
95 ULONG urc; /* returncode */
96
97 urc=DosOpenQueue(&servepid, &qhandle, PRINTFQNAME); /* Open the Q */
98 /* Non-0 RC means Q does not exist or cannot be opened */
99 if (urc==343) return 0; /* queue does not exist, so quit */
100 if (urc!=0) return -1; /* report any other error */
101
102 /* First determine our thread ID (and hence get access to the */
103 /* correct per-thread data. If the per-thread data has not been */
104 /* allocated, then allocate it now. It is never freed, once */
105 /* allocated, as PRINTF is not notified of end-of-thread. */
106 DosGetInfoBlocks(&ptib,&ppib); /* get process/thread info */
107 ourtid=ptib->tib_ptib2->tib2_ultid; /* .. and copy TID */
108 if (ourtid>PRINTFTHREADS) /* too many threads .. */
109 return 0; /* .. so quit, quietly */
110 tp=tps[ourtid]; /* copy to local pointer */
111 if (tp==NULL) { /* uninitialized (NULL=0) */
112 /* allocate a per-thread structure */
113 tp=(struct perthread *)malloc(sizeof(struct perthread));
114 if (tp==NULL) return -1; /* out of memory -- return error */
115 tps[ourtid]=tp; /* save for future calls */
116 strcpy(tp->line,PRINTFID); /* initialize: line.. */
117 tp->lineindex=PRINTFIDSIZE-1; /* ..where next char */
118 tp->tidemark =PRINTFIDSIZE-2; /* ..rightmost char */
119 tp->bell=FALSE; /* ..if line has bell */
120 if (ourpid==0) ourpid=ppib->pib_ulpid; /* save PID for all to use */
121 }
122
123 { /* Block for declarations -- only needed if queue exists, etc. */
124 LONG count; /* count of characters formatted */
125 UCHAR buffer[PRINTFMAXLEN+1]; /* formatting area */
126 LONG i, newind; /* work */
127 UCHAR ch; /* .. */
128 va_list argptr; /* -> variable argument list */
129
130 va_start(argptr, f); /* get pointer to argument list */
131 count=vsprintf(buffer, f, argptr);
132 va_end(argptr); /* done with variable arguments */
133
134 if (count<0) return count-1000;/* bad start */
135
136 if (count>PRINTFMAXLEN) {
137 /* Disaster -- we are probably "dead", but just in case we */
138 /* are not, carry on with truncated data. */
139 count=PRINTFMAXLEN;
140 }
141 buffer[count]='\0'; /* ensure terminated */
142 /* OK, ready to go with the data now in BUFFER */
143 /* We copy from the formatted string to the output (line) buffer, */
144 /* taking note of certain control characters and sending a line */
145 /* the queue whenever we see a LF control, or when the line */
146 /* fills (causing a forced break). */
147 for (i=0; ; i++) {
148 ch=buffer[i]; if (!ch) break;
149 switch(ch) {
150 case '\r': /* carriage return */
151 tp->lineindex=PRINTFIDSIZE-1; /* back to start of line */
152 break;
153 case '\n': /* new line */
154 case '\f': /* form feed */
155 rc=printf_(tp); /* print a line */
156 if (rc!=0) return rc; /* error */
157 break;
158 case '\t': /* tab */
159 newind=tp->lineindex-PRINTFIDSIZE+1; /* offset into data */
160 newind=tp->lineindex+5-newind%5; /* new index requested */
161 if (newind>=PRINTFMAXBUF) newind=PRINTFMAXBUF; /* clamp */
162 for (; tp->lineindex<newind; tp->lineindex++) {
163 if (tp->lineindex>tp->tidemark) { /* beyond current end */
164 tp->line[tp->lineindex]=' '; /* add space */
165 tp->tidemark=tp->lineindex;
166 }
167 }
168 break;
169 case '\v': /* vertical tab */
170 /* ignore it */
171 break;
172 case '\b': /* backspace */
173 tp->lineindex=max(tp->lineindex-1,PRINTFIDSIZE);
174 break;
175 case '\a': /* alert (bell) */
176 tp->bell=TRUE;
177 break;
178 default: /* ordinary character */
179 tp->line[tp->lineindex]=ch;
180 if (tp->lineindex>tp->tidemark) /* is rightmost.. */
181 tp->tidemark=tp->lineindex;
182 tp->lineindex++; /* step for next */
183 } /* switch */
184 if (tp->lineindex>=PRINTFMAXBUF) {
185 rc=printf_(tp); /* print a line */
186 if (rc!=0) return rc; /* error */
187 }
188
189 } /* copy loop */
190 return count; /* all formatted data processed */
191 } /* block */
192 } /* printf */
193
194/* ----- printf_(tp) -- Local subroutine to send a line ------------ */
195/* A line has been completed (or overflowed): write it to the queue. */
196int printf_(struct perthread *tp) /* pointer to per-thread data */
197 {
198 ULONG urc; /* unsigned returncode */
199 PSZ pszTo, pszFrom; /* character pointers */
200 PVOID addr; /* address of output data */
201 long size; /* total size of output data */
202 time_t timenow; /* holds current time */
203
204 tp->line[tp->tidemark+1]='\0'; /* add terminator */
205 size=tp->tidemark+2; /* total length of data */
206
207 /* Get some shared memory that can be given away */
208 urc=DosAllocSharedMem(&addr, NULL, (unsigned)size,
209 OBJ_GIVEABLE|PAG_WRITE|PAG_COMMIT|flAllocMem);
210 /*knut: added flAllocMem */
211
212 if (urc!=0) return -2; /* error */
213
214 pszTo=addr; /* copy for clarity */
215 pszFrom=&(tp->line[0]); /* pointer to source */
216 strcpy(pszTo,pszFrom); /* copy the string to shared memory */
217
218 if (ourpid!=servepid) { /* (no giveaway needed if to self) */
219 urc=DosGiveSharedMem(addr, servepid, PAG_READ); /* give access */
220 if (urc!=0) return -3;} /* error */
221
222 /* Write the selector, size, and timestamp to the queue */
223 if (tp->bell) size=-size; /* BELL passed by negation */
224 time(&timenow); /* optional - else use 0 */
225 urc=DosWriteQueue(qhandle, /* handle */
226 (unsigned)timenow, /* 'request' (timestamp) */
227 (unsigned)size, /* 'length' (length/bell) */
228 addr, /* 'address' (address) */
229 0); /* priority (FIFO if enabled) */
230 if (urc!=0) return -4; /* error */
231 if (ourpid!=servepid) { /* if given away.. */
232 urc=DosFreeMem(addr); /* .. *we* are done with it */
233 if (urc!=0) return -5;} /* error */
234 /* Reset the line buffer and indices */
235 tp->lineindex=PRINTFIDSIZE-1; /* where next char */
236 tp->tidemark =PRINTFIDSIZE-2; /* rightmost char */
237 tp->bell =FALSE; /* true if line has bell */
238 return 0; /* success! */
239 } /* printf_ */
240#endif
241
242
243
244/*****************************************************************************
245 * Standard Version *
246 *****************************************************************************/
247
248static FILE *flog = NULL; /*PLF Mon 97-09-08 20:00:15*/
249static BOOL init = FALSE;
250static BOOL fLogging = TRUE;
251static int dwEnableLogging = 1;
252static int oldcrtmsghandle = 0;
253
254static BOOL fDisableThread[5] = {0};
255static BOOL fFlushLines = FALSE;
256
257//#define CHECK_ODINHEAP
258#if defined(DEBUG) && defined(CHECK_ODINHEAP)
259int checkOdinHeap = 1;
260int checkingheap = 0;
261#define ODIN_HEAPCHECK() \
262 if(checkingheap) checkOdinHeap = 0; \
263 checkingheap++; \
264 if(checkOdinHeap) _heap_check(); \
265 checkingheap--;
266#else
267#define ODIN_HEAPCHECK()
268#endif
269
270//#define LOG_TIME
271//#define SHOW_FPU_CONTROLREG
272#define WIN32_IP_LOGGING
273#define WIN32_IP_LOG_PORT 5001
274
275#ifdef WIN32_IP_LOGGING
276#include <types.h>
277#include <netinet/in.h>
278#include <sys/socket.h>
279
280static int logSocket = -1;
281static struct sockaddr_in servername;
282#endif
283
284int SYSTEM WriteLog(char *tekst, ...)
285{
286 USHORT sel = RestoreOS2FS();
287 va_list argptr;
288 TEB *teb = GetThreadTEB();
289
290 ODIN_HEAPCHECK();
291
292 if(!init)
293 {
294 init = TRUE;
295
296 if(getenv("WIN32LOG_FLUSHLINES")) {
297 fFlushLines = TRUE;
298 }
299#ifdef DEFAULT_LOGGING_OFF
300 if(getenv("WIN32LOG_ENABLED")) {
301#else
302 if(!getenv("NOWIN32LOG")) {
303#endif
304
305#ifdef WIN32_IP_LOGGING
306 char *logserver = getenv("WIN32LOG_IPSERVER");
307 if(logserver) {
308 sock_init();
309
310 memset(&servername, 0, sizeof(servername));
311 servername.sin_family = AF_INET;
312 servername.sin_addr.s_addr = inet_addr(logserver);
313 servername.sin_port = WIN32_IP_LOG_PORT;
314
315 logSocket = socket(PF_INET, SOCK_DGRAM, 0);
316 }
317#endif
318 char logname[CCHMAXPATH];
319
320 sprintf(logname, "odin32_%d.log", loadNr);
321 flog = fopen(logname, "w");
322 if(flog == NULL) {//probably running exe on readonly device
323 sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr);
324 flog = fopen(logname, "w");
325 }
326 oldcrtmsghandle = _set_crt_msg_handle(fileno(flog));
327 }
328 else
329 fLogging = FALSE;
330
331 if(getenv("DISABLE_THREAD1")) {
332 fDisableThread[0] = TRUE;
333 }
334 if(getenv("DISABLE_THREAD2")) {
335 fDisableThread[1] = TRUE;
336 }
337 if(getenv("DISABLE_THREAD3")) {
338 fDisableThread[2] = TRUE;
339 }
340 if(getenv("DISABLE_THREAD4")) {
341 fDisableThread[3] = TRUE;
342 }
343 if(getenv("DISABLE_THREAD5")) {
344 fDisableThread[4] = TRUE;
345 }
346 }
347
348 if(teb) {
349 if(teb->o.odin.threadId < 5 && fDisableThread[teb->o.odin.threadId-1] == 1) {
350 SetFS(sel);
351 return 1;
352 }
353 }
354
355 if(!tekst) {
356 if(flog) fflush( flog);
357 SetFS(sel);
358 return 1;
359 }
360
361 if(fLogging && flog && (dwEnableLogging > 0))
362 {
363 va_start(argptr, tekst);
364
365#ifdef WIN32_IP_LOGGING
366 if(logSocket == -1) {
367#endif
368 if(teb)
369 {
370 ULONG ulCallDepth;
371#ifdef DEBUG
372 ulCallDepth = teb->o.odin.dbgCallDepth;
373#else
374 ulCallDepth = 0;
375#endif
376
377 teb->o.odin.logfile = (DWORD)flog;
378
379#ifdef LOG_TIME
380 if(sel == 0x150b && !fIsOS2Image)
381 fprintf(flog,
382 "t%02d (%3d): (%x) (FS=150B) ",
383 LOWORD(teb->o.odin.threadId),
384 ulCallDepth,
385 GetTickCount());
386 else
387 fprintf(flog,
388 "t%02d (%3d): (%x) ",
389 LOWORD(teb->o.odin.threadId),
390 ulCallDepth,
391 GetTickCount());
392#else
393 if(sel == 0x150b && !fIsOS2Image)
394 fprintf(flog,
395#ifdef SHOW_FPU_CONTROLREG
396 "t%02d (%3d)(%3x): ",
397 LOWORD(teb->o.odin.threadId),
398 ulCallDepth,
399 CONTROL87(0,0));
400#else
401 "t%02d (%3d): (FS=150B) ",
402 LOWORD(teb->o.odin.threadId),
403 ulCallDepth);
404#endif
405 else
406 fprintf(flog,
407#ifdef SHOW_FPU_CONTROLREG
408 "t%02d (%3d)(%3x): ",
409 LOWORD(teb->o.odin.threadId),
410 ulCallDepth,
411 CONTROL87(0,0));
412#else
413 "t%02d (%3d): ",
414 LOWORD(teb->o.odin.threadId),
415 ulCallDepth);
416#endif
417#endif
418 }
419#ifdef LOG_TIME
420 else {
421 fprintf(flog, "tX: (%x) ", GetTickCount());
422 }
423#endif
424#ifdef WIN32_IP_LOGGING
425 }
426#endif
427
428#ifdef WIN32_IP_LOGGING
429 if(logSocket != -1) {
430 char logbuffer[1024];
431 int prefixlen = 0;
432
433 if(teb)
434 {
435 ULONG ulCallDepth;
436#ifdef DEBUG
437 ulCallDepth = teb->o.odin.dbgCallDepth;
438#else
439 ulCallDepth = 0;
440#endif
441 if(sel == 0x150b && !fIsOS2Image)
442 sprintf(logbuffer, "t%02d (%3d): (FS=150B) ",
443 LOWORD(teb->o.odin.threadId), ulCallDepth);
444 else
445 sprintf(logbuffer, "t%02d (%3d): ",
446 LOWORD(teb->o.odin.threadId), ulCallDepth);
447 prefixlen = strlen(logbuffer);
448 }
449
450 vsprintf(&logbuffer[prefixlen], tekst, argptr);
451
452 int rc;
453
454 rc = sendto(logSocket, logbuffer, strlen(logbuffer)+1, 0, (struct sockaddr *)&servername, sizeof(servername));
455
456 if(teb) teb->o.odin.logfile = 0;
457 va_end(argptr);
458 }
459 else {
460 vfprintf(flog, tekst, argptr);
461 if(teb) teb->o.odin.logfile = 0;
462 va_end(argptr);
463
464 if(tekst[strlen(tekst)-1] != '\n')
465 fprintf(flog, "\n");
466
467 if(fFlushLines)
468 fflush(flog);
469 }
470#else
471 vfprintf(flog, tekst, argptr);
472 if(teb) teb->o.odin.logfile = 0;
473 va_end(argptr);
474
475 if(tekst[strlen(tekst)-1] != '\n')
476 fprintf(flog, "\n");
477
478 if(fFlushLines)
479 fflush(flog);
480#endif
481 }
482 SetFS(sel);
483 return 1;
484}
485//******************************************************************************
486//******************************************************************************
487int SYSTEM WriteLogNoEOL(char *tekst, ...)
488{
489 USHORT sel = RestoreOS2FS();
490 va_list argptr;
491
492 ODIN_HEAPCHECK();
493
494 if(!init)
495 {
496 init = TRUE;
497
498#ifdef DEFAULT_LOGGING_OFF
499 if(getenv("WIN32LOG_ENABLED")) {
500#else
501 if(!getenv("NOWIN32LOG")) {
502#endif
503 char logname[CCHMAXPATH];
504
505 sprintf(logname, "odin32_%d.log", loadNr);
506 flog = fopen(logname, "w");
507 if(flog == NULL) {//probably running exe on readonly device
508 sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr);
509 flog = fopen(logname, "w");
510 }
511 }
512 else
513 fLogging = FALSE;
514 }
515
516 if(fLogging && flog && (dwEnableLogging > 0))
517 {
518 TEB *teb = GetThreadTEB();
519
520 va_start(argptr, tekst);
521 if(teb) {
522 teb->o.odin.logfile = (DWORD)flog;
523 }
524 vfprintf(flog, tekst, argptr);
525 if(teb) teb->o.odin.logfile = 0;
526 va_end(argptr);
527 }
528 SetFS(sel);
529 return 1;
530}
531//******************************************************************************
532//******************************************************************************
533void SYSTEM DecreaseLogCount()
534{
535 dwEnableLogging--;
536}
537//******************************************************************************
538//******************************************************************************
539void SYSTEM IncreaseLogCount()
540{
541 dwEnableLogging++;
542}
543//******************************************************************************
544//******************************************************************************
545int SYSTEM WritePrivateLog(void *logfile, char *tekst, ...)
546{
547 USHORT sel = RestoreOS2FS();
548 va_list argptr;
549
550 if(fLogging && logfile)
551 {
552 TEB *teb = GetThreadTEB();
553
554 va_start(argptr, tekst);
555 if(teb) {
556 teb->o.odin.logfile = (DWORD)flog;
557 }
558 vfprintf((FILE *)logfile, tekst, argptr);
559 if(teb) teb->o.odin.logfile = 0;
560 va_end(argptr);
561
562 if(tekst[strlen(tekst)-1] != '\n')
563 fprintf((FILE *)logfile, "\n");
564 }
565
566 SetFS(sel);
567 return 1;
568}
569//******************************************************************************
570//WriteLog has to take special care to handle dprintfs inside our os/2 exception
571//handler; if an exception occurs inside a dprintf, using dprintf in the exception
572//handler will hang the process
573//******************************************************************************
574int LogException(int state, int prevlock)
575{
576 TEB *teb = GetThreadTEB();
577 int ret = 0;
578
579 if (!teb) return 0;
580
581#if !defined(__EMX__)
582 if (teb->o.odin.logfile)
583 {
584#if (__IBMCPP__ == 300) || (__IBMC__ == 300)
585 PUSHORT lock = (USHORT *)(teb->o.odin.logfile+0x1C);
586#else
587#if __IBMC__ >= 360 || __IBMCPP__ >= 360
588//TODO: test this!!!!!!!
589 PUSHORT lock = (USHORT *)(teb->o.odin.logfile+0x1C);
590#else
591#error Check the offset of the lock count word in the file stream structure for this compiler revision!!!!!
592#endif
593#endif
594 ret = (*lock);
595 if (state == ENTER_EXCEPTION)
596 {
597 if((*lock) > 0) (*lock)--;
598 }
599 else
600 { //LEAVE_EXCEPTION
601 if(prevlock) (*lock)++;
602 }
603 }
604#else
605//kso 2001-01-29: EMX/GCC
606// we maybe should do something with the _more->rsem (_rmutex) structure but
607// I wanna have this compile, so we'll address problems later.
608#endif
609 return ret;
610}
611//******************************************************************************
612//Check if the exception occurred inside a fprintf (logging THDB member set)
613//If true, decrease the lock count for that file stream
614//NOTE: HACK: DEPENDS ON COMPILER VERSION!!!!
615//******************************************************************************
616void CheckLogException()
617{
618 TEB *teb = GetThreadTEB();
619 PUSHORT lock;
620
621 if(!teb) return;
622
623#if !defined(__EMX__)
624 if(teb->o.odin.logfile) {
625 //oops, exception in vfprintf; let's clear the lock count
626#if (__IBMCPP__ == 300) || (__IBMC__ == 300)
627 lock = (PUSHORT)(teb->o.odin.logfile+0x1C);
628#else
629#if __IBMC__ >= 360 || __IBMCPP__ >= 360
630//TODO: test this!!!!!!!
631 PUSHORT lock = (USHORT *)(teb->o.odin.logfile+0x1C);
632#else
633#error Check the offset of the lock count word in the file stream structure for this compiler revision!!!!!
634#endif
635#endif
636 (*lock)--;
637 }
638#else
639//kso 2001-01-29: EMX/GCC
640// we maybe should do something with the _more->rsem (_rmutex) structure but
641// I wanna have this compile, so we'll address problems later.
642#endif
643}
644//******************************************************************************
645//NOTE: No need to save/restore FS, as our FS selectors have already been
646// destroyed and FS == 0x150B.
647//******************************************************************************
648void CloseLogFile()
649{
650 if(oldcrtmsghandle)
651 _set_crt_msg_handle(oldcrtmsghandle);
652
653#ifdef WIN32_IP_LOGGING
654 if(logSocket != -1) {
655 soclose(logSocket);
656 }
657#endif
658
659 if(flog) fclose(flog);
660 flog = 0;
661}
662//******************************************************************************
663//Used to open any private logfiles used in kernel32 (for now only in winimagepeldr.cpp)
664//******************************************************************************
665void OpenPrivateLogFiles()
666{
667#ifdef DEFAULT_LOGGING_OFF
668 if(getenv("WIN32LOG_ENABLED")) {
669#else
670 if(!getenv("NOWIN32LOG")) {
671#endif
672 OpenPrivateLogFilePE();
673 }
674}
675//******************************************************************************
676//Used to close all private logfiles used in kernel32 (for now only in winimagepeldr.cpp)
677//******************************************************************************
678void ClosePrivateLogFiles()
679{
680#ifdef DEFAULT_LOGGING_OFF
681 if(getenv("WIN32LOG_ENABLED")) {
682#else
683 if(!getenv("NOWIN32LOG")) {
684#endif
685 ClosePrivateLogFilePE();
686 }
687}
688//******************************************************************************
689//******************************************************************************
690int SYSTEM WriteLogError(char *tekst, ...)
691{
692 USHORT sel = RestoreOS2FS();
693 va_list argptr;
694
695 va_start(argptr, tekst);
696 printf("ERROR: ");
697 vprintf(tekst, argptr);
698 va_end(argptr);
699 if(tekst[strlen(tekst)-1] != '\n')
700 printf("\n");
701
702 SetFS(sel);
703 return 1;
704}
705//******************************************************************************
706//******************************************************************************
707void SYSTEM CheckVersion(ULONG version, char *modname)
708{
709 dprintf(("CheckVersion of %s, %d\n", modname, version));
710 if(version != PE2LX_VERSION){
711 static char msg[300];
712 int r;
713 dprintf(("Version mismatch! %d, %d: %s\n", version, PE2LX_VERSION, modname));
714 sprintf(msg, "%s is intended for use with a different release of Odin.\n", modname);
715 do{
716 r = WinMessageBox(HWND_DESKTOP, NULLHANDLE, msg, "Version Mismatch!", 0, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_MOVEABLE);
717 }while(r == MBID_RETRY); // giggle
718 if( r != MBID_IGNORE )
719 exit(987);
720 }
721}
722//******************************************************************************
723//******************************************************************************
724void SYSTEM CheckVersionFromHMOD(ULONG version, HMODULE hModule)
725{
726 char name[_MAX_PATH];
727
728 // query name of dll.
729 if(!DosQueryModuleName(hModule, sizeof(name), name))
730 CheckVersion(version, name);
731}
732//******************************************************************************
733//******************************************************************************
734#ifdef __WATCOMC__ /*PLF Sat 97-06-21 17:12:36*/
735 extern void interrupt3( void );
736 #pragma aux interrupt3= \
737 "int 3"
738#endif
739void WIN32API DebugBreak()
740{
741 dprintf(("DebugBreak\n"));
742
743 LPSTR lpstrEnv = getenv("WIN32.DEBUGBREAK"); /* query environment */
744 if (lpstrEnv == NULL) /* if environment is not set, don't call debugger ! */
745 return;
746
747#ifdef __WATCOMC__
748 interrupt3();
749#else
750 _interrupt(3);
751#endif
752}
753//******************************************************************************
754//******************************************************************************
755
756
757/*****************************************************************************
758 * Name : DebugErrorBox
759 * Purpose : display an apprioriate error box with detailed information
760 * about the error cause
761 * Parameters: APIRET iErrorCode - OS/2 error code
762 * PSZ pszFormat - printf-format string
763 * ...
764 * Variables :
765 * Result : return code of the message box
766 * Remark :
767 * Status :
768 *
769 * Author : Patrick Haller [Tue, 1999/09/13 19:55]
770 *****************************************************************************/
771
772int SYSTEM DebugErrorBox(ULONG iErrorCode,
773 char* pszFormat,
774 ...)
775{
776 char szMessageBuffer[1024]; /* buffer for the text message */
777 char szErrorBuffer[1024]; /* buffer for the operating system text */
778 ULONG bc; /* dummy */
779 APIRET rc2; /* API returncode */
780 int iRC; /* message box return code */
781
782 USHORT sel = RestoreOS2FS();
783 va_list argptr;
784
785 // clear memory
786 memset (szMessageBuffer, 0, sizeof(szMessageBuffer));
787 memset (szErrorBuffer, 0, sizeof(szErrorBuffer));
788
789 // build message string
790 va_start(argptr, pszFormat);
791 vsprintf(szMessageBuffer, pszFormat, argptr);
792 va_end(argptr);
793
794 // query error string
795 rc2 = DosGetMessage(NULL,
796 0,
797 szErrorBuffer,
798 sizeof(szErrorBuffer),
799 iErrorCode,
800 "OSO001.MSG",
801 &bc);
802
803 // display message box
804 iRC = WinMessageBox(HWND_DESKTOP,
805 NULLHANDLE,
806 szMessageBuffer,
807 szErrorBuffer,
808 0,
809 MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
810 SetFS(sel);
811 return iRC;
812}
813
814
815/**
816 * Query Odin32 build number.
817 * @returns Build number.
818 * @status Completely implemented.
819 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
820 */
821int WIN32API Odin32GetBuildNumber(void)
822{
823 dprintf(("Odin32GetBuildNumber returned %d\n", ODIN32_BUILD_NR));
824 return ODIN32_BUILD_NR;
825}
826
Note: See TracBrowser for help on using the repository browser.