1 57 58 import java.io.*; 59 import java.util.*; 60 61 import org.apache.oro.text.*; 62 import org.apache.oro.text.regex.*; 63 64 71 public final class groups { 72 73 public static final void main(String [] args) { 74 int user; 75 MatchActionProcessor processor = new MatchActionProcessor(); 76 final Hashtable groups = new Hashtable(); 77 Vector users = new Vector(); 78 Enumeration usersElements; 79 MatchAction action = new MatchAction() { 80 public void processMatch(MatchActionInfo info) { 81 ((Vector)groups.get(info.match.toString())).addElement( 83 info.fields.elementAt(0)); 84 } 85 }; 86 87 if(args.length == 0) { 88 args = new String [1]; 90 args[0] = System.getProperty("user.name"); 91 } 92 93 try { 94 processor.setFieldSeparator(":"); 95 for(user = 0; user < args.length; user++) { 96 if(!groups.containsKey(args[user])) { 98 groups.put(args[user], new Vector()); 99 processor.addAction(args[user], action); 101 users.addElement(args[user]); 103 } 104 } 105 } catch(MalformedPatternException e) { 106 e.printStackTrace(); 107 System.exit(1); 108 } 109 110 try { 111 processor.processMatches(new FileInputStream("/etc/group"), 112 System.out); 113 } catch(IOException e) { 114 e.printStackTrace(); 115 System.exit(1); 116 } 117 118 usersElements = users.elements(); 119 120 while(usersElements.hasMoreElements()) { 121 String username; 122 Enumeration values; 123 124 username = (String )usersElements.nextElement(); 125 values = ((Vector)groups.get(username)).elements(); 126 127 System.out.print(username + " :"); 128 while(values.hasMoreElements()) { 129 System.out.print(" " + values.nextElement()); 130 } 131 System.out.println(); 132 } 133 134 System.out.flush(); 135 } 136 137 } 138
| Popular Tags
|