summaryrefslogtreecommitdiff
path: root/usr/gri/pretty/platform.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2008-09-18 16:58:37 -0700
committerRobert Griesemer <gri@golang.org>2008-09-18 16:58:37 -0700
commit9fb7da748396894cb2cb15188f82e124933b8b7a (patch)
tree3f83983bfab51a4a981b8537379eee656016617d /usr/gri/pretty/platform.go
parent2180a3dc9c5c80c097f56350539fbde490845493 (diff)
downloadgolang-9fb7da748396894cb2cb15188f82e124933b8b7a.tar.gz
First cut at a Go pretty printer:
- code scavenged from Go-in-Go front-end (will merge back) - using "symbol-table" free parsing to build AST - no printing yet R=r OCL=15504 CL=15504
Diffstat (limited to 'usr/gri/pretty/platform.go')
-rw-r--r--usr/gri/pretty/platform.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/usr/gri/pretty/platform.go b/usr/gri/pretty/platform.go
new file mode 100644
index 000000000..c76d59150
--- /dev/null
+++ b/usr/gri/pretty/platform.go
@@ -0,0 +1,70 @@
+// 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 Platform
+
+import Utils "utils"
+
+
+// ----------------------------------------------------------------------------
+// Environment
+
+export var
+ GOARCH,
+ GOOS,
+ GOROOT,
+ USER string;
+
+
+func GetEnv(key string) string {
+ n := len(key);
+ for i := 0; i < sys.envc(); i++ {
+ v := sys.envv(i);
+ if v[0 : n] == key {
+ return v[n + 1 : len(v)]; // +1: trim "="
+ }
+ }
+ return "";
+}
+
+
+func init() {
+ GOARCH = GetEnv("GOARCH");
+ GOOS = GetEnv("GOOS");
+ GOROOT = GetEnv("GOROOT");
+ USER = GetEnv("USER");
+}
+
+
+// ----------------------------------------------------------------------------
+// I/O
+
+export const (
+ MAGIC_obj_file = "@gri-go.7@v0"; // make it clear thar it cannot be a source file
+ src_file_ext = ".go";
+ obj_file_ext = ".7";
+)
+
+
+export func ReadObjectFile(filename string) (data string, ok bool) {
+ data, ok = sys.readfile(filename + obj_file_ext);
+ magic := MAGIC_obj_file; // TODO remove once len(constant) works
+ if ok && len(data) >= len(magic) && data[0 : len(magic)] == magic {
+ return data, ok;
+ }
+ return "", false;
+}
+
+
+export func ReadSourceFile(name string) (data string, ok bool) {
+ name = Utils.TrimExt(name, src_file_ext) + src_file_ext;
+ data, ok = sys.readfile(name);
+ return data, ok;
+}
+
+
+export func WriteObjectFile(name string, data string) bool {
+ name = Utils.TrimExt(Utils.BaseName(name), src_file_ext) + obj_file_ext;
+ return sys.writefile(name, data);
+}