Commit 2b32a871 authored by Jeremy White's avatar Jeremy White

Add a basic framework, options parsing, open a display.

parent 469e13b6
......@@ -16,3 +16,5 @@ Makefile.in
*.o
src/x11spice
config.guess
config.sub
AC_INIT([x11spice], 1.0)
AM_INIT_AUTOMAKE
PKG_CHECK_MODULES(X11, x11)
AC_PROG_CC
AC_CONFIG_FILES(Makefile src/Makefile)
AC_OUTPUT
bin_PROGRAMS = x11spice
x11spice_SOURCES = main.c
x11spice_LDADD = $(X11_LIBS)
x11spice_SOURCES = \
options.c \
display.c \
main.c
/*
Copyright (C) 2016 Jeremy White <jwhite@codeweavers.com>
All rights reserved.
This file is part of x11spice
x11spice 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 3 of the License, or
(at your option) any later version.
x11spice 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 x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include "options.h"
#include "display.h"
display_t *display_open(options_t *options)
{
display_t *d = malloc(sizeof(*d));
if (! d)
return NULL;
d->xdisplay = XOpenDisplay(options->display);
// FIXME g_x_error_handler = XSetErrorHandler(handle_xerrors);
if (! d->xdisplay)
{
fprintf(stderr, "Error: could not open display %s\n", options->display ? options->display : "");
return NULL;
}
return d;
}
void display_close(display_t *display)
{
if (display->xdisplay)
{
XCloseDisplay(display->xdisplay);
display->xdisplay = NULL;
}
}
/*
Copyright (C) 2016 Jeremy White <jwhite@codeweavers.com>
All rights reserved.
This file is part of x11spice
x11spice 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 3 of the License, or
(at your option) any later version.
x11spice 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 x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
#include <X11/Xlib.h>
/*----------------------------------------------------------------------------
** Structure definitions
**--------------------------------------------------------------------------*/
typedef struct
{
Display *xdisplay;
} display_t;
/*----------------------------------------------------------------------------
** Prototypes
**--------------------------------------------------------------------------*/
display_t *display_open(options_t *options);
void display_close(display_t *display);
/*
Copyright (C) 2016 Jeremy White <jwhite@codeweavers.com>
All rights reserved.
This file is part of x11spice
x11spice 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 3 of the License, or
(at your option) any later version.
x11spice 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 x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "x11spice.h"
#include "options.h"
#include "display.h"
int main(int argc, char *argv[])
{
printf("hello world\n");
return 0;
int rc;
options_t options;
display_t * display = NULL;
/*------------------------------------------------------------------------
** Parse arguments
**----------------------------------------------------------------------*/
options_init(&options);
rc = options_parse_arguments(argc, argv, &options);
if (rc)
goto exit;
/*------------------------------------------------------------------------
** Open the display
**----------------------------------------------------------------------*/
display = display_open(&options);
if (! display)
{
rc = X11SPICE_ERR_NODISPLAY;
goto exit;
}
/* FIXME - add a main loop... */
rc = 0;
/*------------------------------------------------------------------------
** Close the display, go home
**----------------------------------------------------------------------*/
exit:
options_free(&options);
if (display)
display_close(display);
return rc;
}
/*
Copyright (C) 2016 Jeremy White <jwhite@codeweavers.com>
All rights reserved.
This file is part of x11spice
x11spice 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 3 of the License, or
(at your option) any later version.
x11spice 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 x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
#include <getopt.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "options.h"
#include "x11spice.h"
void options_init(options_t *options)
{
memset(options, 0, sizeof(*options));
}
void options_free(options_t *options)
{
if (options->display)
{
free(options->display);
options->display = NULL;
}
}
static void usage(char *argv0)
{
fprintf(stderr, "%s: \n", argv0);
// FIXME - write usage
}
int options_parse_arguments(int argc, char *argv[], options_t *options)
{
int rc;
int longindex = 0;
enum option_types { OPTION_VIEWONLY, OPTION_TIMEOUT, OPTION_AUTOPORT,
OPTION_GENERATE_PASSCODE, OPTION_DISPLAY, OPTION_HELP
};
static struct option long_options[] =
{
{"viewonly", 0, 0, OPTION_VIEWONLY },
{"timeout", 1, 0, OPTION_TIMEOUT },
{"autoport", 0, 0, OPTION_AUTOPORT },
{"generate-passcode", 0, 0, OPTION_GENERATE_PASSCODE},
{"display", 1, 0, OPTION_DISPLAY },
{"help", 0, 0, OPTION_HELP},
{0, 0, 0, 0}
};
while (1)
{
rc = getopt_long_only(argc, argv, "", long_options, &longindex);
if (rc == -1)
{
rc = 0;
break;
}
switch (rc)
{
case OPTION_TIMEOUT:
options->timeout = atol(optarg);
break;
case OPTION_DISPLAY:
options->display = strdup(optarg);
break;
default:
usage(argv[0]);
rc = X11SPICE_ERR_BADARGS;
break;
}
}
return rc;
}
/*
Copyright (C) 2016 Jeremy White <jwhite@codeweavers.com>
All rights reserved.
This file is part of x11spice
x11spice 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 3 of the License, or
(at your option) any later version.
x11spice 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 x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
/*----------------------------------------------------------------------------
** Structure definitions
**--------------------------------------------------------------------------*/
typedef struct
{
long timeout;
char *display;
} options_t;
/*----------------------------------------------------------------------------
** Prototypes
**--------------------------------------------------------------------------*/
void options_init(options_t *options);
int options_parse_arguments(int argc, char *argv[], options_t *options);
void options_free(options_t *options);
/*
Copyright (C) 2016 Jeremy White <jwhite@codeweavers.com>
All rights reserved.
This file is part of x11spice
x11spice 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 3 of the License, or
(at your option) any later version.
x11spice 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 x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
/*----------------------------------------------------------------------------
** Constant definitions
**--------------------------------------------------------------------------*/
#define X11SPICE_ERR_BADARGS 1
#define X11SPICE_ERR_NODISPLAY 2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment