mirror of
https://github.com/CamHenlin/MessagesForMacintosh.git
synced 2024-11-24 22:32:19 +00:00
rework strsplit and its memory management for updating chatcounts, which was seemingly problematic on a live mac. cut new release. will enable full debugging if this release does not resolve memory issues
This commit is contained in:
parent
ce77fec0fe
commit
2b3f87be58
BIN
dist/MessagesForMacintosh.dsk
vendored
BIN
dist/MessagesForMacintosh.dsk
vendored
Binary file not shown.
BIN
dist/MessagesForMacintosh.zip
vendored
BIN
dist/MessagesForMacintosh.zip
vendored
Binary file not shown.
104
nuklear_app.c
104
nuklear_app.c
@ -15,69 +15,48 @@
|
|||||||
|
|
||||||
// #define MESSAGES_FOR_MACINTOSH_DEBUGGING
|
// #define MESSAGES_FOR_MACINTOSH_DEBUGGING
|
||||||
|
|
||||||
// based on https://github.com/jwerle/strsplit.c -- cleaned up and modified to use strtokm rather than strtok
|
// based on https://github.com/mr21/strsplit.c/blob/master/strsplit.c
|
||||||
int strsplit (const char *str, char *parts[], const char *delimiter) {
|
static char** _strsplit( const char* s, const char* delim, int* nb ) {
|
||||||
|
void* data;
|
||||||
|
char* _s = ( char* )s;
|
||||||
|
const char** ptrs;
|
||||||
|
int
|
||||||
|
ptrsSize,
|
||||||
|
nbWords = 1,
|
||||||
|
sLen = strlen( s ),
|
||||||
|
delimLen = strlen( delim );
|
||||||
|
|
||||||
#ifdef DEBUG_FUNCTION_CALLS
|
while ( ( _s = strstr( _s, delim ) ) ) {
|
||||||
writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: strsplit");
|
_s += delimLen;
|
||||||
#endif
|
++nbWords;
|
||||||
|
}
|
||||||
char *pch;
|
ptrsSize = ( nbWords + 1 ) * sizeof( char* );
|
||||||
int i = 0;
|
ptrs =
|
||||||
char *copy = NULL;
|
data = malloc( ptrsSize + sLen + 1 );
|
||||||
char *tmp = NULL;
|
if ( data ) {
|
||||||
|
*ptrs =
|
||||||
copy = strdup(str);
|
_s = strcpy( ( ( char* )data ) + ptrsSize, s );
|
||||||
|
if ( nbWords > 1 ) {
|
||||||
if (! copy) {
|
while ( ( _s = strstr( _s, delim ) ) ) {
|
||||||
|
*_s = '\0';
|
||||||
goto bad;
|
_s += delimLen;
|
||||||
|
*++ptrs = _s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*++ptrs = NULL;
|
||||||
|
}
|
||||||
|
if ( nb ) {
|
||||||
|
*nb = data ? nbWords : 0;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
pch = strtokm(copy, delimiter);
|
char** strsplit( const char* s, const char* delim ) {
|
||||||
|
return _strsplit( s, delim, NULL );
|
||||||
tmp = strdup(pch);
|
|
||||||
|
|
||||||
if (!tmp) {
|
|
||||||
|
|
||||||
goto bad;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parts[i++] = tmp;
|
char** strsplit_count( const char* s, const char* delim, int* nb ) {
|
||||||
|
return _strsplit( s, delim, nb );
|
||||||
while (pch) {
|
|
||||||
|
|
||||||
pch = strtokm(NULL, delimiter);
|
|
||||||
|
|
||||||
if (NULL == pch) {
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = strdup(pch);
|
|
||||||
|
|
||||||
if (! tmp) {
|
|
||||||
|
|
||||||
goto bad;
|
|
||||||
}
|
|
||||||
|
|
||||||
parts[i++] = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(copy);
|
|
||||||
|
|
||||||
return i;
|
|
||||||
|
|
||||||
bad:
|
|
||||||
|
|
||||||
free(copy);
|
|
||||||
|
|
||||||
for (int j = 0; j < i; j++) {
|
|
||||||
|
|
||||||
free(parts[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void aFailed(char *file, int line) {
|
void aFailed(char *file, int line) {
|
||||||
@ -296,9 +275,8 @@ void getChatCounts() {
|
|||||||
|
|
||||||
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
|
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
|
||||||
int chatCount = 0;
|
int chatCount = 0;
|
||||||
char *(*chats[16])[64];
|
|
||||||
|
|
||||||
chatCount = strsplit(tempChatCountFunctionResponse, (char **)chats, ",");
|
char **chats = strsplit_count(tempChatCountFunctionResponse, ",", &chatCount);
|
||||||
|
|
||||||
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
|
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
|
||||||
|
|
||||||
@ -320,9 +298,8 @@ void getChatCounts() {
|
|||||||
|
|
||||||
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
|
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
|
||||||
int results = 0;
|
int results = 0;
|
||||||
char *(*chatUpdate[2])[64];
|
|
||||||
|
|
||||||
results = strsplit((char *)chats[chatLoopCounter], (char **)chatUpdate, ":::");
|
char **chatUpdate = strsplit_count((char *)chats[chatLoopCounter], ":::", &results);
|
||||||
|
|
||||||
if (results != 2) {
|
if (results != 2) {
|
||||||
|
|
||||||
@ -360,9 +337,8 @@ void getChatCounts() {
|
|||||||
sprintf(chatName, "%.63s", &chatFriendlyNames[i * MAX_FRIENDLY_NAME_LENGTH]);
|
sprintf(chatName, "%.63s", &chatFriendlyNames[i * MAX_FRIENDLY_NAME_LENGTH]);
|
||||||
|
|
||||||
int updateResults = 0;
|
int updateResults = 0;
|
||||||
char *(*updatePieces[2])[64];
|
|
||||||
|
|
||||||
updateResults = strsplit(chatName, (char **)updatePieces, " new) ");
|
char **updatePieces = strsplit_count(chatName, " new) ", &updateResults);
|
||||||
|
|
||||||
if (updateResults != 2) {
|
if (updateResults != 2) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user