Debian Codegraph @

src/pt2_helpers.c

raw symbols SCIP
1 // for finding memory leaks in debug mode with Visual Studio
2 #if defined _DEBUG && defined _MSC_VER
3 #include <crtdbg.h>
4 #endif
5
6 #include <SDL2/SDL.h>
7 #include <stdarg.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include <string.h>
12 #include <ctype.h> // toupper()
13 #include "pt2_structs.h"
14 #include "pt2_config.h"
15
16 void showErrorMsgBox(const char *fmt, ...)
17 {
18 char strBuf[512+1];
19 va_list args;
20
21 // format the text string
22 va_start(args, fmt);
23 vsnprintf(strBuf, sizeof (strBuf)-1, fmt, args);
24 va_end(args);
25
26 // SDL message boxes can be very buggy on Windows XP, use MessageBoxA() instead
27 #ifdef _WIN32
28 MessageBoxA(NULL, strBuf, "Error", MB_OK | MB_ICONERROR);
29 #else
30 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", strBuf, NULL);
31 #endif
32 }
33
34 void sanitizeFilenameChar(char *chr)
35 {
36 // some of these are legal on GNU/Linux and macOS, but whatever...
37 if (*chr == '\\') *chr = ' ';
38 else if (*chr == '/') *chr = ' ';
39 else if (*chr == ':') *chr = ' ';
40 else if (*chr == '*') *chr = ' ';
41 else if (*chr == '?') *chr = ' ';
42 else if (*chr == '\"') *chr = ' ';
43 else if (*chr == '<') *chr = ' ';
44 else if (*chr == '>') *chr = ' ';
45 else if (*chr == '|') *chr = ' ';
46 }
47
48 bool sampleNameIsEmpty(char *name)
49 {
50 if (name == NULL)
51 return true;
52
53 for (int32_t i = 0; i < 22; i++)
54 {
55 if (name[i] != '\0')
56 return false;
57 }
58
59 return true;
60 }
61
62 bool moduleNameIsEmpty(char *name)
63 {
64 if (name == NULL)
65 return true;
66
67 for (int32_t i = 0; i < 20; i++)
68 {
69 if (name[i] != '\0')
70 return false;
71 }
72
73 return true;
74 }
75
76 void updateWindowTitle(bool modified)
77 {
78 char editStr[32], titleTemp[256];
79
80 editStr[0] = '\0';
81 if (editor.currMode == MODE_EDIT)
82 strcpy(editStr, "[EDITING] ");
83
84 if (modified)
85 song->modified = true;
86 else
87 song->modified = false;
88
89 if (song->header.name[0] != '\0')
90 {
91 if (modified)
92 {
93 if (config.modDot)
94 sprintf(titleTemp, "ProTracker 2 clone v%s %s- \"mod.%s\" (unsaved)",
95 PROG_VER_STR, editStr, song->header.name);
96 else
97 sprintf(titleTemp, "ProTracker 2 clone v%s %s- \"%s.mod\" (unsaved)",
98 PROG_VER_STR, editStr, song->header.name);
99 }
100 else
101 {
102 if (config.modDot)
103 sprintf(titleTemp, "ProTracker 2 clone v%s %s- \"mod.%s\"",
104 PROG_VER_STR, editStr, song->header.name);
105 else
106 sprintf(titleTemp, "ProTracker 2 clone v%s %s- \"%s.mod\"",
107 PROG_VER_STR, editStr, song->header.name);
108 }
109 }
110 else
111 {
112 if (modified)
113 {
114 if (config.modDot)
115 sprintf(titleTemp, "ProTracker 2 clone v%s %s- \"mod.untitled\" (unsaved)",
116 PROG_VER_STR, editStr);
117 else
118 sprintf(titleTemp, "ProTracker 2 clone v%s %s- \"untitled.mod\" (unsaved)",
119 PROG_VER_STR, editStr);
120 }
121 else
122 {
123 if (config.modDot)
124 sprintf(titleTemp, "ProTracker 2 clone v%s %s- \"mod.untitled\"",
125 PROG_VER_STR, editStr);
126 else
127 sprintf(titleTemp, "ProTracker 2 clone v%s %s- \"untitled.mod\"",
128 PROG_VER_STR, editStr);
129 }
130 }
131
132 SDL_SetWindowTitle(video.window, titleTemp);
133 }