/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <stdlib.h>

#include <ssdef.h>
#include <iodef.h>
#include <starlet.h>
#include <descrip.h>

static void ooops(long int stat)
{
    printf("status = %d\n", stat);
    exit(0);
}

static void done(short int chan)
{
    sys$cancel(chan);
}

int main()
{
    $DESCRIPTOR(ttdesc, "TT:");
    char buf;
    short int chan, iosb[4];
    long int stat, tmo;
    long long int tmo2;
    stat = sys$assign(&ttdesc, &chan, 0, 0, 0);
    if(stat != SS$_NORMAL) ooops(stat);
    tmo = 10;
    printf("Press a key within %d seconds\n", tmo);
    tmo2 = -tmo * 10000000;
    sys$setimr(0, &tmo2, done, chan, 0);
    stat = sys$qiow(0, chan, IO$_READVBLK, iosb, 0, 0, &buf, 1, 0, 0, 0, 0);
    if(stat == SS$_NORMAL && iosb[0] == SS$_ABORT)
    {
        printf("Arne you are too slow\n");
    }
    else
    {
        if(stat != SS$_NORMAL) ooops(stat);
        if(iosb[0] != SS$_NORMAL) ooops(iosb[0]);
        sys$cantim(&0, 0);
        printf("You entered code: %d\n", buf);
    }
    stat = sys$dassgn(chan);
    if(stat != SS$_NORMAL) ooops(stat);
    return 0;
}

