2 # This file is part of gtkD.
4 # gtkD is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU Lesser General Public License as published by
6 # the Free Software Foundation; either version 2.1 of the License, or
7 # (at your option) any later version.
9 # gtkD is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with gtkD; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # Definitions for wrapping GLib
30 /* The GLib Basic Types */
31 public alias int gint;
32 public alias uint guint;
33 public alias int gboolean;
34 public alias void* gpointer;
35 public alias void* gconstpointer;
36 public alias char gchar;
37 public alias char guchar;
38 public alias short gshort;
39 public alias ushort gushort;
40 public alias int glong;
41 public alias uint gulong;
42 public alias byte gint8;
43 public alias byte guint8;
44 public alias short gint16;
45 public alias ushort guint16;
46 public alias int gint32;
47 public alias long gint64;
48 public alias uint guint32;
49 public alias ulong guint64;
50 public alias float gfloat;
51 public alias double gdouble;
52 public alias uint gsize;
53 public alias int gssize;
54 public alias void* va_list;
55 public alias dchar unichar;
56 public alias wchar unichar2;
57 //public alias dchar gunichar;
58 //public alias wchar gunichar2;
59 public alias int time_t;
60 public alias uint XID;
84 const uint G_MAXUINT = 4294967295;
89 # must start with wrap
93 ###########################################################
94 ### GLib Fundamentals #####################################
95 ###########################################################
97 file: glib-Version-Information.html
103 #file: glib-Basic-Types.html
106 #file: glib-Limits-of-Basic-Types.html
109 #file: glib-Standard-Macros.html
114 #file: glib-Type-Conversion-Macros.html
119 #file: glib-Byte-Order-Macros.html
124 #file: glib-Numerical-Definitions.html
129 #file: glib-Miscellaneous-Macros.html
134 file: glib-Atomic-Operations.html
139 ###########################################################
140 ### GLib Core Application Support #########################
141 ###########################################################
143 file: glib-The-Main-Event-Loop.html
148 noprefix: g_main_context_
153 structWrap: GDataset* Dataset
154 import: glib.MainContext
155 structWrap: GMainContext* MainContext
157 structWrap: GSource* Source
158 nocode: g_main_loop_ref
161 * Increases the reference count on a GMainLoop object by one.
167 public MainLoop doref()
169 // GMainLoop* g_main_loop_ref (GMainLoop *loop);
170 return new MainLoop( g_main_loop_ref(gMainLoop) );
177 prefix: g_main_context_
179 import: glib.MainLoop
180 structWrap: GMainLLoop* MainLoop
182 structWrap: GSource* Source
184 structWrap: GCond* Cond
185 import: gthread.Mutex
186 structWrap: GMutex* Mutex
187 import: glib.ThreadPool
188 structWrap: GThreadPoll* ThreadPoll
189 import: glib.MainContext
190 structWrap: GMainContext* MainContext
191 #import: glib.SourceFuncs
192 #structWrap: GSourceFuncs* SourceFuncs
194 #structWrap: GPollFD* PollFD
198 import: glib.MainLoop
199 structWrap: GMainLoop* MainLoop
201 structWrap: GDataset* Dataset
205 structWrap: GSource* Source
209 import: glib.MainLoop
210 structWrap: GMainLoop* MainLoop
212 structWrap: GDataset* Dataset
219 import: glib.MainLoop
220 structWrap: GMainLoop* MainLoop
222 structWrap: GDataset* Dataset
224 structWrap: GDate* Date
227 #import: glib.SourceFuncs
228 #structWrap: GSourceFuncs* SourceFuncs
230 structWrap: GSource* Source
231 import: glib.MainContext
232 structWrap: GMainContext* MainContext
233 #import: glib.SourceCallbackFuncs
234 #structWrap: GSourceCallbackFuncs* SourceCallbackFuncs
236 #structWrap: GPollFD* PollFD
237 #import: glib.TimeVal
238 #structWrap: GTimeVal* TimeVal
242 file: glib-Threads.html
246 #import: gthread.Mutex
247 #structWrap: GMutex* Mutex
249 #structWrap: GSource* Source
250 #import: glib.Dataset
251 #structWrap: GDataset* Dataset
253 #structWrap: GList* ListG
256 #noprefix: g_static_rec_mutex_
257 #noprefix: g_static_rw_lock_
259 #noprefix: g_private_
260 #noprefix: g_static_private_
261 ##import: glib.ThreadFunctions
262 ##structWrap: GThreadFunctions* ThreadFunctions
263 #structWrap: GThread* Thread
264 ##import: glib.Error*
265 ##structWrap: GError** Error*
266 ##import: glib.StaticMutex
267 ##structWrap: GStaticMutex* StaticMutex
276 #struct: GStaticRecMutex
277 #class: StaticRecMutex
278 #prefix: g_static_rec_mutex_
280 #outFile: StaticRecMutex
282 #struct: GStaticRWLock
284 #prefix: g_static_rw_lock_
291 #structWrap: GDate* Date
294 #import: gthread.Mutex
295 #structWrap: GMutex* Mutex
296 ##import: glib.TimeVal
297 ##structWrap: GTimeVal* TimeVal
302 #import: glib.Dataset
303 #structWrap: GDataset* Dataset
308 #struct: GStaticPrivate
309 #class: StaticPrivate
310 #import: glib.Dataset
311 #structWrap: GDataset* Dataset
312 #prefix: g_static_private_
314 #outFile: StaticPrivate
324 file: glib-Thread-Pools.html
329 structWrap: GList* ListG
330 prefix: g_thread_pool_
331 import: glib.MainLoop
335 file: glib-Asynchronous-Queues.html
338 prefix: g_async_queue_
341 import: glib.AsyncQueue
342 structWrap: GAsyncQueue* AsyncQueue
343 #import: glib.TimeVal
344 #structWrap: GTimeVal* TimeVal
347 file: glib-Dynamic-Loading-of-Modules.html
352 structWrap: GModule* Module
357 file: glib-Memory-Allocation.html
360 #import: glib.MemVTable
361 #structWrap: GMemVTable* MemVTable
365 file: glib-IO-Channels.html
368 prefix: g_io_channel_
374 structWrap: GString* StringG
375 structWrap: GSource* Source
376 #import: glib.IOChannel
377 structWrap: GIOChannel* IOChannel
381 file: glib-Error-Reporting.html
390 file: glib-Warnings-and-Assertions.html
396 file: glib-Message-Logging.html
403 ###########################################################
404 ### GLib Utilities ########################################
405 ###########################################################
407 file: glib-String-Utility-Functions.html
411 structWrap: GString* StringG
417 const static char[10] digits = "0123456789"; /// 0..9
419 /*************************************************
420 * Convert C-style 0 terminated string s to char[] string.
423 public static char[] toString(char *s)
425 return s ? s[0 .. strlen(s)] : cast(char[])null;
428 /*********************************
429 * Convert array of chars s[] to a C-style 0 terminated string.
432 public static char* toStringz(char[] s)
440 // // TODO this one fails in some case???
441 // assert(strlen(result) == s.length);
442 // assert(memcmp(result, s, s.length) == 0);
455 // Need to make a copy
456 copy = new char[s.length + 1];
457 copy[0..s.length] = s;
464 public static char** toStringzArray(char[][] args)
470 char** argv = (new char*[args.length]).ptr;
472 foreach (char[] p; args)
474 argv[argc++] = cast(char*)(p~'\0');
481 public static char[][] toStringArray(char** args)
491 while( (arg) != null && i<10)
493 argv ~= toString(arg);
501 public static char[] toString(bool b)
503 return b ? "true" : "false";
506 public static char[] toString(char c)
508 char[] result = new char[2];
511 return result[0 .. 1];
514 public static char[] toString(ubyte ub) { return toString(cast(uint) ub); } /// ditto
515 public static char[] toString(ushort us) { return toString(cast(uint) us); } /// ditto
517 public static char[] toString(uint u)
518 { char[uint.sizeof * 3] buffer = void;
525 // Avoid storage allocation for simple stuff
526 result = digits[u .. u + 1];
534 buffer[buffer.length - ndigits] = c;
536 result = new char[ndigits];
537 result[] = buffer[buffer.length - ndigits .. buffer.length];
542 public static char[] toString(ulong u)
543 { char[ulong.sizeof * 3] buffer;
548 if (u < 0x1_0000_0000)
549 return toString(cast(uint)u);
556 buffer[buffer.length - ndigits] = c;
558 result = new char[ndigits];
559 result[] = buffer[buffer.length - ndigits .. buffer.length];
563 public static char[] toString(byte b) { return toString(cast(int) b); } /// ditto
564 public static char[] toString(short s) { return toString(cast(int) s); } /// ditto
566 public static char[] toString(int i)
567 { char[1 + int.sizeof * 3] buffer;
572 return toString(cast(uint)i);
580 buffer[buffer.length - ndigits] = c;
583 buffer[buffer.length - ndigits] = '-';
584 result = new char[ndigits];
585 result[] = buffer[buffer.length - ndigits .. buffer.length];
594 file: glib-Character-Set-Conversion.html
599 # these fail to compile because of a reference to a struct that size is not known
600 noprefix: g_convert_with_iconv
601 noprefix: g_iconv_open
603 noprefix: g_iconv_close
604 outFile: CharacterSet
606 file: glib-Unicode-Manipulation.html
614 class: Internationalization
617 outFile: Internationalization
619 file: glib-Date-and-Time-Functions.html
623 #import: glib.TimeVal
624 #structWrap: GTimeVal* TimeVal
627 structWrap: GDate* Date
630 file: glib-Random-Numbers.html
635 structWrap: GRand* RandG
638 #file: glib-Hook-Functions.html
641 ##import: glib.HookList
642 ##structWrap: GHookList* HookList
644 #structWrap: GHook* Hook
647 file: glib-Miscellaneous-Utility-Functions.html
650 structWrap: GList* ListG
652 #import: glib.DebugKey
653 #structWrap: GDebugKey* DebugKey
658 file: glib-Lexical-Scanner.html
661 import: glib.HashTable
662 structWrap: GHashTable* HashTable
664 #import: glib.Scanner
665 structWrap: GScanner* ScannerG
666 #import: glib.ScannerConfig
667 #structWrap: GScannerConfig* ScannerConfig
671 file: glib-Automatic-String-Completion.html
673 class: StringCompletion
675 structWrap: GList* ListG
678 outFile: StringCompletion
680 file: glib-Timers.html
685 structWrap: GTimer* Timer
688 file: glib-Spawning-Processes.html
691 import: glib.MainLoop
692 structWrap: GMainLoop* MainLoop
695 #structWrap: GPid* Pid
697 #structWrap: GError** Error*
704 nocode: g_spawn_async_with_pipes
708 version(Tango) alias splitLines splitlines;
711 char[] workingDirectory = ".";
714 GSpawnFlags flags = SpawnFlags.SEARCH_PATH;
715 GSpawnChildSetupFunc childSetup;
719 FILE* standardOutput;
726 // for commandLineSync
731 alias bool delegate(Spawn) ChildWatch;
732 ChildWatch externalWatch;
735 * Creates a Spawn for execution.
737 public this(char[] program, char[][] envp=null)
744 * Creates a Spawn for execution.
746 public this(char[][] program, char[][] envp=null)
753 * Adds a delegate to be notified on the end of the child process.
758 public void addChildWatch(ChildWatch dlg)
764 * Closes all open streams and child process.
770 fclose(standardInput);
775 fclose(standardOutput);
780 fclose(standardError);
791 * Adds a parameter to the execution program
793 public void addParm(char[] parm)
799 * Gets the last error message
801 public char[] getLastError()
805 return Str.toString(error.message);
812 * Executes the prepared process
814 public int execAsyncWithPipes(
815 ChildWatch externalWatch = null,
816 bool delegate(char[]) readOutput = null,
817 bool delegate(char[]) readError = null )
819 int result = g_spawn_async_with_pipes(
820 Str.toStringz(workingDirectory),
821 Str.toStringzArray(argv),
822 Str.toStringzArray(envp),
835 this.externalWatch = externalWatch;
836 g_child_watch_add(childPid, cast(GChildWatchFunc)(&childWatchCallback), cast(void*)this);
837 standardInput = fdopen(stdIn, "w");
838 standardOutput = fdopen(stdOut, "r");
839 standardError = fdopen(stdErr, "r");
841 if ( readOutput !is null )
843 (new ReadFile(standardOutput, readOutput)).start();
845 if ( readError !is null )
847 (new ReadFile(standardError, readError)).start();
854 class ReadFile : Thread
856 bool delegate(char[]) read;
861 this(FILE* file, bool delegate (char[]) read )
869 char[] line = readLine(file);
870 while( line !is null )
873 //writefln("Spawn.ReadFile.run line (%s) ========== >>>%s<<<", lineCount, line);
874 //printf("Spawn.ReadFile.run line (%d) ========== >>>%.*s<<<", lineCount, line);
879 line = readLine(file);
885 private char[] readLine(FILE* stream, int max=4096)
889 if ( externalWatch !is null )
897 char* lineP = fgets(line.ptr, max, stream);
902 int l = strlen(line.ptr);
904 //printf("\nreadLine\n");
905 //foreach ( char c ; line )
913 extern(C) static void childWatchCallback(int pid, int status, Spawn spawn)
915 //writefln("Spawn.childWatchCallback %s %s", pid, status);
916 spawn.exitStatus = status;
917 if ( spawn.externalWatch !is null )
919 spawn.externalWatch(spawn);
925 public bool endOfOutput()
927 if ( standardOutput is null ) return true;
928 return feof(standardOutput) != 0;
931 public bool endOfError()
933 if ( standardError is null ) return true;
934 return feof(standardError) != 0;
937 char[] getOutputString()
939 return Str.toString(strOutput);
942 char[] getErrorString()
944 return Str.toString(strError);
953 // public int commandLineSync()
955 // char[] commandLine;
956 // foreach ( int count, char[] arg; argv)
960 // commandLine ~= ' ';
962 // commandLine ~= arg;
964 // return g_spawn_command_line_sync(
966 // Str.toStringz(commandLine),
974 * Executes a command synchronasly and
975 * optionally calls delegates for sysout, syserr and end of job
978 public int commandLineSync(
979 ChildWatch externalWatch = null,
980 bool delegate(char[]) readOutput = null,
981 bool delegate(char[]) readError = null )
984 foreach ( int count, char[] arg; argv)
992 int status = g_spawn_command_line_sync(
993 Str.toStringz(commandLine),
998 if ( readOutput != null )
1000 foreach ( char[] line ; splitlines(Str.toString(strOutput)) )
1005 if ( readError != null )
1007 foreach ( char[] line ; splitlines(Str.toString(strError)) )
1012 if ( externalWatch != null )
1014 externalWatch(this);
1026 file: glib-File-Utilities.html
1031 #import: glib.ErrorG
1032 #import: glib.Error*
1033 #structWrap: GError** Error*
1035 #structWrap: GDir* Dir
1036 #import: glib.MappedFile
1037 #structWrap: GMappedFile* MappedFile
1040 file: glib-Shell-related-Utilities.html
1047 file: glib-Commandline-option-parser.html
1049 struct: GOptionContext
1050 class: OptionContext
1052 prefix: g_option_context_
1053 noprefix: g_option_group_
1054 #import: glib.Error*
1055 #structWrap: GError** Error*
1056 #import: glib.OptionEntry
1057 #structWrap: GOptionEntry* OptionEntry
1058 import: glib.OptionGroup
1059 structWrap: GOptionGroup* OptionGroup
1061 outFile: OptionContext
1063 struct: GOptionGroup
1065 import: glib.Dataset
1066 structWrap: GDataset* Dataset
1067 import: glib.OptionContext
1068 structWrap: GOptionContext* OptionContext
1069 prefix: g_option_group_
1071 #import: glib.OptionEntry
1072 #structWrap: GOptionEntry* OptionEntry
1074 outFile: OptionGroup
1076 file: glib-Glob-style-pattern-matching.html
1077 struct: GPatternSpec
1079 prefix: g_pattern_spec_
1080 prefix: g_pattern_match_
1081 #import: glib.PatternSpec
1082 structWrap: GPatternSpec* Pattern
1086 file: glib-Simple-XML-Subset-Parser.html
1087 struct: GMarkupParseContext
1090 import: glib.Dataset
1091 structWrap: GDataset* Dataset
1092 prefix: g_markup_parse_context_
1093 #import: glib.Error*
1094 #structWrap: GError** Error*
1095 #import: glib.MarkupParser
1096 #structWrap: GMarkupParser* MarkupParser
1100 file: glib-Key-value-file-parser.html
1108 file: glib-Windows-Compatibility-Functions.html
1112 outFile: WindowsUtils
1115 ###########################################################
1116 ### GLib Data Types #######################################
1117 ###########################################################
1119 file: glib-Memory-Slices.html
1122 outFile: MemorySlice
1124 file: glib-Memory-Chunks.html
1127 prefix: g_mem_chunk_
1129 outFile: MemoryChunk
1131 file: glib-Doubly-Linked-Lists.html
1136 structWrap: GList* ListG
1142 int* pt =cast(int*)getStruct();
1143 return cast(void *)(*pt);
1152 file: glib-Singly-Linked-Lists.html
1157 #import: glib.ListSG
1158 structWrap: GSList* ListSG
1161 file: glib-Double-ended-Queues.html
1166 #import: glib.QueueG
1167 structWrap: GQueue* QueueG
1169 structWrap: GList* ListG
1172 file: glib-Trash-Stacks.html
1175 prefix: g_trash_stack_
1176 #import: glib.TrashStack*
1177 #structWrap: GTrashStack** TrashStack*
1180 file: glib-Hash-Tables.html
1183 import: glib.Dataset
1184 prefix: g_hash_table_
1185 #import: glib.HashTable
1186 structWrap: GHashTable* HashTable
1189 file: glib-Strings.html
1193 #import: glib.StringG
1194 structWrap: GString* StringG
1198 file: glib-String-Chunks.html
1199 struct: GStringChunk
1201 prefix: g_string_chunk_
1203 outFile: StringGChunk
1205 file: glib-Arrays.html
1211 structWrap: GArray* ArrayG
1215 file: glib-Pointer-Arrays.html
1219 structWrap: GList* ListG
1220 prefix: g_ptr_array_
1221 #import: glib.PtrArray
1222 structWrap: GPtrArray* PtrArray
1225 file: glib-Byte-Arrays.html
1229 structWrap: GList* ListG
1230 prefix: g_byte_array_
1233 file: glib-Balanced-Binary-Trees.html
1237 import: glib.Dataset
1238 structWrap: GList* List*
1239 structWrap: GDataset* Dataset
1243 file: glib-N-ary-Trees.html
1247 structWrap: GTree* BBTree
1248 structWrap: GNode* Node
1252 file: glib-Quarks.html
1260 file: glib-Keyed-Data-Lists.html
1265 import: glib.Dataset
1266 structWrap: GDataset* Dataset
1269 file: glib-Datasets.html
1275 file: glib-Relations-and-Tuples.html
1278 import: glib.HashTable
1279 structWrap: GHashTable* HashTable
1283 structWrap: GTuples* Tuples
1292 file: glib-Caches.html
1295 import: glib.HashTable
1296 structWrap: GHashTable* HashTable
1300 file: glib-Memory-Allocators.html
1303 prefix: g_allocator_
1307 ###########################################################
1308 ### GLib Tools ############################################
1309 ###########################################################