Files
Triforce-Source/host/redact_line.h
ruckus7382sfgsgdf 4fa4f9188b Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
2026-11-25 10:21:32 -06:00

70 lines
3.4 KiB
C

/* ((Triforce) 11-24) The home folder and the user's name out of a line of the logs: the home folder, as a whole, written ~
(%USERPROFILE% on Windows), and the user's name as a folder of any path <user> (a media mount's, another drive's Users
folder). The rest of the line, the rest of each path too, stays as it is. Used by the game's log as it writes it
(host/log_redact.c) and by the bug capture's copy of the log's end (host/bug_capture.c). A line redacted again comes out
the same: ~, %USERPROFILE% and <user> are never a home folder or a name to take out. No OS dependencies. */
#ifndef HOS_REDACT_LINE_H
#define HOS_REDACT_LINE_H
#include <stddef.h>
#include <string.h>
static inline int hos_redact_sep(char c) { return c == '/' || c == '\\'; }
/* (a character a file or folder name has: a name ends at any other) */
static inline int hos_redact_name_char(char c) {
const unsigned char u = (unsigned char)c;
return (u >= '0' && u <= '9') || (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || c == '.' || c == '_' || c == '-' || u >= 0x80;
}
/* (Windows: either separator for either, in any case) */
static inline int hos_redact_matches_at(const char *s, size_t n, size_t at, const char *what, size_t wn, int windows) {
if (!wn || at + wn > n) return 0;
for (size_t i = 0; i < wn; i++) {
char a = s[at + i], b = what[i];
if (hos_redact_sep(a) && hos_redact_sep(b)) {
if (!windows && a != b) return 0;
continue;
}
if (windows) {
if (a >= 'A' && a <= 'Z') a = (char)(a + 32);
if (b >= 'A' && b <= 'Z') b = (char)(b + 32);
}
if (a != b) return 0;
}
return 1;
}
/* line (n bytes) into out (cap bytes, NUL-terminated, cut to fit) with home and user taken out. The length written. home and
user may be NULL or empty (then nothing of theirs is taken out). out needs at most n * 7 + 1 bytes: a home of 2 bytes becomes
%USERPROFILE%'s 13, a name of 1 byte <user>'s 6 */
static inline size_t hos_redact_line(char *out, size_t cap, const char *line, size_t n, const char *home, const char *user,
int windows) {
size_t hn = home ? strlen(home) : 0, un = user ? strlen(user) : 0, o = 0;
while (hn > 1 && hos_redact_sep(home[hn - 1])) hn--;
const int with_home = hn > 1;
if (!cap) return 0;
#define HOS_REDACT_OUT(s, k) do { for (size_t j_ = 0; j_ < (k) && o + 1 < cap; j_++) out[o++] = (s)[j_]; } while (0)
for (size_t i = 0; i < n;) {
/* (the home folder as a whole: not inside a longer name, not the end of another path) */
if (with_home && (i == 0 || (!hos_redact_name_char(line[i - 1]) && !hos_redact_sep(line[i - 1]))) &&
hos_redact_matches_at(line, n, i, home, hn, windows) && (i + hn >= n || !hos_redact_name_char(line[i + hn]))) {
const char *w = windows ? "%USERPROFILE%" : "~";
HOS_REDACT_OUT(w, strlen(w));
i += hn;
continue;
}
/* (the user's name as a folder of any path) */
if (un && i > 0 && hos_redact_sep(line[i - 1]) && hos_redact_matches_at(line, n, i, user, un, windows) &&
(i + un >= n || !hos_redact_name_char(line[i + un]))) {
HOS_REDACT_OUT("<user>", 6);
i += un;
continue;
}
HOS_REDACT_OUT(line + i, 1);
i++;
}
#undef HOS_REDACT_OUT
out[o] = 0;
return o;
}
#endif