Just use getopt_long for option parsing
This commit is contained in:
+57
-32
@@ -33,6 +33,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
#include "wayland-server.h"
|
#include "wayland-server.h"
|
||||||
#include "compositor.h"
|
#include "compositor.h"
|
||||||
@@ -42,28 +43,11 @@
|
|||||||
*/
|
*/
|
||||||
static const char *option_socket_name = NULL;
|
static const char *option_socket_name = NULL;
|
||||||
static const char *option_background = "background.jpg";
|
static const char *option_background = "background.jpg";
|
||||||
static const char *option_geometry = "1024x640";
|
|
||||||
static const char *option_shell = NULL;
|
static const char *option_shell = NULL;
|
||||||
static int option_idle_time = 5;
|
static int option_idle_time = 300;
|
||||||
static int option_connector = 0;
|
static int option_connector = 0;
|
||||||
|
|
||||||
static const GOptionEntry option_entries[] = {
|
WL_EXPORT void
|
||||||
{ "background", 'b', 0, G_OPTION_ARG_STRING,
|
|
||||||
&option_background, "Background image" },
|
|
||||||
{ "connector", 'c', 0, G_OPTION_ARG_INT,
|
|
||||||
&option_connector, "KMS connector" },
|
|
||||||
{ "geometry", 'g', 0, G_OPTION_ARG_STRING,
|
|
||||||
&option_geometry, "Geometry" },
|
|
||||||
{ "socket", 0, 0, G_OPTION_ARG_STRING,
|
|
||||||
&option_socket_name, "Socket Name" },
|
|
||||||
{ "idle-time", 'i', 0, G_OPTION_ARG_INT,
|
|
||||||
&option_idle_time, "Screensaver idle time" },
|
|
||||||
{ "shell", 's', 0, G_OPTION_ARG_STRING,
|
|
||||||
&option_shell, "Shell module" },
|
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
wlsc_matrix_init(struct wlsc_matrix *matrix)
|
wlsc_matrix_init(struct wlsc_matrix *matrix)
|
||||||
{
|
{
|
||||||
static const struct wlsc_matrix identity = {
|
static const struct wlsc_matrix identity = {
|
||||||
@@ -1952,24 +1936,65 @@ int main(int argc, char *argv[])
|
|||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
struct wlsc_compositor *ec;
|
struct wlsc_compositor *ec;
|
||||||
struct wl_event_loop *loop;
|
struct wl_event_loop *loop;
|
||||||
GError *error = NULL;
|
int width, height, o;
|
||||||
GOptionContext *context;
|
|
||||||
int width, height;
|
|
||||||
void *shell_module;
|
void *shell_module;
|
||||||
int (*shell_init)(struct wlsc_compositor *ec);
|
int (*shell_init)(struct wlsc_compositor *ec);
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
static const char opts[] = "b:c:g:S:i:s:";
|
||||||
|
static const struct option longopts[ ] = {
|
||||||
|
{ "background", 1, NULL, 'b' },
|
||||||
|
{ "connector", 1, NULL, 'c' },
|
||||||
|
{ "geometry", 1, NULL, 'g' },
|
||||||
|
{ "socket", 1, NULL, 'S' },
|
||||||
|
{ "idle-time", 1, NULL, 'i' },
|
||||||
|
{ "shell", 1, NULL, 's' },
|
||||||
|
{ NULL, }
|
||||||
|
};
|
||||||
|
|
||||||
g_type_init(); /* GdkPixbuf needs this, it seems. */
|
g_type_init(); /* GdkPixbuf needs this, it seems. */
|
||||||
|
|
||||||
context = g_option_context_new(NULL);
|
width = 1024;
|
||||||
g_option_context_add_main_entries(context, option_entries, "Wayland");
|
height = 640;
|
||||||
if (!g_option_context_parse(context, &argc, &argv, &error)) {
|
|
||||||
fprintf(stderr, "option parsing failed: %s\n", error->message);
|
while (o = getopt_long(argc, argv, opts, longopts, &o), o > 0) {
|
||||||
exit(EXIT_FAILURE);
|
switch (o) {
|
||||||
}
|
case 'b':
|
||||||
if (sscanf(option_geometry, "%dx%d", &width, &height) != 2) {
|
option_background = optarg;
|
||||||
fprintf(stderr, "invalid geometry option: %s \n",
|
break;
|
||||||
option_geometry);
|
case 'c':
|
||||||
exit(EXIT_FAILURE);
|
option_connector = strtol(optarg, &p, 0);
|
||||||
|
if (*p != '\0') {
|
||||||
|
fprintf(stderr,
|
||||||
|
"invalid connection option: %s\n",
|
||||||
|
optarg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
if (sscanf(optarg, "%dx%d", &width, &height) != 2) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"invalid geometry option: %s\n",
|
||||||
|
optarg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
option_socket_name = optarg;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
option_idle_time = strtol(optarg, &p, 0);
|
||||||
|
if (*p != '\0') {
|
||||||
|
fprintf(stderr,
|
||||||
|
"invalid idle time option: %s\n",
|
||||||
|
optarg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
option_shell = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display = wl_display_create();
|
display = wl_display_create();
|
||||||
|
|||||||
Reference in New Issue
Block a user