| 1 | /* $Id: misc.cpp,v 1.19 2000-01-25 21:00:39 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 5 | * Logging procedures
|
|---|
| 6 | *
|
|---|
| 7 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 8 | * Copyright 1998 Joel Troster
|
|---|
| 9 | * Copyright 1998 Peter FitzSimmons
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | /*****************************************************************************
|
|---|
| 15 | * Includes *
|
|---|
| 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 <misc.h>
|
|---|
| 29 | #include "initterm.h"
|
|---|
| 30 | #include "logging.h"
|
|---|
| 31 | #include <wprocess.h>
|
|---|
| 32 |
|
|---|
| 33 | /*****************************************************************************
|
|---|
| 34 | * PMPRINTF Version *
|
|---|
| 35 | *****************************************************************************/
|
|---|
| 36 |
|
|---|
| 37 | #ifdef PMPRINTF
|
|---|
| 38 |
|
|---|
| 39 | /* ----- Customization variables ----- */
|
|---|
| 40 | #define PRINTFID ""
|
|---|
| 41 | #define PRINTFMAXLEN 300
|
|---|
| 42 | #define PRINTFLINELEN 100
|
|---|
| 43 | #define PRINTFTHREADS 54
|
|---|
| 44 | #define PRINTFQNAME "\\QUEUES\\PRINTF32"
|
|---|
| 45 |
|
|---|
| 46 | /* ----- Includes and externals ----- */
|
|---|
| 47 | #include <stddef.h> /* .. */
|
|---|
| 48 | #include <time.h> /* .. */
|
|---|
| 49 |
|
|---|
| 50 | extern ULONG flAllocMem; /*Tue 03.03.1998: knut */
|
|---|
| 51 |
|
|---|
| 52 | /* ----- Local defines ----- */
|
|---|
| 53 | #define PRINTFIDSIZE sizeof(PRINTFID)
|
|---|
| 54 | #define PRINTFMAXBUF PRINTFIDSIZE+PRINTFLINELEN
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | /*****************************************************************************
|
|---|
| 58 | * Structures *
|
|---|
| 59 | *****************************************************************************/
|
|---|
| 60 |
|
|---|
| 61 | /* ----- Per-thread output buffer and current indices into line ---- */
|
|---|
| 62 | struct perthread {
|
|---|
| 63 | LONG lineindex; /* where next char */
|
|---|
| 64 | LONG tidemark; /* rightmost char */
|
|---|
| 65 | int bell; /* TRUE if line has bell */
|
|---|
| 66 | UCHAR line[PRINTFMAXBUF]; /* accumulator */
|
|---|
| 67 | };
|
|---|
| 68 |
|
|---|
| 69 | /* ----- Local static variables ----- */
|
|---|
| 70 | static ULONG ourpid=0; /* our process ID */
|
|---|
| 71 | static ULONG servepid=0; /* process IDs of the server */
|
|---|
| 72 | static HQUEUE qhandle=0; /* handle for the queue */
|
|---|
| 73 | static struct perthread *tps[PRINTFTHREADS+1]; /* -> per-thread data */
|
|---|
| 74 |
|
|---|
| 75 | /* ----- Local subroutine ----- */
|
|---|
| 76 | static int printf_(struct perthread *);
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | /* ----------------------------------------------------------------- */
|
|---|
| 80 | /* The "printf" function. Note this has a variable number of */
|
|---|
| 81 | /* arguments. */
|
|---|
| 82 | /* ----------------------------------------------------------------- */
|
|---|
| 83 | int SYSTEM EXPORT WriteLog(char *f, ...)
|
|---|
| 84 | {
|
|---|
| 85 | TIB *ptib; /* process/thread id structures */
|
|---|
| 86 | PIB *ppib; /* .. */
|
|---|
| 87 | TID ourtid; /* thread ID */
|
|---|
| 88 | struct perthread *tp; /* pointer to per-thread data */
|
|---|
| 89 | int rc; /* returncode */
|
|---|
| 90 | ULONG urc; /* returncode */
|
|---|
| 91 |
|
|---|
| 92 | urc=DosOpenQueue(&servepid, &qhandle, PRINTFQNAME); /* Open the Q */
|
|---|
| 93 | /* Non-0 RC means Q does not exist or cannot be opened */
|
|---|
| 94 | if (urc==343) return 0; /* queue does not exist, so quit */
|
|---|
| 95 | if (urc!=0) return -1; /* report any other error */
|
|---|
| 96 |
|
|---|
| 97 | /* First determine our thread ID (and hence get access to the */
|
|---|
| 98 | /* correct per-thread data. If the per-thread data has not been */
|
|---|
| 99 | /* allocated, then allocate it now. It is never freed, once */
|
|---|
| 100 | /* allocated, as PRINTF is not notified of end-of-thread. */
|
|---|
| 101 | DosGetInfoBlocks(&ptib,&ppib); /* get process/thread info */
|
|---|
| 102 | ourtid=ptib->tib_ptib2->tib2_ultid; /* .. and copy TID */
|
|---|
| 103 | if (ourtid>PRINTFTHREADS) /* too many threads .. */
|
|---|
| 104 | return 0; /* .. so quit, quietly */
|
|---|
| 105 | tp=tps[ourtid]; /* copy to local pointer */
|
|---|
| 106 | if (tp==NULL) { /* uninitialized (NULL=0) */
|
|---|
| 107 | /* allocate a per-thread structure */
|
|---|
| 108 | tp=(struct perthread *)malloc(sizeof(struct perthread));
|
|---|
| 109 | if (tp==NULL) return -1; /* out of memory -- return error */
|
|---|
| 110 | tps[ourtid]=tp; /* save for future calls */
|
|---|
| 111 | strcpy(tp->line,PRINTFID); /* initialize: line.. */
|
|---|
| 112 | tp->lineindex=PRINTFIDSIZE-1; /* ..where next char */
|
|---|
| 113 | tp->tidemark =PRINTFIDSIZE-2; /* ..rightmost char */
|
|---|
| 114 | tp->bell=FALSE; /* ..if line has bell */
|
|---|
| 115 | if (ourpid==0) ourpid=ppib->pib_ulpid; /* save PID for all to use */
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | { /* Block for declarations -- only needed if queue exists, etc. */
|
|---|
| 119 | LONG count; /* count of characters formatted */
|
|---|
| 120 | UCHAR buffer[PRINTFMAXLEN+1]; /* formatting area */
|
|---|
| 121 | LONG i, newind; /* work */
|
|---|
| 122 | UCHAR ch; /* .. */
|
|---|
| 123 | va_list argptr; /* -> variable argument list */
|
|---|
| 124 |
|
|---|
| 125 | va_start(argptr, f); /* get pointer to argument list */
|
|---|
| 126 | count=vsprintf(buffer, f, argptr);
|
|---|
| 127 | va_end(argptr); /* done with variable arguments */
|
|---|
| 128 |
|
|---|
| 129 | if (count<0) return count-1000;/* bad start */
|
|---|
| 130 |
|
|---|
| 131 | if (count>PRINTFMAXLEN) {
|
|---|
| 132 | /* Disaster -- we are probably "dead", but just in case we */
|
|---|
| 133 | /* are not, carry on with truncated data. */
|
|---|
| 134 | count=PRINTFMAXLEN;
|
|---|
| 135 | }
|
|---|
| 136 | buffer[count]='\0'; /* ensure terminated */
|
|---|
| 137 | /* OK, ready to go with the data now in BUFFER */
|
|---|
| 138 | /* We copy from the formatted string to the output (line) buffer, */
|
|---|
| 139 | /* taking note of certain control characters and sending a line */
|
|---|
| 140 | /* the queue whenever we see a LF control, or when the line */
|
|---|
| 141 | /* fills (causing a forced break). */
|
|---|
| 142 | for (i=0; ; i++) {
|
|---|
| 143 | ch=buffer[i]; if (!ch) break;
|
|---|
| 144 | switch(ch) {
|
|---|
| 145 | case '\r': /* carriage return */
|
|---|
| 146 | tp->lineindex=PRINTFIDSIZE-1; /* back to start of line */
|
|---|
| 147 | break;
|
|---|
| 148 | case '\n': /* new line */
|
|---|
| 149 | case '\f': /* form feed */
|
|---|
| 150 | rc=printf_(tp); /* print a line */
|
|---|
| 151 | if (rc!=0) return rc; /* error */
|
|---|
| 152 | break;
|
|---|
| 153 | case '\t': /* tab */
|
|---|
| 154 | newind=tp->lineindex-PRINTFIDSIZE+1; /* offset into data */
|
|---|
| 155 | newind=tp->lineindex+5-newind%5; /* new index requested */
|
|---|
| 156 | if (newind>=PRINTFMAXBUF) newind=PRINTFMAXBUF; /* clamp */
|
|---|
| 157 | for (; tp->lineindex<newind; tp->lineindex++) {
|
|---|
| 158 | if (tp->lineindex>tp->tidemark) { /* beyond current end */
|
|---|
| 159 | tp->line[tp->lineindex]=' '; /* add space */
|
|---|
| 160 | tp->tidemark=tp->lineindex;
|
|---|
| 161 | }
|
|---|
| 162 | }
|
|---|
| 163 | break;
|
|---|
| 164 | case '\v': /* vertical tab */
|
|---|
| 165 | /* ignore it */
|
|---|
| 166 | break;
|
|---|
| 167 | case '\b': /* backspace */
|
|---|
| 168 | tp->lineindex=max(tp->lineindex-1,PRINTFIDSIZE);
|
|---|
| 169 | break;
|
|---|
| 170 | case '\a': /* alert (bell) */
|
|---|
| 171 | tp->bell=TRUE;
|
|---|
| 172 | break;
|
|---|
| 173 | default: /* ordinary character */
|
|---|
| 174 | tp->line[tp->lineindex]=ch;
|
|---|
| 175 | if (tp->lineindex>tp->tidemark) /* is rightmost.. */
|
|---|
| 176 | tp->tidemark=tp->lineindex;
|
|---|
| 177 | tp->lineindex++; /* step for next */
|
|---|
| 178 | } /* switch */
|
|---|
| 179 | if (tp->lineindex>=PRINTFMAXBUF) {
|
|---|
| 180 | rc=printf_(tp); /* print a line */
|
|---|
| 181 | if (rc!=0) return rc; /* error */
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | } /* copy loop */
|
|---|
| 185 | return count; /* all formatted data processed */
|
|---|
| 186 | } /* block */
|
|---|
| 187 | } /* printf */
|
|---|
| 188 |
|
|---|
| 189 | /* ----- printf_(tp) -- Local subroutine to send a line ------------ */
|
|---|
| 190 | /* A line has been completed (or overflowed): write it to the queue. */
|
|---|
| 191 | int printf_(struct perthread *tp) /* pointer to per-thread data */
|
|---|
| 192 | {
|
|---|
| 193 | ULONG urc; /* unsigned returncode */
|
|---|
| 194 | PSZ pszTo, pszFrom; /* character pointers */
|
|---|
| 195 | PVOID addr; /* address of output data */
|
|---|
| 196 | long size; /* total size of output data */
|
|---|
| 197 | time_t timenow; /* holds current time */
|
|---|
| 198 |
|
|---|
| 199 | tp->line[tp->tidemark+1]='\0'; /* add terminator */
|
|---|
| 200 | size=tp->tidemark+2; /* total length of data */
|
|---|
| 201 |
|
|---|
| 202 | /* Get some shared memory that can be given away */
|
|---|
| 203 | urc=DosAllocSharedMem(&addr, NULL, (unsigned)size,
|
|---|
| 204 | OBJ_GIVEABLE|PAG_WRITE|PAG_COMMIT|flAllocMem);
|
|---|
| 205 | /*knut: added flAllocMem */
|
|---|
| 206 |
|
|---|
| 207 | if (urc!=0) return -2; /* error */
|
|---|
| 208 |
|
|---|
| 209 | pszTo=addr; /* copy for clarity */
|
|---|
| 210 | pszFrom=&(tp->line[0]); /* pointer to source */
|
|---|
| 211 | strcpy(pszTo,pszFrom); /* copy the string to shared memory */
|
|---|
| 212 |
|
|---|
| 213 | if (ourpid!=servepid) { /* (no giveaway needed if to self) */
|
|---|
| 214 | urc=DosGiveSharedMem(addr, servepid, PAG_READ); /* give access */
|
|---|
| 215 | if (urc!=0) return -3;} /* error */
|
|---|
| 216 |
|
|---|
| 217 | /* Write the selector, size, and timestamp to the queue */
|
|---|
| 218 | if (tp->bell) size=-size; /* BELL passed by negation */
|
|---|
| 219 | time(&timenow); /* optional - else use 0 */
|
|---|
| 220 | urc=DosWriteQueue(qhandle, /* handle */
|
|---|
| 221 | (unsigned)timenow, /* 'request' (timestamp) */
|
|---|
| 222 | (unsigned)size, /* 'length' (length/bell) */
|
|---|
| 223 | addr, /* 'address' (address) */
|
|---|
| 224 | 0); /* priority (FIFO if enabled) */
|
|---|
| 225 | if (urc!=0) return -4; /* error */
|
|---|
| 226 | if (ourpid!=servepid) { /* if given away.. */
|
|---|
| 227 | urc=DosFreeMem(addr); /* .. *we* are done with it */
|
|---|
| 228 | if (urc!=0) return -5;} /* error */
|
|---|
| 229 | /* Reset the line buffer and indices */
|
|---|
| 230 | tp->lineindex=PRINTFIDSIZE-1; /* where next char */
|
|---|
| 231 | tp->tidemark =PRINTFIDSIZE-2; /* rightmost char */
|
|---|
| 232 | tp->bell =FALSE; /* true if line has bell */
|
|---|
| 233 | return 0; /* success! */
|
|---|
| 234 | } /* printf_ */
|
|---|
| 235 | #endif
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 | /*****************************************************************************
|
|---|
| 240 | * Standard Version *
|
|---|
| 241 | *****************************************************************************/
|
|---|
| 242 |
|
|---|
| 243 | static FILE *flog = NULL; /*PLF Mon 97-09-08 20:00:15*/
|
|---|
| 244 | static BOOL init = FALSE;
|
|---|
| 245 | static BOOL fLogging = TRUE;
|
|---|
| 246 | static int dwEnableLogging = 1;
|
|---|
| 247 |
|
|---|
| 248 | int SYSTEM EXPORT WriteLog(char *tekst, ...)
|
|---|
| 249 | {
|
|---|
| 250 | USHORT sel = RestoreOS2FS();
|
|---|
| 251 | va_list argptr;
|
|---|
| 252 |
|
|---|
| 253 | if(!init)
|
|---|
| 254 | {
|
|---|
| 255 | init = TRUE;
|
|---|
| 256 |
|
|---|
| 257 | #ifdef DEFAULT_LOGGING_OFF
|
|---|
| 258 | if(getenv("WIN32LOG_ENABLED")) {
|
|---|
| 259 | #else
|
|---|
| 260 | if(!getenv("NOWIN32LOG")) {
|
|---|
| 261 | #endif
|
|---|
| 262 | char logname[CCHMAXPATH];
|
|---|
| 263 |
|
|---|
| 264 | sprintf(logname, "odin32_%d.log", loadNr);
|
|---|
| 265 | flog = fopen(logname, "w");
|
|---|
| 266 | if(flog == NULL) {//probably running exe on readonly device
|
|---|
| 267 | sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr);
|
|---|
| 268 | flog = fopen(logname, "w");
|
|---|
| 269 | }
|
|---|
| 270 | }
|
|---|
| 271 | else
|
|---|
| 272 | fLogging = FALSE;
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | if(fLogging && flog && (dwEnableLogging > 0))
|
|---|
| 276 | {
|
|---|
| 277 | THDB *thdb = GetThreadTHDB();
|
|---|
| 278 |
|
|---|
| 279 | va_start(argptr, tekst);
|
|---|
| 280 | if(thdb) {
|
|---|
| 281 | thdb->logfile = (DWORD)flog;
|
|---|
| 282 | fprintf(flog, "t%d: ", thdb->threadId);
|
|---|
| 283 | }
|
|---|
| 284 | vfprintf(flog, tekst, argptr);
|
|---|
| 285 | if(thdb) thdb->logfile = 0;
|
|---|
| 286 | va_end(argptr);
|
|---|
| 287 |
|
|---|
| 288 | if(tekst[strlen(tekst)-1] != '\n')
|
|---|
| 289 | fprintf(flog, "\n");
|
|---|
| 290 | }
|
|---|
| 291 | SetFS(sel);
|
|---|
| 292 | return 1;
|
|---|
| 293 | }
|
|---|
| 294 | //******************************************************************************
|
|---|
| 295 | //******************************************************************************
|
|---|
| 296 | void SYSTEM DecreaseLogCount()
|
|---|
| 297 | {
|
|---|
| 298 | dwEnableLogging--;
|
|---|
| 299 | }
|
|---|
| 300 | //******************************************************************************
|
|---|
| 301 | //******************************************************************************
|
|---|
| 302 | void SYSTEM IncreaseLogCount()
|
|---|
| 303 | {
|
|---|
| 304 | dwEnableLogging++;
|
|---|
| 305 | }
|
|---|
| 306 | //******************************************************************************
|
|---|
| 307 | //******************************************************************************
|
|---|
| 308 | int SYSTEM EXPORT WritePrivateLog(void *logfile, char *tekst, ...)
|
|---|
| 309 | {
|
|---|
| 310 | USHORT sel = RestoreOS2FS();
|
|---|
| 311 | va_list argptr;
|
|---|
| 312 |
|
|---|
| 313 | if(fLogging && logfile)
|
|---|
| 314 | {
|
|---|
| 315 | THDB *thdb = GetThreadTHDB();
|
|---|
| 316 |
|
|---|
| 317 | va_start(argptr, tekst);
|
|---|
| 318 | if(thdb) {
|
|---|
| 319 | thdb->logfile = (DWORD)flog;
|
|---|
| 320 | fprintf(flog, "t%d", thdb->threadId);
|
|---|
| 321 | }
|
|---|
| 322 | vfprintf((FILE *)logfile, tekst, argptr);
|
|---|
| 323 | if(thdb) thdb->logfile = 0;
|
|---|
| 324 | va_end(argptr);
|
|---|
| 325 |
|
|---|
| 326 | if(tekst[strlen(tekst)-1] != '\n')
|
|---|
| 327 | fprintf((FILE *)logfile, "\n");
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | SetFS(sel);
|
|---|
| 331 | return 1;
|
|---|
| 332 | }
|
|---|
| 333 | //******************************************************************************
|
|---|
| 334 | //Check if the exception occurred inside a fprintf (logging THDB member set)
|
|---|
| 335 | //If true, decrease the lock count for that file stream
|
|---|
| 336 | //NOTE: HACK: DEPENDS ON COMPILER VERSION!!!!
|
|---|
| 337 | //******************************************************************************
|
|---|
| 338 | void CheckLogException()
|
|---|
| 339 | {
|
|---|
| 340 | THDB *thdb = GetThreadTHDB();
|
|---|
| 341 | USHORT *lock;
|
|---|
| 342 |
|
|---|
| 343 | if(!thdb) return;
|
|---|
| 344 |
|
|---|
| 345 | if(thdb->logfile) {
|
|---|
| 346 | //oops, exception in vfprintf; let's clear the lock count
|
|---|
| 347 | #if (__IBMCPP__ == 300) || (__IBMC__ == 300)
|
|---|
| 348 | lock = (USHORT *)(thdb->logfile+0x1C);
|
|---|
| 349 | #else
|
|---|
| 350 | #error Check the offset of the lock count word in the file stream structure for this compiler revision!!!!!
|
|---|
| 351 | #endif
|
|---|
| 352 | (*lock)--;
|
|---|
| 353 | }
|
|---|
| 354 | }
|
|---|
| 355 | //******************************************************************************
|
|---|
| 356 | //NOTE: No need to save/restore FS, as our FS selectors have already been
|
|---|
| 357 | // destroyed and FS == 0x150B.
|
|---|
| 358 | //******************************************************************************
|
|---|
| 359 | void CloseLogFile()
|
|---|
| 360 | {
|
|---|
| 361 | fclose(flog);
|
|---|
| 362 | flog = 0;
|
|---|
| 363 | }
|
|---|
| 364 | //******************************************************************************
|
|---|
| 365 | //Used to open any private logfiles used in kernel32 (for now only in winimagepeldr.cpp)
|
|---|
| 366 | //******************************************************************************
|
|---|
| 367 | void OpenPrivateLogFiles()
|
|---|
| 368 | {
|
|---|
| 369 | #ifdef DEFAULT_LOGGING_OFF
|
|---|
| 370 | if(getenv("WIN32LOG_ENABLED")) {
|
|---|
| 371 | #else
|
|---|
| 372 | if(!getenv("NOWIN32LOG")) {
|
|---|
| 373 | #endif
|
|---|
| 374 | OpenPrivateLogFilePE();
|
|---|
| 375 | }
|
|---|
| 376 | }
|
|---|
| 377 | //******************************************************************************
|
|---|
| 378 | //Used to close all private logfiles used in kernel32 (for now only in winimagepeldr.cpp)
|
|---|
| 379 | //******************************************************************************
|
|---|
| 380 | void ClosePrivateLogFiles()
|
|---|
| 381 | {
|
|---|
| 382 | #ifdef DEFAULT_LOGGING_OFF
|
|---|
| 383 | if(getenv("WIN32LOG_ENABLED")) {
|
|---|
| 384 | #else
|
|---|
| 385 | if(!getenv("NOWIN32LOG")) {
|
|---|
| 386 | #endif
|
|---|
| 387 | ClosePrivateLogFilePE();
|
|---|
| 388 | }
|
|---|
| 389 | }
|
|---|
| 390 | //******************************************************************************
|
|---|
| 391 | //******************************************************************************
|
|---|
| 392 | int SYSTEM EXPORT WriteLogError(char *tekst, ...)
|
|---|
| 393 | {
|
|---|
| 394 | USHORT sel = RestoreOS2FS();
|
|---|
| 395 | va_list argptr;
|
|---|
| 396 |
|
|---|
| 397 | va_start(argptr, tekst);
|
|---|
| 398 | printf("ERROR: ");
|
|---|
| 399 | vprintf(tekst, argptr);
|
|---|
| 400 | va_end(argptr);
|
|---|
| 401 | if(tekst[strlen(tekst)-1] != '\n')
|
|---|
| 402 | printf("\n");
|
|---|
| 403 |
|
|---|
| 404 | SetFS(sel);
|
|---|
| 405 | return 1;
|
|---|
| 406 | }
|
|---|
| 407 | //******************************************************************************
|
|---|
| 408 | //******************************************************************************
|
|---|
| 409 | void SYSTEM CheckVersion(ULONG version, char *modname)
|
|---|
| 410 | {
|
|---|
| 411 | dprintf(("CheckVersion of %s, %d\n", modname, version));
|
|---|
| 412 | if(version != PE2LX_VERSION){
|
|---|
| 413 | static char msg[300];
|
|---|
| 414 | int r;
|
|---|
| 415 | dprintf(("Version mismatch! %d, %d: %s\n", version, PE2LX_VERSION, modname));
|
|---|
| 416 | sprintf(msg, "%s is intended for use with a different release of PE2LX.\n", modname);
|
|---|
| 417 | do{
|
|---|
| 418 | r = WinMessageBox(HWND_DESKTOP, NULLHANDLE, msg, "Version Mismatch!", 0, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_MOVEABLE);
|
|---|
| 419 | }while(r == MBID_RETRY); // giggle
|
|---|
| 420 | if( r != MBID_IGNORE )
|
|---|
| 421 | exit(987);
|
|---|
| 422 | }
|
|---|
| 423 | }
|
|---|
| 424 | //******************************************************************************
|
|---|
| 425 | //******************************************************************************
|
|---|
| 426 | void SYSTEM CheckVersionFromHMOD(ULONG version, HMODULE hModule)
|
|---|
| 427 | {
|
|---|
| 428 | char name[_MAX_PATH];
|
|---|
| 429 |
|
|---|
| 430 | // query name of dll.
|
|---|
| 431 | if(!DosQueryModuleName(hModule, sizeof(name), name))
|
|---|
| 432 | CheckVersion(version, name);
|
|---|
| 433 | }
|
|---|
| 434 | //******************************************************************************
|
|---|
| 435 | //******************************************************************************
|
|---|
| 436 | #ifdef __WATCOMC__ /*PLF Sat 97-06-21 17:12:36*/
|
|---|
| 437 | extern void interrupt3( void );
|
|---|
| 438 | #pragma aux interrupt3= \
|
|---|
| 439 | "int 3"
|
|---|
| 440 | #endif
|
|---|
| 441 | void WIN32API DebugBreak()
|
|---|
| 442 | {
|
|---|
| 443 | dprintf(("DebugBreak\n"));
|
|---|
| 444 |
|
|---|
| 445 | LPSTR lpstrEnv = getenv("WIN32.DEBUGBREAK"); /* query environment */
|
|---|
| 446 | if (lpstrEnv == NULL) /* if environment is not set, don't call debugger ! */
|
|---|
| 447 | return;
|
|---|
| 448 |
|
|---|
| 449 | #ifdef __WATCOMC__
|
|---|
| 450 | interrupt3();
|
|---|
| 451 | #else
|
|---|
| 452 | _interrupt(3);
|
|---|
| 453 | #endif
|
|---|
| 454 | }
|
|---|
| 455 | //******************************************************************************
|
|---|
| 456 | //******************************************************************************
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 | /*****************************************************************************
|
|---|
| 460 | * Name : DebugErrorBox
|
|---|
| 461 | * Purpose : display an apprioriate error box with detailed information
|
|---|
| 462 | * about the error cause
|
|---|
| 463 | * Parameters: APIRET iErrorCode - OS/2 error code
|
|---|
| 464 | * PSZ pszFormat - printf-format string
|
|---|
| 465 | * ...
|
|---|
| 466 | * Variables :
|
|---|
| 467 | * Result : return code of the message box
|
|---|
| 468 | * Remark :
|
|---|
| 469 | * Status :
|
|---|
| 470 | *
|
|---|
| 471 | * Author : Patrick Haller [Tue, 1999/09/13 19:55]
|
|---|
| 472 | *****************************************************************************/
|
|---|
| 473 |
|
|---|
| 474 | int SYSTEM EXPORT DebugErrorBox(ULONG iErrorCode,
|
|---|
| 475 | char* pszFormat,
|
|---|
| 476 | ...)
|
|---|
| 477 | {
|
|---|
| 478 | char szMessageBuffer[1024]; /* buffer for the text message */
|
|---|
| 479 | char szErrorBuffer[1024]; /* buffer for the operating system text */
|
|---|
| 480 | ULONG bc; /* dummy */
|
|---|
| 481 | APIRET rc2; /* API returncode */
|
|---|
| 482 | int iRC; /* message box return code */
|
|---|
| 483 |
|
|---|
| 484 | USHORT sel = RestoreOS2FS();
|
|---|
| 485 | va_list argptr;
|
|---|
| 486 |
|
|---|
| 487 | // clear memory
|
|---|
| 488 | memset (szMessageBuffer, 0, sizeof(szMessageBuffer));
|
|---|
| 489 | memset (szErrorBuffer, 0, sizeof(szErrorBuffer));
|
|---|
| 490 |
|
|---|
| 491 | // build message string
|
|---|
| 492 | va_start(argptr, pszFormat);
|
|---|
| 493 | vsprintf(szMessageBuffer, pszFormat, argptr);
|
|---|
| 494 | va_end(argptr);
|
|---|
| 495 |
|
|---|
| 496 | // query error string
|
|---|
| 497 | rc2 = DosGetMessage(NULL,
|
|---|
| 498 | 0,
|
|---|
| 499 | szErrorBuffer,
|
|---|
| 500 | sizeof(szErrorBuffer),
|
|---|
| 501 | iErrorCode,
|
|---|
| 502 | "OSO001.MSG",
|
|---|
| 503 | &bc);
|
|---|
| 504 |
|
|---|
| 505 | // display message box
|
|---|
| 506 | iRC = WinMessageBox(HWND_DESKTOP,
|
|---|
| 507 | NULLHANDLE,
|
|---|
| 508 | szMessageBuffer,
|
|---|
| 509 | szErrorBuffer,
|
|---|
| 510 | 0,
|
|---|
| 511 | MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
|
|---|
| 512 | SetFS(sel);
|
|---|
| 513 | return iRC;
|
|---|
| 514 | }
|
|---|