/*****************************************************
 * Listing 6 signon.c
 *
 * sign_on() -- 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)
               return(err); /* not available */
          else if (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);
}

