2 # This file is part of duit.
4 # duit 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 # duit 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 duit; 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;
83 const uint G_MAXUINT = 4294967295;
88 # must start with wrap
92 ###########################################################
93 ### GLib Fundamentals #####################################
94 ###########################################################
96 file: glib-Version-Information.html
102 #file: glib-Basic-Types.html
105 #file: glib-Limits-of-Basic-Types.html
108 #file: glib-Standard-Macros.html
113 #file: glib-Type-Conversion-Macros.html
118 #file: glib-Byte-Order-Macros.html
123 #file: glib-Numerical-Definitions.html
128 #file: glib-Miscellaneous-Macros.html
133 file: glib-Atomic-Operations.html
138 ###########################################################
139 ### GLib Core Application Support #########################
140 ###########################################################
142 file: glib-The-Main-Event-Loop.html
147 noprefix: g_main_context_
152 structWrap: GDataset* Dataset
153 import: glib.MainContext
154 structWrap: GMainContext* MainContext
156 structWrap: GSource* Source
157 nocode: g_main_loop_ref
160 * Increases the reference count on a GMainLoop object by one.
166 public MainLoop ref()
168 // GMainLoop* g_main_loop_ref (GMainLoop *loop);
169 return new MainLoop( g_main_loop_ref(gMainLoop) );
176 prefix: g_main_context_
178 import: glib.MainLoop
179 structWrap: GMainLLoop* MainLoop
181 structWrap: GSource* Source
183 structWrap: GCond* Cond
184 import: gthread.Mutex
185 structWrap: GMutex* Mutex
186 import: glib.ThreadPool
187 structWrap: GThreadPoll* ThreadPoll
188 import: glib.MainContext
189 structWrap: GMainContext* MainContext
190 #import: glib.SourceFuncs
191 #structWrap: GSourceFuncs* SourceFuncs
193 #structWrap: GPollFD* PollFD
197 import: glib.MainLoop
198 structWrap: GMainLoop* MainLoop
200 structWrap: GDataset* Dataset
204 structWrap: GSource* Source
208 import: glib.MainLoop
209 structWrap: GMainLoop* MainLoop
211 structWrap: GDataset* Dataset
218 import: glib.MainLoop
219 structWrap: GMainLoop* MainLoop
221 structWrap: GDataset* Dataset
223 structWrap: GDate* Date
226 #import: glib.SourceFuncs
227 #structWrap: GSourceFuncs* SourceFuncs
229 structWrap: GSource* Source
230 import: glib.MainContext
231 structWrap: GMainContext* MainContext
232 #import: glib.SourceCallbackFuncs
233 #structWrap: GSourceCallbackFuncs* SourceCallbackFuncs
235 #structWrap: GPollFD* PollFD
236 #import: glib.TimeVal
237 #structWrap: GTimeVal* TimeVal
241 file: /home/ruimt/data/down/GTK/API/glib/glib-Threads.html
245 #import: gthread.Mutex
246 #structWrap: GMutex* Mutex
248 #structWrap: GSource* Source
249 #import: glib.Dataset
250 #structWrap: GDataset* Dataset
252 #structWrap: GList* ListG
255 #noprefix: g_static_rec_mutex_
256 #noprefix: g_static_rw_lock_
258 #noprefix: g_private_
259 #noprefix: g_static_private_
260 ##import: glib.ThreadFunctions
261 ##structWrap: GThreadFunctions* ThreadFunctions
262 #structWrap: GThread* Thread
263 ##import: glib.Error*
264 ##structWrap: GError** Error*
265 ##import: glib.StaticMutex
266 ##structWrap: GStaticMutex* StaticMutex
275 #struct: GStaticRecMutex
276 #class: StaticRecMutex
277 #prefix: g_static_rec_mutex_
279 #outFile: StaticRecMutex
281 #struct: GStaticRWLock
283 #prefix: g_static_rw_lock_
290 #structWrap: GDate* Date
293 #import: gthread.Mutex
294 #structWrap: GMutex* Mutex
295 ##import: glib.TimeVal
296 ##structWrap: GTimeVal* TimeVal
301 #import: glib.Dataset
302 #structWrap: GDataset* Dataset
307 #struct: GStaticPrivate
308 #class: StaticPrivate
309 #import: glib.Dataset
310 #structWrap: GDataset* Dataset
311 #prefix: g_static_private_
313 #outFile: StaticPrivate
323 file: glib-Thread-Pools.html
328 structWrap: GList* ListG
329 prefix: g_thread_pool_
330 import: glib.MainLoop
334 file: glib-Asynchronous-Queues.html
337 prefix: g_async_queue_
340 import: glib.AsyncQueue
341 structWrap: GAsyncQueue* AsyncQueue
342 #import: glib.TimeVal
343 #structWrap: GTimeVal* TimeVal
346 file: glib-Dynamic-Loading-of-Modules.html
351 structWrap: GModule* Module
356 file: glib-Memory-Allocation.html
359 #import: glib.MemVTable
360 #structWrap: GMemVTable* MemVTable
364 file: glib-IO-Channels.html
367 prefix: g_io_channel_
373 structWrap: GString* StringG
374 structWrap: GSource* Source
375 #import: glib.IOChannel
376 structWrap: GIOChannel* IOChannel
380 file: glib-Error-Reporting.html
389 file: glib-Warnings-and-Assertions.html
395 file: glib-Message-Logging.html
402 ###########################################################
403 ### GLib Utilities ########################################
404 ###########################################################
406 file: glib-String-Utility-Functions.html
410 structWrap: GString* StringG
416 const static char[10] digits = "0123456789"; /// 0..9
418 /*************************************************
419 * Convert C-style 0 terminated string s to char[] string.
422 public static char[] toString(char *s)
424 return s ? s[0 .. strlen(s)] : cast(char[])null;
427 /*********************************
428 * Convert array of chars s[] to a C-style 0 terminated string.
431 public static char* toStringz(char[] s)
439 // // TODO this one fails in some case???
440 // assert(strlen(result) == s.length);
441 // assert(memcmp(result, s, s.length) == 0);
454 // Need to make a copy
455 copy = new char[s.length + 1];
456 copy[0..s.length] = s;
463 public static char** toStringzArray(char[][] args)
469 char** argv = (new char*[args.length]).ptr;
471 foreach (char[] p; args)
473 argv[argc++] = cast(char*)(p~'\0');
480 public static char[][] toStringArray(char** args)
490 while( (arg) != null && i<10)
492 argv ~= toString(arg);
500 public static char[] toString(bool b)
502 return b ? "true" : "false";
505 public static char[] toString(char c)
507 char[] result = new char[2];
510 return result[0 .. 1];
513 public static char[] toString(ubyte ub) { return toString(cast(uint) ub); } /// ditto
514 public static char[] toString(ushort us) { return toString(cast(uint) us); } /// ditto
516 public static char[] toString(uint u)
517 { char[uint.sizeof * 3] buffer = void;
524 // Avoid storage allocation for simple stuff
525 result = digits[u .. u + 1];
533 buffer[buffer.length - ndigits] = c;
535 result = new char[ndigits];
536 result[] = buffer[buffer.length - ndigits .. buffer.length];
541 public static char[] toString(ulong u)
542 { char[ulong.sizeof * 3] buffer;
547 if (u < 0x1_0000_0000)
548 return toString(cast(uint)u);
555 buffer[buffer.length - ndigits] = c;
557 result = new char[ndigits];
558 result[] = buffer[buffer.length - ndigits .. buffer.length];
562 public static char[] toString(byte b) { return toString(cast(int) b); } /// ditto
563 public static char[] toString(short s) { return toString(cast(int) s); } /// ditto
565 public static char[] toString(int i)
566 { char[1 + int.sizeof * 3] buffer;
571 return toString(cast(uint)i);
579 buffer[buffer.length - ndigits] = c;
582 buffer[buffer.length - ndigits] = '-';
583 result = new char[ndigits];
584 result[] = buffer[buffer.length - ndigits .. buffer.length];
593 file: glib-Character-Set-Conversion.html
598 # these fail to compile because of a reference to a struct that size is not known
599 noprefix: g_convert_with_iconv
600 noprefix: g_iconv_open
602 noprefix: g_iconv_close
603 outFile: CharacterSet
605 file: glib-Unicode-Manipulation.html
613 class: Internationalization
616 outFile: Internationalization
618 file: glib-Date-and-Time-Functions.html
622 #import: glib.TimeVal
623 #structWrap: GTimeVal* TimeVal
626 structWrap: GDate* Date
629 file: glib-Random-Numbers.html
634 structWrap: GRand* RandG
637 #file: glib-Hook-Functions.html
640 ##import: glib.HookList
641 ##structWrap: GHookList* HookList
643 #structWrap: GHook* Hook
646 file: glib-Miscellaneous-Utility-Functions.html
649 structWrap: GList* ListG
651 #import: glib.DebugKey
652 #structWrap: GDebugKey* DebugKey
657 file: glib-Lexical-Scanner.html
660 import: glib.HashTable
661 structWrap: GHashTable* HashTable
663 #import: glib.Scanner
664 structWrap: GScanner* ScannerG
665 #import: glib.ScannerConfig
666 #structWrap: GScannerConfig* ScannerConfig
670 file: glib-Automatic-String-Completion.html
672 class: StringCompletion
674 structWrap: GList* ListG
677 outFile: StringCompletion
679 file: glib-Timers.html
684 structWrap: GTimer* Timer
687 file: glib-Spawning-Processes.html
690 import: glib.MainLoop
691 structWrap: GMainLoop* MainLoop
694 #structWrap: GPid* Pid
696 #structWrap: GError** Error*
701 import: std.c.string;
702 nocode: g_spawn_async_with_pipes
706 char[] workingDirectory = ".";
709 GSpawnFlags flags = SpawnFlags.SEARCH_PATH;
710 GSpawnChildSetupFunc childSetup;
714 FILE* standardOutput;
721 // for commandLineSync
726 alias bool delegate(Spawn) ChildWatch;
727 ChildWatch externalWatch;
730 * Creates a Spawn for execution.
732 public this(char[] program, char[][] envp=null)
739 * Creates a Spawn for execution.
741 public this(char[][] program, char[][] envp=null)
748 * Adds a delegate to be notified on the end of the child process.
753 public void addChildWatch(ChildWatch dlg)
759 * Closes all open streams and child process.
765 fclose(standardInput);
770 fclose(standardOutput);
775 fclose(standardError);
786 * Adds a parameter to the execution program
788 public void addParm(char[] parm)
794 * Gets the last error message
796 public char[] getLastError()
800 return Str.toString(error.message);
807 * Executes the prepared process
809 public int execAsyncWithPipes(
810 ChildWatch externalWatch = null,
811 bool delegate(char[]) readOutput = null,
812 bool delegate(char[]) readError = null )
814 int result = g_spawn_async_with_pipes(
815 Str.toStringz(workingDirectory),
816 Str.toStringzArray(argv),
817 Str.toStringzArray(envp),
830 this.externalWatch = externalWatch;
831 g_child_watch_add(childPid, cast(GChildWatchFunc)(&childWatchCallback), this);
832 standardInput = fdopen(stdIn, "w");
833 standardOutput = fdopen(stdOut, "r");
834 standardError = fdopen(stdErr, "r");
836 if ( readOutput !is null )
838 (new ReadFile(standardOutput, readOutput)).start();
840 if ( readError !is null )
842 (new ReadFile(standardError, readError)).start();
849 class ReadFile : Thread
851 bool delegate(char[]) read;
856 this(FILE* file, bool delegate (char[]) read )
864 char[] line = readLine(file);
865 while( line !is null )
868 //writefln("Spawn.ReadFile.run line (%s) ========== >>>%s<<<", lineCount, line);
869 //printf("Spawn.ReadFile.run line (%d) ========== >>>%.*s<<<", lineCount, line);
874 line = readLine(file);
880 private char[] readLine(FILE* stream, int max=4096)
884 if ( externalWatch !is null )
892 char* lineP = fgets(line.ptr, max, stream);
897 int l = strlen(line.ptr);
899 //printf("\nreadLine\n");
900 //foreach ( char c ; line )
908 extern(C) static void childWatchCallback(int pid, int status, Spawn spawn)
910 //writefln("Spawn.childWatchCallback %s %s", pid, status);
911 spawn.exitStatus = status;
912 if ( spawn.externalWatch !is null )
914 spawn.externalWatch(spawn);
920 public bool endOfOutput()
922 if ( standardOutput is null ) return true;
923 return feof(standardOutput) != 0;
926 public bool endOfError()
928 if ( standardError is null ) return true;
929 return feof(standardError) != 0;
932 char[] getOutputString()
934 return Str.toString(strOutput);
937 char[] getErrorString()
939 return Str.toString(strError);
948 // public int commandLineSync()
950 // char[] commandLine;
951 // foreach ( int count, char[] arg; argv)
955 // commandLine ~= ' ';
957 // commandLine ~= arg;
959 // return g_spawn_command_line_sync(
961 // Str.toStringz(commandLine),
969 * Executes a command synchronasly and
970 * optionally calls delegates for sysout, syserr and end of job
973 public int commandLineSync(
974 ChildWatch externalWatch = null,
975 bool delegate(char[]) readOutput = null,
976 bool delegate(char[]) readError = null )
979 foreach ( int count, char[] arg; argv)
987 int status = g_spawn_command_line_sync(
988 Str.toStringz(commandLine),
993 if ( readOutput != null )
995 foreach ( char[] line ; splitlines(Str.toString(strOutput)) )
1000 if ( readError != null )
1002 foreach ( char[] line ; splitlines(Str.toString(strError)) )
1007 if ( externalWatch != null )
1009 externalWatch(this);
1021 file: glib-File-Utilities.html
1026 #import: glib.ErrorG
1027 #import: glib.Error*
1028 #structWrap: GError** Error*
1030 #structWrap: GDir* Dir
1031 #import: glib.MappedFile
1032 #structWrap: GMappedFile* MappedFile
1035 file: glib-Shell-related-Utilities.html
1042 file: glib-Commandline-option-parser.html
1044 struct: GOptionContext
1045 class: OptionContext
1047 prefix: g_option_context_
1048 noprefix: g_option_group_
1049 #import: glib.Error*
1050 #structWrap: GError** Error*
1051 #import: glib.OptionEntry
1052 #structWrap: GOptionEntry* OptionEntry
1053 import: glib.OptionGroup
1054 structWrap: GOptionGroup* OptionGroup
1056 outFile: OptionContext
1058 struct: GOptionGroup
1060 import: glib.Dataset
1061 structWrap: GDataset* Dataset
1062 import: glib.OptionContext
1063 structWrap: GOptionContext* OptionContext
1064 prefix: g_option_group_
1066 #import: glib.OptionEntry
1067 #structWrap: GOptionEntry* OptionEntry
1069 outFile: OptionGroup
1071 file: glib-Glob-style-pattern-matching.html
1072 struct: GPatternSpec
1074 prefix: g_pattern_spec_
1075 prefix: g_pattern_match_
1076 #import: glib.PatternSpec
1077 structWrap: GPatternSpec* Pattern
1081 file: glib-Simple-XML-Subset-Parser.html
1082 struct: GMarkupParseContext
1085 import: glib.Dataset
1086 structWrap: GDataset* Dataset
1087 prefix: g_markup_parse_context_
1088 #import: glib.Error*
1089 #structWrap: GError** Error*
1090 #import: glib.MarkupParser
1091 #structWrap: GMarkupParser* MarkupParser
1095 file: glib-Key-value-file-parser.html
1103 file: glib-Windows-Compatibility-Functions.html
1107 outFile: WindowsUtils
1110 ###########################################################
1111 ### GLib Data Types #######################################
1112 ###########################################################
1114 file: glib-Memory-Slices.html
1117 outFile: MemorySlice
1119 file: glib-Memory-Chunks.html
1122 prefix: g_mem_chunk_
1124 outFile: MemoryChunk
1126 file: glib-Doubly-Linked-Lists.html
1131 structWrap: GList* ListG
1134 file: glib-Singly-Linked-Lists.html
1139 #import: glib.ListSG
1140 structWrap: GSList* ListSG
1143 file: glib-Double-ended-Queues.html
1148 #import: glib.QueueG
1149 structWrap: GQueue* QueueG
1151 structWrap: GList* ListG
1154 file: glib-Trash-Stacks.html
1157 prefix: g_trash_stack_
1158 #import: glib.TrashStack*
1159 #structWrap: GTrashStack** TrashStack*
1162 file: glib-Hash-Tables.html
1165 import: glib.Dataset
1166 prefix: g_hash_table_
1167 #import: glib.HashTable
1168 structWrap: GHashTable* HashTable
1171 file: glib-Strings.html
1175 #import: glib.StringG
1176 structWrap: GString* StringG
1180 file: glib-String-Chunks.html
1181 struct: GStringChunk
1183 prefix: g_string_chunk_
1185 outFile: StringGChunk
1187 file: glib-Arrays.html
1193 structWrap: GArray* ArrayG
1197 file: glib-Pointer-Arrays.html
1201 structWrap: GList* ListG
1202 prefix: g_ptr_array_
1203 #import: glib.PtrArray
1204 structWrap: GPtrArray* PtrArray
1207 file: glib-Byte-Arrays.html
1211 structWrap: GList* ListG
1212 prefix: g_byte_array_
1215 file: glib-Balanced-Binary-Trees.html
1219 import: glib.Dataset
1220 structWrap: GList* List*
1221 structWrap: GDataset* Dataset
1225 file: glib-N-ary-Trees.html
1229 structWrap: GTree* BBTree
1230 structWrap: GNode* Node
1234 file: glib-Quarks.html
1242 file: glib-Keyed-Data-Lists.html
1247 import: glib.Dataset
1248 structWrap: GDataset* Dataset
1251 file: glib-Datasets.html
1257 file: glib-Relations-and-Tuples.html
1260 import: glib.HashTable
1261 structWrap: GHashTable* HashTable
1265 structWrap: GTuples* Tuples
1274 file: glib-Caches.html
1277 import: glib.HashTable
1278 structWrap: GHashTable* HashTable
1282 file: glib-Memory-Allocators.html
1285 prefix: g_allocator_
1289 ###########################################################
1290 ### GLib Tools ############################################
1291 ###########################################################