dsh-gufa-code 1.3.49 → 1.3.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,498 @@
1
+ /**
2
+ * 极简 JSON 解析/序列化实现(见 json.h)。
3
+ */
4
+ #include "json.h"
5
+
6
+ #include <math.h>
7
+ #include <string.h>
8
+
9
+ #define GUFA_JSON_MAX_DEPTH 64
10
+
11
+ struct _GufaJson {
12
+ GufaJsonType type;
13
+ gboolean boolean;
14
+ double number;
15
+ char *string;
16
+ /* array: items;object: keys 与 items 一一对应 */
17
+ GPtrArray *keys;
18
+ GPtrArray *items;
19
+ };
20
+
21
+ typedef struct {
22
+ const char *cur;
23
+ const char *end;
24
+ int depth;
25
+ } GufaJsonParser;
26
+
27
+ static GQuark gufa_json_error_quark(void) {
28
+ return g_quark_from_static_string("gufa-json-error");
29
+ }
30
+
31
+ static void json_destroy(gpointer data) {
32
+ gufa_json_free((GufaJson *)data);
33
+ }
34
+
35
+ static GufaJson *json_new(GufaJsonType type) {
36
+ GufaJson *value = g_new0(GufaJson, 1);
37
+ value->type = type;
38
+ return value;
39
+ }
40
+
41
+ void gufa_json_free(GufaJson *value) {
42
+ if (value == NULL) return;
43
+ g_free(value->string);
44
+ if (value->keys != NULL) g_ptr_array_unref(value->keys);
45
+ if (value->items != NULL) g_ptr_array_unref(value->items);
46
+ g_free(value);
47
+ }
48
+
49
+ GufaJsonType gufa_json_get_type(const GufaJson *value) {
50
+ return value == NULL ? GUFA_JSON_NULL : value->type;
51
+ }
52
+
53
+ static gboolean json_error(GufaJsonParser *parser, GError **error, const char *message) {
54
+ (void)parser;
55
+ if (error != NULL && *error == NULL) {
56
+ g_set_error_literal(error, gufa_json_error_quark(), 1, message);
57
+ }
58
+ return FALSE;
59
+ }
60
+
61
+ static void skip_whitespace(GufaJsonParser *parser) {
62
+ while (parser->cur < parser->end) {
63
+ char c = *parser->cur;
64
+ if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
65
+ parser->cur++;
66
+ } else {
67
+ break;
68
+ }
69
+ }
70
+ }
71
+
72
+ static gboolean parse_value(GufaJsonParser *parser, GufaJson **out, GError **error);
73
+
74
+ static void append_utf8_codepoint(GString *out, gunichar codepoint) {
75
+ char buffer[6];
76
+ int length = g_unichar_to_utf8(codepoint, buffer);
77
+ if (length > 0) {
78
+ g_string_append_len(out, buffer, length);
79
+ }
80
+ }
81
+
82
+ static gboolean parse_hex4(const char *p, const char *end, guint *out) {
83
+ guint value = 0;
84
+ if (p + 4 > end) return FALSE;
85
+ for (int i = 0; i < 4; i++) {
86
+ char c = p[i];
87
+ value <<= 4;
88
+ if (c >= '0' && c <= '9') {
89
+ value |= (guint)(c - '0');
90
+ } else if (c >= 'a' && c <= 'f') {
91
+ value |= (guint)(c - 'a' + 10);
92
+ } else if (c >= 'A' && c <= 'F') {
93
+ value |= (guint)(c - 'A' + 10);
94
+ } else {
95
+ return FALSE;
96
+ }
97
+ }
98
+ *out = value;
99
+ return TRUE;
100
+ }
101
+
102
+ static char *parse_string_raw(GufaJsonParser *parser, GError **error) {
103
+ if (parser->cur >= parser->end || *parser->cur != '"') {
104
+ json_error(parser, error, "expected string");
105
+ return NULL;
106
+ }
107
+ parser->cur++;
108
+ GString *out = g_string_new(NULL);
109
+ gboolean closed = FALSE;
110
+ while (parser->cur < parser->end) {
111
+ unsigned char c = (unsigned char)*parser->cur++;
112
+ if (c == '"') {
113
+ closed = TRUE;
114
+ break;
115
+ }
116
+ if (c == '\\') {
117
+ if (parser->cur >= parser->end) break;
118
+ unsigned char escape = (unsigned char)*parser->cur++;
119
+ switch (escape) {
120
+ case '"': g_string_append_c(out, '"'); break;
121
+ case '\\': g_string_append_c(out, '\\'); break;
122
+ case '/': g_string_append_c(out, '/'); break;
123
+ case 'b': g_string_append_c(out, '\b'); break;
124
+ case 'f': g_string_append_c(out, '\f'); break;
125
+ case 'n': g_string_append_c(out, '\n'); break;
126
+ case 'r': g_string_append_c(out, '\r'); break;
127
+ case 't': g_string_append_c(out, '\t'); break;
128
+ case 'u': {
129
+ guint code = 0;
130
+ if (!parse_hex4(parser->cur, parser->end, &code)) {
131
+ json_error(parser, error, "bad \\u escape");
132
+ g_string_free(out, TRUE);
133
+ return NULL;
134
+ }
135
+ parser->cur += 4;
136
+ if (code >= 0xD800 && code <= 0xDBFF && parser->cur + 6 <= parser->end &&
137
+ parser->cur[0] == '\\' && parser->cur[1] == 'u') {
138
+ guint low = 0;
139
+ if (parse_hex4(parser->cur + 2, parser->end, &low) && low >= 0xDC00 && low <= 0xDFFF) {
140
+ parser->cur += 6;
141
+ code = 0x10000 + ((code - 0xD800) << 10) + (low - 0xDC00);
142
+ }
143
+ }
144
+ if (code >= 0xD800 && code <= 0xDFFF) code = 0xFFFD; /* 非法代理对 */
145
+ append_utf8_codepoint(out, (gunichar)code);
146
+ break;
147
+ }
148
+ default:
149
+ json_error(parser, error, "bad escape");
150
+ g_string_free(out, TRUE);
151
+ return NULL;
152
+ }
153
+ continue;
154
+ }
155
+ if (c < 0x20) {
156
+ json_error(parser, error, "control character in string");
157
+ g_string_free(out, TRUE);
158
+ return NULL;
159
+ }
160
+ g_string_append_c(out, (char)c);
161
+ }
162
+ if (!closed) {
163
+ json_error(parser, error, "unterminated string");
164
+ g_string_free(out, TRUE);
165
+ return NULL;
166
+ }
167
+ return g_string_free(out, FALSE);
168
+ }
169
+
170
+ static gboolean parse_number_raw(GufaJsonParser *parser, double *out) {
171
+ const char *start = parser->cur;
172
+ while (parser->cur < parser->end) {
173
+ char c = *parser->cur;
174
+ if ((c >= '0' && c <= '9') || c == '-' || c == '+' || c == '.' || c == 'e' || c == 'E') {
175
+ parser->cur++;
176
+ } else {
177
+ break;
178
+ }
179
+ }
180
+ if (parser->cur == start) return FALSE;
181
+ char *endptr = NULL;
182
+ double value = g_ascii_strtod(start, &endptr);
183
+ if (endptr != parser->cur) {
184
+ parser->cur = start;
185
+ return FALSE;
186
+ }
187
+ *out = value;
188
+ return TRUE;
189
+ }
190
+
191
+ static gboolean parse_object_raw(GufaJsonParser *parser, GufaJson **out, GError **error) {
192
+ /* parser->cur 指向 '{' */
193
+ parser->cur++;
194
+ GufaJson *object = json_new(GUFA_JSON_OBJECT);
195
+ object->keys = g_ptr_array_new_with_free_func(g_free);
196
+ object->items = g_ptr_array_new_with_free_func(json_destroy);
197
+ skip_whitespace(parser);
198
+ if (parser->cur < parser->end && *parser->cur == '}') {
199
+ parser->cur++;
200
+ *out = object;
201
+ return TRUE;
202
+ }
203
+ for (;;) {
204
+ skip_whitespace(parser);
205
+ char *key = parse_string_raw(parser, error);
206
+ if (key == NULL) {
207
+ gufa_json_free(object);
208
+ return FALSE;
209
+ }
210
+ skip_whitespace(parser);
211
+ if (parser->cur >= parser->end || *parser->cur != ':') {
212
+ g_free(key);
213
+ json_error(parser, error, "expected ':' in object");
214
+ gufa_json_free(object);
215
+ return FALSE;
216
+ }
217
+ parser->cur++;
218
+ GufaJson *value = NULL;
219
+ if (!parse_value(parser, &value, error)) {
220
+ g_free(key);
221
+ gufa_json_free(object);
222
+ return FALSE;
223
+ }
224
+ g_ptr_array_add(object->keys, key);
225
+ g_ptr_array_add(object->items, value);
226
+ skip_whitespace(parser);
227
+ if (parser->cur >= parser->end) {
228
+ json_error(parser, error, "unterminated object");
229
+ gufa_json_free(object);
230
+ return FALSE;
231
+ }
232
+ char c = *parser->cur++;
233
+ if (c == '}') break;
234
+ if (c != ',') {
235
+ json_error(parser, error, "expected ',' or '}' in object");
236
+ gufa_json_free(object);
237
+ return FALSE;
238
+ }
239
+ }
240
+ *out = object;
241
+ return TRUE;
242
+ }
243
+
244
+ static gboolean parse_array_raw(GufaJsonParser *parser, GufaJson **out, GError **error) {
245
+ parser->cur++;
246
+ GufaJson *array = json_new(GUFA_JSON_ARRAY);
247
+ array->items = g_ptr_array_new_with_free_func(json_destroy);
248
+ skip_whitespace(parser);
249
+ if (parser->cur < parser->end && *parser->cur == ']') {
250
+ parser->cur++;
251
+ *out = array;
252
+ return TRUE;
253
+ }
254
+ for (;;) {
255
+ GufaJson *value = NULL;
256
+ if (!parse_value(parser, &value, error)) {
257
+ gufa_json_free(array);
258
+ return FALSE;
259
+ }
260
+ g_ptr_array_add(array->items, value);
261
+ skip_whitespace(parser);
262
+ if (parser->cur >= parser->end) {
263
+ json_error(parser, error, "unterminated array");
264
+ gufa_json_free(array);
265
+ return FALSE;
266
+ }
267
+ char c = *parser->cur++;
268
+ if (c == ']') break;
269
+ if (c != ',') {
270
+ json_error(parser, error, "expected ',' or ']' in array");
271
+ gufa_json_free(array);
272
+ return FALSE;
273
+ }
274
+ }
275
+ *out = array;
276
+ return TRUE;
277
+ }
278
+
279
+ static gboolean parse_value(GufaJsonParser *parser, GufaJson **out, GError **error) {
280
+ if (parser->depth >= GUFA_JSON_MAX_DEPTH) {
281
+ return json_error(parser, error, "JSON nesting too deep");
282
+ }
283
+ skip_whitespace(parser);
284
+ if (parser->cur >= parser->end) {
285
+ return json_error(parser, error, "unexpected end of JSON");
286
+ }
287
+ char c = *parser->cur;
288
+ if (c == '{') {
289
+ parser->depth++;
290
+ gboolean ok = parse_object_raw(parser, out, error);
291
+ parser->depth--;
292
+ return ok;
293
+ }
294
+ if (c == '[') {
295
+ parser->depth++;
296
+ gboolean ok = parse_array_raw(parser, out, error);
297
+ parser->depth--;
298
+ return ok;
299
+ }
300
+ if (c == '"') {
301
+ char *string = parse_string_raw(parser, error);
302
+ if (string == NULL) return FALSE;
303
+ GufaJson *value = json_new(GUFA_JSON_STRING);
304
+ value->string = string;
305
+ *out = value;
306
+ return TRUE;
307
+ }
308
+ if (c == 't' && parser->end - parser->cur >= 4 && strncmp(parser->cur, "true", 4) == 0) {
309
+ parser->cur += 4;
310
+ GufaJson *value = json_new(GUFA_JSON_BOOL);
311
+ value->boolean = TRUE;
312
+ *out = value;
313
+ return TRUE;
314
+ }
315
+ if (c == 'f' && parser->end - parser->cur >= 5 && strncmp(parser->cur, "false", 5) == 0) {
316
+ parser->cur += 5;
317
+ GufaJson *value = json_new(GUFA_JSON_BOOL);
318
+ value->boolean = FALSE;
319
+ *out = value;
320
+ return TRUE;
321
+ }
322
+ if (c == 'n' && parser->end - parser->cur >= 4 && strncmp(parser->cur, "null", 4) == 0) {
323
+ parser->cur += 4;
324
+ *out = json_new(GUFA_JSON_NULL);
325
+ return TRUE;
326
+ }
327
+ double number = 0.0;
328
+ if (parse_number_raw(parser, &number)) {
329
+ GufaJson *value = json_new(GUFA_JSON_NUMBER);
330
+ value->number = number;
331
+ *out = value;
332
+ return TRUE;
333
+ }
334
+ return json_error(parser, error, "unexpected character in JSON");
335
+ }
336
+
337
+ GufaJson *gufa_json_parse(const char *text, GError **error) {
338
+ if (text == NULL) {
339
+ g_set_error_literal(error, gufa_json_error_quark(), 1, "empty JSON text");
340
+ return NULL;
341
+ }
342
+ GufaJsonParser parser;
343
+ parser.cur = text;
344
+ parser.end = text + strlen(text);
345
+ parser.depth = 0;
346
+ GufaJson *value = NULL;
347
+ if (!parse_value(&parser, &value, error)) return NULL;
348
+ skip_whitespace(&parser);
349
+ if (parser.cur != parser.end) {
350
+ gufa_json_free(value);
351
+ g_set_error_literal(error, gufa_json_error_quark(), 1, "trailing data after JSON value");
352
+ return NULL;
353
+ }
354
+ return value;
355
+ }
356
+
357
+ GufaJson *gufa_json_object_get(const GufaJson *object, const char *key) {
358
+ if (object == NULL || object->type != GUFA_JSON_OBJECT || key == NULL) return NULL;
359
+ for (guint i = 0; i < object->items->len; i++) {
360
+ const char *candidate = g_ptr_array_index(object->keys, i);
361
+ if (candidate != NULL && strcmp(candidate, key) == 0) {
362
+ return g_ptr_array_index(object->items, i);
363
+ }
364
+ }
365
+ return NULL;
366
+ }
367
+
368
+ const char *gufa_json_get_string(const GufaJson *value) {
369
+ if (value == NULL || value->type != GUFA_JSON_STRING) return NULL;
370
+ return value->string;
371
+ }
372
+
373
+ char *gufa_json_dup_string(const GufaJson *value) {
374
+ const char *string = gufa_json_get_string(value);
375
+ return string == NULL ? NULL : g_strdup(string);
376
+ }
377
+
378
+ gboolean gufa_json_get_bool(const GufaJson *value, gboolean fallback) {
379
+ if (value == NULL || value->type != GUFA_JSON_BOOL) return fallback;
380
+ return value->boolean;
381
+ }
382
+
383
+ double gufa_json_get_number(const GufaJson *value, double fallback) {
384
+ if (value == NULL || value->type != GUFA_JSON_NUMBER) return fallback;
385
+ return value->number;
386
+ }
387
+
388
+ long gufa_json_get_int64(const GufaJson *value, long fallback) {
389
+ if (value == NULL || value->type != GUFA_JSON_NUMBER) return fallback;
390
+ if (!isfinite(value->number)) return fallback;
391
+ return (long)value->number;
392
+ }
393
+
394
+ int gufa_json_array_size(const GufaJson *value) {
395
+ if (value == NULL || value->type != GUFA_JSON_ARRAY) return 0;
396
+ return (int)value->items->len;
397
+ }
398
+
399
+ GufaJson *gufa_json_array_get(const GufaJson *value, int index) {
400
+ if (value == NULL || value->type != GUFA_JSON_ARRAY) return NULL;
401
+ if (index < 0 || (guint)index >= value->items->len) return NULL;
402
+ return g_ptr_array_index(value->items, (guint)index);
403
+ }
404
+
405
+ /* ── 序列化 ─────────────────────────────────────────────────────────── */
406
+
407
+ static void append_escaped_string(GString *out, const char *text) {
408
+ g_string_append_c(out, '"');
409
+ const unsigned char *p = (const unsigned char *)text;
410
+ while (*p != '\0') {
411
+ unsigned char c = *p;
412
+ switch (c) {
413
+ case '"': g_string_append(out, "\\\""); p++; continue;
414
+ case '\\': g_string_append(out, "\\\\"); p++; continue;
415
+ case '\b': g_string_append(out, "\\b"); p++; continue;
416
+ case '\f': g_string_append(out, "\\f"); p++; continue;
417
+ case '\n': g_string_append(out, "\\n"); p++; continue;
418
+ case '\r': g_string_append(out, "\\r"); p++; continue;
419
+ case '\t': g_string_append(out, "\\t"); p++; continue;
420
+ default: break;
421
+ }
422
+ if (c < 0x20) {
423
+ g_string_append_printf(out, "\\u%04x", (unsigned int)c);
424
+ p++;
425
+ continue;
426
+ }
427
+ /* U+2028 / U+2029 在 JS 源码字符串里是行终止符,转义掉最安全(UTF-8: E2 80 A8/A9) */
428
+ if (c == 0xE2 && p[1] == 0x80 && (p[2] == 0xA8 || p[2] == 0xA9)) {
429
+ g_string_append(out, p[2] == 0xA8 ? "\\u2028" : "\\u2029");
430
+ p += 3;
431
+ continue;
432
+ }
433
+ g_string_append_c(out, (char)c);
434
+ p++;
435
+ }
436
+ g_string_append_c(out, '"');
437
+ }
438
+
439
+ static void serialize_value(GString *out, const GufaJson *value) {
440
+ if (value == NULL) {
441
+ g_string_append(out, "null");
442
+ return;
443
+ }
444
+ switch (value->type) {
445
+ case GUFA_JSON_NULL:
446
+ g_string_append(out, "null");
447
+ break;
448
+ case GUFA_JSON_BOOL:
449
+ g_string_append(out, value->boolean ? "true" : "false");
450
+ break;
451
+ case GUFA_JSON_NUMBER:
452
+ if (!isfinite(value->number)) {
453
+ g_string_append(out, "null");
454
+ } else if (value->number == floor(value->number) && fabs(value->number) < 1e15) {
455
+ g_string_append_printf(out, "%.0f", value->number);
456
+ } else {
457
+ g_string_append_printf(out, "%.17g", value->number);
458
+ }
459
+ break;
460
+ case GUFA_JSON_STRING:
461
+ append_escaped_string(out, value->string != NULL ? value->string : "");
462
+ break;
463
+ case GUFA_JSON_ARRAY:
464
+ g_string_append_c(out, '[');
465
+ for (guint i = 0; i < value->items->len; i++) {
466
+ if (i > 0) g_string_append_c(out, ',');
467
+ serialize_value(out, g_ptr_array_index(value->items, i));
468
+ }
469
+ g_string_append_c(out, ']');
470
+ break;
471
+ case GUFA_JSON_OBJECT:
472
+ g_string_append_c(out, '{');
473
+ for (guint i = 0; i < value->items->len; i++) {
474
+ if (i > 0) g_string_append_c(out, ',');
475
+ const char *key = g_ptr_array_index(value->keys, i);
476
+ append_escaped_string(out, key != NULL ? key : "");
477
+ g_string_append_c(out, ':');
478
+ serialize_value(out, g_ptr_array_index(value->items, i));
479
+ }
480
+ g_string_append_c(out, '}');
481
+ break;
482
+ default:
483
+ g_string_append(out, "null");
484
+ break;
485
+ }
486
+ }
487
+
488
+ char *gufa_json_serialize(const GufaJson *value) {
489
+ GString *out = g_string_new(NULL);
490
+ serialize_value(out, value);
491
+ return g_string_free(out, FALSE);
492
+ }
493
+
494
+ char *gufa_json_quote(const char *text) {
495
+ GString *out = g_string_new(NULL);
496
+ append_escaped_string(out, text != NULL ? text : "");
497
+ return g_string_free(out, FALSE);
498
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 极简 JSON 解析/序列化(悬浮层 helper 自用,不引入第三方依赖)
3
+ *
4
+ * 只需要处理 Host 用 JSON.stringify 生成的对象;仍然覆盖完整 JSON 语法,
5
+ * 以便容错 Host 版本差异(null / 数字 / 布尔 / 数组 / 嵌套对象)。
6
+ */
7
+ #ifndef GUFA_JSON_H
8
+ #define GUFA_JSON_H
9
+
10
+ #include <glib.h>
11
+
12
+ typedef enum {
13
+ GUFA_JSON_NULL = 0,
14
+ GUFA_JSON_BOOL,
15
+ GUFA_JSON_NUMBER,
16
+ GUFA_JSON_STRING,
17
+ GUFA_JSON_ARRAY,
18
+ GUFA_JSON_OBJECT
19
+ } GufaJsonType;
20
+
21
+ typedef struct _GufaJson GufaJson;
22
+
23
+ /** 解析一段 JSON 文本;失败返回 NULL 并设置 error。 */
24
+ GufaJson *gufa_json_parse(const char *text, GError **error);
25
+
26
+ /** 释放整棵 JSON 树(value 可以为 NULL)。 */
27
+ void gufa_json_free(GufaJson *value);
28
+
29
+ GufaJsonType gufa_json_get_type(const GufaJson *value);
30
+
31
+ /** 读取对象字段:不存在或对象类型不对时返回 NULL。 */
32
+ GufaJson *gufa_json_object_get(const GufaJson *object, const char *key);
33
+
34
+ /** 字符串字段(借用指针,生命周期同 JSON 树)。 */
35
+ const char *gufa_json_get_string(const GufaJson *value);
36
+
37
+ /** 字符串字段副本(调用方 g_free)。 */
38
+ char *gufa_json_dup_string(const GufaJson *value);
39
+
40
+ gboolean gufa_json_get_bool(const GufaJson *value, gboolean fallback);
41
+
42
+ double gufa_json_get_number(const GufaJson *value, double fallback);
43
+
44
+ long gufa_json_get_int64(const GufaJson *value, long fallback);
45
+
46
+ int gufa_json_array_size(const GufaJson *value);
47
+
48
+ GufaJson *gufa_json_array_get(const GufaJson *value, int index);
49
+
50
+ /** 紧凑序列化(用于把 payload.state 原样注入 localStorage);失败返回 NULL。 */
51
+ char *gufa_json_serialize(const GufaJson *value);
52
+
53
+ /** 把字符串转成合法的 JSON 字符串字面量(含引号),调用方 g_free。 */
54
+ char *gufa_json_quote(const char *text);
55
+
56
+ #endif /* GUFA_JSON_H */
@@ -0,0 +1,48 @@
1
+ /**
2
+ * 悬浮层诊断日志实现(见 log.h)。
3
+ */
4
+ #include "log.h"
5
+
6
+ #include <stdarg.h>
7
+ #include <stdio.h>
8
+
9
+ static char *gufa_log_file_path = NULL;
10
+
11
+ void gufa_log_init(void) {
12
+ if (gufa_log_file_path != NULL) return;
13
+ const char *override = g_getenv("GUFA_FLOAT_DEBUG_LOG");
14
+ if (override != NULL && *override != '\0') {
15
+ gufa_log_file_path = g_strdup(override);
16
+ } else {
17
+ gufa_log_file_path = g_strdup("/tmp/gufa-float-debug.log");
18
+ }
19
+ }
20
+
21
+ const char *gufa_log_path(void) {
22
+ if (gufa_log_file_path == NULL) gufa_log_init();
23
+ return gufa_log_file_path;
24
+ }
25
+
26
+ static void gufa_log_write_file(const char *timestamp, const char *message) {
27
+ const char *path = gufa_log_path();
28
+ FILE *file = fopen(path, "a");
29
+ if (file == NULL) return;
30
+ fprintf(file, "[%s] %s\n", timestamp, message);
31
+ fclose(file);
32
+ }
33
+
34
+ void gufa_log(const char *format, ...) {
35
+ va_list args;
36
+ char *message = NULL;
37
+ GDateTime *now = g_date_time_new_now_local();
38
+ char *timestamp = now != NULL ? g_date_time_format(now, "%Y-%m-%dT%H:%M:%S%z") : g_strdup("?");
39
+ va_start(args, format);
40
+ message = g_strdup_vprintf(format, args);
41
+ va_end(args);
42
+ if (message == NULL) message = g_strdup("");
43
+ g_printerr("[gufa-float][%s] %s\n", timestamp, message);
44
+ gufa_log_write_file(timestamp, message);
45
+ g_free(message);
46
+ g_free(timestamp);
47
+ if (now != NULL) g_date_time_unref(now);
48
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 悬浮层诊断日志:同时写 stderr 与 /tmp/gufa-float-debug.log(可用 GUFA_FLOAT_DEBUG_LOG 覆盖)。
3
+ * 真机验收时用户可直接把该文件发回来排查。
4
+ */
5
+ #ifndef GUFA_LOG_H
6
+ #define GUFA_LOG_H
7
+
8
+ #include <glib.h>
9
+
10
+ /** 初始化(只需要在 main 开头调用一次)。 */
11
+ void gufa_log_init(void);
12
+
13
+ /** 记录一条日志(自动加时间戳)。 */
14
+ void gufa_log(const char *format, ...) G_GNUC_PRINTF(1, 2);
15
+
16
+ /** 当前日志文件路径。 */
17
+ const char *gufa_log_path(void);
18
+
19
+ #endif /* GUFA_LOG_H */