//File: send.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri //The send command is an enhanced function of our simulator. //Its functionality is to send a messaage to another user //the command would be given by issuing a 'send username message' command public class send extends VMachine { /** Creates new send */ public send() { } public void run() { try{ //if there is only one argument then assume that the argument is the username //to send the message to if(args.length == 1) { //set the username String username = args[0]; //see if the user is logged in User user = sysapi.findUser(username); //if the user is logged in if(user != null) { //prompt sender for message String input = sysapi.Read(IN); //accept message until a blank line is typed //send each line as it is typed for(int i = 0; input.compareTo("") != 0; i++) { user.sendmsg(owner + " - " + input + "\n"); //prompt user for more input input = sysapi.Read(IN); } } else { sysapi.Write(OUT,"User not logged in.\n"); } } //if there are more than one arguments then assume the first is the //username and the others are messages else if(args.length > 1) { //set username String username = args[0]; //find the user User user = sysapi.findUser(username); //if the user is logged in if(user != null) { String buffer = owner + " -"; //for each argument send them as the message for(int i = 1; i < args.length; i++) { buffer = buffer + " " + args[i]; } buffer = buffer + "\n"; user.sendmsg(buffer); } else { sysapi.Write(OUT,"User not logged in.\n"); } } else { sysapi.Write(OUT,"No user specified.\n"); } } catch(Exception ex) { System.out.println("Send threw Exception: " + ex); } sysapi.Exit(vmh,owner); } }