Listing 6 (signon.c) Function to Automatically Sign On to a Mainframe Application

int sign_on(void) {

    int err;

    if ((err = keys_to_host("MYAPP")) != 0)
        return (err);
    if ((err = input_to_host("@E")) != 0)
        return(err);
    if ((err = host_wait()) ! = 0)
        return(err);

    /* search PS repeatedly until finding a string
     * that indicates success or failure
     */

    while (1) {
        err = find_msg("ENTER PASSWORD");
        if (err == -1)
            break; /* application available */
        else if (err > 0)
            return(err);

        err = find_msg("NOT AVAILABLE");
        if (err == -1 || err > 0)
            return(err);
    }

    /* enter 2 tabs and password */
    if ((err= keys_to_host("@T@TROSEBUD")) != 0)
        return(err);
    if ((err = input_to_host("@E")) != 0)
        return(err);

    return(0);
}

/* End of File */