Changeset 182 for trunk/dll/error.c


Ignore:
Timestamp:
May 28, 2005, 7:54:26 PM (20 years ago)
Author:
root
Message:

Rework to use common showMsg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/error.c

    r169 r182  
    1414  24 May 05 SHL Rename saymsg to more accurate Misc_Error
    1515  24 May 05 SHL Rework Win_Error args and clean up logic
     16  27 May 05 SHL Rework to use common showMsg
    1617
    1718***********************************************************************/
     
    3132
    3233#pragma data_seg(DATA1)
    33 #pragma alloc_text(FMINPUT,Win_Error,Dos_Error,saymsg)
    34 
    35 // fixme to pass hwndError rather hab
     34#pragma alloc_text(FMINPUT,Win_Error,Dos_Error,saymsg,showMsg)
     35
     36static APIRET showMsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszMsg);
    3637
    3738//== Win_Error: report Win...() error ===
     
    3940VOID Win_Error(HWND hwndErr, HWND hwndOwner, PSZ pszFileName, ULONG ulLineNo, CHAR *pszFmt,...)
    4041{
    41   PERRINFO pErrInfoBlk;         /* Pointer to ERRINFO structure that is filled
     42  PERRINFO pErrInfoBlk;         /* Pointer to ERRINFO structure filled
    4243                                   by WinGetErrorInfo */
    43   PSZ pszOffset;                /* Pointer to the current error message returned
     44  PSZ pszOffset;                /* Pointer to current error message returned
    4445                                   by WinGetErrorInfo */
    45   CHAR szErrBuffer[4096];       /* The error message that is displayed to
    46                                    the user via WinMessageBox */
     46  CHAR szMsg[4096];
    4747  PSZ psz;
    4848  HAB hab;
     
    5050
    5151  if (hwndErr == NULLHANDLE)
    52     hab = (HAB) 0;
     52    hab = (HAB)0;
    5353  else
    5454    hab = WinQueryAnchorBlock(hwndErr);
     
    5656  // Format callers message
    5757  va_start(va, pszFmt);
    58   vsprintf(szErrBuffer, pszFmt, va);
     58  vsprintf(szMsg, pszFmt, va);
    5959  va_end(va);
    6060
    6161  // Append file name and line number
    62   sprintf(szErrBuffer + strlen(szErrBuffer),
     62  sprintf(szMsg + strlen(szMsg),
    6363          GetPString(IDS_GENERR1TEXT),
    6464          pszFileName, ulLineNo, "  ");
    6565
    66   /* Get last PM error for the current thread */
     66  // Get last PM error for the current thread
    6767  pErrInfoBlk = WinGetErrorInfo(hab);
     68  // fixme to report
    6869  if (pErrInfoBlk != NULL)
    6970  {
     
    7778       append error message to source code linenumber
    7879     */
    79     psz = szErrBuffer + strlen(szErrBuffer);
     80    psz = szMsg + strlen(szMsg);
    8081    sprintf(psz, "#0x%04x  \"", ERRORIDERROR(pErrInfoBlk -> idError));
    8182    psz += strlen(psz);
    82     strcpy(psz, ((PSZ) pErrInfoBlk) + *(PSHORT) pszOffset);
     83    strcpy(psz, ((PSZ)pErrInfoBlk) + *(PSHORT)pszOffset);
    8384    psz += strlen(psz);
    8485    strcpy(psz, "\"");
    85     WinFreeErrorInfo(pErrInfoBlk);      /* Free resource segment */
    86 
    87     WinMessageBox(HWND_DESKTOP,         /* Parent */
    88                   hwndOwner,            /* Owner */
    89                   szErrBuffer,          /* Formatted message */
    90                   GetPString(IDS_GENERR2TEXT),  /* Titlebar message */
    91                   0,                    /* Message identifier */
    92                   MB_ENTER | MB_ICONEXCLAMATION | MB_MOVEABLE);
     86    WinFreeErrorInfo(pErrInfoBlk);      // Free resource segment
     87
     88    showMsg(MB_ENTER | MB_ICONEXCLAMATION,
     89            hwndOwner,
     90            GetPString(IDS_GENERR2TEXT),        // Titlebar message
     91            szMsg);                     // Formatted message
    9392  }
    9493
     
    10099              ULONG ulLineNo, CHAR *pszFmt,...)
    101100{
    102   CHAR szMsgBuffer[4096];       /* The whole error message that
    103                                    is displayed to
    104                                    the user via WinMessageBox */
    105   ULONG Class = 17;             /* Error class - fixme to not init? */
    106   ULONG action = 9;             /* Error action */
    107   ULONG Locus = 7;              /* Error location */
     101  CHAR szMsg[4096];
     102  ULONG Class = 17;                     // Error class - fixme to not init?
     103  ULONG action = 9;                     // Error action
     104  ULONG Locus = 7;                      // Error location
    108105  ULONG ulMsgLen;
    109106  CHAR *pszMsgStart;
     
    114111    return MBID_ENTER;                  // Should not have been called
    115112
    116   if (!hwndOwner)
    117     hwndOwner = HWND_DESKTOP;
    118 
    119113  // Format caller's message
    120114  va_start(va, pszFmt);
    121   vsprintf(szMsgBuffer, pszFmt, va);
     115  vsprintf(szMsg, pszFmt, va);
    122116  va_end(va);
    123117
    124118  DosErrClass(ulRC, &Class, &action, &Locus);
    125119
    126   sprintf(szMsgBuffer + strlen(szMsgBuffer),
     120  sprintf(szMsg + strlen(szMsg),
    127121          GetPString(IDS_DOSERR1TEXT),
    128122          pszFileName,
     
    132126          GetPString(IDS_ERRACTION1TEXT + (action - 1)),
    133127          GetPString(IDS_ERRLOCUS1TEXT + (Locus - 1)));
    134   pszMsgStart = szMsgBuffer + strlen(szMsgBuffer) + 1;
     128  pszMsgStart = szMsg + strlen(szMsg) + 1;
    135129  // Get message leaving space for NL separator
    136   if (!DosGetMessage(NULL, 0L, (PCHAR) pszMsgStart + 1, 1024, ulRC, "OSO001.MSG", &ulMsgLen) ||
    137       !DosGetMessage(NULL, 0L, (PCHAR) pszMsgStart + 1, 1024, ulRC, "OSO001H.MSG", &ulMsgLen))
     130  if (!DosGetMessage(NULL, 0L, (PCHAR)pszMsgStart + 1, 1024, ulRC, "OSO001.MSG", &ulMsgLen) ||
     131      !DosGetMessage(NULL, 0L, (PCHAR)pszMsgStart + 1, 1024, ulRC, "OSO001H.MSG", &ulMsgLen))
    138132  {
    139133    // Got message
    140134    pszMsgStart[ulMsgLen + 1] = 0;      // Terminate
    141     *(pszMsgStart - 1) = '\n';  // Stuff NL before message text
     135    *(pszMsgStart - 1) = '\n';          // Stuff NL before message text
    142136    *pszMsgStart = '\"';                // Prefix message text with quote
     137
    143138    psz = pszMsgStart + ulMsgLen;       // Point at last char
    144139    // Chop trailing NL CR TAB
     
    165160  }
    166161
    167   return WinMessageBox(HWND_DESKTOP,    /* Parent */
    168                        hwndOwner,       /* Owner */
    169                        szMsgBuffer,     /* Formatted message */
    170                        GetPString(IDS_DOSERR2TEXT),     /* Title bar text */
    171                        0,               /* Message identifier */
    172                        mb_type | MB_ICONEXCLAMATION | MB_MOVEABLE);
     162  return showMsg(mb_type | MB_ICONEXCLAMATION,
     163                 hwndOwner,
     164                 GetPString(IDS_DOSERR2TEXT),   // Title
     165                 szMsg);
    173166
    174167} // Dos_Error
    175168
    176 // fixme to be Misc_Error instead of saymsg
     169// fixme to be rename to Misc_Error
    177170
    178171//=== saymsg: report misc error ===
     
    180173APIRET saymsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszFmt,...)
    181174{
    182   CHAR szBuffer[4096];
     175  CHAR szMsg[4096];
    183176  va_list va;
    184177
    185178  va_start(va, pszFmt);
    186   vsprintf(szBuffer, pszFmt, va);
     179  vsprintf(szMsg, pszFmt, va);
    187180  va_end(va);
     181
     182  return showMsg(mb_type,
     183                 hwnd,
     184                 pszTitle,
     185                 szMsg);
     186} // saymsg
     187
     188//=== showMsg: report misc error ===
     189
     190static APIRET showMsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszMsg)
     191{
     192  fputs(pszMsg, stderr);
     193  fputc('\n', stderr);
     194  fflush(stderr);
    188195
    189196  if (!hwnd)
    190197    hwnd = HWND_DESKTOP;
    191198
    192   return WinMessageBox(HWND_DESKTOP, hwnd, szBuffer, pszTitle,
    193                        0, mb_type | MB_MOVEABLE);
    194 } // saymsg
     199  return WinMessageBox(HWND_DESKTOP,    // Parent
     200                       hwnd,            // Owner
     201                       pszMsg,
     202                       pszTitle,
     203                       0,               // help id
     204                       mb_type | MB_MOVEABLE);
     205} // showMsg
Note: See TracChangeset for help on using the changeset viewer.