[go: up one dir, main page]

Menu

[3793f0]: / src / encodings.c  Maximize  Restore  History

Download this file

128 lines (103 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
roxterm - VTE/GTK terminal emulator with tabs
Copyright (C) 2004-2011 Tony Houghton <h@realh.co.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "defns.h"
#include <string.h>
#include "dynopts.h"
#include "encodings.h"
#include "optsfile.h"
static const char *encodings_group_name = "roxterm encodings";
static const char *encodings_get_key(int n)
{
static char key[16];
sprintf(key, "e%d", n);
return key;
}
static GPtrArray *encodings_build_default(void)
{
GPtrArray *enc = g_ptr_array_sized_new(2);
g_ptr_array_add(enc, (char *) "ISO-8859-1");
g_ptr_array_add(enc, (char *) "UTF-8");
return enc;
}
static int encodings_compare(const char const **penc1,
const char const **penc2)
{
return dynamic_options_strcmp(*penc1, *penc2);
}
Encodings *encodings_load(void)
{
char *filename = options_file_build_filename("Encodings", NULL);
if (filename)
{
GKeyFile *kf = options_file_open("Encodings", encodings_group_name);
int count = options_file_lookup_int_with_default(kf,
encodings_group_name, "n", 0);
GPtrArray *enc = g_ptr_array_sized_new(count);
int n;
for (n = 0; n < count; ++n)
{
char *v = options_file_lookup_string_with_default(kf,
encodings_group_name, encodings_get_key(n), NULL);
g_ptr_array_add(enc, v);
}
g_free(filename);
g_key_file_free(kf);
g_ptr_array_sort(enc, (GCompareFunc) encodings_compare);
return enc;
}
else
{
return encodings_build_default();
}
}
void encodings_save(Encodings *enc)
{
GKeyFile *kf = g_key_file_new();
int n;
g_key_file_set_integer(kf, encodings_group_name, "n", enc->len);
for (n = 0; n < enc->len; ++n)
{
g_key_file_set_string(kf, encodings_group_name,
encodings_get_key(n), g_ptr_array_index(enc, n));
}
options_file_save(kf, "Encodings");
g_key_file_free(kf);
}
char const **encodings_list(Encodings *enc)
{
int n = encodings_count(enc);
int m;
char const **list;
list = g_new(char const *, n + 2);
list[0] = g_strdup("Default");
for (m = 0; m < n; ++m)
{
list[m + 1] = encodings_lookup(enc, m);
}
list[n + 1] = NULL;
return list;
}
void encodings_add(Encodings *enc, const char *v)
{
g_ptr_array_add(enc, g_strdup(v));
g_ptr_array_sort(enc, (GCompareFunc) encodings_compare);
}
void encodings_change(Encodings *enc, int n, const char *v)
{
encodings_remove(enc, n);
encodings_add(enc, v);
}
/* vi:set sw=4 ts=4 noet cindent cino= */