[cdebconf] helper macros, i18n, backup, etc
Hi,
here are some unrelated issues about cdebconf.
1. The helper macros recently introduced do break several packages
under debian-installer/tools/ which used to declare their own
debconf_input function. Maybe we could remove these macros, I
wonder whether they are that useful.
2. The attached backup.patch finishes support for backing up. As it
slightly changes cdebconf interface, I prefer sending it there.
3. May I set a _ macro in frontend.h in order to start i18n of
frontends? As libdiscover already calls dcgettext, I would like to
set it to
#define _(x) dcgettext("cdebconf", (x), LC_MESSAGES)
4. As esplained in #172218, current TITLE command is not l10n-friendly.
I will wait for Joey's solution before changing this in cdebconf, but
the new progress bar support suffers from the same problem.
Denis
Index: src/commands.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/commands.c,v
retrieving revision 1.37
diff -u -r1.37 commands.c
--- src/commands.c 8 Dec 2002 00:38:07 -0000 1.37
+++ src/commands.c 10 Dec 2002 23:18:36 -0000
@@ -163,18 +163,17 @@
int command_go(struct confmodule *mod, int argc, char **argv,
char *out, size_t outsize)
{
- struct question *q;
-
CHECKARGC(== 0);
if (mod->frontend->methods.go(mod->frontend) == CMDSTATUS_GOBACK)
+ {
snprintf(out, outsize, "%u backup", CMDSTATUS_GOBACK);
- else
- {
- snprintf(out, outsize, "%u ok", CMDSTATUS_SUCCESS);
- /* FIXME questions should be tagged when closing session */
- for (q = mod->frontend->questions; q != NULL; q = q->next)
- q->flags |= DC_QFLAG_SEEN;
- }
+ mod->update_seen_questions(mod, -1);
+ }
+ else
+ {
+ snprintf(out, outsize, "%u ok", CMDSTATUS_SUCCESS);
+ mod->update_seen_questions(mod, 1);
+ }
mod->frontend->methods.clear(mod->frontend);
return DC_OK;
Index: src/confmodule.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/confmodule.c,v
retrieving revision 1.17
diff -u -r1.17 confmodule.c
--- src/confmodule.c 8 Dec 2002 00:38:07 -0000 1.17
+++ src/confmodule.c 10 Dec 2002 23:18:36 -0000
@@ -1,6 +1,8 @@
#include "confmodule.h"
#include "commands.h"
#include "frontend.h"
+#include "database.h"
+#include "question.h"
#include "strutl.h"
#include <stdio.h>
@@ -170,6 +172,72 @@
return pid;
}
+static int confmodule_update_seen_questions(struct confmodule *mod, int action)
+{
+ struct question *q;
+ struct question *qlast = NULL;
+ int i, narg;
+
+ switch (action)
+ {
+ case 1:
+ if (mod->seen_questions == NULL)
+ narg = 0;
+ else
+ narg = sizeof(mod->seen_questions) / sizeof(char *);
+
+ i = narg;
+ for (q = mod->frontend->questions; q != NULL; q = q->next)
+ narg++;
+ if (narg == 0)
+ return DC_OK;
+
+ mod->seen_questions = (char **) realloc(mod->seen_questions, narg);
+ for (q = mod->frontend->questions; q != NULL; q = q->next)
+ {
+ *(mod->seen_questions+i) = strdup(q->tag);
+ i++;
+ }
+ break;
+ case -1:
+ if (mod->seen_questions == NULL)
+ return DC_OK;
+
+ narg = sizeof(mod->seen_questions) / sizeof(char *);
+ for (q = mod->frontend->questions; q != NULL; q = q->next)
+ qlast = q;
+
+ for (q = qlast; q != NULL; q = q->prev)
+ {
+ if (strcmp(*(mod->seen_questions + narg - 1), q->tag) != 0)
+ return DC_OK;
+ DELETE(*(mod->seen_questions + narg - 1));
+ narg --;
+ }
+ break;
+ case 0:
+ if (mod->seen_questions == NULL)
+ return DC_OK;
+
+ narg = sizeof(mod->seen_questions) / sizeof(char *);
+ for (i = 0; i < narg; i++)
+ {
+ q = mod->questions->methods.get(mod->questions, *(mod->seen_questions+i));
+ if (q == NULL)
+ return DC_NOTOK;
+ q->flags |= DC_QFLAG_SEEN;
+ DELETE(*(mod->seen_questions+i));
+ }
+ DELETE(mod->seen_questions);
+ break;
+ default:
+ /* should never happen */
+ DIE("Mismatch argument in confmodule_update_seen_questions");
+ }
+
+ return DC_OK;
+}
+
struct confmodule *confmodule_new(struct configuration *config,
struct template_db *templates, struct question_db *questions,
struct frontend *frontend)
@@ -183,6 +251,7 @@
mod->run = confmodule_run;
mod->communicate = confmodule_communicate;
mod->shutdown = confmodule_shutdown;
+ mod->update_seen_questions = confmodule_update_seen_questions;
/* TODO: I wish we don't need gross hacks like this.... */
setenv("DEBIAN_HAS_FRONTEND", "1", 1);
@@ -194,3 +263,4 @@
{
DELETE(mod);
}
+
Index: src/confmodule.h
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/confmodule.h,v
retrieving revision 1.4
diff -u -r1.4 confmodule.h
--- src/confmodule.h 7 Dec 2002 23:02:40 -0000 1.4
+++ src/confmodule.h 10 Dec 2002 23:18:36 -0000
@@ -17,12 +17,13 @@
struct confmodule {
struct configuration *config;
struct template_db *templates;
- struct question_db *questions;
+ struct question_db *questions;
struct frontend *frontend;
pid_t pid;
int infd, outfd;
int exitcode;
char *owner;
+ char **seen_questions;
/* methods */
/*
@@ -48,6 +49,14 @@
* @return int - exit code of the config script
*/
int (*shutdown)(struct confmodule *mod);
+
+ /**
+ * @brief Stack for already seen questions, to help backing up
+ * @param struct confmodule *mod - confmodule object
+ * @param int action - push, pop or sync values
+ * @return int - DC_OK, DC_NOTOK
+ */
+ int (*update_seen_questions)(struct confmodule *mod, int action);
};
/**
Index: src/debconf.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/debconf.c,v
retrieving revision 1.15
diff -u -r1.15 debconf.c
--- src/debconf.c 7 Dec 2002 23:02:40 -0000 1.15
+++ src/debconf.c 10 Dec 2002 23:18:37 -0000
@@ -28,6 +28,8 @@
static void save()
{
+ if (confmodule != NULL)
+ confmodule->update_seen_questions(confmodule, 0);
if (questions != NULL)
questions->methods.save(questions);
if (templates != NULL)
Reply to: