12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788(** Conversions functions *)openCtypesopenForeign(** C pointer of null terminated array of C strings *)typecarray_of_strings=charptrptrletcarray_of_strings:carray_of_stringstyp=ptr(ptrchar)(** Converts C array of strings to OCaml list of strings *)letcarray_of_strings_to_list:charptrptr->stringlist=letrecloopaccp=matchcoerce(ptrchar)string_opt!@pwith|None->List.revacc|Somes->loop(s::acc)(p+@1)inloop[](** Converts C array of strings to OCaml array of strings *)externalcarray_of_strings_to_array:carray_of_strings->stringarray="caml_copy_string_array"(** GList struct *)typeglistletglist:gliststructuretyp=structure"GList"letglist_data=fieldglist"data"(ptrvoid)letglist_next=fieldglist"next"(ptr_optglist)letglist_prev=fieldglist"prev"(ptr_optglist)let()=sealglistletg_free=foreign"g_free"(ptrvoid@->returningvoid)letg_free_t=ptrvoid@->returningvoidletglist_free_full=foreign"g_list_free_full"(ptrglist@->funptrg_free_t@->returningvoid)(** Get the next element of a glist *)letg_list_nextl_ptr=getf(!@l_ptr)glist_next(** Get the void ptr data of the current element *)letg_list_datal_ptr=getf(!@l_ptr)glist_data(** Transform a GList of strings to an OCaml list of strings *)letglist_of_strings_to_listglist_ptr=letrecloopaccp=matchpwith|None->List.revacc|Somep'->letdata=g_list_datap'inletnext=g_list_nextp'inmatchcoerce(ptrvoid)string_optdatawith|None->loopaccnext|Somes->loop(s::acc)nextinletocaml_list=loop[](Someglist_ptr)inlet_=glist_free_fullglist_ptrg_freeinocaml_list(** GSList struct *)typegslistletgslist:gsliststructuretyp=structure"GSList"letgslist_data=fieldgslist"data"(ptrvoid)letgslist_next=fieldgslist"next"(ptr_optgslist)let()=sealgslist(** Get the next element of a gslist *)letg_slist_nextl_ptr=getf(!@l_ptr)gslist_next(** Get the void ptr data of the current element *)letg_slist_datal_ptr=getf(!@l_ptr)gslist_data(** Transform a GSList of strings to an OCaml list of strings *)letgslist_of_strings_to_listgslist_ptr=letrecloopaccp=matchpwith|None->List.revacc|Somep'->letdata=g_slist_datap'inletnext=g_slist_nextp'inmatchcoerce(ptrvoid)string_optdatawith|None->loopaccnext|Somes->loop(s::acc)nextinloop[](Somegslist_ptr)