audiod: free pointer to config file path.
[paraslash.git] / sdl_gui.c
index a1381c2..6aa7854 100644 (file)
--- a/sdl_gui.c
+++ b/sdl_gui.c
@@ -1,19 +1,7 @@
 /*
- * Copyright (C) 2003-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2003-2007 Andre Noll <maan@systemlinux.org>
  *
- *     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, USA.
+ * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file sdl_gui.c SDL-based interface for paraslash */
@@ -43,7 +31,7 @@ static int width = 0;
 static int height = 0;
 
 extern const char *status_item_list[NUM_STAT_ITEMS];
-struct gengetopt_args_info args_info;
+struct sdl_gui_args_info args_info;
 
 #define FRAME_WIDTH 10
 #define FONT_HEIGHT 36
@@ -119,7 +107,7 @@ struct font fonts[] = {
 
 static struct stat_item stat_items[NUM_STAT_ITEMS];
 
-void para_log(__unused int ll, __unused const char* fmt,...) /* no logging */
+void para_log(__a_unused int ll, __a_unused const char* fmt,...) /* no logging */
 {
 }
 
@@ -356,7 +344,7 @@ static void init_SDL(void)
        SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
        /* Set the window manager title bar */
        SDL_WM_SetCaption("The Gui of death that makes you blind (paraslash "
-               VERSION ")", "SFont");
+               PACKAGE_VERSION ")", "SFont");
 }
 
 /*
@@ -505,7 +493,7 @@ static SDLKey hit_key(const char *msg)
  */
 static int command_handler(void)
 {
-       FILE *pipe;
+       FILE *f;
        unsigned count = 0;
        char text[MAXLINE]="";
        char buf[MAXLINE]="";
@@ -521,15 +509,15 @@ static int command_handler(void)
        if (text[0] == '!') {
                if (text[1] == '\0')
                        return 1;
-               pipe = popen(text + 1, "r");
+               f = popen(text + 1, "r");
        } else {
                sprintf(buf, BINDIR "/para_client %s 2>&1", text);
-               pipe = popen(buf, "r");
+               f = popen(buf, "r");
        }
-       if (!pipe)
+       if (!f)
                return 0;
        fill_output_rect();
-       while(fgets(text, MAXLINE - 1, pipe)) {
+       while(fgets(text, MAXLINE - 1, f)) {
                int len;
 
                tab2space(text);
@@ -554,7 +542,7 @@ static int command_handler(void)
        update_all();
        hit_key("Hit any key to return");
 out:   fill_output_rect();
-       pclose(pipe);
+       pclose(f);
        return 1;
 }
 
@@ -585,14 +573,14 @@ SDL_Surface *load_jpg(void)
        SDL_RWops *rwop;
        int fds[3] = {0, 1, 0};
        pid_t pid;
-       FILE *pipe;
+       FILE *f;
 
        if (para_exec_cmdline_pid(&pid, args_info.pic_cmd_arg, fds) < 0)
                return NULL;
-       pipe = fdopen(fds[1], "r");
-       if (!pipe)
+       f = fdopen(fds[1], "r");
+       if (!f)
                return NULL;
-       if (!(rwop = SDL_RWFromFP(pipe, 0)))
+       if (!(rwop = SDL_RWFromFP(f, 0)))
                return NULL;
        return IMG_LoadJPG_RW(rwop);
 }
@@ -689,7 +677,7 @@ void update_status(char *buf)
  * Read stat line from pipe if pipe is ready, call update_status to
  * display information.
  */
-static int draw_status(int pipe)
+static int draw_status(int fd)
 {
        fd_set rfds;
        int ret;
@@ -698,11 +686,11 @@ static int draw_status(int pipe)
        tv.tv_sec = 0;
        tv.tv_usec = 3000000;
        FD_ZERO(&rfds);
-       FD_SET(pipe, &rfds);
-       ret = para_select(pipe + 1, &rfds, NULL, &tv);
+       FD_SET(fd, &rfds);
+       ret = para_select(fd + 1, &rfds, NULL, &tv);
        if (ret <= 0)
                return 0;
-       if (read_audiod_pipe(pipe, update_status) > 0)
+       if (read_audiod_pipe(fd, update_status) > 0)
                return 1;
        free(stat_items[SI_STATUS_BAR].content);
        stat_items[SI_STATUS_BAR].content =
@@ -739,10 +727,11 @@ static int configfile_exists(void)
  */
 int main(int argc, char *argv[])
 {
-       int i, ret, pipe;
+       int i, ret, fd = -1;
        SDLKey sym;
 
-       cmdline_parser(argc, argv, &args_info);
+       sdl_gui_cmdline_parser(argc, argv, &args_info);
+       HANDLE_VERSION_FLAG("sdl_gui", args_info);
        ret = configfile_exists();
 //     printf("w=%i,h=%i,ret=%i, cf=%s\n", width, height, ret, args_info.config_file_arg);
 
@@ -751,15 +740,21 @@ int main(int argc, char *argv[])
                        args_info.config_file_arg);
                exit(EXIT_FAILURE);
        }
-       if (ret)
-               cmdline_parser_configfile(args_info.config_file_arg,
-                       &args_info, 0, 0, 0);
+       if (ret) {
+               struct sdl_gui_cmdline_parser_params params = {
+                       .override = 0,
+                       .initialize = 0,
+                       .check_required = 0,
+                       .check_ambiguity = 0
+               };
+               sdl_gui_cmdline_parser_config_file(args_info.config_file_arg,
+                       &args_info, &params);
+       }
        signal(SIGCHLD, SIG_IGN);
        width = args_info.width_arg;
        height = args_info.height_arg;
 //     printf("w=%i,h=%i,ret=%i, cf=%s\n", width, height, ret, args_info.config_file_arg);
        init_stat_items();
-       pipe = para_open_audiod_pipe(args_info.stat_cmd_arg);
        init_SDL();
        for (i = 0; fonts[i].name[0]; i++) {
                char buf[MAXLINE];
@@ -775,10 +770,15 @@ int main(int argc, char *argv[])
                update_input();
        }
        for (;;) {
-               ret = draw_status(pipe);
+               if (fd < 0) {
+                       fd = para_open_audiod_pipe(args_info.stat_cmd_arg);
+                       if (fd < 0)
+                               clean_exit(EXIT_FAILURE);
+               }
+               ret = draw_status(fd);
                if (ret < 0) {
-                       close(pipe);
-                       pipe = -1;
+                       close(fd);
+                       fd = -1;
                }
                if (SDL_QuitRequested())
                        clean_exit(0);
@@ -802,12 +802,6 @@ int main(int argc, char *argv[])
                                || sym == SDLK_COMPOSE
                                )
                                continue;
-                       if (pipe < 0) {
-//                             printf("closing pipe\n");
-                               kill(0, SIGINT);
-                               close(pipe);
-//                             printf("pipe closed\n");
-                       }
                        fill_input_rect();
                        update_input();
                        if (!command_handler())
@@ -816,7 +810,6 @@ int main(int argc, char *argv[])
                        print_help();
                        update_pic();
                        SDL_UpdateRect(screen, 0, 0, 0, 0);
-                       pipe = para_open_audiod_pipe(args_info.stat_cmd_arg);
                        break;
                }
        }