Changeset 327 for trunk/dll/error.c


Ignore:
Timestamp:
Jul 25, 2006, 8:24:42 PM (19 years ago)
Author:
root
Message:

Add Runtime_Error
Optimize calling sequences

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/error.c

    r293 r327  
    1616  27 May 05 SHL Rework to use common showMsg
    1717  14 Aug 05 SHL showMsg: suppress write to stdout if not error message
     18  13 Jul 06 SHL Add Runtime_Error
     19  22 Jul 06 SHL Optimize calling sequences
    1820
    1921***********************************************************************/
     
    3537#pragma alloc_text(FMINPUT,Win_Error,Dos_Error,saymsg,showMsg)
    3638
    37 static APIRET showMsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszMsg);
     39static APIRET showMsg(ULONG mb_type, HWND hwnd, PCSZ pszTitle, PCSZ pszMsg);
    3840
    3941//== Win_Error: report Win...() error ===
    4042
    41 VOID Win_Error(HWND hwndErr, HWND hwndOwner, PSZ pszFileName, ULONG ulLineNo, CHAR *pszFmt,...)
     43VOID Win_Error(HWND hwndErr, HWND hwndOwner, PCSZ pszFileName, ULONG ulLineNo, PCSZ pszFmt,...)
    4244{
    4345  PERRINFO pErrInfoBlk;         /* Pointer to ERRINFO structure filled
     
    6062  va_end(va);
    6163
     64  if (strchr(szMsg, ' ') == NULL)
     65    strcat(szMsg, " failed");                   // Assume simple function name
     66
    6267  // Append file name and line number
    6368  sprintf(szMsg + strlen(szMsg),
     
    6772  // Get last PM error for the current thread
    6873  pErrInfoBlk = WinGetErrorInfo(hab);
    69   // fixme to report
    70   if (pErrInfoBlk != NULL)
    71   {
     74  if (!pErrInfoBlk) {
     75    psz = szMsg + strlen(szMsg);
     76    strcpy(psz, " WinGetError failed");
     77  }
     78  else {
    7279    if (!hwndOwner)
    7380      hwndOwner = HWND_DESKTOP;
     
    8693    strcpy(psz, "\"");
    8794    WinFreeErrorInfo(pErrInfoBlk);      // Free resource segment
    88 
    89     showMsg(MB_ENTER | MB_ICONEXCLAMATION,
    90             hwndOwner,
    91             GetPString(IDS_GENERR2TEXT),        // Titlebar message
    92             szMsg);                     // Formatted message
    93   }
     95  }
     96
     97  showMsg(MB_ENTER | MB_ICONEXCLAMATION,
     98          hwndOwner,
     99          GetPString(IDS_GENERR2TEXT),  // Titlebar message
     100          szMsg);                       // Formatted message
    94101
    95102} // Win_Error
     
    97104//== Dos_Error: report Dos...() error ===
    98105
    99 INT Dos_Error(ULONG mb_type, ULONG ulRC, HWND hwndOwner, PSZ pszFileName,
    100               ULONG ulLineNo, CHAR *pszFmt,...)
    101 {
    102   CHAR szMsg[4096];
    103   ULONG Class = 17;                     // Error class - fixme to not init?
    104   ULONG action = 9;                     // Error action
    105   ULONG Locus = 7;                      // Error location
     106INT Dos_Error(ULONG mb_type, ULONG ulRC, HWND hwndOwner, PCSZ pszFileName,
     107              ULONG ulLineNo, PCSZ pszFmt,...)
     108{
     109  CHAR szMsg[4096];
     110  ULONG Class;                  // Error class
     111  ULONG action;                 // Error action
     112  ULONG Locus;                  // Error location
    106113  ULONG ulMsgLen;
    107114  CHAR *pszMsgStart;
     
    116123  vsprintf(szMsg, pszFmt, va);
    117124  va_end(va);
     125
     126  if (strchr(szMsg, ' ') == NULL)
     127    strcat(szMsg, " failed");                   // Assume simple function name
    118128
    119129  DosErrClass(ulRC, &Class, &action, &Locus);
     
    168178} // Dos_Error
    169179
     180//== Runtime_Error: report runtime library error ===
     181
     182VOID Runtime_Error(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt,...)
     183{
     184  CHAR szMsg[4096];
     185  va_list va;
     186  PSZ psz;
     187
     188  // Format caller's message
     189  va_start(va, pszFmt);
     190  vsprintf(szMsg, pszFmt, va);
     191  va_end(va);
     192
     193  if (strchr(szMsg, ' ') == NULL)
     194    strcat(szMsg, " failed");                   // Assume simple function name
     195
     196  sprintf(szMsg + strlen(szMsg),
     197          // GetPString(IDS_DOSERR1TEXT), fixme
     198          "\nModule: %s\nLinenumber: %u",
     199          pszSrcFile,
     200          uSrcLineNo);
     201
     202  showMsg(MB_ICONEXCLAMATION,HWND_DESKTOP,DEBUG_STRING,szMsg);
     203
     204} // Runtime_Error
     205
    170206// fixme to be rename to Misc_Error
    171207
    172208//=== saymsg: report misc error ===
    173209
    174 APIRET saymsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszFmt,...)
     210APIRET saymsg(ULONG mb_type, HWND hwnd, PCSZ pszTitle, PCSZ pszFmt,...)
    175211{
    176212  CHAR szMsg[4096];
     
    189225//=== showMsg: report misc error ===
    190226
    191 static APIRET showMsg(ULONG mb_type, HWND hwnd, CHAR *pszTitle, CHAR *pszMsg)
     227static APIRET showMsg(ULONG mb_type, HWND hwnd, PCSZ pszTitle, PCSZ pszMsg)
    192228{
    193229  if ((mb_type & (MB_YESNO | MB_YESNOCANCEL)) == 0)
     
    201237    hwnd = HWND_DESKTOP;
    202238
     239  DosBeep(250,100);
     240
    203241  return WinMessageBox(HWND_DESKTOP,    // Parent
    204242                       hwnd,            // Owner
    205                        pszMsg,
    206                        pszTitle,
     243                       (PSZ)pszMsg,
     244                       (PSZ)pszTitle,
    207245                       0,               // help id
    208246                       mb_type | MB_MOVEABLE);
Note: See TracChangeset for help on using the changeset viewer.