mirror of https://github.com/GNOME/gimp.git
Removed GCG:
2001-01-08 Michael Natterer <mitch@gimp.org> Removed GCG: * app/colormap_dialog.gc * app/colormap_dialog.i.[ch] * app/colormap_dialog.p.h * app/colormap_dialog.t.h * app/gimp.gh * tools/gcg/*: removed. * app/colormap_dialog.[ch]: moved all the colormap_dialog stuff here and cleaned up the autogenerated code. * autogen.sh * configure.in * app/Makefile.am * app/app_procs.c * app/apptypes.h * app/color_notebook.h * app/commands.c * app/gimpset.h * po/POTFILES.in * tools/Makefile.am: changed accordingly. * libgimp/gimpunitmenu.c: s/class/klass/
This commit is contained in:
parent
ab014f8b3a
commit
4c03fb5eff
29
ChangeLog
29
ChangeLog
|
@ -1,3 +1,30 @@
|
|||
2001-01-08 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
Removed GCG:
|
||||
|
||||
* app/colormap_dialog.gc
|
||||
* app/colormap_dialog.i.[ch]
|
||||
* app/colormap_dialog.p.h
|
||||
* app/colormap_dialog.t.h
|
||||
* app/gimp.gh
|
||||
* tools/gcg/*: removed.
|
||||
|
||||
* app/colormap_dialog.[ch]: moved all the colormap_dialog stuff
|
||||
here and cleaned up the autogenerated code.
|
||||
|
||||
* autogen.sh
|
||||
* configure.in
|
||||
* app/Makefile.am
|
||||
* app/app_procs.c
|
||||
* app/apptypes.h
|
||||
* app/color_notebook.h
|
||||
* app/commands.c
|
||||
* app/gimpset.h
|
||||
* po/POTFILES.in
|
||||
* tools/Makefile.am: changed accordingly.
|
||||
|
||||
* libgimp/gimpunitmenu.c: s/class/klass/
|
||||
|
||||
2001-01-07 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/by_color_select.c
|
||||
|
@ -19,7 +46,7 @@
|
|||
* modules/colorsel_gtk.c
|
||||
* modules/colorsel_triangle.c
|
||||
* modules/colorsel_water.c: made the color_notebook, the color_area
|
||||
and DND speak in terms of RGBA instead of GRB. The alpha value is
|
||||
and DND speak in terms of RGBA instead of RGB. The alpha value is
|
||||
not used yet, only the API changed. Everything should work exactly
|
||||
as before.
|
||||
|
||||
|
|
|
@ -407,10 +407,6 @@ gimp_SOURCES = \
|
|||
$(regex_sources)
|
||||
|
||||
EXTRA_DIST = \
|
||||
colormap_dialog.i.c \
|
||||
colormap_dialog.i.h \
|
||||
colormap_dialog.p.h \
|
||||
colormap_dialog.t.h \
|
||||
makefile.mingw \
|
||||
makefile.mingw.in \
|
||||
makefile.msc \
|
||||
|
@ -452,42 +448,3 @@ files:
|
|||
|
||||
makefile.mingw: $(top_builddir)/config.status $(top_srcdir)/app/makefile.mingw.in
|
||||
cd $(top_builddir) && CONFIG_FILES=app/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
# GCG stuff
|
||||
#
|
||||
# SUFFIXES = .gc .gh
|
||||
#
|
||||
# if WITH_GCG
|
||||
# GCG = ../tools/gcg/gcg -I$(srcdir) -I$(top_srcdir)/tools/gcg/gh
|
||||
# GEN_CODE = colormap_dialog.c
|
||||
# if WITH_GNU_MAKE
|
||||
# GEN_HEADER =$(subst .gc,.t.h,$(GCG_DEFS)) \
|
||||
# $(subst .gc,.p.h,$(GCG_DEFS)) \
|
||||
# $(subst .gc,.i.h,$(GCG_DEFS)) \
|
||||
# $(subst .gc,.h,$(GCG_DEFS))
|
||||
#
|
||||
# $(GEN_CODE): %.c: %.gc
|
||||
# $(GCG) -o $@ $<
|
||||
# else # WITH_GNU_MAKE
|
||||
# GEN_HEADER = # fill in here manually, if you bother
|
||||
# .gc.c:
|
||||
# $(GCG) -o $@ $<
|
||||
# endif # WITH_GNU_MAKE
|
||||
#
|
||||
# BUILT_SOURCES = $(GEN_CODE) $(GEN_HEADER)
|
||||
#
|
||||
# if ENABLE_GCG_DEPS
|
||||
# if WITH_GNU_MAKE
|
||||
# # dependency magic
|
||||
# GCGMAKEDEPEND = $(top_srcdir)/tools/gcg/gcgmakedepend
|
||||
# $(DEF_DEPS): .deps/%.d: %.gc
|
||||
# $(GCGMAKEDEPEND) $(DEF_INC) $< >$@
|
||||
# automake uses .P for .c files, we use .d for .gc files, should
|
||||
# be no conflict..
|
||||
# GCG_DEFS = $(subst .c,.gc,$(GEN_CODE))
|
||||
# DEF_DEPS = $(patsubst %.gc,.deps/%.d,$(GCG_DEFS))
|
||||
# -include $(DEF_DEPS)
|
||||
# endif # WITH_GNU_MAKE
|
||||
# endif # ENABLE_GCG_DEPS
|
||||
# endif # WITH_GCG
|
||||
# end GCG stuff
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "about_dialog.h"
|
||||
#include "app_procs.h"
|
||||
#include "brush_select.h"
|
||||
#include "colormap_dialog.i.h"
|
||||
#include "colormap_dialog.h"
|
||||
#include "color_area.h"
|
||||
#include "commands.h"
|
||||
#include "convert.h"
|
||||
|
@ -1185,13 +1185,13 @@ dialogs_palette_cmd_callback (GtkWidget *widget,
|
|||
}
|
||||
|
||||
static void
|
||||
dialogs_indexed_palette_select_callback (ColormapDialog *dialog,
|
||||
gpointer data)
|
||||
dialogs_indexed_palette_select_callback (GimpColormapDialog *dialog,
|
||||
gpointer data)
|
||||
{
|
||||
guchar *color;
|
||||
GimpImage *image = colormap_dialog_image (dialog);
|
||||
GimpImage *image = gimp_colormap_dialog_image (dialog);
|
||||
|
||||
color = &image->cmap[colormap_dialog_col_index (dialog) * 3];
|
||||
color = &image->cmap[gimp_colormap_dialog_col_index (dialog) * 3];
|
||||
|
||||
if (active_color == FOREGROUND)
|
||||
gimp_context_set_foreground (gimp_context_get_user (),
|
||||
|
@ -1205,16 +1205,22 @@ void
|
|||
dialogs_indexed_palette_cmd_callback (GtkWidget *widget,
|
||||
gpointer client_data)
|
||||
{
|
||||
static ColormapDialog *cmap_dlg;
|
||||
static GimpColormapDialog *cmap_dlg;
|
||||
|
||||
if (!cmap_dlg)
|
||||
{
|
||||
cmap_dlg = colormap_dialog_create (image_context);
|
||||
colormap_dialog_connect_selected (dialogs_indexed_palette_select_callback,
|
||||
NULL, cmap_dlg);
|
||||
cmap_dlg = gimp_colormap_dialog_create (image_context);
|
||||
|
||||
gtk_signal_connect
|
||||
(GTK_OBJECT (cmap_dlg), "selected",
|
||||
GTK_SIGNAL_FUNC (dialogs_indexed_palette_select_callback),
|
||||
NULL);
|
||||
}
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (cmap_dlg));
|
||||
if (! GTK_WIDGET_VISIBLE (cmap_dlg))
|
||||
gtk_widget_show (GTK_WIDGET (cmap_dlg));
|
||||
else
|
||||
gdk_window_raise (GTK_WIDGET (cmap_dlg)->window);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "gdisplay_ops.h"
|
||||
#include "gimpbrushlist.h"
|
||||
#include "gimpcontext.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimprc.h"
|
||||
#include "gimpparasite.h"
|
||||
#include "gimpset.h"
|
||||
|
|
|
@ -345,6 +345,8 @@ typedef enum /*< skip >*/
|
|||
typedef struct _GimpObject GimpObject;
|
||||
|
||||
typedef struct _GimpSet GimpSet;
|
||||
typedef guint GimpSetHandlerId;
|
||||
|
||||
typedef struct _GimpList GimpList;
|
||||
|
||||
typedef struct _GimpContext GimpContext;
|
||||
|
@ -383,6 +385,8 @@ typedef struct _BezierSelect BezierSelect;
|
|||
|
||||
typedef struct _BoundSeg BoundSeg;
|
||||
|
||||
typedef struct _ColorNotebook ColorNotebook;
|
||||
|
||||
typedef struct _DrawCore DrawCore;
|
||||
|
||||
typedef struct _GDisplay GDisplay;
|
||||
|
|
|
@ -36,8 +36,6 @@ typedef void (* ColorNotebookCallback) (gint red,
|
|||
|
||||
typedef struct _ColorSelectorInstance ColorSelectorInstance;
|
||||
|
||||
typedef struct _ColorNotebook ColorNotebook;
|
||||
|
||||
struct _ColorNotebook
|
||||
{
|
||||
GtkWidget *shell;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,28 +0,0 @@
|
|||
#include <gimp.gh>
|
||||
#include <gtk.gh>
|
||||
|
||||
module Gimp.ColormapDialog;
|
||||
|
||||
import Gtk, g;
|
||||
|
||||
class ColormapDialog : Gtk.Dialog {
|
||||
public static ColormapDialog* create(Set* context);
|
||||
read-only Image* image;
|
||||
read-only int col-index;
|
||||
protected pre-emit void selected ();
|
||||
Widget* vbox;
|
||||
Preview* palette;
|
||||
Widget* image-menu;
|
||||
OptionMenu* option-menu;
|
||||
Set* context;
|
||||
uint event-handler;
|
||||
int xn;
|
||||
int yn;
|
||||
int cellsize;
|
||||
Entry* index-entry;
|
||||
Entry* color-entry;
|
||||
SetHandlerId rename-handler;
|
||||
SetHandlerId cmap-changed-handler;
|
||||
Widget* add-item;
|
||||
.ColorNotebookP color-select;
|
||||
}
|
|
@ -16,24 +16,64 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _g_gimp_colormap_dialog_funcs
|
||||
#define _g_gimp_colormap_dialog_funcs
|
||||
#ifndef __COLORMAP_DIALOG_H__
|
||||
#define __COLORMAP_DIALOG_H__
|
||||
|
||||
#include <colormap_dialog.t.h>
|
||||
#include <gimpset.h>
|
||||
#include <gimpimage.h>
|
||||
|
||||
GimpColormapDialog* gimp_colormap_dialog_create (
|
||||
GimpSet* context);
|
||||
GimpImage* gimp_colormap_dialog_image (
|
||||
const GimpColormapDialog* colormap_dialog);
|
||||
gint gimp_colormap_dialog_col_index (
|
||||
const GimpColormapDialog* colormap_dialog);
|
||||
typedef void (*GimpColormapDialogHandler_selected)(GimpColormapDialog*,
|
||||
gpointer);
|
||||
void gimp_colormap_dialog_connect_selected (
|
||||
GimpColormapDialogHandler_selected handler,
|
||||
gpointer user_data,
|
||||
GimpColormapDialog* colormap_dialog);
|
||||
#include <gtk/gtkdialog.h>
|
||||
|
||||
#endif /* _g_gimp_colormap_dialog_funcs */
|
||||
|
||||
#define GIMP_TYPE_COLORMAP_DIALOG (gimp_colormap_dialog_get_type ())
|
||||
#define GIMP_COLORMAP_DIALOG(obj) (GTK_CHECK_CAST((obj), GIMP_TYPE_COLORMAP_DIALOG, GimpColormapDialog))
|
||||
#define GIMP_COLORMAP_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GIMP_TYPE_COLORMAP_DIALOG, GimpColormapDialogClass))
|
||||
#define GIMP_IS_COLORMAP_DIALOG(obj) (GTK_CHECK_TYPE((obj), GIMP_TYPE_COLORMAP_DIALOG))
|
||||
#define GIMP_IS_COLORMAP_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GIMP_TYPE_COLORMAP_DIALOG))
|
||||
|
||||
|
||||
typedef struct _GimpColormapDialog GimpColormapDialog;
|
||||
typedef struct _GimpColormapDialogClass GimpColormapDialogClass;
|
||||
|
||||
struct _GimpColormapDialog
|
||||
{
|
||||
GtkDialog parent;
|
||||
|
||||
GimpImage *image;
|
||||
gint col_index;
|
||||
gint dnd_col_index;
|
||||
GtkWidget *vbox;
|
||||
GtkPreview *palette;
|
||||
GtkWidget *image_menu;
|
||||
GtkWidget *popup_menu;
|
||||
GtkOptionMenu *option_menu;
|
||||
GimpSet *context;
|
||||
guint event_handler;
|
||||
gint xn;
|
||||
gint yn;
|
||||
gint cellsize;
|
||||
GtkWidget *index_spinbutton;
|
||||
GtkAdjustment *index_adjustment;
|
||||
GtkEntry *color_entry;
|
||||
GimpSetHandlerId rename_handler;
|
||||
GimpSetHandlerId cmap_changed_handler;
|
||||
GtkWidget *add_item;
|
||||
ColorNotebook *color_notebook;
|
||||
};
|
||||
|
||||
struct _GimpColormapDialogClass
|
||||
{
|
||||
GtkDialogClass parent_class;
|
||||
|
||||
void (* selected) (GimpColormapDialog *gcd);
|
||||
};
|
||||
|
||||
|
||||
GtkType gimp_colormap_dialog_get_type (void);
|
||||
GimpColormapDialog * gimp_colormap_dialog_create (GimpSet* context);
|
||||
|
||||
void gimp_colormap_dialog_selected (GimpColormapDialog *colormap_dialog);
|
||||
|
||||
GimpImage * gimp_colormap_dialog_image (const GimpColormapDialog *colormap_dialog);
|
||||
gint gimp_colormap_dialog_col_index (const GimpColormapDialog *colormap_dialog);
|
||||
|
||||
|
||||
#endif /* __COLORMAP_DIALOG_H__ */
|
||||
|
|
|
@ -1,995 +0,0 @@
|
|||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#include "color_notebook.h"
|
||||
#include "image_render.h"
|
||||
#include "dialog_handler.h"
|
||||
#include "colormaps.h"
|
||||
#include "color_area.h"
|
||||
#include "gdisplay.h"
|
||||
#include "gimpdnd.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimpui.h"
|
||||
#include "procedural_db.h"
|
||||
|
||||
#include "libgimp/gimphelpui.h"
|
||||
#include "libgimp/gimpmath.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
/* Add these features:
|
||||
*
|
||||
* load/save colormaps
|
||||
* requantize
|
||||
* add color--by clicking in the checked region
|
||||
* all changes need to flush colormap lookup cache
|
||||
*/
|
||||
|
||||
|
||||
/* indexed palette routines */
|
||||
static void ipal_draw (GimpColormapDialog *ipal);
|
||||
static void ipal_clear (GimpColormapDialog *ipal);
|
||||
static void ipal_set_image (GimpColormapDialog *ipal,
|
||||
GimpImage *gimage);
|
||||
static void ipal_update_entries (GimpColormapDialog *ipal);
|
||||
static void ipal_set_index (GimpColormapDialog *ipal,
|
||||
gint i);
|
||||
static void ipal_draw_cell (GimpColormapDialog *ipal,
|
||||
gint col);
|
||||
static void ipal_update_image_list (GimpColormapDialog *ipal);
|
||||
|
||||
|
||||
/* indexed palette menu callbacks */
|
||||
static void ipal_add_callback (GtkWidget *, gpointer);
|
||||
static void ipal_edit_callback (GtkWidget *, gpointer);
|
||||
static void ipal_close_callback (GtkWidget *, gpointer);
|
||||
static void ipal_select_callback (gint, gint, gint, gint, ColorNotebookState,
|
||||
gpointer);
|
||||
|
||||
/* event callback */
|
||||
static gint ipal_area_events (GtkWidget *, GdkEvent *, GimpColormapDialog *);
|
||||
|
||||
/* create image menu */
|
||||
static void image_menu_callback (GtkWidget *, gpointer);
|
||||
static GtkWidget * create_image_menu (GimpColormapDialog *,
|
||||
GimpImage **,
|
||||
gint *,
|
||||
GtkSignalFunc);
|
||||
static void frame_size_alloc_cb (GtkFrame *frame, GtkAllocation *alloc,
|
||||
GimpColormapDialog *ipal);
|
||||
static void window_size_req_cb (GtkWindow *win, GtkRequisition *req,
|
||||
GimpColormapDialog *ipal);
|
||||
|
||||
static void index_adjustment_change_cb (GtkAdjustment *adjustment,
|
||||
GimpColormapDialog *ipal);
|
||||
static void hex_entry_change_cb (GtkEntry *entry,
|
||||
GimpColormapDialog *ipal);
|
||||
|
||||
static void set_addrem_cb (GimpSet *set, GimpImage *image,
|
||||
GimpColormapDialog *ipal);
|
||||
static void image_rename_cb (GimpImage *img, GimpColormapDialog *ipal);
|
||||
static void image_cmap_change_cb (GimpImage *img, gint ncol,
|
||||
GimpColormapDialog *ipal);
|
||||
|
||||
/* dnd stuff */
|
||||
static GtkTargetEntry color_palette_target_table[] =
|
||||
{
|
||||
GIMP_TARGET_COLOR
|
||||
};
|
||||
static guint n_color_palette_targets = (sizeof (color_palette_target_table) /
|
||||
sizeof (color_palette_target_table[0]));
|
||||
|
||||
static void
|
||||
palette_drag_color (GtkWidget *widget,
|
||||
guchar *r,
|
||||
guchar *g,
|
||||
guchar *b,
|
||||
guchar *a,
|
||||
gpointer data)
|
||||
{
|
||||
GimpColormapDialog *ipal = (GimpColormapDialog *) data;
|
||||
guint col = ipal->dnd_col_index;
|
||||
GimpImage *gimage;
|
||||
|
||||
gimage = ipal->image;
|
||||
|
||||
*r = gimage->cmap[col * 3 + 0];
|
||||
*g = gimage->cmap[col * 3 + 1];
|
||||
*b = gimage->cmap[col * 3 + 2];
|
||||
*a = 255;
|
||||
}
|
||||
|
||||
static void
|
||||
palette_drop_color (GtkWidget *widget,
|
||||
guchar r,
|
||||
guchar g,
|
||||
guchar b,
|
||||
guchar a,
|
||||
gpointer data)
|
||||
{
|
||||
GimpColormapDialog *ipal = (GimpColormapDialog *) data;
|
||||
|
||||
if (!GTK_WIDGET_IS_SENSITIVE (ipal->vbox) ||
|
||||
!(ipal->image->num_cols < 256))
|
||||
return;
|
||||
|
||||
ipal->image->cmap[ipal->image->num_cols * 3 + 0] = r;
|
||||
ipal->image->cmap[ipal->image->num_cols * 3 + 1] = g;
|
||||
ipal->image->cmap[ipal->image->num_cols * 3 + 2] = b;
|
||||
ipal->image->num_cols++;
|
||||
gimp_image_colormap_changed (ipal->image, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_create_popup_menu (GimpColormapDialog *ipal)
|
||||
{
|
||||
GtkWidget *menu;
|
||||
GtkWidget *menu_item;
|
||||
|
||||
ipal->popup_menu = menu = gtk_menu_new ();
|
||||
|
||||
menu_item = gtk_menu_item_new_with_label (_("Add"));
|
||||
gtk_menu_append (GTK_MENU (menu), menu_item);
|
||||
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
|
||||
GTK_SIGNAL_FUNC (ipal_add_callback),
|
||||
(gpointer) ipal);
|
||||
gtk_widget_show (menu_item);
|
||||
|
||||
ipal->add_item = menu_item;
|
||||
|
||||
menu_item = gtk_menu_item_new_with_label (_("Edit"));
|
||||
gtk_menu_append (GTK_MENU (menu), menu_item);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
|
||||
GTK_SIGNAL_FUNC (ipal_edit_callback),
|
||||
(gpointer) ipal);
|
||||
gtk_widget_show (menu_item);
|
||||
}
|
||||
|
||||
/**************************************/
|
||||
/* Public indexed palette functions */
|
||||
/**************************************/
|
||||
|
||||
#define COLORMAP_DIALOG_CREATE ipal_create
|
||||
|
||||
GimpColormapDialog *
|
||||
ipal_create (GimpSet *context)
|
||||
{
|
||||
GimpColormapDialog *ipal;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *util_box;
|
||||
GtkWidget *label;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *hbox2;
|
||||
GtkWidget *entry;
|
||||
GtkWidget *evbox;
|
||||
GtkAccelGroup *accel_group;
|
||||
|
||||
ipal = gtk_type_new (GIMP_TYPE_COLORMAP_DIALOG);
|
||||
|
||||
/* The action area */
|
||||
gimp_dialog_create_action_area (GTK_DIALOG (ipal),
|
||||
|
||||
_("Close"), ipal_close_callback,
|
||||
ipal, NULL, NULL, TRUE, TRUE,
|
||||
|
||||
NULL);
|
||||
|
||||
ipal->image = NULL;
|
||||
ipal->context = context;
|
||||
ipal->cmap_changed_handler
|
||||
= gimp_set_add_handler (context, "colormap_changed",
|
||||
image_cmap_change_cb, ipal);
|
||||
ipal->rename_handler
|
||||
= gimp_set_add_handler (context, "rename",
|
||||
image_rename_cb, ipal);
|
||||
|
||||
accel_group = gtk_accel_group_new ();
|
||||
gtk_window_set_wmclass (GTK_WINDOW (ipal), "indexed_color_palette", "Gimp");
|
||||
dialog_register (GTK_WIDGET (ipal));
|
||||
gtk_window_set_policy (GTK_WINDOW (ipal), TRUE, TRUE, TRUE);
|
||||
gtk_window_set_title (GTK_WINDOW (ipal), _("Indexed Color Palette"));
|
||||
gtk_window_add_accel_group (GTK_WINDOW (ipal), accel_group);
|
||||
gtk_signal_connect (GTK_OBJECT (ipal), "delete_event",
|
||||
GTK_SIGNAL_FUNC (gtk_widget_hide_on_delete),
|
||||
NULL);
|
||||
|
||||
ipal->vbox = vbox = gtk_vbox_new (FALSE, 2);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
||||
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (ipal)->vbox), vbox);
|
||||
|
||||
/* The hbox to hold the command menu and image option menu box */
|
||||
util_box = gtk_hbox_new (FALSE, 4);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), util_box, FALSE, FALSE, 0);
|
||||
|
||||
/* The GIMP image option menu */
|
||||
label = gtk_label_new (_("Image:"));
|
||||
gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 0);
|
||||
ipal->option_menu = GTK_OPTION_MENU (gtk_option_menu_new ());
|
||||
gtk_box_pack_start (GTK_BOX (util_box),
|
||||
GTK_WIDGET (ipal->option_menu),
|
||||
TRUE, TRUE, 0);
|
||||
|
||||
hbox2 = gtk_hbox_new (TRUE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox2, TRUE, TRUE, 0);
|
||||
|
||||
ipal_create_popup_menu (ipal);
|
||||
|
||||
/* The palette frame */
|
||||
evbox = gtk_event_box_new ();
|
||||
gtk_container_set_resize_mode (GTK_CONTAINER (evbox),
|
||||
GTK_RESIZE_QUEUE);
|
||||
gtk_widget_set_usize (GTK_WIDGET (evbox), -1, 60);
|
||||
gtk_signal_connect (GTK_OBJECT (evbox), "size_request",
|
||||
GTK_SIGNAL_FUNC (window_size_req_cb),
|
||||
ipal);
|
||||
gtk_signal_connect(GTK_OBJECT (evbox), "size_allocate",
|
||||
GTK_SIGNAL_FUNC (frame_size_alloc_cb),
|
||||
ipal);
|
||||
gtk_box_pack_start (GTK_BOX (hbox2), evbox, TRUE, TRUE, 0);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
||||
gtk_container_add (GTK_CONTAINER (evbox), frame);
|
||||
ipal->palette = GTK_PREVIEW (gtk_preview_new (GTK_PREVIEW_COLOR));
|
||||
gtk_preview_size (ipal->palette, 256, 256);
|
||||
gtk_widget_set_events (GTK_WIDGET(ipal->palette), GDK_BUTTON_PRESS_MASK);
|
||||
ipal->event_handler =
|
||||
gtk_signal_connect (GTK_OBJECT (ipal->palette), "event",
|
||||
GTK_SIGNAL_FUNC (ipal_area_events),
|
||||
ipal);
|
||||
gtk_signal_handler_block (GTK_OBJECT (ipal->palette),
|
||||
ipal->event_handler);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (ipal->palette));
|
||||
|
||||
/* dnd stuff */
|
||||
gtk_drag_source_set (GTK_WIDGET (ipal->palette),
|
||||
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
|
||||
color_palette_target_table, n_color_palette_targets,
|
||||
GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
||||
gimp_dnd_color_source_set (GTK_WIDGET (ipal->palette),
|
||||
palette_drag_color, ipal);
|
||||
|
||||
gtk_drag_dest_set (GTK_WIDGET (ipal->palette),
|
||||
GTK_DEST_DEFAULT_HIGHLIGHT |
|
||||
GTK_DEST_DEFAULT_MOTION |
|
||||
GTK_DEST_DEFAULT_DROP,
|
||||
color_palette_target_table, n_color_palette_targets,
|
||||
GDK_ACTION_COPY);
|
||||
gimp_dnd_color_dest_set (GTK_WIDGET (ipal->palette),
|
||||
palette_drop_color, ipal);
|
||||
|
||||
/* some helpful hints */
|
||||
hbox = gtk_hbox_new (FALSE, 4);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||
|
||||
label = gtk_label_new (_("Index:"));
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
||||
|
||||
ipal->index_spinbutton =
|
||||
gimp_spin_button_new ((GtkObject **) &ipal->index_adjustment,
|
||||
0, 0, 0, 1, 10, 10, 1.0, 0);
|
||||
gtk_signal_connect (GTK_OBJECT (ipal->index_adjustment), "value_changed",
|
||||
GTK_SIGNAL_FUNC (index_adjustment_change_cb),
|
||||
ipal);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), ipal->index_spinbutton, FALSE, FALSE, 0);
|
||||
|
||||
label = gtk_label_new (_("Hex Triplet:"));
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
||||
|
||||
entry = gtk_entry_new_with_max_length (7);
|
||||
ipal->color_entry = GTK_ENTRY (entry);
|
||||
gtk_signal_connect (GTK_OBJECT (entry), "activate",
|
||||
GTK_SIGNAL_FUNC (hex_entry_change_cb),
|
||||
ipal);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
|
||||
|
||||
/* Connect the "F1" help key */
|
||||
gimp_help_connect_help_accel (GTK_WIDGET (ipal),
|
||||
gimp_standard_help_func,
|
||||
"dialogs/indexed_palette.html");
|
||||
|
||||
gtk_widget_show_all (vbox);
|
||||
/* gtk_widget_show (ipal); */
|
||||
|
||||
ipal_update_image_list (ipal);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (context), "add",
|
||||
GTK_SIGNAL_FUNC (set_addrem_cb),
|
||||
ipal);
|
||||
gtk_signal_connect (GTK_OBJECT (context), "remove",
|
||||
GTK_SIGNAL_FUNC (set_addrem_cb),
|
||||
ipal);
|
||||
|
||||
return ipal;
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_update_image_list (GimpColormapDialog* ipal)
|
||||
{
|
||||
gint default_index;
|
||||
GimpImage *default_gimage;
|
||||
|
||||
default_gimage = ipal->image;
|
||||
ipal->image_menu =
|
||||
create_image_menu (ipal,
|
||||
&default_gimage,
|
||||
&default_index,
|
||||
image_menu_callback);
|
||||
gtk_option_menu_set_menu (ipal->option_menu, ipal->image_menu);
|
||||
|
||||
if (default_index != -1)
|
||||
{
|
||||
if (! GTK_WIDGET_IS_SENSITIVE (ipal->vbox))
|
||||
gtk_widget_set_sensitive (ipal->vbox, TRUE);
|
||||
gtk_option_menu_set_history (ipal->option_menu, default_index);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GTK_WIDGET_IS_SENSITIVE (ipal->vbox))
|
||||
{
|
||||
gtk_widget_set_sensitive (ipal->vbox, FALSE);
|
||||
}
|
||||
}
|
||||
ipal_set_image (ipal, default_gimage);
|
||||
}
|
||||
|
||||
static void
|
||||
frame_size_alloc_cb (GtkFrame *frame,
|
||||
GtkAllocation *alloc,
|
||||
GimpColormapDialog *ipal)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (frame);
|
||||
GtkAllocation allocation = *alloc;
|
||||
GtkRequisition requisition;
|
||||
|
||||
if (ipal->image)
|
||||
ipal_draw (ipal);
|
||||
else
|
||||
ipal_clear (ipal);
|
||||
|
||||
widget = GTK_BIN (widget)->child;
|
||||
gtk_widget_size_request (widget, &requisition);
|
||||
|
||||
allocation.x = MAX (0, allocation.width - requisition.width) / 2;
|
||||
allocation.y = MAX (0, allocation.height - requisition.height) / 2;
|
||||
allocation.width = MIN (allocation.width, requisition.width);
|
||||
allocation.height = MIN (allocation.height, requisition.height);
|
||||
|
||||
gtk_widget_size_allocate (widget, &allocation);
|
||||
}
|
||||
|
||||
static void
|
||||
window_size_req_cb (GtkWindow *window,
|
||||
GtkRequisition *requsition,
|
||||
GimpColormapDialog *ipal)
|
||||
{
|
||||
requsition->width = GTK_WIDGET (window)->allocation.width;
|
||||
requsition->height = GTK_WIDGET (window)->allocation.height;
|
||||
}
|
||||
|
||||
#define MIN_CELL_SIZE 4
|
||||
|
||||
static void
|
||||
ipal_draw (GimpColormapDialog* ipal)
|
||||
{
|
||||
GimpImage *gimage;
|
||||
gint i, j, k, l, b;
|
||||
gint col;
|
||||
guchar *row;
|
||||
gint cellsize, ncol, xn, yn, width, height;
|
||||
GtkWidget *palette;
|
||||
GtkContainer *parent;
|
||||
|
||||
g_return_if_fail (ipal);
|
||||
|
||||
gimage = ipal->image;
|
||||
g_return_if_fail (gimage);
|
||||
|
||||
palette = GTK_WIDGET (ipal->palette);
|
||||
parent = GTK_CONTAINER (palette->parent);
|
||||
width = GTK_WIDGET (parent)->allocation.width - parent->border_width;
|
||||
height = GTK_WIDGET (parent)->allocation.height - parent->border_width;
|
||||
ncol = gimage->num_cols;
|
||||
|
||||
if (!ncol)
|
||||
{
|
||||
ipal_clear (ipal);
|
||||
return;
|
||||
}
|
||||
|
||||
cellsize = sqrt(width * height / ncol);
|
||||
while (cellsize >= MIN_CELL_SIZE
|
||||
&& (xn = width/cellsize) * (yn = height/cellsize) < ncol)
|
||||
cellsize--;
|
||||
|
||||
if (cellsize < MIN_CELL_SIZE)
|
||||
{
|
||||
cellsize = MIN_CELL_SIZE;
|
||||
xn = yn = ceil (sqrt (ncol));
|
||||
}
|
||||
|
||||
yn = ((ncol + xn - 1) / xn);
|
||||
width = xn * cellsize;
|
||||
height = yn * cellsize;
|
||||
ipal->xn = xn;
|
||||
ipal->yn = yn;
|
||||
ipal->cellsize = cellsize;
|
||||
|
||||
gtk_preview_size (ipal->palette, width, height);
|
||||
|
||||
/*gtk_container_resize_children(GTK_WIDGET(parent)->parent);*/
|
||||
|
||||
/* req.width = width + parent->border_width;
|
||||
req.height = height + parent->border_width;
|
||||
gtk_widget_size_request(palette->parent, &req);*/
|
||||
/*gtk_widget_queue_resize (GTK_WIDGET(ipal));*/
|
||||
/*gtk_container_check_resize (GTK_WIDGET(parent)->parent);*/
|
||||
|
||||
|
||||
row = g_new (guchar, xn * cellsize * 3);
|
||||
col = 0;
|
||||
for (i = 0; i < yn; i++)
|
||||
{
|
||||
for (j = 0; j < xn && col < ncol; j++, col++)
|
||||
{
|
||||
for (k = 0; k < cellsize; k++)
|
||||
for (b = 0; b < 3; b++)
|
||||
row[(j * cellsize + k) * 3 + b] = gimage->cmap[col * 3 + b];
|
||||
}
|
||||
|
||||
for (k = 0; k < cellsize; k++)
|
||||
{
|
||||
for (l = j * cellsize; l < xn * cellsize; l++)
|
||||
for (b = 0; b < 3; b++)
|
||||
row[l * 3 + b] = ((((i * cellsize + k) & 0x4) ? (l) : (l + 0x4)) & 0x4) ?
|
||||
blend_light_check[0] : blend_dark_check[0];
|
||||
|
||||
gtk_preview_draw_row (ipal->palette, row, 0,
|
||||
i * cellsize + k, cellsize * xn);
|
||||
}
|
||||
}
|
||||
ipal_draw_cell (ipal, ipal->col_index);
|
||||
|
||||
g_free (row);
|
||||
gtk_widget_draw (palette, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_draw_cell (GimpColormapDialog *ipal,
|
||||
gint col)
|
||||
{
|
||||
guchar *row;
|
||||
gint cellsize, x, y, k;
|
||||
GdkRectangle rec;
|
||||
|
||||
g_assert (ipal);
|
||||
g_assert (ipal->image);
|
||||
g_assert (col < ipal->image->num_cols);
|
||||
|
||||
cellsize = ipal->cellsize;
|
||||
row = g_new(guchar, cellsize * 3);
|
||||
x = (col % ipal->xn) * cellsize;
|
||||
y = (col / ipal->xn) * cellsize;
|
||||
|
||||
if (col == ipal->col_index)
|
||||
{
|
||||
for(k = 0; k < cellsize; k++)
|
||||
row[k*3] = row[k*3+1] = row[k*3+2] = (k & 1) * 255;
|
||||
gtk_preview_draw_row (ipal->palette, row, x, y, cellsize);
|
||||
|
||||
if (!(cellsize & 1))
|
||||
for (k = 0; k < cellsize; k++)
|
||||
row[k*3] = row[k*3+1] = row[k*3+2] = ((x+y+1) & 1) * 255;
|
||||
gtk_preview_draw_row (ipal->palette, row, x, y+cellsize-1, cellsize);
|
||||
|
||||
row[0]=row[1]=row[2]=255;
|
||||
row[cellsize*3-3] = row[cellsize*3-2] = row[cellsize*3-1]
|
||||
= 255 * (cellsize & 1);
|
||||
for (k = 1; k < cellsize - 1; k++)
|
||||
{
|
||||
row[k*3] = ipal->image->cmap[col * 3];
|
||||
row[k*3+1] = ipal->image->cmap[col * 3 + 1];
|
||||
row[k*3+2] = ipal->image->cmap[col * 3 + 2];
|
||||
}
|
||||
for (k = 1; k < cellsize - 1; k+=2)
|
||||
gtk_preview_draw_row (ipal->palette, row, x, y+k, cellsize);
|
||||
|
||||
row[0] = row[1] = row[2] = 0;
|
||||
row[cellsize*3-3] = row[cellsize*3-2] = row[cellsize*3-1]
|
||||
= 255 * ((cellsize+1) & 1);
|
||||
for (k = 2; k < cellsize - 1; k += 2)
|
||||
gtk_preview_draw_row (ipal->palette, row, x, y+k, cellsize);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (k = 0; k < cellsize; k++)
|
||||
{
|
||||
row[k*3] = ipal->image->cmap[col * 3];
|
||||
row[k*3+1] = ipal->image->cmap[col * 3 + 1];
|
||||
row[k*3+2] = ipal->image->cmap[col * 3 + 2];
|
||||
}
|
||||
for (k = 0; k < cellsize; k++)
|
||||
gtk_preview_draw_row (ipal->palette, row, x, y+k, cellsize);
|
||||
}
|
||||
rec.x = x;
|
||||
rec.y = y;
|
||||
rec.width = rec.height = cellsize;
|
||||
gtk_widget_draw (GTK_WIDGET (ipal->palette), &rec);
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_clear (GimpColormapDialog* ipal)
|
||||
{
|
||||
gint i, j;
|
||||
gint offset;
|
||||
gint width, height;
|
||||
guchar *row = NULL;
|
||||
GtkWidget *palette;
|
||||
|
||||
g_return_if_fail (ipal);
|
||||
|
||||
palette = GTK_WIDGET (ipal->palette);
|
||||
|
||||
/* Watch out for negative values (at least on Win32) */
|
||||
width = (int) (gint16) palette->allocation.width;
|
||||
height = (int) (gint16) palette->allocation.height;
|
||||
if (width > 0)
|
||||
row = g_new (guchar, width * 3);
|
||||
|
||||
gtk_preview_size (ipal->palette, width, height);
|
||||
|
||||
for (i = 0; i < height; i += 4)
|
||||
{
|
||||
offset = (i & 0x4) ? 0x4 : 0x0;
|
||||
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
row[j * 3 + 0] = row[j * 3 + 1] = row[j * 3 + 2] =
|
||||
((j + offset) & 0x4) ? blend_light_check[0] : blend_dark_check[0];
|
||||
}
|
||||
|
||||
for (j = 0; j < 4 && i+j < height; j++)
|
||||
gtk_preview_draw_row (ipal->palette, row, 0, i + j, width);
|
||||
}
|
||||
if (width > 0)
|
||||
g_free (row);
|
||||
gtk_widget_draw (palette, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_update_entries (GimpColormapDialog *ipal)
|
||||
{
|
||||
if (!ipal->image)
|
||||
{
|
||||
gtk_widget_set_sensitive (ipal->index_spinbutton, FALSE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (ipal->color_entry), FALSE);
|
||||
gtk_adjustment_set_value (ipal->index_adjustment, 0);
|
||||
gtk_entry_set_text (ipal->color_entry, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *string;
|
||||
guchar *col;
|
||||
|
||||
gtk_adjustment_set_value (ipal->index_adjustment, ipal->col_index);
|
||||
|
||||
col = &ipal->image->cmap[ipal->col_index * 3];
|
||||
string = g_strdup_printf ("#%02x%02x%02x", col[0], col[1], col[2]);
|
||||
gtk_entry_set_text (ipal->color_entry, string);
|
||||
g_free (string);
|
||||
gtk_widget_set_sensitive (ipal->index_spinbutton, TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (ipal->color_entry), TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_set_index (GimpColormapDialog *ipal,
|
||||
gint i)
|
||||
{
|
||||
if (i != ipal->col_index)
|
||||
{
|
||||
gint old = ipal->col_index;
|
||||
ipal->col_index = i;
|
||||
ipal->dnd_col_index = i;
|
||||
ipal_draw_cell (ipal, old);
|
||||
ipal_draw_cell (ipal, i);
|
||||
ipal_update_entries (ipal);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
index_adjustment_change_cb (GtkAdjustment *adjustment,
|
||||
GimpColormapDialog *ipal)
|
||||
{
|
||||
g_return_if_fail (ipal);
|
||||
|
||||
if (!ipal->image)
|
||||
return;
|
||||
|
||||
ipal_set_index (ipal, (gint) (adjustment->value + 0.5));
|
||||
|
||||
ipal_update_entries (ipal);
|
||||
}
|
||||
|
||||
static void
|
||||
hex_entry_change_cb (GtkEntry *entry,
|
||||
GimpColormapDialog *ipal)
|
||||
{
|
||||
gchar *s;
|
||||
gulong i;
|
||||
|
||||
g_return_if_fail (ipal);
|
||||
g_return_if_fail (ipal->image);
|
||||
|
||||
s = gtk_entry_get_text (entry);
|
||||
|
||||
if (sscanf (s, "#%lx", &i))
|
||||
{
|
||||
guchar *c = &ipal->image->cmap[3 * ipal->col_index];
|
||||
c[0] = (i & 0xFF0000) >> 16;
|
||||
c[1] = (i & 0x00FF00) >> 8;
|
||||
c[2] = (i & 0x0000FF);
|
||||
gimp_image_colormap_changed (ipal->image, ipal->col_index);
|
||||
}
|
||||
|
||||
ipal_update_entries (ipal);
|
||||
}
|
||||
|
||||
static void
|
||||
set_addrem_cb (GimpSet *set,
|
||||
GimpImage *image,
|
||||
GimpColormapDialog *ipal)
|
||||
{
|
||||
ipal_update_image_list (ipal);
|
||||
}
|
||||
|
||||
static void
|
||||
image_rename_cb (GimpImage *img,
|
||||
GimpColormapDialog *ipal)
|
||||
{
|
||||
ipal_update_image_list (ipal);
|
||||
}
|
||||
|
||||
static void
|
||||
image_cmap_change_cb (GimpImage *img,
|
||||
gint ncol,
|
||||
GimpColormapDialog *ipal)
|
||||
{
|
||||
if (img == ipal->image && gimp_image_base_type (img) == INDEXED)
|
||||
{
|
||||
if (ncol < 0)
|
||||
{
|
||||
ipal_draw (ipal);
|
||||
gtk_container_queue_resize (GTK_CONTAINER (ipal));
|
||||
}
|
||||
else
|
||||
{
|
||||
ipal_draw_cell (ipal, ncol);
|
||||
}
|
||||
|
||||
if (ncol == ipal->col_index)
|
||||
ipal_update_entries (ipal);
|
||||
|
||||
gtk_widget_set_sensitive (ipal->add_item, (img->num_cols < 256));
|
||||
|
||||
if ((ipal->index_adjustment->upper + 1) < img->num_cols)
|
||||
{
|
||||
ipal->index_adjustment->upper = img->num_cols - 1;
|
||||
gtk_adjustment_changed (ipal->index_adjustment);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ipal_update_image_list (ipal);
|
||||
}
|
||||
|
||||
gdisplays_flush_now ();
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_set_image (GimpColormapDialog *ipal,
|
||||
GimpImage *gimage)
|
||||
{
|
||||
g_assert (ipal);
|
||||
|
||||
if (ipal->image)
|
||||
{
|
||||
ipal->image = gimage;
|
||||
|
||||
if (!gimage)
|
||||
{
|
||||
gtk_signal_handler_block (GTK_OBJECT (ipal->palette),
|
||||
ipal->event_handler);
|
||||
if (GTK_WIDGET_MAPPED (GTK_WIDGET (ipal)))
|
||||
ipal_clear (ipal);
|
||||
}
|
||||
}
|
||||
|
||||
ipal->col_index = 0;
|
||||
ipal->dnd_col_index = 0;
|
||||
if (gimage)
|
||||
{
|
||||
if (!ipal->image)
|
||||
gtk_signal_handler_unblock (GTK_OBJECT (ipal->palette),
|
||||
ipal->event_handler);
|
||||
g_return_if_fail (gimp_set_have (ipal->context, gimage));
|
||||
g_return_if_fail (gimp_image_base_type (gimage) == INDEXED);
|
||||
ipal->image = gimage;
|
||||
ipal_draw (ipal);
|
||||
gtk_container_queue_resize (GTK_CONTAINER (ipal));
|
||||
ipal->index_adjustment->upper = ipal->image->num_cols - 1;
|
||||
gtk_adjustment_changed (ipal->index_adjustment);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ipal->color_notebook)
|
||||
color_notebook_hide (ipal->color_notebook);
|
||||
ipal->index_adjustment->upper = 0;
|
||||
gtk_adjustment_changed (ipal->index_adjustment);
|
||||
}
|
||||
|
||||
gtk_widget_set_sensitive (ipal->add_item,
|
||||
(gimage && gimage->num_cols < 256));
|
||||
ipal_update_entries (ipal);
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_add_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GimpColormapDialog *ipal = data;
|
||||
|
||||
g_return_if_fail (ipal);
|
||||
g_return_if_fail (ipal->image->num_cols < 256);
|
||||
|
||||
memcpy (&ipal->image->cmap[ipal->image->num_cols * 3],
|
||||
&ipal->image->cmap[ipal->col_index * 3],
|
||||
3);
|
||||
ipal->image->num_cols++;
|
||||
|
||||
gimp_image_colormap_changed (ipal->image, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_edit_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GimpColormapDialog* ipal = data;
|
||||
guchar r, g, b;
|
||||
|
||||
g_return_if_fail (ipal);
|
||||
|
||||
r = ipal->image->cmap[ipal->col_index*3];
|
||||
g = ipal->image->cmap[ipal->col_index*3+1];
|
||||
b = ipal->image->cmap[ipal->col_index*3+2];
|
||||
|
||||
if (! ipal->color_notebook)
|
||||
{
|
||||
ipal->color_notebook
|
||||
= color_notebook_new (r, g, b, 255,
|
||||
ipal_select_callback, ipal, FALSE, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
color_notebook_show (ipal->color_notebook);
|
||||
color_notebook_set_color (ipal->color_notebook, r, g, b, 255, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_close_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GimpColormapDialog* ipal = data;
|
||||
|
||||
g_assert (ipal);
|
||||
|
||||
gtk_widget_hide (GTK_WIDGET (ipal));
|
||||
}
|
||||
|
||||
static void
|
||||
ipal_select_callback (gint r,
|
||||
gint g,
|
||||
gint b,
|
||||
gint a,
|
||||
ColorNotebookState state,
|
||||
gpointer data)
|
||||
{
|
||||
GimpImage *gimage;
|
||||
GimpColormapDialog *ipal = data;
|
||||
|
||||
g_return_if_fail (ipal);
|
||||
g_return_if_fail (ipal->image);
|
||||
g_return_if_fail (ipal->color_notebook);
|
||||
|
||||
gimage = ipal->image;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case COLOR_NOTEBOOK_UPDATE:
|
||||
break;
|
||||
case COLOR_NOTEBOOK_OK:
|
||||
gimage->cmap[ipal->col_index * 3 + 0] = r;
|
||||
gimage->cmap[ipal->col_index * 3 + 1] = g;
|
||||
gimage->cmap[ipal->col_index * 3 + 2] = b;
|
||||
gimp_image_colormap_changed (gimage, ipal->col_index);
|
||||
/* Fall through */
|
||||
case COLOR_NOTEBOOK_CANCEL:
|
||||
color_notebook_hide (ipal->color_notebook);
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
ipal_area_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
GimpColormapDialog *ipal)
|
||||
{
|
||||
GimpImage *gimage;
|
||||
GdkEventButton *bevent;
|
||||
guchar r, g, b;
|
||||
guint col;
|
||||
|
||||
g_assert (ipal);
|
||||
|
||||
gimage = ipal->image;
|
||||
g_assert (gimage);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case GDK_BUTTON_PRESS:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button < 1 || bevent->button > 3)
|
||||
return FALSE;
|
||||
|
||||
if (!(bevent->y < ipal->cellsize * ipal->yn
|
||||
&& bevent->x < ipal->cellsize * ipal->xn))
|
||||
return FALSE;
|
||||
|
||||
col = ipal->xn * ((int)bevent->y / ipal->cellsize)
|
||||
+ ((int)bevent->x / ipal->cellsize);
|
||||
|
||||
if (col >= ipal->image->num_cols)
|
||||
return FALSE;
|
||||
|
||||
r = gimage->cmap[col * 3 + 0];
|
||||
g = gimage->cmap[col * 3 + 1];
|
||||
b = gimage->cmap[col * 3 + 2];
|
||||
|
||||
switch (bevent->button)
|
||||
{
|
||||
case 1:
|
||||
ipal_set_index (ipal, col);
|
||||
gimp_colormap_dialog_selected (ipal);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
ipal->dnd_col_index = col;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
ipal_set_index (ipal, col);
|
||||
gtk_menu_popup (GTK_MENU (ipal->popup_menu), NULL, NULL,
|
||||
NULL, NULL, 3,
|
||||
bevent->time);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
image_menu_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GimpColormapDialog* ipal = gtk_object_get_data (GTK_OBJECT (widget),
|
||||
"colormap_dialog");
|
||||
GimpImage* image = GIMP_IMAGE (data);
|
||||
|
||||
g_assert (ipal);
|
||||
g_assert (image);
|
||||
|
||||
ipal_set_image (ipal, image);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GimpImage **def;
|
||||
gint *default_index;
|
||||
GtkSignalFunc callback;
|
||||
GtkWidget *menu;
|
||||
gint num_items;
|
||||
GimpImage *id;
|
||||
GimpColormapDialog *ipal;
|
||||
} IMCBData;
|
||||
|
||||
static void
|
||||
create_image_menu_cb (gpointer im,
|
||||
gpointer d)
|
||||
{
|
||||
GimpImage *gimage = GIMP_IMAGE (im);
|
||||
IMCBData *data = (IMCBData *) d;
|
||||
gchar *image_name;
|
||||
gchar *menu_item_label;
|
||||
GtkWidget *menu_item;
|
||||
|
||||
if (gimp_image_base_type (gimage) != INDEXED)
|
||||
return;
|
||||
|
||||
/* make sure the default index gets set to _something_, if possible */
|
||||
if (*data->default_index == -1)
|
||||
{
|
||||
data->id = gimage;
|
||||
*data->default_index = data->num_items;
|
||||
}
|
||||
|
||||
if (gimage == *data->def)
|
||||
{
|
||||
data->id = *data->def;
|
||||
*data->default_index = data->num_items;
|
||||
}
|
||||
|
||||
image_name = g_basename (gimp_image_filename (gimage));
|
||||
menu_item_label = g_strdup_printf ("%s-%d", image_name,
|
||||
pdb_image_to_id (gimage));
|
||||
menu_item = gtk_menu_item_new_with_label (menu_item_label);
|
||||
gtk_object_set_data (GTK_OBJECT (menu_item), "colormap_dialog", data->ipal);
|
||||
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
|
||||
data->callback,
|
||||
gimage);
|
||||
gtk_container_add (GTK_CONTAINER (data->menu), menu_item);
|
||||
gtk_widget_show (menu_item);
|
||||
|
||||
g_free (menu_item_label);
|
||||
data->num_items ++;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_image_menu (GimpColormapDialog *ipal,
|
||||
GimpImage **def,
|
||||
gint *default_index,
|
||||
GtkSignalFunc callback)
|
||||
{
|
||||
IMCBData data;
|
||||
|
||||
data.def = def;
|
||||
data.default_index = default_index;
|
||||
data.callback = callback;
|
||||
data.menu = gtk_menu_new ();
|
||||
data.num_items = 0;
|
||||
data.id = NULL;
|
||||
data.ipal = ipal;
|
||||
|
||||
*default_index = -1;
|
||||
|
||||
gimp_set_foreach (ipal->context, create_image_menu_cb, &data);
|
||||
|
||||
if (!data.num_items)
|
||||
{
|
||||
GtkWidget* menu_item;
|
||||
menu_item = gtk_menu_item_new_with_label (_("none"));
|
||||
gtk_container_add (GTK_CONTAINER (data.menu), menu_item);
|
||||
gtk_widget_show (menu_item);
|
||||
}
|
||||
|
||||
*def = data.id;
|
||||
|
||||
return data.menu;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef _g_gimp_colormap_dialog_import
|
||||
#define _g_gimp_colormap_dialog_import
|
||||
#include <colormap_dialog.h>
|
||||
#define TYPE_COLORMAP_DIALOG GIMP_TYPE_COLORMAP_DIALOG
|
||||
#define ColormapDialog GimpColormapDialog
|
||||
#define IS_COLORMAP_DIALOG GIMP_IS_COLORMAP_DIALOG
|
||||
#define COLORMAP_DIALOG GIMP_COLORMAP_DIALOG
|
||||
#define colormap_dialog_create gimp_colormap_dialog_create
|
||||
#define colormap_dialog_image gimp_colormap_dialog_image
|
||||
#define colormap_dialog_col_index gimp_colormap_dialog_col_index
|
||||
#define colormap_dialog_connect_selected gimp_colormap_dialog_connect_selected
|
||||
#define colormap_dialog_selected gimp_colormap_dialog_selected
|
||||
#endif /* _g_gimp_colormap_dialog_import */
|
|
@ -1,45 +0,0 @@
|
|||
#ifndef _g_gimp_colormap_dialog_prot
|
||||
#define _g_gimp_colormap_dialog_prot
|
||||
#include <colormap_dialog.h>
|
||||
#include <gtk/gtkdialog.h>
|
||||
#include <gimpimage.h>
|
||||
#include <glib.h>
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <gtk/gtkpreview.h>
|
||||
#include <gtk/gtkoptionmenu.h>
|
||||
#include <gimpset.h>
|
||||
#include <gtk/gtkentry.h>
|
||||
#include <color_notebook.h>
|
||||
|
||||
|
||||
typedef struct _GimpColormapDialogClass GimpColormapDialogClass;
|
||||
struct _GimpColormapDialogClass {
|
||||
GtkDialogClass parent_class;
|
||||
void (*selected) (GimpColormapDialog*);
|
||||
};
|
||||
struct _GimpColormapDialog {
|
||||
GtkDialog parent;
|
||||
GimpImage* image;
|
||||
gint col_index;
|
||||
gint dnd_col_index;
|
||||
GtkWidget* vbox;
|
||||
GtkPreview* palette;
|
||||
GtkWidget* image_menu;
|
||||
GtkWidget* popup_menu;
|
||||
GtkOptionMenu* option_menu;
|
||||
GimpSet* context;
|
||||
guint event_handler;
|
||||
gint xn;
|
||||
gint yn;
|
||||
gint cellsize;
|
||||
GtkWidget* index_spinbutton;
|
||||
GtkAdjustment* index_adjustment;
|
||||
GtkEntry* color_entry;
|
||||
GimpSetHandlerId rename_handler;
|
||||
GimpSetHandlerId cmap_changed_handler;
|
||||
GtkWidget* add_item;
|
||||
ColorNotebook *color_notebook;
|
||||
};
|
||||
void gimp_colormap_dialog_selected (
|
||||
GimpColormapDialog* colormap_dialog);
|
||||
#endif /* _g_gimp_colormap_dialog_prot */
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef _g_gimp_colormap_dialog_type
|
||||
#define _g_gimp_colormap_dialog_type
|
||||
#include <gtk/gtktypeutils.h>
|
||||
|
||||
|
||||
#define GIMP_TYPE_COLORMAP_DIALOG \
|
||||
(_gimp_colormap_dialog_type ? (void)0 : _gimp_colormap_dialog_init_type (), _gimp_colormap_dialog_type)
|
||||
extern GtkType _gimp_colormap_dialog_type;
|
||||
void _gimp_colormap_dialog_init_type (void);
|
||||
typedef struct _GimpColormapDialog GimpColormapDialog;
|
||||
#define GIMP_IS_COLORMAP_DIALOG(o) GTK_CHECK_TYPE(o, GIMP_TYPE_COLORMAP_DIALOG)
|
||||
#define GIMP_COLORMAP_DIALOG(o) GTK_CHECK_CAST(o, GIMP_TYPE_COLORMAP_DIALOG, GimpColormapDialog)
|
||||
#endif /* _g_gimp_colormap_dialog_type */
|
|
@ -29,7 +29,7 @@
|
|||
#include "about_dialog.h"
|
||||
#include "app_procs.h"
|
||||
#include "brush_select.h"
|
||||
#include "colormap_dialog.i.h"
|
||||
#include "colormap_dialog.h"
|
||||
#include "color_area.h"
|
||||
#include "commands.h"
|
||||
#include "convert.h"
|
||||
|
@ -1185,13 +1185,13 @@ dialogs_palette_cmd_callback (GtkWidget *widget,
|
|||
}
|
||||
|
||||
static void
|
||||
dialogs_indexed_palette_select_callback (ColormapDialog *dialog,
|
||||
gpointer data)
|
||||
dialogs_indexed_palette_select_callback (GimpColormapDialog *dialog,
|
||||
gpointer data)
|
||||
{
|
||||
guchar *color;
|
||||
GimpImage *image = colormap_dialog_image (dialog);
|
||||
GimpImage *image = gimp_colormap_dialog_image (dialog);
|
||||
|
||||
color = &image->cmap[colormap_dialog_col_index (dialog) * 3];
|
||||
color = &image->cmap[gimp_colormap_dialog_col_index (dialog) * 3];
|
||||
|
||||
if (active_color == FOREGROUND)
|
||||
gimp_context_set_foreground (gimp_context_get_user (),
|
||||
|
@ -1205,16 +1205,22 @@ void
|
|||
dialogs_indexed_palette_cmd_callback (GtkWidget *widget,
|
||||
gpointer client_data)
|
||||
{
|
||||
static ColormapDialog *cmap_dlg;
|
||||
static GimpColormapDialog *cmap_dlg;
|
||||
|
||||
if (!cmap_dlg)
|
||||
{
|
||||
cmap_dlg = colormap_dialog_create (image_context);
|
||||
colormap_dialog_connect_selected (dialogs_indexed_palette_select_callback,
|
||||
NULL, cmap_dlg);
|
||||
cmap_dlg = gimp_colormap_dialog_create (image_context);
|
||||
|
||||
gtk_signal_connect
|
||||
(GTK_OBJECT (cmap_dlg), "selected",
|
||||
GTK_SIGNAL_FUNC (dialogs_indexed_palette_select_callback),
|
||||
NULL);
|
||||
}
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (cmap_dlg));
|
||||
if (! GTK_WIDGET_VISIBLE (cmap_dlg))
|
||||
gtk_widget_show (GTK_WIDGET (cmap_dlg));
|
||||
else
|
||||
gdk_window_raise (GTK_WIDGET (cmap_dlg)->window);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -36,8 +36,6 @@ typedef void (* ColorNotebookCallback) (gint red,
|
|||
|
||||
typedef struct _ColorSelectorInstance ColorSelectorInstance;
|
||||
|
||||
typedef struct _ColorNotebook ColorNotebook;
|
||||
|
||||
struct _ColorNotebook
|
||||
{
|
||||
GtkWidget *shell;
|
||||
|
|
30
app/gimp.gh
30
app/gimp.gh
|
@ -1,30 +0,0 @@
|
|||
#include <gcg.gh>
|
||||
|
||||
package Gimp <> {
|
||||
module <gimpimage.h>{
|
||||
class Image;
|
||||
}
|
||||
module <gimpobject.h>{
|
||||
class Object;
|
||||
}
|
||||
module <gimplayer.h>{
|
||||
class Layer;
|
||||
}
|
||||
module <gimpdrawable.h>{
|
||||
class Drawable;
|
||||
}
|
||||
module <gimpset.h>{
|
||||
class Set;
|
||||
foreign SetHandlerId;
|
||||
}
|
||||
class ColormapDialog;
|
||||
}
|
||||
|
||||
package {
|
||||
module <color_select.h>{
|
||||
foreign ColorSelectP;
|
||||
}
|
||||
module <color_notebook.h>{
|
||||
foreign ColorNotebookP;
|
||||
}
|
||||
}
|
|
@ -66,8 +66,6 @@ struct _GimpSetClass
|
|||
};
|
||||
|
||||
|
||||
typedef guint GimpSetHandlerId;
|
||||
|
||||
GtkType gimp_set_get_type (void);
|
||||
GimpSet * gimp_set_new (GtkType type,
|
||||
gboolean weak);
|
||||
|
|
|
@ -36,8 +36,6 @@ typedef void (* ColorNotebookCallback) (gint red,
|
|||
|
||||
typedef struct _ColorSelectorInstance ColorSelectorInstance;
|
||||
|
||||
typedef struct _ColorNotebook ColorNotebook;
|
||||
|
||||
struct _ColorNotebook
|
||||
{
|
||||
GtkWidget *shell;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,24 +16,64 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _g_gimp_colormap_dialog_funcs
|
||||
#define _g_gimp_colormap_dialog_funcs
|
||||
#ifndef __COLORMAP_DIALOG_H__
|
||||
#define __COLORMAP_DIALOG_H__
|
||||
|
||||
#include <colormap_dialog.t.h>
|
||||
#include <gimpset.h>
|
||||
#include <gimpimage.h>
|
||||
|
||||
GimpColormapDialog* gimp_colormap_dialog_create (
|
||||
GimpSet* context);
|
||||
GimpImage* gimp_colormap_dialog_image (
|
||||
const GimpColormapDialog* colormap_dialog);
|
||||
gint gimp_colormap_dialog_col_index (
|
||||
const GimpColormapDialog* colormap_dialog);
|
||||
typedef void (*GimpColormapDialogHandler_selected)(GimpColormapDialog*,
|
||||
gpointer);
|
||||
void gimp_colormap_dialog_connect_selected (
|
||||
GimpColormapDialogHandler_selected handler,
|
||||
gpointer user_data,
|
||||
GimpColormapDialog* colormap_dialog);
|
||||
#include <gtk/gtkdialog.h>
|
||||
|
||||
#endif /* _g_gimp_colormap_dialog_funcs */
|
||||
|
||||
#define GIMP_TYPE_COLORMAP_DIALOG (gimp_colormap_dialog_get_type ())
|
||||
#define GIMP_COLORMAP_DIALOG(obj) (GTK_CHECK_CAST((obj), GIMP_TYPE_COLORMAP_DIALOG, GimpColormapDialog))
|
||||
#define GIMP_COLORMAP_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GIMP_TYPE_COLORMAP_DIALOG, GimpColormapDialogClass))
|
||||
#define GIMP_IS_COLORMAP_DIALOG(obj) (GTK_CHECK_TYPE((obj), GIMP_TYPE_COLORMAP_DIALOG))
|
||||
#define GIMP_IS_COLORMAP_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GIMP_TYPE_COLORMAP_DIALOG))
|
||||
|
||||
|
||||
typedef struct _GimpColormapDialog GimpColormapDialog;
|
||||
typedef struct _GimpColormapDialogClass GimpColormapDialogClass;
|
||||
|
||||
struct _GimpColormapDialog
|
||||
{
|
||||
GtkDialog parent;
|
||||
|
||||
GimpImage *image;
|
||||
gint col_index;
|
||||
gint dnd_col_index;
|
||||
GtkWidget *vbox;
|
||||
GtkPreview *palette;
|
||||
GtkWidget *image_menu;
|
||||
GtkWidget *popup_menu;
|
||||
GtkOptionMenu *option_menu;
|
||||
GimpSet *context;
|
||||
guint event_handler;
|
||||
gint xn;
|
||||
gint yn;
|
||||
gint cellsize;
|
||||
GtkWidget *index_spinbutton;
|
||||
GtkAdjustment *index_adjustment;
|
||||
GtkEntry *color_entry;
|
||||
GimpSetHandlerId rename_handler;
|
||||
GimpSetHandlerId cmap_changed_handler;
|
||||
GtkWidget *add_item;
|
||||
ColorNotebook *color_notebook;
|
||||
};
|
||||
|
||||
struct _GimpColormapDialogClass
|
||||
{
|
||||
GtkDialogClass parent_class;
|
||||
|
||||
void (* selected) (GimpColormapDialog *gcd);
|
||||
};
|
||||
|
||||
|
||||
GtkType gimp_colormap_dialog_get_type (void);
|
||||
GimpColormapDialog * gimp_colormap_dialog_create (GimpSet* context);
|
||||
|
||||
void gimp_colormap_dialog_selected (GimpColormapDialog *colormap_dialog);
|
||||
|
||||
GimpImage * gimp_colormap_dialog_image (const GimpColormapDialog *colormap_dialog);
|
||||
gint gimp_colormap_dialog_col_index (const GimpColormapDialog *colormap_dialog);
|
||||
|
||||
|
||||
#endif /* __COLORMAP_DIALOG_H__ */
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "about_dialog.h"
|
||||
#include "app_procs.h"
|
||||
#include "brush_select.h"
|
||||
#include "colormap_dialog.i.h"
|
||||
#include "colormap_dialog.h"
|
||||
#include "color_area.h"
|
||||
#include "commands.h"
|
||||
#include "convert.h"
|
||||
|
@ -1185,13 +1185,13 @@ dialogs_palette_cmd_callback (GtkWidget *widget,
|
|||
}
|
||||
|
||||
static void
|
||||
dialogs_indexed_palette_select_callback (ColormapDialog *dialog,
|
||||
gpointer data)
|
||||
dialogs_indexed_palette_select_callback (GimpColormapDialog *dialog,
|
||||
gpointer data)
|
||||
{
|
||||
guchar *color;
|
||||
GimpImage *image = colormap_dialog_image (dialog);
|
||||
GimpImage *image = gimp_colormap_dialog_image (dialog);
|
||||
|
||||
color = &image->cmap[colormap_dialog_col_index (dialog) * 3];
|
||||
color = &image->cmap[gimp_colormap_dialog_col_index (dialog) * 3];
|
||||
|
||||
if (active_color == FOREGROUND)
|
||||
gimp_context_set_foreground (gimp_context_get_user (),
|
||||
|
@ -1205,16 +1205,22 @@ void
|
|||
dialogs_indexed_palette_cmd_callback (GtkWidget *widget,
|
||||
gpointer client_data)
|
||||
{
|
||||
static ColormapDialog *cmap_dlg;
|
||||
static GimpColormapDialog *cmap_dlg;
|
||||
|
||||
if (!cmap_dlg)
|
||||
{
|
||||
cmap_dlg = colormap_dialog_create (image_context);
|
||||
colormap_dialog_connect_selected (dialogs_indexed_palette_select_callback,
|
||||
NULL, cmap_dlg);
|
||||
cmap_dlg = gimp_colormap_dialog_create (image_context);
|
||||
|
||||
gtk_signal_connect
|
||||
(GTK_OBJECT (cmap_dlg), "selected",
|
||||
GTK_SIGNAL_FUNC (dialogs_indexed_palette_select_callback),
|
||||
NULL);
|
||||
}
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (cmap_dlg));
|
||||
if (! GTK_WIDGET_VISIBLE (cmap_dlg))
|
||||
gtk_widget_show (GTK_WIDGET (cmap_dlg));
|
||||
else
|
||||
gdk_window_raise (GTK_WIDGET (cmap_dlg)->window);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "about_dialog.h"
|
||||
#include "app_procs.h"
|
||||
#include "brush_select.h"
|
||||
#include "colormap_dialog.i.h"
|
||||
#include "colormap_dialog.h"
|
||||
#include "color_area.h"
|
||||
#include "commands.h"
|
||||
#include "convert.h"
|
||||
|
@ -1185,13 +1185,13 @@ dialogs_palette_cmd_callback (GtkWidget *widget,
|
|||
}
|
||||
|
||||
static void
|
||||
dialogs_indexed_palette_select_callback (ColormapDialog *dialog,
|
||||
gpointer data)
|
||||
dialogs_indexed_palette_select_callback (GimpColormapDialog *dialog,
|
||||
gpointer data)
|
||||
{
|
||||
guchar *color;
|
||||
GimpImage *image = colormap_dialog_image (dialog);
|
||||
GimpImage *image = gimp_colormap_dialog_image (dialog);
|
||||
|
||||
color = &image->cmap[colormap_dialog_col_index (dialog) * 3];
|
||||
color = &image->cmap[gimp_colormap_dialog_col_index (dialog) * 3];
|
||||
|
||||
if (active_color == FOREGROUND)
|
||||
gimp_context_set_foreground (gimp_context_get_user (),
|
||||
|
@ -1205,16 +1205,22 @@ void
|
|||
dialogs_indexed_palette_cmd_callback (GtkWidget *widget,
|
||||
gpointer client_data)
|
||||
{
|
||||
static ColormapDialog *cmap_dlg;
|
||||
static GimpColormapDialog *cmap_dlg;
|
||||
|
||||
if (!cmap_dlg)
|
||||
{
|
||||
cmap_dlg = colormap_dialog_create (image_context);
|
||||
colormap_dialog_connect_selected (dialogs_indexed_palette_select_callback,
|
||||
NULL, cmap_dlg);
|
||||
cmap_dlg = gimp_colormap_dialog_create (image_context);
|
||||
|
||||
gtk_signal_connect
|
||||
(GTK_OBJECT (cmap_dlg), "selected",
|
||||
GTK_SIGNAL_FUNC (dialogs_indexed_palette_select_callback),
|
||||
NULL);
|
||||
}
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (cmap_dlg));
|
||||
if (! GTK_WIDGET_VISIBLE (cmap_dlg))
|
||||
gtk_widget_show (GTK_WIDGET (cmap_dlg));
|
||||
else
|
||||
gdk_window_raise (GTK_WIDGET (cmap_dlg)->window);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -36,8 +36,6 @@ typedef void (* ColorNotebookCallback) (gint red,
|
|||
|
||||
typedef struct _ColorSelectorInstance ColorSelectorInstance;
|
||||
|
||||
typedef struct _ColorNotebook ColorNotebook;
|
||||
|
||||
struct _ColorNotebook
|
||||
{
|
||||
GtkWidget *shell;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,24 +16,64 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _g_gimp_colormap_dialog_funcs
|
||||
#define _g_gimp_colormap_dialog_funcs
|
||||
#ifndef __COLORMAP_DIALOG_H__
|
||||
#define __COLORMAP_DIALOG_H__
|
||||
|
||||
#include <colormap_dialog.t.h>
|
||||
#include <gimpset.h>
|
||||
#include <gimpimage.h>
|
||||
|
||||
GimpColormapDialog* gimp_colormap_dialog_create (
|
||||
GimpSet* context);
|
||||
GimpImage* gimp_colormap_dialog_image (
|
||||
const GimpColormapDialog* colormap_dialog);
|
||||
gint gimp_colormap_dialog_col_index (
|
||||
const GimpColormapDialog* colormap_dialog);
|
||||
typedef void (*GimpColormapDialogHandler_selected)(GimpColormapDialog*,
|
||||
gpointer);
|
||||
void gimp_colormap_dialog_connect_selected (
|
||||
GimpColormapDialogHandler_selected handler,
|
||||
gpointer user_data,
|
||||
GimpColormapDialog* colormap_dialog);
|
||||
#include <gtk/gtkdialog.h>
|
||||
|
||||
#endif /* _g_gimp_colormap_dialog_funcs */
|
||||
|
||||
#define GIMP_TYPE_COLORMAP_DIALOG (gimp_colormap_dialog_get_type ())
|
||||
#define GIMP_COLORMAP_DIALOG(obj) (GTK_CHECK_CAST((obj), GIMP_TYPE_COLORMAP_DIALOG, GimpColormapDialog))
|
||||
#define GIMP_COLORMAP_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GIMP_TYPE_COLORMAP_DIALOG, GimpColormapDialogClass))
|
||||
#define GIMP_IS_COLORMAP_DIALOG(obj) (GTK_CHECK_TYPE((obj), GIMP_TYPE_COLORMAP_DIALOG))
|
||||
#define GIMP_IS_COLORMAP_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GIMP_TYPE_COLORMAP_DIALOG))
|
||||
|
||||
|
||||
typedef struct _GimpColormapDialog GimpColormapDialog;
|
||||
typedef struct _GimpColormapDialogClass GimpColormapDialogClass;
|
||||
|
||||
struct _GimpColormapDialog
|
||||
{
|
||||
GtkDialog parent;
|
||||
|
||||
GimpImage *image;
|
||||
gint col_index;
|
||||
gint dnd_col_index;
|
||||
GtkWidget *vbox;
|
||||
GtkPreview *palette;
|
||||
GtkWidget *image_menu;
|
||||
GtkWidget *popup_menu;
|
||||
GtkOptionMenu *option_menu;
|
||||
GimpSet *context;
|
||||
guint event_handler;
|
||||
gint xn;
|
||||
gint yn;
|
||||
gint cellsize;
|
||||
GtkWidget *index_spinbutton;
|
||||
GtkAdjustment *index_adjustment;
|
||||
GtkEntry *color_entry;
|
||||
GimpSetHandlerId rename_handler;
|
||||
GimpSetHandlerId cmap_changed_handler;
|
||||
GtkWidget *add_item;
|
||||
ColorNotebook *color_notebook;
|
||||
};
|
||||
|
||||
struct _GimpColormapDialogClass
|
||||
{
|
||||
GtkDialogClass parent_class;
|
||||
|
||||
void (* selected) (GimpColormapDialog *gcd);
|
||||
};
|
||||
|
||||
|
||||
GtkType gimp_colormap_dialog_get_type (void);
|
||||
GimpColormapDialog * gimp_colormap_dialog_create (GimpSet* context);
|
||||
|
||||
void gimp_colormap_dialog_selected (GimpColormapDialog *colormap_dialog);
|
||||
|
||||
GimpImage * gimp_colormap_dialog_image (const GimpColormapDialog *colormap_dialog);
|
||||
gint gimp_colormap_dialog_col_index (const GimpColormapDialog *colormap_dialog);
|
||||
|
||||
|
||||
#endif /* __COLORMAP_DIALOG_H__ */
|
||||
|
|
|
@ -106,9 +106,6 @@ echo "Running gettextize... Ignore non-fatal messages."
|
|||
echo "no" | gettextize --copy --force
|
||||
|
||||
autogen_dirs="."
|
||||
#if test -z "$NO_GCG"; then
|
||||
# autogen_dirs="$autogen_dirs tools/gcg"
|
||||
#fi
|
||||
|
||||
for i in $autogen_dirs; do
|
||||
echo "Processing $i..."
|
||||
|
|
18
configure.in
18
configure.in
|
@ -54,24 +54,6 @@ dnl,
|
|||
dnl if $ac_make -v 2>/dev/null | grep 'GNU Make' >/dev/null; then
|
||||
dnl with_gnu_make=yes
|
||||
dnl fi)
|
||||
dnl
|
||||
dnl AC_ARG_WITH(gcg, [ --with-gcg build 'gcg' code generation tool],
|
||||
dnl,
|
||||
dnl with_gcg=$enable_maintainer_mode)
|
||||
dnl
|
||||
dnl if test "x$with_gcg" = xyes; then
|
||||
dnl AC_CONFIG_SUBDIRS(tools/gcg)
|
||||
dnl fi
|
||||
dnl
|
||||
dnl AC_ARG_ENABLE(gcg-deps, [ --enable-gcg-deps turn on dynamic gcg dependency tracking (need gcc and gnu make)],
|
||||
dnl ,
|
||||
dnl if eval "test x$GCC$with_gnu_make$with_gcg = xyesyesyes"; then
|
||||
dnl enable_gcg_deps=yes
|
||||
dnl fi)
|
||||
dnl
|
||||
dnl AM_CONDITIONAL(WITH_GCG, test x$with_gcg = xyes)
|
||||
dnl AM_CONDITIONAL(WITH_GNU_MAKE, test x$with_gnu_make = xyes)
|
||||
dnl AM_CONDITIONAL(ENABLE_GCG_DEPS, test x$enable_gcg_deps = xyes)
|
||||
|
||||
AC_ARG_ENABLE(ansi, [ --enable-ansi turn on strict ansi [default=no]],
|
||||
, enable_ansi=no)
|
||||
|
|
|
@ -68,11 +68,11 @@ gimp_unit_menu_destroy (GtkObject *object)
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_unit_menu_class_init (GimpUnitMenuClass *class)
|
||||
gimp_unit_menu_class_init (GimpUnitMenuClass *klass)
|
||||
{
|
||||
GtkObjectClass *object_class;
|
||||
|
||||
object_class = (GtkObjectClass*) class;
|
||||
object_class = (GtkObjectClass*) klass;
|
||||
|
||||
parent_class = gtk_type_class (gtk_option_menu_get_type ());
|
||||
|
||||
|
@ -87,7 +87,7 @@ gimp_unit_menu_class_init (GimpUnitMenuClass *class)
|
|||
gtk_object_class_add_signals (object_class, gimp_unit_menu_signals,
|
||||
LAST_SIGNAL);
|
||||
|
||||
class->unit_changed = NULL;
|
||||
klass->unit_changed = NULL;
|
||||
|
||||
object_class->destroy = gimp_unit_menu_destroy;
|
||||
}
|
||||
|
|
|
@ -68,11 +68,11 @@ gimp_unit_menu_destroy (GtkObject *object)
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_unit_menu_class_init (GimpUnitMenuClass *class)
|
||||
gimp_unit_menu_class_init (GimpUnitMenuClass *klass)
|
||||
{
|
||||
GtkObjectClass *object_class;
|
||||
|
||||
object_class = (GtkObjectClass*) class;
|
||||
object_class = (GtkObjectClass*) klass;
|
||||
|
||||
parent_class = gtk_type_class (gtk_option_menu_get_type ());
|
||||
|
||||
|
@ -87,7 +87,7 @@ gimp_unit_menu_class_init (GimpUnitMenuClass *class)
|
|||
gtk_object_class_add_signals (object_class, gimp_unit_menu_signals,
|
||||
LAST_SIGNAL);
|
||||
|
||||
class->unit_changed = NULL;
|
||||
klass->unit_changed = NULL;
|
||||
|
||||
object_class->destroy = gimp_unit_menu_destroy;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ app/color_balance.c
|
|||
app/color_notebook.c
|
||||
app/color_picker.c
|
||||
app/color_select.c
|
||||
app/colormap_dialog.i.c
|
||||
app/colormap_dialog.c
|
||||
app/commands.c
|
||||
app/convert.c
|
||||
app/convolve.c
|
||||
|
|
|
@ -29,10 +29,4 @@ INCLUDES = \
|
|||
$(GTK_CFLAGS) \
|
||||
-I$(includedir)
|
||||
|
||||
#if WITH_GCG
|
||||
#D_gcg=gcg
|
||||
#else
|
||||
#D_gcg=
|
||||
#endif
|
||||
|
||||
SUBDIRS = $(D_pdbgen) $(D_authorgen) #$(D_gcg)
|
||||
SUBDIRS = $(D_pdbgen) $(D_authorgen)
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
Makefile
|
||||
Makefile.in
|
||||
.deps
|
||||
lexer.c
|
||||
parser.c
|
||||
parser.h
|
||||
y.output
|
||||
gcg
|
||||
aclocal.m4
|
||||
configure
|
||||
config.log
|
||||
config.status
|
||||
config.cache
|
|
@ -1 +0,0 @@
|
|||
Lauri Alanko <la@iki.fi>
|
|
@ -1,113 +0,0 @@
|
|||
1999-07-03 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gcg.c: When built on Win32 with gcc, don't use popen,
|
||||
as it doesn't seem to work when gcc is itself running under
|
||||
cygwin, but gcg is not.
|
||||
|
||||
* makefile.cygwin: New file.
|
||||
|
||||
* Makefile.am: Distribute it.
|
||||
|
||||
Sun Jun 6 11:16:56 PDT 1999 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* Makefile.am
|
||||
* configure.in: various dist fixes
|
||||
|
||||
1999-05-19 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* Makefile.am: Distribute getopt.c and makefile.msc.
|
||||
|
||||
* getopt.c makefile.msc: New files.
|
||||
|
||||
* gcg.c lexer.l: Portability improvements for Win32.
|
||||
|
||||
Wed Jan 20 20:46:39 PST 1999 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* AUTHORS
|
||||
* NEWS: satisfy automake
|
||||
|
||||
* gcg.c: braces around ambiguous if
|
||||
|
||||
Wed Jan 13 16:03:47 PST 1999 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* Makefile.am: grr, some cc's barf if the search dir doesn't
|
||||
exist, leave $(datadir)/gcg out for now
|
||||
|
||||
Sat Jan 9 22:44:03 PST 1999 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* autogen.sh: call configure again
|
||||
|
||||
* gcg.c
|
||||
* Makefile.am: use CPP_SEARCH for finding stuff
|
||||
|
||||
Sat Jan 9 16:00:22 PST 1999 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* configure.in: pass -x c to gcc so it doesn't try to
|
||||
pass the .gc files as linker input
|
||||
|
||||
* Makefile.am: use builtin automake rules for yacc/lex
|
||||
|
||||
Thu Jan 7 15:50:21 PST 1999 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* configure.in
|
||||
* gcg.c: use CPP_PROGRAM instead of hardcoding "cpp"
|
||||
|
||||
1999-01-07 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Took out configure from autogen.sh
|
||||
|
||||
1999-01-05 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Fixed the parser and lexer a bit, changed naming conventions
|
||||
here and there.
|
||||
|
||||
Mon Dec 21 21:56:58 PST 1998 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* fixed up ex for latest glib/gtk+
|
||||
|
||||
1998-11-21 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Added signal demarshallers. Currently they are generated for
|
||||
each module (= compilation unit) separately, which is bound to
|
||||
cause some code duplication..
|
||||
|
||||
* Added import headers and some more example stuff.
|
||||
|
||||
* It actually runs now, with a zillion caveats, but anyway..
|
||||
Still have to do lotsa things for serious use..
|
||||
|
||||
1998-11-20 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Again modified the formatting stuff. Some preliminary header
|
||||
stuff. Soon moving to use cpp..
|
||||
|
||||
1998-11-18 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Signal marshalling should be pretty complete now. Demarshalling
|
||||
isn't quite yet, though..
|
||||
|
||||
1998-11-17 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Misc enhancements.
|
||||
|
||||
1998-11-14 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Changed lotsa internal stuff. Started work on signal wrappers
|
||||
and marshallers.
|
||||
|
||||
1998-10-24 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Redid the backend. It takes more time and memory now, but should
|
||||
be a bit more flexible, and type safe.
|
||||
|
||||
1998-10-22 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* A bit more method generation
|
||||
|
||||
1998-10-21 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Added vfunc wrappers and accessors
|
||||
|
||||
1998-10-21 Lauri Alanko <la@iki.fi>
|
||||
|
||||
* Initially committed to CVS
|
|
@ -1,37 +0,0 @@
|
|||
noinst_PROGRAMS = gcg
|
||||
|
||||
# CPP=cpp -nostdinc -I /usr/share/gcg -I /usr/local/share/gcg -I .
|
||||
|
||||
EXTRA_DIST = \
|
||||
getopt.c \
|
||||
makefile.msc \
|
||||
makefile.cygwin \
|
||||
gh/gcg.gh \
|
||||
gh/glib.gh \
|
||||
gh/gtk.gh
|
||||
|
||||
#AM_CPPFLAGS = -DCPP_SEARCH=\"" -I $(datadir)/gcg -I ."\"
|
||||
AM_CPPFLAGS = -DCPP_SEARCH=\"" -I ."\"
|
||||
INCLUDES = @GLIB_CFLAGS@
|
||||
YFLAGS = -d -v
|
||||
LFLAGS = -d
|
||||
LIBS = @GLIB_LIBS@
|
||||
|
||||
gcg_SOURCES = \
|
||||
gcg.c \
|
||||
parser.y \
|
||||
lexer.l \
|
||||
output.c \
|
||||
pnode.c \
|
||||
db.c \
|
||||
output_enum.c \
|
||||
output_flags.c \
|
||||
output_object.c \
|
||||
fp.c \
|
||||
marshall.c
|
||||
|
||||
if FALSE
|
||||
ex = ex
|
||||
endif
|
||||
|
||||
SUBDIRS = $(ex)
|
|
@ -1,13 +0,0 @@
|
|||
Apparently, you invoke gcg as follows:
|
||||
|
||||
gcg -I<include-path> -o colormap_dialog.c colormap_dialog.gc
|
||||
|
||||
The README I found follows, but seems to be out of date:
|
||||
|
||||
|
||||
GCG - docs forthcoming (hopefully)
|
||||
|
||||
GCG is under development, it doesn't do much of anything sensible yet. What
|
||||
little it does, you can test with:
|
||||
|
||||
gcg -t gimpimageT.h -f gimpimage.h -p gimpimageP.h -s gimpimage.c gimpimage.def
|
|
@ -1,7 +0,0 @@
|
|||
Not in any order:
|
||||
|
||||
- fix memory leaks (no significance in practice, but...)
|
||||
- gtkarg wrappers for data members, with a more generic "attribute" concept
|
||||
- Pretty formatted comments from doc strings
|
||||
- HTML doc output
|
||||
- IDL output
|
|
@ -1,19 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
if test -z "$*"; then
|
||||
echo "I am going to run ./configure with no arguments - if you wish "
|
||||
echo "to pass any to it, please specify them on the $0 command line."
|
||||
fi
|
||||
|
||||
echo processing...
|
||||
|
||||
aclocal $ACLOCAL_FLAGS &&
|
||||
automake -a --foreign &&
|
||||
autoconf &&
|
||||
./configure "$@"
|
||||
|
||||
if [ $? -eq 0 ];then
|
||||
echo "Now run './configure', then 'make' to compile GCG."
|
||||
else
|
||||
echo "Configuration error!"
|
||||
fi
|
|
@ -1,26 +0,0 @@
|
|||
AC_INIT(gcg.c)
|
||||
AM_INIT_AUTOMAKE(gcg, 0.1, no-define)
|
||||
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_STDC
|
||||
AC_PROG_CPP
|
||||
AC_PROG_RANLIB
|
||||
AC_PROG_YACC
|
||||
AM_PROG_LEX
|
||||
|
||||
dnl Utility conditional
|
||||
AM_CONDITIONAL(FALSE, test x = y)
|
||||
|
||||
AM_PATH_GLIB(1.0.0,,AC_ERROR(need at least Glib version 1.0))
|
||||
|
||||
CPP_PROGRAM="$CPP"
|
||||
if test "x$GCC" = "xyes"; then
|
||||
CPP_PROGRAM="$CPP_PROGRAM -x c"
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED(CPP_PROGRAM, "$CPP_PROGRAM")
|
||||
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
ex/Makefile])
|
|
@ -1,55 +0,0 @@
|
|||
#include "gcg.h"
|
||||
|
||||
|
||||
static GHashTable* package_hash = NULL;
|
||||
static GSList* def_list = NULL;
|
||||
|
||||
|
||||
void init_db(void){
|
||||
package_hash = g_hash_table_new(NULL, NULL);
|
||||
}
|
||||
|
||||
PrimType* get_type(Package* pkg, Id name){
|
||||
if(pkg)
|
||||
return g_hash_table_lookup(pkg->type_hash, name);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void put_type(PrimType* t){
|
||||
if(t->module && t->module->package)
|
||||
g_hash_table_insert(t->module->package->type_hash,
|
||||
(gpointer)t->name, t);
|
||||
}
|
||||
|
||||
void put_def(Def* d){
|
||||
def_list = g_slist_append (def_list, d);
|
||||
}
|
||||
|
||||
Package* get_pkg(Id pkgname){
|
||||
return g_hash_table_lookup(package_hash, pkgname);
|
||||
}
|
||||
|
||||
void put_pkg(Package* pkg){
|
||||
g_hash_table_insert(package_hash, (gpointer)pkg->name, pkg);
|
||||
}
|
||||
|
||||
Module* get_mod(Package* pkg, Id modname){
|
||||
if(pkg)
|
||||
return g_hash_table_lookup(pkg->mod_hash, modname);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void put_mod(Module* m){
|
||||
if(m->package && m->name)
|
||||
g_hash_table_insert(m->package->mod_hash, (gpointer)m->name, m);
|
||||
}
|
||||
|
||||
void foreach_def(DefFunc f, gpointer user_data){
|
||||
GSList* l = def_list;
|
||||
while(l){
|
||||
f(l->data, user_data);
|
||||
l = l->next;
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
Makefile
|
||||
Makefile.in
|
||||
.deps
|
||||
ostream.c
|
||||
ostream.t.h
|
||||
ostream.h
|
||||
ostream.p.h
|
||||
ostream.i.h
|
||||
file_ostream.c
|
||||
file_ostream.t.h
|
||||
file_ostream.h
|
||||
file_ostream.p.h
|
||||
file_ostream.i.h
|
||||
foo
|
||||
strtest
|
|
@ -1,54 +0,0 @@
|
|||
GEN_CODE = ostream.c file_ostream.c
|
||||
|
||||
# actual automake variables
|
||||
|
||||
noinst_LIBRARIES = libgcgexample.a
|
||||
noinst_PROGRAMS = strtest
|
||||
|
||||
CFLAGS = -g -Wall -W -I.. @GLIB_CFLAGS@
|
||||
|
||||
SUFFIXES = .gc .gh
|
||||
|
||||
libgcgexample_a_SOURCES = $(GEN_CODE)
|
||||
|
||||
strtest_SOURCES = strtest.c
|
||||
strtest_LDADD = libgcgexample.a -lgtk -lgdk -lgmodule -lglib
|
||||
|
||||
|
||||
# tools
|
||||
|
||||
GCG = ../gcg
|
||||
SED = sed
|
||||
MAKEDEPEND = ../gcgmakedepend
|
||||
|
||||
|
||||
# dependencies and other rules for the def files
|
||||
|
||||
GCG_DEFS = $(subst .c,.gc,$(GEN_CODE))
|
||||
|
||||
# automake uses .P for .c files, we use .d for .gc files, should
|
||||
# be no conflict..
|
||||
DEF_DEPS = $(patsubst %.gc,.deps/%.d,$(GCG_DEFS))
|
||||
|
||||
GEN_HEADER =$(subst .gc,.t.h,$(GCG_DEFS)) \
|
||||
$(subst .gc,.p.h,$(GCG_DEFS)) \
|
||||
$(subst .gc,.i.h,$(GCG_DEFS)) \
|
||||
$(subst .gc,.h,$(GCG_DEFS))
|
||||
|
||||
# gcg include path
|
||||
|
||||
DEF_INC = -I ../gh
|
||||
|
||||
$(GEN_CODE): %.c: %.gc
|
||||
$(GCG) -o $@ $(DEF_INC) $<
|
||||
|
||||
$(DEF_DEPS): .deps/%.d: %.gc
|
||||
$(MAKEDEPEND) $(DEF_INC) $< >$@
|
||||
|
||||
# the real dependency magic
|
||||
|
||||
-include $(DEF_DEPS)
|
||||
|
||||
# stuff to clean properly
|
||||
|
||||
BUILT_SOURCES = $(GEN_CODE) $(GEN_HEADER)
|
|
@ -1 +0,0 @@
|
|||
This is just a bunch of miscellaneous test/example classes.
|
|
@ -1,15 +0,0 @@
|
|||
#include "stream.gh"
|
||||
|
||||
package{
|
||||
module <stdio.h> {
|
||||
foreign FILE;
|
||||
}
|
||||
}
|
||||
|
||||
module Ex.FileOstream;
|
||||
|
||||
|
||||
class FileOstream : Ostream{
|
||||
.FILE* file;
|
||||
public static FileOstream* open(g.char* filename);
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define FILE_OSTREAM_INIT fo_init
|
||||
|
||||
static void fo_init(ExFileOstream* str){
|
||||
str->file = NULL;
|
||||
}
|
||||
|
||||
static void fo_putchar(ExOstream* s, gchar c){
|
||||
ExFileOstream* str = EX_FILE_OSTREAM(s);
|
||||
fputc(c, str->file);
|
||||
}
|
||||
|
||||
static void fo_close(ExOstream* s){
|
||||
ExFileOstream* str = EX_FILE_OSTREAM(s);
|
||||
fclose(str->file);
|
||||
str->file = NULL;
|
||||
}
|
||||
|
||||
#define FILE_OSTREAM_CLASS_INIT fo_cinit
|
||||
|
||||
static void fo_cinit(ExFileOstreamClass* klass){
|
||||
((ExOstreamClass*)klass)->putchar = fo_putchar;
|
||||
((ExOstreamClass*)klass)->close = fo_close;
|
||||
}
|
||||
|
||||
|
||||
#define FILE_OSTREAM_OPEN fo_open
|
||||
|
||||
static ExFileOstream* fo_open(gchar* filename){
|
||||
ExFileOstream* str;
|
||||
FILE* f = fopen(filename, "w+");
|
||||
if(!f)
|
||||
return NULL;
|
||||
str = gtk_type_new(EX_TYPE_FILE_OSTREAM);
|
||||
str->file = f;
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#include <stream.gh>
|
||||
|
||||
module Ex.Ostream;
|
||||
import g;
|
||||
|
||||
|
||||
class Ostream {
|
||||
public virtual void putchar (char c);
|
||||
public pre-emit void putstring (char* str);
|
||||
public pre-emit void flush ();
|
||||
public pre-emit void close ();
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
/* Aye, _mondo_ slow default method.. */
|
||||
|
||||
static void putstring(ExOstream* str, gchar* string){
|
||||
gint i;
|
||||
for(i = 0; string[i]; i++)
|
||||
ex_ostream_putchar(str, string[i]);
|
||||
}
|
||||
|
||||
#define OSTREAM_CLASS_INIT ostream_class_init
|
||||
static void ostream_class_init(ExOstreamClass* klass){
|
||||
klass->putstring = putstring;
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#include <gcg.gh>
|
||||
|
||||
package Ex {
|
||||
module Ostream{
|
||||
class Ostream;
|
||||
}
|
||||
module FileOstream{
|
||||
class FileOstream;
|
||||
}
|
||||
module StringOstream{
|
||||
class StringOstream;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#include <ex/file_ostream.i.h>
|
||||
|
||||
void putstring_handler(Ostream* o, gchar* msg, gpointer data){
|
||||
gchar* s = data;
|
||||
g_print("Putstring: %s (%p), \"%s\"..\n", s, o, msg);
|
||||
}
|
||||
|
||||
void close_handler(Ostream* o, gpointer data){
|
||||
gchar* s = data;
|
||||
g_print("Closed: %s (%p)!\n", s, o);
|
||||
}
|
||||
|
||||
int main(void){
|
||||
Ostream* x;
|
||||
gtk_type_init();
|
||||
x = OSTREAM(file_ostream_open("foo"));
|
||||
ostream_connect_putstring(putstring_handler, "foo", x);
|
||||
ostream_connect_close(close_handler, "foo", x);
|
||||
ostream_putstring(x, "Whammo!\n");
|
||||
ostream_close(x);
|
||||
return 0;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#include "output.h"
|
||||
|
||||
|
||||
FunParams* fparams(const gchar* fmt, ...){
|
||||
FunParams* first;
|
||||
FunParams** last=&first;
|
||||
gint i;
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
for(i=0;fmt[i];i++) switch(fmt[i]){
|
||||
FunParams* f;
|
||||
GSList* l;
|
||||
case 'p':
|
||||
l=va_arg(args, GSList*);
|
||||
while(l){
|
||||
Param* p=l->data;
|
||||
f=g_new(FunParams, 1);
|
||||
f->type=p->type;
|
||||
f->name=p_c_ident(p->name);
|
||||
f->doc=p_nil;
|
||||
*last=f;
|
||||
last=&f->next;
|
||||
l=l->next;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
f=g_new(FunParams, 1);
|
||||
f->type=*va_arg(args, Type*);
|
||||
f->name=va_arg(args, PNode*);
|
||||
p_ref(f->name);
|
||||
f->doc=va_arg(args, PNode*);
|
||||
p_ref(f->doc);
|
||||
*last=f;
|
||||
last=&f->next;
|
||||
break;
|
||||
case 's':
|
||||
f=g_new(FunParams, 1);
|
||||
f->type.prim=va_arg(args, PrimType*);
|
||||
f->type.indirection=va_arg(args, gint);
|
||||
f->type.notnull=va_arg(args, gboolean);
|
||||
f->name=va_arg(args, PNode*);
|
||||
p_ref(f->name);
|
||||
f->doc=va_arg(args, PNode*);
|
||||
p_ref(f->doc);
|
||||
*last=f;
|
||||
last=&f->next;
|
||||
break;
|
||||
}
|
||||
*last=NULL;
|
||||
return first;
|
||||
}
|
||||
|
||||
void fparams_free(FunParams* f){
|
||||
while(f){
|
||||
FunParams* n=f->next;
|
||||
p_unref(f->name);
|
||||
p_unref(f->doc);
|
||||
g_free(f);
|
||||
f=n;
|
||||
}
|
||||
}
|
||||
|
205
tools/gcg/gcg.c
205
tools/gcg/gcg.c
|
@ -1,205 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "gcg.h"
|
||||
#include "parse.h"
|
||||
#ifndef G_OS_WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "output.h"
|
||||
#include "marshall.h"
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
extern int opterr, optind, optopt;
|
||||
extern char *optarg;
|
||||
extern int getopt(int nargc, char** nargv, char* ostr);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define DONT_USE_POPEN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef CPP_PROGRAM
|
||||
#define CPP_PROGRAM "cpp"
|
||||
#endif
|
||||
|
||||
#ifndef CPP_SEARCH
|
||||
#define CPP_SEARCH
|
||||
#endif
|
||||
|
||||
#ifdef DONT_USE_POPEN
|
||||
#define GCGTMP "__gcg.tmp"
|
||||
#endif
|
||||
|
||||
Id header_root = NULL;
|
||||
Id source_name = NULL;
|
||||
|
||||
gboolean collect_marshall = FALSE;
|
||||
|
||||
GString* cpp_cmd;
|
||||
|
||||
void get_options(int argc, char* argv[]){
|
||||
gint x=0;
|
||||
yydebug = yy_flex_debug = FALSE;
|
||||
do{
|
||||
x=getopt(argc, argv, "D:i:dI:o:m");
|
||||
switch(x){
|
||||
case 'D':
|
||||
header_root=optarg;
|
||||
break;
|
||||
case 'I':
|
||||
g_string_append(cpp_cmd, " -I ");
|
||||
g_string_append(cpp_cmd, optarg);
|
||||
break;
|
||||
case 'd':
|
||||
if(!yydebug)
|
||||
yydebug = TRUE;
|
||||
else
|
||||
yy_flex_debug = TRUE;
|
||||
break;
|
||||
case 'o':
|
||||
source_name = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
collect_marshall = TRUE;
|
||||
case '?':
|
||||
case ':':
|
||||
g_error("Bad option %c!\n", x);
|
||||
}
|
||||
}while(x!=EOF);
|
||||
}
|
||||
|
||||
void output_cb(Def* def, gpointer out){
|
||||
output_def(out, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void open_out(PNode*(*func)(Module*),
|
||||
Id suffix, PNode* n, PRoot* out){
|
||||
GString* s = g_string_new(header_root);
|
||||
gchar* str;
|
||||
PNode* guard;
|
||||
FILE* f;
|
||||
g_string_append(s, G_DIR_SEPARATOR_S);
|
||||
str = p_to_str(func(current_module), NULL);
|
||||
g_string_append(s, str);
|
||||
g_free(str);
|
||||
f = fopen(s->str, "w+");
|
||||
if(!f)
|
||||
g_error("Unable to open file %s: %s",
|
||||
s->str,
|
||||
strerror(errno));
|
||||
g_string_free(s, TRUE);
|
||||
guard=p_fmt("_g_~_~_~",
|
||||
p_c_ident(current_module->package->name),
|
||||
p_c_ident(current_module->name),
|
||||
p_str(suffix));
|
||||
p_write(p_fmt("#ifndef ~\n"
|
||||
"#define ~\n"
|
||||
"~"
|
||||
"#endif /* ~ */\n",
|
||||
guard,
|
||||
guard,
|
||||
n,
|
||||
guard),
|
||||
f, out);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
/* target=stdout;*/
|
||||
PRoot* out=pr_new();
|
||||
FILE* f;
|
||||
|
||||
init_db();
|
||||
cpp_cmd = g_string_new(CPP_PROGRAM CPP_SEARCH);
|
||||
yydebug=0;
|
||||
get_options(argc, argv);
|
||||
g_string_append(cpp_cmd, " ");
|
||||
g_string_append(cpp_cmd, argv[optind]);
|
||||
|
||||
#ifdef DONT_USE_POPEN
|
||||
g_string_append(cpp_cmd, " -o " GCGTMP);
|
||||
system(cpp_cmd->str);
|
||||
yyin=fopen(GCGTMP, "r");
|
||||
#else
|
||||
yyin=popen(cpp_cmd->str, "r");
|
||||
#endif
|
||||
/*yyin=fopen(argv[optind], "r");*/
|
||||
g_assert(yyin);
|
||||
yyparse();
|
||||
#ifdef DONT_USE_POPEN
|
||||
fclose(yyin);
|
||||
#else
|
||||
pclose(yyin);
|
||||
#endif
|
||||
|
||||
if(!source_name)
|
||||
source_name = p_to_str(p_fmt("~.c",
|
||||
p_c_ident(current_module->name)),
|
||||
NULL);
|
||||
if(!header_root) {
|
||||
if(!current_module->package->headerbase
|
||||
|| current_module->package->headerbase[0])
|
||||
header_root = "..";
|
||||
else
|
||||
header_root = ".";
|
||||
}
|
||||
foreach_def(output_cb, out);
|
||||
|
||||
f=fopen(source_name, "w+");
|
||||
if(!f)
|
||||
g_error("Unable to open file %s: %s",
|
||||
source_name, strerror(errno));
|
||||
p_write(p_fmt("~~~~"
|
||||
"#ifdef GCG_IMPL\n"
|
||||
"#\tinclude GCG_IMPL\n"
|
||||
"#else\n"
|
||||
"#\tinclude \"~\"\n"
|
||||
"#endif\n"
|
||||
"~",
|
||||
p_col("source_prot_depends", p_prot_include),
|
||||
p_col("source_head", NULL),
|
||||
p_col("source_sigtypes", p_sigdemarsh_decl),
|
||||
p_col("source_sigtypes", p_demarshaller),
|
||||
p_fmt("~.i.c",
|
||||
p_c_ident(current_module->name)),
|
||||
p_col("source", NULL)),
|
||||
f, out);
|
||||
fclose(f);
|
||||
|
||||
|
||||
open_out(p_type_header, "type",
|
||||
p_fmt("#include <gtk/gtktypeutils.h>\n"
|
||||
"~",
|
||||
p_col("type", NULL)),
|
||||
out);
|
||||
|
||||
open_out(p_func_header, "funcs",
|
||||
p_fmt("~~~",
|
||||
p_col("func_parent_depends", p_func_include),
|
||||
p_col("func_depends", p_type_include),
|
||||
p_col("functions", NULL)),
|
||||
out);
|
||||
|
||||
open_out(p_prot_header, "prot",
|
||||
p_fmt("~~~~",
|
||||
p_func_include(current_module),
|
||||
p_col("prot_parent_depends", p_prot_include),
|
||||
p_col("prot_depends", p_type_include),
|
||||
p_col("protected", NULL)),
|
||||
out);
|
||||
|
||||
open_out(p_import_header, "import",
|
||||
p_fmt("~~~",
|
||||
p_func_include(current_module),
|
||||
p_col("import_depends", p_import_include),
|
||||
p_col("import_alias", NULL)),
|
||||
out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
189
tools/gcg/gcg.h
189
tools/gcg/gcg.h
|
@ -1,189 +0,0 @@
|
|||
#ifndef __GCG_H__
|
||||
#define __GCG_H__
|
||||
#include <glib.h>
|
||||
|
||||
extern gboolean in_ident;
|
||||
|
||||
typedef const gchar* Id;
|
||||
|
||||
#define GET_ID(x) (g_quark_to_string(g_quark_from_string(x)))
|
||||
|
||||
typedef const gchar* Header;
|
||||
|
||||
typedef struct _Member Member;
|
||||
typedef struct _PrimType PrimType;
|
||||
typedef struct _Type Type;
|
||||
typedef struct _ObjectDef ObjectDef;
|
||||
typedef struct _Def Def;
|
||||
typedef struct _EnumDef EnumDef;
|
||||
typedef struct _FlagsDef FlagsDef;
|
||||
typedef struct _DataMember DataMember;
|
||||
typedef struct _Method Method;
|
||||
typedef struct _MemberClass MemberClass;
|
||||
typedef struct _DefClass DefClass;
|
||||
typedef struct _Param Param;
|
||||
typedef struct _Module Module;
|
||||
typedef struct _Package Package;
|
||||
|
||||
typedef enum{
|
||||
TYPE_INVALID,
|
||||
TYPE_NONE,
|
||||
TYPE_INT,
|
||||
TYPE_LONG,
|
||||
TYPE_DOUBLE,
|
||||
TYPE_ENUM,
|
||||
TYPE_FLAGS,
|
||||
TYPE_FOREIGN,
|
||||
TYPE_OBJECT,
|
||||
TYPE_BOXED,
|
||||
TYPE_CHAR
|
||||
} TypeKind;
|
||||
|
||||
struct _Package {
|
||||
Id name;
|
||||
Id headerbase;
|
||||
GHashTable* type_hash;
|
||||
GHashTable* mod_hash;
|
||||
};
|
||||
|
||||
struct _Module {
|
||||
Package* package;
|
||||
Id name;
|
||||
Id header;
|
||||
};
|
||||
|
||||
|
||||
struct _PrimType {
|
||||
Module* module;
|
||||
Id name;
|
||||
TypeKind kind;
|
||||
};
|
||||
|
||||
struct _Type {
|
||||
gboolean is_const; /* concerning the _ultimate dereferenced_ object */
|
||||
gint indirection; /* num of pointers to type */
|
||||
gboolean notnull; /* concerning the _immediate pointer_ */
|
||||
PrimType* prim;
|
||||
};
|
||||
|
||||
struct _DefClass {
|
||||
void (*output)(Def*);
|
||||
};
|
||||
|
||||
struct _Def {
|
||||
PrimType *type;
|
||||
GString* doc;
|
||||
};
|
||||
|
||||
#define DEF(x) ((Def*)(x))
|
||||
|
||||
extern DefClass enum_class;
|
||||
|
||||
struct _EnumDef {
|
||||
Def def;
|
||||
PrimType* parent;
|
||||
GSList* alternatives; /* list of Id */
|
||||
};
|
||||
|
||||
extern DefClass flags_class;
|
||||
|
||||
struct _FlagsDef {
|
||||
Def def;
|
||||
PrimType* parent; /* flags to extend */
|
||||
GSList* flags; /* list of Id */
|
||||
};
|
||||
|
||||
extern DefClass object_class;
|
||||
|
||||
struct _ObjectDef {
|
||||
Def def;
|
||||
PrimType* parent;
|
||||
Type self_type[2]; /* both non-const and const */
|
||||
GSList* members;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
METH_PUBLIC,
|
||||
METH_PROTECTED,
|
||||
VIS_PRIVATE
|
||||
} MethProtection;
|
||||
|
||||
typedef enum {
|
||||
DATA_READWRITE,
|
||||
DATA_READONLY,
|
||||
DATA_PROTECTED
|
||||
} DataProtection;
|
||||
|
||||
typedef enum _EmitDef{
|
||||
EMIT_NONE,
|
||||
EMIT_PRE,
|
||||
EMIT_POST
|
||||
} EmitDef;
|
||||
|
||||
typedef enum _MemberType{
|
||||
MEMBER_DATA,
|
||||
MEMBER_METHOD
|
||||
} MemberType;
|
||||
|
||||
typedef enum _DataMemberKind{
|
||||
DATA_STATIC,
|
||||
DATA_DIRECT,
|
||||
DATA_STATIC_VIRTUAL
|
||||
} DataMemberKind;
|
||||
|
||||
typedef enum _MethodKind{
|
||||
METH_STATIC,
|
||||
METH_DIRECT,
|
||||
METH_VIRTUAL,
|
||||
METH_EMIT_PRE,
|
||||
METH_EMIT_POST,
|
||||
METH_EMIT_BOTH
|
||||
} MethodKind;
|
||||
|
||||
struct _Member{
|
||||
MemberType membertype;
|
||||
ObjectDef* my_class;
|
||||
Id name;
|
||||
GString* doc;
|
||||
};
|
||||
|
||||
#define MEMBER(x) ((Member*)(x))
|
||||
|
||||
struct _DataMember {
|
||||
Member member;
|
||||
DataMemberKind kind;
|
||||
DataProtection prot;
|
||||
Type type;
|
||||
};
|
||||
|
||||
struct _Method {
|
||||
Member member;
|
||||
MethodKind kind;
|
||||
MethProtection prot;
|
||||
GSList* params; /* list of Param* */
|
||||
gboolean self_const;
|
||||
Type ret_type;
|
||||
};
|
||||
|
||||
struct _Param {
|
||||
Id name;
|
||||
Method* method;
|
||||
GString* doc;
|
||||
Type type;
|
||||
};
|
||||
|
||||
typedef void (*DefFunc)(Def* def, gpointer user_data);
|
||||
|
||||
|
||||
void init_db(void);
|
||||
|
||||
PrimType* get_type(Package* pkg, Id type);
|
||||
void put_type(PrimType* t);
|
||||
Package* get_pkg(Id pkgname);
|
||||
void put_pkg(Package* pkg);
|
||||
Module* get_mod(Package* pkg, Id module);
|
||||
void put_mod(Module* m);
|
||||
void put_def(Def* d);
|
||||
void foreach_def(DefFunc f, gpointer user_data);
|
||||
|
||||
#endif
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/sh
|
||||
gcc -M -I . -x c $* | sed -e "s/.gc.o/.c/g"
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1987 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)getopt.c 4.13 (Berkeley) 2/23/91";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* get option letter from argument vector
|
||||
*/
|
||||
int opterr = 1, /* if error message should be printed */
|
||||
optind = 1, /* index into parent argv vector */
|
||||
optopt; /* character checked for validity */
|
||||
char *optarg; /* argument associated with option */
|
||||
|
||||
#define BADCH (int)'?'
|
||||
#define EMSG ""
|
||||
|
||||
int
|
||||
getopt(int nargc, char** nargv, char* ostr)
|
||||
{
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
register char *oli; /* option letter list index */
|
||||
char *p;
|
||||
|
||||
if (!*place) { /* update scanning pointer */
|
||||
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||
place = EMSG;
|
||||
return(EOF);
|
||||
}
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
++optind;
|
||||
place = EMSG;
|
||||
return(EOF);
|
||||
}
|
||||
} /* option letter okay? */
|
||||
if ((optopt = (int)*place++) == (int)':' ||
|
||||
!(oli = strchr(ostr, optopt))) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means EOF.
|
||||
*/
|
||||
if (optopt == (int)'-')
|
||||
return(EOF);
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (opterr) {
|
||||
if (!(p = strrchr(*nargv, '/')))
|
||||
p = *nargv;
|
||||
else
|
||||
++p;
|
||||
(void)fprintf(stderr, "%s: illegal option -- %c\n",
|
||||
p, optopt);
|
||||
}
|
||||
return(BADCH);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
optarg = NULL;
|
||||
if (!*place)
|
||||
++optind;
|
||||
}
|
||||
else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
optarg = place;
|
||||
else if (nargc <= ++optind) { /* no arg */
|
||||
place = EMSG;
|
||||
if (!(p = strrchr(*nargv, '/')))
|
||||
p = *nargv;
|
||||
else
|
||||
++p;
|
||||
if (opterr)
|
||||
(void)fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
p, optopt);
|
||||
return(BADCH);
|
||||
}
|
||||
else /* white space */
|
||||
optarg = nargv[optind];
|
||||
place = EMSG;
|
||||
++optind;
|
||||
}
|
||||
return(optopt); /* dump back option letter */
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
|
||||
package Gtk{
|
||||
module <gtksignal.h>{
|
||||
class Object;
|
||||
}
|
||||
}
|
||||
|
||||
#include <glib.gh>
|
||||
|
||||
root Gtk.Object;
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
package g <> {
|
||||
module <glib.h> {
|
||||
integer int;
|
||||
integer uint;
|
||||
integer boolean;
|
||||
character char;
|
||||
character uchar;
|
||||
}
|
||||
}
|
||||
|
||||
package G <> {
|
||||
module <glib.h> {
|
||||
boxed List;
|
||||
boxed SList;
|
||||
boxed HashTable;
|
||||
boxed String;
|
||||
boxed Array;
|
||||
boxed Cache;
|
||||
boxed Data;
|
||||
boxed Node;
|
||||
boxed Scanner;
|
||||
boxed ScannerConfig;
|
||||
boxed Relation;
|
||||
boxed MemChunk;
|
||||
boxed Hook;
|
||||
foreign Func;
|
||||
foreign HashFunc;
|
||||
foreign HFunc;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package Gtk {
|
||||
module <gtkwidget.h> {
|
||||
class Widget;
|
||||
}
|
||||
module <gtkdialog.h> {
|
||||
class Dialog;
|
||||
}
|
||||
module <gtkoptionmenu.h>{
|
||||
class OptionMenu;
|
||||
}
|
||||
module <gtkpreview.h>{
|
||||
class Preview;
|
||||
}
|
||||
module <gtkentry.h>{
|
||||
class Entry;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
%option noyywrap
|
||||
%option yylineno
|
||||
|
||||
%{
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "gcg.h"
|
||||
#include "parser.h"
|
||||
#include "parse.h"
|
||||
%}
|
||||
|
||||
|
||||
ident [A-Za-z][A-Za-z0-9-]*
|
||||
header <[[:alnum:]_/.]*>
|
||||
ws [ \n\t\r]
|
||||
comment \/\/[^\n]*\n
|
||||
string \"(([^\"]*)|\\\"|\\\\)*\"
|
||||
preproc ^#.*\n
|
||||
|
||||
|
||||
|
||||
%%
|
||||
|
||||
public return T_PUBLIC;
|
||||
static return T_STATIC;
|
||||
protected return T_PROTECTED;
|
||||
pre-emit return T_PRE_EMIT;
|
||||
post-emit return T_POST_EMIT;
|
||||
mid-emit return T_DUAL_EMIT;
|
||||
read-only return T_READ_ONLY;
|
||||
read-write return T_READ_WRITE;
|
||||
private return T_PRIVATE;
|
||||
const return T_CONST;
|
||||
virtual return T_ABSTRACT;
|
||||
direct return T_DIRECT;
|
||||
type return T_TYPE;
|
||||
attribute return T_ATTRIBUTE;
|
||||
module return T_MODULE;
|
||||
import return T_IMPORT;
|
||||
header return T_HEADER;
|
||||
opaque return T_OPAQUE;
|
||||
package return T_PACKAGE;
|
||||
void return T_VOID;
|
||||
root return T_ROOT;
|
||||
|
||||
class return T_CLASS;
|
||||
enum return T_ENUM;
|
||||
flags return T_FLAGS;
|
||||
integer return T_INT;
|
||||
double return T_DOUBLE;
|
||||
boxed return T_BOXED;
|
||||
foreign return T_FOREIGN;
|
||||
character return T_CHAR;
|
||||
|
||||
{ident} {
|
||||
yylval.id=g_quark_to_string(g_quark_from_string(yytext));
|
||||
return T_IDENT;
|
||||
}
|
||||
|
||||
{comment} {
|
||||
}
|
||||
|
||||
{ws} {
|
||||
}
|
||||
|
||||
{preproc} {
|
||||
}
|
||||
|
||||
{header} {
|
||||
gchar* tmp = g_strndup(&yytext[1], yyleng-2);
|
||||
yylval.id=g_quark_to_string(g_quark_from_string(tmp));
|
||||
g_free (tmp);
|
||||
return T_HEADERNAME;
|
||||
}
|
||||
|
||||
{string} {
|
||||
yylval.str=g_string_new(yytext);
|
||||
return T_STRING;
|
||||
}
|
||||
|
||||
\. return T_SCOPE;
|
||||
\* return T_POINTER;
|
||||
\& return T_NOTNULLPTR;
|
||||
\; return T_END;
|
||||
\{ return T_OPEN_B;
|
||||
\} return T_CLOSE_B;
|
||||
\( return T_OPEN_P;
|
||||
\) return T_CLOSE_P;
|
||||
\, return T_COMMA;
|
||||
\: return T_INHERITANCE;
|
||||
. return yytext[0];
|
||||
|
||||
%%
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
#include "classc.h"
|
||||
#include "parser.h"
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include <unistd.h>
|
||||
#include "output.h"
|
||||
|
||||
GHashTable* decl_hash;
|
||||
GHashTable* def_hash;
|
||||
Id current_module;
|
||||
Method* current_method;
|
||||
ObjectDef* current_class;
|
||||
Id current_header;
|
||||
GSList* imports;
|
||||
|
||||
|
||||
guint type_name_hash(gconstpointer c){
|
||||
const TypeName* t=c;
|
||||
return g_str_hash(t->module) ^ g_str_hash(t->type);
|
||||
}
|
||||
|
||||
gboolean type_name_cmp(gconstpointer a, gconstpointer b){
|
||||
const TypeName *t1=a, *t2=b;
|
||||
return (t1->type == t2->type) && (t1->module == t2->module);
|
||||
}
|
||||
|
||||
void output_type(TypeName* t, Def* def, gpointer foo){
|
||||
def->klass->output(def);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
extern int yydebug;
|
||||
extern FILE* yyin;
|
||||
/* target=stdout;*/
|
||||
|
||||
decl_hash=g_hash_table_new(type_name_hash, type_name_cmp);
|
||||
def_hash=g_hash_table_new(type_name_hash, type_name_cmp);
|
||||
yydebug=0;
|
||||
yyin=fopen(argv[1], "r");
|
||||
yyparse();
|
||||
type_gtk_type=g_new(Type, 1);
|
||||
type_gtk_type->is_const=FALSE;
|
||||
type_gtk_type->indirection=0;
|
||||
type_gtk_type->notnull=FALSE;
|
||||
type_gtk_type->prim=get_decl(GET_ID("Gtk"), GET_ID("Type"));
|
||||
g_assert(type_gtk_type->prim);
|
||||
func_hdr=file_new("gen_funcs.h");
|
||||
type_hdr=file_new("gen_types.h");
|
||||
prot_hdr=file_new("gen_prots.h");
|
||||
source=file_new("gen_source.c");
|
||||
source_head=file_sub(source);
|
||||
g_hash_table_foreach(def_hash, output_type, NULL);
|
||||
file_flush(func_hdr);
|
||||
file_flush(type_hdr);
|
||||
file_flush(source_head);
|
||||
/* file_flush(source);*/
|
||||
file_flush(prot_hdr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
## Makefile for building gcg with gcc -mno-cygwin
|
||||
## Use: make -f makefile.cygwin
|
||||
|
||||
################################################################
|
||||
|
||||
CC = gcc -mno-cygwin -mpentium -fnative-struct
|
||||
|
||||
LEX = flex
|
||||
YACC = bison -y
|
||||
|
||||
INSTALL = install
|
||||
|
||||
GLIB_VER = 1.3
|
||||
|
||||
GLIB = ../../../glib
|
||||
|
||||
CFLAGS = -g -I$(GLIB) -DCPP_PROGRAM="\"$(CC) -E -x c\"" -DYY_NEVER_INTERACTIVE
|
||||
|
||||
all: gcg.exe
|
||||
|
||||
YFLAGS = -d -v
|
||||
LFLAGS = -d
|
||||
|
||||
lexer.c : lexer.l
|
||||
$(LEX) $(LFLAGS) -t lexer.l >lexer.c
|
||||
|
||||
parser.c parser.h: parser.y
|
||||
$(YACC) $(YFLAGS) parser.y
|
||||
cp y.tab.c parser.c
|
||||
cp y.tab.h parser.h
|
||||
|
||||
gcg_OBJECTS = \
|
||||
gcg.o \
|
||||
getopt.o \
|
||||
parser.o \
|
||||
lexer.o \
|
||||
output.o \
|
||||
pnode.o \
|
||||
db.o \
|
||||
output_enum.o \
|
||||
output_flags.o\
|
||||
output_object.o\
|
||||
fp.o \
|
||||
marshall.o \
|
||||
|
||||
gcg.exe : $(gcg_OBJECTS)
|
||||
$(CC) $(CFLAGS) -o gcg.exe $(gcg_OBJECTS) -L $(GLIB) -lglib-$(GLIB_VER) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
-rm parser.[ch] lexer.c *.exe *.o
|
|
@ -1,68 +0,0 @@
|
|||
## Makefile for building gcg with Microsoft C
|
||||
## Use: nmake -f makefile.msc
|
||||
|
||||
################################################################
|
||||
|
||||
# Nothing much configurable below
|
||||
|
||||
# cl -? describes the options
|
||||
CC = cl -GA -G5 -GF -Ox -W3 -MD -nologo
|
||||
|
||||
# flex is from cygwin, for instance
|
||||
LEX = flex
|
||||
# yacc is bison, also from cygwin
|
||||
YACC = bison -y
|
||||
|
||||
LDFLAGS = /link /subsystem:console /machine:ix86
|
||||
INSTALL = copy
|
||||
|
||||
GLIB_VER = 1.3
|
||||
|
||||
GLIB = ..\..\..\glib
|
||||
|
||||
CFLAGS = -I$(GLIB) -DCPP_PROGRAM="\"cl -E\""
|
||||
CPP = cl -E -I.
|
||||
|
||||
all: gcg.exe
|
||||
|
||||
YFLAGS = -d -v
|
||||
LFLAGS = -d
|
||||
|
||||
lexer.c : lexer.l
|
||||
$(LEX) $(LFLAGS) -t lexer.l >lexer.c
|
||||
|
||||
parser.c parser.h: parser.y
|
||||
$(YACC) $(YFLAGS) parser.y
|
||||
copy y.tab.c parser.c
|
||||
copy y.tab.h parser.h
|
||||
|
||||
gcg_OBJECTS = \
|
||||
gcg.obj \
|
||||
getopt.obj \
|
||||
parser.obj \
|
||||
lexer.obj \
|
||||
output.obj \
|
||||
pnode.obj \
|
||||
db.obj \
|
||||
output_enum.obj \
|
||||
output_flags.obj\
|
||||
output_object.obj\
|
||||
fp.obj \
|
||||
marshall.obj \
|
||||
|
||||
gcg.exe : $(gcg_OBJECTS)
|
||||
$(CC) $(CFLAGS) -Fegcg.exe $(gcg_OBJECTS) $(GLIB)\glib-$(GLIB_VER).lib $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
del parser.c
|
||||
del parser.h
|
||||
del lexer.c
|
||||
del *.exe
|
||||
del *.lib
|
||||
del *.obj
|
||||
del *.exp
|
||||
del *.err
|
||||
del *.map
|
||||
del *.sym
|
||||
del *.pdb
|
||||
del *.ilk
|
|
@ -1,332 +0,0 @@
|
|||
#include "gcg.h"
|
||||
#include "output.h"
|
||||
#include "marshall.h"
|
||||
|
||||
|
||||
static GHashTable* sigtype_hash;
|
||||
|
||||
typedef enum {
|
||||
MARSHALL_INT,
|
||||
MARSHALL_DOUBLE,
|
||||
MARSHALL_POINTER,
|
||||
MARSHALL_VOID,
|
||||
MARSHALL_LONG
|
||||
} MarshallType;
|
||||
|
||||
|
||||
struct _SignalType {
|
||||
Id package;
|
||||
Id module;
|
||||
MarshallType rettype;
|
||||
GSList* argtypes;
|
||||
};
|
||||
|
||||
MarshallType marshalling_type(Type* t){
|
||||
if(!t)
|
||||
return MARSHALL_VOID;
|
||||
if(t->indirection)
|
||||
return MARSHALL_POINTER;
|
||||
if(!t->prim)
|
||||
return MARSHALL_VOID;
|
||||
switch(t->prim->kind){
|
||||
case TYPE_INT:
|
||||
case TYPE_FLAGS:
|
||||
case TYPE_ENUM:
|
||||
return MARSHALL_INT;
|
||||
case TYPE_LONG:
|
||||
return MARSHALL_LONG;
|
||||
case TYPE_DOUBLE:
|
||||
return MARSHALL_DOUBLE;
|
||||
case TYPE_NONE:
|
||||
return MARSHALL_VOID;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
return MARSHALL_VOID;
|
||||
}
|
||||
}
|
||||
|
||||
/* Yes, this is hyperbly kludgetical */
|
||||
|
||||
SignalType* sig_type(Method* m){
|
||||
SignalType *t=g_new(SignalType, 1), *s;
|
||||
GSList* p=m->params, *a=NULL;
|
||||
PNode* g;
|
||||
gchar* f;
|
||||
t->package = DEF(MEMBER(m)->my_class)->type->module->package->name;
|
||||
t->module = DEF(MEMBER(m)->my_class)->type->module->name;
|
||||
t->rettype = marshalling_type(&m->ret_type);
|
||||
if(!sigtype_hash)
|
||||
sigtype_hash = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
while(p){
|
||||
Param* param=p->data;
|
||||
MarshallType* t=g_new(MarshallType, 1);
|
||||
*t=marshalling_type(¶m->type);
|
||||
a=g_slist_prepend(a, t);
|
||||
p=p->next;
|
||||
}
|
||||
a=g_slist_reverse(a);
|
||||
t->argtypes=a;
|
||||
g = p_signal_demarshaller_name(t);
|
||||
f = p_to_str(g, NULL);
|
||||
p_unref(g);
|
||||
s = g_hash_table_lookup(sigtype_hash, f);
|
||||
if(!s){
|
||||
g_hash_table_insert(sigtype_hash, f, t);
|
||||
return t;
|
||||
}
|
||||
else{
|
||||
sig_type_free(t);
|
||||
g_free(f);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
void sig_type_free(SignalType* t){
|
||||
GSList* l=t->argtypes;
|
||||
while(l){
|
||||
g_free(l->data);
|
||||
l=l->next;
|
||||
}
|
||||
g_slist_free(t->argtypes);
|
||||
g_free(t);
|
||||
}
|
||||
|
||||
typedef enum{
|
||||
GTKNAME,
|
||||
ENCODING,
|
||||
CTYPE
|
||||
} MMap;
|
||||
|
||||
|
||||
PNode* p_gtype_name(MarshallType t, MMap map){
|
||||
static const struct GTypeName{
|
||||
MarshallType type;
|
||||
Id gtkname;
|
||||
Id encoding;
|
||||
Id ctype;
|
||||
}names[]={
|
||||
{MARSHALL_POINTER, "POINTER", "P", "gpointer"},
|
||||
{MARSHALL_INT, "INT", "I", "gint"},
|
||||
{MARSHALL_DOUBLE, "DOUBLE", "D", "gdouble"},
|
||||
{MARSHALL_LONG, "LONG", "L", "glong"},
|
||||
{MARSHALL_VOID, "NONE", "0", "void"},
|
||||
};
|
||||
gint i;
|
||||
|
||||
for(i=0;i<(gint)(sizeof(names)/sizeof(names[0]));i++)
|
||||
if(names[i].type==t){
|
||||
Id id;
|
||||
switch(map){
|
||||
case GTKNAME:
|
||||
id = names[i].gtkname;
|
||||
break;
|
||||
case ENCODING:
|
||||
id = names[i].encoding;
|
||||
break;
|
||||
case CTYPE:
|
||||
id = names[i].ctype;
|
||||
break;
|
||||
}
|
||||
return p_str(id);
|
||||
}
|
||||
|
||||
g_assert_not_reached();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PNode* p_gtabbr(gpointer p){
|
||||
MarshallType* t=p;
|
||||
return p_gtype_name(*t, ENCODING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PNode* p_gtktype(Type* t){
|
||||
if(t->indirection==0){
|
||||
if(!t->prim)
|
||||
return p_str("GTK_TYPE_NONE");
|
||||
switch(t->prim->kind){
|
||||
case TYPE_INT:
|
||||
return p_str("GTK_TYPE_INT");
|
||||
case TYPE_DOUBLE:
|
||||
return p_str("GTK_TYPE_DOUBLE");
|
||||
case TYPE_ENUM:
|
||||
case TYPE_FLAGS:
|
||||
return p_macro_name(t->prim, "TYPE", NULL);
|
||||
case TYPE_CHAR:
|
||||
return p_str("GTK_TYPE_CHAR");
|
||||
case TYPE_FOREIGN:
|
||||
g_error("Cannot marshall foreign type %s.%s!",
|
||||
t->prim->module->package->name,
|
||||
t->prim->name);
|
||||
return NULL;
|
||||
default:
|
||||
g_error("Cannot marshall type by value: %s.%s",
|
||||
t->prim->module->package->name,
|
||||
t->prim->name);
|
||||
return NULL;
|
||||
}
|
||||
}else if(t->indirection==1
|
||||
&& t->prim
|
||||
&& (t->prim->kind==TYPE_BOXED
|
||||
|| t->prim->kind==TYPE_OBJECT))
|
||||
return p_macro_name(t->prim, "TYPE", NULL);
|
||||
else
|
||||
return p_str("GTK_TYPE_POINTER");
|
||||
}
|
||||
|
||||
|
||||
PNode* p_signal_func_name(SignalType* t, PNode* basename){
|
||||
#if 1
|
||||
return p_fmt("_~_~_~_~~",
|
||||
p_c_ident(t->package),
|
||||
p_c_ident(t->module),
|
||||
basename,
|
||||
p_gtype_name(t->rettype, ENCODING),
|
||||
p_for(t->argtypes, p_gtabbr, p_nil));
|
||||
#else
|
||||
return p_fmt("_~_~_~~",
|
||||
p_c_ident(t->package),
|
||||
basename,
|
||||
p_gtype_name(t->rettype, ENCODING),
|
||||
p_for(t->argtypes, p_gtabbr, p_nil));
|
||||
#endif
|
||||
}
|
||||
|
||||
PNode* p_signal_marshaller_name(SignalType* t){
|
||||
return p_signal_func_name(t, p_str("marshall"));
|
||||
}
|
||||
|
||||
PNode* p_signal_demarshaller_name(SignalType* t){
|
||||
return p_signal_func_name(t, p_str("demarshall"));
|
||||
}
|
||||
|
||||
PNode* p_handler_type(SignalType* t){
|
||||
#if 1
|
||||
return p_fmt("_~~Handler_~~",
|
||||
p_str(t->package),
|
||||
p_str(t->module),
|
||||
p_gtype_name(t->rettype, ENCODING),
|
||||
p_for(t->argtypes, p_gtabbr, p_nil));
|
||||
#else
|
||||
return p_fmt("_~Handler_~~",
|
||||
p_str(t->package),
|
||||
p_gtype_name(t->rettype, ENCODING),
|
||||
p_for(t->argtypes, p_gtabbr, p_nil));
|
||||
#endif
|
||||
}
|
||||
|
||||
PNode* p_signal_id(Method* s){
|
||||
PrimType* t=DEF(MEMBER(s)->my_class)->type;
|
||||
return p_fmt("_~_~_signal_~",
|
||||
p_c_ident(t->module->package->name),
|
||||
p_c_ident(t->name),
|
||||
p_c_ident(MEMBER(s)->name));
|
||||
}
|
||||
|
||||
typedef struct{
|
||||
PNode* args;
|
||||
gint idx;
|
||||
}ArgMarshData;
|
||||
|
||||
PNode* p_arg_marsh(gpointer p, gpointer d){
|
||||
Param* par=p;
|
||||
gint* idx=d;
|
||||
(*idx)++;
|
||||
return p_fmt(/* "\targs[~].type=~;\n" unnecessary... */
|
||||
"\tGTK_VALUE_~(args[~]) = ~;\n",
|
||||
/* p_prf("%d", *idx),
|
||||
p_gtktype(&par->type), */
|
||||
p_gtype_name(marshalling_type(&par->type), GTKNAME),
|
||||
p_prf("%d", *idx),
|
||||
p_c_ident(par->name));
|
||||
}
|
||||
|
||||
PNode* p_sig_marshalling(Method* m){
|
||||
gint idx=-1;
|
||||
gint nargs = g_slist_length(m->params);
|
||||
gboolean ret = marshalling_type(&m->ret_type)!=MARSHALL_VOID;
|
||||
return p_fmt("\t{\n"
|
||||
"~"
|
||||
"~"
|
||||
"~"
|
||||
"~"
|
||||
"\tgtk_signal_emitv((GtkObject*)~, ~, ~);\n"
|
||||
"~"
|
||||
"\t}\n",
|
||||
nargs > 0
|
||||
? p_fmt("\tGtkArg args[~];\n",
|
||||
p_prf("%d", nargs+ret))
|
||||
: p_nil,
|
||||
ret
|
||||
?p_fmt("\t~ retval;\n",
|
||||
p_type(&m->ret_type))
|
||||
:p_nil,
|
||||
p_for(m->params, p_arg_marsh, &idx),
|
||||
ret
|
||||
/* cannot use retloc here, ansi forbids casted lvalues */
|
||||
?p_fmt("\tGTK_VALUE_POINTER(args[~]) = &retval;\n",
|
||||
p_prf("%d", nargs))
|
||||
:p_nil,
|
||||
p_c_ident(DEF(MEMBER(m)->my_class)->type->name),
|
||||
p_signal_id(m),
|
||||
nargs > 0
|
||||
? p_str("args")
|
||||
: p_str("NULL"),
|
||||
ret
|
||||
?p_str("\treturn retval;\n")
|
||||
:p_nil);
|
||||
}
|
||||
|
||||
|
||||
PNode* p_arg_demarsh(gpointer p, gpointer d){
|
||||
MarshallType* t=p;
|
||||
gint* data=d;
|
||||
(*data)++;
|
||||
return p_fmt("\t\tGTK_VALUE_~(args[~]),\n",
|
||||
p_gtype_name(*t, FALSE),
|
||||
p_prf("%d", *data));
|
||||
}
|
||||
|
||||
PNode* p_sig_arg_ctype(MarshallType* t){
|
||||
return p_fmt(", ~", p_gtype_name(*t, CTYPE));
|
||||
}
|
||||
|
||||
PNode* p_sigdemarsh_decl(SignalType* t){
|
||||
#if 1
|
||||
return p_fmt("static void ~ (GtkObject*, GtkSignalFunc, "
|
||||
"gpointer, GtkArg*);\n"
|
||||
"typedef ~ (*~)(GtkObject*~, gpointer);\n",
|
||||
p_signal_demarshaller_name(t),
|
||||
p_gtype_name(t->rettype, CTYPE),
|
||||
p_handler_type(t),
|
||||
p_for(t->argtypes, p_sig_arg_ctype, p_nil));
|
||||
#else
|
||||
return p_fmt("extern void ~ (GtkObject*, GtkSignalFunc, "
|
||||
"gpointer, GtkArg*);\n",
|
||||
p_signal_demarshaller_name(t));
|
||||
#endif
|
||||
}
|
||||
|
||||
PNode* p_demarshaller(SignalType* t){
|
||||
gint idx=-1;
|
||||
return p_fmt("static void ~ (\n"
|
||||
"\tGtkObject* object,\n"
|
||||
"\tGtkSignalFunc func,\n"
|
||||
"\tgpointer user_data,\n"
|
||||
"\tGtkArg* args){\n"
|
||||
"\t(void)args;\n"
|
||||
"~~"
|
||||
"}\n",
|
||||
p_signal_demarshaller_name(t),
|
||||
(t->rettype==TYPE_NONE)
|
||||
? p_fmt("\t*(GTK_RETLOC_~(args[~])) =\n",
|
||||
p_gtype_name(t->rettype, FALSE),
|
||||
p_prf("%d", g_slist_length(t->argtypes)))
|
||||
: p_nil,
|
||||
p_fmt("\t~(object,\n"
|
||||
"~"
|
||||
"\tuser_data);\n",
|
||||
p_cast(p_handler_type(t), p_str("func")),
|
||||
p_for(t->argtypes, p_arg_demarsh, &idx)));
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef __MARSHALL_H__
|
||||
#define __MARSHALL_H__
|
||||
|
||||
#include "gcg.h"
|
||||
#include "pnode.h"
|
||||
|
||||
typedef struct _SignalType SignalType;
|
||||
SignalType* sig_type(Method* m);
|
||||
void sig_type_free(SignalType* t);
|
||||
PNode* p_gtabbr(gpointer p);
|
||||
PNode* p_signal_marshaller_name(SignalType* s);
|
||||
PNode* p_signal_demarshaller_name(SignalType* s);
|
||||
PNode* p_arg_marsh(gpointer p, gpointer d);
|
||||
PNode* p_gtktype(Type* t);
|
||||
PNode* p_signal_id(Method* s);
|
||||
PNode* p_sig_marshalling(Method* m);
|
||||
PNode* p_sigdemarsh_decl(SignalType* t);
|
||||
PNode* p_demarshaller(SignalType* t);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,384 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "output.h"
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
PNode* p_c_ident(Id id){
|
||||
PNode* n;
|
||||
gint i = 0;
|
||||
GString* s = g_string_new(NULL);
|
||||
|
||||
for(i = 0; id[i]; i++){
|
||||
if(!isalnum(id[i]) || (i && isupper(id[i])))
|
||||
g_string_append_c(s, '_');
|
||||
if(isalnum(id[i]))
|
||||
g_string_append_c(s, tolower(id[i]));
|
||||
}
|
||||
n = p_str(s->str);
|
||||
g_string_free(s, TRUE);
|
||||
return n;
|
||||
}
|
||||
|
||||
PNode* p_c_macro(Id id){
|
||||
PNode* n;
|
||||
gint i = 0;
|
||||
GString* s = g_string_new(NULL);
|
||||
|
||||
for(i = 0; id[i]; i++){
|
||||
if(!isalnum(id[i]) || (i && isupper(id[i])))
|
||||
g_string_append_c(s, '_');
|
||||
if(isalnum(id[i]))
|
||||
g_string_append_c(s, toupper(id[i]));
|
||||
}
|
||||
n = p_str(s->str);
|
||||
g_string_free(s, TRUE);
|
||||
return n;
|
||||
}
|
||||
|
||||
PNode* p_param(FunParams* p, ParamOptions* o){
|
||||
return p_fmt("~~~~~~",
|
||||
o->first ? p_nil : p_str(","),
|
||||
!o->first && !(o->types && o->names) ? p_str(" ") : p_nil,
|
||||
(o->types && o->names) ? p_str("\n\t") : p_nil,
|
||||
o->types ? p_type(&p->type) : p_nil,
|
||||
o->types && o->names ? p_str(" ") : p_nil,
|
||||
o->names ? p->name : p_nil);
|
||||
}
|
||||
|
||||
PNode* p_header(Module* m, Id suffix){
|
||||
Id base = m->package->headerbase;
|
||||
Id hdr = m->header;
|
||||
Id name = m->package->name;
|
||||
|
||||
return p_fmt("~~",
|
||||
base
|
||||
? (base[0]
|
||||
? p_fmt("~/", p_str(base))
|
||||
: p_nil)
|
||||
: ((name && name[0])
|
||||
? p_fmt("~/", p_c_ident(name))
|
||||
: p_nil),
|
||||
hdr
|
||||
? p_str(hdr)
|
||||
: p_fmt("~~",
|
||||
p_c_ident(m->name),
|
||||
p_str(suffix)));
|
||||
}
|
||||
|
||||
PNode* p_prot_header(Module* m){
|
||||
return p_header(m, ".p.h");
|
||||
}
|
||||
|
||||
PNode* p_type_header(Module* m){
|
||||
return p_header(m, ".t.h");
|
||||
}
|
||||
|
||||
PNode* p_func_header(Module* m){
|
||||
return p_header(m, ".h");
|
||||
}
|
||||
|
||||
PNode* p_import_header(Module* m){
|
||||
if(m->header)
|
||||
return p_nil;
|
||||
else
|
||||
return p_header(m, ".i.h");
|
||||
}
|
||||
|
||||
PNode* p_type_include(Module* m){
|
||||
return p_fmt("#include <~>\n",
|
||||
p_type_header(m));
|
||||
}
|
||||
|
||||
PNode* p_prot_include(Module* m){
|
||||
return p_fmt("#include <~>\n",
|
||||
p_prot_header(m));
|
||||
}
|
||||
|
||||
PNode* p_func_include(Module* m){
|
||||
return p_fmt("#include <~>\n",
|
||||
p_func_header(m));
|
||||
}
|
||||
|
||||
PNode* p_import_include(Module* m){
|
||||
PNode* hdr = p_import_header(m);
|
||||
if(hdr == p_nil)
|
||||
return p_nil;
|
||||
else
|
||||
return p_fmt("#include <~>\n", hdr);
|
||||
}
|
||||
|
||||
|
||||
PNode* p_params(FunParams* args, ParamOptions* opt){
|
||||
ParamOptions o=*opt;
|
||||
PNode* n=p_nil;
|
||||
while(args){
|
||||
n=p_fmt("~~", n, p_param(args, &o));
|
||||
args=args->next;
|
||||
o.first=FALSE;
|
||||
}
|
||||
if(n==p_nil)
|
||||
if(opt->first)
|
||||
return p_str("void");
|
||||
else
|
||||
return p_nil;
|
||||
else
|
||||
return n;
|
||||
}
|
||||
|
||||
PNode* p_prim_varname(PrimType* t){
|
||||
return p_c_ident(t->name);
|
||||
}
|
||||
|
||||
PNode* p_primtype(PrimType* t){
|
||||
return p_fmt("~~",
|
||||
p_str(t->module->package->name),
|
||||
p_str(t->name));
|
||||
}
|
||||
|
||||
PNode* p_cast(PNode* force_type, PNode* expression){
|
||||
return p_fmt("((~)~)",
|
||||
force_type,
|
||||
expression);
|
||||
}
|
||||
|
||||
PNode* p_type(Type* t){
|
||||
if(t && t->prim){
|
||||
PNode* node;
|
||||
gint i=t->indirection;
|
||||
node=p_fmt("~~",
|
||||
t->is_const ? p_str("const ") : p_nil,
|
||||
p_primtype(t->prim));
|
||||
while(i--)
|
||||
node=p_fmt("~~", node, p_str("*"));
|
||||
/* file_add_dep(s, t->prim->decl_header);*/
|
||||
return node;
|
||||
}else
|
||||
return p_str("void");
|
||||
}
|
||||
|
||||
PNode* p_self_type(ObjectDef* o, PBool const_self){
|
||||
return p_fmt("~~*",
|
||||
(const_self ? p_str("const ") : p_nil),
|
||||
p_primtype(DEF(o)->type));
|
||||
}
|
||||
|
||||
PNode* p_varname(PrimType* t, PNode* name){
|
||||
return p_fmt("~_~_~",
|
||||
p_c_ident(t->module->package->name),
|
||||
p_c_ident(t->name),
|
||||
name);
|
||||
}
|
||||
|
||||
PNode* p_internal_varname(PrimType* t, PNode* name){
|
||||
return p_fmt("_~",
|
||||
p_varname(t, name));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PNode* p_type_guard(Type* t, PNode* var){
|
||||
PrimType* p=t->prim;
|
||||
/*
|
||||
if(t->notnull && (p->indirection>1 || p->kind!=GTK_TYPE_OBJECT))
|
||||
return p_fmt("\tg_assert (~);\n", var);
|
||||
else if(p->kind==GTK_TYPE_OBJECT)
|
||||
return p_fmt("\tg_assert (~
|
||||
|
||||
kind !=
|
||||
*/
|
||||
return p_fmt("~~",
|
||||
(t->indirection && t->notnull
|
||||
? p_fmt("\tg_assert (~);\n", var)
|
||||
: p_nil),
|
||||
((t->indirection==1 && p->kind == TYPE_OBJECT)
|
||||
? (t->notnull
|
||||
? p_fmt("\tg_assert (~(~));\n",
|
||||
p_macro_name(p, "is", NULL),
|
||||
var)
|
||||
: p_fmt("\tg_assert (!~ || ~(~));\n",
|
||||
var,
|
||||
p_macro_name(p, "is", NULL),
|
||||
var))
|
||||
: (t->indirection==0
|
||||
? ((p->kind == TYPE_ENUM)
|
||||
? p_fmt("\tg_assert (~ <= ~);\n",
|
||||
var,
|
||||
p_macro_name(p, NULL, "last"))
|
||||
: ((p->kind == TYPE_FLAGS)
|
||||
? p_fmt("\tg_assert ((~ << 1) < ~);\n",
|
||||
var,
|
||||
p_macro_name(p, NULL, "last"))
|
||||
: p_nil))
|
||||
: p_nil)));
|
||||
}
|
||||
|
||||
PNode* p_type_guards(FunParams* args){
|
||||
PNode* p=p_nil;
|
||||
while(args){
|
||||
p=p_fmt("~~", p, p_type_guard(&args->type, args->name));
|
||||
args=args->next;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
PNode* p_prototype(Type* rettype, PNode* name,
|
||||
PNode* args1,
|
||||
FunParams* args2){
|
||||
ParamOptions o;
|
||||
o.first = !args1 || args1 == p_nil;
|
||||
o.names = TRUE;
|
||||
o.types = TRUE;
|
||||
|
||||
return p_fmt("~ ~ (~~)",
|
||||
p_type(rettype),
|
||||
name,
|
||||
args1,
|
||||
p_params(args2, &o));
|
||||
}
|
||||
|
||||
void output_var_alias(PRoot* out, PrimType* t, PNode* basename){
|
||||
pr_put(out, "import_alias",
|
||||
p_fmt("#define ~ ~_~\n",
|
||||
basename,
|
||||
p_c_ident(t->module->package->name),
|
||||
basename));
|
||||
}
|
||||
|
||||
void output_type_alias(PRoot* out, PrimType* t, PNode* basename){
|
||||
pr_put(out, "import_alias",
|
||||
p_fmt("typedef ~~ ~;\n",
|
||||
p_str(t->module->package->name),
|
||||
basename,
|
||||
basename));
|
||||
}
|
||||
|
||||
|
||||
void output_func(PRoot* out,
|
||||
Id tag,
|
||||
Type* rettype,
|
||||
PNode* name,
|
||||
PNode* args1,
|
||||
FunParams* args2,
|
||||
PNode* body){
|
||||
pr_put(out, tag ? tag : "source_head",
|
||||
p_fmt("~~;\n",
|
||||
tag
|
||||
? p_nil
|
||||
: p_str("static "),
|
||||
p_prototype(rettype, name, args1, args2)));
|
||||
pr_put(out, "source",
|
||||
p_fmt("~~{\n"
|
||||
"~"
|
||||
"~"
|
||||
"}\n\n",
|
||||
tag
|
||||
? p_nil
|
||||
: p_str("static "),
|
||||
p_prototype(rettype, name, args1, args2),
|
||||
p_type_guards(args2),
|
||||
body));
|
||||
}
|
||||
|
||||
|
||||
PNode* p_macro_name(PrimType* t, Id mid, Id post){
|
||||
return p_fmt("~~_~~",
|
||||
p_c_macro(t->module->package->name),
|
||||
mid ? p_fmt("_~", p_c_macro(mid)) : p_nil,
|
||||
p_c_macro(t->name),
|
||||
post ? p_fmt("_~", p_c_macro(post)) : p_nil);
|
||||
}
|
||||
|
||||
void output_var(PRoot* out, Id tag, PNode* type, PNode* name){
|
||||
if(tag)
|
||||
pr_put(out, tag,
|
||||
p_fmt("extern ~ ~;\n",
|
||||
type,
|
||||
name));
|
||||
pr_put(out, "source_head",
|
||||
p_fmt("~~ ~;\n",
|
||||
tag?p_nil:p_str("static "),
|
||||
type,
|
||||
name));
|
||||
}
|
||||
|
||||
void output_def(PRoot* out, Def* d){
|
||||
PrimType* t=d->type;
|
||||
PNode* type_var=p_internal_varname(t, p_str("type"));
|
||||
|
||||
/* GTK_TYPE_FOO macro */
|
||||
pr_put(out, "type", p_str("\n\n"));
|
||||
pr_put(out, "source", p_str("\n"));
|
||||
pr_put(out, "protected", p_str("\n\n"));
|
||||
pr_put(out, "source_head", p_str("\n"));
|
||||
pr_put(out, "type", p_fmt("#define ~ \\\n"
|
||||
" (~ ? (void)0 : ~ (), ~)\n",
|
||||
p_macro_name(t, "type", NULL),
|
||||
type_var,
|
||||
p_internal_varname(t, p_str("init_type")),
|
||||
type_var));
|
||||
output_macro_import(out, t, "type", NULL);
|
||||
output_type_import(out, t->module->package, p_str(t->name));
|
||||
output_var(out, "type",
|
||||
p_str("GtkType"),
|
||||
type_var);
|
||||
switch(d->type->kind){
|
||||
case TYPE_OBJECT:
|
||||
output_object(out, d);
|
||||
break;
|
||||
case TYPE_ENUM:
|
||||
output_enum(out, d);
|
||||
break;
|
||||
case TYPE_FLAGS:
|
||||
output_flags(out, d);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void output_type_import(PRoot* out, Package* pkg, PNode* body){
|
||||
#if 1
|
||||
pr_put(out, "import_alias",
|
||||
p_fmt("#define ~ ~~\n",
|
||||
body,
|
||||
p_str(pkg->name),
|
||||
body));
|
||||
#else
|
||||
pr_put(out, "import_alias",
|
||||
p_fmt("typedef ~~ ~;\n",
|
||||
p_str(pkg->name),
|
||||
body,
|
||||
body));
|
||||
#endif
|
||||
}
|
||||
|
||||
void output_macro_import(PRoot* out, PrimType* t, Id mid, Id post){
|
||||
pr_put(out, "import_alias",
|
||||
p_fmt("#define ~~~ ~\n",
|
||||
mid ? p_fmt("~_", p_c_macro(mid)) : p_nil,
|
||||
p_c_macro(t->name),
|
||||
post ? p_fmt("_~", p_c_macro(post)) : p_nil,
|
||||
p_macro_name(t, mid, post)));
|
||||
}
|
||||
|
||||
void output_var_import(PRoot* out, PrimType* t, PNode* body){
|
||||
pr_put(out, "import_alias",
|
||||
p_fmt("#define ~_~ ~\n",
|
||||
p_c_ident(t->name),
|
||||
body,
|
||||
p_varname(t, body)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void add_dep(PRoot* out, Id tag, PrimType* type){
|
||||
pr_put(out, tag, type->module);
|
||||
}
|
||||
|
||||
PNode* p_deps(Id tag){
|
||||
return p_col(tag, p_dep, NULL);
|
||||
}
|
||||
*/
|
|
@ -1,93 +0,0 @@
|
|||
#ifndef __OUTPUT_H__
|
||||
#define __OUTPUT_H__
|
||||
|
||||
#include "gcg.h"
|
||||
#include <stdio.h>
|
||||
#include "pnode.h"
|
||||
|
||||
typedef gconstpointer PBool;
|
||||
extern const PBool ptrue;
|
||||
extern const PBool pfalse;
|
||||
|
||||
|
||||
typedef struct _FunParams FunParams;
|
||||
struct _FunParams{
|
||||
FunParams* next;
|
||||
Type type;
|
||||
PNode* name;
|
||||
PNode* doc;
|
||||
};
|
||||
|
||||
FunParams* fparams(const gchar* fmt, ...);
|
||||
void fparams_free(FunParams* f);
|
||||
|
||||
|
||||
typedef struct{
|
||||
gboolean first : 1;
|
||||
gboolean names : 1;
|
||||
gboolean types : 1;
|
||||
/* gboolean docs : 1; */
|
||||
} ParamOptions;
|
||||
|
||||
PNode* p_prim_varname(PrimType* t);
|
||||
PNode* p_cast(PNode* type, PNode* expr);
|
||||
PNode* p_params(FunParams* args, ParamOptions* opt);
|
||||
PNode* p_primtype(PrimType* t);
|
||||
PNode* p_type(Type* t);
|
||||
PNode* p_varname(PrimType* t, PNode* name);
|
||||
PNode* p_internal_varname(PrimType* t, PNode* name);
|
||||
PNode* p_object_member(Member* m);
|
||||
PNode* p_object_body(ObjectDef* c);
|
||||
PNode* p_object_decl(ObjectDef* c);
|
||||
PNode* p_class_member(Member* m);
|
||||
PNode* p_class_body(ObjectDef* c);
|
||||
PNode* p_class_decl(ObjectDef* c);
|
||||
PNode* p_prototype(Type* rettype, PNode* name,
|
||||
PNode* args1,
|
||||
FunParams* args2);
|
||||
|
||||
|
||||
|
||||
PNode* p_macro_name(PrimType* t, Id mid, Id post);
|
||||
PNode* p_class_macros(ObjectDef* c );
|
||||
PNode* p_get_type(ObjectDef* c);
|
||||
PNode* p_gtype(Type* t);
|
||||
PNode* p_guard_name(const gchar* c);
|
||||
PNode* p_guard_start(const gchar *c);
|
||||
PNode* p_guard_end(const gchar *c);
|
||||
|
||||
PNode* p_c_ident(Id id);
|
||||
PNode* p_c_macro(Id id);
|
||||
PNode* p_prot_header(Module* m);
|
||||
PNode* p_type_header(Module* m);
|
||||
PNode* p_func_header(Module* m);
|
||||
PNode* p_import_header(Module* m);
|
||||
|
||||
|
||||
|
||||
void output_func(PRoot* out,
|
||||
Id tag,
|
||||
Type* rettype,
|
||||
PNode* name,
|
||||
PNode* args1,
|
||||
FunParams* args2,
|
||||
PNode* body);
|
||||
|
||||
|
||||
void output_var(PRoot* out, Id tag, PNode* type, PNode* name);
|
||||
void output_def(PRoot* out, Def* d);
|
||||
void output_object(PRoot* out, Def* d);
|
||||
void output_enum(PRoot* out, Def* d);
|
||||
void output_flags(PRoot* out, Def* d);
|
||||
PNode* p_type_include(Module* m);
|
||||
PNode* p_prot_include(Module* m);
|
||||
PNode* p_func_include(Module* m);
|
||||
PNode* p_import_include(Module* m);
|
||||
|
||||
void output_type_import(PRoot* out, Package* pkg, PNode* body);
|
||||
void output_macro_import(PRoot* out, PrimType* t, Id mid, Id post);
|
||||
void output_var_import(PRoot* out, PrimType* t, PNode* body);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,55 +0,0 @@
|
|||
#include "output.h"
|
||||
|
||||
PNode* p_enum_member(Id id, PrimType* t){
|
||||
return p_fmt("\t~,\n",
|
||||
p_macro_name(t, NULL, id));
|
||||
}
|
||||
|
||||
PNode* p_enum_decl(EnumDef* e){
|
||||
PrimType* t=DEF(e)->type;
|
||||
return p_fmt("typedef enum {\n"
|
||||
"~"
|
||||
"\t~ = ~\n"
|
||||
"} ~;\n",
|
||||
p_for(e->alternatives, p_enum_member, t),
|
||||
p_macro_name(t, NULL, "last"),
|
||||
p_macro_name(t, NULL,
|
||||
g_slist_last(e->alternatives)->data),
|
||||
p_primtype(t));
|
||||
}
|
||||
|
||||
PNode* p_enum_value(Id i, PrimType* t){
|
||||
return p_fmt("\t\t{~,\n"
|
||||
"\t\t\"~\",\n"
|
||||
"\t\t\"~\"},\n",
|
||||
p_macro_name(t, NULL, i),
|
||||
p_macro_name(t, NULL, i),
|
||||
p_str(i));
|
||||
}
|
||||
|
||||
void output_enum_type_init(PRoot* out, EnumDef* e){
|
||||
PrimType* t=DEF(e)->type;
|
||||
output_func(out,
|
||||
"type",
|
||||
NULL,
|
||||
p_internal_varname(t, p_str("init_type")),
|
||||
p_nil,
|
||||
NULL,
|
||||
p_fmt("\tstatic GtkEnumValue values[~] = {\n"
|
||||
"~"
|
||||
"\t\t{0, NULL, NULL}\n"
|
||||
"\t};\n"
|
||||
"\t~ = gtk_type_register_enum (\"~\", values);\n",
|
||||
p_prf("%d", g_slist_length(e->alternatives)+1),
|
||||
p_for(e->alternatives, p_enum_value, t),
|
||||
p_internal_varname(t, p_str("type")),
|
||||
p_primtype(t),
|
||||
p_internal_varname(t, p_str("type"))));
|
||||
}
|
||||
|
||||
void output_enum(PRoot* out, Def* d){
|
||||
EnumDef* e = (EnumDef*)d;
|
||||
output_enum_type_init(out, e);
|
||||
pr_put(out, "type", p_enum_decl(e));
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
#include "output.h"
|
||||
|
||||
typedef struct {
|
||||
gint i;
|
||||
PrimType* t;
|
||||
}FlagData;
|
||||
|
||||
PNode* p_flags_member(Id id, FlagData* d){
|
||||
d->i++;
|
||||
return p_fmt("\t~ = 1 << ~,\n",
|
||||
p_macro_name(d->t, NULL, id),
|
||||
p_prf("%d", d->i));
|
||||
}
|
||||
|
||||
PNode* p_flags_decl(FlagsDef* e){
|
||||
FlagData d;
|
||||
d.i = -1;
|
||||
d.t = DEF(e)->type;
|
||||
return p_fmt("typedef enum {\n"
|
||||
"~"
|
||||
"} ~;\n"
|
||||
"const ~ ~ = ~;\n",
|
||||
p_for(e->flags, p_flags_member, &d),
|
||||
p_primtype(d.t),
|
||||
p_primtype(d.t),
|
||||
p_macro_name(d.t, NULL, "last"),
|
||||
p_macro_name(d.t, NULL, g_slist_last(e->flags)->data));
|
||||
}
|
||||
|
||||
PNode* p_flags_value(Id i, PrimType* t){
|
||||
return p_fmt("\t\t{~,\n"
|
||||
"\t\t\"~\",\n"
|
||||
"\t\t\"~\"},\n",
|
||||
p_macro_name(t, NULL, i),
|
||||
p_macro_name(t, NULL, i),
|
||||
p_str(i));
|
||||
}
|
||||
|
||||
void output_flags_type_init(PRoot* out, FlagsDef* e){
|
||||
PrimType* t=DEF(e)->type;
|
||||
output_func(out,
|
||||
"type",
|
||||
NULL,
|
||||
p_internal_varname(t, p_str("init_type")),
|
||||
p_nil,
|
||||
NULL,
|
||||
p_fmt("\tstatic GtkFlagValue values[~] = {\n"
|
||||
"~"
|
||||
"\t\t{0, NULL, NULL}\n"
|
||||
"\t};\n"
|
||||
"\t~ = gtk_type_register_flags (\"~\", values);\n",
|
||||
p_prf("%d", g_slist_length(e->flags)+1),
|
||||
p_for(e->flags, p_flags_value, t),
|
||||
p_internal_varname(t, p_str("type")),
|
||||
p_primtype(t),
|
||||
p_internal_varname(t, p_str("type"))));
|
||||
}
|
||||
|
||||
void output_flags(PRoot* out, Def* d){
|
||||
FlagsDef* f = (FlagsDef*) d;
|
||||
pr_put(out, "type", p_flags_decl(f));
|
||||
output_flags_type_init(out, f);
|
||||
}
|
||||
|
|
@ -1,468 +0,0 @@
|
|||
#include "output.h"
|
||||
#include "marshall.h"
|
||||
|
||||
PNode* p_self_name(Member* o){
|
||||
return p_c_ident(DEF(o->my_class)->type->name);
|
||||
}
|
||||
|
||||
PNode* p_object_member(Member* m){
|
||||
DataMember* d;
|
||||
if(m->membertype != MEMBER_DATA)
|
||||
return p_nil;
|
||||
d=(DataMember*)m;
|
||||
if(d->kind!=DATA_DIRECT)
|
||||
return p_nil;
|
||||
return p_fmt("\t~ ~;\n",
|
||||
p_type(&d->type),
|
||||
p_c_ident(m->name));
|
||||
}
|
||||
|
||||
PNode* p_object_body(ObjectDef* o){
|
||||
return p_fmt("struct _~ {\n"
|
||||
"\t~ parent;\n"
|
||||
"~"
|
||||
"};\n",
|
||||
p_primtype(DEF(o)->type),
|
||||
p_primtype(o->parent),
|
||||
p_for(o->members, p_object_member, p_nil));
|
||||
}
|
||||
|
||||
PNode* p_object_decl(ObjectDef* o){
|
||||
PrimType* n=DEF(o)->type;
|
||||
return p_fmt("typedef struct _~ ~;\n",
|
||||
p_primtype(n),
|
||||
p_primtype(n));
|
||||
}
|
||||
|
||||
PNode* p_class_member(Member* m){
|
||||
ParamOptions o = {TRUE,FALSE,TRUE};
|
||||
if(m->membertype == MEMBER_DATA){
|
||||
DataMember* d=(DataMember*)m;
|
||||
if(d->kind != DATA_STATIC_VIRTUAL)
|
||||
return p_nil;
|
||||
else
|
||||
return p_fmt("\t~ ~;\n",
|
||||
p_type(&d->type),
|
||||
p_c_ident(m->name));
|
||||
}else if (m->membertype == MEMBER_METHOD){
|
||||
Method* d=(Method*)m;
|
||||
FunParams* p;
|
||||
PNode* parnode;
|
||||
|
||||
if(d->kind==METH_STATIC ||
|
||||
d->kind==METH_DIRECT)
|
||||
return p_nil;
|
||||
p=fparams("tp",
|
||||
&m->my_class->self_type[d->self_const],
|
||||
p_nil, p_nil,
|
||||
d->params);
|
||||
parnode=p_params(p, &o);
|
||||
fparams_free(p);
|
||||
return p_fmt("\t~ (*~) (~);\n",
|
||||
p_type(&d->ret_type),
|
||||
p_c_ident(m->name),
|
||||
parnode);
|
||||
}else
|
||||
return p_nil;
|
||||
}
|
||||
|
||||
PNode* p_class_name(PrimType* o){
|
||||
return p_fmt("~Class",
|
||||
p_primtype(o));
|
||||
}
|
||||
|
||||
PNode* p_impl_name(ObjectDef* o){
|
||||
return p_fmt("~Impl",
|
||||
p_primtype(DEF(o)->type));
|
||||
}
|
||||
|
||||
PNode* p_class_body(ObjectDef* o){
|
||||
return p_fmt("struct _~ {\n"
|
||||
"\t~ parent_class;\n"
|
||||
"~"
|
||||
"};\n",
|
||||
p_class_name(DEF(o)->type),
|
||||
p_class_name(o->parent),
|
||||
p_for(o->members, p_class_member, p_nil));
|
||||
}
|
||||
|
||||
PNode* p_class_decl(ObjectDef* o){
|
||||
return p_fmt("typedef struct _~ ~;\n",
|
||||
p_class_name(DEF(o)->type),
|
||||
p_class_name(DEF(o)->type));
|
||||
}
|
||||
|
||||
|
||||
PNode* p_real_varname(PrimType* t, PNode* name){
|
||||
return p_fmt("~_real",
|
||||
p_varname(t, name));
|
||||
}
|
||||
|
||||
|
||||
PNode* p_signal_handler_type(Method* s){
|
||||
Member* m=MEMBER(s);
|
||||
return p_fmt("~Handler_~",
|
||||
p_primtype(DEF(m->my_class)->type),
|
||||
p_c_ident(m->name));
|
||||
}
|
||||
|
||||
|
||||
void output_connector(PRoot* out, Method* m){
|
||||
FunParams* par=fparams("t",
|
||||
&MEMBER(m)->my_class->self_type[m->self_const],
|
||||
p_self_name(MEMBER(m)),
|
||||
p_nil);
|
||||
|
||||
output_func(out, "functions",
|
||||
&m->ret_type,
|
||||
p_varname(DEF(MEMBER(m)->my_class)->type,
|
||||
p_fmt("connect_~",
|
||||
p_c_ident(MEMBER(m)->name))),
|
||||
p_fmt("\n\t~ handler,\n\tgpointer user_data",
|
||||
p_signal_handler_type(m)),
|
||||
par,
|
||||
p_fmt("\t~gtk_signal_connect((GtkObject*)~,\n"
|
||||
"\t\t\"~\",\n"
|
||||
"\t\t(GtkSignalFunc)handler,\n"
|
||||
"\t\tuser_data);\n",
|
||||
m->ret_type.prim?p_str("return "):p_nil,
|
||||
p_self_name(MEMBER(m)),
|
||||
p_str(MEMBER(m)->name)));
|
||||
output_var_import(out, DEF(MEMBER(m)->my_class)->type,
|
||||
p_fmt("connect_~",
|
||||
p_c_ident(MEMBER(m)->name)));
|
||||
}
|
||||
|
||||
PNode* p_param_marshtype(gpointer p){
|
||||
Param* param=p;
|
||||
return p_fmt(",\n\t\t~",
|
||||
p_gtktype(¶m->type));
|
||||
}
|
||||
|
||||
|
||||
void output_method(PRoot* out, Method* m){
|
||||
PrimType* t=DEF(MEMBER(m)->my_class)->type;
|
||||
PNode* name=p_c_ident(MEMBER(m)->name);
|
||||
MethodKind k=m->kind;
|
||||
ParamOptions o={TRUE, TRUE, FALSE};
|
||||
FunParams* par;
|
||||
PNode* dispatch;
|
||||
GSList* params;
|
||||
|
||||
if(k == METH_STATIC)
|
||||
par = fparams("p", m->params);
|
||||
else
|
||||
par = fparams("tp",
|
||||
&MEMBER(m)->my_class->self_type[m->self_const],
|
||||
p_self_name(MEMBER(m)),
|
||||
p_nil,
|
||||
m->params);
|
||||
|
||||
switch(k){
|
||||
SignalType* sig;
|
||||
case METH_EMIT_PRE:
|
||||
case METH_EMIT_POST:
|
||||
case METH_EMIT_BOTH:
|
||||
sig=sig_type(m);
|
||||
output_var(out, NULL,
|
||||
p_str("guint"),
|
||||
p_signal_id(m));
|
||||
o.names=FALSE;
|
||||
o.types=TRUE;
|
||||
pr_put(out, "source_sigtypes", sig);
|
||||
pr_put(out, "member_class_init",
|
||||
p_fmt("\t~ =\n"
|
||||
"\tgtk_signal_new(\"~\",\n"
|
||||
"\t\tGTK_RUN_~,\n"
|
||||
"\t\tobklass->type,\n"
|
||||
"\t\tGTK_SIGNAL_OFFSET (~, ~),\n"
|
||||
"\t\t~,\n"
|
||||
"\t\t~,\n"
|
||||
"\t\t~"
|
||||
"~);\n"
|
||||
"\tgtk_object_class_add_signals(obklass,\n"
|
||||
"\t\t&~,\n"
|
||||
"\t\t1);\n",
|
||||
p_signal_id(m),
|
||||
p_str(MEMBER(m)->name),
|
||||
p_str(m->kind==METH_EMIT_PRE
|
||||
?"FIRST"
|
||||
:m->kind==METH_EMIT_POST
|
||||
?"LAST"
|
||||
:"BOTH"),
|
||||
p_class_name(t),
|
||||
name,
|
||||
p_signal_demarshaller_name(sig),
|
||||
p_gtktype(&m->ret_type),
|
||||
p_prf("%d", g_slist_length(m->params)),
|
||||
p_for(m->params, p_param_marshtype, p_nil),
|
||||
p_signal_id(m)));
|
||||
|
||||
pr_put(out, "functions",
|
||||
p_fmt("typedef ~ (*~)("
|
||||
"~,\n"
|
||||
"\tgpointer);\n",
|
||||
p_type(&m->ret_type),
|
||||
p_signal_handler_type(m),
|
||||
p_params(par, &o)));
|
||||
output_connector(out, m);
|
||||
o.names=TRUE;
|
||||
o.types=FALSE;
|
||||
dispatch=p_sig_marshalling(m);
|
||||
break;
|
||||
case METH_STATIC:
|
||||
case METH_DIRECT:{
|
||||
PNode* impl_name;
|
||||
o.names=TRUE;
|
||||
o.types=FALSE;
|
||||
|
||||
impl_name=p_fmt("~_~",
|
||||
p_c_macro(t->name),
|
||||
p_c_macro(MEMBER(m)->name));
|
||||
|
||||
dispatch=p_fmt("#ifdef ~\n"
|
||||
"\t~~ (~);\n"
|
||||
"#else\n"
|
||||
"\tg_error(\"Not implemented: ~.~.~\");\n"
|
||||
"#endif\n",
|
||||
impl_name,
|
||||
m->ret_type.prim
|
||||
? p_str("return ")
|
||||
: p_nil,
|
||||
impl_name,
|
||||
p_params(par, &o),
|
||||
p_str(t->module->package->name),
|
||||
p_str(t->name),
|
||||
p_str(MEMBER(m)->name));
|
||||
|
||||
break;
|
||||
}
|
||||
case METH_VIRTUAL:
|
||||
dispatch=p_fmt("\t~((~*)((GtkObject*) ~)->klass)->~ (~);\n",
|
||||
m->ret_type.prim?
|
||||
p_str("return "):
|
||||
p_nil,
|
||||
p_class_name(DEF(MEMBER(m)->my_class)->type),
|
||||
p_c_ident(t->name),
|
||||
name,
|
||||
p_params(par, &o));
|
||||
break;
|
||||
}
|
||||
output_func
|
||||
(out,
|
||||
m->prot==METH_PUBLIC?"functions":"protected",
|
||||
&m->ret_type,
|
||||
p_varname(t, name),
|
||||
p_nil,
|
||||
par,
|
||||
dispatch);
|
||||
|
||||
output_var_import(out, t, name);
|
||||
for(params = m->params; params; params = params->next)
|
||||
pr_put(out,
|
||||
m->prot==METH_PUBLIC?"func_depends":"prot_depends",
|
||||
((Param*)(params->data))->type.prim->module);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fparams_free(par);
|
||||
}
|
||||
|
||||
void output_data_member(PRoot* out, DataMember* m){
|
||||
PrimType* t=DEF(MEMBER(m)->my_class)->type;
|
||||
PNode* name = p_c_ident(MEMBER(m)->name);
|
||||
PNode* self = p_self_name(MEMBER(m));
|
||||
|
||||
|
||||
switch(m->prot){
|
||||
FunParams* par;
|
||||
case DATA_READWRITE: {
|
||||
par=fparams("tt", &MEMBER(m)->my_class->self_type[FALSE],
|
||||
self,
|
||||
p_nil,
|
||||
&m->type,
|
||||
name,
|
||||
p_nil);
|
||||
output_var_import(out, t, p_fmt("set_~", name));
|
||||
output_func(out,
|
||||
"functions",
|
||||
NULL,
|
||||
p_varname(t, p_fmt("set_~", name)),
|
||||
p_nil,
|
||||
par,
|
||||
p_fmt("~"
|
||||
"\t~->~ = ~;\n",
|
||||
(m->type.prim->kind==TYPE_OBJECT
|
||||
&& m->type.indirection==1)
|
||||
?m->type.notnull
|
||||
?p_fmt("\tgtk_object_ref "
|
||||
"((GtkObject*) ~);\n"
|
||||
"\tgtk_object_unref "
|
||||
"((GtkObject*) ~->~);\n",
|
||||
name,
|
||||
self,
|
||||
name)
|
||||
:p_fmt("\tif(~)\n"
|
||||
"\t\tgtk_object_ref "
|
||||
"((GtkObject*) ~);\n"
|
||||
"\tif(~->~)\n"
|
||||
"\t\tgtk_object_unref "
|
||||
"((GtkObject*) ~->~);\n",
|
||||
name,
|
||||
name,
|
||||
self,
|
||||
name,
|
||||
self,
|
||||
name)
|
||||
:p_nil,
|
||||
self,
|
||||
name,
|
||||
name));
|
||||
fparams_free(par);
|
||||
}
|
||||
/* fall through */
|
||||
case DATA_READONLY:
|
||||
pr_put(out, "func_depends", m->type.prim->module);
|
||||
par=fparams("t", &MEMBER(m)->my_class->self_type[TRUE],
|
||||
self,
|
||||
p_nil);
|
||||
output_var_import(out, t, name);
|
||||
output_func(out,
|
||||
"functions",
|
||||
&m->type,
|
||||
p_varname(t, name),
|
||||
p_nil,
|
||||
par,
|
||||
p_fmt("\treturn ~->~;\n",
|
||||
self,
|
||||
name));
|
||||
fparams_free(par);
|
||||
/* fall through */
|
||||
case DATA_PROTECTED:
|
||||
pr_put(out, "prot_depends", m->type.prim->module);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void output_member(PRoot* out, Member* m){
|
||||
switch(m->membertype){
|
||||
case MEMBER_METHOD:
|
||||
output_method(out, (Method*)m);
|
||||
break;
|
||||
case MEMBER_DATA:
|
||||
output_data_member(out, (DataMember*)m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void output_member_cb(gpointer a, gpointer b){
|
||||
output_member(b, a);
|
||||
}
|
||||
|
||||
void output_class_macros(PRoot* out, ObjectDef* o){
|
||||
PrimType* t=DEF(o)->type;
|
||||
pr_put(out, "type",
|
||||
p_fmt("#define ~(o) GTK_CHECK_TYPE(o, ~)\n"
|
||||
"#define ~(o) GTK_CHECK_CAST(o, ~, ~)\n",
|
||||
p_macro_name(t, "is", NULL),
|
||||
p_macro_name(t, "type", NULL),
|
||||
p_macro_name(t, NULL, NULL),
|
||||
p_macro_name(t, "type", NULL),
|
||||
p_primtype(t)));
|
||||
output_macro_import(out, t, "is", NULL);
|
||||
output_macro_import(out, t, NULL, NULL);
|
||||
}
|
||||
|
||||
void output_object_type_init(PRoot* out, ObjectDef* o){
|
||||
PrimType* t=DEF(o)->type;
|
||||
PNode* type_var=p_internal_varname(t, p_str("type"));
|
||||
output_func(out,
|
||||
"type",
|
||||
NULL,
|
||||
p_internal_varname(t, p_str("init_type")),
|
||||
p_nil,
|
||||
NULL,
|
||||
p_fmt("\tstatic GtkTypeInfo info = {\n"
|
||||
"\t\t\"~\",\n"
|
||||
"\t\tsizeof (~),\n"
|
||||
"\t\tsizeof (~),\n"
|
||||
"\t\t(GtkClassInitFunc) ~,\n"
|
||||
"\t\t(GtkObjectInitFunc) ~,\n"
|
||||
"\t\tNULL,\n"
|
||||
"\t\tNULL,\n"
|
||||
"\t\tNULL,\n"
|
||||
"\t};\n"
|
||||
"\tif (!~)\n"
|
||||
"\t\t~ = gtk_type_unique (~, &info);\n",
|
||||
p_primtype(t),
|
||||
p_primtype(t),
|
||||
p_class_name(t),
|
||||
p_varname(t, p_str("class_init")),
|
||||
p_varname(t, p_str("init")),
|
||||
type_var,
|
||||
type_var,
|
||||
p_macro_name(o->parent, "type", NULL),
|
||||
type_var));
|
||||
}
|
||||
|
||||
|
||||
void output_object_init(PRoot* out, ObjectDef* o){
|
||||
PrimType* t = DEF(o)->type;
|
||||
output_func(out, NULL,
|
||||
NULL,
|
||||
p_varname(t, p_str("init")),
|
||||
p_fmt("~ ~",
|
||||
p_type(&o->self_type[FALSE]),
|
||||
p_c_ident(t->name)),
|
||||
NULL,
|
||||
p_fmt("\t(void) ~;\n"
|
||||
"#ifdef ~_INIT\n"
|
||||
"\t~_INIT (~);\n"
|
||||
"#endif\n",
|
||||
p_c_ident(t->name),
|
||||
p_c_macro(t->name),
|
||||
p_c_macro(t->name),
|
||||
p_c_ident(t->name)));
|
||||
}
|
||||
|
||||
void output_class_init(PRoot* out, ObjectDef* o){
|
||||
PrimType* t = DEF(o)->type;
|
||||
output_func(out, NULL,
|
||||
NULL,
|
||||
p_varname(t, p_str("class_init")),
|
||||
p_fmt("~* klass",
|
||||
p_class_name(t)),
|
||||
NULL,
|
||||
p_fmt("\tGtkObjectClass* obklass = "
|
||||
"(GtkObjectClass*) klass;\n"
|
||||
"~"
|
||||
"\t(void) obklass;\n"
|
||||
"~"
|
||||
"#ifdef ~_CLASS_INIT\n"
|
||||
"\t~_CLASS_INIT (klass);\n"
|
||||
"#endif\n",
|
||||
p_col("class_init_head", NULL),
|
||||
p_col("member_class_init", NULL),
|
||||
p_c_macro(t->name),
|
||||
p_c_macro(t->name)));
|
||||
}
|
||||
|
||||
void output_object(PRoot* out, Def* d){
|
||||
ObjectDef* o = (ObjectDef*)d;
|
||||
pr_put(out, "func_depends", d->type->module);
|
||||
pr_put(out, "func_parent_depends", o->parent->module);
|
||||
pr_put(out, "prot_parent_depends", o->parent->module);
|
||||
pr_put(out, "source_prot_depends", d->type->module);
|
||||
pr_put(out, "import_depends", o->parent->module);
|
||||
output_object_type_init(out, o);
|
||||
output_class_init(out, o);
|
||||
output_object_init(out, o);
|
||||
pr_put(out, "protected", p_class_decl(o));
|
||||
pr_put(out, "protected", p_class_body(o));
|
||||
pr_put(out, "type", p_object_decl(o));
|
||||
output_class_macros(out, o);
|
||||
pr_put(out, "protected", p_object_body(o));
|
||||
g_slist_foreach(o->members, output_member_cb, out);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef __PARSE_H__
|
||||
#define __PARSE_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include "gcg.h"
|
||||
|
||||
|
||||
gint yylex(void);
|
||||
gint yyerror(gchar* s);
|
||||
gint yyparse(void);
|
||||
extern int yydebug;
|
||||
extern int yy_flex_debug;
|
||||
extern FILE* yyin;
|
||||
|
||||
extern Module* current_module;
|
||||
|
||||
#endif
|
|
@ -1,500 +0,0 @@
|
|||
%{
|
||||
#include "gcg.h"
|
||||
#include "parse.h"
|
||||
|
||||
#define YYDEBUG 1
|
||||
|
||||
static Package* current_package;
|
||||
Module* current_module;
|
||||
static ObjectDef* current_class;
|
||||
static Method* current_method;
|
||||
static PrimType* root_class;
|
||||
static GSList* imports_list;
|
||||
|
||||
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
GSList* list;
|
||||
Id id;
|
||||
GString* str;
|
||||
PrimType* primtype;
|
||||
MethodKind methkind;
|
||||
DataMemberKind datakind;
|
||||
MethProtection methprot;
|
||||
DataProtection dataprot;
|
||||
MethodKind kind;
|
||||
Def* def;
|
||||
ObjectDef* class_def;
|
||||
Member* member;
|
||||
Param* param;
|
||||
EmitDef emit_def;
|
||||
gboolean bool;
|
||||
Type type;
|
||||
TypeKind fund_type;
|
||||
};
|
||||
|
||||
%token T_MODULE
|
||||
%token T_ENUM
|
||||
%token T_FLAGS
|
||||
%token T_READ_WRITE
|
||||
%token T_READ_ONLY
|
||||
%token T_PRIVATE
|
||||
%token T_PROTECTED
|
||||
%token T_PUBLIC
|
||||
%token T_CLASS
|
||||
%token T_PRE_EMIT
|
||||
%token T_POST_EMIT
|
||||
%token T_DUAL_EMIT
|
||||
%token T_SCOPE
|
||||
%token T_ABSTRACT
|
||||
%token T_EMPTY
|
||||
%token T_DIRECT
|
||||
%token T_STATIC
|
||||
%token T_CONST
|
||||
%token T_TYPE
|
||||
%token T_END
|
||||
%token T_OPEN_B
|
||||
%token T_POINTER
|
||||
%token T_NOTNULLPTR
|
||||
%token T_CLOSE_B
|
||||
%token T_INHERITANCE
|
||||
%token T_ATTRIBUTE
|
||||
%token T_HEADER
|
||||
%token T_OPEN_P
|
||||
%token T_HEADER
|
||||
%token T_CLOSE_P
|
||||
%token T_COMMA
|
||||
%token T_IMPORT
|
||||
%token T_OPAQUE
|
||||
%token T_VOID
|
||||
%token T_INT
|
||||
%token T_DOUBLE
|
||||
%token T_BOXED
|
||||
%token T_SIGNAL
|
||||
%token T_FOREIGN
|
||||
%token T_PACKAGE
|
||||
%token T_ROOT
|
||||
%token T_CHAR
|
||||
|
||||
%token<id> T_IDENT
|
||||
%token<id> T_HEADERNAME
|
||||
%token<str> T_STRING
|
||||
|
||||
%type<id> maybeident
|
||||
%type<id> ident
|
||||
%type<id> headerdef
|
||||
%type<fund_type> fundtype
|
||||
%type<type> type
|
||||
%type<type> typeorvoid
|
||||
%type<type> semitype
|
||||
%type<primtype> primtype
|
||||
%type<primtype> parent
|
||||
%type<list> paramlist
|
||||
%type<list> idlist
|
||||
%type<methkind> methkind
|
||||
%type<datakind> datakind
|
||||
%type<methprot> methprot
|
||||
%type<dataprot> dataprot
|
||||
%type<list> classbody
|
||||
%type<def> flagsdef
|
||||
%type<def> enumdef
|
||||
%type<def> classdef
|
||||
%type<def> def
|
||||
%type<list> paramtail
|
||||
%type<param> param
|
||||
%type<str> docstring
|
||||
%type<member> member_def
|
||||
%type<member> data_member_def
|
||||
%type<member> method_def
|
||||
%type<emit_def> emitdef
|
||||
%type<bool> const_def;
|
||||
|
||||
%% /* Grammar rules and actions follow */
|
||||
|
||||
start_symbol: deffile ;
|
||||
|
||||
deffile: declarations definitions;
|
||||
|
||||
declarations: /* empty */ | declarations package | declarations rootdef;
|
||||
|
||||
|
||||
rootdef: T_ROOT primtype T_END {
|
||||
if($2->kind != TYPE_OBJECT)
|
||||
g_error("Bad root type: %s.%s",
|
||||
$2->module->package->name,
|
||||
$2->name);
|
||||
root_class = $2;
|
||||
};
|
||||
|
||||
|
||||
definitions: current_module_def deflist;
|
||||
|
||||
deflist: /* empty */ | deflist def {
|
||||
put_def($2);
|
||||
} | deflist import;
|
||||
|
||||
import: T_IMPORT importlist T_END;
|
||||
|
||||
importlist: ident {
|
||||
Package* p = get_pkg($1);
|
||||
if(!p)
|
||||
g_error("Attempt to import unknown package %s", $1);
|
||||
imports_list = g_slist_prepend(imports_list, p);
|
||||
} | importlist T_COMMA ident {
|
||||
Package* p = get_pkg($3);
|
||||
if(!p)
|
||||
g_error("Attempt to import unknown package %s", $3);
|
||||
imports_list = g_slist_prepend(imports_list, p);
|
||||
}
|
||||
|
||||
package: T_PACKAGE maybeident headerdef T_OPEN_B {
|
||||
Package* p;
|
||||
Id i = $2;
|
||||
if(!i)
|
||||
i = GET_ID("");
|
||||
p = get_pkg(i);
|
||||
if(!p){
|
||||
p = g_new(Package, 1);
|
||||
p->name = i;
|
||||
p->type_hash = g_hash_table_new(NULL, NULL);
|
||||
p->mod_hash = g_hash_table_new(NULL, NULL);
|
||||
p->headerbase = $3;
|
||||
put_pkg(p);
|
||||
}
|
||||
current_package = p;
|
||||
} modulelist T_CLOSE_B {
|
||||
current_package = NULL;
|
||||
};
|
||||
|
||||
current_module_def: T_MODULE ident T_SCOPE ident T_END {
|
||||
Package* p = get_pkg($2);
|
||||
Module* m;
|
||||
if(!p)
|
||||
g_error("Unknown package %s", $2);
|
||||
m = get_mod(p, $4);
|
||||
if(!m)
|
||||
g_error("Unknown module %s.%s", $2, $4);
|
||||
current_module = m;
|
||||
}
|
||||
|
||||
|
||||
modulelist: /* empty */ | modulelist simpledecl | modulelist module;
|
||||
|
||||
headerdef: /* empty */ {
|
||||
$$ = NULL;
|
||||
}| T_HEADERNAME;
|
||||
|
||||
|
||||
maybeident: ident | /* empty */ {
|
||||
$$ = NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
module: T_MODULE maybeident headerdef T_OPEN_B {
|
||||
Module* m = get_mod(current_package, $2);
|
||||
if(!m){
|
||||
m = g_new(Module, 1);
|
||||
m->package = current_package;
|
||||
m->name = $2;
|
||||
m->header = $3;
|
||||
put_mod(m);
|
||||
}
|
||||
current_module = m;
|
||||
} decllist T_CLOSE_B {
|
||||
current_module = NULL;
|
||||
};
|
||||
|
||||
decllist: /* empty */ | decllist decl;
|
||||
|
||||
decl: simpledecl ;/* | classdecl | opaquedecl | protclassdecl;*/
|
||||
|
||||
fundtype: T_INT {
|
||||
$$ = TYPE_INT;
|
||||
} | T_DOUBLE {
|
||||
$$ = TYPE_DOUBLE;
|
||||
} | T_CLASS {
|
||||
$$ = TYPE_OBJECT;
|
||||
} | T_ENUM {
|
||||
$$ = TYPE_ENUM;
|
||||
} | T_FLAGS {
|
||||
$$ = TYPE_FLAGS;
|
||||
} | T_BOXED {
|
||||
$$ = TYPE_BOXED;
|
||||
} | T_FOREIGN {
|
||||
$$ = TYPE_FOREIGN;
|
||||
} | T_CHAR {
|
||||
$$ = TYPE_CHAR;
|
||||
};
|
||||
|
||||
|
||||
simpledecl: fundtype ident T_END {
|
||||
PrimType* t = g_new(PrimType, 1);
|
||||
if(current_module)
|
||||
t->module = current_module;
|
||||
else{
|
||||
Module* m;
|
||||
g_assert(!get_mod(current_package, $2));
|
||||
m = g_new(Module, 1);
|
||||
m->package = current_package;
|
||||
m->name = $2;
|
||||
m->header = NULL;
|
||||
put_mod(m);
|
||||
t->module = m;
|
||||
}
|
||||
|
||||
t->name = $2;
|
||||
t->kind = $1;
|
||||
put_type(t);
|
||||
};
|
||||
|
||||
semitype: const_def primtype {
|
||||
$$.is_const = $1;
|
||||
$$.indirection = 0;
|
||||
$$.notnull = FALSE;
|
||||
$$.prim = $2;
|
||||
} | semitype T_POINTER {
|
||||
$$ = $1;
|
||||
$$.indirection++;
|
||||
};
|
||||
|
||||
type: semitype {
|
||||
if(!$$.indirection){
|
||||
g_assert($$.prim->kind != TYPE_OBJECT);
|
||||
g_assert($$.prim->kind != TYPE_BOXED);
|
||||
}
|
||||
} | semitype T_NOTNULLPTR {
|
||||
$$ = $1;
|
||||
$$.indirection++;
|
||||
$$.notnull = TRUE;
|
||||
};
|
||||
|
||||
|
||||
ident: T_IDENT;
|
||||
|
||||
typeorvoid: type | T_VOID {
|
||||
$$.prim = NULL;
|
||||
$$.indirection = 0;
|
||||
$$.is_const = FALSE;
|
||||
$$.notnull = FALSE;
|
||||
};
|
||||
|
||||
|
||||
primtype: maybeident T_SCOPE ident {
|
||||
Id i = $1;
|
||||
Package* p;
|
||||
PrimType* t;
|
||||
if(!i)
|
||||
i = GET_ID("");
|
||||
p = get_pkg(i);
|
||||
if(!p)
|
||||
g_error("Unknown package %s!", i);
|
||||
t = get_type(p, $3);
|
||||
if(!t)
|
||||
g_error("Unknown type %s:%s", i, $3);
|
||||
$$ = t;
|
||||
} | ident {
|
||||
Package* p = current_module->package;
|
||||
PrimType* t;
|
||||
GSList* l = imports_list;
|
||||
t = get_type(p, $1);
|
||||
while(l && !t){
|
||||
t = get_type(l->data, $1);
|
||||
l = l->next;
|
||||
}
|
||||
if(!t)
|
||||
g_error("Couldn't find type %s in import list", $1);
|
||||
$$ = t;
|
||||
};
|
||||
|
||||
paramlist: /* empty */ {
|
||||
$$ = NULL;
|
||||
} | param paramtail {
|
||||
$$ = g_slist_prepend($2, $1);
|
||||
};
|
||||
|
||||
paramtail: /* empty */ {
|
||||
$$ = NULL;
|
||||
} | T_COMMA param paramtail {
|
||||
$$ = g_slist_prepend($3, $2);
|
||||
};
|
||||
|
||||
param: type ident docstring {
|
||||
$$=g_new(Param, 1);
|
||||
$$->method=current_method;
|
||||
$$->doc=$3;
|
||||
$$->name=$2;
|
||||
$$->type=$1;
|
||||
};
|
||||
|
||||
methkind: T_ABSTRACT {
|
||||
$$ = METH_VIRTUAL;
|
||||
} | T_DIRECT {
|
||||
$$ = METH_DIRECT;
|
||||
} | /* empty */ {
|
||||
$$ = METH_DIRECT;
|
||||
} | T_STATIC {
|
||||
$$ = METH_STATIC;
|
||||
} | T_PRE_EMIT {
|
||||
$$ = METH_EMIT_PRE;
|
||||
} | T_POST_EMIT {
|
||||
$$ = METH_EMIT_POST;
|
||||
} | T_DUAL_EMIT {
|
||||
$$ = METH_EMIT_BOTH;
|
||||
};
|
||||
|
||||
|
||||
datakind: T_ABSTRACT {
|
||||
$$ = DATA_STATIC_VIRTUAL;
|
||||
} | T_DIRECT {
|
||||
$$ = DATA_DIRECT;
|
||||
} | /* empty */ {
|
||||
$$ = DATA_DIRECT;
|
||||
} | T_STATIC {
|
||||
$$ = DATA_STATIC;
|
||||
};
|
||||
|
||||
|
||||
methprot: T_PROTECTED{
|
||||
$$ = METH_PROTECTED;
|
||||
} | T_PUBLIC {
|
||||
$$ = METH_PUBLIC;
|
||||
};
|
||||
|
||||
dataprot: /* empty */ {
|
||||
$$ = DATA_PROTECTED;
|
||||
} | T_READ_ONLY {
|
||||
$$ = DATA_READONLY;
|
||||
} | T_READ_WRITE {
|
||||
$$ = DATA_READWRITE;
|
||||
};
|
||||
|
||||
emitdef: /* empty */ {
|
||||
$$ = EMIT_NONE;
|
||||
} | T_PRE_EMIT {
|
||||
$$ = EMIT_PRE;
|
||||
} | T_POST_EMIT {
|
||||
$$ = EMIT_POST;
|
||||
};
|
||||
|
||||
docstring: T_STRING {
|
||||
$$ = $1;
|
||||
} | /* empty */ {
|
||||
$$ = NULL;
|
||||
};
|
||||
|
||||
|
||||
idlist: ident {
|
||||
$$ = g_slist_prepend(NULL, (gpointer)($1));
|
||||
} | idlist T_COMMA ident {
|
||||
$$ = g_slist_append($1, (gpointer)($3));
|
||||
};
|
||||
|
||||
def: classdef | enumdef | flagsdef;
|
||||
|
||||
enumdef: T_ENUM primtype docstring T_OPEN_B idlist T_CLOSE_B {
|
||||
EnumDef* d=g_new(EnumDef, 1);
|
||||
g_assert($2->kind==TYPE_ENUM);
|
||||
d->alternatives = $5;
|
||||
$$=DEF(d);
|
||||
$$->type=$2;
|
||||
$$->doc=$3;
|
||||
};
|
||||
|
||||
flagsdef: T_FLAGS primtype docstring T_OPEN_B idlist T_CLOSE_B T_END {
|
||||
FlagsDef* d=g_new(FlagsDef, 1);
|
||||
g_assert($2->kind==TYPE_ENUM);
|
||||
d->flags = $5;
|
||||
$$=DEF(d);
|
||||
$$->type=$2;
|
||||
$$->doc=$3;
|
||||
};
|
||||
|
||||
parent: /* empty */{
|
||||
g_assert(root_class);
|
||||
$$ = root_class;
|
||||
} | T_INHERITANCE primtype{
|
||||
$$=$2;
|
||||
}
|
||||
|
||||
classdef: T_CLASS primtype parent docstring T_OPEN_B {
|
||||
g_assert($2->kind==TYPE_OBJECT);
|
||||
g_assert(!$3 || $3->kind==TYPE_OBJECT);
|
||||
g_assert($2->module == current_module);
|
||||
current_class=g_new(ObjectDef, 1);
|
||||
} classbody T_CLOSE_B {
|
||||
Type t;
|
||||
t.is_const = FALSE;
|
||||
t.indirection = 1;
|
||||
t.notnull = TRUE;
|
||||
t.prim = $2;
|
||||
current_class->self_type[0]=t;
|
||||
t.is_const=TRUE;
|
||||
current_class->self_type[1]=t;
|
||||
current_class->parent = $3;
|
||||
current_class->members = g_slist_reverse($7);
|
||||
$$=DEF(current_class);
|
||||
current_class=NULL;
|
||||
$$->type = $2;
|
||||
$$->doc = $4;
|
||||
};
|
||||
|
||||
member_def: data_member_def | method_def;
|
||||
|
||||
|
||||
|
||||
data_member_def: dataprot datakind type ident emitdef docstring T_END {
|
||||
DataMember* m = g_new(DataMember, 1);
|
||||
m->prot = $1;
|
||||
m->type = $3;
|
||||
m->kind = $2;
|
||||
$$ = MEMBER(m);
|
||||
$$->membertype = MEMBER_DATA;
|
||||
$$->name = $4;
|
||||
/* $$->emit = $5; */
|
||||
$$->doc = $6;
|
||||
};
|
||||
|
||||
method_def: methprot methkind typeorvoid ident T_OPEN_P {
|
||||
current_method = g_new(Method, 1);
|
||||
} paramlist T_CLOSE_P const_def emitdef docstring T_END {
|
||||
current_method->prot = $1;
|
||||
current_method->ret_type = $3;
|
||||
current_method->self_const = $9;
|
||||
current_method->params = $7;
|
||||
current_method->kind = $2;
|
||||
$$=MEMBER(current_method);
|
||||
current_method=NULL;
|
||||
$$->membertype = MEMBER_METHOD;
|
||||
$$->name = $4;
|
||||
/* $$->emit = $10; */
|
||||
$$->doc = $11;
|
||||
};
|
||||
|
||||
const_def: T_CONST {
|
||||
$$ = TRUE;
|
||||
} | /* empty */ {
|
||||
$$ = FALSE;
|
||||
};
|
||||
|
||||
classbody: /* empty */ {
|
||||
$$ = NULL;
|
||||
} | classbody member_def{
|
||||
$2->my_class=current_class;
|
||||
$$ = g_slist_prepend($1, $2);
|
||||
};
|
||||
|
||||
%%
|
||||
#define YYDEBUG 1
|
||||
|
||||
GHashTable* type_hash;
|
||||
GHashTable* class_hash;
|
||||
|
||||
gboolean in_ident;
|
||||
|
||||
int yyerror (char* s){
|
||||
g_error ("Parser error: %s", s);
|
||||
return 0;
|
||||
}
|
|
@ -1,305 +0,0 @@
|
|||
#include "pnode.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
static const gconstpointer p_node_magic_tag = &p_node_magic_tag;
|
||||
|
||||
|
||||
|
||||
#define BE_NODE(x) g_assert((x) && ((PNode*)(x))->magic == &p_node_magic_tag)
|
||||
|
||||
static GMemChunk* p_node_chunk;
|
||||
|
||||
static GList* p_float_list;
|
||||
static GHashTable* p_str_hash;
|
||||
|
||||
typedef enum{
|
||||
NODE_NIL,
|
||||
NODE_DATA,
|
||||
NODE_COLLECT
|
||||
} PNodeType;
|
||||
|
||||
typedef struct{
|
||||
gchar* str;
|
||||
PNode* node;
|
||||
} PBlock;
|
||||
|
||||
typedef struct _PRNode{
|
||||
GQuark tag;
|
||||
PNode* node;
|
||||
} PRNode;
|
||||
|
||||
|
||||
struct _PRoot{
|
||||
GData* data;
|
||||
GList* nodes;
|
||||
};
|
||||
|
||||
struct _PNode{
|
||||
gconstpointer magic;
|
||||
guint ref_count;
|
||||
GList* float_link;
|
||||
PNodeType type;
|
||||
union {
|
||||
struct {
|
||||
gint nblocks;
|
||||
PBlock* blocks;
|
||||
} b;
|
||||
struct {
|
||||
PNodeCreateFunc func;
|
||||
GQuark tag;
|
||||
} c;
|
||||
} u;
|
||||
};
|
||||
|
||||
static PNode p_nil_node = {
|
||||
&p_node_magic_tag,
|
||||
-1,
|
||||
NULL,
|
||||
NODE_NIL,
|
||||
{{0,NULL}}
|
||||
};
|
||||
|
||||
PNode* p_nil = &p_nil_node;
|
||||
|
||||
static PNode* p_make(PNodeType type){
|
||||
PNode* node;
|
||||
if(!p_node_chunk)
|
||||
p_node_chunk = g_mem_chunk_create(PNode, 1024,
|
||||
G_ALLOC_AND_FREE);
|
||||
|
||||
node = g_chunk_new(PNode, p_node_chunk);
|
||||
node->ref_count = 0;
|
||||
node->magic = &p_node_magic_tag;
|
||||
node->float_link = p_float_list = g_list_prepend(p_float_list, node);
|
||||
node->type = type;
|
||||
return node;
|
||||
}
|
||||
|
||||
void p_ref(PNode* node){
|
||||
BE_NODE(node);
|
||||
if(node==p_nil)
|
||||
return;
|
||||
if(!node->ref_count){
|
||||
p_float_list = g_list_remove_link(p_float_list,
|
||||
node->float_link);
|
||||
node->float_link = NULL;
|
||||
}
|
||||
node->ref_count++;
|
||||
}
|
||||
|
||||
void p_unref(PNode* node){
|
||||
BE_NODE(node);
|
||||
if(node==p_nil)
|
||||
return;
|
||||
node->ref_count--;
|
||||
if(node->ref_count>0)
|
||||
return;
|
||||
switch(node->type){
|
||||
case NODE_DATA:{
|
||||
PBlock* bl = node->u.b.blocks;
|
||||
gint i=node->u.b.nblocks;
|
||||
while(i--){
|
||||
g_free(bl[i].str);
|
||||
p_unref(bl[i].node);
|
||||
}
|
||||
g_free(bl);
|
||||
break;
|
||||
}
|
||||
case NODE_NIL:
|
||||
break;
|
||||
case NODE_COLLECT:
|
||||
break;
|
||||
}
|
||||
g_mem_chunk_free(p_node_chunk, node);
|
||||
}
|
||||
|
||||
void p_write(PNode* node, FILE* f, PRoot* r){
|
||||
g_assert(f);
|
||||
BE_NODE(node);
|
||||
switch(node->type){
|
||||
case NODE_DATA:{
|
||||
gint i = 0, n = node->u.b.nblocks;
|
||||
PBlock* bl = node->u.b.blocks;
|
||||
|
||||
for(i = 0; i < n; i++){
|
||||
if(bl[i].str)
|
||||
fputs(bl[i].str, f);
|
||||
p_write(bl[i].node, f, r);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_NIL:
|
||||
break;
|
||||
case NODE_COLLECT:
|
||||
if(r){
|
||||
GList* l = g_datalist_id_get_data(&r->data,
|
||||
node->u.c.tag);
|
||||
l = g_list_last(l);
|
||||
|
||||
if(node->u.c.func)
|
||||
for(; l; l = l->prev)
|
||||
p_write(node->u.c.func(l->data),
|
||||
f, r);
|
||||
else
|
||||
for(; l; l = l->prev)
|
||||
p_write(l->data, f, r);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gchar* p_to_str(PNode* n, PRoot* pr){
|
||||
FILE* f = tmpfile();
|
||||
glong len;
|
||||
gchar* buf;
|
||||
p_write(n, f, pr);
|
||||
len = ftell(f);
|
||||
rewind(f);
|
||||
buf = g_new(gchar, len+1);
|
||||
fread(buf, len, 1, f);
|
||||
buf[len]='\0';
|
||||
fclose(f);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static PNode* p_simple_string(gchar* str){
|
||||
PNode* n = p_make(NODE_DATA);
|
||||
n->u.b.nblocks = 1;
|
||||
n->u.b.blocks = g_new(PBlock, 1);
|
||||
n->u.b.blocks[0].str = str;
|
||||
n->u.b.blocks[0].node = p_nil;
|
||||
return n;
|
||||
}
|
||||
|
||||
PNode* p_str(const gchar* str){
|
||||
PNode* n;
|
||||
|
||||
if(!str)
|
||||
return p_nil;
|
||||
|
||||
if(!p_str_hash)
|
||||
p_str_hash = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
n = g_hash_table_lookup(p_str_hash, str);
|
||||
if(n)
|
||||
return n;
|
||||
else
|
||||
return p_simple_string(g_strdup(str));
|
||||
}
|
||||
|
||||
PNode* p_prf(const gchar* format, ...){
|
||||
PNode* n;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
n = p_simple_string(g_strdup_vprintf (format, args));
|
||||
va_end(args);
|
||||
return n;
|
||||
}
|
||||
|
||||
PNode* p_fmt(const gchar* f, ...){
|
||||
va_list args;
|
||||
const gchar* b;
|
||||
PNode* n = p_make(NODE_DATA);
|
||||
gint i;
|
||||
PBlock* bl;
|
||||
|
||||
va_start(args, f);
|
||||
g_assert(f);
|
||||
for(b = f, i = 0; *b; b++)
|
||||
if(*b == '~')
|
||||
i++;
|
||||
if(b!=f && b[-1] != '~')
|
||||
i++;
|
||||
bl = g_new(PBlock, i);
|
||||
n->u.b.blocks = bl;
|
||||
n->u.b.nblocks = i;
|
||||
|
||||
for(b = f, i = 0; *b; i++){
|
||||
gint idx=0;
|
||||
PNode* p = p_nil;
|
||||
while(b[idx] && b[idx] != '~')
|
||||
idx++;
|
||||
bl[i].str = g_strndup(b, idx);
|
||||
if(b[idx] == '~'){
|
||||
p = va_arg(args, PNode*);
|
||||
BE_NODE(p);
|
||||
p_ref(p);
|
||||
idx++;
|
||||
}
|
||||
bl[i].node = p;
|
||||
b = &b[idx];
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
PNode* p_for(GSList* lst, PNodeCreateFunc func, gpointer user_data){
|
||||
PNode* n = p_make(NODE_DATA);
|
||||
GSList* l = lst;
|
||||
gint i = g_slist_length(l);
|
||||
n->u.b.nblocks = i;
|
||||
n->u.b.blocks = g_new(PBlock, i);
|
||||
i = 0;
|
||||
while(l){
|
||||
PNode* p;
|
||||
if(user_data == p_nil)
|
||||
p = func(l->data);
|
||||
else
|
||||
p = func(l->data, user_data);
|
||||
BE_NODE(p);
|
||||
p_ref(p);
|
||||
n->u.b.blocks[i].str = NULL;
|
||||
n->u.b.blocks[i++].node = p;
|
||||
l = l->next;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
PNode* p_col(const gchar* tag, PNodeCreateFunc func){
|
||||
PNode* n = p_make(NODE_COLLECT);
|
||||
n->u.c.func = func;
|
||||
n->u.c.tag = g_quark_from_string(tag);
|
||||
return n;
|
||||
}
|
||||
|
||||
PRoot* pr_new(void){
|
||||
PRoot* pr = g_new(PRoot, 1);
|
||||
pr->nodes = NULL;
|
||||
g_datalist_init(&pr->data);
|
||||
return pr;
|
||||
}
|
||||
|
||||
/*
|
||||
void pr_add(PRoot* pr, const gchar* tag, PNode* node){
|
||||
PRNode* n;
|
||||
g_assert(pr);
|
||||
BE_NODE(node);
|
||||
if(node == p_nil)
|
||||
return;
|
||||
n = g_new(PRNode, 1);
|
||||
n->tag = g_quark_from_string(tag);
|
||||
n->node = node;
|
||||
pr->nodes = g_list_prepend(pr->nodes, n);
|
||||
p_ref(node);
|
||||
}
|
||||
*/
|
||||
void pr_put(PRoot* pr, const gchar* tag, gpointer datum){
|
||||
GList* l = g_datalist_get_data(&pr->data, tag);
|
||||
|
||||
if(!g_list_find(l, datum))
|
||||
g_datalist_set_data(&pr->data, tag,
|
||||
g_list_prepend(l, datum));
|
||||
}
|
||||
|
||||
|
||||
void pr_free(PRoot* pr){
|
||||
GList* l;
|
||||
for(l=pr->nodes;l;l = l->next){
|
||||
PRNode* n = l->data;
|
||||
p_unref(n->node);
|
||||
g_free(n);
|
||||
}
|
||||
g_list_free(pr->nodes);
|
||||
g_free(pr);
|
||||
}
|
||||
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef __PNODE_H__
|
||||
#define __PNODE_H__
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct _PNode PNode;
|
||||
typedef struct _PRoot PRoot;
|
||||
typedef const gconstpointer Tag;
|
||||
extern PNode* p_nil;
|
||||
|
||||
typedef void (*PNodeTraverseFunc) (PNode* n, gpointer user_data);
|
||||
typedef PNode* (*PNodeCreateFunc) ();
|
||||
|
||||
void p_ref(PNode* node);
|
||||
void p_unref(PNode* node);
|
||||
PNode* p_str(const gchar* str);
|
||||
PNode* p_prf(const gchar* format, ...) G_GNUC_PRINTF(1, 2);
|
||||
PNode* p_fmt(const gchar* f, ...);
|
||||
PNode* p_lst(PNode* n, ...);
|
||||
PNode* p_for(GSList* l, PNodeCreateFunc func, gpointer user_data);
|
||||
PNode* p_col(const gchar* tag, PNodeCreateFunc func);
|
||||
void p_write(PNode* node, FILE* f, PRoot* r);
|
||||
gchar* p_to_str(PNode* n, PRoot* pr);
|
||||
|
||||
|
||||
|
||||
PRoot* pr_new(void);
|
||||
void pr_put(PRoot* pr, const gchar* tag, gpointer datum);
|
||||
void pr_write(PRoot* pr, FILE* stream, const gchar* tag);
|
||||
void pr_free(PRoot* root);
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue