Skip to content

Commit c3cc80e

Browse files
committed
mbop: move mbop_fprintf to global namespace
References: GXH-145, GXL-427
1 parent 48c28d5 commit c3cc80e

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

tools/mbop.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ extern int cmd_parser(int, char **);
2929
extern char *g_arg_username, *g_arg_userdir;
3030
extern unsigned int g_continuous_mode, g_verbose_mode, g_command_num;
3131

32-
template <typename... Args> int mbop_fprintf(Args &&...args) {
33-
if (g_verbose_mode)
34-
fprintf(stderr, "%s [cmd %d]: ", g_storedir, g_command_num);
35-
return fprintf(std::forward<Args>(args)...);
3632
}
33+
34+
template<typename... Args> int mbop_fprintf(Args &&...args)
35+
{
36+
if (global::g_verbose_mode)
37+
fprintf(stderr, "%s [cmd %d]: ", g_storedir, global::g_command_num);
38+
return fprintf(std::forward<Args>(args)...);
3739
}
3840

3941
extern void mbop_help_cb(const struct HXoptcb *);

tools/mbop_delmsg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int main(int argc, char **argv)
5454
while (*++argv != nullptr) {
5555
eid_t eid = gi_lookup_eid_by_name(g_storedir, *argv);
5656
if (eid == 0) {
57-
global::mbop_fprintf(stderr, "Not recognized/found: \"%s\"\n", *argv);
57+
mbop_fprintf(stderr, "Not recognized/found: \"%s\"\n", *argv);
5858
return EXIT_FAILURE;
5959
}
6060
eids.push_back(eid);

tools/mbop_emptyfld.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static int generic_del(eid_t fid, const std::vector<uint64_t> &chosen)
4646
ea.pids = deconst(chosen.data());
4747
if (!exmdb_client->delete_messages(g_storedir, CP_ACP, nullptr, fid,
4848
&ea, false, &partial_complete)) {
49-
global::mbop_fprintf(stderr, "fid 0x%llx delete_messages failed\n", LLU{rop_util_get_gc_value(fid)});
49+
mbop_fprintf(stderr, "fid 0x%llx delete_messages failed\n", LLU{rop_util_get_gc_value(fid)});
5050
return EXIT_FAILURE;
5151
}
5252
return EXIT_SUCCESS;
@@ -64,7 +64,7 @@ static int select_mids_by_time(eid_t fid, unsigned int tbl_flags,
6464
RESTRICTION rst_e = {RES_AND, {deconst(&rst_d)}};
6565
if (!exmdb_client->load_content_table(g_storedir, CP_ACP, fid, nullptr,
6666
tbl_flags, &rst_e, nullptr, &table_id, &row_count)) {
67-
global::mbop_fprintf(stderr, "fid 0x%llx load_content_table failed\n", LLU{rop_util_get_gc_value(fid)});
67+
mbop_fprintf(stderr, "fid 0x%llx load_content_table failed\n", LLU{rop_util_get_gc_value(fid)});
6868
return EXIT_FAILURE;
6969
}
7070
auto cl_0 = HX::make_scope_exit([&]() { exmdb_client->unload_table(g_storedir, table_id); });
@@ -73,7 +73,7 @@ static int select_mids_by_time(eid_t fid, unsigned int tbl_flags,
7373
tarray_set rowset{};
7474
if (!exmdb_client->query_table(g_storedir, nullptr, CP_ACP, table_id,
7575
&mtaghdr, 0, row_count, &rowset)) {
76-
global::mbop_fprintf(stderr, "fid 0x%llx query_table failed\n", LLU{rop_util_get_gc_value(fid)});
76+
mbop_fprintf(stderr, "fid 0x%llx query_table failed\n", LLU{rop_util_get_gc_value(fid)});
7777
return EXIT_FAILURE;
7878
}
7979
for (const auto &row : rowset) {
@@ -119,7 +119,7 @@ static int do_hierarchy(eid_t fid, uint32_t depth)
119119
uint32_t table_id = 0, row_count = 0;
120120
if (!exmdb_client->load_hierarchy_table(g_storedir, fid,
121121
nullptr, 0, nullptr, &table_id, &row_count)) {
122-
global::mbop_fprintf(stderr, "fid 0x%llx load_content_table failed\n", LLU{rop_util_get_gc_value(fid)});
122+
mbop_fprintf(stderr, "fid 0x%llx load_content_table failed\n", LLU{rop_util_get_gc_value(fid)});
123123
return EXIT_FAILURE;
124124
}
125125
auto cl_1 = HX::make_scope_exit([=]() { exmdb_client->unload_table(g_storedir, table_id); });
@@ -128,7 +128,7 @@ static int do_hierarchy(eid_t fid, uint32_t depth)
128128
tarray_set rowset{};
129129
if (!exmdb_client->query_table(g_storedir, nullptr, CP_ACP, table_id,
130130
&ftaghdr, 0, row_count, &rowset)) {
131-
global::mbop_fprintf(stderr, "fid 0x%llx query_table failed\n", LLU{rop_util_get_gc_value(fid)});
131+
mbop_fprintf(stderr, "fid 0x%llx query_table failed\n", LLU{rop_util_get_gc_value(fid)});
132132
return EXIT_FAILURE;
133133
}
134134
exmdb_client->unload_table(g_storedir, table_id);
@@ -145,7 +145,7 @@ static int do_hierarchy(eid_t fid, uint32_t depth)
145145
static constexpr PROPTAG_ARRAY ftaghdr2 = {std::size(ftags2), deconst(ftags2)};
146146
TPROPVAL_ARRAY props{};
147147
if (!exmdb_client->get_folder_properties(g_storedir, CP_ACP, fid, &ftaghdr2, &props)) {
148-
global::mbop_fprintf(stderr, "fid 0x%llx get_folder_props failed\n", LLU{fid});
148+
mbop_fprintf(stderr, "fid 0x%llx get_folder_props failed\n", LLU{fid});
149149
return EXIT_FAILURE;
150150
}
151151
auto p1 = props.get<const uint32_t>(PR_CONTENT_COUNT);
@@ -159,12 +159,12 @@ static int do_hierarchy(eid_t fid, uint32_t depth)
159159
BOOL b_result = false;
160160
if (!exmdb_client->delete_folder(g_storedir, CP_ACP, fid,
161161
g_del_flags & DELETE_HARD_DELETE, &b_result)) {
162-
global::mbop_fprintf(stderr, "fid 0x%llx delete_folder RPC rejected/malformed\n", LLU{rop_util_get_gc_value(fid)});
162+
mbop_fprintf(stderr, "fid 0x%llx delete_folder RPC rejected/malformed\n", LLU{rop_util_get_gc_value(fid)});
163163
return EXIT_FAILURE;
164164
} else if (!b_result) {
165-
global::mbop_fprintf(stderr, "fid 0x%llx delete_folder unsuccessful (no permissions etc.)\n", LLU{rop_util_get_gc_value(fid)});
165+
mbop_fprintf(stderr, "fid 0x%llx delete_folder unsuccessful (no permissions etc.)\n", LLU{rop_util_get_gc_value(fid)});
166166
} else {
167-
global::mbop_fprintf(stderr, "Folder 0x%llx: deleted due to --delempty\n", LLU{rop_util_get_gc_value(fid)});
167+
mbop_fprintf(stderr, "Folder 0x%llx: deleted due to --delempty\n", LLU{rop_util_get_gc_value(fid)});
168168
}
169169
return EXIT_SUCCESS;
170170
}
@@ -176,26 +176,26 @@ int main(int argc, char **argv)
176176
return EXIT_PARAM;
177177
auto cl_0 = HX::make_scope_exit([=]() { HX_zvecfree(argv); });
178178
if (g_del_flags & DEL_FOLDERS && g_recurse) {
179-
global::mbop_fprintf(stderr, "Combining -R and --nuke-folders is unreasonable: when you nuke folders, you cannot recurse into them anymore.\n");
179+
mbop_fprintf(stderr, "Combining -R and --nuke-folders is unreasonable: when you nuke folders, you cannot recurse into them anymore.\n");
180180
return EXIT_FAILURE;
181181
} else if (g_delempty && !g_recurse) {
182-
global::mbop_fprintf(stderr, "--delempty requires -R\n");
182+
mbop_fprintf(stderr, "--delempty requires -R\n");
183183
return EXIT_FAILURE;
184184
}
185185
if (g_time_str != nullptr) {
186186
char *end = nullptr;
187187
auto t = HX_strtoull_sec(g_time_str, &end);
188188
if (t == ULLONG_MAX && errno == ERANGE) {
189-
global::mbop_fprintf(stderr, "Timespec \"%s\" is too damn big\n", g_time_str);
189+
mbop_fprintf(stderr, "Timespec \"%s\" is too damn big\n", g_time_str);
190190
return EXIT_FAILURE;
191191
} else if (end != nullptr && *end != '\0') {
192-
global::mbop_fprintf(stderr, "Timespec \"%s\" not fully understood (error at: \"%s\")\n",
192+
mbop_fprintf(stderr, "Timespec \"%s\" not fully understood (error at: \"%s\")\n",
193193
g_time_str, end);
194194
return EXIT_FAILURE;
195195
}
196196
g_cutoff_time = rop_util_unix_to_nttime(time(nullptr) - t);
197197
if (g_del_flags & DEL_FOLDERS) {
198-
global::mbop_fprintf(stderr, "Combining -t and --nuke-folders is unreasonable: when you delete folders, it may delete messages therein which are younger than -t.\n");
198+
mbop_fprintf(stderr, "Combining -t and --nuke-folders is unreasonable: when you delete folders, it may delete messages therein which are younger than -t.\n");
199199
return EXIT_FAILURE;
200200
}
201201
}
@@ -205,7 +205,7 @@ int main(int argc, char **argv)
205205
BOOL partial = false;
206206
eid_t eid = gi_lookup_eid_by_name(g_storedir, *argv);
207207
if (eid == 0) {
208-
global::mbop_fprintf(stderr, "Not recognized/found: \"%s\"\n", *argv);
208+
mbop_fprintf(stderr, "Not recognized/found: \"%s\"\n", *argv);
209209
return EXIT_FAILURE;
210210
}
211211
if (g_cutoff_time != 0 || g_recurse) {
@@ -220,7 +220,7 @@ int main(int argc, char **argv)
220220
auto ok = exmdb_client->empty_folder(g_storedir, CP_UTF8, nullptr,
221221
eid, g_del_flags, &partial);
222222
if (!ok) {
223-
global::mbop_fprintf(stderr, "empty_folder(%s) failed\n", *argv);
223+
mbop_fprintf(stderr, "empty_folder(%s) failed\n", *argv);
224224
ret = EXIT_FAILURE;
225225
}
226226
delcount(eid, &curr_delc, &curr_fldc);

tools/mbop_freebusy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ static int xmktime(const char *str, time_t *out)
3535
struct tm tm{};
3636
end = strptime(str, "%FT%T", &tm);
3737
if (end != nullptr && *end != '\0') {
38-
global::mbop_fprintf(stderr, "\"%s\" not understood, error at \"%s\". Required format is \"2024-01-01T00:00:00\" [always local system time] or unixtime.\n", g_start_txt, end);
38+
mbop_fprintf(stderr, "\"%s\" not understood, error at \"%s\". Required format is \"2024-01-01T00:00:00\" [always local system time] or unixtime.\n", g_start_txt, end);
3939
return -1;
4040
}
4141
tm.tm_wday = -1;
4242
*out = mktime(&tm);
4343
if (*out == -1 && tm.tm_wday == -1) {
44-
global::mbop_fprintf(stderr, "\"%s\" not understood by mktime\n", g_start_txt);
44+
mbop_fprintf(stderr, "\"%s\" not understood by mktime\n", g_start_txt);
4545
return -1;
4646
}
4747
return 0;
@@ -60,7 +60,7 @@ int main(int argc, char **argv)
6060
return EXIT_PARAM;
6161
std::vector<freebusy_event> fbout;
6262
if (!get_freebusy(g_requestor, g_storedir, start_time, end_time, fbout)) {
63-
global::mbop_fprintf(stderr, "get_freebusy call not successful\n");
63+
mbop_fprintf(stderr, "get_freebusy call not successful\n");
6464
return EXIT_FAILURE;
6565
}
6666
printf("Results (%zu rows):\n", fbout.size());

tools/mbop_locale.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ int main(int argc, char **argv)
3131
return EXIT_PARAM;
3232
auto cl_0a = HX::make_scope_exit([=]() { HX_zvecfree(argv); });
3333
if (g_language == nullptr) {
34-
global::mbop_fprintf(stderr, "You need to specify the -l option\n");
34+
mbop_fprintf(stderr, "You need to specify the -l option\n");
3535
return EXIT_PARAM;
3636
}
3737
textmaps_init();
3838
if (!mysql_adaptor_set_user_lang(g_dstuser.c_str(), g_language)) {
39-
global::mbop_fprintf(stderr, "Update of UI language rejected\n");
39+
mbop_fprintf(stderr, "Update of UI language rejected\n");
4040
return EXIT_FAILURE;
4141
}
4242

@@ -58,7 +58,7 @@ int main(int argc, char **argv)
5858
TPROPVAL_ARRAY props{};
5959
if (!exmdb_client->get_folder_properties(g_storedir,
6060
CP_ACP, folder_id, &taghdr, &props)) {
61-
global::mbop_fprintf(stderr, "get_folder_props failed\n");
61+
mbop_fprintf(stderr, "get_folder_props failed\n");
6262
return EXIT_FAILURE;
6363
}
6464
auto orig_name = props.get<const char>(PR_DISPLAY_NAME);
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
6969
PROBLEM_ARRAY probs{};
7070
if (!exmdb_client->set_folder_properties(g_storedir, CP_ACP,
7171
folder_id, &new_props, &probs)) {
72-
global::mbop_fprintf(stderr, "set_folder_props failed\n");
72+
mbop_fprintf(stderr, "set_folder_props failed\n");
7373
return EXIT_FAILURE;
7474
}
7575
}

tools/mbop_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ static int main(int argc, char **argv)
170170
else if (strcmp(argv[0], "recalc-sizes") == 0)
171171
ok = recalc_sizes(g_storedir);
172172
else {
173-
global::mbop_fprintf(stderr, "Unrecognized subcommand \"%s\"\n", argv[0]);
173+
mbop_fprintf(stderr, "Unrecognized subcommand \"%s\"\n", argv[0]);
174174
return EXIT_PARAM;
175175
}
176176
if (!ok) {
177-
global::mbop_fprintf(stderr, "%s: the operation failed\n", argv[0]);
177+
mbop_fprintf(stderr, "%s: the operation failed\n", argv[0]);
178178
return EXIT_FAILURE;
179179
}
180180
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)