From b0d3f871f9e111bc2420de6367bd80fdc434fb2d Mon Sep 17 00:00:00 2001 From: mtijanic Date: Mon, 2 Apr 2018 22:12:41 +0200 Subject: [PATCH] fix floating truncation; reduce debug spew --- lib/detours/lib/detours.lib | Bin 271688 -> 271688 bytes mysql.c | 13 +++++++------ nwnxlite.c | 10 ++++++++++ nwnxlite.h | 5 +++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/detours/lib/detours.lib b/lib/detours/lib/detours.lib index dfce2649691c6d365b60541fbfac12fb1c1c21d8..2d8e1d9b96601f39f611ca0d0aa149babb22fead 100644 GIT binary patch delta 3154 zcmZWr2UJtn8_&Hj<0SzS8D&Wb2*{8SRHg`s78OMS6&x5DGDI1oC@Mn)k%A!hQEwRv z)fN>6#YmqOnN>hW>nu1>TdB0JqNS)5_5a=rw&!niPV$ZW?flODZbzrMqf=Zsk?ZK< z;xct=t?8)dIIA?(G9Bmb2_JI{{{Dj2m3bvB)^=nc26dH%=DsG#vkJ2(p3W1Xjw;NN zVvNu>6|)YVRL8u~ViAUu#sJI(Ulaf>g2}&6!zg3-gw6kUR}~C>Qw|On^gN zA|_M*bEBh-mak`wXq)b_O>Q^4cE4PxKJn^~8((CBC-|MJzX*b@# z*m0g{Z?v=wI*_RagKZsy3RhMwwaBg6t;)08>n z2r+wIb5X+jb%EP^Dx5A&HGBPQ)bHVA&WoEuGF?~LC)~N6{4O&-1H1_`vy;yC=-7MU z%@kw(x;k(7$)|;5t^35c{65Hu&+!V`u9QBtO?TL-zR%oP;~&rP_}B#5I_0~jIch2x z*%R}+Eiei?%8lLf>8OwcT#%dtI4G?Ob3^@Hpn()ZAV)uHVq7HV0wJxNfZ|f&ynhjd zCUz4%VkaUF69HZVcL}WH#t@H5K^X32eS9Sz|Tk zNQ*e~V}nvu$OpdYeKqFs{{={qq?!WgKShyLQRM*jP-v%%oQR%tfe0D#fe-SVfH4uY zRrS5affU76Q_!c;P1h$RZ3W;2=RW{uGXN$n#b6aQ&ET?F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YcukvMnqk&lg6vF}Pc&qOk zis7SHbxd16*r475$VI{y%nn&-V#Y{=MUECEw-Rkpa>YcT7Pc9F)P$g-3H_{tsnTH@ z6TQ*L1n>%Z#T$@RhefyA!{-nhnD_h_jJ&K?*E3Vw0-y1RHTf6#~mpYy(q# zg1mlJX*?Q(G#{^Yqo<@Kp)okfGY%6Im!q&`I;Ad*Q>c?tiCoZ>s1V#v#F{a9i$mn5 zU|TSl#zljvR# zSo~iy%`z*s2V={vgR#P5!PB;O-Qt@GH}7d?@Gpqwe1fWLP<9q3Vwdvc_s{e-MxdH3 zOpm?e`n4&~NqsKr&ca+oUCfl<)2Cm*Jsf!2FQM+x>HzoAM^kl;lFbH!?#_Y%3#5~c ziHai9@4YEeO;~s8ZPbYc(*x{+$LDT+DKyz>eyD75Z0>$!?5t~l#nzEjkAw6mmbFKa z)k(|Kx%R0gE-Sch%UZ35oTm@N?}uvlwYE$+3vUc*O5*p`D58ggz6Q1DI zt9_xdm@&vCG&Je1TK@srFc-Q2 diff --git a/mysql.c b/mysql.c index dc99ae1..4d35859 100644 --- a/mysql.c +++ b/mysql.c @@ -52,7 +52,7 @@ void sql_destroy_prepared_query() { int sql_prepare_query(const char *query) { LOG_INFO("SQL prepare query: %s", query); if (sql.stmt) { - LOG_INFO("Destroying previous query"); + LOG_DEBUG("Destroying previous query"); sql_destroy_prepared_query(); } @@ -64,7 +64,7 @@ int sql_prepare_query(const char *query) { if (!mysql_stmt_prepare(sql.stmt, query, strlen(query))) { sql.paramCount = mysql_stmt_param_count(sql.stmt); - LOG_INFO("Detected %d parameters.", sql.paramCount); + LOG_DEBUG("Detected %d parameters.", sql.paramCount); assert(sql.paramCount < count_of(sql.params)); return 1; } @@ -86,7 +86,7 @@ int sql_execute_prepared_query() { } if (!mysql_stmt_execute(sql.stmt)) { - LOG_INFO("Successful query"); + LOG_DEBUG("Successful query"); sql.result = mysql_stmt_result_metadata(sql.stmt); if (sql.result) { sql.columns = mysql_num_fields(sql.result); @@ -122,15 +122,16 @@ int sql_read_next_row() { } for (int i = 0; i < sql.columns; i++) { + sql.lengths[i] += 128; sql.resultBuffer[i] = realloc(sql.resultBuffer[i], sql.lengths[i] + 1); //assert(sql.resultBuffer[i]); - LOG_INFO("Column %d of %d, length %d; res: %p", i, sql.columns, sql.lengths[i], sql.resultBuffer[i]); + LOG_DEBUG("Column %d of %d, length %d; res: %p", i, sql.columns, sql.lengths[i], sql.resultBuffer[i]); sql.binds[i].buffer = sql.resultBuffer[i]; sql.binds[i].buffer_length = sql.lengths[i]; int fetched = mysql_stmt_fetch_column(sql.stmt, &sql.binds[i], i, 0); sql.resultBuffer[i][sql.lengths[i]] = 0; - LOG_INFO("fetched = %d", fetched); + LOG_DEBUG("fetched = %d", fetched); } sql.currentRow++; return 1; @@ -140,7 +141,7 @@ char *sql_read_data_in_active_row(int column) { if (!sql.stmt || column < 0 || column >= sql.columns) return ""; - LOG_INFO("Reading column %d, value %s", column, sql.resultBuffer[column]); + LOG_DEBUG("Reading column %d, value %s", column, sql.resultBuffer[column]); return sql.resultBuffer[column]; } int sql_get_affected_rows() { diff --git a/nwnxlite.c b/nwnxlite.c index fd9e9ce..1853824 100644 --- a/nwnxlite.c +++ b/nwnxlite.c @@ -8,6 +8,8 @@ __declspec(dllexport) void dummy() { } FILE *logfile; struct cfg cfg; +int loglevel = 1; + void parse_config() { FILE *f = fopen("nwnxlite.ini", "r"); if (!f) { @@ -37,6 +39,14 @@ void (__fastcall *CNWSScriptVarTable__SetString)(CNWSScriptVarTable* thisP void SQLExecDirect(char *name, char *value); char *SQLFetch(char *name); char *SQLGetData(char *name); +void SetLogLevel(char *name, char *value) { + switch (*value) { + case '1': loglevel = 1; break; + case '2': loglevel = 2; break; + case '0': loglevel - 0; break; + } +} + struct { const char *cmd; SetStringHandler handler; diff --git a/nwnxlite.h b/nwnxlite.h index 19104b4..07bb0d6 100644 --- a/nwnxlite.h +++ b/nwnxlite.h @@ -6,9 +6,10 @@ #include "string.h" extern FILE *logfile; +extern int loglevel; #define LOG_INIT(logname) (logfile = fopen(logname, "w")) -#define LOG_DEBUG(fmt, ...) (fprintf(logfile, "[DEBUG] " fmt "\n", ##__VA_ARGS__), fflush(logfile)) -#define LOG_INFO(fmt, ...) (fprintf(logfile, "[INFO] " fmt "\n", ##__VA_ARGS__), fflush(logfile)) +#define LOG_DEBUG(fmt, ...) if (loglevel >= 2) { fprintf(logfile, "[DEBUG] " fmt "\n", ##__VA_ARGS__), fflush(logfile); } else +#define LOG_INFO(fmt, ...) if (loglevel >= 1) { fprintf(logfile, "[INFO] " fmt "\n", ##__VA_ARGS__), fflush(logfile); } else #define LOG_ERROR(fmt, ...) (fprintf(logfile, "[ERROR] " fmt "\n", ##__VA_ARGS__), fflush(logfile)) #define LOG_CLOSE() (fclose(logfile))