1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-12-22 13:30:49 +02:00

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
This commit is contained in:
Werner Almesberger 2012-08-21 01:59:46 -03:00
parent 7c037ae78a
commit 8982d09474
5 changed files with 32 additions and 2 deletions

1
fpd.h
View File

@ -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);

6
fpd.l
View File

@ -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;

15
fped.c
View File

@ -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,

7
fped.h
View File

@ -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 */

5
gui.c
View File

@ -102,6 +102,8 @@ static GtkItemFactoryEntry menu_entries[] = {
{ "/File/Write Postscript",
NULL, write_ps, 0, "<Item>" },
{ "/File/sep2", NULL, NULL, 0, "<Separator>" },
{ "/File/Reload", NULL, reload, 0, "<Item>" },
{ "/File/sep3", NULL, NULL, 0, "<Separator>" },
{ "/File/Quit", NULL, gtk_main_quit, 0, "<Item>" },
{ "/View", NULL, NULL, 0, "<Branch>" },
{ "/View/Zoom in", NULL, zoom_in_center, 0, "<Item>" },
@ -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);
}