From 8982d094747b5a0f09704b02d5e273123f4a827e Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 21 Aug 2012 01:59:46 -0300 Subject: [PATCH] add experimental reload feature This is a first crude attempt at allowing reloading without exiting fped. This should be useful when writing a design as text and using the GUI only to visualize it. Reload is only enabled (in the File menu) if the file doesn't have the "MACHINE-GENERATED" header. Known bugs: - exits on parse errors - leaks memory badly - current frame is reset to root --- fpd.h | 1 + fpd.l | 6 ++++++ fped.c | 15 +++++++++++++++ fped.h | 7 +++++-- gui.c | 5 +++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/fpd.h b/fpd.h index 356c777..99843be 100644 --- a/fpd.h +++ b/fpd.h @@ -26,6 +26,7 @@ extern struct value *var_value_list; int dbg_print(const struct expr *expr, const struct frame *frame); void scan_empty(void); +void scan_file(void); void scan_expr(const char *s); void scan_var(const char *s); void scan_values(const char *s); diff --git a/fpd.l b/fpd.l index 5d2cd20..8265adf 100644 --- a/fpd.l +++ b/fpd.l @@ -35,6 +35,12 @@ void scan_empty(void) } +void scan_file(void) +{ + start_token = START_FPD; +} + + void scan_expr(const char *s) { start_token = START_EXPR; diff --git a/fped.c b/fped.c index df6d253..608f5a2 100644 --- a/fped.c +++ b/fped.c @@ -64,6 +64,21 @@ static void load_file(const char *name) } +void reload(void) +{ + struct frame *old_frames; + + /* @@@ this needs more work */ + purge(); + old_frames = frames; + scan_file(); + load_file(save_file_name); + if (!instantiate()) + frames = old_frames; + change_world(); +} + + static void usage(const char *name) { fprintf(stderr, diff --git a/fped.h b/fped.h index 02916aa..e579102 100644 --- a/fped.h +++ b/fped.h @@ -1,8 +1,8 @@ /* * fped.h - Things fped.c exports * - * Written 2010 by Werner Almesberger - * Copyright 2010 by Werner Almesberger + * Written 2010, 2012 by Werner Almesberger + * Copyright 2010, 2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,4 +17,7 @@ extern char *save_file_name; extern int no_save; + +void reload(void); + #endif /* !FPED_H */ diff --git a/gui.c b/gui.c index 934d0ff..b4d2fb4 100644 --- a/gui.c +++ b/gui.c @@ -102,6 +102,8 @@ static GtkItemFactoryEntry menu_entries[] = { { "/File/Write Postscript", NULL, write_ps, 0, "" }, { "/File/sep2", NULL, NULL, 0, "" }, + { "/File/Reload", NULL, reload, 0, "" }, + { "/File/sep3", NULL, NULL, 0, "" }, { "/File/Quit", NULL, gtk_main_quit, 0, "" }, { "/View", NULL, NULL, 0, "" }, { "/View/Zoom in", NULL, zoom_in_center, 0, "" }, @@ -127,6 +129,9 @@ static void make_menu_bar(GtkWidget *hbox) gtk_widget_set_sensitive( gtk_item_factory_get_item(factory, "/File/Save"), !no_save); + gtk_widget_set_sensitive( + gtk_item_factory_get_item(factory, "/File/Reload"), + no_save && !!save_file_name); }