home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OMessage.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  6KB  |  207 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OMessage.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30. // $Header: W:/Projects/OCL/Source/rcs/OMessage.cpp 1.50 1996/08/11 23:49:23 B.STEIN Release $
  31.  
  32. #define __OCL_SOURCE__
  33.  
  34. #define OINCL_OSTRING
  35. #define OINCL_BASE
  36.  
  37. #include <ocl.hpp>
  38. #include <OMessage.hpp>
  39.  
  40.  
  41.  
  42. OMessage::OMessage()
  43.    : message(OCL_MAXMESSAGE),
  44.      msglen(0) 
  45.    {}
  46.  
  47.  
  48.  
  49. OMessage::OMessage(ULONG msgId,
  50.                    PSZ   msgFileName,
  51.                    PSZ   textInsert1,
  52.                    PSZ   textInsert2,
  53.                    PSZ   textInsert3,
  54.                    PSZ   textInsert4,
  55.                    PSZ   textInsert5,
  56.                    PSZ   textInsert6,
  57.                    PSZ   textInsert7,
  58.                    PSZ   textInsert8,
  59.                    PSZ   textInsert9)
  60.    : message(OCL_MAXMESSAGE),
  61.      msglen(0) 
  62. {
  63.  retrieve(msgId, msgFileName,
  64.           textInsert1, textInsert2, textInsert3, textInsert4, textInsert5,
  65.           textInsert6, textInsert7, textInsert8, textInsert9);
  66. };
  67.  
  68.  
  69. OMessage& OMessage::retrieve(ULONG msgId,
  70.                     PSZ   msgFileName,
  71.                     PSZ   textInsert1,
  72.                     PSZ   textInsert2,
  73.                     PSZ   textInsert3,
  74.                     PSZ   textInsert4,
  75.                     PSZ   textInsert5,
  76.                     PSZ   textInsert6,
  77.                     PSZ   textInsert7,
  78.                     PSZ   textInsert8,
  79.                     PSZ   textInsert9)
  80. {
  81.  APIRET rc = 0;
  82.  ULONG  count = 0;
  83.  PSZ    insertTable[9] = { 0 };
  84.  
  85.  if (!msgFileName)
  86.    throw OVioException("No message file specified.", OException::unrecoverable);
  87.  
  88.  if (textInsert1)
  89.   {
  90.    count++;
  91.    insertTable[0] = (PSZ)textInsert1;
  92.    if (textInsert2)
  93.     {
  94.      count++;
  95.      insertTable[1] = (PSZ)textInsert2;
  96.      if (textInsert3)
  97.       {
  98.        count++;
  99.        insertTable[2] = (PSZ)textInsert3;
  100.        if (textInsert4)
  101.         {
  102.          count++;
  103.          insertTable[3] = (PSZ)textInsert4;
  104.          if (textInsert5)
  105.           {
  106.            count++;
  107.            insertTable[4] = (PSZ)textInsert5;
  108.            if (textInsert6)
  109.             {
  110.              count++;
  111.              insertTable[5] = (PSZ)textInsert6;
  112.              if (textInsert7)
  113.               {
  114.                count++;
  115.                insertTable[6] = (PSZ)textInsert7;
  116.                if (textInsert8)
  117.                 {
  118.                  count++;
  119.                  insertTable[7] = (PSZ)textInsert8;
  120.                  if (textInsert9)
  121.                   {
  122.                    count++;
  123.                    insertTable[8] = (PSZ)textInsert9;
  124.                   }
  125.                 }
  126.               }
  127.             }
  128.           }
  129.         }
  130.       }
  131.     }
  132.   }
  133.  
  134.  
  135.  rc = DosGetMessage(insertTable,
  136.                     count,
  137.                     message.getText(),
  138.                     OCL_MAXMESSAGE,
  139.                     msgId,
  140.                     (PSZ)msgFileName,
  141.                     &msglen);
  142.  
  143.  if (rc != 0)
  144.    throw OVioException("Cannot load message.\n", rc, OException::unrecoverable);
  145.  
  146.  message.getText()[msglen] = '\0';
  147.  message.replace("\r\n", "\n");
  148.  return(*this);
  149. }
  150.  
  151.  
  152. OMessage::~OMessage()
  153.  {}
  154.  
  155.  
  156.  
  157. PSZ OMessage::isOfType() const
  158. {
  159.  return("OMessage");
  160. }
  161.  
  162.  
  163.  
  164. PSZ OMessage::getText()
  165. {
  166.  return(message.getText());
  167. }
  168.  
  169.  
  170.  
  171. ULONG OMessage::getLen()
  172. {
  173.  return(msglen);
  174. }
  175.  
  176.  
  177.  
  178. PSZ OMessage::getMessage(ULONG msgId,
  179.                          PSZ   msgFileName,
  180.                          PSZ   textInsert1,
  181.                          PSZ   textInsert2,
  182.                          PSZ   textInsert3,
  183.                          PSZ   textInsert4,
  184.                          PSZ   textInsert5,
  185.                          PSZ   textInsert6,
  186.                          PSZ   textInsert7,
  187.                          PSZ   textInsert8,
  188.                          PSZ   textInsert9)
  189. {
  190.  retrieve(msgId, msgFileName,
  191.           textInsert1, textInsert2, textInsert3, textInsert4, textInsert5,
  192.           textInsert6, textInsert7, textInsert8, textInsert9);
  193.  return(message.getText());
  194. };
  195.  
  196.  
  197.  
  198. ostream& operator <<   (ostream& out, pOMessage s)
  199. {
  200.  if (s)
  201.    out << s->getText();
  202.  return(out);
  203. }
  204.  
  205.  
  206. // end of source
  207.