Permalink
Browse files

Handle multiple expressions in a single file! Yay! Patch from Lars Da…

…merow

2007-01-12  Ross Burton  <ross@burtonini.com>

	* src/e-sexp.c:
	* src/parser.[ch]:
	* src/devilspie.c:
	* README:
	Handle multiple expressions in a single file! Yay! Patch from Lars
	Damerow <lars@pixar.com>.

svn path=/trunk/; revision=183
  • Loading branch information...
1 parent 2d9aa43 commit 75f1957eab065d1f15a6219929717e23748b9fa6 @rossburton rossburton committed with Ross Burton Jan 12, 2007
Showing with 61 additions and 27 deletions.
  1. +9 −0 ChangeLog
  2. +3 −4 README
  3. +4 −2 src/devilspie.c
  4. +1 −1 src/e-sexp.c
  5. +43 −19 src/parser.c
  6. +1 −1 src/parser.h
View
@@ -1,3 +1,12 @@
+2007-01-12 Ross Burton <ross@burtonini.com>
+
+ * src/e-sexp.c:
+ * src/parser.[ch]:
+ * src/devilspie.c:
+ * README:
+ Handle multiple expressions in a single file! Yay! Patch from Lars
+ Damerow <lars@pixar.com>.
+
2007-01-08 Ross Burton <ross@burtonini.com>
* devilspie.1:
View
7 README
@@ -35,10 +35,9 @@ about it is probably wrong.
Devil's Pie is configured by reading a number of files from two directories:
$HOME/.devilspie/ and $SYSCONFDIR/devilspie (typically /etc/devilspie). Devil's
-Pie will read s-expressions from every .ds file in those paths. Note that
-currently only the first s-expressions is parsed, but this will be fixed
-shortly. S-expressions are familiar to most Emacs users and in the limited use
-they have in Devil's Pie are trivially learnt by example.
+Pie will read s-expressions from every .ds file in those paths. S-expressions
+are familiar to most Emacs users and in the limited use they have in Devil's Pie
+are trivially learnt by example.
The basic model is that every time a window is created, the s-expressions are
evaluated. The window is available to the functions you call as an implicit
View
@@ -121,14 +121,16 @@ int main(int argc, char **argv) {
/* If there were files specified use those, otherwise load the default configuration */
if (files) {
while (*files) {
- ESExp *s;
+ GList *s;
s = load_configuration_file (*files++);
- if (s) sexps = g_list_append (sexps, s);
+ if (s) sexps = g_list_concat (sexps, s);
}
} else {
load_configuration ();
}
+ if (debug) g_printerr("%d s-expressions loaded.\n", g_list_length(sexps));
+
if (g_list_length (sexps) == 0) {
g_printerr(_("No s-expressions loaded, quiting\n"));
return 1;
View
@@ -1209,7 +1209,7 @@ e_sexp_parse(ESExp *f)
f->tree = parse_value (f);
- return 0;
+ return g_scanner_peek_next_token(f->scanner) != G_TOKEN_EOF;
}
/* returns NULL on error */
View
@@ -87,11 +87,14 @@ static const struct {
/**
* Load a single configuration file.
*/
-ESExp *load_configuration_file (const char *path)
+GList *load_configuration_file (const char *path)
{
/* TODO: GError argument */
+ GList *exp_list = NULL;
+ GScanner *gs = NULL;
ESExp *sexp = NULL;
size_t i;
+ int more_left = 0;
FILE *f;
g_return_val_if_fail (path != NULL, NULL);
@@ -109,27 +112,48 @@ ESExp *load_configuration_file (const char *path)
return NULL;
}
- sexp = e_sexp_new ();
- for(i=0; i < sizeof(symbols)/sizeof(symbols[0]); i++) {
- if (symbols[i].shortcut) {
- e_sexp_add_ifunction(sexp, 0, symbols[i].name, symbols[i].func, &context);
- } else {
- e_sexp_add_function(sexp, 0, symbols[i].name, symbols[i].func, &context);
- }
- }
-
- e_sexp_input_file(sexp, fileno(f));
-
- if (e_sexp_parse(sexp) == -1) {
- g_printerr(_("Cannot parse %s: %s\n"), path, e_sexp_error (sexp));
- g_object_unref (sexp);
- fclose(f);
- return NULL;
- }
+ do {
+ sexp = e_sexp_new ();
+
+ /* HACK: Since e-sexp doesn't seem to have a good way to share one
+ scanner reference between multiple sexps, we fake it by freeing the
+ new one it's given at instantiation and replace it with the one we
+ grab the first time around. */
+ if (gs) {
+ g_scanner_destroy(sexp->scanner);
+ sexp->scanner = gs;
+ }
+
+ /* HACK: If this is the first sexp in the file, hold on to the scanner
+ it gets at instantiation. */
+ if (NULL == gs)
+ gs = sexp->scanner;
+
+ for(i=0; i < sizeof(symbols)/sizeof(symbols[0]); i++) {
+ if (symbols[i].shortcut) {
+ e_sexp_add_ifunction(sexp, 0, symbols[i].name, symbols[i].func, &context);
+ } else {
+ e_sexp_add_function(sexp, 0, symbols[i].name, symbols[i].func, &context);
+ }
+ }
+
+ e_sexp_input_file(sexp, fileno(f));
+
+ more_left = e_sexp_parse(sexp);
+
+ if (more_left == -1) {
+ g_printerr(_("Cannot parse %s: %s\n"), path, e_sexp_error (sexp));
+ g_object_unref (sexp);
+ fclose(f);
+ return NULL;
+ }
+
+ exp_list = g_list_append(exp_list, sexp);
+ } while (more_left);
fclose(f);
- return sexp;
+ return exp_list;
}
/**
View
@@ -22,6 +22,6 @@
#include "e-sexp.h"
void load_configuration(void);
-ESExp *load_configuration_file (const char *path);
+GList *load_configuration_file (const char *path);
#endif /* CONFIG_PARSER_H */

0 comments on commit 75f1957

Please sign in to comment.