wmail: handle allocation failures.
[dockapps.git] / wmradio / rc.c
blob52568d6dc324b72dc9df9cfb7349f271cb153392
1 /*
2 * Copyright (C) 12 Jun 2003 Tomas Cermak
4 * This file is part of wmradio program.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "rc.h"
22 #include "const.h"
23 #include "skin.h"
24 #include "stationnames.h"
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <locale.h>
29 #include "ini.h"
31 List *ini = NULL;
33 void rc_set_variable(char *sec, char *var, char *val)
35 ini = ini_set_variable(ini,sec,var,val);
38 char *rc_get_variable(char *sec, char *var, char *def)
40 return ini_get_variable(ini,sec,var,def);
43 int rc_get_variable_as_int(char *sec, char *var, int def)
45 return ini_get_variable_as_int(ini,sec,var,def);
48 void rc_set_variable_as_int(char *sec, char *var, int value)
50 ini = ini_set_variable_as_int(ini,sec,var,value);
53 void rc_save_config(void)
55 char rcfile[256];
57 setlocale(LC_ALL,"C");
58 snprintf(rcfile,sizeof(rcfile),"%s/.wmradio",getenv("HOME"));
59 ini_save_file(ini,rcfile);
62 void rc_read_config(void)
64 char rcfile[256];
66 snprintf(rcfile,sizeof(rcfile),"%s/.wmradio",getenv("HOME"));
67 ini = ini_load_file(NULL,"config",rcfile);
70 void rc_set_variable_as_pseudofloat(char *section, char *variable, int value)
72 IniVariable *i;
74 ini = ini_set_variable(ini,section,variable,freqtostr(value));
75 i = ini_get_variable_ini_variable(ini,section,variable);
76 if(i) i->value_int = value;
79 int rc_get_variable_as_pseudofloat(char *section, char *variable, int dflt)
81 IniVariable *i;
83 i = ini_get_variable_ini_variable(ini,section,variable);
84 if(!i) return dflt;
85 if(i->value_int == INI_INT_UNDEFINED) i->value_int = ato100i(i->value);
86 return i->value_int;
89 int rc_get_freq(int index)
91 char buffer[10];
93 snprintf(buffer,sizeof(buffer),"preset%i",index);
94 return rc_get_variable_as_pseudofloat(SECTION_CONFIG,buffer,9700);
97 void rc_set_freq(int index, int value)
99 char buffer[10];
101 snprintf(buffer,sizeof(buffer),"preset%i",index);
102 rc_set_variable_as_pseudofloat(SECTION_CONFIG,buffer,value);
105 IniVariable *rc_get_variable_ini_variable(char *section, char *variable)
107 return ini_get_variable_ini_variable(ini,section,variable);
110 IniSection *rc_get_section(char *section)
112 return ini_get_section(ini,section);
115 void rc_free_config(void)
117 ini_free(ini);