home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / GETMSG.C < prev    next >
Text File  |  1995-12-11  |  7KB  |  135 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   getmsg.c                                                                */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   Some basic message functions common to SD386 and ESP.                   */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   11/11/93 Created.                                                       */
  12. /*                                                                           */
  13. /**Includes*******************************************************************/
  14.  
  15. #include "all.h"
  16.  
  17. /*****************************************************************************/
  18. /* GetHelpMsg                                                                */
  19. /*                                                                           */
  20. /* Description:                                                              */
  21. /*                                                                           */
  22. /*  Get a message from the message file.                                     */
  23. /*                                                                           */
  24. /* Parameters:                                                               */
  25. /*                                                                           */
  26. /*    id         message number we want to get.                              */
  27. /*    pIvTable   ->to table of pointers to substitution strings.             */
  28. /*    IvCount    number of substitution strings.                             */
  29. /*                                                                           */
  30. /* Return:                                                                   */
  31. /*                                                                           */
  32. /*    pMsgBuf    -> to the buffer that will hold the message.                */
  33. /*                                                                           */
  34. /* Assumptions:                                                              */
  35. /*                                                                           */
  36. /*    Caller frees pMsgBuf.                                                  */
  37. /*                                                                           */
  38. /*****************************************************************************/
  39. UCHAR *GetHelpMsg(ULONG id,UCHAR **pIvTable, ULONG IvCount)
  40. {
  41.  APIRET rc;
  42.  ULONG  nbytes;
  43.  char  *pMsgBuf;
  44.  
  45.  pMsgBuf = Talloc(MAXHELPMSG);
  46.  
  47.  rc = DosGetMessage(pIvTable,
  48.                     IvCount,
  49.                     pMsgBuf,
  50.                     MAXHELPMSG,
  51.                     id,
  52.                     MSGFILE,
  53.                     (ULONG*)&nbytes);
  54.  if ( rc != 0 )
  55.  {
  56.   if( rc == ERROR_FILE_NOT_FOUND )
  57.    nbytes = sprintf(pMsgBuf,"\n\nCan't find file \"%s\"\r\n", MSGFILE);
  58.   else
  59.    nbytes = sprintf(pMsgBuf, "\n\nDosGetMessage(rc=%d)\r\n",rc);
  60.  }
  61.  pMsgBuf[nbytes] = 0;
  62.  
  63.  return( pMsgBuf );
  64. }
  65.  
  66. /*****************************************************************************/
  67. /* SayMsg                                                                    */
  68. /*                                                                           */
  69. /* Description:                                                              */
  70. /*                                                                           */
  71. /*   Display a fatal message and then exit the debugger.                     */
  72. /*   These messages are displayed before the debugger executes vioinit().    */
  73. /*                                                                           */
  74. /* Parameters:                                                               */
  75. /*                                                                           */
  76. /*   MsgId         id of the message to display.                             */
  77. /*                                                                           */
  78. /* Return:                                                                   */
  79. /*                                                                           */
  80. /* Assumptions:                                                              */
  81. /*                                                                           */
  82. /*****************************************************************************/
  83. void SayMsg(ULONG MsgId)
  84. {
  85.  uchar *pMsgBuf;
  86.  
  87.  pMsgBuf = GetHelpMsg(MsgId, NULL,0);
  88.  printf("%s",pMsgBuf);
  89.  Tfree( pMsgBuf );
  90.  exit(0);
  91. }
  92.  
  93. /*****************************************************************************/
  94. /* ErrorPrintf()                                                             */
  95. /*                                                                           */
  96. /* Description:                                                              */
  97. /*                                                                           */
  98. /*   Display a fatal message and then exit the debugger.                     */
  99. /*                                                                           */
  100. /*   This function allows for a substitution string and a substitution       */
  101. /*   number to be tossed into the %1 and %2 fields of the message            */
  102. /*   defined by the message id.                                              */
  103. /*                                                                           */
  104. /* Parameters:                                                               */
  105. /*                                                                           */
  106. /*   MsgId          id of the message to display.                            */
  107. /*   Fatal          TRUE=>kill the debugger. FALSE=>informational.           */
  108. /*   SubStringCount String that will go into %1,%2,... substitutions.        */
  109. /*   ...            list of ptrs to strings                                  */
  110. /*                                                                           */
  111. /* Return:                                                                   */
  112. /*                                                                           */
  113. /* Assumptions:                                                              */
  114. /*                                                                           */
  115. /*   These messages are always fatal.                                        */
  116. /*                                                                           */
  117. /*****************************************************************************/
  118. #include <stdarg.h>
  119. void _System ErrorPrintf(ULONG MsgId, int SubStringCount,...)
  120. {
  121.  UCHAR   *SubStringTable[MAX_SUBSTRINGS];
  122.  int      i;
  123.  va_list  pSubString;
  124.  UCHAR   *pMsgBuf;
  125.  
  126.  va_start(pSubString,SubStringCount);
  127.  for( i = 0; i < SubStringCount; i++ )
  128.   SubStringTable[i] = va_arg(pSubString,char *);
  129.  
  130.  pMsgBuf = GetHelpMsg(MsgId, SubStringTable,SubStringCount);
  131.  printf(pMsgBuf);fflush(0);
  132.  Tfree( pMsgBuf );
  133.  MyExit();
  134. }
  135.