home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / QPROC.ZIP / QPMSG.C < prev    next >
C/C++ Source or Header  |  1990-10-18  |  4KB  |  145 lines

  1. /*****************************************************************/ 
  2. /**             Microsoft LAN Manager            **/ 
  3. /**           Copyright(c) Microsoft Corp., 1985-1990        **/ 
  4. /*****************************************************************/ 
  5. /****************************** Module Header ******************************\
  6.  
  7. Module Name: QPMSG.C
  8.  
  9. This module displays message box for errors detected by the default PM
  10. Queue Processor.
  11.  
  12. History:
  13.  07-Sep-88 [stevewo]  Created.
  14.  14-Feb-90 [thomaspa] DBCS fixes.
  15.  
  16.   WARNING:  This module placed in a code segment other than the default
  17.             segment.  All function calls from this module to others in
  18.             the default segment must be far calls.  For this reason,
  19.             do not use the standard str*f() functions directly.  Instead
  20.             use the wrapper functions as found in strwrap.c.
  21. \***************************************************************************/
  22.  
  23. #define INCL_WINDIALOGS
  24. #include "pmprint.h"
  25. #include <netlib.h>
  26. #include <strapi.h>
  27. #include <makenear.h>
  28.  
  29. /* See ..\spooler\prterrl.c */
  30.  
  31. /* SplQpMessage -- displays and logs error
  32.  *
  33.  * in:  pszPort - -> port error occured on
  34.  *      uErrId - resource id of error text
  35.  *      uErrCode - see PMERR_ (might be NULL, then no error is logged)
  36.  * out: ACT_QUERY: value returned by SplMessageBox
  37.  *      ACT_ABORT: MBID_CANCEL
  38.  *      ACT_CONTINUE: MBID_ENTER
  39.  */
  40. USHORT FARENTRY SplQpMessage(PSZ pszPort, USHORT uErrId, USHORT uErrCode)
  41. {
  42.     USHORT uSeverity;
  43.     USHORT fErrInfo;
  44.     USHORT fErrData;
  45.     USHORT fStyle;
  46.     PSZ    pszMsgText;
  47.     PSZ    pszFmtStr;
  48.     PSZ    ptmp;
  49.     NPSZ   pMsg;
  50.     USHORT cb;
  51.     USHORT rc;
  52.     USHORT cIStrings = 0;
  53.  
  54.  
  55.     SplOutSem();
  56.  
  57.     fErrInfo  = SPLINFO_QPERROR;
  58.     if(uErrId == SPL_ID_QP_INVALID_PARAMETER ||
  59.        uErrId == SPL_ID_QP_MEM_ERROR) {
  60.         fErrInfo |= SPLINFO_WARNING;
  61.         fErrData = SPLDATA_OTHER;
  62.         fStyle = MB_OK;
  63.         uSeverity = SEVERITY_WARNING;
  64.     } else {
  65.         fErrData = SPLDATA_UNEXPECTERROR;
  66.         fStyle = MB_CANCEL;
  67.         uSeverity = SEVERITY_ERROR;
  68.     }
  69.     if (uErrCode)
  70.         WinSetErrorInfo(MAKEERRORID(uSeverity, uErrCode ), SEI_NOPROMPT);
  71.  
  72.     pszMsgText = pszSplStrings[ uErrId ];
  73.     pMsg = NULL;
  74.     if (uErrId == SPL_ID_QP_INTERNAL_ERROR ) {
  75.     /*
  76.      * Calculate the number of insert strings.
  77.      */
  78.     ptmp = pszMsgText;
  79.     while( ptmp = MAKENEAR(FarStrstr(ptmp, "%0")) )
  80.         cIStrings++;
  81.     
  82.     /*
  83.      * the insert strings are the ascii string from a USHORT, and
  84.      * so are a max of 5 characters long.
  85.      */
  86.         cb = SafeStrlen( pszMsgText )+(5*cIStrings) + 1;
  87.         pszFmtStr = pszMsgText;
  88.       EnterSplSem();
  89.         pMsg = AllocSplMem( cb );
  90.       LeaveSplSem();
  91.         pszMsgText = (PSZ)pMsg;
  92.  
  93.     /*
  94.      * The following far to near conversions are ok because the
  95.      * pointer returned points into the dest string which is
  96.      * near.
  97.      */
  98.     /*
  99.      * Replace all occurrences of "%0" in pszFmtStr with the ascii
  100.      * string value of uErrCode and place the result in pMsg.
  101.      * pszMsgText points to the beginning of the buffer and pMsg
  102.      * will be incremented.  pMsg will then be restored to point
  103.      * to the beginning of the buffer after the copy is complete.
  104.      */
  105.     while (ptmp = MAKENEAR(FarStrstr(pszFmtStr, "%0")) )
  106.     {
  107.         *ptmp++ = '\0';
  108.         pMsg = MAKENEAR(EndStrcpy( pMsg, pszFmtStr));
  109.         pszFmtStr = ++ptmp;
  110.         pMsg = (NPSZ)MAKENEAR(MyItoa(uErrCode, (PSZ)pMsg));
  111.     }
  112.     EndStrcpy(pMsg, pszFmtStr);
  113.     pMsg = MAKENEAR(pszMsgText);
  114.  
  115. /* OLD CODE:  The following was replaced with the above lines because
  116. *        It is NOT DBCS compatible.
  117. *        while (c = *pszFmtStr++)
  118. *            if (c == '%' && *pszFmtStr == '0') {
  119. *                pszFmtStr++;
  120. *                pMsg = (NPSZ)MyItoa(uErrCode, (PSZ)pMsg);
  121. *                }
  122. *            else
  123. *                *pMsg++ = c;
  124. *        *pMsg = 0;
  125. *        pMsg = (NPSZ)pszMsgText;
  126. */
  127.         }
  128.  
  129.     rc = SplMessageBox( pszPort,
  130.                         fErrInfo,
  131.                         fErrData,
  132.                         pszMsgText,
  133.                         QPROC_CAPTION,
  134.                         0,
  135.                         fStyle
  136.                         );
  137.  
  138.     if (pMsg) {
  139.       EnterSplSem();
  140.         FreeSplMem( pMsg, cb );
  141.       LeaveSplSem();
  142.     }
  143.     return( rc );
  144. }
  145.