00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #include "stdinc.h"
00032
00033 #include "audio_output.h"
00034 #include "config.h"
00035 #include "dbus.h"
00036 #include "gui.h"
00037 #include "playq.h"
00038 #include "scrobbler.h"
00039 #include "vfs.h"
00040
00044 static void
00045 version(void)
00046 {
00047 g_printerr(APP_NAME " " APP_VERSION
00048 " (Two-clause BSD license"
00049 #if defined(BUILD_AO) || defined(BUILD_MP3) || defined(BUILD_SNDFILE)
00050 ", using GNU GPL licensed libraries"
00051 #endif
00052 ")\n\n"
00053 "%s: " CONFFILE "\n"
00054 "%s: " AUDIO_OUTPUT "\n"
00055 "%s: %s\n"
00056 "%s: %s\n"
00057 "%s: %s\n"
00058 "%s: %s\n"
00059 "%s:\n"
00060 #ifdef BUILD_VORBIS
00061 "- Ogg Vorbis\n"
00062 #endif
00063 #ifdef BUILD_MP3
00064 "- MP3\n"
00065 #endif
00066 #ifdef BUILD_MODPLUG
00067 "- libmodplug\n"
00068 #endif
00069 #ifdef BUILD_SNDFILE
00070 "- libsndfile\n"
00071 #endif
00072 ,
00073 _("Global configuration file"),
00074 _("Audio output"),
00075 _("Support for AudioScrobbler"),
00076 #ifdef BUILD_SCROBBLER
00077 _("yes"),
00078 #else
00079 _("no"),
00080 #endif
00081 _("Support for DBus integration"),
00082 #ifdef BUILD_DBUS
00083 _("yes"),
00084 #else
00085 _("no"),
00086 #endif
00087 _("Support for HTTP streams"),
00088 #ifdef BUILD_HTTP
00089 _("yes"),
00090 #else
00091 _("no"),
00092 #endif
00093 _("Support for XSPF playlists (`spiff')"),
00094 #ifdef BUILD_XSPF
00095 _("yes"),
00096 #else
00097 _("no"),
00098 #endif
00099 _("Supported audio file formats"));
00100
00101 exit(0);
00102 }
00103
00107 static void
00108 usage(void)
00109 {
00110 g_printerr("%s: " APP_NAME " [-pvx] [-c configfile] "
00111 "[file ...]\n", _("usage"));
00112 exit(1);
00113 }
00114
00118 int
00119 main(int argc, char *argv[])
00120 {
00121 int ch, i, show_version = 0, autoplay = 0, xmms = 0;
00122 char *cwd;
00123 const char *errmsg;
00124 struct vfsref *vr;
00125 #ifdef CLOSE_STDERR
00126 int devnull;
00127 #endif
00128
00129 #ifdef BUILD_NLS
00130 setlocale(LC_ALL, "");
00131 bindtextdomain(APP_NAME, TRANSDIR);
00132 textdomain(APP_NAME);
00133 #endif
00134
00135
00136 config_load(CONFFILE, 1);
00137 config_load(CONFHOMEDIR "config", 1);
00138
00139 while ((ch = getopt(argc, argv, "c:pvx")) != -1) {
00140 switch (ch) {
00141 case 'c':
00142 config_load(optarg, 0);
00143 break;
00144 case 'p':
00145 autoplay = 1;
00146 break;
00147 case 'v':
00148 show_version = 1;
00149 break;
00150 case 'x':
00151 xmms = 1;
00152 break;
00153 default:
00154 usage();
00155 }
00156 }
00157 argc -= optind;
00158 argv += optind;
00159
00160 if (show_version)
00161 version();
00162
00163 g_thread_init(NULL);
00164
00165 if (audio_output_open() != 0)
00166 return (-1);
00167
00168
00169 gui_draw_init_pre();
00170
00171 #ifdef CLOSE_STDERR
00172 devnull = open("/dev/null", O_WRONLY);
00173 #endif
00174 if ((errmsg = vfs_lockup()) != NULL) {
00175 gui_draw_init_abort();
00176 g_printerr("%s", errmsg);
00177 return (1);
00178 }
00179
00180
00181 #ifdef BUILD_DBUS
00182 dbus_init();
00183 #endif
00184 #ifdef BUILD_SCROBBLER
00185 scrobbler_init();
00186 #endif
00187 playq_init(autoplay, xmms, (argc == 0));
00188
00189
00190 gui_draw_init_post();
00191
00192 cwd = g_get_current_dir();
00193 for (i = 0; i < argc; i++) {
00194
00195 if ((vr = vfs_lookup(argv[i], NULL, cwd, 1)) != NULL) {
00196 playq_song_add_tail(vr);
00197 vfs_close(vr);
00198 }
00199 }
00200 g_free(cwd);
00201
00202 #ifdef CLOSE_STDERR
00203
00204 dup2(devnull, STDERR_FILENO);
00205 close(devnull);
00206 #endif
00207
00208
00209 playq_spawn();
00210 #ifdef BUILD_DBUS
00211 dbus_spawn();
00212 #endif
00213 #ifdef BUILD_SCROBBLER
00214 scrobbler_spawn();
00215 #endif
00216
00217
00218 gui_input_loop();
00219 g_assert_not_reached();
00220 return (1);
00221 }