1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "github.com/ebitengine/purego"
6
7 "github.com/bnema/puregotk/pkg/core"
8)
9
10// Error codes returned by shell functions.
11type ShellError int
12
13const (
14
15 // Mismatched or otherwise mangled quoting.
16 GShellErrorBadQuotingValue ShellError = 0
17 // String to be parsed was empty.
18 GShellErrorEmptyStringValue ShellError = 1
19 // Some other error.
20 GShellErrorFailedValue ShellError = 2
21)
22
23var xShellParseArgv func(string, *int, *[]string, **Error) bool
24
25// Parses a command line into an argument vector, in much the same way
26// the shell would, but without many of the expansions the shell would
27// perform (variable expansion, globs, operators, filename expansion,
28// etc. are not supported).
29//
30// The results are defined to be the same as those you would get from
31// a UNIX98 `/bin/sh`, as long as the input contains none of the
32// unsupported shell expansions. If the input does contain such expansions,
33// they are passed through literally.
34//
35// Possible errors are those from the %G_SHELL_ERROR domain.
36//
37// In particular, if @command_line is an empty string (or a string containing
38// only whitespace), %G_SHELL_ERROR_EMPTY_STRING will be returned. It’s
39// guaranteed that @argvp will be a non-empty array if this function returns
40// successfully.
41//
42// Free the returned vector with g_strfreev().
43func ShellParseArgv(CommandLineVar string, ArgcpVar *int, ArgvpVar *[]string) (bool, error) {
44 var cerr *Error
45
46 cret := xShellParseArgv(CommandLineVar, ArgcpVar, ArgvpVar, &cerr)
47
48 if cerr == nil {
49 return cret, nil
50 }
51 return cret, cerr
52
53}
54
55var xShellQuote func(string) string
56
57// Quotes a string so that the shell (/bin/sh) will interpret the
58// quoted string to mean @unquoted_string.
59//
60// If you pass a filename to the shell, for example, you should first
61// quote it with this function.
62//
63// The return value must be freed with g_free().
64//
65// The quoting style used is undefined (single or double quotes may be
66// used).
67func ShellQuote(UnquotedStringVar string) string {
68
69 cret := xShellQuote(UnquotedStringVar)
70
71 return cret
72}
73
74var xShellUnquote func(string, **Error) string
75
76// Unquotes a string as the shell (/bin/sh) would.
77//
78// This function only handles quotes; if a string contains file globs,
79// arithmetic operators, variables, backticks, redirections, or other
80// special-to-the-shell features, the result will be different from the
81// result a real shell would produce (the variables, backticks, etc.
82// will be passed through literally instead of being expanded).
83//
84// This function is guaranteed to succeed if applied to the result of
85// g_shell_quote(). If it fails, it returns %NULL and sets the
86// error.
87//
88// The @quoted_string need not actually contain quoted or escaped text;
89// g_shell_unquote() simply goes through the string and unquotes/unescapes
90// anything that the shell would. Both single and double quotes are
91// handled, as are escapes including escaped newlines.
92//
93// The return value must be freed with g_free().
94//
95// Possible errors are in the %G_SHELL_ERROR domain.
96//
97// Shell quoting rules are a bit strange. Single quotes preserve the
98// literal string exactly. escape sequences are not allowed; not even
99// `\'` - if you want a `'` in the quoted text, you have to do something
100// like `'foo'\”bar'`. Double quotes allow `$`, ```, `"`, `\`, and
101// newline to be escaped with backslash. Otherwise double quotes
102// preserve things literally.
103func ShellUnquote(QuotedStringVar string) (string, error) {
104 var cerr *Error
105
106 cret := xShellUnquote(QuotedStringVar, &cerr)
107
108 if cerr == nil {
109 return cret, nil
110 }
111 return cret, cerr
112
113}
114
115func init() {
116 core.SetPackageName("GLIB", "glib-2.0")
117 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
118 var libs []uintptr
119 for _, libPath := range core.GetPaths("GLIB") {
120 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
121 if err != nil {
122 panic(err)
123 }
124 libs = append(libs, lib)
125 }
126
127 core.PuregoSafeRegister(&xShellParseArgv, libs, "g_shell_parse_argv")
128 core.PuregoSafeRegister(&xShellQuote, libs, "g_shell_quote")
129 core.PuregoSafeRegister(&xShellUnquote, libs, "g_shell_unquote")
130
131}