[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[cdebconf] Addition in frontend.h to fully support backing up



Hi,

questions must not be flagged 'seen' as soon as they are displayed,
otherwise backing up is impossible because questions won't ever
be displayed again.  So they have to be flagged when session is
over.  This is performed by this patch, but as it adds a new
member to the frontend structure, I prefer asking here if there
are objections.  Also should new functions be added to the
frontend_module structure?

Denis
Index: commands.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/commands.c,v
retrieving revision 1.35
diff -u -r1.35 commands.c
--- commands.c	29 Nov 2002 22:19:33 -0000	1.35
+++ commands.c	1 Dec 2002 21:41:43 -0000
@@ -300,17 +300,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 {
+		frontend_tag_unseen(mod->frontend);
+	}
+	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;
-        }
+		frontend_tag_seen(mod->frontend);
+	}
 	mod->frontend->methods.clear(mod->frontend);
 
 	return DC_OK;
Index: debconf.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/debconf.c,v
retrieving revision 1.14
diff -u -r1.14 debconf.c
--- debconf.c	24 Nov 2002 13:06:48 -0000	1.14
+++ debconf.c	1 Dec 2002 21:41:43 -0000
@@ -24,6 +24,8 @@
 
 static void save()
 {
+	if (frontend != NULL)
+		frontend_sync(frontend);
 	if (questions != NULL)
 		questions->methods.save(questions);
 	if (templates != NULL)
Index: frontend.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/frontend.c,v
retrieving revision 1.15
diff -u -r1.15 frontend.c
--- frontend.c	29 Nov 2002 22:19:33 -0000	1.15
+++ frontend.c	1 Dec 2002 21:41:43 -0000
@@ -79,6 +79,87 @@
 }
 
 /*
+ * Function: frontend_sync
+ * Input: frontend
+ * Output: none
+ * Description: set 'seen' flag of all seen questions
+ * Assumptions: none
+ */
+int frontend_sync(struct frontend *obj)
+{
+	struct question *q;
+	int narg;
+	int i;
+
+	if (obj->seen == NULL)
+		return DC_OK;
+
+	narg = sizeof(obj->seen) / sizeof(char *);
+	for (i = 0; i < narg; i++)
+	{
+		q = obj->qdb->methods.get(obj->qdb, *(obj->seen+i));
+		if (q == NULL)
+			return DC_NOTOK;
+		q->flags |= DC_QFLAG_SEEN;
+		free(*(obj->seen+i));
+	}
+
+	DELETE(obj->seen);
+	return DC_OK;
+}
+
+int frontend_tag_seen(struct frontend *obj)
+{
+	struct question *q;
+	int narg;
+	int i;
+
+	if (obj->seen == NULL)
+		narg = 0;
+	else
+		narg = sizeof(obj->seen) / sizeof(char *);
+
+	i = narg;
+	for (q = obj->questions; q != NULL; q = q->next)
+		narg++;
+	if (narg == 0)
+		return DC_OK;
+
+	obj->seen = (char **) realloc(obj->seen, narg);
+	for (q = obj->questions; q != NULL; q = q->next)
+	{
+		*(obj->seen+i) = strdup(q->tag);
+		i++;
+	}
+
+	return DC_OK;
+}
+
+int frontend_tag_unseen(struct frontend *obj)
+{
+	struct question *q;
+	struct question *qlast = NULL;
+	int narg;
+
+	if (obj->seen == NULL)
+		return DC_OK;
+
+	narg = sizeof(obj->seen) / sizeof(char *);
+	for (q = obj->questions; q != NULL; q = q->next)
+		qlast = q;
+
+	for (q = qlast; q != NULL; q = q->prev)
+	{
+		if (strcmp(*(obj->seen + narg - 1), q->tag) != 0)
+			return DC_OK;
+		free(*(obj->seen + narg - 1));
+		narg --;
+	}
+
+	return DC_OK;
+}
+
+/*
  * Function:
  * Input:
  * Output:
Index: frontend.h
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/frontend.h,v
retrieving revision 1.5
diff -u -r1.5 frontend.h
--- frontend.h	9 Jul 2002 05:25:03 -0000	1.5
+++ frontend.h	1 Dec 2002 21:41:43 -0000
@@ -43,10 +43,18 @@
 	char *title;
 	
 	/* methods */
-    struct frontend_module methods;
+	struct frontend_module methods;
+
+	/* new member */
+	char **seen;
 };
 
 struct frontend *frontend_new(struct configuration *, struct template_db *, struct question_db *);
 void frontend_delete(struct frontend *);
+
+/*  should go into frontend_module */
+int frontend_tag_seen(struct frontend *);
+int frontend_tag_unseen(struct frontend *);
+int frontend_sync(struct frontend *);
 
 #endif

Reply to: