home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / MBLIB10 / C_EXAMP / WRITEMSG.C < prev    next >
Text File  |  1993-03-07  |  2KB  |  53 lines

  1. /* WARNING: THIS EXAMPLE IS QUICK & DIRTY!!! Its only purpose is to         */
  2. /* demonstrate how certain MB_lib functions are used and how they work.     */
  3. /* While the code is a functional program, no attempt has been made to      */
  4. /* clean up the code or to streamline it, and I've economized a bit on      */
  5. /* error checking since I've made this in a hurry. However, if you're       */
  6. /* able to use MB_lib, odds are that you also know how to write neat code.  */
  7.  
  8. /* Write a demo message to All in board 1. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "mb_lib.h"
  14.  
  15. MSGHDR_RECORD myhdr;    /* Message header */
  16. M_TEXT mytext;          /* Text handle    */
  17. char buf [20];          /* String buffer  */
  18.  
  19. void main () {
  20.   if (msg_open ("C:\\MSGBASE")) {
  21.     puts ("Error opening message base");
  22.     exit (1);
  23.   }
  24.   mytext = txt_new ("This is the first paragraph of this message. \n");
  25.   txt_add (mytext, "Text will be added until a Hard Carriage Return");
  26.   txt_add (mytext, "is encountered. I've added one to this line.\r");
  27.   txt_add (mytext, "This is the second paragraph. As you can see the \\n, ");
  28.   txt_add (mytext, "which was added above, has been ignored according ");
  29.   txt_add (mytext, "to FSC-0001.\r");
  30.   sprintf (buf, "%cPID: MB_LIB 1.0\r", KLUDGE);     /* Add product ID */
  31.   txt_add (mytext, buf);
  32.   msg_hdr_clear (& myhdr);        /* Now build the message header */
  33.   myhdr.dest_net = 1331;          /* To: 27:1331/703.0 */
  34.   myhdr.dest_node = 703;
  35.   myhdr.dest_zone = 27;
  36.   myhdr.orig_net = 285;           /* From: 2:285/504.0 */
  37.   myhdr.orig_node = 504;
  38.   myhdr.orig_zone = 2;
  39.   myhdr.msg_attr = MA_PRIVATE | MA_LOCAL;
  40.   myhdr.board = 1;                /* Tell him where to put it :-) */
  41.   strcpy (myhdr.who_from, "Frank Van.wensveen");
  42.   strcpy (myhdr.who_to, "All");
  43.   strcpy (myhdr.subject, "Testing, testing...");
  44.   if (msg_lock ("C:\\RA\\SEMAFORE")) {
  45.     puts ("Error locking message base");
  46.     exit (1);
  47.   }
  48.   if (msg_write_new (& myhdr, mytext))        /* See how easy it is? */
  49.     printf ("Error %d writing message base:\n%s", errortype, errorstring);
  50.   msg_unlock ();
  51.   msg_close ();
  52. }
  53.