/* Collection of code snippets by Arne Vajhøj */
/* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) */
#include <stdio.h>
#include <string.h>

#include <descrip.h>

#define C2SMBX "C2SMBX"
#define S2CMBX "S2CMBX"

int main(int argc, char *argv[])
{
    FILE *fc2s, *fs2c;
    $DESCRIPTOR(dc2smbx, C2SMBX);   
    $DESCRIPTOR(ds2cmbx, S2CMBX);   
    char *outmsg, inmsg[1000];
    /* open mailboxes */
    fc2s = fopen(C2SMBX ":", "w"); 
    if(fc2s == NULL) printf("fopen %s failed\n", C2SMBX);
    fs2c = fopen(S2CMBX ":", "r"); 
    if(fs2c == NULL) printf("fopen %s failed\n", S2CMBX);
    /* write  */
    outmsg = "Hi from C!\r\n";
    fputs(outmsg, fc2s);
    /* read */
    while(fgets(inmsg, sizeof(inmsg), fs2c))
    {
        if(inmsg[0] == '*') break;
        inmsg[strlen(inmsg) - 1] = 0; /* strip newline */
        printf("%s\n", inmsg);
    }
    /* close */
    fclose(fc2s);
    fclose(fs2c);
    return 0;
}
