// Return input with pattern replaced by sub. func reSub(pattern []byte, sub []byte, input []byte) []byte { var err *C.GError = nil re := C.g_regex_new( (*C.gchar)(data(append(pattern, 0))), C.G_REGEX_CASELESS| C.G_REGEX_RAW| C.G_REGEX_NO_AUTO_CAPTURE| C.G_REGEX_OPTIMIZE, 0, &err) if err != nil { panic("g_regex_new") } defer C.g_regex_unref(re) subd := C.g_regex_replace_literal(re, (*C.gchar)(data(input)), C.gssize(len(input)), 0, (*C.gchar)(data(sub)), 0, &err) if err != nil { panic("g_regex_replace_literal") } defer C.g_free(C.gpointer(subd)) l := C.strlen((*C.char)(subd)) rv := make([]byte, l) C.memcpy(data(rv), unsafe.Pointer(subd), l) return rv }
func gtk_init() error { var err *C.GError = nil // redundant in Go, but let's explicitly assign it anyway // gtk_init_with_args() gives us error info (thanks chpe in irc.gimp.net/#gtk+) // don't worry about GTK+'s command-line arguments; they're also available as environment variables (thanks mclasen in irc.gimp.net/#gtk+) result := C.gtk_init_with_args(nil, nil, nil, nil, nil, &err) if result == C.FALSE { return fmt.Errorf("error actually initilaizing GTK+: %s", fromgstr(err.message)) } // now apply our custom program-global styles provider := C.gtk_css_provider_new() if C.gtk_css_provider_load_from_data(provider, (*C.gchar)(unsafe.Pointer(>kStyles[0])), C.gssize(len(gtkStyles)), &err) == C.FALSE { return fmt.Errorf("error applying package ui's custom program-global styles to GTK+: %v", fromgstr(err.message)) } // GDK (at least as far back as GTK+ 3.4, but officially documented as of 3.10) merges all screens into one big one, so we don't need to worry about multimonitor // thanks to baedert and mclasen in irc.gimp.net/#gtk+ C.gtk_style_context_add_provider_for_screen(C.gdk_screen_get_default(), (*C.GtkStyleProvider)(unsafe.Pointer(provider)), C.GTK_STYLE_PROVIDER_PRIORITY_USER) return nil }