trivial diff: print a usage message instead of the help message

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Nov 13 16:05:19 AEDT 1998


trace/mercury_trace_internal.c:
	Print a usage message instead of the help message on user errors.

Zoltan.

cvs diff: Diffing .
Index: mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.10
diff -u -u -r1.10 mercury_trace_internal.c
--- mercury_trace_internal.c	1998/11/12 03:26:38	1.10
+++ mercury_trace_internal.c	1998/11/13 04:45:28
@@ -140,6 +140,7 @@
 			const char *cat, const char *item);
 static	bool	MR_trace_options_confirmed(bool *confirmed, char ***words,
 			int *word_count, const char *cat, const char *item);
+static	void	MR_trace_usage(const char *cat, const char *item);
 static	void	MR_trace_retry(const MR_Stack_Layout_Label *layout,
 			Word *saved_regs, MR_Event_Details *event_details,
 			int seqno, int depth, int *max_mr_num,
@@ -469,7 +470,7 @@
 			cmd->MR_trace_stop_event = MR_trace_event_number + n;
 			goto return_stop_interacting;
 		} else {
-			MR_trace_help_cat_item("forward", "step");
+			MR_trace_usage("forward", "step");
 		}
 	} else if (streq(words[0], "goto")) {
 		cmd->MR_trace_strict = TRUE;
@@ -489,7 +490,7 @@
 					"to a past event.\n");
 			}
 		} else {
-			MR_trace_help_cat_item("forward", "goto");
+			MR_trace_usage("forward", "goto");
 		}
 	} else if (streq(words[0], "finish")) {
 		int	stop_depth;
@@ -507,7 +508,7 @@
 		} else if (word_count == 1) {
 			stop_depth = depth;
 		} else {
-			MR_trace_help_cat_item("forward", "finish");
+			MR_trace_usage("forward", "finish");
 			goto return_keep_interacting;
 		}
 
@@ -533,7 +534,7 @@
 				printf("This command is a no-op from this port.\n");
 			}
 		} else {
-			MR_trace_help_cat_item("forward", "return");
+			MR_trace_usage("forward", "return");
 		}
 	} else if (streq(words[0], "forward")) {
 		cmd->MR_trace_strict = TRUE;
@@ -550,7 +551,7 @@
 				printf("This command is a no-op from this port.\n");
 			}
 		} else {
-			MR_trace_help_cat_item("forward", "forward");
+			MR_trace_usage("forward", "forward");
 		}
 	} else if (streq(words[0], "mindepth")) {
 		int	newdepth;
@@ -568,7 +569,7 @@
 			cmd->MR_trace_stop_depth = newdepth;
 			goto return_stop_interacting;
 		} else {
-			MR_trace_help_cat_item("forward", "mindepth");
+			MR_trace_usage("forward", "mindepth");
 		}
 	} else if (streq(words[0], "maxdepth")) {
 		int	newdepth;
@@ -586,7 +587,7 @@
 			cmd->MR_trace_stop_depth = newdepth;
 			goto return_stop_interacting;
 		} else {
-			MR_trace_help_cat_item("forward", "maxdepth");
+			MR_trace_usage("forward", "maxdepth");
 		}
 	} else if (streq(words[0], "continue")) {
 		cmd->MR_trace_strict = FALSE;
@@ -613,7 +614,7 @@
 			}
 			goto return_stop_interacting;
 		} else {
-			MR_trace_help_cat_item("forward", "continue");
+			MR_trace_usage("forward", "continue");
 		}
 	} else if (streq(words[0], "retry")) {
 		int	stop_depth;
@@ -623,7 +624,7 @@
 		} else if (word_count == 1) {
 			stop_depth = depth;
 		} else {
-			MR_trace_help_cat_item("backward", "retry");
+			MR_trace_usage("backward", "retry");
 			goto return_keep_interacting;
 		}
 
@@ -661,7 +662,7 @@
 				printf("%s.\n", problem);
 			}
 		} else {
-			MR_trace_help_cat_item("browsing", "level");
+			MR_trace_usage("browsing", "level");
 		}
 	} else if (streq(words[0], "up")) {
 		if (word_count == 2 && MR_trace_is_number(words[1], &n)) {
@@ -685,7 +686,7 @@
 				printf("%s.\n", problem);
 			}
 		} else {
-			MR_trace_help_cat_item("browsing", "up");
+			MR_trace_usage("browsing", "up");
 		}
 	} else if (streq(words[0], "down")) {
 		if (word_count == 2 && MR_trace_is_number(words[1], &n)) {
@@ -709,14 +710,14 @@
 				printf("%s.\n", problem);
 			}
 		} else {
-			MR_trace_help_cat_item("browsing", "down");
+			MR_trace_usage("browsing", "down");
 		}
 	} else if (streq(words[0], "vars")) {
 		if (word_count == 1) {
 			MR_trace_list_vars(layout, saved_regs,
 				*ancestor_level);
 		} else {
-			MR_trace_help_cat_item("browsing", "vars");
+			MR_trace_usage("browsing", "vars");
 		}
 	} else if (streq(words[0], "print")) {
 		if (word_count == 2) {
@@ -737,7 +738,7 @@
 					*ancestor_level, var_spec);
 			}
 		} else {
-			MR_trace_help_cat_item("browsing", "print");
+			MR_trace_usage("browsing", "print");
 		}
 	} else if (streq(words[0], "stack")) {
 		if (word_count == 1) {
@@ -752,14 +753,14 @@
 				printf("%s.\n", result);
 			}
 		} else {
-			MR_trace_help_cat_item("browsing", "stack");
+			MR_trace_usage("browsing", "stack");
 		}
 	} else if (streq(words[0], "current")) {
 		if (word_count == 1) {
 			MR_trace_event_print_internal_report(layout, port,
 				seqno, depth, path);
 		} else {
-			MR_trace_help_cat_item("browsing", "current");
+			MR_trace_usage("browsing", "current");
 		}
 	} else if (streq(words[0], "break")) {
 		MR_Proc_Spec	spec;
@@ -808,7 +809,7 @@
 				printf("There is no such procedure.\n");
 			}
 		} else {
-			MR_trace_help_cat_item("breakpoint", "break");
+			MR_trace_usage("breakpoint", "break");
 		}
 	} else if (streq(words[0], "enable")) {
 		if (word_count == 2 && MR_trace_is_number(words[1], &n)) {
@@ -828,7 +829,7 @@
 				printf("There no break points yet.\n");
 			}
 		} else {
-			MR_trace_help_cat_item("breakpoint", "enable");
+			MR_trace_usage("breakpoint", "enable");
 		}
 	} else if (streq(words[0], "disable")) {
 		if (word_count == 2 && MR_trace_is_number(words[1], &n)) {
@@ -848,7 +849,7 @@
 				printf("There no break points yet.\n");
 			}
 		} else {
-			MR_trace_help_cat_item("breakpoint", "disable");
+			MR_trace_usage("breakpoint", "disable");
 		}
 	} else if (streq(words[0], "register")) {
 		bool	verbose;
@@ -860,21 +861,21 @@
 		} else if (word_count == 1) {
 			MR_register_all_modules_and_procs(stdout, verbose);
 		} else {
-			MR_trace_help_cat_item("breakpoint", "register");
+			MR_trace_usage("breakpoint", "register");
 		}
 	} else if (streq(words[0], "modules")) {
 		if (word_count == 1) {
 			MR_register_all_modules_and_procs(stdout, TRUE);
 			MR_dump_module_list(stdout);
 		} else {
-			MR_trace_help_cat_item("breakpoint", "modules");
+			MR_trace_usage("breakpoint", "modules");
 		}
 	} else if (streq(words[0], "procedures")) {
 		if (word_count == 2) {
 			MR_register_all_modules_and_procs(stdout, TRUE);
 			MR_dump_module_procs(stdout, words[1]);
 		} else {
-			MR_trace_help_cat_item("breakpoint", "procedures");
+			MR_trace_usage("breakpoint", "procedures");
 		}
 	} else if (streq(words[0], "printlevel")) {
 		if (word_count == 2) {
@@ -897,7 +898,7 @@
 						"`all'.\n");
 				}
 			} else {
-				MR_trace_help_cat_item("parameter",
+				MR_trace_usage("parameter",
 					"printlevel");
 			}
 		} else if (word_count == 1) {
@@ -920,7 +921,7 @@
 					break;
 			}
 		} else {
-			MR_trace_help_cat_item("parameter", "printlevel");
+			MR_trace_usage("parameter", "printlevel");
 		}
 	} else if (streq(words[0], "scroll")) {
 		if (word_count == 2) {
@@ -941,7 +942,7 @@
 						"%d.\n", MR_scroll_limit);
 				}
 			} else {
-				MR_trace_help_cat_item("parameter", "scroll");
+				MR_trace_usage("parameter", "scroll");
 			}
 		} else if (word_count == 1) {
 			printf("Scroll control is ");
@@ -953,7 +954,7 @@
 			printf(", scroll window size is %d.\n",
 				MR_scroll_limit);
 		} else {
-			MR_trace_help_cat_item("parameter", "scroll");
+			MR_trace_usage("parameter", "scroll");
 		}
 	} else if (streq(words[0], "echo")) {
 		if (word_count == 2) {
@@ -968,7 +969,7 @@
 					printf("Command echo enabled.\n");
 				}
 			} else {
-				MR_trace_help_cat_item("parameter", "echo");
+				MR_trace_usage("parameter", "echo");
 			}
 		} else if (word_count == 1) {
 			printf("Command echo is ");
@@ -978,7 +979,7 @@
 				printf("off.\n");
 			}
 		} else {
-			MR_trace_help_cat_item("parameter", "echo");
+			MR_trace_usage("parameter", "echo");
 		}
 	} else if (streq(words[0], "alias")) {
 		if (word_count == 1) {
@@ -1010,7 +1011,7 @@
 					words[1]);
 			}
 		} else {
-			MR_trace_help_cat_item("parameter", "unalias");
+			MR_trace_usage("parameter", "unalias");
 		}
 	} else if (streq(words[0], "document_category")) {
 		int		slot;
@@ -1019,9 +1020,9 @@
 
 		help_text = MR_trace_read_help_text();
 		if (word_count != 3) {
-			MR_trace_help_cat_item("help", "document_category");
+			MR_trace_usage("help", "document_category");
 		} else if (! MR_trace_is_number(words[1], &slot)) {
-			MR_trace_help_cat_item("help", "document_category");
+			MR_trace_usage("help", "document_category");
 		} else {
 			msg = MR_trace_add_cat(words[2], slot, help_text);
 			if (msg != NULL) {
@@ -1036,9 +1037,9 @@
 
 		help_text = MR_trace_read_help_text();
 		if (word_count != 4) {
-			MR_trace_help_cat_item("help", "document");
+			MR_trace_usage("help", "document");
 		} else if (! MR_trace_is_number(words[2], &slot)) {
-			MR_trace_help_cat_item("help", "document");
+			MR_trace_usage("help", "document");
 		} else {
 			msg = MR_trace_add_item(words[1], words[3], slot,
 				help_text);
@@ -1056,7 +1057,7 @@
 		} else if (word_count == 3) {
 			MR_trace_help_cat_item(words[1], words[2]);
 		} else {
-			MR_trace_help_cat_item("help", "help");
+			MR_trace_usage("help", "help");
 		}
 #ifdef	MR_TRACE_HISTOGRAM
 	} else if (streq(words[0], "histogram_all")) {
@@ -1079,7 +1080,7 @@
 				}
 			}
 		} else {
-			MR_trace_help_cat_item("exp", "histogram_all");
+			MR_trace_usage("exp", "histogram_all");
 		}
 	} else if (streq(words[0], "histogram_exp")) {
 		if (word_count == 2) {
@@ -1101,7 +1102,7 @@
 				}
 			}
 		} else {
-			MR_trace_help_cat_item("exp", "histogram_exp");
+			MR_trace_usage("exp", "histogram_exp");
 		}
 	} else if (streq(words[0], "clear_histogram")) {
 		if (word_count == 1) {
@@ -1109,7 +1110,7 @@
 				MR_trace_histogram_exp[i] = 0;
 			}
 		} else {
-			MR_trace_help_cat_item("exp", "clear_histogram");
+			MR_trace_usage("exp", "clear_histogram");
 		}
 #endif	/* MR_TRACE_HISTOGRAM */
 	} else if (streq(words[0], "nondet_stack")) {
@@ -1118,7 +1119,7 @@
 			MR_dump_nondet_stack_from_layout(stdout,
 				MR_saved_maxfr(saved_regs));
 		} else {
-			MR_trace_help_cat_item("developer", "nondet_stack");
+			MR_trace_usage("developer", "nondet_stack");
 		}
 	} else if (streq(words[0], "stack_regs")) {
 		if (word_count == 1) {
@@ -1127,7 +1128,7 @@
 				MR_saved_curfr(saved_regs),
 				MR_saved_maxfr(saved_regs));
 		} else {
-			MR_trace_help_cat_item("developer", "stack_regs");
+			MR_trace_usage("developer", "stack_regs");
 		}
 	} else if (streq(words[0], "source")) {
 		if (word_count == 2) {
@@ -1137,7 +1138,7 @@
 			*/
 			(void) MR_trace_source(words[1]);
 		} else {
-			MR_trace_help_cat_item("misc", "source");
+			MR_trace_usage("misc", "source");
 		}
 	} else if (streq(words[0], "quit")) {
 		bool	confirmed;
@@ -1178,7 +1179,7 @@
 				exit(EXIT_SUCCESS);
 			}
 		} else {
-			MR_trace_help_cat_item("misc", "quit");
+			MR_trace_usage("misc", "quit");
 		}
 	} else {
 		printf("Unknown command `%s'. "
@@ -1239,7 +1240,7 @@
 				break;
 
 			default:
-				MR_trace_help_cat_item(cat, item);
+				MR_trace_usage(cat, item);
 				return FALSE;
 		}
 	}
@@ -1291,7 +1292,7 @@
 				break;
 
 			default:
-				MR_trace_help_cat_item(cat, item);
+				MR_trace_usage(cat, item);
 				return FALSE;
 		}
 	}
@@ -1322,7 +1323,7 @@
 				break;
 
 			default:
-				MR_trace_help_cat_item(cat, item);
+				MR_trace_usage(cat, item);
 				return FALSE;
 		}
 	}
@@ -1359,7 +1360,7 @@
 				break;
 
 			default:
-				MR_trace_help_cat_item(cat, item);
+				MR_trace_usage(cat, item);
 				return FALSE;
 		}
 	}
@@ -1367,6 +1368,15 @@
 	*words = *words + MR_optind - 1;
 	*word_count = *word_count - MR_optind + 1;
 	return TRUE;
+}
+
+static void
+MR_trace_usage(const char *cat, const char *item)
+/* cat is unused now, but could be used later */
+{
+
+	printf("mdb: %s: usage error -- type `help %s' for help.\n",
+		item, item);
 }
 
 static void



More information about the developers mailing list