Fixing things - Alex
[terminatorX.git] / src / tX_global.c
index 49b2272445a08d55f6fb6a07df108aa5d3ab3284..de281dab24a8cc87a743bb1aacdff320b837121a 100644 (file)
 #include "string.h"
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
+#include <libxml/encoding.h>
+
 
 #define TX_XML_RC_VERSION "1.0"
 
 tx_global globals;
+int _store_compress_xml=0;
 
 void get_rc_name(char *buffer)
 {
@@ -67,11 +70,10 @@ void set_global_defaults() {
        globals.no_gui = 0;
        globals.alternate_rc = 0;
        
-       
        strcpy(globals.xinput_device, "");
        globals.xinput_enable=0;
        
-       globals.update_idle=18;
+       globals.update_idle=14;
        globals.update_delay=1;
        
        strcpy(globals.oss_device, "/dev/dsp");
@@ -79,12 +81,12 @@ void set_global_defaults() {
        globals.oss_buff_size=9;
        globals.oss_samplerate=44100;
 
-       strcpy(globals.alsa_device, "hw:0,0");  
-       globals.alsa_buff_no=2;
-       globals.alsa_buff_size=1024;
+       strcpy(globals.alsa_device, "00-00: Default");  
+       globals.alsa_buffer_time=10000;
+       globals.alsa_period_time=5000;
        globals.alsa_samplerate=44100;
        
-       globals.sense_cycles=12;
+       globals.sense_cycles=80;
        
        globals.mouse_speed=0.8;
        
@@ -126,9 +128,10 @@ void set_global_defaults() {
        globals.current_path = NULL;
        globals.pitch=1.0;
        globals.volume=1.0;
-       globals.fullscreen_enabled=1;
        
-       if (!globals.true_block_size) globals.true_block_size=1<globals.oss_buff_size;
+       strcpy(globals.lrdf_path, "/usr/share/ladspa/rdf:/usr/local/share/ladspa/rdf");
+       globals.fullscreen_enabled=1;
+       globals.compress_set_files=0;
 }
 
 int load_globals_xml() {
@@ -138,7 +141,8 @@ int load_globals_xml() {
        xmlNodePtr cur;
        int elementFound;
        double dvalue;
-
+       char tmp_xml_buffer[4096];
+       
        get_rc_name(rc_name);
        
        doc = xmlParseFile(rc_name);
@@ -176,8 +180,8 @@ int load_globals_xml() {
                        restore_int("oss_samplerate", globals.oss_samplerate);
 
                        restore_string("alsa_device", globals.alsa_device);
-                       restore_int("alsa_buff_no", globals.alsa_buff_no);
-                       restore_int("alsa_buff_size", globals.alsa_buff_size);
+                       restore_int("alsa_buffer_time", globals.alsa_buffer_time);
+                       restore_int("alsa_period_time", globals.alsa_period_time);
                        restore_int("alsa_samplerate", globals.alsa_samplerate);
 
                        restore_string("xinput_device", globals.xinput_device);
@@ -197,10 +201,12 @@ int load_globals_xml() {
                        restore_float("volume", globals.volume);
                        restore_float("flash_response", globals.flash_response);
                        restore_int("button_type", globals.button_type);
-                       restore_int("true_block_size", globals.true_block_size);
                        restore_string("tables_filename", globals.tables_filename);
                        restore_string("record_filename", globals.record_filename);
                        restore_string("file_editor", globals.file_editor);
+                       restore_string("lrdf_path", globals.lrdf_path);
+                       
+                       restore_int("compress_set_files", globals.compress_set_files);
                        restore_int("fullscreen_enabled", globals.fullscreen_enabled);
 
                        if (!elementFound) {
@@ -223,6 +229,8 @@ void store_globals() {
        char device_type[16];
        char indent[]="\t";
        FILE *rc;
+       gzFile rz;
+       _store_compress_xml=0;
        char tmp_xml_buffer[4096];
        
        get_rc_name(rc_name);
@@ -243,7 +251,7 @@ void store_globals() {
        }
        
        if (rc) {               
-               fprintf(rc, "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n\n");
+               fprintf(rc, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n");
                fprintf(rc, "<!-- Warning: this file will be rewritten by terminatorX on exit!\n     Don\'t waste your time adding comments - they will be erased -->\n\n" );
                fprintf(rc, "<terminatorXrc version=\"%s\">\n", TX_XML_RC_VERSION);
 
@@ -257,8 +265,8 @@ void store_globals() {
                store_int("oss_samplerate", globals.oss_samplerate);
 
                store_string("alsa_device", globals.alsa_device);
-               store_int("alsa_buff_no", globals.alsa_buff_no);
-               store_int("alsa_buff_size", globals.alsa_buff_size);
+               store_int("alsa_buffer_time", globals.alsa_buffer_time);
+               store_int("alsa_period_time", globals.alsa_period_time);
                store_int("alsa_samplerate", globals.alsa_samplerate);          
                
                store_string("xinput_device", globals.xinput_device);
@@ -279,10 +287,11 @@ void store_globals() {
                store_float("volume", globals.volume);
                store_float("flash_response", globals.flash_response);
                store_int("button_type", globals.button_type);
-               store_int("true_block_size", globals.true_block_size);
                store_string("tables_filename", globals.tables_filename);
                store_string("record_filename", globals.record_filename);
                store_string("file_editor", globals.file_editor);
+               store_string("lrdf_path", globals.lrdf_path);
+               store_int("compress_set_files", globals.compress_set_files);
                store_int("fullscreen_enabled", globals.fullscreen_enabled);
                
                fprintf(rc,"</terminatorXrc>\n");
@@ -306,23 +315,47 @@ void load_globals() {
 
 char *encode_xml(char *dest, const char *src) {
        int i, t, max;
+       char tmp[4096];
        
-       dest[0]=0;
+       tmp[0]=0;
        t=0;
        max=strlen(src);
        
        for (i=0; i<max; i++) {
                switch (src[i]) {
-                       case '<': dest[t]=0; strcat(dest, "&lt;"); t+=4; break;
-                       case '>': dest[t]=0; strcat(dest, "&gt;"); t+=4; break;
-                       case '&': dest[t]=0; strcat(dest, "&amp;"); t+=5; break;
-                       case '"': dest[t]=0; strcat(dest, "&quot;"); t+=6; break;
-                       case '\'': strcat(dest, "&apos;"); t+=7; break;
-                       default: dest[t]=src[i]; t++;
+                       case '<': tmp[t]=0; strcat(tmp, "&lt;"); t+=4; break;
+                       case '>': tmp[t]=0; strcat(tmp, "&gt;"); t+=4; break;
+                       case '&': tmp[t]=0; strcat(tmp, "&amp;"); t+=5; break;
+                       case '"': tmp[t]=0; strcat(tmp, "&quot;"); t+=6; break;
+                       case '\'': strcat(tmp, "&apos;"); t+=7; break;
+                       default: tmp[t]=src[i]; t++;
                }
        }
-       dest[t]=0;
+       tmp[t]=0;
+
+       int outlen=4096;
+       int inlen=t;
+       
+       int res=isolat1ToUTF8((unsigned char *) dest, &outlen, (unsigned char *) tmp, &inlen);
+       dest[outlen]=0;
+       if (res<0) {
+               tX_error("failed to encode string (%s) to UTF-8.", src);
+       }
        
        //tX_debug("encode_xml: from \"%s\" to \"%s\".", src, dest); 
        return dest;
 }
+
+char *decode_xml(char *dest, const char *src) {
+       int inlen=strlen(src);
+       int outlen=4096;
+       
+       int res=UTF8Toisolat1(dest, &outlen, src, &inlen);
+       dest[outlen]=0;
+       
+       if (res<0) {
+               tX_error("failed to decode UTF-8 string (%s).", src);
+       }
+       
+       return dest;
+}