github.com/nakagami/firebirdsql@v0.9.10/_attic/errmsgs.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 // 1. Get copy of Firebird 5 sources or at least src/include from Firebird 5 sources 9 // 2. Run CGO_CFLAGS=-I/path/to/firebird/src/include go run ./_attic ./errmsgs.go 10 11 //#include "msgs.h" 12 import "C" 13 import ( 14 "strings" 15 ) 16 17 var outFile *os.File 18 19 func writeOut(val string) { 20 _, err := outFile.WriteString(val) 21 if err != nil { 22 fmt.Printf("Unable to write file: %v\n", err) 23 os.Exit(1) 24 } 25 } 26 27 func main() { 28 var err error 29 30 if len(os.Args) < 2 { 31 fmt.Println("Output file required") 32 os.Exit(1) 33 } 34 if outFile, err = os.OpenFile(os.Args[1], os.O_CREATE|os.O_RDWR, 0644); err != nil { 35 fmt.Printf("Unable to open file: %v\n", err) 36 } 37 defer outFile.Close() 38 39 writeOut(`/**************************************************************************** 40 The contents of this file are subject to the Interbase Public 41 License Version 1.0 (the "License"); you may not use this file 42 except in compliance with the License. You may obtain a copy 43 of the License at http://www.Inprise.com/IPL.html 44 45 Software distributed under the License is distributed on an 46 "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express 47 or implied. See the License for the specific language governing 48 rights and limitations under the License. 49 50 *****************************************************************************/ 51 52 package firebirdsql 53 54 var errmsgs = map[int]string{ 55 `) 56 57 C.process_messages() 58 writeOut("}\n") 59 } 60 61 //export addMessage 62 func addMessage(code C.int, message *C.char) { 63 var msg string = C.GoString(message) 64 if !strings.HasSuffix(msg, `\n"`) { 65 msg = msg[:len(msg)-1] 66 msg += `\n"` 67 } 68 writeOut(fmt.Sprintf("\t%d: %s,\n", int(code), msg)) 69 }