Apply coding style

Regards https://github.com/profanity-im/profanity/issues/1396
This commit is contained in:
Michael Vetter
2020-07-07 09:43:28 +02:00
parent 66f9a6b721
commit 9b55f2dec0
214 changed files with 19572 additions and 17582 deletions

View File

@@ -33,31 +33,31 @@
*
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <glib.h>
#include "common.h"
#include "log.h"
#include "config/account.h"
#include "log.h"
#include "xmpp/jid.h"
#include "xmpp/resource.h"
ProfAccount*
account_new(const gchar *const name, const gchar *const jid,
const gchar *const password, const gchar *eval_password, gboolean enabled, const gchar *const server,
int port, const gchar *const resource, const gchar *const last_presence,
const gchar *const login_presence, int priority_online, int priority_chat,
int priority_away, int priority_xa, int priority_dnd,
const gchar *const muc_service, const gchar *const muc_nick,
const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic,
GList *otr_always, const gchar *const omemo_policy, GList *omemo_enabled,
GList *omemo_disabled, const gchar *const pgp_keyid, const char *const startscript,
const char *const theme, gchar *tls_policy, gchar *auth_policy)
account_new(const gchar* const name, const gchar* const jid,
const gchar* const password, const gchar* eval_password, gboolean enabled, const gchar* const server,
int port, const gchar* const resource, const gchar* const last_presence,
const gchar* const login_presence, int priority_online, int priority_chat,
int priority_away, int priority_xa, int priority_dnd,
const gchar* const muc_service, const gchar* const muc_nick,
const gchar* const otr_policy, GList* otr_manual, GList* otr_opportunistic,
GList* otr_always, const gchar* const omemo_policy, GList* omemo_enabled,
GList* omemo_disabled, const gchar* const pgp_keyid, const char* const startscript,
const char* const theme, gchar* tls_policy, gchar* auth_policy)
{
ProfAccount *new_account = malloc(sizeof(ProfAccount));
ProfAccount* new_account = malloc(sizeof(ProfAccount));
memset(new_account, 0, sizeof(ProfAccount));
new_account->name = strdup(name);
@@ -125,7 +125,7 @@ account_new(const gchar *const name, const gchar *const jid,
}
if (muc_nick == NULL) {
Jid *jidp = jid_create(new_account->jid);
Jid* jidp = jid_create(new_account->jid);
new_account->muc_nick = strdup(jidp->domainpart);
jid_destroy(jidp);
} else {
@@ -185,7 +185,7 @@ account_new(const gchar *const name, const gchar *const jid,
}
char*
account_create_connect_jid(ProfAccount *account)
account_create_connect_jid(ProfAccount* account)
{
if (account->resource) {
return create_fulljid(account->jid, account->resource);
@@ -195,15 +195,15 @@ account_create_connect_jid(ProfAccount *account)
}
gboolean
account_eval_password(ProfAccount *account)
account_eval_password(ProfAccount* account)
{
assert(account != NULL);
assert(account->eval_password != NULL);
gchar **output = NULL;
gchar **error = NULL;
gchar** output = NULL;
gchar** error = NULL;
gchar *argv[] = {"sh", "-c", account->eval_password, NULL};
gchar* argv[] = { "sh", "-c", account->eval_password, NULL };
if (!call_external(argv, &output, &error)) {
return FALSE;
}
@@ -228,7 +228,7 @@ account_eval_password(ProfAccount *account)
}
void
account_free(ProfAccount *account)
account_free(ProfAccount* account)
{
if (account == NULL) {
return;
@@ -259,24 +259,28 @@ account_free(ProfAccount *account)
free(account);
}
void account_set_server(ProfAccount *account, const char *server)
void
account_set_server(ProfAccount* account, const char* server)
{
free(account->server);
account->server = strdup(server);
}
void account_set_port(ProfAccount *account, int port)
void
account_set_port(ProfAccount* account, int port)
{
account->port = port;
}
void account_set_tls_policy(ProfAccount *account, const char *tls_policy)
void
account_set_tls_policy(ProfAccount* account, const char* tls_policy)
{
free(account->tls_policy);
account->tls_policy = strdup(tls_policy);
}
void account_set_auth_policy(ProfAccount *account, const char *auth_policy)
void
account_set_auth_policy(ProfAccount* account, const char* auth_policy)
{
free(account->auth_policy);
account->auth_policy = strdup(auth_policy);

View File

@@ -38,54 +38,55 @@
#include "common.h"
typedef struct prof_account_t {
gchar *name;
gchar *jid;
gchar *password;
gchar *eval_password;
gchar *resource;
gchar *server;
typedef struct prof_account_t
{
gchar* name;
gchar* jid;
gchar* password;
gchar* eval_password;
gchar* resource;
gchar* server;
int port;
gchar *last_presence;
gchar *login_presence;
gchar* last_presence;
gchar* login_presence;
gint priority_online;
gint priority_chat;
gint priority_away;
gint priority_xa;
gint priority_dnd;
gchar *muc_service;
gchar *muc_nick;
gchar* muc_service;
gchar* muc_nick;
gboolean enabled;
gchar *otr_policy;
GList *otr_manual;
GList *otr_opportunistic;
GList *otr_always;
gchar *omemo_policy;
GList *omemo_enabled;
GList *omemo_disabled;
gchar *pgp_keyid;
gchar *startscript;
gchar *theme;
gchar *tls_policy;
gchar *auth_policy;
gchar* otr_policy;
GList* otr_manual;
GList* otr_opportunistic;
GList* otr_always;
gchar* omemo_policy;
GList* omemo_enabled;
GList* omemo_disabled;
gchar* pgp_keyid;
gchar* startscript;
gchar* theme;
gchar* tls_policy;
gchar* auth_policy;
} ProfAccount;
ProfAccount* account_new(const gchar *const name, const gchar *const jid,
const gchar *const passord, const gchar *eval_password, gboolean enabled, const gchar *const server,
int port, const gchar *const resource, const gchar *const last_presence,
const gchar *const login_presence, int priority_online, int priority_chat,
int priority_away, int priority_xa, int priority_dnd,
const gchar *const muc_service, const gchar *const muc_nick,
const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic,
GList *otr_always, const gchar *const omemo_policy, GList *omemo_enabled,
GList *omemo_disabled, const gchar *const pgp_keyid, const char *const startscript,
const char *const theme, gchar *tls_policy, gchar *auth_policy);
char* account_create_connect_jid(ProfAccount *account);
gboolean account_eval_password(ProfAccount *account);
void account_free(ProfAccount *account);
void account_set_server(ProfAccount *account, const char *server);
void account_set_port(ProfAccount *account, int port);
void account_set_tls_policy(ProfAccount *account, const char *tls_policy);
void account_set_auth_policy(ProfAccount *account, const char *auth_policy);
ProfAccount* account_new(const gchar* const name, const gchar* const jid,
const gchar* const passord, const gchar* eval_password, gboolean enabled, const gchar* const server,
int port, const gchar* const resource, const gchar* const last_presence,
const gchar* const login_presence, int priority_online, int priority_chat,
int priority_away, int priority_xa, int priority_dnd,
const gchar* const muc_service, const gchar* const muc_nick,
const gchar* const otr_policy, GList* otr_manual, GList* otr_opportunistic,
GList* otr_always, const gchar* const omemo_policy, GList* omemo_enabled,
GList* omemo_disabled, const gchar* const pgp_keyid, const char* const startscript,
const char* const theme, gchar* tls_policy, gchar* auth_policy);
char* account_create_connect_jid(ProfAccount* account);
gboolean account_eval_password(ProfAccount* account);
void account_free(ProfAccount* account);
void account_set_server(ProfAccount* account, const char* server);
void account_set_port(ProfAccount* account, int port);
void account_set_tls_policy(ProfAccount* account, const char* tls_policy);
void account_set_auth_policy(ProfAccount* account, const char* auth_policy);
#endif

View File

@@ -42,16 +42,16 @@
#include "accounts.h"
#include "common.h"
#include "log.h"
#include "config/files.h"
#include "config/account.h"
#include "config/conflists.h"
#include "config/files.h"
#include "log.h"
#include "tools/autocomplete.h"
#include "xmpp/xmpp.h"
#include "xmpp/jid.h"
#include "xmpp/xmpp.h"
static char *accounts_loc;
static GKeyFile *accounts;
static char* accounts_loc;
static GKeyFile* accounts;
static Autocomplete all_ac;
static Autocomplete enabled_ac;
@@ -75,7 +75,7 @@ accounts_load(void)
// create the logins searchable list for autocompletion
gsize naccounts;
gchar **account_names = g_key_file_get_groups(accounts, &naccounts);
gchar** account_names = g_key_file_get_groups(accounts, &naccounts);
gsize i;
for (i = 0; i < naccounts; i++) {
@@ -97,13 +97,13 @@ accounts_close(void)
}
char*
accounts_find_enabled(const char *const prefix, gboolean previous, void *context)
accounts_find_enabled(const char* const prefix, gboolean previous, void* context)
{
return autocomplete_complete(enabled_ac, prefix, TRUE, previous);
}
char*
accounts_find_all(const char *const prefix, gboolean previous, void *context)
accounts_find_all(const char* const prefix, gboolean previous, void* context)
{
return autocomplete_complete(all_ac, prefix, TRUE, previous);
}
@@ -121,12 +121,12 @@ accounts_reset_enabled_search(void)
}
void
accounts_add(const char *account_name, const char *altdomain, const int port, const char *const tls_policy, const char *const auth_policy)
accounts_add(const char* account_name, const char* altdomain, const int port, const char* const tls_policy, const char* const auth_policy)
{
// set account name and resource
const char *barejid = account_name;
char *resource = jid_random_resource();
Jid *jid = jid_create(account_name);
const char* barejid = account_name;
char* resource = jid_random_resource();
Jid* jid = jid_create(account_name);
if (jid) {
barejid = jid->barejid;
if (jid->resourcepart) {
@@ -156,7 +156,7 @@ accounts_add(const char *account_name, const char *altdomain, const int port, co
g_key_file_set_string(accounts, account_name, "auth.policy", auth_policy);
}
Jid *jidp = jid_create(barejid);
Jid* jidp = jid_create(barejid);
if (jidp->localpart == NULL) {
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
@@ -183,7 +183,7 @@ accounts_add(const char *account_name, const char *altdomain, const int port, co
}
int
accounts_remove(const char *account_name)
accounts_remove(const char* account_name)
{
int r = g_key_file_remove_group(accounts, account_name, NULL);
_save_accounts();
@@ -199,12 +199,12 @@ accounts_get_list(void)
}
ProfAccount*
accounts_get_account(const char *const name)
accounts_get_account(const char* const name)
{
if (!g_key_file_has_group(accounts, name)) {
return NULL;
} else {
gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);
gchar* jid = g_key_file_get_string(accounts, name, "jid", NULL);
// fix accounts that have no jid property by setting to name
if (jid == NULL) {
@@ -212,16 +212,16 @@ accounts_get_account(const char *const name)
_save_accounts();
}
gchar *password = g_key_file_get_string(accounts, name, "password", NULL);
gchar *eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL);
gchar* password = g_key_file_get_string(accounts, name, "password", NULL);
gchar* eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL);
gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
gchar* server = g_key_file_get_string(accounts, name, "server", NULL);
gchar* resource = g_key_file_get_string(accounts, name, "resource", NULL);
int port = g_key_file_get_integer(accounts, name, "port", NULL);
gchar *last_presence = g_key_file_get_string(accounts, name, "presence.last", NULL);
gchar *login_presence = g_key_file_get_string(accounts, name, "presence.login", NULL);
gchar* last_presence = g_key_file_get_string(accounts, name, "presence.last", NULL);
gchar* login_presence = g_key_file_get_string(accounts, name, "presence.login", NULL);
int priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL);
int priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL);
@@ -229,7 +229,7 @@ accounts_get_account(const char *const name)
int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL);
int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL);
gchar *muc_service = NULL;
gchar* muc_service = NULL;
if (g_key_file_has_key(accounts, name, "muc.service", NULL)) {
muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
} else {
@@ -241,16 +241,16 @@ accounts_get_account(const char *const name)
}
}
}
gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);
gchar* muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);
gchar *otr_policy = NULL;
gchar* otr_policy = NULL;
if (g_key_file_has_key(accounts, name, "otr.policy", NULL)) {
otr_policy = g_key_file_get_string(accounts, name, "otr.policy", NULL);
}
gsize length;
GList *otr_manual = NULL;
gchar **manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
GList* otr_manual = NULL;
gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
if (manual) {
int i = 0;
for (i = 0; i < length; i++) {
@@ -259,8 +259,8 @@ accounts_get_account(const char *const name)
g_strfreev(manual);
}
GList *otr_opportunistic = NULL;
gchar **opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
GList* otr_opportunistic = NULL;
gchar** opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
if (opportunistic) {
int i = 0;
for (i = 0; i < length; i++) {
@@ -269,8 +269,8 @@ accounts_get_account(const char *const name)
g_strfreev(opportunistic);
}
GList *otr_always = NULL;
gchar **always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
GList* otr_always = NULL;
gchar** always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
if (always) {
int i = 0;
for (i = 0; i < length; i++) {
@@ -279,13 +279,13 @@ accounts_get_account(const char *const name)
g_strfreev(always);
}
gchar *omemo_policy = NULL;
gchar* omemo_policy = NULL;
if (g_key_file_has_key(accounts, name, "omemo.policy", NULL)) {
omemo_policy = g_key_file_get_string(accounts, name, "omemo.policy", NULL);
}
GList *omemo_enabled = NULL;
gchar **enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
GList* omemo_enabled = NULL;
gchar** enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
if (enabled_list) {
int i = 0;
for (i = 0; i < length; i++) {
@@ -294,8 +294,8 @@ accounts_get_account(const char *const name)
g_strfreev(enabled_list);
}
GList *omemo_disabled = NULL;
gchar **disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
GList* omemo_disabled = NULL;
gchar** disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
if (disabled_list) {
int i = 0;
for (i = 0; i < length; i++) {
@@ -304,40 +304,36 @@ accounts_get_account(const char *const name)
g_strfreev(disabled_list);
}
gchar *pgp_keyid = NULL;
gchar* pgp_keyid = NULL;
if (g_key_file_has_key(accounts, name, "pgp.keyid", NULL)) {
pgp_keyid = g_key_file_get_string(accounts, name, "pgp.keyid", NULL);
}
gchar *startscript = NULL;
gchar* startscript = NULL;
if (g_key_file_has_key(accounts, name, "script.start", NULL)) {
startscript = g_key_file_get_string(accounts, name, "script.start", NULL);
}
gchar *theme = NULL;
gchar* theme = NULL;
if (g_key_file_has_key(accounts, name, "theme", NULL)) {
theme = g_key_file_get_string(accounts, name, "theme", NULL);
}
gchar *tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL);
if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) &&
(g_strcmp0(tls_policy, "allow") != 0) &&
(g_strcmp0(tls_policy, "trust") != 0) &&
(g_strcmp0(tls_policy, "disable") != 0) &&
(g_strcmp0(tls_policy, "legacy") != 0))) {
gchar* tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL);
if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) && (g_strcmp0(tls_policy, "allow") != 0) && (g_strcmp0(tls_policy, "trust") != 0) && (g_strcmp0(tls_policy, "disable") != 0) && (g_strcmp0(tls_policy, "legacy") != 0))) {
g_free(tls_policy);
tls_policy = NULL;
}
gchar *auth_policy = g_key_file_get_string(accounts, name, "auth.policy", NULL);
gchar* auth_policy = g_key_file_get_string(accounts, name, "auth.policy", NULL);
ProfAccount *new_account = account_new(name, jid, password, eval_password, enabled,
server, port, resource, last_presence, login_presence,
priority_online, priority_chat, priority_away, priority_xa,
priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
otr_opportunistic, otr_always, omemo_policy, omemo_enabled,
omemo_disabled, pgp_keyid, startscript, theme, tls_policy,
auth_policy);
ProfAccount* new_account = account_new(name, jid, password, eval_password, enabled,
server, port, resource, last_presence, login_presence,
priority_online, priority_chat, priority_away, priority_xa,
priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
otr_opportunistic, otr_always, omemo_policy, omemo_enabled,
omemo_disabled, pgp_keyid, startscript, theme, tls_policy,
auth_policy);
g_free(jid);
g_free(password);
@@ -361,7 +357,7 @@ accounts_get_account(const char *const name)
}
gboolean
accounts_enable(const char *const name)
accounts_enable(const char* const name)
{
if (g_key_file_has_group(accounts, name)) {
g_key_file_set_boolean(accounts, name, "enabled", TRUE);
@@ -374,7 +370,7 @@ accounts_enable(const char *const name)
}
gboolean
accounts_disable(const char *const name)
accounts_disable(const char* const name)
{
if (g_key_file_has_group(accounts, name)) {
g_key_file_set_boolean(accounts, name, "enabled", FALSE);
@@ -387,7 +383,7 @@ accounts_disable(const char *const name)
}
gboolean
accounts_rename(const char *const account_name, const char *const new_name)
accounts_rename(const char* const account_name, const char* const new_name)
{
if (g_key_file_has_group(accounts, new_name)) {
return FALSE;
@@ -398,7 +394,7 @@ accounts_rename(const char *const account_name, const char *const new_name)
}
// treat all properties as strings for copy
gchar *string_keys[] = {
gchar* string_keys[] = {
"enabled",
"jid",
"server",
@@ -431,7 +427,7 @@ accounts_rename(const char *const account_name, const char *const new_name)
int i;
for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
char* value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
if (value) {
g_key_file_set_string(accounts, new_name, string_keys[i], value);
g_free(value);
@@ -452,16 +448,15 @@ accounts_rename(const char *const account_name, const char *const new_name)
}
gboolean
accounts_account_exists(const char *const account_name)
accounts_account_exists(const char* const account_name)
{
return g_key_file_has_group(accounts, account_name);
}
void
accounts_set_jid(const char *const account_name, const char *const value)
accounts_set_jid(const char* const account_name, const char* const value)
{
Jid *jid = jid_create(value);
Jid* jid = jid_create(value);
if (jid) {
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "jid", jid->barejid);
@@ -483,7 +478,7 @@ accounts_set_jid(const char *const account_name, const char *const value)
}
void
accounts_set_server(const char *const account_name, const char *const value)
accounts_set_server(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "server", value);
@@ -492,7 +487,7 @@ accounts_set_server(const char *const account_name, const char *const value)
}
void
accounts_set_port(const char *const account_name, const int value)
accounts_set_port(const char* const account_name, const int value)
{
if (value != 0) {
g_key_file_set_integer(accounts, account_name, "port", value);
@@ -501,7 +496,7 @@ accounts_set_port(const char *const account_name, const int value)
}
void
accounts_set_resource(const char *const account_name, const char *const value)
accounts_set_resource(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "resource", value);
@@ -510,7 +505,7 @@ accounts_set_resource(const char *const account_name, const char *const value)
}
void
accounts_set_password(const char *const account_name, const char *const value)
accounts_set_password(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "password", value);
@@ -519,7 +514,7 @@ accounts_set_password(const char *const account_name, const char *const value)
}
void
accounts_set_eval_password(const char *const account_name, const char *const value)
accounts_set_eval_password(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "eval_password", value);
@@ -528,7 +523,7 @@ accounts_set_eval_password(const char *const account_name, const char *const val
}
void
accounts_set_pgp_keyid(const char *const account_name, const char *const value)
accounts_set_pgp_keyid(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "pgp.keyid", value);
@@ -537,7 +532,7 @@ accounts_set_pgp_keyid(const char *const account_name, const char *const value)
}
void
accounts_set_script_start(const char *const account_name, const char *const value)
accounts_set_script_start(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "script.start", value);
@@ -546,7 +541,7 @@ accounts_set_script_start(const char *const account_name, const char *const valu
}
void
accounts_set_theme(const char *const account_name, const char *const value)
accounts_set_theme(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "theme", value);
@@ -555,7 +550,7 @@ accounts_set_theme(const char *const account_name, const char *const value)
}
void
accounts_clear_password(const char *const account_name)
accounts_clear_password(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "password", NULL);
@@ -564,7 +559,7 @@ accounts_clear_password(const char *const account_name)
}
void
accounts_clear_eval_password(const char *const account_name)
accounts_clear_eval_password(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "eval_password", NULL);
@@ -573,7 +568,7 @@ accounts_clear_eval_password(const char *const account_name)
}
void
accounts_clear_server(const char *const account_name)
accounts_clear_server(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "server", NULL);
@@ -582,7 +577,7 @@ accounts_clear_server(const char *const account_name)
}
void
accounts_clear_port(const char *const account_name)
accounts_clear_port(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "port", NULL);
@@ -591,7 +586,7 @@ accounts_clear_port(const char *const account_name)
}
void
accounts_clear_pgp_keyid(const char *const account_name)
accounts_clear_pgp_keyid(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "pgp.keyid", NULL);
@@ -600,7 +595,7 @@ accounts_clear_pgp_keyid(const char *const account_name)
}
void
accounts_clear_script_start(const char *const account_name)
accounts_clear_script_start(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "script.start", NULL);
@@ -609,7 +604,7 @@ accounts_clear_script_start(const char *const account_name)
}
void
accounts_clear_theme(const char *const account_name)
accounts_clear_theme(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "theme", NULL);
@@ -618,7 +613,7 @@ accounts_clear_theme(const char *const account_name)
}
void
accounts_clear_muc(const char *const account_name)
accounts_clear_muc(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "muc.service", NULL);
@@ -627,7 +622,7 @@ accounts_clear_muc(const char *const account_name)
}
void
accounts_clear_resource(const char *const account_name)
accounts_clear_resource(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "resource", NULL);
@@ -636,7 +631,7 @@ accounts_clear_resource(const char *const account_name)
}
void
accounts_clear_otr(const char *const account_name)
accounts_clear_otr(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "otr.policy", NULL);
@@ -645,10 +640,10 @@ accounts_clear_otr(const char *const account_name)
}
void
accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy)
accounts_add_otr_policy(const char* const account_name, const char* const contact_jid, const char* const policy)
{
if (accounts_account_exists(account_name)) {
GString *key = g_string_new("otr.");
GString* key = g_string_new("otr.");
g_string_append(key, policy);
conf_string_list_add(accounts, account_name, key->str, contact_jid);
g_string_free(key, TRUE);
@@ -672,7 +667,7 @@ accounts_add_otr_policy(const char *const account_name, const char *const contac
}
void
accounts_add_omemo_state(const char *const account_name, const char *const contact_jid, gboolean enabled)
accounts_add_omemo_state(const char* const account_name, const char* const contact_jid, gboolean enabled)
{
if (accounts_account_exists(account_name)) {
if (enabled) {
@@ -688,7 +683,7 @@ accounts_add_omemo_state(const char *const account_name, const char *const conta
}
void
accounts_clear_omemo_state(const char *const account_name, const char *const contact_jid)
accounts_clear_omemo_state(const char* const account_name, const char* const contact_jid)
{
if (accounts_account_exists(account_name)) {
conf_string_list_remove(accounts, account_name, "omemo.enabled", contact_jid);
@@ -698,7 +693,7 @@ accounts_clear_omemo_state(const char *const account_name, const char *const con
}
void
accounts_set_muc_service(const char *const account_name, const char *const value)
accounts_set_muc_service(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "muc.service", value);
@@ -707,7 +702,7 @@ accounts_set_muc_service(const char *const account_name, const char *const value
}
void
accounts_set_muc_nick(const char *const account_name, const char *const value)
accounts_set_muc_nick(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "muc.nick", value);
@@ -716,7 +711,7 @@ accounts_set_muc_nick(const char *const account_name, const char *const value)
}
void
accounts_set_otr_policy(const char *const account_name, const char *const value)
accounts_set_otr_policy(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "otr.policy", value);
@@ -725,7 +720,7 @@ accounts_set_otr_policy(const char *const account_name, const char *const value)
}
void
accounts_set_omemo_policy(const char *const account_name, const char *const value)
accounts_set_omemo_policy(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "omemo.policy", value);
@@ -734,7 +729,7 @@ accounts_set_omemo_policy(const char *const account_name, const char *const valu
}
void
accounts_set_tls_policy(const char *const account_name, const char *const value)
accounts_set_tls_policy(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "tls.policy", value);
@@ -743,7 +738,7 @@ accounts_set_tls_policy(const char *const account_name, const char *const value)
}
void
accounts_set_auth_policy(const char *const account_name, const char *const value)
accounts_set_auth_policy(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "auth.policy", value);
@@ -752,7 +747,7 @@ accounts_set_auth_policy(const char *const account_name, const char *const value
}
void
accounts_set_priority_online(const char *const account_name, const gint value)
accounts_set_priority_online(const char* const account_name, const gint value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_integer(accounts, account_name, "priority.online", value);
@@ -761,7 +756,7 @@ accounts_set_priority_online(const char *const account_name, const gint value)
}
void
accounts_set_priority_chat(const char *const account_name, const gint value)
accounts_set_priority_chat(const char* const account_name, const gint value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_integer(accounts, account_name, "priority.chat", value);
@@ -770,7 +765,7 @@ accounts_set_priority_chat(const char *const account_name, const gint value)
}
void
accounts_set_priority_away(const char *const account_name, const gint value)
accounts_set_priority_away(const char* const account_name, const gint value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_integer(accounts, account_name, "priority.away", value);
@@ -779,7 +774,7 @@ accounts_set_priority_away(const char *const account_name, const gint value)
}
void
accounts_set_priority_xa(const char *const account_name, const gint value)
accounts_set_priority_xa(const char* const account_name, const gint value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_integer(accounts, account_name, "priority.xa", value);
@@ -788,7 +783,7 @@ accounts_set_priority_xa(const char *const account_name, const gint value)
}
void
accounts_set_priority_dnd(const char *const account_name, const gint value)
accounts_set_priority_dnd(const char* const account_name, const gint value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_integer(accounts, account_name, "priority.dnd", value);
@@ -797,7 +792,7 @@ accounts_set_priority_dnd(const char *const account_name, const gint value)
}
void
accounts_set_priority_all(const char *const account_name, const gint value)
accounts_set_priority_all(const char* const account_name, const gint value)
{
if (accounts_account_exists(account_name)) {
accounts_set_priority_online(account_name, value);
@@ -810,28 +805,27 @@ accounts_set_priority_all(const char *const account_name, const gint value)
}
gint
accounts_get_priority_for_presence_type(const char *const account_name,
resource_presence_t presence_type)
accounts_get_priority_for_presence_type(const char* const account_name,
resource_presence_t presence_type)
{
gint result;
switch (presence_type)
{
case (RESOURCE_ONLINE):
result = g_key_file_get_integer(accounts, account_name, "priority.online", NULL);
break;
case (RESOURCE_CHAT):
result = g_key_file_get_integer(accounts, account_name, "priority.chat", NULL);
break;
case (RESOURCE_AWAY):
result = g_key_file_get_integer(accounts, account_name, "priority.away", NULL);
break;
case (RESOURCE_XA):
result = g_key_file_get_integer(accounts, account_name, "priority.xa", NULL);
break;
default:
result = g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
break;
switch (presence_type) {
case (RESOURCE_ONLINE):
result = g_key_file_get_integer(accounts, account_name, "priority.online", NULL);
break;
case (RESOURCE_CHAT):
result = g_key_file_get_integer(accounts, account_name, "priority.chat", NULL);
break;
case (RESOURCE_AWAY):
result = g_key_file_get_integer(accounts, account_name, "priority.away", NULL);
break;
case (RESOURCE_XA):
result = g_key_file_get_integer(accounts, account_name, "priority.xa", NULL);
break;
default:
result = g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
break;
}
if (result < JABBER_PRIORITY_MIN || result > JABBER_PRIORITY_MAX)
@@ -841,7 +835,7 @@ accounts_get_priority_for_presence_type(const char *const account_name,
}
void
accounts_set_last_presence(const char *const account_name, const char *const value)
accounts_set_last_presence(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "presence.last", value);
@@ -850,7 +844,7 @@ accounts_set_last_presence(const char *const account_name, const char *const val
}
void
accounts_set_last_status(const char *const account_name, const char *const value)
accounts_set_last_status(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
if (value) {
@@ -863,16 +857,16 @@ accounts_set_last_status(const char *const account_name, const char *const value
}
void
accounts_set_last_activity(const char *const account_name)
accounts_set_last_activity(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
GDateTime *nowdt = g_date_time_new_now_utc();
GDateTime* nowdt = g_date_time_new_now_utc();
GTimeVal nowtv;
gboolean res = g_date_time_to_timeval(nowdt, &nowtv);
g_date_time_unref(nowdt);
if (res) {
char *timestr = g_time_val_to_iso8601(&nowtv);
char* timestr = g_time_val_to_iso8601(&nowtv);
g_key_file_set_string(accounts, account_name, "last.activity", timestr);
free(timestr);
_save_accounts();
@@ -881,7 +875,7 @@ accounts_set_last_activity(const char *const account_name)
}
char*
accounts_get_last_activity(const char *const account_name)
accounts_get_last_activity(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
return g_key_file_get_string(accounts, account_name, "last.activity", NULL);
@@ -891,7 +885,7 @@ accounts_get_last_activity(const char *const account_name)
}
void
accounts_set_login_presence(const char *const account_name, const char *const value)
accounts_set_login_presence(const char* const account_name, const char* const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "presence.login", value);
@@ -900,10 +894,10 @@ accounts_set_login_presence(const char *const account_name, const char *const va
}
resource_presence_t
accounts_get_last_presence(const char *const account_name)
accounts_get_last_presence(const char* const account_name)
{
resource_presence_t result;
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
gchar* setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
if (setting == NULL || (strcmp(setting, "online") == 0)) {
result = RESOURCE_ONLINE;
@@ -917,7 +911,7 @@ accounts_get_last_presence(const char *const account_name)
result = RESOURCE_DND;
} else {
log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'",
account_name, setting);
account_name, setting);
result = RESOURCE_ONLINE;
}
@@ -928,16 +922,16 @@ accounts_get_last_presence(const char *const account_name)
}
char*
accounts_get_last_status(const char *const account_name)
accounts_get_last_status(const char* const account_name)
{
return g_key_file_get_string(accounts, account_name, "presence.laststatus", NULL);
}
resource_presence_t
accounts_get_login_presence(const char *const account_name)
accounts_get_login_presence(const char* const account_name)
{
resource_presence_t result;
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
gchar* setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
if (setting == NULL || (strcmp(setting, "online") == 0)) {
result = RESOURCE_ONLINE;
@@ -953,7 +947,7 @@ accounts_get_login_presence(const char *const account_name)
result = accounts_get_last_presence(account_name);
} else {
log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'",
account_name, setting);
account_name, setting);
result = RESOURCE_ONLINE;
}
@@ -967,10 +961,10 @@ static void
_save_accounts(void)
{
gsize g_data_size;
gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL);
gchar* g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL);
gchar *base = g_path_get_dirname(accounts_loc);
gchar *true_loc = get_file_or_linked(accounts_loc, base);
gchar* base = g_path_get_dirname(accounts_loc);
gchar* true_loc = get_file_or_linked(accounts_loc, base);
g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL);
g_chmod(accounts_loc, S_IRUSR | S_IWUSR);

View File

@@ -44,61 +44,61 @@
void accounts_load(void);
void accounts_close(void);
char* accounts_find_all(const char *const prefix, gboolean previous, void *context);
char* accounts_find_enabled(const char *const prefix, gboolean previous, void *context);
char* accounts_find_all(const char* const prefix, gboolean previous, void* context);
char* accounts_find_enabled(const char* const prefix, gboolean previous, void* context);
void accounts_reset_all_search(void);
void accounts_reset_enabled_search(void);
void accounts_add(const char *jid, const char *altdomain, const int port, const char *const tls_policy, const char *const auth_policy);
int accounts_remove(const char *jid);
void accounts_add(const char* jid, const char* altdomain, const int port, const char* const tls_policy, const char* const auth_policy);
int accounts_remove(const char* jid);
gchar** accounts_get_list(void);
ProfAccount* accounts_get_account(const char *const name);
gboolean accounts_enable(const char *const name);
gboolean accounts_disable(const char *const name);
gboolean accounts_rename(const char *const account_name,
const char *const new_name);
gboolean accounts_account_exists(const char *const account_name);
void accounts_set_jid(const char *const account_name, const char *const value);
void accounts_set_server(const char *const account_name, const char *const value);
void accounts_set_port(const char *const account_name, const int value);
void accounts_set_resource(const char *const account_name, const char *const value);
void accounts_set_password(const char *const account_name, const char *const value);
void accounts_set_eval_password(const char *const account_name, const char *const value);
void accounts_set_muc_service(const char *const account_name, const char *const value);
void accounts_set_muc_nick(const char *const account_name, const char *const value);
void accounts_set_otr_policy(const char *const account_name, const char *const value);
void accounts_set_tls_policy(const char *const account_name, const char *const value);
void accounts_set_auth_policy(const char *const account_name, const char *const value);
void accounts_set_last_presence(const char *const account_name, const char *const value);
void accounts_set_last_status(const char *const account_name, const char *const value);
void accounts_set_last_activity(const char *const account_name);
char* accounts_get_last_activity(const char *const account_name);
void accounts_set_login_presence(const char *const account_name, const char *const value);
resource_presence_t accounts_get_login_presence(const char *const account_name);
char* accounts_get_last_status(const char *const account_name);
resource_presence_t accounts_get_last_presence(const char *const account_name);
void accounts_set_priority_online(const char *const account_name, const gint value);
void accounts_set_priority_chat(const char *const account_name, const gint value);
void accounts_set_priority_away(const char *const account_name, const gint value);
void accounts_set_priority_xa(const char *const account_name, const gint value);
void accounts_set_priority_dnd(const char *const account_name, const gint value);
void accounts_set_priority_all(const char *const account_name, const gint value);
gint accounts_get_priority_for_presence_type(const char *const account_name,
resource_presence_t presence_type);
void accounts_set_pgp_keyid(const char *const account_name, const char *const value);
void accounts_set_script_start(const char *const account_name, const char *const value);
void accounts_set_theme(const char *const account_name, const char *const value);
void accounts_clear_password(const char *const account_name);
void accounts_clear_eval_password(const char *const account_name);
void accounts_clear_server(const char *const account_name);
void accounts_clear_port(const char *const account_name);
void accounts_clear_otr(const char *const account_name);
void accounts_clear_pgp_keyid(const char *const account_name);
void accounts_clear_script_start(const char *const account_name);
void accounts_clear_theme(const char *const account_name);
void accounts_clear_muc(const char *const account_name);
void accounts_clear_resource(const char *const account_name);
void accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy);
void accounts_add_omemo_state(const char *const account_name, const char *const contact_jid, gboolean enabled);
void accounts_clear_omemo_state(const char *const account_name, const char *const contact_jid);
ProfAccount* accounts_get_account(const char* const name);
gboolean accounts_enable(const char* const name);
gboolean accounts_disable(const char* const name);
gboolean accounts_rename(const char* const account_name,
const char* const new_name);
gboolean accounts_account_exists(const char* const account_name);
void accounts_set_jid(const char* const account_name, const char* const value);
void accounts_set_server(const char* const account_name, const char* const value);
void accounts_set_port(const char* const account_name, const int value);
void accounts_set_resource(const char* const account_name, const char* const value);
void accounts_set_password(const char* const account_name, const char* const value);
void accounts_set_eval_password(const char* const account_name, const char* const value);
void accounts_set_muc_service(const char* const account_name, const char* const value);
void accounts_set_muc_nick(const char* const account_name, const char* const value);
void accounts_set_otr_policy(const char* const account_name, const char* const value);
void accounts_set_tls_policy(const char* const account_name, const char* const value);
void accounts_set_auth_policy(const char* const account_name, const char* const value);
void accounts_set_last_presence(const char* const account_name, const char* const value);
void accounts_set_last_status(const char* const account_name, const char* const value);
void accounts_set_last_activity(const char* const account_name);
char* accounts_get_last_activity(const char* const account_name);
void accounts_set_login_presence(const char* const account_name, const char* const value);
resource_presence_t accounts_get_login_presence(const char* const account_name);
char* accounts_get_last_status(const char* const account_name);
resource_presence_t accounts_get_last_presence(const char* const account_name);
void accounts_set_priority_online(const char* const account_name, const gint value);
void accounts_set_priority_chat(const char* const account_name, const gint value);
void accounts_set_priority_away(const char* const account_name, const gint value);
void accounts_set_priority_xa(const char* const account_name, const gint value);
void accounts_set_priority_dnd(const char* const account_name, const gint value);
void accounts_set_priority_all(const char* const account_name, const gint value);
gint accounts_get_priority_for_presence_type(const char* const account_name,
resource_presence_t presence_type);
void accounts_set_pgp_keyid(const char* const account_name, const char* const value);
void accounts_set_script_start(const char* const account_name, const char* const value);
void accounts_set_theme(const char* const account_name, const char* const value);
void accounts_clear_password(const char* const account_name);
void accounts_clear_eval_password(const char* const account_name);
void accounts_clear_server(const char* const account_name);
void accounts_clear_port(const char* const account_name);
void accounts_clear_otr(const char* const account_name);
void accounts_clear_pgp_keyid(const char* const account_name);
void accounts_clear_script_start(const char* const account_name);
void accounts_clear_theme(const char* const account_name);
void accounts_clear_muc(const char* const account_name);
void accounts_clear_resource(const char* const account_name);
void accounts_add_otr_policy(const char* const account_name, const char* const contact_jid, const char* const policy);
void accounts_add_omemo_state(const char* const account_name, const char* const contact_jid, gboolean enabled);
void accounts_clear_omemo_state(const char* const account_name, const char* const contact_jid);
#endif

View File

@@ -36,11 +36,11 @@
#include "config.h"
#include <glib.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <glib.h>
#ifdef HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h>
@@ -52,13 +52,15 @@
#include "config/theme.h"
#include "log.h"
static
struct color_pair_cache
static struct color_pair_cache
{
struct { int16_t fg, bg; } *pairs;
struct
{
int16_t fg, bg;
} * pairs;
int size;
int capacity;
} cache = {0};
} cache = { 0 };
/*
* xterm default 256 colors
@@ -66,279 +68,281 @@ struct color_pair_cache
*/
const struct color_def color_names[COLOR_NAME_SIZE] = {
[0] = { 0, 0, 0, "black" },
[1] = { 0, 100, 25, "red" },
[2] = { 120, 100, 25, "green" },
[3] = { 60, 100, 25, "yellow" },
[4] = { 240, 100, 25, "blue" },
[5] = { 300, 100, 25, "magenta" },
[6] = { 180, 100, 25, "cyan" },
[7] = { 0, 0, 75, "white" },
[8] = { 0, 0, 50, "lightblack" },
[9] = { 0, 100, 50, "lightred" },
[10] = { 120, 100, 50, "lightgreen" },
[11] = { 60, 100, 50, "lightyellow" },
[12] = { 240, 100, 50, "lightblue" },
[13] = { 300, 100, 50, "lightmagenta" },
[14] = { 180, 100, 50, "lightcyan" },
[15] = { 0, 0, 100, "lightwhite" },
[16] = { 0, 0, 0, "grey0" },
[17] = { 240, 100, 18, "navyblue" },
[18] = { 240, 100, 26, "darkblue" },
[19] = { 240, 100, 34, "blue3" },
[20] = { 240, 100, 42, "blue3" },
[21] = { 240, 100, 50, "blue1" },
[22] = { 120, 100, 18, "darkgreen" },
[23] = { 180, 100, 18, "deepskyblue4" },
[24] = { 97, 100, 26, "deepskyblue4" },
[25] = { 7, 100, 34, "deepskyblue4" },
[26] = { 13, 100, 42, "dodgerblue3" },
[27] = { 17, 100, 50, "dodgerblue2" },
[28] = { 120, 100, 26, "green4" },
[29] = { 62, 100, 26, "springgreen4" },
[30] = { 180, 100, 26, "turquoise4" },
[31] = { 93, 100, 34, "deepskyblue3" },
[32] = { 2, 100, 42, "deepskyblue3" },
[33] = { 8, 100, 50, "dodgerblue1" },
[34] = { 120, 100, 34, "green3" },
[35] = { 52, 100, 34, "springgreen3" },
[36] = { 66, 100, 34, "darkcyan" },
[37] = { 180, 100, 34, "lightseagreen" },
[38] = { 91, 100, 42, "deepskyblue2" },
[39] = { 98, 100, 50, "deepskyblue1" },
[40] = { 120, 100, 42, "green3" },
[41] = { 46, 100, 42, "springgreen3" },
[42] = { 57, 100, 42, "springgreen2" },
[43] = { 68, 100, 42, "cyan3" },
[44] = { 180, 100, 42, "darkturquoise" },
[45] = { 89, 100, 50, "turquoise2" },
[46] = { 120, 100, 50, "green1" },
[47] = { 42, 100, 50, "springgreen2" },
[48] = { 51, 100, 50, "springgreen1" },
[49] = { 61, 100, 50, "mediumspringgreen" },
[50] = { 70, 100, 50, "cyan2" },
[51] = { 180, 100, 50, "cyan1" },
[52] = { 0, 100, 18, "darkred" },
[53] = { 300, 100, 18, "deeppink4" },
[54] = { 82, 100, 26, "purple4" },
[55] = { 72, 100, 34, "purple4" },
[56] = { 66, 100, 42, "purple3" },
[57] = { 62, 100, 50, "blueviolet" },
[58] = { 60, 100, 18, "orange4" },
[59] = { 0, 0, 37, "grey37" },
[60] = { 240, 17, 45, "mediumpurple4" },
[61] = { 240, 33, 52, "slateblue3" },
[62] = { 240, 60, 60, "slateblue3" },
[63] = { 240, 100, 68, "royalblue1" },
[64] = { 7, 100, 26, "chartreuse4" },
[65] = { 120, 17, 45, "darkseagreen4" },
[66] = { 180, 17, 45, "paleturquoise4" },
[67] = { 210, 33, 52, "steelblue" },
[68] = { 220, 60, 60, "steelblue3" },
[69] = { 225, 100, 68, "cornflowerblue" },
[70] = { 7, 100, 34, "chartreuse3" },
[71] = { 120, 33, 52, "darkseagreen4" },
[72] = { 150, 33, 52, "cadetblue" },
[73] = { 180, 33, 52, "cadetblue" },
[74] = { 200, 60, 60, "skyblue3" },
[75] = { 210, 100, 68, "steelblue1" },
[76] = { 3, 100, 42, "chartreuse3" },
[77] = { 120, 60, 60, "palegreen3" },
[78] = { 140, 60, 60, "seagreen3" },
[79] = { 160, 60, 60, "aquamarine3" },
[80] = { 180, 60, 60, "mediumturquoise" },
[81] = { 195, 100, 68, "steelblue1" },
[82] = { 7, 100, 50, "chartreuse2" },
[83] = { 120, 100, 68, "seagreen2" },
[84] = { 135, 100, 68, "seagreen1" },
[85] = { 150, 100, 68, "seagreen1" },
[86] = { 165, 100, 68, "aquamarine1" },
[87] = { 180, 100, 68, "darkslategray2" },
[88] = { 0, 100, 26, "darkred" },
[89] = { 17, 100, 26, "deeppink4" },
[90] = { 300, 100, 26, "darkmagenta" },
[91] = { 86, 100, 34, "darkmagenta" },
[92] = { 77, 100, 42, "darkviolet" },
[93] = { 71, 100, 50, "purple" },
[94] = { 2, 100, 26, "orange4" },
[95] = { 0, 17, 45, "lightpink4" },
[96] = { 300, 17, 45, "plum4" },
[97] = { 270, 33, 52, "mediumpurple3" },
[98] = { 260, 60, 60, "mediumpurple3" },
[99] = { 255, 100, 68, "slateblue1" },
[100] = { 60, 100, 26, "yellow4" },
[101] = { 60, 17, 45, "wheat4" },
[102] = { 0, 0, 52, "grey53" },
[103] = { 240, 20, 60, "lightslategrey" },
[104] = { 240, 50, 68, "mediumpurple" },
[105] = { 240, 100, 76, "lightslateblue" },
[106] = { 3, 100, 34, "yellow4" },
[107] = { 90, 33, 52, "darkolivegreen3" },
[108] = { 120, 20, 60, "darkseagreen" },
[109] = { 180, 20, 60, "lightskyblue3" },
[110] = { 210, 50, 68, "lightskyblue3" },
[111] = { 220, 100, 76, "skyblue2" },
[112] = { 2, 100, 42, "chartreuse2" },
[113] = { 100, 60, 60, "darkolivegreen3" },
[114] = { 120, 50, 68, "palegreen3" },
[115] = { 150, 50, 68, "darkseagreen3" },
[116] = { 180, 50, 68, "darkslategray3" },
[117] = { 200, 100, 76, "skyblue1" },
[118] = { 8, 100, 50, "chartreuse1" },
[119] = { 105, 100, 68, "lightgreen" },
[120] = { 120, 100, 76, "lightgreen" },
[121] = { 140, 100, 76, "palegreen1" },
[122] = { 160, 100, 76, "aquamarine1" },
[123] = { 180, 100, 76, "darkslategray1" },
[124] = { 0, 100, 34, "red3" },
[125] = { 27, 100, 34, "deeppink4" },
[126] = { 13, 100, 34, "mediumvioletred" },
[127] = { 300, 100, 34, "magenta3" },
[128] = { 88, 100, 42, "darkviolet" },
[129] = { 81, 100, 50, "purple" },
[130] = { 2, 100, 34, "darkorange3" },
[131] = { 0, 33, 52, "indianred" },
[132] = { 330, 33, 52, "hotpink3" },
[133] = { 300, 33, 52, "mediumorchid3" },
[134] = { 280, 60, 60, "mediumorchid" },
[135] = { 270, 100, 68, "mediumpurple2" },
[136] = { 6, 100, 34, "darkgoldenrod" },
[137] = { 30, 33, 52, "lightsalmon3" },
[138] = { 0, 20, 60, "rosybrown" },
[139] = { 300, 20, 60, "grey63" },
[140] = { 270, 50, 68, "mediumpurple2" },
[141] = { 260, 100, 76, "mediumpurple1" },
[142] = { 60, 100, 34, "gold3" },
[143] = { 60, 33, 52, "darkkhaki" },
[144] = { 60, 20, 60, "navajowhite3" },
[145] = { 0, 0, 68, "grey69" },
[146] = { 240, 33, 76, "lightsteelblue3" },
[147] = { 240, 100, 84, "lightsteelblue" },
[148] = { 1, 100, 42, "yellow3" },
[149] = { 80, 60, 60, "darkolivegreen3" },
[150] = { 90, 50, 68, "darkseagreen3" },
[151] = { 120, 33, 76, "darkseagreen2" },
[152] = { 180, 33, 76, "lightcyan3" },
[153] = { 210, 100, 84, "lightskyblue1" },
[154] = { 8, 100, 50, "greenyellow" },
[155] = { 90, 100, 68, "darkolivegreen2" },
[156] = { 100, 100, 76, "palegreen1" },
[157] = { 120, 100, 84, "darkseagreen2" },
[158] = { 150, 100, 84, "darkseagreen1" },
[159] = { 180, 100, 84, "paleturquoise1" },
[160] = { 0, 100, 42, "red3" },
[161] = { 33, 100, 42, "deeppink3" },
[162] = { 22, 100, 42, "deeppink3" },
[163] = { 11, 100, 42, "magenta3" },
[164] = { 300, 100, 42, "magenta3" },
[165] = { 90, 100, 50, "magenta2" },
[166] = { 6, 100, 42, "darkorange3" },
[167] = { 0, 60, 60, "indianred" },
[168] = { 340, 60, 60, "hotpink3" },
[169] = { 320, 60, 60, "hotpink2" },
[170] = { 300, 60, 60, "orchid" },
[171] = { 285, 100, 68, "mediumorchid1" },
[172] = { 7, 100, 42, "orange3" },
[173] = { 20, 60, 60, "lightsalmon3" },
[174] = { 0, 50, 68, "lightpink3" },
[175] = { 330, 50, 68, "pink3" },
[176] = { 300, 50, 68, "plum3" },
[177] = { 280, 100, 76, "violet" },
[178] = { 8, 100, 42, "gold3" },
[179] = { 40, 60, 60, "lightgoldenrod3" },
[180] = { 30, 50, 68, "tan" },
[181] = { 0, 33, 76, "mistyrose3" },
[182] = { 300, 33, 76, "thistle3" },
[183] = { 270, 100, 84, "plum2" },
[184] = { 60, 100, 42, "yellow3" },
[185] = { 60, 60, 60, "khaki3" },
[186] = { 60, 50, 68, "lightgoldenrod2" },
[187] = { 60, 33, 76, "lightyellow3" },
[188] = { 0, 0, 84, "grey84" },
[189] = { 240, 100, 92, "lightsteelblue1" },
[190] = { 9, 100, 50, "yellow2" },
[191] = { 75, 100, 68, "darkolivegreen1" },
[192] = { 80, 100, 76, "darkolivegreen1" },
[193] = { 90, 100, 84, "darkseagreen1" },
[194] = { 120, 100, 92, "honeydew2" },
[195] = { 180, 100, 92, "lightcyan1" },
[196] = { 0, 100, 50, "red1" },
[197] = { 37, 100, 50, "deeppink2" },
[198] = { 28, 100, 50, "deeppink1" },
[199] = { 18, 100, 50, "deeppink1" },
[200] = { 9, 100, 50, "magenta2" },
[201] = { 300, 100, 50, "magenta1" },
[202] = { 2, 100, 50, "orangered1" },
[203] = { 0, 100, 68, "indianred1" },
[204] = { 345, 100, 68, "indianred1" },
[205] = { 330, 100, 68, "hotpink" },
[206] = { 315, 100, 68, "hotpink" },
[207] = { 300, 100, 68, "mediumorchid1" },
[208] = { 1, 100, 50, "darkorange" },
[209] = { 15, 100, 68, "salmon1" },
[210] = { 0, 100, 76, "lightcoral" },
[211] = { 340, 100, 76, "palevioletred1" },
[212] = { 320, 100, 76, "orchid2" },
[213] = { 300, 100, 76, "orchid1" },
[214] = { 1, 100, 50, "orange1" },
[215] = { 30, 100, 68, "sandybrown" },
[216] = { 20, 100, 76, "lightsalmon1" },
[217] = { 0, 100, 84, "lightpink1" },
[218] = { 330, 100, 84, "pink1" },
[219] = { 300, 100, 84, "plum1" },
[220] = { 0, 100, 50, "gold1" },
[221] = { 45, 100, 68, "lightgoldenrod2" },
[222] = { 40, 100, 76, "lightgoldenrod2" },
[223] = { 30, 100, 84, "navajowhite1" },
[224] = { 0, 100, 92, "mistyrose1" },
[225] = { 300, 100, 92, "thistle1" },
[226] = { 60, 100, 50, "yellow1" },
[227] = { 60, 100, 68, "lightgoldenrod1" },
[228] = { 60, 100, 76, "khaki1" },
[229] = { 60, 100, 84, "wheat1" },
[230] = { 60, 100, 92, "cornsilk1" },
[231] = { 0, 0, 100, "grey100" },
[232] = { 0, 0, 3, "grey3" },
[233] = { 0, 0, 7, "grey7" },
[234] = { 0, 0, 10, "grey11" },
[235] = { 0, 0, 14, "grey15" },
[236] = { 0, 0, 18, "grey19" },
[237] = { 0, 0, 22, "grey23" },
[238] = { 0, 0, 26, "grey27" },
[239] = { 0, 0, 30, "grey30" },
[240] = { 0, 0, 34, "grey35" },
[241] = { 0, 0, 37, "grey39" },
[242] = { 0, 0, 40, "grey42" },
[243] = { 0, 0, 46, "grey46" },
[244] = { 0, 0, 50, "grey50" },
[245] = { 0, 0, 54, "grey54" },
[246] = { 0, 0, 58, "grey58" },
[247] = { 0, 0, 61, "grey62" },
[248] = { 0, 0, 65, "grey66" },
[249] = { 0, 0, 69, "grey70" },
[250] = { 0, 0, 73, "grey74" },
[251] = { 0, 0, 77, "grey78" },
[252] = { 0, 0, 81, "grey82" },
[253] = { 0, 0, 85, "grey85" },
[254] = { 0, 0, 89, "grey89" },
[255] = { 0, 0, 93, "grey93" },
[0] = { 0, 0, 0, "black" },
[1] = { 0, 100, 25, "red" },
[2] = { 120, 100, 25, "green" },
[3] = { 60, 100, 25, "yellow" },
[4] = { 240, 100, 25, "blue" },
[5] = { 300, 100, 25, "magenta" },
[6] = { 180, 100, 25, "cyan" },
[7] = { 0, 0, 75, "white" },
[8] = { 0, 0, 50, "lightblack" },
[9] = { 0, 100, 50, "lightred" },
[10] = { 120, 100, 50, "lightgreen" },
[11] = { 60, 100, 50, "lightyellow" },
[12] = { 240, 100, 50, "lightblue" },
[13] = { 300, 100, 50, "lightmagenta" },
[14] = { 180, 100, 50, "lightcyan" },
[15] = { 0, 0, 100, "lightwhite" },
[16] = { 0, 0, 0, "grey0" },
[17] = { 240, 100, 18, "navyblue" },
[18] = { 240, 100, 26, "darkblue" },
[19] = { 240, 100, 34, "blue3" },
[20] = { 240, 100, 42, "blue3" },
[21] = { 240, 100, 50, "blue1" },
[22] = { 120, 100, 18, "darkgreen" },
[23] = { 180, 100, 18, "deepskyblue4" },
[24] = { 97, 100, 26, "deepskyblue4" },
[25] = { 7, 100, 34, "deepskyblue4" },
[26] = { 13, 100, 42, "dodgerblue3" },
[27] = { 17, 100, 50, "dodgerblue2" },
[28] = { 120, 100, 26, "green4" },
[29] = { 62, 100, 26, "springgreen4" },
[30] = { 180, 100, 26, "turquoise4" },
[31] = { 93, 100, 34, "deepskyblue3" },
[32] = { 2, 100, 42, "deepskyblue3" },
[33] = { 8, 100, 50, "dodgerblue1" },
[34] = { 120, 100, 34, "green3" },
[35] = { 52, 100, 34, "springgreen3" },
[36] = { 66, 100, 34, "darkcyan" },
[37] = { 180, 100, 34, "lightseagreen" },
[38] = { 91, 100, 42, "deepskyblue2" },
[39] = { 98, 100, 50, "deepskyblue1" },
[40] = { 120, 100, 42, "green3" },
[41] = { 46, 100, 42, "springgreen3" },
[42] = { 57, 100, 42, "springgreen2" },
[43] = { 68, 100, 42, "cyan3" },
[44] = { 180, 100, 42, "darkturquoise" },
[45] = { 89, 100, 50, "turquoise2" },
[46] = { 120, 100, 50, "green1" },
[47] = { 42, 100, 50, "springgreen2" },
[48] = { 51, 100, 50, "springgreen1" },
[49] = { 61, 100, 50, "mediumspringgreen" },
[50] = { 70, 100, 50, "cyan2" },
[51] = { 180, 100, 50, "cyan1" },
[52] = { 0, 100, 18, "darkred" },
[53] = { 300, 100, 18, "deeppink4" },
[54] = { 82, 100, 26, "purple4" },
[55] = { 72, 100, 34, "purple4" },
[56] = { 66, 100, 42, "purple3" },
[57] = { 62, 100, 50, "blueviolet" },
[58] = { 60, 100, 18, "orange4" },
[59] = { 0, 0, 37, "grey37" },
[60] = { 240, 17, 45, "mediumpurple4" },
[61] = { 240, 33, 52, "slateblue3" },
[62] = { 240, 60, 60, "slateblue3" },
[63] = { 240, 100, 68, "royalblue1" },
[64] = { 7, 100, 26, "chartreuse4" },
[65] = { 120, 17, 45, "darkseagreen4" },
[66] = { 180, 17, 45, "paleturquoise4" },
[67] = { 210, 33, 52, "steelblue" },
[68] = { 220, 60, 60, "steelblue3" },
[69] = { 225, 100, 68, "cornflowerblue" },
[70] = { 7, 100, 34, "chartreuse3" },
[71] = { 120, 33, 52, "darkseagreen4" },
[72] = { 150, 33, 52, "cadetblue" },
[73] = { 180, 33, 52, "cadetblue" },
[74] = { 200, 60, 60, "skyblue3" },
[75] = { 210, 100, 68, "steelblue1" },
[76] = { 3, 100, 42, "chartreuse3" },
[77] = { 120, 60, 60, "palegreen3" },
[78] = { 140, 60, 60, "seagreen3" },
[79] = { 160, 60, 60, "aquamarine3" },
[80] = { 180, 60, 60, "mediumturquoise" },
[81] = { 195, 100, 68, "steelblue1" },
[82] = { 7, 100, 50, "chartreuse2" },
[83] = { 120, 100, 68, "seagreen2" },
[84] = { 135, 100, 68, "seagreen1" },
[85] = { 150, 100, 68, "seagreen1" },
[86] = { 165, 100, 68, "aquamarine1" },
[87] = { 180, 100, 68, "darkslategray2" },
[88] = { 0, 100, 26, "darkred" },
[89] = { 17, 100, 26, "deeppink4" },
[90] = { 300, 100, 26, "darkmagenta" },
[91] = { 86, 100, 34, "darkmagenta" },
[92] = { 77, 100, 42, "darkviolet" },
[93] = { 71, 100, 50, "purple" },
[94] = { 2, 100, 26, "orange4" },
[95] = { 0, 17, 45, "lightpink4" },
[96] = { 300, 17, 45, "plum4" },
[97] = { 270, 33, 52, "mediumpurple3" },
[98] = { 260, 60, 60, "mediumpurple3" },
[99] = { 255, 100, 68, "slateblue1" },
[100] = { 60, 100, 26, "yellow4" },
[101] = { 60, 17, 45, "wheat4" },
[102] = { 0, 0, 52, "grey53" },
[103] = { 240, 20, 60, "lightslategrey" },
[104] = { 240, 50, 68, "mediumpurple" },
[105] = { 240, 100, 76, "lightslateblue" },
[106] = { 3, 100, 34, "yellow4" },
[107] = { 90, 33, 52, "darkolivegreen3" },
[108] = { 120, 20, 60, "darkseagreen" },
[109] = { 180, 20, 60, "lightskyblue3" },
[110] = { 210, 50, 68, "lightskyblue3" },
[111] = { 220, 100, 76, "skyblue2" },
[112] = { 2, 100, 42, "chartreuse2" },
[113] = { 100, 60, 60, "darkolivegreen3" },
[114] = { 120, 50, 68, "palegreen3" },
[115] = { 150, 50, 68, "darkseagreen3" },
[116] = { 180, 50, 68, "darkslategray3" },
[117] = { 200, 100, 76, "skyblue1" },
[118] = { 8, 100, 50, "chartreuse1" },
[119] = { 105, 100, 68, "lightgreen" },
[120] = { 120, 100, 76, "lightgreen" },
[121] = { 140, 100, 76, "palegreen1" },
[122] = { 160, 100, 76, "aquamarine1" },
[123] = { 180, 100, 76, "darkslategray1" },
[124] = { 0, 100, 34, "red3" },
[125] = { 27, 100, 34, "deeppink4" },
[126] = { 13, 100, 34, "mediumvioletred" },
[127] = { 300, 100, 34, "magenta3" },
[128] = { 88, 100, 42, "darkviolet" },
[129] = { 81, 100, 50, "purple" },
[130] = { 2, 100, 34, "darkorange3" },
[131] = { 0, 33, 52, "indianred" },
[132] = { 330, 33, 52, "hotpink3" },
[133] = { 300, 33, 52, "mediumorchid3" },
[134] = { 280, 60, 60, "mediumorchid" },
[135] = { 270, 100, 68, "mediumpurple2" },
[136] = { 6, 100, 34, "darkgoldenrod" },
[137] = { 30, 33, 52, "lightsalmon3" },
[138] = { 0, 20, 60, "rosybrown" },
[139] = { 300, 20, 60, "grey63" },
[140] = { 270, 50, 68, "mediumpurple2" },
[141] = { 260, 100, 76, "mediumpurple1" },
[142] = { 60, 100, 34, "gold3" },
[143] = { 60, 33, 52, "darkkhaki" },
[144] = { 60, 20, 60, "navajowhite3" },
[145] = { 0, 0, 68, "grey69" },
[146] = { 240, 33, 76, "lightsteelblue3" },
[147] = { 240, 100, 84, "lightsteelblue" },
[148] = { 1, 100, 42, "yellow3" },
[149] = { 80, 60, 60, "darkolivegreen3" },
[150] = { 90, 50, 68, "darkseagreen3" },
[151] = { 120, 33, 76, "darkseagreen2" },
[152] = { 180, 33, 76, "lightcyan3" },
[153] = { 210, 100, 84, "lightskyblue1" },
[154] = { 8, 100, 50, "greenyellow" },
[155] = { 90, 100, 68, "darkolivegreen2" },
[156] = { 100, 100, 76, "palegreen1" },
[157] = { 120, 100, 84, "darkseagreen2" },
[158] = { 150, 100, 84, "darkseagreen1" },
[159] = { 180, 100, 84, "paleturquoise1" },
[160] = { 0, 100, 42, "red3" },
[161] = { 33, 100, 42, "deeppink3" },
[162] = { 22, 100, 42, "deeppink3" },
[163] = { 11, 100, 42, "magenta3" },
[164] = { 300, 100, 42, "magenta3" },
[165] = { 90, 100, 50, "magenta2" },
[166] = { 6, 100, 42, "darkorange3" },
[167] = { 0, 60, 60, "indianred" },
[168] = { 340, 60, 60, "hotpink3" },
[169] = { 320, 60, 60, "hotpink2" },
[170] = { 300, 60, 60, "orchid" },
[171] = { 285, 100, 68, "mediumorchid1" },
[172] = { 7, 100, 42, "orange3" },
[173] = { 20, 60, 60, "lightsalmon3" },
[174] = { 0, 50, 68, "lightpink3" },
[175] = { 330, 50, 68, "pink3" },
[176] = { 300, 50, 68, "plum3" },
[177] = { 280, 100, 76, "violet" },
[178] = { 8, 100, 42, "gold3" },
[179] = { 40, 60, 60, "lightgoldenrod3" },
[180] = { 30, 50, 68, "tan" },
[181] = { 0, 33, 76, "mistyrose3" },
[182] = { 300, 33, 76, "thistle3" },
[183] = { 270, 100, 84, "plum2" },
[184] = { 60, 100, 42, "yellow3" },
[185] = { 60, 60, 60, "khaki3" },
[186] = { 60, 50, 68, "lightgoldenrod2" },
[187] = { 60, 33, 76, "lightyellow3" },
[188] = { 0, 0, 84, "grey84" },
[189] = { 240, 100, 92, "lightsteelblue1" },
[190] = { 9, 100, 50, "yellow2" },
[191] = { 75, 100, 68, "darkolivegreen1" },
[192] = { 80, 100, 76, "darkolivegreen1" },
[193] = { 90, 100, 84, "darkseagreen1" },
[194] = { 120, 100, 92, "honeydew2" },
[195] = { 180, 100, 92, "lightcyan1" },
[196] = { 0, 100, 50, "red1" },
[197] = { 37, 100, 50, "deeppink2" },
[198] = { 28, 100, 50, "deeppink1" },
[199] = { 18, 100, 50, "deeppink1" },
[200] = { 9, 100, 50, "magenta2" },
[201] = { 300, 100, 50, "magenta1" },
[202] = { 2, 100, 50, "orangered1" },
[203] = { 0, 100, 68, "indianred1" },
[204] = { 345, 100, 68, "indianred1" },
[205] = { 330, 100, 68, "hotpink" },
[206] = { 315, 100, 68, "hotpink" },
[207] = { 300, 100, 68, "mediumorchid1" },
[208] = { 1, 100, 50, "darkorange" },
[209] = { 15, 100, 68, "salmon1" },
[210] = { 0, 100, 76, "lightcoral" },
[211] = { 340, 100, 76, "palevioletred1" },
[212] = { 320, 100, 76, "orchid2" },
[213] = { 300, 100, 76, "orchid1" },
[214] = { 1, 100, 50, "orange1" },
[215] = { 30, 100, 68, "sandybrown" },
[216] = { 20, 100, 76, "lightsalmon1" },
[217] = { 0, 100, 84, "lightpink1" },
[218] = { 330, 100, 84, "pink1" },
[219] = { 300, 100, 84, "plum1" },
[220] = { 0, 100, 50, "gold1" },
[221] = { 45, 100, 68, "lightgoldenrod2" },
[222] = { 40, 100, 76, "lightgoldenrod2" },
[223] = { 30, 100, 84, "navajowhite1" },
[224] = { 0, 100, 92, "mistyrose1" },
[225] = { 300, 100, 92, "thistle1" },
[226] = { 60, 100, 50, "yellow1" },
[227] = { 60, 100, 68, "lightgoldenrod1" },
[228] = { 60, 100, 76, "khaki1" },
[229] = { 60, 100, 84, "wheat1" },
[230] = { 60, 100, 92, "cornsilk1" },
[231] = { 0, 0, 100, "grey100" },
[232] = { 0, 0, 3, "grey3" },
[233] = { 0, 0, 7, "grey7" },
[234] = { 0, 0, 10, "grey11" },
[235] = { 0, 0, 14, "grey15" },
[236] = { 0, 0, 18, "grey19" },
[237] = { 0, 0, 22, "grey23" },
[238] = { 0, 0, 26, "grey27" },
[239] = { 0, 0, 30, "grey30" },
[240] = { 0, 0, 34, "grey35" },
[241] = { 0, 0, 37, "grey39" },
[242] = { 0, 0, 40, "grey42" },
[243] = { 0, 0, 46, "grey46" },
[244] = { 0, 0, 50, "grey50" },
[245] = { 0, 0, 54, "grey54" },
[246] = { 0, 0, 58, "grey58" },
[247] = { 0, 0, 61, "grey62" },
[248] = { 0, 0, 65, "grey66" },
[249] = { 0, 0, 69, "grey70" },
[250] = { 0, 0, 73, "grey74" },
[251] = { 0, 0, 77, "grey78" },
[252] = { 0, 0, 81, "grey82" },
[253] = { 0, 0, 85, "grey85" },
[254] = { 0, 0, 89, "grey89" },
[255] = { 0, 0, 93, "grey93" },
};
/* -1 is valid curses color */
#define COL_ERR -2
static inline int color_distance(const struct color_def *a, const struct color_def *b)
static inline int
color_distance(const struct color_def* a, const struct color_def* b)
{
int h = MIN((a->h - b->h)%360, (b->h - a->h)%360);
int h = MIN((a->h - b->h) % 360, (b->h - a->h) % 360);
int s = (int)a->s - b->s;
int l = (int)a->l - b->l;
return h*h + s*s + l*l;
return h * h + s * s + l * l;
}
static int find_closest_col(int h, int s, int l)
static int
find_closest_col(int h, int s, int l)
{
int i;
struct color_def a = {h, s, l};
struct color_def a = { h, s, l };
int min = 0;
int dmin = color_distance(&a, &color_names[0]);
@@ -352,10 +356,11 @@ static int find_closest_col(int h, int s, int l)
return min;
}
static int find_col(const char *col_name, int n)
static int
find_col(const char* col_name, int n)
{
int i;
char name[32] = {0};
char name[32] = { 0 };
/*
* make a null terminated version of col_name. we don't want to
@@ -366,7 +371,7 @@ static int find_col(const char *col_name, int n)
if (n >= sizeof(name)) {
/* truncate */
log_error("Color: <%s,%d> bigger than %zu", col_name, n, sizeof(name));
n = sizeof(name)-1;
n = sizeof(name) - 1;
}
memcpy(name, col_name, n);
@@ -383,10 +388,11 @@ static int find_col(const char *col_name, int n)
return COL_ERR;
}
static int color_hash(const char *str, color_profile profile)
static int
color_hash(const char* str, color_profile profile)
{
GChecksum *cs = NULL;
guint8 buf[256] = {0};
GChecksum* cs = NULL;
guint8 buf[256] = { 0 };
gsize len = 256;
int rc = -1; /* default ncurse color */
@@ -403,27 +409,27 @@ static int color_hash(const char *str, color_profile profile)
double h = ((buf[1] << 8) | buf[0]) / 65536. * 360.;
switch(profile)
{
case COLOR_PROFILE_REDGREEN_BLINDNESS:
// red/green blindness correction
h = fmod(fmod(h + 90., 180) - 90., 360.);
break;
case COLOR_PROFILE_BLUE_BLINDNESS:
// blue blindness correction
h = fmod(h, 180.);
default:
break;
switch (profile) {
case COLOR_PROFILE_REDGREEN_BLINDNESS:
// red/green blindness correction
h = fmod(fmod(h + 90., 180) - 90., 360.);
break;
case COLOR_PROFILE_BLUE_BLINDNESS:
// blue blindness correction
h = fmod(h, 180.);
default:
break;
}
rc = find_closest_col((int)h, 100, 50);
out:
out:
g_checksum_free(cs);
return rc;
}
void color_pair_cache_reset(void)
void
color_pair_cache_reset(void)
{
if (cache.pairs) {
free(cache.pairs);
@@ -440,7 +446,7 @@ void color_pair_cache_reset(void)
if (cache.capacity < 0)
cache.capacity = 8;
cache.pairs = g_malloc0(sizeof(*cache.pairs)*cache.capacity);
cache.pairs = g_malloc0(sizeof(*cache.pairs) * cache.capacity);
if (cache.pairs) {
/* default_default */
cache.pairs[0].fg = -1;
@@ -451,7 +457,8 @@ void color_pair_cache_reset(void)
}
}
static int _color_pair_cache_get(int fg, int bg)
static int
_color_pair_cache_get(int fg, int bg)
{
int i;
@@ -497,12 +504,13 @@ static int _color_pair_cache_get(int fg, int bg)
* hash a string into a color that will be used as fg
* check for 'bkgnd' in theme file or use default color as bg
*/
int color_pair_cache_hash_str(const char *str, color_profile profile)
int
color_pair_cache_hash_str(const char* str, color_profile profile)
{
int fg = color_hash(str, profile);
int bg = -1;
char *bkgnd = theme_get_bkgnd();
char* bkgnd = theme_get_bkgnd();
if (bkgnd) {
bg = find_col(bkgnd, strlen(bkgnd));
free(bkgnd);
@@ -517,9 +525,10 @@ int color_pair_cache_hash_str(const char *str, color_profile profile)
* if the pair doesn't exist it will allocate it in curses with init_pair
* if the pair exists it returns its id
*/
int color_pair_cache_get(const char *pair_name)
int
color_pair_cache_get(const char* pair_name)
{
const char *sep;
const char* sep;
int fg, bg;
sep = strchr(pair_name, '_');
@@ -529,7 +538,7 @@ int color_pair_cache_get(const char *pair_name)
}
fg = find_col(pair_name, sep - pair_name);
bg = find_col(sep+1, strlen(sep));
bg = find_col(sep + 1, strlen(sep));
if (fg == COL_ERR || bg == COL_ERR) {
log_error("Color: bad color name %s", pair_name);
return -1;

View File

@@ -47,16 +47,18 @@ typedef enum {
COLOR_PROFILE_BLUE_BLINDNESS,
} color_profile;
struct color_def {
uint16_t h; uint8_t s, l;
const char *name;
struct color_def
{
uint16_t h;
uint8_t s, l;
const char* name;
};
extern const struct color_def color_names[];
/* hash string to color pair */
int color_pair_cache_hash_str(const char *str, color_profile profile);
int color_pair_cache_hash_str(const char* str, color_profile profile);
/* parse fg_bg string to color pair */
int color_pair_cache_get(const char *pair_name);
int color_pair_cache_get(const char* pair_name);
/* clear cache */
void color_pair_cache_reset(void);

View File

@@ -33,15 +33,15 @@
*
*/
#include <string.h>
#include <glib.h>
#include <string.h>
gboolean
conf_string_list_add(GKeyFile *keyfile, const char *const group, const char *const key, const char *const item)
conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item)
{
gsize length;
gchar **list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
GList *glist = NULL;
gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
GList* glist = NULL;
// list found
if (list) {
@@ -61,8 +61,8 @@ conf_string_list_add(GKeyFile *keyfile, const char *const group, const char *con
glist = g_list_append(glist, strdup(item));
// create the new list entry
const gchar* new_list[g_list_length(glist)+1];
GList *curr = glist;
const gchar* new_list[g_list_length(glist) + 1];
GList* curr = glist;
i = 0;
while (curr) {
new_list[i++] = curr->data;
@@ -71,7 +71,7 @@ conf_string_list_add(GKeyFile *keyfile, const char *const group, const char *con
new_list[i] = NULL;
g_key_file_set_string_list(keyfile, group, key, new_list, g_list_length(glist));
// list not found
// list not found
} else {
const gchar* new_list[2];
new_list[0] = item;
@@ -86,15 +86,15 @@ conf_string_list_add(GKeyFile *keyfile, const char *const group, const char *con
}
gboolean
conf_string_list_remove(GKeyFile *keyfile, const char *const group, const char *const key, const char *const item)
conf_string_list_remove(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item)
{
gsize length;
gchar **list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
gboolean deleted = FALSE;
if (list) {
int i = 0;
GList *glist = NULL;
GList* glist = NULL;
for (i = 0; i < length; i++) {
// item found, mark as deleted
@@ -111,8 +111,8 @@ conf_string_list_remove(GKeyFile *keyfile, const char *const group, const char *
g_key_file_remove_key(keyfile, group, key, NULL);
} else {
// create the new list entry
const gchar* new_list[g_list_length(glist)+1];
GList *curr = glist;
const gchar* new_list[g_list_length(glist) + 1];
GList* curr = glist;
i = 0;
while (curr) {
new_list[i++] = curr->data;

View File

@@ -38,9 +38,9 @@
#include <glib.h>
gboolean conf_string_list_add(GKeyFile *keyfile, const char *const group, const char *const key,
const char *const item);
gboolean conf_string_list_remove(GKeyFile *keyfile, const char *const group, const char *const key,
const char *const item);
gboolean conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* const key,
const char* const item);
gboolean conf_string_list_remove(GKeyFile* keyfile, const char* const group, const char* const key,
const char* const item);
#endif

View File

@@ -35,15 +35,15 @@
*/
#include "config.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
#include "common.h"
#include "log.h"
#include "config/files.h"
#include "config/preferences.h"
#include "log.h"
static char* _files_get_xdg_config_home(void);
static char* _files_get_xdg_data_home(void);
@@ -51,18 +51,18 @@ static char* _files_get_xdg_data_home(void);
void
files_create_directories(void)
{
gchar *xdg_config = _files_get_xdg_config_home();
gchar *xdg_data = _files_get_xdg_data_home();
gchar* xdg_config = _files_get_xdg_config_home();
gchar* xdg_data = _files_get_xdg_data_home();
GString *themes_dir = g_string_new(xdg_config);
GString* themes_dir = g_string_new(xdg_config);
g_string_append(themes_dir, "/profanity/themes");
GString *icons_dir = g_string_new(xdg_config);
GString* icons_dir = g_string_new(xdg_config);
g_string_append(icons_dir, "/profanity/icons");
GString *chatlogs_dir = g_string_new(xdg_data);
GString* chatlogs_dir = g_string_new(xdg_data);
g_string_append(chatlogs_dir, "/profanity/chatlogs");
GString *logs_dir = g_string_new(xdg_data);
GString* logs_dir = g_string_new(xdg_data);
g_string_append(logs_dir, "/profanity/logs");
GString *plugins_dir = g_string_new(xdg_data);
GString* plugins_dir = g_string_new(xdg_data);
g_string_append(plugins_dir, "/profanity/plugins");
if (!mkdir_recursive(themes_dir->str)) {
@@ -94,14 +94,14 @@ files_create_directories(void)
gchar*
files_get_inputrc_file(void)
{
gchar *xdg_config = _files_get_xdg_config_home();
GString *inputrc_file = g_string_new(xdg_config);
gchar* xdg_config = _files_get_xdg_config_home();
GString* inputrc_file = g_string_new(xdg_config);
g_free(xdg_config);
g_string_append(inputrc_file, "/profanity/inputrc");
if (g_file_test(inputrc_file->str, G_FILE_TEST_IS_REGULAR)) {
gchar *result = g_strdup(inputrc_file->str);
gchar* result = g_strdup(inputrc_file->str);
g_string_free(inputrc_file, TRUE);
return result;
@@ -113,10 +113,10 @@ files_get_inputrc_file(void)
}
char*
files_get_log_file(const char *const log_file)
files_get_log_file(const char* const log_file)
{
gchar *xdg_data = _files_get_xdg_data_home();
GString *logfile = g_string_new(xdg_data);
gchar* xdg_data = _files_get_xdg_data_home();
GString* logfile = g_string_new(xdg_data);
if (log_file) {
g_string_append(logfile, "/profanity/logs/");
@@ -131,7 +131,7 @@ files_get_log_file(const char *const log_file)
g_string_append(logfile, ".log");
char *result = g_strdup(logfile->str);
char* result = g_strdup(logfile->str);
free(xdg_data);
g_string_free(logfile, TRUE);
@@ -140,13 +140,13 @@ files_get_log_file(const char *const log_file)
}
gchar*
files_get_config_path(const char *const config_base)
files_get_config_path(const char* const config_base)
{
gchar *xdg_config = _files_get_xdg_config_home();
GString *file_str = g_string_new(xdg_config);
gchar* xdg_config = _files_get_xdg_config_home();
GString* file_str = g_string_new(xdg_config);
g_string_append(file_str, "/profanity/");
g_string_append(file_str, config_base);
gchar *result = g_strdup(file_str->str);
gchar* result = g_strdup(file_str->str);
g_free(xdg_config);
g_string_free(file_str, TRUE);
@@ -154,13 +154,13 @@ files_get_config_path(const char *const config_base)
}
gchar*
files_get_data_path(const char *const data_base)
files_get_data_path(const char* const data_base)
{
gchar *xdg_data = _files_get_xdg_data_home();
GString *file_str = g_string_new(xdg_data);
gchar* xdg_data = _files_get_xdg_data_home();
GString* file_str = g_string_new(xdg_data);
g_string_append(file_str, "/profanity/");
g_string_append(file_str, data_base);
gchar *result = g_strdup(file_str->str);
gchar* result = g_strdup(file_str->str);
g_free(xdg_data);
g_string_free(file_str, TRUE);
@@ -168,18 +168,18 @@ files_get_data_path(const char *const data_base)
}
gchar*
files_get_account_data_path(const char *const specific_dir, const char *const jid)
files_get_account_data_path(const char* const specific_dir, const char* const jid)
{
gchar *data_dir = files_get_data_path(specific_dir);
GString *result_dir = g_string_new(data_dir);
gchar* data_dir = files_get_data_path(specific_dir);
GString* result_dir = g_string_new(data_dir);
g_free(data_dir);
gchar *account_dir = str_replace(jid, "@", "_at_");
gchar* account_dir = str_replace(jid, "@", "_at_");
g_string_append(result_dir, "/");
g_string_append(result_dir, account_dir);
g_free(account_dir);
gchar *result = g_strdup(result_dir->str);
gchar* result = g_strdup(result_dir->str);
g_string_free(result_dir, TRUE);
return result;
@@ -188,8 +188,8 @@ files_get_account_data_path(const char *const specific_dir, const char *const ji
static char*
_files_get_xdg_config_home(void)
{
gchar *xdg_config_home_env = getenv("XDG_CONFIG_HOME");
gchar *xdg_config_home = NULL;
gchar* xdg_config_home_env = getenv("XDG_CONFIG_HOME");
gchar* xdg_config_home = NULL;
if (xdg_config_home_env) {
xdg_config_home = strdup(xdg_config_home_env);
@@ -199,9 +199,9 @@ _files_get_xdg_config_home(void)
if (xdg_config_home && (strcmp(xdg_config_home, "") != 0)) {
return xdg_config_home;
} else {
GString *default_path = g_string_new(getenv("HOME"));
GString* default_path = g_string_new(getenv("HOME"));
g_string_append(default_path, "/.config");
char *result = strdup(default_path->str);
char* result = strdup(default_path->str);
g_string_free(default_path, TRUE);
return result;
@@ -211,8 +211,8 @@ _files_get_xdg_config_home(void)
static char*
_files_get_xdg_data_home(void)
{
gchar *xdg_data_home_env = getenv("XDG_DATA_HOME");
gchar *xdg_data_home = NULL;
gchar* xdg_data_home_env = getenv("XDG_DATA_HOME");
gchar* xdg_data_home = NULL;
if (xdg_data_home_env) {
xdg_data_home = strdup(xdg_data_home_env);
@@ -222,9 +222,9 @@ _files_get_xdg_data_home(void)
if (xdg_data_home && (strcmp(xdg_data_home, "") != 0)) {
return xdg_data_home;
} else {
GString *default_path = g_string_new(getenv("HOME"));
GString* default_path = g_string_new(getenv("HOME"));
g_string_append(default_path, "/.local/share");
gchar *result = strdup(default_path->str);
gchar* result = strdup(default_path->str);
g_string_free(default_path, TRUE);
return result;

View File

@@ -39,32 +39,32 @@
#include <glib.h>
#define FILE_PROFRC "profrc"
#define FILE_ACCOUNTS "accounts"
#define FILE_TLSCERTS "tlscerts"
#define FILE_PLUGIN_SETTINGS "plugin_settings"
#define FILE_PLUGIN_THEMES "plugin_themes"
#define FILE_CAPSCACHE "capscache"
#define FILE_PROFANITY_IDENTIFIER "profident"
#define FILE_PROFRC "profrc"
#define FILE_ACCOUNTS "accounts"
#define FILE_TLSCERTS "tlscerts"
#define FILE_PLUGIN_SETTINGS "plugin_settings"
#define FILE_PLUGIN_THEMES "plugin_themes"
#define FILE_CAPSCACHE "capscache"
#define FILE_PROFANITY_IDENTIFIER "profident"
#define FILE_BOOKMARK_AUTOJOIN_IGNORE "bookmark_ignore"
#define DIR_THEMES "themes"
#define DIR_ICONS "icons"
#define DIR_SCRIPTS "scripts"
#define DIR_THEMES "themes"
#define DIR_ICONS "icons"
#define DIR_SCRIPTS "scripts"
#define DIR_CHATLOGS "chatlogs"
#define DIR_OTR "otr"
#define DIR_PGP "pgp"
#define DIR_OMEMO "omemo"
#define DIR_PLUGINS "plugins"
#define DIR_OTR "otr"
#define DIR_PGP "pgp"
#define DIR_OMEMO "omemo"
#define DIR_PLUGINS "plugins"
#define DIR_DATABASE "database"
void files_create_directories(void);
gchar* files_get_config_path(const char *const config_base);
gchar* files_get_data_path(const char *const data_base);
gchar* files_get_account_data_path(const char *const specific_dir, const char *const jid);
gchar* files_get_config_path(const char* const config_base);
gchar* files_get_data_path(const char* const data_base);
gchar* files_get_account_data_path(const char* const specific_dir, const char* const jid);
gchar* files_get_log_file(const char *const log_file);
gchar* files_get_log_file(const char* const log_file);
gchar* files_get_inputrc_file(void);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -175,30 +175,32 @@ typedef enum {
PREF_URL_SAVE_CMD,
} preference_t;
typedef struct prof_alias_t {
gchar *name;
gchar *value;
typedef struct prof_alias_t
{
gchar* name;
gchar* value;
} ProfAlias;
typedef struct prof_winplacement_t {
typedef struct prof_winplacement_t
{
int titlebar_pos;
int mainwin_pos;
int statusbar_pos;
int inputwin_pos;
} ProfWinPlacement;
void prefs_load(char *config_file);
void prefs_load(char* config_file);
void prefs_save(void);
void prefs_close(void);
void prefs_reload(void);
char* prefs_find_login(char *prefix);
char* prefs_find_login(char* prefix);
void prefs_reset_login_search(void);
char* prefs_autocomplete_boolean_choice(const char *const prefix, gboolean previous, void *context);
char* prefs_autocomplete_boolean_choice(const char* const prefix, gboolean previous, void* context);
void prefs_reset_boolean_choice(void);
char* prefs_autocomplete_room_trigger(const char *const prefix, gboolean previous, void *context);
char* prefs_autocomplete_room_trigger(const char* const prefix, gboolean previous, void* context);
void prefs_reset_room_trigger_ac(void);
gint prefs_get_gone(void);
@@ -235,19 +237,19 @@ gint prefs_get_autoxa_time(void);
void prefs_set_autoxa_time(gint value);
gchar** prefs_get_plugins(void);
void prefs_free_plugins(gchar **plugins);
void prefs_add_plugin(const char *const name);
void prefs_remove_plugin(const char *const name);
void prefs_free_plugins(gchar** plugins);
void prefs_add_plugin(const char* const name);
void prefs_remove_plugin(const char* const name);
char* prefs_get_otr_char(void);
gboolean prefs_set_otr_char(char *ch);
gboolean prefs_set_otr_char(char* ch);
char* prefs_get_pgp_char(void);
gboolean prefs_set_pgp_char(char *ch);
gboolean prefs_set_pgp_char(char* ch);
char* prefs_get_omemo_char(void);
gboolean prefs_set_omemo_char(char *ch);
gboolean prefs_set_omemo_char(char* ch);
// XEP-0373: OpenPGP for XMPP
char* prefs_get_ox_char(void);
gboolean prefs_set_ox_char(char *ch);
gboolean prefs_set_ox_char(char* ch);
char prefs_get_roster_header_char(void);
void prefs_set_roster_header_char(char ch);
@@ -286,23 +288,23 @@ void prefs_set_occupants_indent(gint value);
char* prefs_get_correction_char(void);
void prefs_set_correction_char(char ch);
void prefs_add_login(const char *jid);
void prefs_add_login(const char* jid);
void prefs_set_tray_timer(gint value);
gint prefs_get_tray_timer(void);
gboolean prefs_add_alias(const char *const name, const char *const value);
gboolean prefs_remove_alias(const char *const name);
char* prefs_get_alias(const char *const name);
gboolean prefs_add_alias(const char* const name, const char* const value);
gboolean prefs_remove_alias(const char* const name);
char* prefs_get_alias(const char* const name);
GList* prefs_get_aliases(void);
void prefs_free_aliases(GList *aliases);
void prefs_free_aliases(GList* aliases);
gboolean prefs_add_room_notify_trigger(const char * const text);
gboolean prefs_remove_room_notify_trigger(const char * const text);
gboolean prefs_add_room_notify_trigger(const char* const text);
gboolean prefs_remove_room_notify_trigger(const char* const text);
GList* prefs_get_room_notify_triggers(void);
ProfWinPlacement* prefs_get_win_placement(void);
void prefs_free_win_placement(ProfWinPlacement *placement);
void prefs_free_win_placement(ProfWinPlacement* placement);
gboolean prefs_titlebar_pos_up(void);
gboolean prefs_titlebar_pos_down(void);
@@ -313,35 +315,35 @@ gboolean prefs_statusbar_pos_down(void);
gboolean prefs_inputwin_pos_up(void);
gboolean prefs_inputwin_pos_down(void);
ProfWinPlacement* prefs_create_profwin_placement(int titlebar, int mainwin, int statusbar, int inputwin);
void prefs_save_win_placement(ProfWinPlacement *placement);
void prefs_save_win_placement(ProfWinPlacement* placement);
gboolean prefs_get_boolean(preference_t pref);
void prefs_set_boolean(preference_t pref, gboolean value);
char* prefs_get_string(preference_t pref);
char* prefs_get_string_with_option(preference_t pref, gchar *option);
gchar **prefs_get_string_list_with_option(preference_t pref, gchar *option);
void prefs_set_string(preference_t pref, char *value);
void prefs_set_string_with_option(preference_t pref, char *option, char *value);
void prefs_set_string_list_with_option(preference_t pref, char *option, const gchar* const *values);
char* prefs_get_string_with_option(preference_t pref, gchar* option);
gchar** prefs_get_string_list_with_option(preference_t pref, gchar* option);
void prefs_set_string(preference_t pref, char* value);
void prefs_set_string_with_option(preference_t pref, char* option, char* value);
void prefs_set_string_list_with_option(preference_t pref, char* option, const gchar* const* values);
char* prefs_get_tls_certpath(void);
gboolean prefs_do_chat_notify(gboolean current_win);
gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const mynick,
const char *const theirnick, const char *const message, gboolean mention, gboolean trigger_found);
gboolean prefs_do_room_notify_mention(const char *const roomjid, int unread, gboolean mention, gboolean trigger);
GList* prefs_message_get_triggers(const char *const message);
gboolean prefs_do_room_notify(gboolean current_win, const char* const roomjid, const char* const mynick,
const char* const theirnick, const char* const message, gboolean mention, gboolean trigger_found);
gboolean prefs_do_room_notify_mention(const char* const roomjid, int unread, gboolean mention, gboolean trigger);
GList* prefs_message_get_triggers(const char* const message);
void prefs_set_room_notify(const char *const roomjid, gboolean value);
void prefs_set_room_notify_mention(const char *const roomjid, gboolean value);
void prefs_set_room_notify_trigger(const char *const roomjid, gboolean value);
gboolean prefs_reset_room_notify(const char *const roomjid);
gboolean prefs_has_room_notify(const char *const roomjid);
gboolean prefs_has_room_notify_mention(const char *const roomjid);
gboolean prefs_has_room_notify_trigger(const char *const roomjid);
gboolean prefs_get_room_notify(const char *const roomjid);
gboolean prefs_get_room_notify_mention(const char *const roomjid);
gboolean prefs_get_room_notify_trigger(const char *const roomjid);
void prefs_set_room_notify(const char* const roomjid, gboolean value);
void prefs_set_room_notify_mention(const char* const roomjid, gboolean value);
void prefs_set_room_notify_trigger(const char* const roomjid, gboolean value);
gboolean prefs_reset_room_notify(const char* const roomjid);
gboolean prefs_has_room_notify(const char* const roomjid);
gboolean prefs_has_room_notify_mention(const char* const roomjid);
gboolean prefs_has_room_notify_trigger(const char* const roomjid);
gboolean prefs_get_room_notify(const char* const roomjid);
gboolean prefs_get_room_notify_mention(const char* const roomjid);
gboolean prefs_get_room_notify_trigger(const char* const roomjid);
gchar* prefs_get_inputrc(void);

View File

@@ -33,18 +33,18 @@
*
*/
#include <stdlib.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "common.h"
#include "log.h"
#include "config/files.h"
#include "command/cmd_defs.h"
#include "common.h"
#include "config/files.h"
#include "log.h"
#include "ui/ui.h"
#include "ui/window_list.h"
#include "xmpp/xmpp.h"
@@ -52,13 +52,13 @@
void
scripts_init(void)
{
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
char* scriptsdir = files_get_data_path(DIR_SCRIPTS);
// mkdir if doesn't exist
errno = 0;
int res = g_mkdir_with_parents(scriptsdir, S_IRWXU);
if (res == -1) {
char *errmsg = strerror(errno);
char* errmsg = strerror(errno);
if (errmsg) {
log_error("Error creating directory: %s, %s", scriptsdir, errmsg);
} else {
@@ -72,14 +72,14 @@ scripts_init(void)
GSList*
scripts_list(void)
{
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
char* scriptsdir = files_get_data_path(DIR_SCRIPTS);
GSList *result = NULL;
GDir *scripts = g_dir_open(scriptsdir, 0, NULL);
GSList* result = NULL;
GDir* scripts = g_dir_open(scriptsdir, 0, NULL);
free(scriptsdir);
if (scripts) {
const gchar *script = g_dir_read_name(scripts);
const gchar* script = g_dir_read_name(scripts);
while (script) {
result = g_slist_append(result, strdup(script));
script = g_dir_read_name(scripts);
@@ -91,15 +91,15 @@ scripts_list(void)
}
GSList*
scripts_read(const char *const script)
scripts_read(const char* const script)
{
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
GString *scriptpath = g_string_new(scriptsdir);
char* scriptsdir = files_get_data_path(DIR_SCRIPTS);
GString* scriptpath = g_string_new(scriptsdir);
free(scriptsdir);
g_string_append(scriptpath, "/");
g_string_append(scriptpath, script);
FILE *scriptfile = g_fopen(scriptpath->str, "r");
FILE* scriptfile = g_fopen(scriptpath->str, "r");
if (!scriptfile) {
log_info("Script not found: %s", scriptpath->str);
g_string_free(scriptpath, TRUE);
@@ -108,35 +108,36 @@ scripts_read(const char *const script)
g_string_free(scriptpath, TRUE);
char *line = NULL;
char* line = NULL;
size_t len = 0;
ssize_t read;
GSList *result = NULL;
GSList* result = NULL;
while ((read = getline(&line, &len, scriptfile)) != -1) {
if (g_str_has_suffix(line, "\n")) {
result = g_slist_append(result, g_strndup(line, strlen(line) -1));
result = g_slist_append(result, g_strndup(line, strlen(line) - 1));
} else {
result = g_slist_append(result, strdup(line));
}
}
fclose(scriptfile);
if (line) free(line);
if (line)
free(line);
return result;
}
gboolean
scripts_exec(const char *const script)
scripts_exec(const char* const script)
{
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
GString *scriptpath = g_string_new(scriptsdir);
char* scriptsdir = files_get_data_path(DIR_SCRIPTS);
GString* scriptpath = g_string_new(scriptsdir);
free(scriptsdir);
g_string_append(scriptpath, "/");
g_string_append(scriptpath, script);
FILE *scriptfile = g_fopen(scriptpath->str, "r");
FILE* scriptfile = g_fopen(scriptpath->str, "r");
if (!scriptfile) {
log_info("Script not found: %s", scriptpath->str);
g_string_free(scriptpath, TRUE);
@@ -145,20 +146,20 @@ scripts_exec(const char *const script)
g_string_free(scriptpath, TRUE);
char *line = NULL;
char* line = NULL;
size_t len = 0;
ssize_t read;
while ((read = getline(&line, &len, scriptfile)) != -1) {
ProfWin *win = wins_get_current();
ProfWin* win = wins_get_current();
cmd_process_input(win, line);
session_process_events();
ui_update();
}
fclose(scriptfile);
if (line) free(line);
if (line)
free(line);
return TRUE;
}

View File

@@ -40,7 +40,7 @@
void scripts_init(void);
GSList* scripts_list(void);
GSList* scripts_read(const char *const script);
gboolean scripts_exec(const char *const script);
GSList* scripts_read(const char* const script);
gboolean scripts_exec(const char* const script);
#endif

View File

@@ -48,24 +48,24 @@
#endif
#include "common.h"
#include "log.h"
#include "config/files.h"
#include "config/theme.h"
#include "config/preferences.h"
#include "config/color.h"
#include "config/files.h"
#include "config/preferences.h"
#include "config/theme.h"
#include "log.h"
static GString *theme_loc;
static GKeyFile *theme;
static GHashTable *bold_items;
static GHashTable *defaults;
static GString* theme_loc;
static GKeyFile* theme;
static GHashTable* bold_items;
static GHashTable* defaults;
static void _load_preferences(void);
static void _theme_list_dir(const gchar *const dir, GSList **result);
static GString* _theme_find(const char *const theme_name);
static gboolean _theme_load_file(const char *const theme_name);
static void _theme_list_dir(const gchar* const dir, GSList** result);
static GString* _theme_find(const char* const theme_name);
static gboolean _theme_load_file(const char* const theme_name);
void
theme_init(const char *const theme_name)
theme_init(const char* const theme_name)
{
if (!_theme_load_file(theme_name)) {
log_error("Loading theme %s failed.", theme_name);
@@ -78,98 +78,98 @@ theme_init(const char *const theme_name)
defaults = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
// Set default colors
g_hash_table_insert(defaults, strdup("main.text"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.history"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.me"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.them"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.splash"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("main.help.header"), strdup("default"));
g_hash_table_insert(defaults, strdup("error"), strdup("red"));
g_hash_table_insert(defaults, strdup("incoming"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("mention"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("trigger"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("input.text"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.time"), strdup("default"));
g_hash_table_insert(defaults, strdup("titlebar.text"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.brackets"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("titlebar.unencrypted"), strdup("red"));
g_hash_table_insert(defaults, strdup("titlebar.encrypted"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("titlebar.trusted"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.online"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.offline"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.away"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.chat"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.dnd"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.xa"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.scrolled"), strdup("default"));
g_hash_table_insert(defaults, strdup("statusbar.text"), strdup("white"));
g_hash_table_insert(defaults, strdup("statusbar.brackets"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.current"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.new"), strdup("white"));
g_hash_table_insert(defaults, strdup("statusbar.time"), strdup("white"));
g_hash_table_insert(defaults, strdup("me"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("them"), strdup("green"));
g_hash_table_insert(defaults, strdup("receipt.sent"), strdup("red"));
g_hash_table_insert(defaults, strdup("roominfo"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roommention"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roommention.term"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roomtrigger"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roomtrigger.term"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("online"), strdup("green"));
g_hash_table_insert(defaults, strdup("offline"), strdup("red"));
g_hash_table_insert(defaults, strdup("away"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("chat"), strdup("green"));
g_hash_table_insert(defaults, strdup("dnd"), strdup("red"));
g_hash_table_insert(defaults, strdup("xa"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("typing"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("gone"), strdup("red"));
g_hash_table_insert(defaults, strdup("subscribed"), strdup("green"));
g_hash_table_insert(defaults, strdup("unsubscribed"), strdup("red"));
g_hash_table_insert(defaults, strdup("otr.started.trusted"), strdup("green"));
g_hash_table_insert(defaults, strdup("otr.started.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("otr.ended"), strdup("red"));
g_hash_table_insert(defaults, strdup("otr.trusted"), strdup("green"));
g_hash_table_insert(defaults, strdup("otr.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roster.header"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roster.online"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.online.active"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline.active"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat.active"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd.active"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.online.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline.unread"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away.unread"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd.unread"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa.unread"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.room"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.trigger"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.mention"), strdup("green"));
g_hash_table_insert(defaults, strdup("occupants.header"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("untrusted"), strdup("red"));
g_hash_table_insert(defaults, strdup("cmd.wins.unread"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.history"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.me"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.text.them"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.splash"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("main.help.header"), strdup("default"));
g_hash_table_insert(defaults, strdup("error"), strdup("red"));
g_hash_table_insert(defaults, strdup("incoming"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("mention"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("trigger"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("input.text"), strdup("default"));
g_hash_table_insert(defaults, strdup("main.time"), strdup("default"));
g_hash_table_insert(defaults, strdup("titlebar.text"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.brackets"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("titlebar.unencrypted"), strdup("red"));
g_hash_table_insert(defaults, strdup("titlebar.encrypted"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("titlebar.trusted"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.online"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.offline"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.away"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.chat"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.dnd"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.xa"), strdup("white"));
g_hash_table_insert(defaults, strdup("titlebar.scrolled"), strdup("default"));
g_hash_table_insert(defaults, strdup("statusbar.text"), strdup("white"));
g_hash_table_insert(defaults, strdup("statusbar.brackets"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.current"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("statusbar.new"), strdup("white"));
g_hash_table_insert(defaults, strdup("statusbar.time"), strdup("white"));
g_hash_table_insert(defaults, strdup("me"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("them"), strdup("green"));
g_hash_table_insert(defaults, strdup("receipt.sent"), strdup("red"));
g_hash_table_insert(defaults, strdup("roominfo"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roommention"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roommention.term"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roomtrigger"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roomtrigger.term"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("online"), strdup("green"));
g_hash_table_insert(defaults, strdup("offline"), strdup("red"));
g_hash_table_insert(defaults, strdup("away"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("chat"), strdup("green"));
g_hash_table_insert(defaults, strdup("dnd"), strdup("red"));
g_hash_table_insert(defaults, strdup("xa"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("typing"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("gone"), strdup("red"));
g_hash_table_insert(defaults, strdup("subscribed"), strdup("green"));
g_hash_table_insert(defaults, strdup("unsubscribed"), strdup("red"));
g_hash_table_insert(defaults, strdup("otr.started.trusted"), strdup("green"));
g_hash_table_insert(defaults, strdup("otr.started.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("otr.ended"), strdup("red"));
g_hash_table_insert(defaults, strdup("otr.trusted"), strdup("green"));
g_hash_table_insert(defaults, strdup("otr.untrusted"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roster.header"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roster.online"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.online.active"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline.active"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat.active"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd.active"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa.active"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.online.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.offline.unread"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.chat.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.away.unread"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.dnd.unread"), strdup("red"));
g_hash_table_insert(defaults, strdup("roster.xa.unread"), strdup("cyan"));
g_hash_table_insert(defaults, strdup("roster.room"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.unread"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.trigger"), strdup("green"));
g_hash_table_insert(defaults, strdup("roster.room.mention"), strdup("green"));
g_hash_table_insert(defaults, strdup("occupants.header"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("untrusted"), strdup("red"));
g_hash_table_insert(defaults, strdup("cmd.wins.unread"), strdup("default"));
//_load_preferences();
}
gboolean
theme_exists(const char *const theme_name)
theme_exists(const char* const theme_name)
{
if (g_strcmp0(theme_name, "default") == 0) {
return TRUE;
}
GString *new_theme_file = _theme_find(theme_name);
GString* new_theme_file = _theme_find(theme_name);
if (new_theme_file == NULL) {
return FALSE;
}
@@ -179,7 +179,7 @@ theme_exists(const char *const theme_name)
}
gboolean
theme_load(const char *const theme_name, gboolean load_theme_prefs)
theme_load(const char* const theme_name, gboolean load_theme_prefs)
{
color_pair_cache_reset();
@@ -194,7 +194,7 @@ theme_load(const char *const theme_name, gboolean load_theme_prefs)
}
static gboolean
_theme_load_file(const char *const theme_name)
_theme_load_file(const char* const theme_name)
{
// use default theme
if (theme_name == NULL || strcmp(theme_name, "default") == 0) {
@@ -203,9 +203,9 @@ _theme_load_file(const char *const theme_name)
}
theme = g_key_file_new();
// load theme from file
// load theme from file
} else {
GString *new_theme_file = _theme_find(theme_name);
GString* new_theme_file = _theme_find(theme_name);
if (new_theme_file == NULL) {
log_info("Theme does not exist \"%s\"", theme_name);
return FALSE;
@@ -221,7 +221,7 @@ _theme_load_file(const char *const theme_name)
}
theme = g_key_file_new();
g_key_file_load_from_file(theme, theme_loc->str, G_KEY_FILE_KEEP_COMMENTS,
NULL);
NULL);
}
return TRUE;
@@ -230,8 +230,8 @@ _theme_load_file(const char *const theme_name)
GSList*
theme_list(void)
{
GSList *result = NULL;
gchar *themes_dir = files_get_config_path(DIR_THEMES);
GSList* result = NULL;
gchar* themes_dir = files_get_config_path(DIR_THEMES);
_theme_list_dir(themes_dir, &result);
g_free(themes_dir);
@@ -272,17 +272,17 @@ theme_init_colours(void)
}
static void
_set_string_preference(char *prefstr, preference_t pref)
_set_string_preference(char* prefstr, preference_t pref)
{
if (g_key_file_has_key(theme, "ui", prefstr, NULL)) {
gchar *val = g_key_file_get_string(theme, "ui", prefstr, NULL);
gchar* val = g_key_file_get_string(theme, "ui", prefstr, NULL);
prefs_set_string(pref, val);
g_free(val);
}
}
static void
_set_boolean_preference(char *prefstr, preference_t pref)
_set_boolean_preference(char* prefstr, preference_t pref)
{
if (g_key_file_has_key(theme, "ui", prefstr, NULL)) {
gboolean val = g_key_file_get_boolean(theme, "ui", prefstr, NULL);
@@ -401,7 +401,7 @@ _load_preferences(void)
// load chars from theme and set them to prefs
// with custom set functions
if (g_key_file_has_key(theme, "ui", "occupants.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "occupants.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "occupants.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_occupants_char(ch[0]);
g_free(ch);
@@ -409,7 +409,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "occupants.header.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "occupants.header.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "occupants.header.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_occupants_header_char(ch[0]);
g_free(ch);
@@ -417,7 +417,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "roster.header.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_roster_header_char(ch[0]);
g_free(ch);
@@ -425,7 +425,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "roster.contact.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_roster_contact_char(ch[0]);
g_free(ch);
@@ -433,7 +433,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "roster.resource.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "roster.resource.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "roster.resource.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_roster_resource_char(ch[0]);
g_free(ch);
@@ -443,7 +443,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "roster.rooms.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "roster.rooms.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_roster_room_char(ch[0]);
g_free(ch);
@@ -451,7 +451,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "roster.rooms.private.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_roster_room_private_char(ch[0]);
g_free(ch);
@@ -459,7 +459,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "roster.private.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "roster.private.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "roster.private.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_roster_private_char(ch[0]);
g_free(ch);
@@ -467,7 +467,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "otr.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "otr.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "otr.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_otr_char(ch);
g_free(ch);
@@ -475,7 +475,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "pgp.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "pgp.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "pgp.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_pgp_char(ch);
g_free(ch);
@@ -483,7 +483,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "omemo.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "omemo.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "omemo.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_omemo_char(ch);
g_free(ch);
@@ -491,7 +491,7 @@ _load_preferences(void)
}
if (g_key_file_has_key(theme, "ui", "correction.char", NULL)) {
gchar *ch = g_key_file_get_string(theme, "ui", "correction.char", NULL);
gchar* ch = g_key_file_get_string(theme, "ui", "correction.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_correction_char(ch[0]);
g_free(ch);
@@ -499,17 +499,14 @@ _load_preferences(void)
}
// load window positions
if (g_key_file_has_key(theme, "ui", "titlebar.position", NULL) &&
g_key_file_has_key(theme, "ui", "mainwin.position", NULL) &&
g_key_file_has_key(theme, "ui", "statusbar.position", NULL) &&
g_key_file_has_key(theme, "ui", "inputwin.position", NULL)) {
if (g_key_file_has_key(theme, "ui", "titlebar.position", NULL) && g_key_file_has_key(theme, "ui", "mainwin.position", NULL) && g_key_file_has_key(theme, "ui", "statusbar.position", NULL) && g_key_file_has_key(theme, "ui", "inputwin.position", NULL)) {
int titlebar_pos = g_key_file_get_integer(theme, "ui", "titlebar.position", NULL);
int mainwin_pos = g_key_file_get_integer(theme, "ui", "mainwin.position", NULL);
int statusbar_pos = g_key_file_get_integer(theme, "ui", "statusbar.position", NULL);
int inputwin_pos = g_key_file_get_integer(theme, "ui", "inputwin.position", NULL);
ProfWinPlacement *placement = prefs_create_profwin_placement(titlebar_pos, mainwin_pos, statusbar_pos, inputwin_pos);
ProfWinPlacement* placement = prefs_create_profwin_placement(titlebar_pos, mainwin_pos, statusbar_pos, inputwin_pos);
prefs_save_win_placement(placement);
prefs_free_win_placement(placement);
@@ -517,11 +514,11 @@ _load_preferences(void)
}
static void
_theme_list_dir(const gchar *const dir, GSList **result)
_theme_list_dir(const gchar* const dir, GSList** result)
{
GDir *themes = g_dir_open(dir, 0, NULL);
GDir* themes = g_dir_open(dir, 0, NULL);
if (themes) {
const gchar *theme = g_dir_read_name(themes);
const gchar* theme = g_dir_read_name(themes);
while (theme) {
*result = g_slist_append(*result, strdup(theme));
theme = g_dir_read_name(themes);
@@ -531,10 +528,10 @@ _theme_list_dir(const gchar *const dir, GSList **result)
}
static GString*
_theme_find(const char *const theme_name)
_theme_find(const char* const theme_name)
{
GString *path = NULL;
gchar *themes_dir = files_get_config_path(DIR_THEMES);
GString* path = NULL;
gchar* themes_dir = files_get_config_path(DIR_THEMES);
if (themes_dir) {
path = g_string_new(themes_dir);
@@ -563,7 +560,7 @@ _theme_find(const char *const theme_name)
}
theme_item_t
theme_roster_unread_presence_attrs(const char *const presence)
theme_roster_unread_presence_attrs(const char* const presence)
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ROSTER_ONLINE_UNREAD;
@@ -581,7 +578,7 @@ theme_roster_unread_presence_attrs(const char *const presence)
}
theme_item_t
theme_roster_active_presence_attrs(const char *const presence)
theme_roster_active_presence_attrs(const char* const presence)
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ROSTER_ONLINE_ACTIVE;
@@ -599,7 +596,7 @@ theme_roster_active_presence_attrs(const char *const presence)
}
theme_item_t
theme_roster_presence_attrs(const char *const presence)
theme_roster_presence_attrs(const char* const presence)
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ROSTER_ONLINE;
@@ -617,7 +614,7 @@ theme_roster_presence_attrs(const char *const presence)
}
theme_item_t
theme_main_presence_attrs(const char *const presence)
theme_main_presence_attrs(const char* const presence)
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ONLINE;
@@ -635,9 +632,9 @@ theme_main_presence_attrs(const char *const presence)
}
static void
_theme_prep_bgnd(char *setting, char *def, GString *lookup_str)
_theme_prep_bgnd(char* setting, char* def, GString* lookup_str)
{
gchar *val = g_key_file_get_string(theme, "colours", setting, NULL);
gchar* val = g_key_file_get_string(theme, "colours", setting, NULL);
if (!val) {
g_string_append(lookup_str, def);
} else {
@@ -654,17 +651,17 @@ _theme_prep_bgnd(char *setting, char *def, GString *lookup_str)
char*
theme_get_bkgnd(void)
{
char *val = g_key_file_get_string(theme, "colours", "bkgnd", NULL);
char* val = g_key_file_get_string(theme, "colours", "bkgnd", NULL);
return val;
}
/* gets the foreground color from the theme. or uses the one defined in 'defaults' */
static void
_theme_prep_fgnd(char *setting, GString *lookup_str, gboolean *bold)
_theme_prep_fgnd(char* setting, GString* lookup_str, gboolean* bold)
{
gchar *val = g_key_file_get_string(theme, "colours", setting, NULL);
gchar* val = g_key_file_get_string(theme, "colours", setting, NULL);
if (!val) {
char *def = g_hash_table_lookup(defaults, setting);
char* def = g_hash_table_lookup(defaults, setting);
g_string_append(lookup_str, def);
} else {
if (g_str_has_prefix(val, "bold_")) {
@@ -679,9 +676,9 @@ _theme_prep_fgnd(char *setting, GString *lookup_str, gboolean *bold)
}
char*
theme_get_string(char *str)
theme_get_string(char* str)
{
char *res = g_key_file_get_string(theme, "colours", str, NULL);
char* res = g_key_file_get_string(theme, "colours", str, NULL);
if (!res) {
return strdup(g_hash_table_lookup(defaults, str));
} else {
@@ -690,7 +687,7 @@ theme_get_string(char *str)
}
void
theme_free_string(char *str)
theme_free_string(char* str)
{
if (str) {
g_free(str);
@@ -698,11 +695,11 @@ theme_free_string(char *str)
}
int
theme_hash_attrs(const char *str)
theme_hash_attrs(const char* str)
{
color_profile profile = COLOR_PROFILE_DEFAULT;
char *color_pref = prefs_get_string(PREF_COLOR_NICK);
char* color_pref = prefs_get_string(PREF_COLOR_NICK);
if (strcmp(color_pref, "redgreen") == 0) {
profile = COLOR_PROFILE_REDGREEN_BLINDNESS;
} else if (strcmp(color_pref, "blue") == 0) {
@@ -719,109 +716,322 @@ theme_attrs(theme_item_t attrs)
{
int result = 0;
GString *lookup_str = g_string_new("");
GString* lookup_str = g_string_new("");
gboolean bold = FALSE;
// get forground colour
switch (attrs) {
case THEME_TEXT: _theme_prep_fgnd("main.text", lookup_str, &bold); break;
case THEME_TEXT_HISTORY: _theme_prep_fgnd("main.text.history", lookup_str, &bold); break;
case THEME_TEXT_ME: _theme_prep_fgnd("main.text.me", lookup_str, &bold); break;
case THEME_TEXT_THEM: _theme_prep_fgnd("main.text.them", lookup_str, &bold); break;
case THEME_SPLASH: _theme_prep_fgnd("main.splash", lookup_str, &bold); break;
case THEME_TRACKBAR: _theme_prep_fgnd("main.trackbar", lookup_str, &bold); break;
case THEME_HELP_HEADER: _theme_prep_fgnd("main.help.header", lookup_str, &bold); break;
case THEME_ERROR: _theme_prep_fgnd("error", lookup_str, &bold); break;
case THEME_INCOMING: _theme_prep_fgnd("incoming", lookup_str, &bold); break;
case THEME_MENTION: _theme_prep_fgnd("mention", lookup_str, &bold); break;
case THEME_TRIGGER: _theme_prep_fgnd("trigger", lookup_str, &bold); break;
case THEME_INPUT_TEXT: _theme_prep_fgnd("input.text", lookup_str, &bold); break;
case THEME_TIME: _theme_prep_fgnd("main.time", lookup_str, &bold); break;
case THEME_TITLE_TEXT: _theme_prep_fgnd("titlebar.text", lookup_str, &bold); break;
case THEME_TITLE_BRACKET: _theme_prep_fgnd("titlebar.brackets", lookup_str, &bold); break;
case THEME_TITLE_SCROLLED: _theme_prep_fgnd("titlebar.scrolled", lookup_str, &bold); break;
case THEME_TITLE_UNENCRYPTED: _theme_prep_fgnd("titlebar.unencrypted", lookup_str, &bold); break;
case THEME_TITLE_ENCRYPTED: _theme_prep_fgnd("titlebar.encrypted", lookup_str, &bold); break;
case THEME_TITLE_UNTRUSTED: _theme_prep_fgnd("titlebar.untrusted", lookup_str, &bold); break;
case THEME_TITLE_TRUSTED: _theme_prep_fgnd("titlebar.trusted", lookup_str, &bold); break;
case THEME_TITLE_ONLINE: _theme_prep_fgnd("titlebar.online", lookup_str, &bold); break;
case THEME_TITLE_OFFLINE: _theme_prep_fgnd("titlebar.offline", lookup_str, &bold); break;
case THEME_TITLE_AWAY: _theme_prep_fgnd("titlebar.away", lookup_str, &bold); break;
case THEME_TITLE_CHAT: _theme_prep_fgnd("titlebar.chat", lookup_str, &bold); break;
case THEME_TITLE_DND: _theme_prep_fgnd("titlebar.dnd", lookup_str, &bold); break;
case THEME_TITLE_XA: _theme_prep_fgnd("titlebar.xa", lookup_str, &bold); break;
case THEME_STATUS_TEXT: _theme_prep_fgnd("statusbar.text", lookup_str, &bold); break;
case THEME_STATUS_BRACKET: _theme_prep_fgnd("statusbar.brackets", lookup_str, &bold); break;
case THEME_STATUS_ACTIVE: _theme_prep_fgnd("statusbar.active", lookup_str, &bold); break;
case THEME_STATUS_CURRENT: _theme_prep_fgnd("statusbar.current", lookup_str, &bold); break;
case THEME_STATUS_NEW: _theme_prep_fgnd("statusbar.new", lookup_str, &bold); break;
case THEME_STATUS_TIME: _theme_prep_fgnd("statusbar.time", lookup_str, &bold); break;
case THEME_ME: _theme_prep_fgnd("me", lookup_str, &bold); break;
case THEME_THEM: _theme_prep_fgnd("them", lookup_str, &bold); break;
case THEME_RECEIPT_SENT: _theme_prep_fgnd("receipt.sent", lookup_str, &bold); break;
case THEME_ROOMINFO: _theme_prep_fgnd("roominfo", lookup_str, &bold); break;
case THEME_ROOMMENTION: _theme_prep_fgnd("roommention", lookup_str, &bold); break;
case THEME_ROOMMENTION_TERM: _theme_prep_fgnd("roommention.term", lookup_str, &bold); break;
case THEME_ROOMTRIGGER: _theme_prep_fgnd("roomtrigger", lookup_str, &bold); break;
case THEME_ROOMTRIGGER_TERM: _theme_prep_fgnd("roomtrigger.term", lookup_str, &bold); break;
case THEME_ONLINE: _theme_prep_fgnd("online", lookup_str, &bold); break;
case THEME_OFFLINE: _theme_prep_fgnd("offline", lookup_str, &bold); break;
case THEME_AWAY: _theme_prep_fgnd("away", lookup_str, &bold); break;
case THEME_CHAT: _theme_prep_fgnd("chat", lookup_str, &bold); break;
case THEME_DND: _theme_prep_fgnd("dnd", lookup_str, &bold); break;
case THEME_XA: _theme_prep_fgnd("xa", lookup_str, &bold); break;
case THEME_TYPING: _theme_prep_fgnd("typing", lookup_str, &bold); break;
case THEME_GONE: _theme_prep_fgnd("gone", lookup_str, &bold); break;
case THEME_SUBSCRIBED: _theme_prep_fgnd("subscribed", lookup_str, &bold); break;
case THEME_UNSUBSCRIBED: _theme_prep_fgnd("unsubscribed", lookup_str, &bold); break;
case THEME_OTR_STARTED_TRUSTED: _theme_prep_fgnd("otr.started.trusted", lookup_str, &bold); break;
case THEME_OTR_STARTED_UNTRUSTED: _theme_prep_fgnd("otr.started.untrusted", lookup_str, &bold); break;
case THEME_OTR_ENDED: _theme_prep_fgnd("otr.ended", lookup_str, &bold); break;
case THEME_OTR_TRUSTED: _theme_prep_fgnd("otr.trusted", lookup_str, &bold); break;
case THEME_OTR_UNTRUSTED: _theme_prep_fgnd("otr.untrusted", lookup_str, &bold); break;
case THEME_ROSTER_HEADER: _theme_prep_fgnd("roster.header", lookup_str, &bold); break;
case THEME_ROSTER_ONLINE: _theme_prep_fgnd("roster.online", lookup_str, &bold); break;
case THEME_ROSTER_OFFLINE: _theme_prep_fgnd("roster.offline", lookup_str, &bold); break;
case THEME_ROSTER_CHAT: _theme_prep_fgnd("roster.chat", lookup_str, &bold); break;
case THEME_ROSTER_AWAY: _theme_prep_fgnd("roster.away", lookup_str, &bold); break;
case THEME_ROSTER_DND: _theme_prep_fgnd("roster.dnd", lookup_str, &bold); break;
case THEME_ROSTER_XA: _theme_prep_fgnd("roster.xa", lookup_str, &bold); break;
case THEME_ROSTER_ONLINE_ACTIVE: _theme_prep_fgnd("roster.online.active", lookup_str, &bold); break;
case THEME_ROSTER_OFFLINE_ACTIVE: _theme_prep_fgnd("roster.offline.active", lookup_str, &bold); break;
case THEME_ROSTER_CHAT_ACTIVE: _theme_prep_fgnd("roster.chat.active", lookup_str, &bold); break;
case THEME_ROSTER_AWAY_ACTIVE: _theme_prep_fgnd("roster.away.active", lookup_str, &bold); break;
case THEME_ROSTER_DND_ACTIVE: _theme_prep_fgnd("roster.dnd.active", lookup_str, &bold); break;
case THEME_ROSTER_XA_ACTIVE: _theme_prep_fgnd("roster.xa.active", lookup_str, &bold); break;
case THEME_ROSTER_ONLINE_UNREAD: _theme_prep_fgnd("roster.online.unread", lookup_str, &bold); break;
case THEME_ROSTER_OFFLINE_UNREAD: _theme_prep_fgnd("roster.offline.unread", lookup_str, &bold); break;
case THEME_ROSTER_CHAT_UNREAD: _theme_prep_fgnd("roster.chat.unread", lookup_str, &bold); break;
case THEME_ROSTER_AWAY_UNREAD: _theme_prep_fgnd("roster.away.unread", lookup_str, &bold); break;
case THEME_ROSTER_DND_UNREAD: _theme_prep_fgnd("roster.dnd.unread", lookup_str, &bold); break;
case THEME_ROSTER_XA_UNREAD: _theme_prep_fgnd("roster.xa.unread", lookup_str, &bold); break;
case THEME_ROSTER_ROOM: _theme_prep_fgnd("roster.room", lookup_str, &bold); break;
case THEME_ROSTER_ROOM_UNREAD: _theme_prep_fgnd("roster.room.unread", lookup_str, &bold); break;
case THEME_ROSTER_ROOM_TRIGGER: _theme_prep_fgnd("roster.room.trigger", lookup_str, &bold); break;
case THEME_ROSTER_ROOM_MENTION: _theme_prep_fgnd("roster.room.mention", lookup_str, &bold); break;
case THEME_OCCUPANTS_HEADER: _theme_prep_fgnd("occupants.header", lookup_str, &bold); break;
case THEME_UNTRUSTED: _theme_prep_fgnd("untrusted", lookup_str, &bold); break;
case THEME_CMD_WINS_UNREAD: _theme_prep_fgnd("cmd.wins.unread", lookup_str, &bold); break;
case THEME_WHITE: g_string_append(lookup_str, "white"); bold = FALSE; break;
case THEME_WHITE_BOLD: g_string_append(lookup_str, "white"); bold = TRUE; break;
case THEME_GREEN: g_string_append(lookup_str, "green"); bold = FALSE; break;
case THEME_GREEN_BOLD: g_string_append(lookup_str, "green"); bold = TRUE; break;
case THEME_RED: g_string_append(lookup_str, "red"); bold = FALSE; break;
case THEME_RED_BOLD: g_string_append(lookup_str, "red"); bold = TRUE; break;
case THEME_YELLOW: g_string_append(lookup_str, "yellow"); bold = FALSE; break;
case THEME_YELLOW_BOLD: g_string_append(lookup_str, "yellow"); bold = TRUE; break;
case THEME_BLUE: g_string_append(lookup_str, "blue"); bold = FALSE; break;
case THEME_BLUE_BOLD: g_string_append(lookup_str, "blue"); bold = TRUE; break;
case THEME_CYAN: g_string_append(lookup_str, "cyan"); bold = FALSE; break;
case THEME_CYAN_BOLD: g_string_append(lookup_str, "cyan"); bold = TRUE; break;
case THEME_BLACK: g_string_append(lookup_str, "black"); bold = FALSE; break;
case THEME_BLACK_BOLD: g_string_append(lookup_str, "black"); bold = TRUE; break;
case THEME_MAGENTA: g_string_append(lookup_str, "magenta"); bold = FALSE; break;
case THEME_MAGENTA_BOLD: g_string_append(lookup_str, "magenta"); bold = TRUE; break;
default: g_string_append(lookup_str, "default"); bold = FALSE; break;
case THEME_TEXT:
_theme_prep_fgnd("main.text", lookup_str, &bold);
break;
case THEME_TEXT_HISTORY:
_theme_prep_fgnd("main.text.history", lookup_str, &bold);
break;
case THEME_TEXT_ME:
_theme_prep_fgnd("main.text.me", lookup_str, &bold);
break;
case THEME_TEXT_THEM:
_theme_prep_fgnd("main.text.them", lookup_str, &bold);
break;
case THEME_SPLASH:
_theme_prep_fgnd("main.splash", lookup_str, &bold);
break;
case THEME_TRACKBAR:
_theme_prep_fgnd("main.trackbar", lookup_str, &bold);
break;
case THEME_HELP_HEADER:
_theme_prep_fgnd("main.help.header", lookup_str, &bold);
break;
case THEME_ERROR:
_theme_prep_fgnd("error", lookup_str, &bold);
break;
case THEME_INCOMING:
_theme_prep_fgnd("incoming", lookup_str, &bold);
break;
case THEME_MENTION:
_theme_prep_fgnd("mention", lookup_str, &bold);
break;
case THEME_TRIGGER:
_theme_prep_fgnd("trigger", lookup_str, &bold);
break;
case THEME_INPUT_TEXT:
_theme_prep_fgnd("input.text", lookup_str, &bold);
break;
case THEME_TIME:
_theme_prep_fgnd("main.time", lookup_str, &bold);
break;
case THEME_TITLE_TEXT:
_theme_prep_fgnd("titlebar.text", lookup_str, &bold);
break;
case THEME_TITLE_BRACKET:
_theme_prep_fgnd("titlebar.brackets", lookup_str, &bold);
break;
case THEME_TITLE_SCROLLED:
_theme_prep_fgnd("titlebar.scrolled", lookup_str, &bold);
break;
case THEME_TITLE_UNENCRYPTED:
_theme_prep_fgnd("titlebar.unencrypted", lookup_str, &bold);
break;
case THEME_TITLE_ENCRYPTED:
_theme_prep_fgnd("titlebar.encrypted", lookup_str, &bold);
break;
case THEME_TITLE_UNTRUSTED:
_theme_prep_fgnd("titlebar.untrusted", lookup_str, &bold);
break;
case THEME_TITLE_TRUSTED:
_theme_prep_fgnd("titlebar.trusted", lookup_str, &bold);
break;
case THEME_TITLE_ONLINE:
_theme_prep_fgnd("titlebar.online", lookup_str, &bold);
break;
case THEME_TITLE_OFFLINE:
_theme_prep_fgnd("titlebar.offline", lookup_str, &bold);
break;
case THEME_TITLE_AWAY:
_theme_prep_fgnd("titlebar.away", lookup_str, &bold);
break;
case THEME_TITLE_CHAT:
_theme_prep_fgnd("titlebar.chat", lookup_str, &bold);
break;
case THEME_TITLE_DND:
_theme_prep_fgnd("titlebar.dnd", lookup_str, &bold);
break;
case THEME_TITLE_XA:
_theme_prep_fgnd("titlebar.xa", lookup_str, &bold);
break;
case THEME_STATUS_TEXT:
_theme_prep_fgnd("statusbar.text", lookup_str, &bold);
break;
case THEME_STATUS_BRACKET:
_theme_prep_fgnd("statusbar.brackets", lookup_str, &bold);
break;
case THEME_STATUS_ACTIVE:
_theme_prep_fgnd("statusbar.active", lookup_str, &bold);
break;
case THEME_STATUS_CURRENT:
_theme_prep_fgnd("statusbar.current", lookup_str, &bold);
break;
case THEME_STATUS_NEW:
_theme_prep_fgnd("statusbar.new", lookup_str, &bold);
break;
case THEME_STATUS_TIME:
_theme_prep_fgnd("statusbar.time", lookup_str, &bold);
break;
case THEME_ME:
_theme_prep_fgnd("me", lookup_str, &bold);
break;
case THEME_THEM:
_theme_prep_fgnd("them", lookup_str, &bold);
break;
case THEME_RECEIPT_SENT:
_theme_prep_fgnd("receipt.sent", lookup_str, &bold);
break;
case THEME_ROOMINFO:
_theme_prep_fgnd("roominfo", lookup_str, &bold);
break;
case THEME_ROOMMENTION:
_theme_prep_fgnd("roommention", lookup_str, &bold);
break;
case THEME_ROOMMENTION_TERM:
_theme_prep_fgnd("roommention.term", lookup_str, &bold);
break;
case THEME_ROOMTRIGGER:
_theme_prep_fgnd("roomtrigger", lookup_str, &bold);
break;
case THEME_ROOMTRIGGER_TERM:
_theme_prep_fgnd("roomtrigger.term", lookup_str, &bold);
break;
case THEME_ONLINE:
_theme_prep_fgnd("online", lookup_str, &bold);
break;
case THEME_OFFLINE:
_theme_prep_fgnd("offline", lookup_str, &bold);
break;
case THEME_AWAY:
_theme_prep_fgnd("away", lookup_str, &bold);
break;
case THEME_CHAT:
_theme_prep_fgnd("chat", lookup_str, &bold);
break;
case THEME_DND:
_theme_prep_fgnd("dnd", lookup_str, &bold);
break;
case THEME_XA:
_theme_prep_fgnd("xa", lookup_str, &bold);
break;
case THEME_TYPING:
_theme_prep_fgnd("typing", lookup_str, &bold);
break;
case THEME_GONE:
_theme_prep_fgnd("gone", lookup_str, &bold);
break;
case THEME_SUBSCRIBED:
_theme_prep_fgnd("subscribed", lookup_str, &bold);
break;
case THEME_UNSUBSCRIBED:
_theme_prep_fgnd("unsubscribed", lookup_str, &bold);
break;
case THEME_OTR_STARTED_TRUSTED:
_theme_prep_fgnd("otr.started.trusted", lookup_str, &bold);
break;
case THEME_OTR_STARTED_UNTRUSTED:
_theme_prep_fgnd("otr.started.untrusted", lookup_str, &bold);
break;
case THEME_OTR_ENDED:
_theme_prep_fgnd("otr.ended", lookup_str, &bold);
break;
case THEME_OTR_TRUSTED:
_theme_prep_fgnd("otr.trusted", lookup_str, &bold);
break;
case THEME_OTR_UNTRUSTED:
_theme_prep_fgnd("otr.untrusted", lookup_str, &bold);
break;
case THEME_ROSTER_HEADER:
_theme_prep_fgnd("roster.header", lookup_str, &bold);
break;
case THEME_ROSTER_ONLINE:
_theme_prep_fgnd("roster.online", lookup_str, &bold);
break;
case THEME_ROSTER_OFFLINE:
_theme_prep_fgnd("roster.offline", lookup_str, &bold);
break;
case THEME_ROSTER_CHAT:
_theme_prep_fgnd("roster.chat", lookup_str, &bold);
break;
case THEME_ROSTER_AWAY:
_theme_prep_fgnd("roster.away", lookup_str, &bold);
break;
case THEME_ROSTER_DND:
_theme_prep_fgnd("roster.dnd", lookup_str, &bold);
break;
case THEME_ROSTER_XA:
_theme_prep_fgnd("roster.xa", lookup_str, &bold);
break;
case THEME_ROSTER_ONLINE_ACTIVE:
_theme_prep_fgnd("roster.online.active", lookup_str, &bold);
break;
case THEME_ROSTER_OFFLINE_ACTIVE:
_theme_prep_fgnd("roster.offline.active", lookup_str, &bold);
break;
case THEME_ROSTER_CHAT_ACTIVE:
_theme_prep_fgnd("roster.chat.active", lookup_str, &bold);
break;
case THEME_ROSTER_AWAY_ACTIVE:
_theme_prep_fgnd("roster.away.active", lookup_str, &bold);
break;
case THEME_ROSTER_DND_ACTIVE:
_theme_prep_fgnd("roster.dnd.active", lookup_str, &bold);
break;
case THEME_ROSTER_XA_ACTIVE:
_theme_prep_fgnd("roster.xa.active", lookup_str, &bold);
break;
case THEME_ROSTER_ONLINE_UNREAD:
_theme_prep_fgnd("roster.online.unread", lookup_str, &bold);
break;
case THEME_ROSTER_OFFLINE_UNREAD:
_theme_prep_fgnd("roster.offline.unread", lookup_str, &bold);
break;
case THEME_ROSTER_CHAT_UNREAD:
_theme_prep_fgnd("roster.chat.unread", lookup_str, &bold);
break;
case THEME_ROSTER_AWAY_UNREAD:
_theme_prep_fgnd("roster.away.unread", lookup_str, &bold);
break;
case THEME_ROSTER_DND_UNREAD:
_theme_prep_fgnd("roster.dnd.unread", lookup_str, &bold);
break;
case THEME_ROSTER_XA_UNREAD:
_theme_prep_fgnd("roster.xa.unread", lookup_str, &bold);
break;
case THEME_ROSTER_ROOM:
_theme_prep_fgnd("roster.room", lookup_str, &bold);
break;
case THEME_ROSTER_ROOM_UNREAD:
_theme_prep_fgnd("roster.room.unread", lookup_str, &bold);
break;
case THEME_ROSTER_ROOM_TRIGGER:
_theme_prep_fgnd("roster.room.trigger", lookup_str, &bold);
break;
case THEME_ROSTER_ROOM_MENTION:
_theme_prep_fgnd("roster.room.mention", lookup_str, &bold);
break;
case THEME_OCCUPANTS_HEADER:
_theme_prep_fgnd("occupants.header", lookup_str, &bold);
break;
case THEME_UNTRUSTED:
_theme_prep_fgnd("untrusted", lookup_str, &bold);
break;
case THEME_CMD_WINS_UNREAD:
_theme_prep_fgnd("cmd.wins.unread", lookup_str, &bold);
break;
case THEME_WHITE:
g_string_append(lookup_str, "white");
bold = FALSE;
break;
case THEME_WHITE_BOLD:
g_string_append(lookup_str, "white");
bold = TRUE;
break;
case THEME_GREEN:
g_string_append(lookup_str, "green");
bold = FALSE;
break;
case THEME_GREEN_BOLD:
g_string_append(lookup_str, "green");
bold = TRUE;
break;
case THEME_RED:
g_string_append(lookup_str, "red");
bold = FALSE;
break;
case THEME_RED_BOLD:
g_string_append(lookup_str, "red");
bold = TRUE;
break;
case THEME_YELLOW:
g_string_append(lookup_str, "yellow");
bold = FALSE;
break;
case THEME_YELLOW_BOLD:
g_string_append(lookup_str, "yellow");
bold = TRUE;
break;
case THEME_BLUE:
g_string_append(lookup_str, "blue");
bold = FALSE;
break;
case THEME_BLUE_BOLD:
g_string_append(lookup_str, "blue");
bold = TRUE;
break;
case THEME_CYAN:
g_string_append(lookup_str, "cyan");
bold = FALSE;
break;
case THEME_CYAN_BOLD:
g_string_append(lookup_str, "cyan");
bold = TRUE;
break;
case THEME_BLACK:
g_string_append(lookup_str, "black");
bold = FALSE;
break;
case THEME_BLACK_BOLD:
g_string_append(lookup_str, "black");
bold = TRUE;
break;
case THEME_MAGENTA:
g_string_append(lookup_str, "magenta");
bold = FALSE;
break;
case THEME_MAGENTA_BOLD:
g_string_append(lookup_str, "magenta");
bold = TRUE;
break;
default:
g_string_append(lookup_str, "default");
bold = FALSE;
break;
}
g_string_append(lookup_str, "_");

View File

@@ -143,20 +143,20 @@ typedef enum {
THEME_TRACKBAR,
} theme_item_t;
void theme_init(const char *const theme_name);
void theme_init(const char* const theme_name);
void theme_init_colours(void);
gboolean theme_load(const char *const theme_name, gboolean load_theme_prefs);
gboolean theme_exists(const char *const theme_name);
gboolean theme_load(const char* const theme_name, gboolean load_theme_prefs);
gboolean theme_exists(const char* const theme_name);
GSList* theme_list(void);
void theme_close(void);
int theme_hash_attrs(const char *str);
int theme_hash_attrs(const char* str);
int theme_attrs(theme_item_t attrs);
char* theme_get_string(char *str);
void theme_free_string(char *str);
theme_item_t theme_main_presence_attrs(const char *const presence);
theme_item_t theme_roster_unread_presence_attrs(const char *const presence);
theme_item_t theme_roster_active_presence_attrs(const char *const presence);
theme_item_t theme_roster_presence_attrs(const char *const presence);
char* theme_get_string(char* str);
void theme_free_string(char* str);
theme_item_t theme_main_presence_attrs(const char* const presence);
theme_item_t theme_roster_unread_presence_attrs(const char* const presence);
theme_item_t theme_roster_active_presence_attrs(const char* const presence);
theme_item_t theme_roster_presence_attrs(const char* const presence);
char* theme_get_bkgnd(void);
#endif

View File

@@ -39,20 +39,20 @@
#include <glib.h>
#include <glib/gstdio.h>
#include "log.h"
#include "common.h"
#include "config/files.h"
#include "config/tlscerts.h"
#include "log.h"
#include "tools/autocomplete.h"
static char *tlscerts_loc;
static GKeyFile *tlscerts;
static char* tlscerts_loc;
static GKeyFile* tlscerts;
static void _save_tlscerts(void);
static Autocomplete certs_ac;
static char *current_fp;
static char* current_fp;
void
tlscerts_init(void)
@@ -69,7 +69,7 @@ tlscerts_init(void)
certs_ac = autocomplete_new();
gsize len = 0;
gchar **groups = g_key_file_get_groups(tlscerts, &len);
gchar** groups = g_key_file_get_groups(tlscerts, &len);
int i = 0;
for (i = 0; i < g_strv_length(groups); i++) {
@@ -81,7 +81,7 @@ tlscerts_init(void)
}
void
tlscerts_set_current(const char *const fp)
tlscerts_set_current(const char* const fp)
{
if (current_fp) {
free(current_fp);
@@ -105,7 +105,7 @@ tlscerts_clear_current(void)
}
gboolean
tlscerts_exists(const char *const fingerprint)
tlscerts_exists(const char* const fingerprint)
{
return g_key_file_has_group(tlscerts, fingerprint);
}
@@ -113,24 +113,24 @@ tlscerts_exists(const char *const fingerprint)
GList*
tlscerts_list(void)
{
GList *res = NULL;
GList* res = NULL;
gsize len = 0;
gchar **groups = g_key_file_get_groups(tlscerts, &len);
gchar** groups = g_key_file_get_groups(tlscerts, &len);
int i = 0;
for (i = 0; i < g_strv_length(groups); i++) {
char *fingerprint = strdup(groups[i]);
char* fingerprint = strdup(groups[i]);
int version = g_key_file_get_integer(tlscerts, fingerprint, "version", NULL);
char *serialnumber = g_key_file_get_string(tlscerts, fingerprint, "serialnumber", NULL);
char *subjectname = g_key_file_get_string(tlscerts, fingerprint, "subjectname", NULL);
char *issuername = g_key_file_get_string(tlscerts, fingerprint, "issuername", NULL);
char *notbefore = g_key_file_get_string(tlscerts, fingerprint, "start", NULL);
char *notafter = g_key_file_get_string(tlscerts, fingerprint, "end", NULL);
char *keyalg = g_key_file_get_string(tlscerts, fingerprint, "keyalg", NULL);
char *signaturealg = g_key_file_get_string(tlscerts, fingerprint, "signaturealg", NULL);
char* serialnumber = g_key_file_get_string(tlscerts, fingerprint, "serialnumber", NULL);
char* subjectname = g_key_file_get_string(tlscerts, fingerprint, "subjectname", NULL);
char* issuername = g_key_file_get_string(tlscerts, fingerprint, "issuername", NULL);
char* notbefore = g_key_file_get_string(tlscerts, fingerprint, "start", NULL);
char* notafter = g_key_file_get_string(tlscerts, fingerprint, "end", NULL);
char* keyalg = g_key_file_get_string(tlscerts, fingerprint, "keyalg", NULL);
char* signaturealg = g_key_file_get_string(tlscerts, fingerprint, "signaturealg", NULL);
TLSCertificate *cert = tlscerts_new(fingerprint, version, serialnumber, subjectname, issuername, notbefore,
notafter, keyalg, signaturealg);
TLSCertificate* cert = tlscerts_new(fingerprint, version, serialnumber, subjectname, issuername, notbefore,
notafter, keyalg, signaturealg);
free(fingerprint);
free(serialnumber);
@@ -152,11 +152,11 @@ tlscerts_list(void)
}
TLSCertificate*
tlscerts_new(const char *const fingerprint, int version, const char *const serialnumber, const char *const subjectname,
const char *const issuername, const char *const notbefore, const char *const notafter,
const char *const key_alg, const char *const signature_alg)
tlscerts_new(const char* const fingerprint, int version, const char* const serialnumber, const char* const subjectname,
const char* const issuername, const char* const notbefore, const char* const notafter,
const char* const key_alg, const char* const signature_alg)
{
TLSCertificate *cert = malloc(sizeof(TLSCertificate));
TLSCertificate* cert = malloc(sizeof(TLSCertificate));
if (fingerprint) {
cert->fingerprint = strdup(fingerprint);
@@ -287,7 +287,7 @@ tlscerts_new(const char *const fingerprint, int version, const char *const seria
}
void
tlscerts_add(TLSCertificate *cert)
tlscerts_add(TLSCertificate* cert)
{
if (!cert) {
return;
@@ -326,9 +326,9 @@ tlscerts_add(TLSCertificate *cert)
}
gboolean
tlscerts_revoke(const char *const fingerprint)
tlscerts_revoke(const char* const fingerprint)
{
gboolean result = g_key_file_remove_group(tlscerts, fingerprint, NULL);
gboolean result = g_key_file_remove_group(tlscerts, fingerprint, NULL);
if (result) {
autocomplete_remove(certs_ac, fingerprint);
}
@@ -339,23 +339,23 @@ tlscerts_revoke(const char *const fingerprint)
}
TLSCertificate*
tlscerts_get_trusted(const char * const fingerprint)
tlscerts_get_trusted(const char* const fingerprint)
{
if (!g_key_file_has_group(tlscerts, fingerprint)) {
return NULL;
}
int version = g_key_file_get_integer(tlscerts, fingerprint, "version", NULL);
char *serialnumber = g_key_file_get_string(tlscerts, fingerprint, "serialnumber", NULL);
char *subjectname = g_key_file_get_string(tlscerts, fingerprint, "subjectname", NULL);
char *issuername = g_key_file_get_string(tlscerts, fingerprint, "issuername", NULL);
char *notbefore = g_key_file_get_string(tlscerts, fingerprint, "start", NULL);
char *notafter = g_key_file_get_string(tlscerts, fingerprint, "end", NULL);
char *keyalg = g_key_file_get_string(tlscerts, fingerprint, "keyalg", NULL);
char *signaturealg = g_key_file_get_string(tlscerts, fingerprint, "signaturealg", NULL);
char* serialnumber = g_key_file_get_string(tlscerts, fingerprint, "serialnumber", NULL);
char* subjectname = g_key_file_get_string(tlscerts, fingerprint, "subjectname", NULL);
char* issuername = g_key_file_get_string(tlscerts, fingerprint, "issuername", NULL);
char* notbefore = g_key_file_get_string(tlscerts, fingerprint, "start", NULL);
char* notafter = g_key_file_get_string(tlscerts, fingerprint, "end", NULL);
char* keyalg = g_key_file_get_string(tlscerts, fingerprint, "keyalg", NULL);
char* signaturealg = g_key_file_get_string(tlscerts, fingerprint, "signaturealg", NULL);
TLSCertificate *cert = tlscerts_new(fingerprint, version, serialnumber, subjectname, issuername, notbefore,
notafter, keyalg, signaturealg);
TLSCertificate* cert = tlscerts_new(fingerprint, version, serialnumber, subjectname, issuername, notbefore,
notafter, keyalg, signaturealg);
free(serialnumber);
free(subjectname);
@@ -369,7 +369,7 @@ tlscerts_get_trusted(const char * const fingerprint)
}
char*
tlscerts_complete(const char *const prefix, gboolean previous, void *context)
tlscerts_complete(const char* const prefix, gboolean previous, void* context)
{
return autocomplete_complete(certs_ac, prefix, TRUE, previous);
}
@@ -381,7 +381,7 @@ tlscerts_reset_ac(void)
}
void
tlscerts_free(TLSCertificate *cert)
tlscerts_free(TLSCertificate* cert)
{
if (cert) {
free(cert->serialnumber);
@@ -433,7 +433,7 @@ static void
_save_tlscerts(void)
{
gsize g_data_size;
gchar *g_tlscerts_data = g_key_file_to_data(tlscerts, &g_data_size, NULL);
gchar* g_tlscerts_data = g_key_file_to_data(tlscerts, &g_data_size, NULL);
g_file_set_contents(tlscerts_loc, g_tlscerts_data, g_data_size, NULL);
g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR);
g_free(g_tlscerts_data);

View File

@@ -38,59 +38,60 @@
#include <glib.h>
typedef struct tls_cert_t {
typedef struct tls_cert_t
{
int version;
char *serialnumber;
char *subjectname;
char *subject_country;
char *subject_state;
char *subject_distinguishedname;
char *subject_serialnumber;
char *subject_commonname;
char *subject_organisation;
char *subject_organisation_unit;
char *subject_email;
char *issuername;
char *issuer_country;
char *issuer_state;
char *issuer_distinguishedname;
char *issuer_serialnumber;
char *issuer_commonname;
char *issuer_organisation;
char *issuer_organisation_unit;
char *issuer_email;
char *notbefore;
char *notafter;
char *fingerprint;
char *key_alg;
char *signature_alg;
char* serialnumber;
char* subjectname;
char* subject_country;
char* subject_state;
char* subject_distinguishedname;
char* subject_serialnumber;
char* subject_commonname;
char* subject_organisation;
char* subject_organisation_unit;
char* subject_email;
char* issuername;
char* issuer_country;
char* issuer_state;
char* issuer_distinguishedname;
char* issuer_serialnumber;
char* issuer_commonname;
char* issuer_organisation;
char* issuer_organisation_unit;
char* issuer_email;
char* notbefore;
char* notafter;
char* fingerprint;
char* key_alg;
char* signature_alg;
} TLSCertificate;
void tlscerts_init(void);
TLSCertificate* tlscerts_new(const char *const fingerprint, int version, const char *const serialnumber, const char *const subjectname,
const char *const issuername, const char *const notbefore, const char *const notafter,
const char *const key_alg, const char *const signature_alg);
TLSCertificate* tlscerts_new(const char* const fingerprint, int version, const char* const serialnumber, const char* const subjectname,
const char* const issuername, const char* const notbefore, const char* const notafter,
const char* const key_alg, const char* const signature_alg);
void tlscerts_set_current(const char *const fp);
void tlscerts_set_current(const char* const fp);
char* tlscerts_get_current(void);
void tlscerts_clear_current(void);
gboolean tlscerts_exists(const char *const fingerprint);
gboolean tlscerts_exists(const char* const fingerprint);
void tlscerts_add(TLSCertificate *cert);
void tlscerts_add(TLSCertificate* cert);
gboolean tlscerts_revoke(const char *const fingerprint);
gboolean tlscerts_revoke(const char* const fingerprint);
TLSCertificate* tlscerts_get_trusted(const char *const fingerprint);
TLSCertificate* tlscerts_get_trusted(const char* const fingerprint);
void tlscerts_free(TLSCertificate *cert);
void tlscerts_free(TLSCertificate* cert);
GList* tlscerts_list(void);
char* tlscerts_complete(const char *const prefix, gboolean previous, void *context);
char* tlscerts_complete(const char* const prefix, gboolean previous, void* context);
void tlscerts_reset_ac(void);