Adding a simulator to the Coder IDE
This commit is contained in:
parent
98b6cd10f2
commit
39fad0e289
2
Makefile
2
Makefile
|
@ -39,6 +39,8 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/src/project.h \
|
||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/tools/gdeasm.c \
|
||||
$(PACKAGE)-$(VERSION)/tools/simulator.c \
|
||||
$(PACKAGE)-$(VERSION)/tools/simulator-main.c \
|
||||
$(PACKAGE)-$(VERSION)/tools/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/COPYING \
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
MKDIR = mkdir -p
|
||||
MKDIR = mkdir -m 0755 -p
|
||||
INSTALL = install
|
||||
RM = rm -f
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ PREFIX = /usr/local
|
|||
DESTDIR =
|
||||
RM = rm -f
|
||||
LN = ln -f
|
||||
MKDIR = mkdir -p
|
||||
MKDIR = mkdir -m 0755 -p
|
||||
INSTALL = install
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ LDFLAGSF= `pkg-config --libs libSystem libDesktop`
|
|||
LDFLAGS =
|
||||
RM = rm -f
|
||||
LN = ln -f
|
||||
MKDIR = mkdir -p
|
||||
MKDIR = mkdir -m 0755 -p
|
||||
INSTALL = install
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
TARGETS = gdeasm
|
||||
TARGETS = gdeasm simulator
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
BINDIR = $(PREFIX)/bin
|
||||
|
@ -6,29 +6,42 @@ SBINDIR = $(PREFIX)/sbin
|
|||
CC = cc
|
||||
CPPFLAGSF=
|
||||
CPPFLAGS=
|
||||
CFLAGSF = -W `pkg-config --cflags libSystem libDesktop Asm`
|
||||
CFLAGSF = -W `pkg-config --cflags libDesktop`
|
||||
CFLAGS = -Wall -g -O2 -pedantic
|
||||
LDFLAGSF= `pkg-config --libs libSystem libDesktop Asm`
|
||||
LDFLAGSF= `pkg-config --libs libDesktop`
|
||||
RM = rm -f
|
||||
LN = ln -f
|
||||
MKDIR = mkdir -p
|
||||
MKDIR = mkdir -m 0755 -p
|
||||
INSTALL = install
|
||||
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
gdeasm_OBJS = gdeasm.o
|
||||
gdeasm_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
gdeasm_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
gdeasm_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) `pkg-config --cflags Asm`
|
||||
gdeasm_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs Asm`
|
||||
|
||||
gdeasm: $(gdeasm_OBJS)
|
||||
$(CC) -o gdeasm $(gdeasm_OBJS) $(gdeasm_LDFLAGS)
|
||||
|
||||
simulator_OBJS = simulator.o simulator-main.o
|
||||
simulator_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
simulator_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
simulator: $(simulator_OBJS)
|
||||
$(CC) -o simulator $(simulator_OBJS) $(simulator_LDFLAGS)
|
||||
|
||||
gdeasm.o: gdeasm.c ../config.h
|
||||
$(CC) $(gdeasm_CFLAGS) -c gdeasm.c
|
||||
|
||||
simulator.o: simulator.c ../config.h
|
||||
$(CC) -D PREFIX=\"$(PREFIX)\" $(simulator_CFLAGS) -c simulator.c
|
||||
|
||||
simulator-main.o: simulator-main.c
|
||||
$(CC) $(simulator_CFLAGS) -c simulator-main.c
|
||||
|
||||
clean:
|
||||
$(RM) -- $(gdeasm_OBJS)
|
||||
$(RM) -- $(gdeasm_OBJS) $(simulator_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) -- $(TARGETS)
|
||||
|
@ -36,8 +49,11 @@ distclean: clean
|
|||
install: $(TARGETS)
|
||||
$(MKDIR) $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL) -m 0755 -- gdeasm $(DESTDIR)$(BINDIR)/gdeasm
|
||||
$(MKDIR) $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL) -m 0755 -- simulator $(DESTDIR)$(BINDIR)/simulator
|
||||
|
||||
uninstall:
|
||||
$(RM) -- $(DESTDIR)$(BINDIR)/gdeasm
|
||||
$(RM) -- $(DESTDIR)$(BINDIR)/simulator
|
||||
|
||||
.PHONY: all clean distclean install uninstall
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
targets=gdeasm
|
||||
cflags_force=-W `pkg-config --cflags libSystem libDesktop Asm`
|
||||
targets=gdeasm,simulator
|
||||
cflags_force=-W `pkg-config --cflags libDesktop`
|
||||
cflags=-Wall -g -O2 -pedantic
|
||||
ldflags_force=`pkg-config --libs libSystem libDesktop Asm`
|
||||
ldflags_force=`pkg-config --libs libDesktop`
|
||||
|
||||
[gdeasm]
|
||||
type=binary
|
||||
sources=gdeasm.c
|
||||
cflags=`pkg-config --cflags Asm`
|
||||
ldflags=`pkg-config --libs Asm`
|
||||
install=$(BINDIR)
|
||||
|
||||
[gdeasm.c]
|
||||
depends=../config.h
|
||||
|
||||
[simulator]
|
||||
type=binary
|
||||
sources=simulator.c,simulator-main.c
|
||||
install=$(BINDIR)
|
||||
|
||||
[simulator.c]
|
||||
cppflags=-D PREFIX=\"$(PREFIX)\"
|
||||
depends=../config.h
|
||||
|
|
69
tools/simulator-main.c
Normal file
69
tools/simulator-main.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Coder */
|
||||
/* This program 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, version 3 of the License.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <System.h>
|
||||
#include "simulator.h"
|
||||
|
||||
|
||||
/* private */
|
||||
/* prototypes */
|
||||
static int _simulator(void);
|
||||
|
||||
static int _usage(void);
|
||||
|
||||
|
||||
/* functions */
|
||||
/* simulator */
|
||||
static int _simulator(void)
|
||||
{
|
||||
Simulator * simulator;
|
||||
|
||||
if((simulator = simulator_new()) == NULL)
|
||||
return error_print("simulator");
|
||||
gtk_main();
|
||||
simulator_delete(simulator);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* usage */
|
||||
static int _usage(void)
|
||||
{
|
||||
fputs("Usage: simulator\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
/* main */
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int o;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
while((o = getopt(argc, argv, "")) != -1)
|
||||
switch(o)
|
||||
{
|
||||
default:
|
||||
return _usage();
|
||||
}
|
||||
return (_simulator() == 0) ? 0 : 2;
|
||||
}
|
154
tools/simulator.c
Normal file
154
tools/simulator.c
Normal file
|
@ -0,0 +1,154 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Coder */
|
||||
/* This program 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, version 3 of the License.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* FIXME:
|
||||
* - terminate the underlying server on quit */
|
||||
|
||||
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <System.h>
|
||||
#include "simulator.h"
|
||||
#include "../config.h"
|
||||
|
||||
#ifndef PREFIX
|
||||
# define PREFIX "/usr/local"
|
||||
#endif
|
||||
#ifndef BINDIR
|
||||
# define BINDIR PREFIX "/bin"
|
||||
#endif
|
||||
|
||||
|
||||
/* Simulator */
|
||||
/* private */
|
||||
/* types */
|
||||
struct _Simulator
|
||||
{
|
||||
GPid pid;
|
||||
|
||||
/* widgets */
|
||||
GtkWidget * window;
|
||||
GtkWidget * socket;
|
||||
};
|
||||
|
||||
|
||||
/* prototypes */
|
||||
/* callbacks */
|
||||
static void _simulator_on_child_watch(GPid pid, gint status, gpointer data);
|
||||
static gboolean _simulator_on_closex(gpointer data);
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
/* simulator_new */
|
||||
Simulator * simulator_new(void)
|
||||
{
|
||||
Simulator * simulator;
|
||||
GtkWidget * vbox;
|
||||
GtkWidget * widget;
|
||||
char * argv[] = { BINDIR "/Xephyr", "Xephyr", "-parent", NULL, ":1",
|
||||
NULL };
|
||||
char buf[16];
|
||||
int flags = G_SPAWN_FILE_AND_ARGV_ZERO | G_SPAWN_DO_NOT_REAP_CHILD;
|
||||
GError * error = NULL;
|
||||
|
||||
if((simulator = object_new(sizeof(*simulator))) == NULL)
|
||||
return NULL;
|
||||
simulator->window = NULL;
|
||||
/* widgets */
|
||||
simulator->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_widget_set_size_request(simulator->window, 800, 600);
|
||||
gtk_window_set_resizable(GTK_WINDOW(simulator->window), FALSE);
|
||||
gtk_window_set_title(GTK_WINDOW(simulator->window), "Simulator");
|
||||
g_signal_connect_swapped(simulator->window, "delete-event", G_CALLBACK(
|
||||
_simulator_on_closex), simulator);
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
/* menu bar */
|
||||
widget = gtk_menu_bar_new();
|
||||
gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0);
|
||||
/* view */
|
||||
simulator->socket = gtk_socket_new();
|
||||
gtk_box_pack_start(GTK_BOX(vbox), simulator->socket, TRUE, TRUE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(simulator->window), vbox);
|
||||
gtk_widget_show_all(vbox);
|
||||
/* launch Xephyr */
|
||||
snprintf(buf, sizeof(buf), "%u", gtk_socket_get_id(
|
||||
GTK_SOCKET(simulator->socket)));
|
||||
argv[3] = buf;
|
||||
if(g_spawn_async(NULL, argv, NULL, flags, NULL, NULL,
|
||||
&simulator->pid, &error) == FALSE)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: %s\n", "Simulator", argv[1],
|
||||
error->message);
|
||||
g_error_free(error);
|
||||
simulator_delete(simulator);
|
||||
return NULL;
|
||||
}
|
||||
g_child_watch_add(simulator->pid, _simulator_on_child_watch,
|
||||
simulator);
|
||||
gtk_widget_show(simulator->window);
|
||||
return simulator;
|
||||
}
|
||||
|
||||
|
||||
/* simulator_delete */
|
||||
void simulator_delete(Simulator * simulator)
|
||||
{
|
||||
if(simulator->pid > 0)
|
||||
g_spawn_close_pid(simulator->pid);
|
||||
/* FIXME also take care of the sub-processes */
|
||||
if(simulator->window != NULL)
|
||||
gtk_widget_destroy(simulator->window);
|
||||
object_delete(simulator);
|
||||
}
|
||||
|
||||
|
||||
/* private */
|
||||
/* functions */
|
||||
/* callbacks */
|
||||
/* simulator_on_child_watch */
|
||||
static void _simulator_on_child_watch(GPid pid, gint status, gpointer data)
|
||||
{
|
||||
Simulator * simulator = data;
|
||||
|
||||
if(simulator->pid != pid)
|
||||
return;
|
||||
if(WIFEXITED(status))
|
||||
{
|
||||
if(WEXITSTATUS(status) != 0)
|
||||
fprintf(stderr, "%s: %s%u\n", "Simulator",
|
||||
"Xephyr exited with status ",
|
||||
WEXITSTATUS(status));
|
||||
gtk_main_quit();
|
||||
}
|
||||
else if(WIFSIGNALED(status))
|
||||
{
|
||||
fprintf(stderr, "%s: %s%u\n", "Simulator",
|
||||
"Xephyr exited with signal ", WTERMSIG(status));
|
||||
gtk_main_quit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* simulator_on_closex */
|
||||
static gboolean _simulator_on_closex(gpointer data)
|
||||
{
|
||||
Simulator * simulator = data;
|
||||
|
||||
gtk_widget_hide(simulator->window);
|
||||
gtk_main_quit();
|
||||
return TRUE;
|
||||
}
|
Loading…
Reference in New Issue
Block a user