2 // Body of Error interface.
3 // This file implements the code of the Error.cp file.
10 public static void WriteLn()
15 public static void Write(char ch
)
20 private static char[] strRep(int val
)
22 if (val
< 0) { // ==> must be minInt
23 char[] min
= {' ',' ','2','1','4','7','4','8','3','6','4','8'};
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;
35 public static void WriteInt(int val
, int fwd
)
37 char[] str
= (val
>= 0 ?
strRep(val
) : strRep(-val
));
40 for (blank
= 0; str
[blank
] == ' '; blank
++)
43 str
[blank
-1] = '-'; blank
--;
46 // 01...............901
47 // _________xxxxxxxxxxx
48 // <-blank->< 12-blank>
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
));
55 System
.err
.print(new String(str
, 12-fwd
, fwd
));
57 for (int i
= fwd
-12; i
> 0; i
--)
58 System
.err
.print(" ");
59 System
.err
.print(new String(str
));
63 public static void WriteHex(int val
, int wid
)
65 char[] str
= new char[9];
67 int j
; // index of last blank
73 str
[i
] = (char) (dig
+ ((int) 'A' - 10));
75 str
[i
] = (char) (dig
+ (int) '0');
82 if (wid
== 0) // special case, exactly one blank
83 jls
= new String(str
, j
, 9-j
);
85 jls
= new String(str
, j
+1, 8-j
);
87 jls
= new String(str
, 9-wid
, wid
);
89 for (i
= wid
-9; i
> 0; i
--)
90 System
.err
.print(" ");
91 jls
= new String(str
);
93 System
.err
.print(jls
);
97 public static void WriteString(char[] str
)
100 for (int i
= 0; i
< len
&& str
[i
] != '\0'; i
++)
101 System
.err
.print(str
[i
]);
105 } // end of public class Console