source: trunk/tools/common/kAssert.c@ 8003

Last change on this file since 8003 was 8003, checked in by bird, 24 years ago

New kFile* classes; now in sync with os2tools.

File size: 2.5 KB
Line 
1/* $Id: kAssert.c,v 1.1 2002-02-24 02:47:23 bird Exp $
2 *
3 * kAssert - Assertion helper functions.
4 *
5 * Copyright (c) 2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
6 *
7 * GPL
8 *
9 */
10#ifndef NOFILEID
11static const char szFileId[] = "$Id: kAssert.c,v 1.1 2002-02-24 02:47:23 bird Exp $";
12#endif
13
14
15/*******************************************************************************
16* Header Files *
17*******************************************************************************/
18#define INCL_BASE
19#include <os2.h>
20
21#include <stdio.h>
22#include "kTypes.h"
23
24
25/**
26 * This function will display and log assertions which failes.
27 * @returns TRUE: issue breakpoint instruction
28 * FALSE: continue execution.
29 * @param pszExpr
30 * @param pszFilename Name of the file the kASSERT macro is called from.
31 * @param uLine Line number (within pszFilename) of the kASSERT macro call.
32 * @param pszFunction Name of the function the kASSERT macro is called from.
33 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
34 */
35KBOOL KLIBCALL kAssertMsg(const char *pszExpr, const char *pszFilename, unsigned uLine, const char *pszFunction)
36{
37 PTIB ptib;
38 PPIB ppib;
39 KBOOL fRc = TRUE;
40
41 DosGetInfoBlocks(&ptib, &ppib);
42 if (ppib->pib_ultype != 3) /* !PM */
43 {
44 fprintf(stderr,
45 "\n"
46 "Assertion Failed: %.640s\n"
47 "File: %.260s\n"
48 "Line: %d\n"
49 "Function: %.128s\n",
50 pszExpr, pszFilename, uLine, pszFunction);
51 }
52 else
53 {
54 char szTitle[42];
55 char szMsg[1024];
56 HAB hab;
57 HMQ hmq;
58 hab = WinInitialize(0);
59 hmq = WinCreateMsgQueue(hab, 0);
60
61 /*
62 * Format a title.
63 */
64 if (DosQueryModuleName(ppib->pib_hmte, sizeof(szTitle), &szTitle[0]))
65 sprintf(szTitle, "Process 0x%x(%d)", ppib->pib_ulpid, ppib->pib_ulpid);
66
67 /*
68 * Format the message.
69 */
70 sprintf(szMsg,
71 "\n"
72 "Assertion Failed: %.640s\n"
73 "File: %.260s\n"
74 "Line: %d\n"
75 "Function: %.128s\n",
76 pszExpr, pszFilename, uLine, pszFunction);
77
78 fRc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szTitle, szMsg, 0,
79 MB_ABORTRETRYIGNORE | MB_MOVEABLE | MB_APPLMODAL) != MBID_IGNORE;
80
81 WinDestroyMsgQueue(hmq);
82 WinTerminate(hab);
83 }
84 return fRc;
85}
86
87
Note: See TracBrowser for help on using the repository browser.