1 /*
2 * mape - C4 Landscape.txt editor
3 *
4 * Copyright (c) 2005-2009, Armin Burgmeier
5 *
6 * Distributed under the terms of the ISC license; see accompanying file
7 * "COPYING" for details.
8 *
9 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10 * See accompanying file "TRADEMARK" for details.
11 *
12 * To redistribute this file separately, substitute the full license texts
13 * for the above references.
14 */
15
16 #include "C4Include.h"
17 #include "c4group/C4Group.h"
18 #include "mape/cpp-handles/group-handle.h"
19
20 #define GROUP_TO_HANDLE(group) (reinterpret_cast<C4GroupHandle*>(group))
21 #define HANDLE_TO_GROUP(handle) (reinterpret_cast<C4Group*>(handle))
22
23 extern "C" {
24
c4_group_handle_new(void)25 C4GroupHandle* c4_group_handle_new(void)
26 {
27 return GROUP_TO_HANDLE(new C4Group);
28 }
29
c4_group_handle_free(C4GroupHandle * handle)30 void c4_group_handle_free(C4GroupHandle* handle)
31 {
32 delete HANDLE_TO_GROUP(handle);
33 }
34
c4_group_handle_get_error(C4GroupHandle * handle)35 const gchar* c4_group_handle_get_error(C4GroupHandle* handle)
36 {
37 return HANDLE_TO_GROUP(handle)->GetError();
38 }
39
c4_group_handle_open(C4GroupHandle * handle,const gchar * path,gboolean create)40 gboolean c4_group_handle_open(C4GroupHandle* handle, const gchar* path, gboolean create)
41 {
42 return HANDLE_TO_GROUP(handle)->Open(path, create);
43 }
44
c4_group_handle_open_as_child(C4GroupHandle * handle,C4GroupHandle * mother,const gchar * name,gboolean exclusive,gboolean create)45 gboolean c4_group_handle_open_as_child(C4GroupHandle* handle, C4GroupHandle* mother, const gchar* name, gboolean exclusive, gboolean create)
46 {
47 return HANDLE_TO_GROUP(handle)->OpenAsChild(HANDLE_TO_GROUP(mother),
48 name, exclusive, create);
49 }
50
c4_group_handle_get_name(C4GroupHandle * handle)51 const gchar* c4_group_handle_get_name(C4GroupHandle* handle)
52 {
53 return HANDLE_TO_GROUP(handle)->GetName();
54 }
55
c4_group_handle_get_full_name(C4GroupHandle * handle)56 gchar* c4_group_handle_get_full_name(C4GroupHandle* handle)
57 {
58 StdStrBuf buf(HANDLE_TO_GROUP(handle)->GetFullName());
59 gchar* res = static_cast<gchar*>(g_malloc(buf.getSize()*sizeof(gchar)));
60 memcpy(res, buf.getData(), buf.getSize());
61 return res;
62 }
63
c4_group_handle_reset_search(C4GroupHandle * handle)64 void c4_group_handle_reset_search(C4GroupHandle* handle)
65 {
66 HANDLE_TO_GROUP(handle)->ResetSearch();
67 }
68
c4_group_handle_find_next_entry(C4GroupHandle * handle,const gchar * wildcard,gsize * size,gchar * filename,gboolean start_at_filename)69 gboolean c4_group_handle_find_next_entry(C4GroupHandle* handle, const gchar* wildcard, gsize* size, gchar* filename, gboolean start_at_filename)
70 {
71 return HANDLE_TO_GROUP(handle)->FindNextEntry(wildcard, filename, size, start_at_filename);
72 }
73
c4_group_handle_access_next_entry(C4GroupHandle * handle,const gchar * wildcard,gsize * size,gchar * filename,gboolean start_at_filename)74 gboolean c4_group_handle_access_next_entry(C4GroupHandle* handle, const gchar* wildcard, gsize* size, gchar* filename, gboolean start_at_filename)
75 {
76 return HANDLE_TO_GROUP(handle)->AccessNextEntry(wildcard, size, filename, start_at_filename);
77 }
78
c4_group_handle_access_entry(C4GroupHandle * handle,const gchar * wildcard,gsize * size,gchar * filename,gboolean needs_to_be_a_group)79 gboolean c4_group_handle_access_entry(C4GroupHandle* handle, const gchar* wildcard, gsize* size, gchar* filename, gboolean needs_to_be_a_group)
80 {
81 return HANDLE_TO_GROUP(handle)->AccessEntry(wildcard, size, filename, needs_to_be_a_group);
82 }
83
c4_group_handle_accessed_entry_size(C4GroupHandle * handle)84 gsize c4_group_handle_accessed_entry_size(C4GroupHandle* handle)
85 {
86 return HANDLE_TO_GROUP(handle)->AccessedEntrySize();
87 }
88
c4_group_handle_read(C4GroupHandle * handle,gpointer buffer,gsize size)89 gboolean c4_group_handle_read(C4GroupHandle* handle, gpointer buffer, gsize size)
90 {
91 return HANDLE_TO_GROUP(handle)->Read(buffer, size);
92 }
93
c4_group_handle_is_folder(C4GroupHandle * handle)94 gboolean c4_group_handle_is_folder(C4GroupHandle* handle)
95 {
96 C4Group *group = HANDLE_TO_GROUP(handle);
97 return group->IsOpen() && !group->IsPacked();
98 }
99
100 } /* extern "C" */
101