Add a pretty-printer

Adds a -pp option to the compiler which will cause it to simply
pretty-print the given file.
This commit is contained in:
Marijn Haverbeke
2011-03-04 07:22:43 +01:00
committed by Graydon Hoare
parent 8047957b99
commit 0624f9db4a
9 changed files with 1013 additions and 25 deletions

View File

@@ -91,24 +91,28 @@ tag fileflag {
truncate;
}
fn writefd(int fd, vec[u8] v) {
auto len = _vec.len[u8](v);
auto count = 0u;
auto vbuf;
while (count < len) {
vbuf = _vec.buf_off[u8](v, count);
auto nout = os.libc.write(fd, vbuf, len);
if (nout < 0) {
log "error dumping buffer";
log sys.rustrt.last_os_error();
fail;
}
count += nout as uint;
}
}
fn new_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
state obj fd_buf_writer(int fd) {
fn write(vec[u8] v) {
auto len = _vec.len[u8](v);
auto count = 0u;
auto vbuf;
while (count < len) {
vbuf = _vec.buf_off[u8](v, count);
auto nout = os.libc.write(fd, vbuf, len);
if (nout < 0) {
log "error dumping buffer";
log sys.rustrt.last_os_error();
fail;
}
count += nout as uint;
}
writefd(fd, v);
}
drop {