GCC Code Coverage Report


Directory: main/
File: tools/ps1_gameid.c
Date: 2025-10-04 14:03:00
Exec Total Coverage
Lines: 0 29 0.0%
Functions: 0 3 0.0%
Branches: 0 6 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2020-2022, Thanos Siopoudis
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 #include <stdio.h>
7 #include <string.h>
8 #include "ps1_gameid.h"
9
10 static void rolfl(char *str, const char *toRemove) {
11 if (NULL == (str = strstr(str, toRemove))) {
12 // no match.
13 return;
14 }
15
16 // str points to toRemove in str now.
17 const size_t remLen = strlen(toRemove);
18 char *copyEnd;
19 char *copyFrom = str + remLen;
20 while (NULL != (copyEnd = strstr(copyFrom, toRemove))) {
21 memmove(str, copyFrom, copyEnd - copyFrom);
22 str += copyEnd - copyFrom;
23 copyFrom = copyEnd + remLen;
24 }
25 memmove(str, copyFrom, 1 + strlen(copyFrom));
26 }
27
28 static char* replace_char(char* str, char find, char replace) {
29 char *current_pos = strchr(str,find);
30 while (current_pos) {
31 *current_pos = replace;
32 current_pos = strchr(current_pos,find);
33 }
34 return str;
35 }
36
37 void ps1_gid_sanitize(char *gameID) {
38 rolfl((char *)gameID, "cdrom:");
39 rolfl((char *)gameID, "\\DSC\\");
40 rolfl((char *)gameID, "\\EXE\\");
41 rolfl((char *)gameID, "\\exe\\");
42 rolfl((char *)gameID, "\\TEKKEN3\\");
43 rolfl((char *)gameID, "\\MGS\\");
44 rolfl((char *)gameID, "/");
45 rolfl((char *)gameID, "\\");
46 rolfl((char *)gameID, ".");
47 replace_char((char *)gameID, '_', '-');
48 replace_char((char *)gameID, ';', '\0');
49 }
50
51