1 19 20 package soot.options; 21 import java.util.*; 22 23 import soot.*; 24 25 28 29 abstract class OptionsBase { 30 private String pad( int initial, String opts, int tab, String desc ) { 31 StringBuffer b = new StringBuffer (); 32 for( int i = 0; i < initial; i++ ) b.append( " " ); 33 b.append(opts); 34 int i; 35 if( tab <= opts.length() ) { 36 b.append( "\n" ); 37 i = 0; 38 } else i = opts.length()+initial; 39 for( ; i <= tab; i++ ) { 40 b.append(" "); 41 } 42 for( StringTokenizer t = new StringTokenizer( desc ); 43 t.hasMoreTokens(); ) { 44 String s = t.nextToken(); 45 if( i + s.length() > 78 ) { 46 b.append( "\n" ); 47 i = 0; 48 for( ; i <= tab; i++ ) { 49 b.append(" "); 50 } 51 } 52 b.append( s ); 53 b.append( " " ); 54 i += s.length() + 1; 55 } 56 b.append( "\n" ); 57 return b.toString(); 58 } 59 60 protected String padOpt( String opts, String desc ) { 61 return pad( 1, opts, 30, desc ); 62 } 63 64 protected String padVal( String vals, String desc ) { 65 return pad( 4, vals, 32, desc ); 66 } 67 68 protected String getPhaseUsage() { 69 StringBuffer b = new StringBuffer (); 70 b.append( "\nPhases and phase options:\n" ); 71 for( Iterator pIt = PackManager.v().allPacks().iterator(); pIt.hasNext(); ) { 72 final Pack p = (Pack) pIt.next(); 73 b.append( padOpt( p.getPhaseName(), p.getDeclaredOptions() ) ); 74 for( Iterator phIt = p.iterator(); phIt.hasNext(); ) { 75 final HasPhaseOptions ph = (HasPhaseOptions) phIt.next(); 76 b.append( padVal( ph.getPhaseName(), ph.getDeclaredOptions() ) ); 77 } 78 } 79 return b.toString(); 80 } 81 82 private LinkedList options = new LinkedList(); 83 protected void pushOptions( String s ) { 84 options.addFirst( s ); 85 } 86 87 protected boolean hasMoreOptions() { return !options.isEmpty(); } 88 protected String nextOption() { return (String ) options.removeFirst(); } 89 90 protected LinkedList classes = new LinkedList(); 91 public LinkedList classes() { return classes; } 92 93 public boolean setPhaseOption( String phase, String option ) { 94 return PhaseOptions.v().processPhaseOptions( phase, option ); 95 } 96 97 } 98 99 | Popular Tags |