diff options
| author | Jeff Carr <[email protected]> | 2025-02-01 11:38:22 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-02-01 11:38:22 -0600 |
| commit | 22e0cbe022faa067c3dddc50f99029ccfa24c2df (patch) | |
| tree | e901bbdfb41ade81a99d12f12113ea6559a13517 /doWITCOM.go | |
| parent | 899cbb3483ee67fc9b868531b9c16bea5d364aee (diff) | |
Diffstat (limited to 'doWITCOM.go')
| -rw-r--r-- | doWITCOM.go | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/doWITCOM.go b/doWITCOM.go index 83b2662..085a332 100644 --- a/doWITCOM.go +++ b/doWITCOM.go @@ -1,3 +1,7 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + + package main import ( @@ -25,6 +29,7 @@ func doWITCOM() { } // add a common header for WIT files +// add a common header for WIT files func addCommonHeader(filename string) error { // read in the .proto file @@ -34,13 +39,7 @@ func addCommonHeader(filename string) error { return err } - pf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) - defer pf.Close() - if err != nil { - log.Info("file open error. permissions?", filename, err) - return err - } - + var newfile string var start bool = true var found bool var done bool @@ -52,10 +51,10 @@ func addCommonHeader(filename string) error { start = false if strings.Contains(line, "WIT.COM") { found = true - continue } else { - fmt.Fprintln(pf, line) + newfile += fmt.Sprintln(line) } + continue } // dump every other comment @@ -64,16 +63,28 @@ func addCommonHeader(filename string) error { } else { found = false } + + // print the header once if !done { - fmt.Fprintln(pf, "// Copyright 2017-2025 WIT.COM Inc. All rights reserved.") - fmt.Fprintln(pf, "// Use of this source code is governed by the GPL 3.0") - fmt.Fprintln(pf, "") - fmt.Fprintln(pf, line) + newfile += fmt.Sprintln("// Copyright 2017-2025 WIT.COM Inc. All rights reserved.") + newfile += fmt.Sprintln("// Use of this source code is governed by the GPL 3.0") + newfile += fmt.Sprintln("") done = true } - fmt.Fprintln(pf, line) + newfile += fmt.Sprintln(line) } + pf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { + log.Info("file open error. permissions?", filename, err) + return err + } + + // trim trailing empty lines from the new file + newfile = strings.TrimSpace(newfile) + fmt.Fprintln(pf, newfile) + pf.Close() + return nil } |
