Merge marina project in subdirectory marina/
[fleet.git] / marina / testCode / com / sun / vlsi / chips / marina / test / Indenter.java
1 package com.sun.vlsi.chips.marina.test;
2
3 public class Indenter {
4     private static char NL = '\n';
5     private int indent = 0;
6     private boolean beginLine = true;
7         
8     private void spaces(int n) {
9         StringBuffer sb = new StringBuffer();
10         for (int i=0; i<n; i++)  sb.append(" ");
11         System.out.print(sb.toString());
12     }
13     private void indentIfNeeded() {
14         if (beginLine) spaces(indent);
15         beginLine = false;
16     }
17     private void printLines(String msg) {
18         while (true) {
19             int nl = msg.indexOf(NL);
20             if (nl==-1) {
21                 indentIfNeeded();
22                 System.out.print(msg);
23                 return;
24             } else {
25                 // found a new line.
26                 String line = msg.substring(0, nl);
27                 indentIfNeeded();
28                 System.out.println(line);
29                 beginLine = true;
30                 if (nl==msg.length()-1) {
31                     // nothing left after the newline
32                     return;
33                 }
34                 msg = msg.substring(nl+1);
35             }
36         }
37     }
38     public void prln(String msg) {printLines(msg+NL);}
39     public void pr(String msg) {printLines(msg);}
40     public void adjustIndent(int n) {
41         indent += n;
42     }
43
44
45 }