Fixed compiler errors in zwinconstgen.go output.

This commit is contained in:
Pietro Gagliardi 2014-07-11 10:02:55 -04:00
parent a54e3e67de
commit 114c4050eb
1 changed files with 18 additions and 23 deletions

View File

@ -86,24 +86,23 @@ func writeLine(f *os.File, line string) {
} }
const cgopreamble = ` const cgopreamble = `
#define UNICODE // #define UNICODE
#define _UNICODE // #define _UNICODE
#define STRICT // #define STRICT
#define STRICT_TYPED_ITEMIDS // #define STRICT_TYPED_ITEMIDS
/* get Windows version right; right now Windows XP */ // /* get Windows version right; right now Windows XP */
#define WINVER 0x0501 // #define WINVER 0x0501
#define _WIN32_WINNT 0x0501 // #define _WIN32_WINNT 0x0501
#define _WIN32_WINDOWS 0x0501 /* according to Microsoft's winperf.h */ // #define _WIN32_WINDOWS 0x0501 /* according to Microsoft's winperf.h */
#define _WIN32_IE 0x0600 /* according to Microsoft's sdkddkver.h */ // #define _WIN32_IE 0x0600 /* according to Microsoft's sdkddkver.h */
#define NTDDI_VERSION 0x05010000 /* according to Microsoft's sdkddkver.h */ // #define NTDDI_VERSION 0x05010000 /* according to Microsoft's sdkddkver.h */
#include <windows.h> // #include <windows.h>
#include <commctrl.h> // #include <commctrl.h>
#include <stdint.h> // #include <stdint.h>` // no closing newline; added by writeLine()
`
func writeConstCast(f *os.File, c string) { func writeConstCast(f *os.File, c string) {
cc := c[2:] // strip leading c_ cc := c[2:] // strip leading c_
fmt.Fprintf(f, "uintptr_t %s = (uintptr_t) (%s);\n", c, cc) fmt.Fprintf(f, "// uintptr_t %s = (uintptr_t) (%s);\n", c, cc)
} }
func writeConstPrint(f *os.File, c string) { func writeConstPrint(f *os.File, c string) {
@ -169,28 +168,24 @@ func main() {
writeLine(f, "package main") writeLine(f, "package main")
writeLine(f, "import \"fmt\"") writeLine(f, "import \"fmt\"")
writeLine(f, "import \"bytes\"") writeLine(f, "import \"bytes\"")
writeLine(f, "import \"runtime\"") writeLine(f, "import \"reflect\"")
writeLine(f, "import \"go/format\"") writeLine(f, "import \"go/format\"")
writeLine(f, "/*")
writeLine(f, cgopreamble) writeLine(f, cgopreamble)
for _, c := range consts { for _, c := range consts {
writeConstCast(f, c) writeConstCast(f, c)
} }
writeLine(f, "*/")
writeLine(f, "import \"C\"") writeLine(f, "import \"C\"")
writeLine(f, "func main() {") writeLine(f, "func main() {")
writeLine(f, "\tbuf := new(bytes.Buffer)") writeLine(f, "\tbuf := new(bytes.Buffer)")
writeLine(f, "\tfmt.Fprintln(buf, \"package main\")") writeLine(f, "\tfmt.Fprintln(buf, \"package ui\")")
writeLine(f, "\tfmt.Fprintln(buf, \"func main() {\")")
for _, c := range consts { for _, c := range consts {
writeConstPrint(f, c) writeConstPrint(f, c)
} }
writeLine(f, "\tfmt.Fprintln(buf, \"var t reflect.Type\")") writeLine(f, "\tvar t reflect.Type")
writeLine(f, "\tfmt.Fprintln(buf, \"var s string\")") writeLine(f, "\tvar s string")
for _, s := range structs { for _, s := range structs {
writeStructPrint(f, s) writeStructPrint(f, s)
} }
writeLine(f, "\tfmt.Fprintln(buf, \"}\")")
writeLine(f, "\tres, err := format.Source(buf.Bytes())") writeLine(f, "\tres, err := format.Source(buf.Bytes())")
writeLine(f, "\tif err != nil { panic(err) }") writeLine(f, "\tif err != nil { panic(err) }")
writeLine(f, "\tfmt.Printf(\"%s\", res)") writeLine(f, "\tfmt.Printf(\"%s\", res)")