fix README
[melted_gui] / src / opts.c
1 /*
2 * opts.c -- GTK+ 2 melted gui
3 * Copyright (C) 2012 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 { "host", required_argument, NULL, '0'},
37 { "unit", required_argument, NULL, '1'},
38 { "lib-port", required_argument, NULL, '2'},
39 { "main-port", required_argument, NULL, '3'},
40 { "help", no_argument, NULL, 'h'},
41 { 0, 0, 0, 0}
42 };
43
44
45
46 int instance_opt(int argc, char** argv, instance_t* app)
47 {
48 char* p;
49 int c, index = 0;
50
51 /* setup defaults */
52 app->players.port = 5250;
53 app->library.port = 5250;
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 /** --host */
70 case '0':
71 strncpy(app->players.host, optarg, PATH_MAX);
72 break;
73
74 /** --unit */
75 case '1':
76 app->players.item[app->players.count].unit = atol(optarg);
77 app->players.item[app->players.count].idx = app->players.count;
78 app->players.item[app->players.count].app = app;
79 app->players.count++;
80 break;
81
82 /** --lib-port */
83 case '2':
84 app->library.port = atol(optarg);
85 break;
86
87 /** --main-port */
88 case '3':
89 app->players.port = atol(optarg);
90 break;
91
92 default:
93 fprintf(stderr, "ERROR: Incorrect argument!\n");
94 return 1;
95 break;
96 };
97 };
98
99 return 0;
100 };
101
102 void instance_usage(void)
103 {
104 fprintf
105 (
106 stderr,
107 "Usage:\n"
108 "\t--host=<STRING> Host name of melted server\n"
109 "\t--unit=<INT> Player to use (e.g. unit number)\n"
110 "\t--main-port=<INT> Melted instance ip port binded (default 5250), playback operations\n"
111 "\t--lib-port=<INT> Melted instance ip port binded (default 5250), library operations\n"
112 );
113 };