4ae920685a984f6f82d99b917446b98a1f02b72d
[melted_gui] / src / opts.c
1 /*
2 * opts.c -- GTK+ 2 omnplay
3 * Copyright (C) 2011 Maksym Veremeyenko <verem@m1stereo.tv>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <getopt.h>
27
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30
31 #include "opts.h"
32
33 static const char short_options [] = "h";
34 static const struct option long_options [] =
35 {
36 { "directory", required_argument, NULL, '0'},
37 { "player", required_argument, NULL, '1'},
38 { "library", required_argument, NULL, '2'},
39 { "whois", required_argument, NULL, '3'},
40 { "id-display-rate", required_argument, NULL, '4'},
41 { "help", no_argument, NULL, 'h'},
42 { 0, 0, 0, 0}
43 };
44
45
46
47 int omnplay_opt(int argc, char** argv, omnplay_instance_t* app)
48 {
49 char* p;
50 int c, index = 0;
51
52 /* setup defaults */
53 app->library.id_display_rate = 20;
54
55 /* reset datas */
56 optind = 0; opterr = 0; optopt = 0;
57
58 /* program arguments processing */
59 while(1)
60 {
61 c = getopt_long (argc, argv, short_options, long_options, &index);
62
63 if((-1) == c) break;
64
65 switch(c)
66 {
67 case 0: break;
68
69 /** --direcotry */
70 case '0':
71 strncpy(app->players.path, optarg, PATH_MAX);
72 break;
73
74 /** --player */
75 case '1':
76 p = strchr(optarg, '@');
77 if(p)
78 {
79 *p = 0;
80 strncpy(app->players.item[app->players.count].name, optarg, PATH_MAX);
81 strncpy(app->players.item[app->players.count].host, p + 1, PATH_MAX);
82 app->players.item[app->players.count].idx = app->players.count;
83 app->players.item[app->players.count].app = app;
84 app->players.count++;
85 };
86 break;
87
88 /** --library */
89 case '2':
90 strncpy(app->library.filename, optarg, PATH_MAX);
91 break;
92
93 /** --whois */
94 case '3':
95 strncpy(app->library.whois, optarg, PATH_MAX);
96 break;
97
98 /** --id-display-rate */
99 case '4':
100 app->library.id_display_rate = atol(optarg);
101 break;
102
103 default:
104 fprintf(stderr, "ERROR: Incorrect argument!\n");
105 return 1;
106 break;
107 };
108 };
109
110 return 0;
111 };
112
113 void omnplay_usage(void)
114 {
115 fprintf
116 (
117 stderr,
118 "Usage:\n"
119 "\t--directory=<PATH> Directory to override default\n"
120 "\t--player=<STRING> Player to use in a form <player_name>@<mediadirector host>\n"
121 "\t--whois=<URL> Whois service URL\n"
122 "\t--library=<PATH> File used for library storage\n"
123 "\t--id-display-rate=<NUM> Rate of id displaying during server content requesting\n"
124 );
125 };