Code

way too much stuff to describe here
[ncmpc.git] / src / conf.c
index 0069489fa08856f2bf9aae46c64be9a28ef70f37..df0ac546564e055f8b5ef5ca231f8111f0717415 100644 (file)
@@ -38,8 +38,6 @@
 #include "colors.h"
 #include "conf.h"
 
-#define ENABLE_OLD_SYNTAX
-
 #define MAX_LINE_LENGTH 1024
 #define COMMENT_TOKEN   '#'
 
 #define CONF_COLOR_DEFINITION        "colordef"
 #define CONF_LIST_FORMAT             "list-format"
 #define CONF_STATUS_FORMAT           "status-format"
+#define CONF_XTERM_TITLE_FORMAT      "xterm-title-format"
 #define CONF_LIST_WRAP               "wrap-around"
 #define CONF_FIND_WRAP               "find-wrap"
+#define CONF_FIND_SHOW_LAST          "find-show-last"
 #define CONF_AUDIBLE_BELL            "audible-bell"
 #define CONF_VISIBLE_BELL            "visible-bell"
 #define CONF_XTERM_TITLE             "set-xterm-title"
-
-/* Deprecated - configuration field names */
-#define OLD_CONF_ENABLE_COLORS       "enable_colors"
-#define OLD_CONF_AUTO_CENTER         "auto_center"
-#define OLD_CONF_WIDE_CURSOR         "wide_cursor"
-#define CONF_COLOR_BACKGROUND        "background_color"
-#define CONF_COLOR_TITLE             "title_color"
-#define CONF_COLOR_LINE              "line_color"
-#define CONF_COLOR_LIST              "list_color"
-#define CONF_COLOR_PROGRESS          "progress_color"
-#define CONF_COLOR_STATUS            "status_color"
-#define CONF_COLOR_ALERT             "alert_color"
-
+#define CONF_ENABLE_MOUSE            "enable-mouse"
+#define CONF_CROSSFADE_TIME          "crossfade-time"
+#define CONF_SEARCH_MODE             "search-mode"
+#define CONF_HIDE_CURSOR             "hide-cursor"
+#define CONF_SEEK_TIME               "seek-time"
+#define CONF_SCREEN_LIST             "screen-list"
+#define CONF_TIMEDISPLAY_TYPE        "timedisplay-type"
+#define CONF_HOST                    "host"
+#define CONF_PORT                    "port"
+#define CONF_PASSWORD                "password"
+#define CONF_LYRICS_TIMEOUT          "lyrics-timeout"
+#define CONF_SHOW_SPLASH             "show-splash"
+#define CONF_SCROLL                  "scroll"
+#define CONF_SCROLL_SEP              "scroll-sep"
 
 typedef enum {
   KEY_PARSER_UNKNOWN,
@@ -80,6 +81,10 @@ typedef enum {
   KEY_PARSER_DONE
 } key_parser_state_t;
 
+
+extern gint screen_get_id(char *name);
+
+
 static gboolean
 str2bool(char *str)
 {
@@ -143,7 +148,7 @@ parse_key_value(char *str, size_t len, char **end)
        case KEY_PARSER_HEX:
          if( !isdigit(next) )
            {
-             fprintf(stderr,_("Error: Digit expexted after 0x - %s\n"), str);
+             fprintf(stderr,_("Error: Digit expected after 0x - %s\n"), str);
              return -1;
            }
          value = (int) strtol(str+(i+1), end, 16);
@@ -189,7 +194,7 @@ parse_key_definition(char *str)
 
   /* get the value part */
   memset(buf, 0, MAX_LINE_LENGTH);
-  strncpy(buf, str+i, len-i);
+  g_strlcpy(buf, str+i, MAX_LINE_LENGTH);
   len = strlen(buf);
   if( len==0 )
     {
@@ -220,6 +225,17 @@ parse_key_definition(char *str)
   return assign_keys(cmd, keys);
 }
 
+static char *
+parse_timedisplay_type(char *str)
+{
+ if((!strcmp(str,"elapsed")) || (!strcmp(str,"remaining"))){
+   return str;
+ } else {
+   fprintf(stderr,_("Error: Bad time display type - %s\n"), str);
+   return DEFAULT_TIMEDISPLAY_TYPE;
+ }
+}
+
 static int
 parse_color(char *str)
 {
@@ -246,7 +262,6 @@ parse_color(char *str)
   return colors_assign(name, value);
 }
 
-
 static int
 parse_color_definition(char *str)
 {
@@ -276,7 +291,7 @@ parse_color_definition(char *str)
 
   /* get the value part */
   memset(buf, 0, MAX_LINE_LENGTH);
-  strncpy(buf, str+i, len-i);
+  g_strlcpy(buf, str+i, MAX_LINE_LENGTH);
   len = strlen(buf);
   if( len==0 )
     {
@@ -323,6 +338,36 @@ get_format(char *str)
   return g_strdup(str);
 }
 
+static char **
+check_screen_list(char *value)
+{
+  char **tmp = g_strsplit_set(value, " \t,", 100);
+  char **screen = NULL;
+  int i,j;
+
+  i=0;
+  j=0;
+  while( tmp && tmp[i] )
+    {
+      tmp[i] = lowerstr(tmp[i]);
+      if( screen_get_id(tmp[i]) == -1 )
+       fprintf(stderr,
+               _("Error: Unsupported screen \"%s\"\n"), 
+               tmp[i]);
+      else
+       {
+         screen = g_realloc(screen, (j+2)*sizeof(char *));
+         screen[j++] = g_strdup(tmp[i]);
+         screen[j] = NULL;
+       }
+      i++;
+    }
+  g_strfreev(tmp);
+  if( screen == NULL )
+    return g_strsplit_set(DEFAULT_SCREEN_LIST, " ", 0);
+
+  return screen;
+}
 
 static int
 read_rc_file(char *filename, options_t *options)
@@ -428,75 +473,18 @@ read_rc_file(char *filename, options_t *options)
                {
                  parse_color(value);
                }
-#ifdef ENABLE_OLD_SYNTAX
-             /* background color */
-             else if( !strcasecmp(CONF_COLOR_BACKGROUND, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
-                 colors_assign("background", value);
-               }
-             /* color - top (title) window */
-             else if( !strcasecmp(CONF_COLOR_TITLE, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
-                 colors_assign("title", value);
-                 colors_assign("title2", value);
-               }
-             /* color - line (title) window */
-             else if( !strcasecmp(CONF_COLOR_LINE, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
-                 colors_assign("line", value);
-                 colors_assign("line2", value);
-               }
-             /* color - list window */
-             else if( !strcasecmp(CONF_COLOR_LIST, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
-                 colors_assign("list", value);
-               }
-             /* color - progress bar */
-             else if( !strcasecmp(CONF_COLOR_PROGRESS, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
-                 colors_assign("progressbar", value);
-               }
-             /* color - status window */
-             else if( !strcasecmp(CONF_COLOR_STATUS, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
-                 colors_assign("status", value);
-                 colors_assign("status2", value);
-               }
-             /* color - alerts */
-             else if( !strcasecmp(CONF_COLOR_ALERT, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
-                 colors_assign("alert", value);
-               }
-             /* enable colors */
-             else if( !strcasecmp(OLD_CONF_ENABLE_COLORS, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated - use %s!\n", filename, name, CONF_ENABLE_COLORS);
-                 options->enable_colors = str2bool(value);
-               }
-             /* auto center */
-             else if( !strcasecmp(OLD_CONF_AUTO_CENTER, name) )
-               {
-                 fprintf(stderr,"%s: %s deprecated - use %s!\n", filename, name, CONF_AUTO_CENTER);
-                 options->auto_center = str2bool(value);
-               }
              /* wide cursor */
-             else if( !strcasecmp(OLD_CONF_WIDE_CURSOR, name) )
+             else if( !strcasecmp(CONF_WIDE_CURSOR, name) )
                {
-                 fprintf(stderr,"%s: %s deprecated - use %s!\n", filename, name, CONF_WIDE_CURSOR);
                  options->wide_cursor = str2bool(value);
                }
-#endif
-             /* wide cursor */
-             else if( !strcasecmp(CONF_WIDE_CURSOR, name) )
+             /* timer display type */
+             else if( !strcasecmp(CONF_TIMEDISPLAY_TYPE, name) )
                {
-                 options->wide_cursor = str2bool(value);
+                   g_free(options->timedisplay_type);
+                   options->timedisplay_type=g_strdup(parse_timedisplay_type(value));
+                   D("deb");
+                   D(options->timedisplay_type);
                }
              /* color definition */
              else if( !strcasecmp(CONF_COLOR_DEFINITION, name) )
@@ -515,6 +503,12 @@ read_rc_file(char *filename, options_t *options)
                  g_free(options->status_format);
                  options->status_format = get_format(value);
                }
+             /* xterm title format string */
+             else if( !strcasecmp(CONF_XTERM_TITLE_FORMAT, name) )
+               {
+                 g_free(options->xterm_title_format);
+                 options->xterm_title_format = get_format(value);
+               }
              else if( !strcasecmp(CONF_LIST_WRAP, name) )
                {
                  options->list_wrap = str2bool(value);
@@ -523,6 +517,10 @@ read_rc_file(char *filename, options_t *options)
                {
                  options->find_wrap = str2bool(value);
                }
+             else if( !strcasecmp(CONF_FIND_SHOW_LAST,name) )
+               {
+                 options->find_show_last_pattern = str2bool(value);
+               }
              else if( !strcasecmp(CONF_AUDIBLE_BELL, name) )
                {
                  options->audible_bell = str2bool(value);
@@ -535,23 +533,79 @@ read_rc_file(char *filename, options_t *options)
                {
                  options->enable_xterm_title = str2bool(value);
                }
+             else if( !strcasecmp(CONF_ENABLE_MOUSE, name) )
+               {
+                 options->enable_mouse = str2bool(value);
+               }
+             else if( !strcasecmp(CONF_CROSSFADE_TIME, name) )
+               {
+                 options->crossfade_time = atoi(value);
+               }
+             else if( !strcasecmp(CONF_SEARCH_MODE, name) )
+               {
+                 options->search_mode = atoi(value);
+               }
+             else if( !strcasecmp(CONF_HIDE_CURSOR, name) )
+               {
+                 options->hide_cursor = atoi(value);
+               }
+             else if( !strcasecmp(CONF_SEEK_TIME, name) )
+               {
+                 options->seek_time = atoi(value);
+               }
+             else if( !strcasecmp(CONF_SCREEN_LIST, name) )
+               {
+                 g_strfreev(options->screen_list);
+                 options->screen_list = check_screen_list(value);
+               }
+             else if( !strcasecmp(CONF_SHOW_SPLASH, name) )
+               {
+                 options->show_splash = str2bool(value);
+                         
+#ifdef DEBUG
+                 D("screen-list:"); 
+                 j=0;
+                 while(options->screen_list[j])
+                   D(" %s", options->screen_list[j++]);
+                 D("\n"); 
+#endif
+               }
+           else if( !strcasecmp(CONF_HOST, name))
+           {
+           options->host = get_format(value);
+           }
+           else if( !strcasecmp(CONF_PORT, name))
+           {
+           options->port = atoi(get_format(value));
+           }
+           else if( !strcasecmp(CONF_PASSWORD, name))
+             {
+               options->password = get_format(value);
+             }
+           else if( !strcasecmp(CONF_LYRICS_TIMEOUT, name))
+           {
+           options->lyrics_timeout = atoi(get_format(value));
+           }           
+           else if( !strcasecmp(CONF_SCROLL, name))
+           {
+           options->scroll = str2bool(value);
+           }
+           else if( !strcasecmp(CONF_SCROLL_SEP, name))
+           {
+           g_free(options->scroll_sep);
+           options->scroll_sep = get_format(value);
+           }
              else
                {
                  match_found = 0;
                }
-             
 
              if( !match_found )
                fprintf(stderr, 
                        _("Unknown configuration parameter: %s\n"), 
                        name);
-#ifdef DEBUG
-             printf( "  %s = %s %s\n", 
-                     name, 
-                     value,
-                     match_found ? "" : "- UNKNOWN SETTING!" );
-#endif
-
+             D("conf>  %s = %s %s\n", name, value,
+               match_found ? "" : "- UNKNOWN SETTING!" );
            }
        }         
     }
@@ -663,6 +717,3 @@ read_configuration(options_t *options)
 
   return 0;
 }
-
-
-