TIP: Click on subject to list as thread! ANSI
echo: net_dev
to: All
from: andrew clarke
date: 1997-03-05 01:37:48
subject: MsgAPI demonstration program

* Crossposted in area C_ECHO, MAXDEV, AUST_C_HERE, NET_DEV, PUBLIC_DOMAIN

I needed a simple demonstration program to test the `SMAPI' library.  SMAPI
is essentially a copy of the MSGAPI0 code with numerous public domain
modifications to allow it compatible with some additional compilers (eg.
MetaWare High C) and operating systems (Linux, FreeBSD).  It is available
for FREQ from 3:635/728 as SMAPI12.ZIP, or FTP from the /pub/msged/
directory on ftp.zws.com.  It is also available from Bob Juge's BBS
(1:106/2000, ftp.juge.com).

The following code took me about 20 minutes to write.  Enjoy.

/*
 *  Simple MsgAPI demonstration program.  Writes a single message to a
 *  Squish message base using the MsgAPI library.
 *
 *  Released to the public domain in March 1997 by Andrew Clarke.
 */

#include 
#include 
#include 
#include 

static struct _minf minf;
extern word _stdc msgapierr;

static MSG *mh;
static MSGH *msgh;
static XMSG msg;

static char *msgarea = "test";

int main(void)
{
    int rc;
    char text[100], ctxt[100];

    minf.def_zone = 0;
    minf.req_version = 0;

    rc = (int) MsgOpenApi(&minf);
    if (rc != 0)
    {
        fprintf(stderr, "Can't initialise the MsgAPI!\n");
        return EXIT_FAILURE;
    }
    
    mh = MsgOpenArea(msgarea, MSGAREA_CRIFNEC, MSGTYPE_SQUISH);
    if (mh == NULL)
    {
        fprintf(stderr, "Can't open message area '%s'!\n", msgarea);
        return EXIT_FAILURE;
    }

    rc = (int) MsgLock(mh);
    if (rc != 0)
    {
        fprintf(stderr, "Can't lock message area!\n");
        return EXIT_FAILURE;
    }

    msgh = MsgOpenMsg(mh, MOPEN_CREATE, 0);
    if (msgh == NULL)
    {
        fprintf(stderr, "Can't create new message!\n");
        return EXIT_FAILURE;
    }

    /* initialise XMSG structure */

    msg.attr |= MSGLOCAL;
    strcpy(msg.from, "andrew clarke");
    strcpy(msg.to, "All");
    strcpy(msg.subj, "test");
    msg.orig.zone = 3;
    msg.orig.net = 635;
    msg.orig.node = 728;
    msg.orig.point = 4;
    msg.dest = msg.orig;
    msg.date_written.date.da = 5;
    msg.date_written.date.mo = 3;
    msg.date_written.date.yr = 1997 - 1980;
    msg.date_written.time.hh = 1;
    msg.date_written.time.mm = 21;
    msg.date_written.time.ss = 1;
    msg.date_arrived = msg.date_written;

    strcpy(text, "Hello world.");
    strcpy(ctxt, "\01MSGID: 3:635/728.4{at}fidonet 12345678");
    rc = (int) MsgWriteMsg(msgh, 0, &msg, text, strlen(text),
      strlen(text), strlen(ctxt), ctxt);
    if (rc != 0)
    {
        fprintf(stderr, "Can't write new message!\n");
        return EXIT_FAILURE;
    }
    
    MsgCloseMsg(msgh);

    rc = (int) MsgUnlock(mh);
    if (rc != 0)
    {
        fprintf(stderr, "Can't unlock message area!\n");
        return EXIT_FAILURE;
    }

    MsgCloseArea(mh);
    MsgCloseApi();

    return EXIT_SUCCESS;
}

: Andrew Clarke, VidMgr author                Zone 3 moderator of the C_Echo
: Melbourne, Victoria, Australia                               randy{at}zws.com

--- Msged/2 4.20 beta 2
* Origin: Blizzard of Ozz, Melbourne, Australia (3:635/728.4{at}fidonet)
SEEN-BY: 50/99 54/99 270/101 620/243 635/544 728 670/218 711/413 430 934
SEEN-BY: 712/311 407 505 506 517 623 624 841 713/317 800/1
@PATH: 635/728 50/99 712/624 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.