Changeset 636 for trunk/dll


Ignore:
Timestamp:
Apr 24, 2007, 3:08:46 AM (19 years ago)
Author:
Steven Levine
Message:

Add Win_Error_NoMsgBox. Sync others to use common code.

Location:
trunk/dll
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/error.c

    r616 r636  
    2424  19 Apr 07 SHL Add DbgMsg
    2525  20 Apr 07 SHL Correct IDS_GENERR1TEXT formatting
     26  23 Apr 07 SHL Add Win_Error_NoMsgBox.  Rework others
    2627
    2728***********************************************************************/
     
    4344#pragma alloc_text(FMINPUT,Win_Error,Dos_Error,saymsg,showMsg)
    4445
     46static VOID formatWinError(PSZ pszBuf, UINT cBufBytes, HWND hwndErr, HWND hwndOwner,
     47                           PCSZ pszSrcFile, UINT uSrcLineNo,
     48                           PCSZ pszFmt, va_list pva);
     49
    4550static APIRET showMsg(ULONG mb_type, HWND hwnd, PCSZ pszTitle, PCSZ pszMsg, BOOL wantLog);
    4651
    47 //== Win_Error: report Win...() error using passed message string ===
    48 
    49 VOID Win_Error(HWND hwndErr, HWND hwndOwner, PCSZ pszFileName, ULONG ulLineNo,
    50                PCSZ pszFmt, ...)
    51 {
    52   PERRINFO pErrInfoBlk;         /* Pointer to ERRINFO structure filled
    53                                    by WinGetErrorInfo */
    54   PSZ pszOffset;                /* Pointer to current error message returned
    55                                    by WinGetErrorInfo */
    56   CHAR szMsg[4096];
    57   PSZ psz;
    58   HAB hab;
    59   va_list va;
    60 
    61   if (hwndErr == NULLHANDLE)
    62     hab = (HAB)0;
    63   else
    64     hab = WinQueryAnchorBlock(hwndErr);
    65 
    66   // Format callers message
    67   va_start(va, pszFmt);
    68   szMsg[sizeof(szMsg) - 1] = 0;
    69   vsprintf(szMsg, pszFmt, va);
    70   va_end(va);
    71 
    72   if (szMsg[sizeof(szMsg) - 1]) {
    73     fprintf(stderr, "Buffer overflow in Win_Error - need %u bytes\n", strlen(szMsg) + 1);
    74     fflush(stderr);
    75   }
    76 
    77   if (strchr(szMsg, ' ') == NULL)
    78     strcat(szMsg, " failed.");          // Assume simple function name
    79 
    80   // Append file name and line number
    81   sprintf(szMsg + strlen(szMsg),
    82           GetPString(IDS_GENERR1TEXT), pszFileName, ulLineNo);
    83 
    84   // Get last PM error for the current thread
    85   pErrInfoBlk = WinGetErrorInfo(hab);
    86   if (!pErrInfoBlk) {
    87     psz = szMsg + strlen(szMsg);
    88     strcpy(psz, " WinGetErrorInfo failed.");
    89   }
    90   else {
    91     if (!hwndOwner)
    92       hwndOwner = HWND_DESKTOP;
    93     /* Find message offset in array of message offsets
    94        Assume 1 message - fixme?
    95      */
    96     pszOffset = ((PSZ) pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
    97     /* Address error message in array of messages and
    98        append error message to source code linenumber
    99      */
    100     psz = szMsg + strlen(szMsg);
    101     sprintf(psz, "#0x%04x \"", ERRORIDERROR(pErrInfoBlk->idError));
    102     psz += strlen(psz);
    103     strcpy(psz, ((PSZ) pErrInfoBlk) + *(PSHORT) pszOffset);
    104     psz += strlen(psz);
    105     // Chop trailing mush
    106     psz--;
    107     while (*psz == '\r' || *psz == '\n' || *psz == ' ')
    108       *psz-- = 0;
    109     if (*psz)
    110       psz++;
    111     strcpy(psz, "\"");
    112     WinFreeErrorInfo(pErrInfoBlk);      // Free resource segment
    113   }
    114 
    115   showMsg(MB_ENTER | MB_ICONEXCLAMATION, hwndOwner, GetPString(IDS_GENERR2TEXT),
    116           szMsg, TRUE);
    117 
    118 }                                       // Win_Error
    119 
    120 //== Win_Error2: report Win...() error using passed message id ===
    121 
    122 VOID Win_Error2(HWND hwndErr, HWND hwndOwner, PCSZ pszFileName,
    123                 ULONG ulLineNo, UINT idMsg)
    124 {
    125   Win_Error(hwndErr, hwndOwner, pszFileName, ulLineNo, GetPString(idMsg));
    126 
    127 }                                       // Win_Error2
     52//=== DbgMsg: output debug message stderr ===
     53
     54VOID DbgMsg(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
     55{
     56  va_list va;
     57
     58  // OK for source file name to be null
     59  fprintf(stderr, "%s %u", pszSrcFile ? pszSrcFile : "n/a", uSrcLineNo);
     60  // If format null want just file and line
     61  if (pszFmt) {
     62    fputc(' ', stderr);
     63    va_start(va, pszFmt);
     64    vfprintf(stderr, pszFmt, va);
     65    va_end(va);
     66  }
     67  fputc('\n', stderr);
     68  fflush(stderr);
     69
     70} // DbgMsg
    12871
    12972//== Dos_Error: report Dos...() error using passed message string ===
    13073
    131 INT Dos_Error(ULONG mb_type, ULONG ulRC, HWND hwndOwner, PCSZ pszFileName,
    132               ULONG ulLineNo, PCSZ pszFmt, ...)
    133 {
    134   CHAR szMsg[4096];
    135   ULONG Class;                  // Error class
    136   ULONG action;                 // Error action
    137   ULONG Locus;                  // Error location
     74INT Dos_Error(ULONG mb_type, ULONG ulRC, HWND hwndOwner,
     75              PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
     76{
     77  CHAR szMsg[4096];
     78  ULONG Class;                          // Error class
     79  ULONG action;                         // Error action
     80  ULONG Locus;                          // Error location
    13881  ULONG ulMsgLen;
    13982  CHAR *pszMsgStart;
     
    15699
    157100  if (strchr(szMsg, ' ') == NULL)
    158     strcat(szMsg, " failed.");          // Assume simple function name
     101    strcat(szMsg, " failed");           // Assume simple function name
    159102
    160103  DosErrClass(ulRC, &Class, &action, &Locus);
     
    162105  sprintf(szMsg + strlen(szMsg),
    163106          GetPString(IDS_DOSERR1TEXT),
    164           pszFileName,
    165           ulLineNo,
     107          pszSrcFile,
     108          uSrcLineNo,
    166109          ulRC,
    167110          GetPString(IDS_ERRCLASS1TEXT + (Class - 1)),
     
    203146                 szMsg, TRUE);
    204147
    205 }                                       // Dos_Error
     148} // Dos_Error
    206149
    207150//== Dos_Error2: report Dos...() error using passed message id ===
    208151
    209 INT Dos_Error2(ULONG mb_type, ULONG ulRC, HWND hwndOwner, PCSZ pszFileName,
    210                ULONG ulLineNo, UINT idMsg)
    211 {
    212   return Dos_Error(mb_type, ulRC, hwndOwner, pszFileName, ulLineNo,
     152INT Dos_Error2(ULONG mb_type, ULONG ulRC, HWND hwndOwner,
     153               PCSZ pszSrcFile, UINT uSrcLineNo, UINT idMsg)
     154{
     155  return Dos_Error(mb_type, ulRC, hwndOwner, pszSrcFile, uSrcLineNo,
    213156                   GetPString(idMsg));
    214 }                                       // Dos_Error2
     157} // Dos_Error2
     158
     159/**
     160 * Format last PM error into passed buffer
     161 */
     162
     163static VOID formatWinError(PSZ pszBuf, UINT cBufBytes,
     164                           HWND hwndErr, HWND hwndOwner,
     165                           PCSZ pszSrcFile, UINT uSrcLineNo,
     166                           PCSZ pszFmt, va_list pva)
     167{
     168  PERRINFO pErrInfoBlk;         /* Pointer to ERRINFO structure filled
     169                                   by WinGetErrorInfo */
     170  PSZ pszOffset;                /* Pointer to current error message returned
     171                                   by WinGetErrorInfo */
     172  PSZ psz;
     173  HAB hab;
     174
     175  if (hwndErr == NULLHANDLE)
     176    hab = (HAB)0;
     177  else
     178    hab = WinQueryAnchorBlock(hwndErr);
     179
     180  // Format callers message
     181  pszBuf[cBufBytes - 1] = 0;
     182  vsprintf(pszBuf, pszFmt, pva);
     183
     184  if (pszBuf[cBufBytes - 1]) {
     185    fprintf(stderr, "Buffer overflow in formatWinError - need %u bytes\n", strlen(pszBuf) + 1);
     186    fflush(stderr);
     187  }
     188
     189  if (strchr(pszBuf, ' ') == NULL)
     190    strcat(pszBuf, " failed");          // Assume simple function name
     191
     192  // Append file name and line number and trailing space
     193  sprintf(pszBuf + strlen(pszBuf),
     194          GetPString(IDS_GENERR1TEXT), pszSrcFile, uSrcLineNo);
     195
     196  // Get last PM error for the current thread
     197  pErrInfoBlk = WinGetErrorInfo(hab);
     198  if (!pErrInfoBlk) {
     199    psz = pszBuf + strlen(pszBuf);
     200    strcpy(psz, "WinGetErrorInfo failed");
     201  }
     202  else {
     203    if (!hwndOwner)
     204      hwndOwner = HWND_DESKTOP;
     205    /* Find message offset in array of message offsets
     206       Assume 1 message - fixme?
     207     */
     208    pszOffset = ((PSZ) pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
     209    /* Address error message in array of messages and
     210       append error message to source code linenumber
     211     */
     212    psz = pszBuf + strlen(pszBuf);
     213    sprintf(psz, "#0x%04x \"", ERRORIDERROR(pErrInfoBlk->idError));
     214    psz += strlen(psz);
     215    strcpy(psz, ((PSZ) pErrInfoBlk) + *(PSHORT) pszOffset);
     216    psz += strlen(psz);
     217    // Chop trailing mush
     218    psz--;
     219    while (*psz == '\r' || *psz == '\n' || *psz == ' ')
     220      *psz-- = 0;
     221    if (*psz)
     222      psz++;
     223    strcpy(psz, "\"");
     224    WinFreeErrorInfo(pErrInfoBlk);      // Free resource segment
     225  }
     226
     227} // formatWinError
    215228
    216229//== Runtime_Error: report runtime library error using passed message string ===
     
    234247
    235248  if (strchr(szMsg, ' ') == NULL)
    236     strcat(szMsg, " failed.");          // Assume simple function name
     249    strcat(szMsg, " failed");           // Assume simple function name
    237250
    238251  sprintf(szMsg + strlen(szMsg),
     
    241254  showMsg(MB_ICONEXCLAMATION, HWND_DESKTOP, DEBUG_STRING, szMsg, TRUE);
    242255
    243 }                                       // Runtime_Error
     256} // Runtime_Error
    244257
    245258//== Runtime_Error2: report runtime library error using passed message id ===
     
    249262  Runtime_Error(pszSrcFile, uSrcLineNo, GetPString(idMsg));
    250263
    251 }                                       // Runtime_Error2
     264} // Runtime_Error2
    252265
    253266// fixme to be rename to Misc_Error
     
    272285  return showMsg(mb_type, hwnd, pszTitle, szMsg, FALSE);
    273286
    274 }                                       // saymsg
     287} // saymsg
    275288
    276289//=== showMsg: display error popup ===
    277290
    278 static APIRET showMsg(ULONG mb_type, HWND hwndOwner, PCSZ pszTitle, PCSZ pszMsg, BOOL wantLog)
     291static APIRET showMsg(ULONG mb_type, HWND hwndOwner,
     292                      PCSZ pszTitle, PCSZ pszMsg, BOOL wantLog)
    279293{
    280294  if (wantLog) {
     
    296310} // showMsg
    297311
    298 //=== DbgMsg: output debug message stderr ===
    299 
    300 VOID DbgMsg(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
    301 {
    302   va_list va;
    303 
    304   // OK for source file name to be null
    305   fprintf(stderr, "%s %u", pszSrcFile ? pszSrcFile : "n/a", uSrcLineNo);
    306   // If format null want just file and line
    307   if (pszFmt) {
    308     fputc(' ', stderr);
    309     va_start(va, pszFmt);
    310     vfprintf(stderr, pszFmt, va);
    311     va_end(va);
    312   }
     312//== Win_Error: report Win...() error using passed message string ===
     313
     314VOID Win_Error(HWND hwndErr, HWND hwndOwner,
     315               PCSZ pszSrcFile, UINT uSrcLineNo,
     316               PCSZ pszFmt, ...)
     317{
     318  CHAR szMsg[4096];
     319  PSZ psz;
     320  HAB hab;
     321  va_list va;
     322
     323  // Format callers message
     324  va_start(va, pszFmt);
     325  formatWinError(szMsg, sizeof(szMsg), hwndErr, hwndOwner, pszSrcFile, uSrcLineNo, pszFmt, va);
     326  va_end(va);
     327
     328  showMsg(MB_ENTER | MB_ICONEXCLAMATION, hwndOwner, GetPString(IDS_GENERR2TEXT),
     329          szMsg, TRUE);
     330
     331} // Win_Error
     332
     333//== Win_Error2: report Win...() error using passed message id ===
     334
     335VOID Win_Error2(HWND hwndErr, HWND hwndOwner,
     336                PCSZ pszSrcFile, UINT uSrcLineNo, UINT idMsg)
     337{
     338  Win_Error(hwndErr, hwndOwner, pszSrcFile, uSrcLineNo, GetPString(idMsg));
     339
     340} // Win_Error2
     341
     342/**
     343  * Output PM error messsage to stderr
     344  * This does to same reporting as Win_Error, but bypasses the
     345  * message box popup.
     346  * Use this version when the popup would hang PM.
     347  */
     348
     349VOID Win_Error_NoMsgBox(HWND hwndErr, HWND hwndOwner,
     350                        PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
     351{
     352  CHAR szMsg[4096];
     353  va_list va;
     354
     355  // Format callers message
     356  va_start(va, pszFmt);
     357  formatWinError(szMsg, sizeof(szMsg), hwndErr, hwndOwner, pszSrcFile, uSrcLineNo, pszFmt, va);
     358  va_end(va);
     359
     360  fputs(szMsg, stderr);
     361  fputc('\n', stderr);
    313362  fputc('\n', stderr);
    314363  fflush(stderr);
    315364
    316 } // DbgMsg
    317 
     365  DosBeep(250, 100);
     366
     367} // Win_Error_NoMsgBox
  • trunk/dll/fm3dll.h

    r633 r636  
    4545  19 Apr 07 SHL Add DbgMsg.  Sync with AcceptOneDrop GetOneDrop mods.
    4646  21 Apr 07 GKY Find FM2Utils by path or utils directory eliminate fAddUtils global
     47  23 Apr 07 SHL Add Win_Error_NoMsgBox
    4748
    4849***********************************************************************/
     
    147148#define EXTRA_ARCRECORD_BYTES   (sizeof(ARCITEM) - sizeof(MINIRECORDCORE))
    148149#define ALLATTRS                (FILE_NORMAL | FILE_DIRECTORY | FILE_ARCHIVED |\
    149                                 FILE_HIDDEN | FILE_READONLY | FILE_SYSTEM)
     150                                FILE_HIDDEN | FILE_READONLY | FILE_SYSTEM)
    150151#define LISTTEMPROOT            "$FM2LI$T."
    151152
     
    633634
    634635/* error.c */
     636VOID DbgMsg(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...);
    635637INT Dos_Error(ULONG mb_type, ULONG ulRC, HWND hwndOwner,
    636               PCSZ pszFileName, ULONG ulLineNo, PCSZ pszFmt, ...);
    637 INT Dos_Error2(ULONG mb_type, ULONG ulRC, HWND hwndOwner, PCSZ pszFileName,
    638                ULONG ulLineNo, UINT idMsg);
    639 VOID Win_Error(HWND hwndErr, HWND hwndOwner,
    640                PCSZ pszFileName, ULONG ulLineNo, PCSZ pszFmt, ...);
    641 VOID Win_Error2(HWND hwndErr, HWND hwndOwner, PCSZ pszFileName,
    642                 ULONG ulLineNo, UINT idMsg);
     638              PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...);
     639INT Dos_Error2(ULONG mb_type, ULONG ulRC, HWND hwndOwner, PCSZ pszSrcFile,
     640               UINT uSrcLineNo, UINT idMsg);
    643641VOID Runtime_Error(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...);
    644642VOID Runtime_Error2(PCSZ pszSrcFile, UINT uSrcLineNo, UINT idMsg);
    645643APIRET saymsg(ULONG mb_type, HWND hwnd, PCSZ pszTitle, PCSZ pszFmt, ...);
    646 VOID DbgMsg(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...);
     644VOID Win_Error(HWND hwndErr, HWND hwndOwner,
     645               PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...);
     646VOID Win_Error2(HWND hwndErr, HWND hwndOwner, PCSZ pszSrcFile,
     647                UINT uSrcLineNo, UINT idMsg);
     648VOID Win_Error_NoMsgBox(HWND hwndErr, HWND hwndOwner,
     649                        PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...);
    647650
    648651/* valid.c */
  • trunk/dll/fm3dll.str

    r616 r636  
    331331No files found.
    332332FM/2: View HELP files
    333 \nModule: %s Line number: %d
     333\nModule: %s Line number: %u
    334334                                  Error Message Information
    335 \nModule: %s Line number: %d\nOS/2 error: %d\nClass: %s\nAction: %s\nLocation: %s
     335\nModule: %s Line number: %u\nOS/2 error: %d\nClass: %s\nAction: %s\nLocation: %s
    336336                                  OS/2 Error Message Information
    337337Out of resource
Note: See TracChangeset for help on using the changeset viewer.