DEADSOFTWARE

Build with help make
[gpcp-linux.git] / libs / java / Error.java
1 //
2 // Body of Error interface.
3 // This file implements the code of the Error.cp file.
4 // kjg November 1999.
6 package CP.Error;
8 public class Error
9 {
10 public static void WriteLn()
11 {
12 System.err.println();
13 }
15 public static void Write(char ch)
16 {
17 System.err.print(ch);
18 }
20 private static char[] strRep(int val)
21 {
22 if (val < 0) { // ==> must be minInt
23 char[] min = {' ',' ','2','1','4','7','4','8','3','6','4','8'};
24 return min;
25 }
27 char[] str = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
28 str[11] = (char) (val % 10 + (int) '0'); val = val / 10;
29 for (int i = 10; val != 0; i--) {
30 str[i] = (char) (val % 10 + (int) '0'); val = val / 10;
31 }
32 return str;
33 }
35 public static void WriteInt(int val, int fwd)
36 {
37 char[] str = (val >= 0 ? strRep(val) : strRep(-val));
39 int blank;
40 for (blank = 0; str[blank] == ' '; blank++)
41 ;
42 if (val < 0) {
43 str[blank-1] = '-'; blank--;
44 }
45 // format ...
46 // 01...............901
47 // _________xxxxxxxxxxx
48 // <-blank->< 12-blank>
49 // <-----fwd------>
50 if (fwd == 0) // magic case, put out exactly one blank
51 System.err.print(new String(str, blank-1, 13-blank));
52 else if (fwd < (12-blank))
53 System.err.print(new String(str, blank, 12-blank));
54 else if (fwd <= 12)
55 System.err.print(new String(str, 12-fwd, fwd));
56 else { // fwd > 12
57 for (int i = fwd-12; i > 0; i--)
58 System.err.print(" ");
59 System.err.print(new String(str));
60 }
61 }
63 public static void WriteHex(int val, int wid)
64 {
65 char[] str = new char[9];
66 String jls;
67 int j; // index of last blank
68 int i = 8;
69 do {
70 int dig = val & 0xF;
71 val = val >>> 4;
72 if (dig >= 10)
73 str[i] = (char) (dig + ((int) 'A' - 10));
74 else
75 str[i] = (char) (dig + (int) '0');
76 i--;
77 } while (val != 0);
78 j = i;
79 while (i >= 0) {
80 str[i] = ' '; i--;
81 }
82 if (wid == 0) // special case, exactly one blank
83 jls = new String(str, j, 9-j);
84 else if (wid < (8-j))
85 jls = new String(str, j+1, 8-j);
86 else if (wid <= 9)
87 jls = new String(str, 9-wid, wid);
88 else {
89 for (i = wid-9; i > 0; i--)
90 System.err.print(" ");
91 jls = new String(str);
92 }
93 System.err.print(jls);
94 }
97 public static void WriteString(char[] str)
98 {
99 int len = str.length;
100 for (int i = 0; i < len && str[i] != '\0'; i++)
101 System.err.print(str[i]);
105 } // end of public class Console