| 1 | #cxx . . $ `<file>/dokidoki-support/log.c`/include "log.h"cxx . . $ `<file>/dokidoki-support/log.h`/ |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | |
| 7 | #include <lauxlib.h> |
| 8 | #include <lualib.h> |
| 9 | |
| 10 | FILEcxx . . $ FILE# *filecxx . . $ file. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 11 | |
| 12 | #if defined(DOKIDOKI_LINUXcxx . . $ `<built-in>:416:9`!) || defined(DOKIDOKI_MACOSX) |
| 13 | static void open_logfilecxx . . $ open_logfile(d878ad36e69247c7).() |
| 14 | { |
| 15 | const char *suffix = "/.dokidoki.log"; |
| 16 | const char *home = getenvcxx . . $ getenv(a8b8e32347182212).("HOME"); |
| 17 | size_tcxx . . $ size_t# len = strlencxx . . $ strlen(751346f8406fd082).(suffix) + strlencxx . . $ strlen(751346f8406fd082).(home) + 1; |
| 18 | char *path = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(len * sizeof(char)); |
| 19 | strcpycxx . . $ strcpy(b7b3a83273496486).(path, home); |
| 20 | strcatcxx . . $ strcat(b7b3a83273496486).(path, suffix); |
| 21 | filecxx . . $ file. = fopencxx . . $ fopen(82ec0787cd37e0a3).(path, "w"); |
| 22 | freecxx . . $ free(5d22bdacc48458e8).(path); |
| 23 | } |
| 24 | #else |
| 25 | static void open_logfile() |
| 26 | { |
| 27 | file = fopen("dokidoki.log", "w"); |
| 28 | } |
| 29 | #endif |
| 30 | |
| 31 | void log_initcxx . . $ log_init(d4f767463ce0a6b3).(int use_logfile) |
| 32 | { |
| 33 | if(use_logfile) |
| 34 | open_logfilecxx . . $ open_logfile(d878ad36e69247c7).(); |
| 35 | |
| 36 | if(!filecxx . . $ file.) |
| 37 | filecxx . . $ file. = stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!; |
| 38 | } |
| 39 | |
| 40 | void log_messagecxx . . $ log_message(85c52e162fed56f9).(const char *message) |
| 41 | { |
| 42 | fputscxx . . $ fputs(874fa6a5e59ab9bd).(message, filecxx . . $ file.); |
| 43 | fputscxx . . $ fputs(874fa6a5e59ab9bd).("\n", filecxx . . $ file.); |
| 44 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(filecxx . . $ file.); |
| 45 | } |
| 46 | |
| 47 | void log_messagefcxx . . $ log_messagef(326aeb464d16410c).(const char *fmt, ...) |
| 48 | { |
| 49 | va_listcxx . . $ va_list# args; |
| 50 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, fmt); |
| 51 | |
| 52 | vfprintfcxx . . $ vfprintf(bded311e54d67f9c).(filecxx . . $ file., fmt, args); |
| 53 | fputscxx . . $ fputs(874fa6a5e59ab9bd).("\n", filecxx . . $ file.); |
| 54 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(filecxx . . $ file.); |
| 55 | |
| 56 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args); |
| 57 | } |
| 58 | |
| 59 | //// lua binding ////////////////////////////////////////////////////////////// |
| 60 | |
| 61 | static int log__log_messagecxx . . $ log__log_message(e4b172c3fcff213).(lua_Statecxx . . $ lua_State# *L) |
| 62 | { |
| 63 | log_messagecxx . . $ log_message(85c52e162fed56f9).(luaL_checkstringcxx . . $ `<external>/18095755238171912061/lauxlib.h:102:9`!(L, 1)); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static const luaL_Regcxx . . $ luaL_Reg# log_libcxx . . $ log_lib.[] = |
| 68 | { |
| 69 | {"log_message", log__log_messagecxx . . $ log__log_message(e4b172c3fcff213).}, |
| 70 | {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!} |
| 71 | }; |
| 72 | |
| 73 | int luaopen_logcxx . . $ luaopen_log(e4b172c3fcff213).(lua_Statecxx . . $ lua_State# *L) |
| 74 | { |
| 75 | lua_newtablecxx . . $ `<external>/15848857005865937740/lua.h:256:9`!(L); |
| 76 | luaL_registercxx . . $ luaL_register(78d27bf8f6419b9e).(L, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, log_libcxx . . $ log_lib.); |
| 77 | return 1; |
| 78 | } |