Make sure variable is initialized always
This commit is contained in:
parent
bae85ba323
commit
1b4f88f1c5
1 changed files with 194 additions and 145 deletions
|
@ -100,7 +100,8 @@ static uae_u32 to_amiga_start_cb(TrapContext *ctx, void *ud)
|
|||
{
|
||||
if (trap_get_long(ctx, clipboard_data) != 0)
|
||||
return 0;
|
||||
if (clipboard_debug) {
|
||||
if (clipboard_debug)
|
||||
{
|
||||
debugwrite(ctx, _T("clipboard_p2a"), clipboard_data, to_amiga_size);
|
||||
}
|
||||
#if DEBUG_CLIP > 0
|
||||
|
@ -135,7 +136,8 @@ static uae_char *pctoamiga (const uae_char *txt)
|
|||
len = strlen(txt) + 1;
|
||||
txt2 = xmalloc(uae_char, len);
|
||||
j = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
uae_char c = txt[i];
|
||||
#ifdef _WIN32
|
||||
if (c == 13)
|
||||
|
@ -148,7 +150,8 @@ static uae_char *pctoamiga (const uae_char *txt)
|
|||
|
||||
static int parsecsi(const char* txt, int off, int len)
|
||||
{
|
||||
while (off < len) {
|
||||
while (off < len)
|
||||
{
|
||||
if (txt[off] >= 0x40)
|
||||
break;
|
||||
off++;
|
||||
|
@ -168,7 +171,8 @@ static TCHAR *amigatopc (const char *txt)
|
|||
int pc = 0;
|
||||
int cnt = 0;
|
||||
size_t len = strlen(txt) + 1;
|
||||
for (int i = 0; i < len; i++) {
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
uae_char c = txt[i];
|
||||
if (c == 13)
|
||||
pc = 1;
|
||||
|
@ -179,7 +183,8 @@ static TCHAR *amigatopc (const char *txt)
|
|||
return my_strdup_ansi(txt);
|
||||
char* txt2 = xcalloc(char, len + cnt);
|
||||
int j = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
uae_char c = txt[i];
|
||||
if (c == 0 && i + 1 < len)
|
||||
continue;
|
||||
|
@ -187,10 +192,13 @@ static TCHAR *amigatopc (const char *txt)
|
|||
if (c == 10)
|
||||
txt2[j++] = 13;
|
||||
#endif
|
||||
if (c == 0x9b) {
|
||||
if (c == 0x9b)
|
||||
{
|
||||
i = parsecsi(txt, i + 1, len);
|
||||
continue;
|
||||
} else if (c == 0x1b && i + 1 < len && txt[i + 1] == '[') {
|
||||
}
|
||||
if (c == 0x1b && i + 1 < len && txt[i + 1] == '[')
|
||||
{
|
||||
i = parsecsi(txt, i + 2, len);
|
||||
continue;
|
||||
}
|
||||
|
@ -233,21 +241,24 @@ static void to_iff_text(TrapContext *ctx, const TCHAR *pctxt)
|
|||
}
|
||||
|
||||
static int clipboard_put_text(const TCHAR* txt);
|
||||
|
||||
static void from_iff_text(uae_u8* addr, uae_u32 len)
|
||||
{
|
||||
uae_u8* eaddr;
|
||||
char *txt = NULL;
|
||||
char* txt = nullptr;
|
||||
int txtsize = 0;
|
||||
|
||||
eaddr = addr + len;
|
||||
if (memcmp("FTXT", addr + 8, 4))
|
||||
return;
|
||||
addr += 12;
|
||||
while (addr < eaddr) {
|
||||
while (addr < eaddr)
|
||||
{
|
||||
uae_u32 csize = (addr[4] << 24) | (addr[5] << 16) | (addr[6] << 8) | (addr[7] << 0);
|
||||
if (addr + 8 + csize > eaddr)
|
||||
break;
|
||||
if (!memcmp(addr, "CHRS", 4) && csize) {
|
||||
if (!memcmp(addr, "CHRS", 4) && csize)
|
||||
{
|
||||
int prevsize = txtsize;
|
||||
txtsize += csize;
|
||||
txt = xrealloc(char, txt, txtsize + 1);
|
||||
|
@ -260,9 +271,12 @@ static void from_iff_text(uae_u8 *addr, uae_u32 len)
|
|||
else if (csize >= 1 && addr[-1] == 0x0d && addr[0] == 0x0a)
|
||||
addr++;
|
||||
}
|
||||
if (txt == NULL) {
|
||||
if (txt == nullptr)
|
||||
{
|
||||
clipboard_put_text(_T(""));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR* pctxt = amigatopc(txt);
|
||||
clipboard_put_text(pctxt);
|
||||
xfree(pctxt);
|
||||
|
@ -738,7 +752,8 @@ static void from_iff(TrapContext *ctx, uaecptr data, uae_u32 len)
|
|||
|
||||
if (clipboard_debug)
|
||||
debugwrite(ctx, _T("clipboard_a2p"), data, len);
|
||||
if (!memcmp ("FORM", buf, 4)) {
|
||||
if (!memcmp("FORM", buf, 4))
|
||||
{
|
||||
if (!memcmp("FTXT", buf + 8, 4))
|
||||
from_iff_text(buf, len);
|
||||
#ifdef AMIBERRY
|
||||
|
@ -765,11 +780,12 @@ static void clipboard_read(TrapContext *ctx, HWND hwnd, bool keyboardinject)
|
|||
#ifdef AMIBERRY
|
||||
write_log("clipboard clip_disabled=%d hwnd=%d to_amiga=%d "
|
||||
"heartbeat=%d\n",
|
||||
clip_disabled, hwnd, to_amiga != NULL, filesys_heartbeat());
|
||||
clip_disabled, hwnd, to_amiga != nullptr, filesys_heartbeat());
|
||||
#endif
|
||||
if (clip_disabled || !hwnd)
|
||||
return;
|
||||
if (to_amiga) {
|
||||
if (to_amiga)
|
||||
{
|
||||
#if DEBUG_CLIP > 0
|
||||
write_log (_T("clipboard: read windows clipboard but ignored because previous clip transfer still active\n"));
|
||||
#endif
|
||||
|
@ -787,13 +803,17 @@ static void clipboard_read(TrapContext *ctx, HWND hwnd, bool keyboardinject)
|
|||
return;
|
||||
#endif
|
||||
#ifdef AMIBERRY
|
||||
char *lptstr;
|
||||
char* lptstr = nullptr;
|
||||
SDL_mutexP(clipboard_from_host_mutex);
|
||||
if (clipboard_from_host_changed) {
|
||||
if (clipboard_from_host_text) {
|
||||
if (clipboard_from_host_changed)
|
||||
{
|
||||
if (clipboard_from_host_text)
|
||||
{
|
||||
lptstr = strdup(clipboard_from_host_text);
|
||||
} else {
|
||||
lptstr = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
lptstr = nullptr;
|
||||
}
|
||||
// lptstr = strdup(
|
||||
// clipboard_from_host_text ? clipboard_from_host_text : "");
|
||||
|
@ -810,21 +830,27 @@ static void clipboard_read(TrapContext *ctx, HWND hwnd, bool keyboardinject)
|
|||
bmp = TRUE;
|
||||
}
|
||||
#endif
|
||||
if (text) {
|
||||
if (text)
|
||||
{
|
||||
#ifdef AMIBERRY
|
||||
if (true) {
|
||||
if constexpr (true)
|
||||
{
|
||||
#else
|
||||
hglb = GetClipboardData (CF_UNICODETEXT);
|
||||
if (hglb != NULL) {
|
||||
TCHAR *lptstr = (TCHAR*)GlobalLock (hglb);
|
||||
#endif
|
||||
if (lptstr != NULL) {
|
||||
if (lptstr != nullptr)
|
||||
{
|
||||
#if DEBUG_CLIP > 0
|
||||
write_log (_T("clipboard: CF_UNICODETEXT '%s'\n"), lptstr);
|
||||
#endif
|
||||
if (keyboardinject) {
|
||||
if (keyboardinject)
|
||||
{
|
||||
to_keyboard(lptstr);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
to_iff_text(ctx, lptstr);
|
||||
}
|
||||
#ifdef AMIBERRY
|
||||
|
@ -834,7 +860,9 @@ static void clipboard_read(TrapContext *ctx, HWND hwnd, bool keyboardinject)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
} else if (bmp) {
|
||||
}
|
||||
else if (bmp)
|
||||
{
|
||||
#ifdef AMIBERRY
|
||||
write_log(_T("[CLIPBOARD] Bitmap clipboard sharing not implemented\n"));
|
||||
#else
|
||||
|
@ -855,7 +883,7 @@ static void clipboard_read(TrapContext *ctx, HWND hwnd, bool keyboardinject)
|
|||
|
||||
static void clipboard_free_delayed(void)
|
||||
{
|
||||
if (clipboard_delayed_data == 0)
|
||||
if (clipboard_delayed_data == nullptr)
|
||||
return;
|
||||
if (clipboard_delayed_size < 0)
|
||||
xfree(clipboard_delayed_data);
|
||||
|
@ -864,7 +892,7 @@ static void clipboard_free_delayed (void)
|
|||
else
|
||||
DeleteObject (clipboard_delayed_data);
|
||||
#endif
|
||||
clipboard_delayed_data = 0;
|
||||
clipboard_delayed_data = nullptr;
|
||||
clipboard_delayed_size = 0;
|
||||
}
|
||||
|
||||
|
@ -879,11 +907,12 @@ void clipboard_changed (HWND hwnd)
|
|||
return;
|
||||
if (clipopen)
|
||||
return;
|
||||
if (!clipactive) {
|
||||
if (!clipactive)
|
||||
{
|
||||
clipboard_change = 1;
|
||||
return;
|
||||
}
|
||||
clipboard_read(NULL, hwnd, false);
|
||||
clipboard_read(nullptr, hwnd, false);
|
||||
}
|
||||
|
||||
#ifdef AMIBERRY
|
||||
|
@ -911,9 +940,10 @@ static int clipboard_put_text_real (const TCHAR *txt)
|
|||
{
|
||||
#ifdef AMIBERRY
|
||||
SDL_mutexP(clipboard_to_host_mutex);
|
||||
if (clipboard_to_host_text != NULL) {
|
||||
if (clipboard_to_host_text != nullptr)
|
||||
{
|
||||
free(clipboard_to_host_text);
|
||||
clipboard_to_host_text = NULL;
|
||||
clipboard_to_host_text = nullptr;
|
||||
}
|
||||
clipboard_to_host_text = strdup(txt);
|
||||
SDL_mutexV(clipboard_to_host_mutex);
|
||||
|
@ -999,7 +1029,8 @@ uae_u32 amiga_clipboard_proc_start(TrapContext *ctx)
|
|||
|
||||
void amiga_clipboard_got_data(TrapContext* ctx, uaecptr data, uae_u32 size, uae_u32 actual)
|
||||
{
|
||||
if (!initialized) {
|
||||
if (!initialized)
|
||||
{
|
||||
write_log(_T("clipboard: got_data() before initialized!?\n"));
|
||||
return;
|
||||
}
|
||||
|
@ -1018,24 +1049,27 @@ int amiga_clipboard_want_data(TrapContext *ctx)
|
|||
|
||||
addr = trap_get_long(ctx, clipboard_data + 4);
|
||||
size = trap_get_long(ctx, clipboard_data);
|
||||
if (!initialized) {
|
||||
if (!initialized)
|
||||
{
|
||||
write_log(_T("clipboard: want_data() before initialized!? (%08x %08x %d)\n"), clipboard_data, addr, size);
|
||||
to_amiga = NULL;
|
||||
to_amiga = nullptr;
|
||||
return 0;
|
||||
}
|
||||
if (size != to_amiga_size) {
|
||||
if (size != to_amiga_size)
|
||||
{
|
||||
write_log(_T("clipboard: size %d <> %d mismatch!?\n"), size, to_amiga_size);
|
||||
to_amiga = NULL;
|
||||
to_amiga = nullptr;
|
||||
return 0;
|
||||
}
|
||||
if (addr && size) {
|
||||
if (addr && size)
|
||||
{
|
||||
trap_put_bytes(ctx, to_amiga, addr, size);
|
||||
}
|
||||
xfree(to_amiga);
|
||||
#if DEBUG_CLIP > 0
|
||||
write_log (_T("clipboard: ->amiga, %08x, %08x %d (%d) bytes\n"), clipboard_data, addr, size, to_amiga_size);
|
||||
#endif
|
||||
to_amiga = NULL;
|
||||
to_amiga = nullptr;
|
||||
to_amiga_size = 0;
|
||||
return 1;
|
||||
}
|
||||
|
@ -1045,17 +1079,22 @@ void clipboard_active(HWND hwnd, int active)
|
|||
clipactive = active;
|
||||
if (!initialized || !hwnd)
|
||||
return;
|
||||
if (clipactive && clipboard_change) {
|
||||
clipboard_read(NULL, hwnd, false);
|
||||
if (clipactive && clipboard_change)
|
||||
{
|
||||
clipboard_read(nullptr, hwnd, false);
|
||||
}
|
||||
if (!clipactive && clipboard_delayed_data) {
|
||||
if (clipboard_delayed_size < 0) {
|
||||
clipboard_put_text_real ((TCHAR*)clipboard_delayed_data);
|
||||
if (!clipactive && clipboard_delayed_data)
|
||||
{
|
||||
if (clipboard_delayed_size < 0)
|
||||
{
|
||||
clipboard_put_text_real(static_cast<TCHAR*>(clipboard_delayed_data));
|
||||
xfree(clipboard_delayed_data);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
//clipboard_put_bmp_real ((HBITMAP)clipboard_delayed_data);
|
||||
}
|
||||
clipboard_delayed_data = NULL;
|
||||
clipboard_delayed_data = nullptr;
|
||||
clipboard_delayed_size = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1063,7 +1102,8 @@ void clipboard_active(HWND hwnd, int active)
|
|||
static uae_u32 clipboard_vsync_cb(TrapContext* ctx, void* ud)
|
||||
{
|
||||
uaecptr task = trap_get_long(ctx, clipboard_data + 8);
|
||||
if (task && native2amiga_isfree()) {
|
||||
if (task && native2amiga_isfree())
|
||||
{
|
||||
uae_Signal(task, 1 << 13);
|
||||
#if DEBUG_CLIP > 0
|
||||
write_log(_T("clipboard: signal %08x\n"), clipboard_data);
|
||||
|
@ -1079,22 +1119,25 @@ void clipboard_vsync(void)
|
|||
if (!clipboard_data)
|
||||
return;
|
||||
|
||||
if (signaling) {
|
||||
if (signaling)
|
||||
{
|
||||
vdelay--;
|
||||
if (vdelay > 0)
|
||||
return;
|
||||
|
||||
trap_callback(clipboard_vsync_cb, NULL);
|
||||
trap_callback(clipboard_vsync_cb, nullptr);
|
||||
vdelay = 50;
|
||||
}
|
||||
|
||||
if (vdelay2 > 0) {
|
||||
if (vdelay2 > 0)
|
||||
{
|
||||
vdelay2--;
|
||||
//write_log(_T("vdelay2 = %d\n"), vdelay2);
|
||||
}
|
||||
|
||||
if (to_amiga_phase == 1 && vdelay2 <= 0) {
|
||||
trap_callback(to_amiga_start_cb, NULL);
|
||||
if (to_amiga_phase == 1 && vdelay2 <= 0)
|
||||
{
|
||||
trap_callback(to_amiga_start_cb, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1107,7 +1150,7 @@ void clipboard_reset(void)
|
|||
signaling = 0;
|
||||
initialized = 0;
|
||||
xfree(to_amiga);
|
||||
to_amiga = NULL;
|
||||
to_amiga = nullptr;
|
||||
to_amiga_size = 0;
|
||||
to_amiga_phase = 0;
|
||||
clip_disabled = false;
|
||||
|
@ -1120,7 +1163,7 @@ void clipboard_reset(void)
|
|||
#ifdef AMIBERRY
|
||||
void clipboard_init(void)
|
||||
{
|
||||
chwnd = (HWND) 1; // fake window handle
|
||||
chwnd = static_cast<HWND>(1); // fake window handle
|
||||
write_log(_T("clipboard_init\n"));
|
||||
clipboard_from_host_mutex = SDL_CreateMutex();
|
||||
clipboard_from_host_text = strdup("");
|
||||
|
@ -1141,7 +1184,7 @@ void target_paste_to_keyboard(void)
|
|||
#ifdef AMIBERRY
|
||||
write_log("target_paste_to_keyboard (clipboard)\n");
|
||||
#endif
|
||||
clipboard_read(NULL, chwnd, true);
|
||||
clipboard_read(nullptr, chwnd, true);
|
||||
}
|
||||
|
||||
// force 2 second delay before accepting new data
|
||||
|
@ -1158,8 +1201,9 @@ char *uae_clipboard_get_text()
|
|||
{
|
||||
SDL_mutexP(clipboard_to_host_mutex);
|
||||
char* text = clipboard_to_host_text;
|
||||
if (text) {
|
||||
clipboard_to_host_text = NULL;
|
||||
if (text)
|
||||
{
|
||||
clipboard_to_host_text = nullptr;
|
||||
}
|
||||
SDL_mutexV(clipboard_to_host_mutex);
|
||||
return text;
|
||||
|
@ -1167,27 +1211,34 @@ char *uae_clipboard_get_text()
|
|||
|
||||
void uae_clipboard_free_text(char* text)
|
||||
{
|
||||
if (text) {
|
||||
if (text)
|
||||
{
|
||||
free(clipboard_to_host_text);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
write_log("WARNING: uae_clipboard_free_text called with NULL pointer\n");
|
||||
}
|
||||
}
|
||||
|
||||
void uae_clipboard_put_text(const char* text)
|
||||
{
|
||||
if (!clipboard_from_host_text) {
|
||||
if (!clipboard_from_host_text)
|
||||
{
|
||||
// clipboard_init not called yet
|
||||
return;
|
||||
}
|
||||
if (!text) {
|
||||
if (!text)
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
if (strcmp(clipboard_from_host_text, text) == 0) {
|
||||
if (strcmp(clipboard_from_host_text, text) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SDL_mutexP(clipboard_from_host_mutex);
|
||||
if (clipboard_from_host_text) {
|
||||
if (clipboard_from_host_text)
|
||||
{
|
||||
free(clipboard_from_host_text);
|
||||
}
|
||||
clipboard_from_host_text = strdup(text);
|
||||
|
@ -1215,5 +1266,3 @@ void uae_clipboard_put_text(const char *text)
|
|||
}
|
||||
|
||||
#endif // AMIBERRY
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue