1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-06-30 03:56:45 +02:00

Added sound notifications and prepared for later system notifications. Also, now using libconfig for configuration loading.

This commit is contained in:
mannol
2014-07-21 03:25:21 +02:00
43 changed files with 1200 additions and 422 deletions

View File

@ -25,6 +25,7 @@
#include <string.h>
#include <time.h>
#include <limits.h>
#include <dirent.h>
#include "toxic.h"
#include "windows.h"
@ -108,7 +109,7 @@ char *hex_string_to_bin(const char *hex_string)
}
/* Returns 1 if the string is empty, 0 otherwise */
int string_is_empty(char *string)
int string_is_empty(const char *string)
{
return string[0] == '\0';
}
@ -174,23 +175,29 @@ int valid_nick(char *nick)
void get_file_name(char *namebuf, int bufsize, const char *pathname)
{
int idx = strlen(pathname) - 1;
char *path = strdup(pathname);
char tmpname[MAX_STR_SIZE];
snprintf(tmpname, sizeof(tmpname), "%s", pathname);
if (path == NULL)
exit_toxic_err("failed in get_file_name", FATALERR_MEMORY);
while (idx >= 0 && pathname[idx] == '/')
tmpname[idx--] = '\0';
path[idx--] = '\0';
char *filename = strrchr(tmpname, '/');
char *finalname = strdup(path);
if (filename != NULL) {
if (!strlen(++filename))
filename = tmpname;
} else {
filename = tmpname;
if (finalname == NULL)
exit_toxic_err("failed in get_file_name", FATALERR_MEMORY);
const char *basenm = strrchr(path, '/');
if (basenm != NULL) {
if (basenm[1])
strcpy(finalname, &basenm[1]);
}
snprintf(namebuf, bufsize, "%s", filename);
snprintf(namebuf, bufsize, "%s", finalname);
free(finalname);
free(path);
}
/* converts str to all lowercase */
@ -210,4 +217,32 @@ int get_nick_truncate(Tox *m, char *buf, int friendnum)
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
buf[len] = '\0';
return len;
}
/* returns index of the first instance of ch in s starting at idx.
returns length of s if char not found */
int char_find(int idx, const char *s, char ch)
{
int i = idx;
for (i = idx; s[i]; ++i) {
if (s[i] == ch)
break;
}
return i;
}
/* returns index of the last instance of ch in s starting at len
returns 0 if char not found (skips 0th index) */
int char_rfind(const char *s, char ch, int len)
{
int i = 0;
for (i = len; i > 0; --i) {
if (s[i] == ch)
break;
}
return i;
}