Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
127c65b4
Commit
127c65b4
authored
Nov 19, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- untab app (snapshot - not quite complete)
R=r OCL=19558 CL=19558
parent
79d94d50
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
9 deletions
+67
-9
Makefile
usr/gri/pretty/Makefile
+6
-0
tabwriter.go
usr/gri/pretty/tabwriter.go
+8
-9
untab.go
usr/gri/pretty/untab.go
+53
-0
No files found.
usr/gri/pretty/Makefile
View file @
127c65b4
...
...
@@ -5,6 +5,11 @@
G
=
6g
L
=
6l
all
:
untab pretty
untab
:
untab.6
$(L)
-o
untab untab.6
pretty
:
pretty.6
$(L)
-o
pretty pretty.6
...
...
@@ -34,6 +39,7 @@ platform.6: utils.6
printer.6
:
scanner.6 ast.6 tabwriter.6
untab.6
:
tabwriter.6
%.6
:
%.go
$(G)
$(F)
$<
usr/gri/pretty/tabwriter.go
View file @
127c65b4
...
...
@@ -85,7 +85,7 @@ func (b *ByteArray) Append(s *[]byte) {
// of adjacent cells have the same width (by adding padding). For more
// details see: http://nickgravgaard.com/elastictabstops/index.html .
type
TabWriter
struct
{
export
type
TabWriter
struct
{
// configuration
writer
IO
.
Write
;
tabwidth
int
;
...
...
@@ -232,26 +232,25 @@ func (b *TabWriter) Tab() {
func
(
b
*
TabWriter
)
Newline
()
{
b
.
Tab
();
// add last cell to current line
if
b
.
LastLine
()
.
Len
()
==
1
{
// The current line has only one cell which does not have an impact
// on the formatting of the following lines (the last cell per line
// is ignored by Format), thus we can print the TabWriter contents.
if
b
.
widths
.
Len
()
!=
0
{
panic
();
panic
(
"internal error"
);
}
//b.Dump();
b
.
Format
(
0
,
0
,
b
.
lines
.
Len
());
if
b
.
widths
.
Len
()
!=
0
{
panic
();
panic
(
"internal error"
);
}
// reset
the
TabWriter
// reset TabWriter
b
.
width
=
0
;
b
.
buf
.
Clear
();
b
.
lines
.
Reset
();
}
b
.
AddLine
();
}
...
...
@@ -278,7 +277,7 @@ func (b *TabWriter) Write(buf *[]byte) (i int, err *OS.Error) {
}
export
func
MakeTabWriter
(
writer
IO
.
Write
,
tabwidth
int
)
IO
.
Write
{
export
func
MakeTabWriter
(
writer
IO
.
Write
,
tabwidth
int
)
*
TabWriter
{
b
:=
new
(
TabWriter
);
b
.
Init
(
writer
,
tabwidth
);
return
b
;
...
...
usr/gri/pretty/untab.go
0 → 100644
View file @
127c65b4
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
import
(
OS
"os"
;
IO
"io"
;
Flag
"flag"
;
Fmt
"fmt"
;
TabWriter
"tabwriter"
;
)
var
(
tabwidth
=
Flag
.
Int
(
"tabwidth"
,
4
,
nil
,
"tab width"
);
)
func
Error
(
fmt
string
,
params
...
)
{
Fmt
.
printf
(
fmt
,
params
);
sys
.
exit
(
1
);
}
func
Untab
(
name
string
,
src
*
OS
.
FD
,
dst
*
TabWriter
.
TabWriter
)
{
n
,
err
:=
IO
.
Copyn
(
src
,
dst
,
2e9
/* inf */
);
// TODO use Copy
if
err
!=
nil
{
Error
(
"error while processing %s (%v)"
,
name
,
err
);
}
//dst.Flush();
}
func
main
()
{
Flag
.
Parse
();
dst
:=
TabWriter
.
MakeTabWriter
(
OS
.
Stdout
,
int
(
tabwidth
.
IVal
()));
if
Flag
.
NArg
()
>
0
{
for
i
:=
0
;
i
<
Flag
.
NArg
();
i
++
{
name
:=
Flag
.
Arg
(
i
);
src
,
err
:=
OS
.
Open
(
name
,
OS
.
O_RDONLY
,
0
);
if
err
!=
nil
{
Error
(
"could not open %s (%v)
\n
"
,
name
,
err
);
}
Untab
(
name
,
src
,
dst
);
src
.
Close
();
// ignore errors
}
}
else
{
// no files => use stdin
Untab
(
"/dev/stdin"
,
OS
.
Stdin
,
dst
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment