aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1998-05-23 22:43:14 +0000
committerEric S. Raymond <esr@thyrsus.com>1998-05-23 22:43:14 +0000
commit8397dc3c13adbed6de9ca6c3b6f0663f9d63ad0b (patch)
tree48c0b32f6193426d8f21ab83881721f1c4c9c9b4
parent44cacf5a0e6ebfed70606e12e002a4f2bce0ba9e (diff)
downloadfetchmail-8397dc3c13adbed6de9ca6c3b6f0663f9d63ad0b.tar.gz
fetchmail-8397dc3c13adbed6de9ca6c3b6f0663f9d63ad0b.tar.bz2
fetchmail-8397dc3c13adbed6de9ca6c3b6f0663f9d63ad0b.zip
This code yields a syntactically correct Python initializer that
evaluates with no errors. svn path=/trunk/; revision=1813
-rw-r--r--conf.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/conf.c b/conf.c
index 1a821864..095d396b 100644
--- a/conf.c
+++ b/conf.c
@@ -33,10 +33,19 @@ static void indent(char ic)
if (ic == ')' || ic == ']' || ic == '}')
indent_level--;
- for (i = 0; i < indent_level / 2; i++)
- putc('\t', stdout);
- if (indent_level % 2)
- fputs(" ", stdout);
+ /*
+ * The guard here is a kluge. It depends on the fact that in the
+ * particular structure we're dumping, opening [s are always
+ * initializers for dictionary members and thus will be preceded
+ * by a member name.
+ */
+ if (ic != '[')
+ {
+ for (i = 0; i < indent_level / 2; i++)
+ putc('\t', stdout);
+ if (indent_level % 2)
+ fputs(" ", stdout);
+ }
if (ic)
{
@@ -86,7 +95,7 @@ static void listdump(const char *name, struct idlist *list)
fprintf(stdout, "'%s':", name);
if (!list)
- fputs("nil,\n", stdout);
+ fputs("None,\n", stdout);
else
{
struct idlist *idp;
@@ -117,7 +126,11 @@ void dump_config(struct runctl *runp, struct query *querylist)
struct idlist *idp;
indent_level = 0;
+
+ fputs("from Tkinter import *\t# for FALSE\n\n", stdout);
+
fputs("# Start of initializer\n", stdout);
+ fputs("configuration = ", stdout);
indent('{');
numdump("poll_interval", runp->poll_interval);
@@ -127,13 +140,12 @@ void dump_config(struct runctl *runp, struct query *querylist)
booldump("invisible", runp->invisible);
if (!querylist)
- {
- indent('}');
- return;
- }
+ goto alldone;
indent(0);
fputs("# List of server entries begins here\n", stdout);
+ indent(0);
+ fputs("'servers': ", stdout);
indent('[');
for (ctl = querylist; ctl; ctl = ctl->next)
@@ -147,6 +159,7 @@ void dump_config(struct runctl *runp, struct query *querylist)
{
indent(']');
indent('}');
+ indent('\0'); putc(',', stdout);
}
indent(0);
@@ -194,6 +207,8 @@ void dump_config(struct runctl *runp, struct query *querylist)
stringdump("monitor", ctl->server.monitor);
#endif /* linux */
+ indent(0);
+ fputs("'users': ", stdout);
indent('[');
}
@@ -203,7 +218,7 @@ void dump_config(struct runctl *runp, struct query *querylist)
stringdump("password", ctl->password);
indent('\0');
- fprintf(stdout, "`localnames':[");
+ fprintf(stdout, "'localnames':[");
for (idp = ctl->localnames; idp; idp = idp->next)
{
if (idp->val.id2)
@@ -252,6 +267,7 @@ void dump_config(struct runctl *runp, struct query *querylist)
/* end array of servers */
indent(']');
+ alldone:
/* end top-level dictionary */
indent('}');
fputs("# End of initializer\n", stdout);