for review: change util/info_to_mdb.c to fix query doc problem

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Mar 25 22:59:19 AEDT 1999


Zoltan, could you please review this one?

--------------------

Estimated hours taken: 0.5

Fix a problem with the automatically-generated mdb documentation
for the query/cc_query/io_query mdb commands.  The documentation
for the first two was blank, because the shared description for
all three was only listed for the third.

util/info_to_mdb.c:
	Handle the case where several commands are documented together,
	by adding cross-references in the generated mdb documentation.
	(A better fix would be to duplicate the same documentation for
	each such command, or to provide some way of resolving these
	cross-references automatically rather than just telling the 
	user to do it, but that would be more work...)
	Also simplify the code a little.

Index: util/info_to_mdb.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/info_to_mdb.c,v
retrieving revision 1.3
diff -u -r1.3 info_to_mdb.c
--- info_to_mdb.c	1999/03/25 10:42:57	1.3
+++ info_to_mdb.c	1999/03/25 11:50:13
@@ -25,7 +25,7 @@
 static	bool	is_empty(const char *line);
 static	bool	is_all_same_char(const char *line, const char what);
 static	bool	is_command(const char *line, bool *is_concept);
-static	bool	diff_command(const char *line, const char *command);
+static	void	get_command(const char *line, char *command);
 static	void	print_command_line(const char *line, bool is_concept);
 
 static	char	*get_next_line(FILE *infp);
@@ -41,10 +41,10 @@
 	char	*category;	/* mdb help category */
 	FILE	*infp;
 	char	*line;
+	int	num_lines;
 	char	command[MAXLINELEN];
+	char	next_command[MAXLINELEN];
 	int	slot = 0;
-	int	len;
-	int	i;
 	bool	is_concept;
 	bool	next_concept;
 
@@ -88,26 +88,43 @@
 		slot += 100;
 		printf("document %s %d ", category, slot);
 		if (is_concept) {
+			int	i;
 			for (i = 0; line[i] != '\n'; i++) {
 				command[i] = concept_char(line[i]);
-				putchar(concept_char(line[i]));
 			}
-			putchar('\n');
 			command[i] = '\0';
 		} else {
-			for (i = 1; MR_isalnumunder(line[i]); i++) {
-				command[i-1] = line[i];
-				putchar(line[i]);
-			}
-			putchar('\n');
-			command[i-1] = '\0';
+			get_command(line, command);
 		}
+		puts(command);
 
 		print_command_line(line, is_concept);
 
+		num_lines = 0; 
 		while ((line = get_next_line(infp)) != NULL) {
 			if (is_command(line, &next_concept)) {
-				if (diff_command(line, command)) {
+				get_command(line, next_command);
+				if (strcmp(command, next_command) != 0) {
+					/*
+					** Sometimes several commands
+					** are documented together, e.g.
+					**
+					** cmd1 args...
+					** cmd2 args...
+					** cmd3 args...
+					**	description...
+					**
+					** It's difficult for us to handle
+					** that case properly here, so we
+					** just insert cross references
+					** ("cmd1: see cmd2", "cmd2: see cmd3",
+					** etc.)
+					*/
+					if (num_lines == 0) {
+						printf("    See help for "
+							"`%s'.\n",
+							next_command);
+					}
 					put_line_back(line);
 					break;
 				} else {
@@ -116,6 +133,7 @@
 			} else {
 				printf("%s", line);
 			}
+			num_lines++;
 		}
 
 		printf("end\n");
@@ -171,19 +189,15 @@
 	}
 }
 
-static bool
-diff_command(const char *line, const char *command)
+static void
+get_command(const char *line, char *command)
 {
 	int	i;
 
-	for (i = 0; command[i] != '\0' && line[i + 1] == command[i]; i++)
-		;
-
-	if (command[i] == '\0' && ! MR_isalnumunder(line[i+1])) {
-		return FALSE;
-	} else {
-		return TRUE;
+	for (i = 0; MR_isalnumunder(line[i + 1]); i++) {
+		command[i] = line[i + 1];
 	}
+	command[i] = '\0';
 }
 
 static void

Here's a diff of the automatically-generated mdb_doc file:

--- mdb_doc.old	Thu Mar 25 21:38:25 1999
+++ mdb_doc	Thu Mar 25 22:51:18 1999
@@ -60,9 +60,11 @@
 end
 document queries 100 query
 query MODULE1 MODULE2 ...
+    See help for `cc_query'.
 end
 document queries 200 cc_query
 cc_query MODULE1 MODULE2 ...
+    See help for `io_query'.
 end
 document queries 300 io_query
 io_query MODULE1 MODULE2 ...

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list