I got this idea from here:
<http://www.gnu.org/software/hurd/microkernel/mach/gnumach/projects/
clean_up_the_code.html>

I don't know if this qualifies as a rewrite of db_expr.h; in my mind it 
does, so I removed the copyright; I don't know if that was a good idea. 
I completely removed calls to db_expression. I think it is a trivial 
function; it just complicates things. 

Also I noticed that the current build skips db_expr.h, so if that code 
is scheduled for removal, it doesn't matter, this patch was a good 
exercise in reading code.

Anyway, here's the ChangeLog and the patch:

2013-07-01 Marin Ramesa <marin.ram...@gmail.com>

* ddb/ddb_expr.h: Remove copyright notice, it's a rewrite.
Remove unneeded includes.
Remove obvious comment.
(db_expression): Remove prototype.
(db_logical_or_expr): New prototype.

* ddb/ddb_expr.c (db_expression): Remove trivial function.
(db_term): Call db_logical_or_expr instead of db_expression.

* ddb/db_break.c (db_delete_cmd): Call db_logical_or_expr instead of db_expression.

* ddb/db_command.c (db_command): Likewise.
(db_fncall): Likewise.

* ddb/db_cond.c (db_cond_check): Likewise.
(db_cond_cmd): Comment the new call.
Call db_logical_or_expr instead of db_expression.

* ddb/db_examine.c (db_print_cmd): Likewise.
(db_search_cmd): Likewise.

* ddb/db_macro.c (db_exec_macro): Likewise.

* ddb/db_task_thread.c (db_get_next_thread): Likewise.

* ddb/db_variables.c (db_set_cmd): Likewise.

* ddb/db_watch.c (db_get_task): Likewise.
(db_watchpoint_cmd): Likewise.

* ddb/db_write_cmd.c (db_write_cmd): Likewise.
diff -x ChangeLog -Nurp ../gnumach/ddb/db_break.c ../gnumach1/ddb/db_break.c
--- ../gnumach/ddb/db_break.c	2013-06-28 10:10:49.865024564 +0200
+++ ../gnumach1/ddb/db_break.c	2013-07-01 11:35:27.004536175 +0200
@@ -639,7 +639,7 @@ db_delete_cmd()
 	    return;
 	}
 	db_unread_token(t);
-	if (!db_expression(&addr)) {
+	if (!db_logical_or_expr(&addr)) {
 	    /*
 	     *	We attempt to pick up the user_space indication from db_dot,
 	     *	so that a plain "d" always works.
diff -x ChangeLog -Nurp ../gnumach/ddb/db_command.c ../gnumach1/ddb/db_command.c
--- ../gnumach/ddb/db_command.c	2013-06-28 10:10:49.865024564 +0200
+++ ../gnumach1/ddb/db_command.c	2013-07-01 11:39:09.475908208 +0200
@@ -231,7 +231,7 @@ db_command(last_cmdp, cmd_table)
 		    modif[0] = '\0';
 		}
 
-		if (db_expression(&addr)) {
+		if (db_logical_or_expr(&addr)) {
 		    db_dot = (db_addr_t) addr;
 		    db_last_addr = db_dot;
 		    have_addr = TRUE;
@@ -242,7 +242,7 @@ db_command(last_cmdp, cmd_table)
 		}
 		t = db_read_token();
 		if (t == tCOMMA) {
-		    if (!db_expression(&count)) {
+		    if (!db_logical_or_expr(&count)) {
 			db_printf("Count missing after ','\n");
 			db_flush_lex();
 			return;
@@ -512,7 +512,7 @@ db_fncall()
 	db_expr_t	(*func)();
 	int		t;
 
-	if (!db_expression(&fn_addr)) {
+	if (!db_logical_or_expr(&fn_addr)) {
 	    db_printf("Bad function \"%s\"\n", db_tok_string);
 	    db_flush_lex();
 	    return;
@@ -521,7 +521,7 @@ db_fncall()
 
 	t = db_read_token();
 	if (t == tLPAREN) {
-	    if (db_expression(&args[0])) {
+	    if (db_logical_or_expr(&args[0])) {
 		nargs++;
 		while ((t = db_read_token()) == tCOMMA) {
 		    if (nargs == MAXARGS) {
@@ -529,7 +529,7 @@ db_fncall()
 			db_flush_lex();
 			return;
 		    }
-		    if (!db_expression(&args[nargs])) {
+		    if (!db_logical_or_expr(&args[nargs])) {
 			db_printf("Argument missing\n");
 			db_flush_lex();
 			return;
diff -x ChangeLog -Nurp ../gnumach/ddb/db_cond.c ../gnumach1/ddb/db_cond.c
--- ../gnumach/ddb/db_cond.c	2013-06-28 10:10:49.865024564 +0200
+++ ../gnumach1/ddb/db_cond.c	2013-07-01 11:41:39.689527545 +0200
@@ -85,7 +85,7 @@ db_cond_check(bkpt)
 	 */
 	cp = &db_cond[bkpt->tb_cond - 1];
 	db_switch_input(cp->c_cond_cmd, cp->c_size);
-	if (!db_expression(&value)) {
+	if (!db_logical_or_expr(&value)) {
 	    db_printf("error: condition evaluation error\n");
 	    return(TRUE);
 	}
@@ -162,15 +162,15 @@ db_cond_cmd()
 	for (p = cp->c_cond_cmd; c >= 0; c = db_read_char())
 	    *p++ = c;
 	/*
-	 * switch to saved data and call db_expression to check the condition.
-	 * If no condition is supplied, db_expression will return false.
+	 * switch to saved data and call db_logical_or_expr to check the condition.
+	 * If no condition is supplied, db_logical_or_expr will return false.
 	 * In this case, clear previous condition of the break point.
          * If condition is supplied, set the condition to the permanent area.
-	 * Note: db_expression will not return here, if the condition
+	 * Note: db_logical_or_expr will not return here, if the condition
 	 *       expression is wrong.
 	 */
 	db_switch_input(cp->c_cond_cmd, p - cp->c_cond_cmd);
-	if (!db_expression(&value)) {
+	if (!db_logical_or_expr(&value)) {
 	    /* since condition is already freed, do nothing */
 	    db_flush_lex();
 	    return;
diff -x ChangeLog -Nurp ../gnumach/ddb/db_examine.c ../gnumach1/ddb/db_examine.c
--- ../gnumach/ddb/db_examine.c	2013-06-28 10:10:49.866024547 +0200
+++ ../gnumach1/ddb/db_examine.c	2013-07-01 11:46:41.146861540 +0200
@@ -286,7 +286,7 @@ db_print_cmd()
 		continue;
 	    }
 	    db_unread_token(t);
-	    if (!db_expression(&value))
+	    if (!db_logical_or_expr(&value))
 		break;
 	    switch (db_print_format) {
 	    case 'a':
@@ -395,24 +395,24 @@ db_search_cmd()
 	    size = sizeof(int);
 	}
 
-	if (!db_expression(&addr)) {
+	if (!db_logical_or_expr(&addr)) {
 	    db_printf("Address missing\n");
 	    db_flush_lex();
 	    return;
 	}
 
-	if (!db_expression(&value)) {
+	if (!db_logical_or_expr(&value)) {
 	    db_printf("Value missing\n");
 	    db_flush_lex();
 	    return;
 	}
 
-	if (!db_expression(&mask))
+	if (!db_logical_or_expr(&mask))
 	    mask = ~0;
 
 	t = db_read_token();
 	if (t == tCOMMA) {
-	    if (!db_expression(&count)) {
+	    if (!db_logical_or_expr(&count)) {
 		db_printf("Count missing\n");
 		db_flush_lex();
 		return;
diff -x ChangeLog -Nurp ../gnumach/ddb/db_expr.c ../gnumach1/ddb/db_expr.c
--- ../gnumach/ddb/db_expr.c	2013-06-28 10:10:49.866024547 +0200
+++ ../gnumach1/ddb/db_expr.c	2013-07-01 11:30:56.182719802 +0200
@@ -76,7 +76,7 @@ db_term(valuep)
 		return (FALSE);
 	    return (TRUE);
 	case tLPAREN:
-	    if (!db_expression(valuep)) {
+	    if (!db_logical_or_expr(valuep)) {
 		db_error("Unmached ()s\n");
 		/*NOTREACHED*/
 	    }
@@ -385,11 +385,4 @@ db_logical_or_expr(valuep)
 	return (TRUE);
 }
 
-int
-db_expression(valuep)
-	db_expr_t *valuep;
-{
-	return (db_logical_or_expr(valuep));
-}
-
 #endif /* MACH_KDB */
diff -x ChangeLog -Nurp ../gnumach/ddb/db_expr.h ../gnumach1/ddb/db_expr.h
--- ../gnumach/ddb/db_expr.h	2013-06-28 10:10:49.866024547 +0200
+++ ../gnumach1/ddb/db_expr.h	2013-07-01 11:47:42.441914114 +0200
@@ -1,26 +1,11 @@
-/*
- * (c) Copyright 1992, 1993, 1994, 1995 OPEN SOFTWARE FOUNDATION, INC. 
- * ALL RIGHTS RESERVED 
- */
-/*
- * OSF RI nmk19b2 5/2/95
- */
-
 #ifndef	_DDB_DB_EXPR_H_
 #define	_DDB_DB_EXPR_H_
 
-#include <mach/boolean.h>
-#include <machine/db_machdep.h>
-
-
-/* Prototypes for functions exported by this module.
- */
-
 int db_size_option(
 	char		*modif,
 	boolean_t	*u_option,
 	boolean_t	*t_option);
 
-int db_expression(db_expr_t *valuep);
+boolean_t db_logical_or_expr(db_expr_t *valuep);
 
 #endif	/* !_DDB_DB_EXPR_H_ */
diff -x ChangeLog -Nurp ../gnumach/ddb/db_macro.c ../gnumach1/ddb/db_macro.c
--- ../gnumach/ddb/db_macro.c	2013-06-28 10:10:49.867024531 +0200
+++ ../gnumach1/ddb/db_macro.c	2013-07-01 11:48:35.831088777 +0200
@@ -155,7 +155,7 @@ db_exec_macro(name)
 	}
 	for (n = 0;
 	     n < DB_NARGS &&
-	     db_expression(&db_macro_args[db_macro_level+1][n]);
+	     db_logical_or_expr(&db_macro_args[db_macro_level+1][n]);
 	     n++);
 	while (n < DB_NARGS)
 	    db_macro_args[db_macro_level+1][n++] = 0;
diff -x ChangeLog -Nurp ../gnumach/ddb/db_task_thread.c ../gnumach1/ddb/db_task_thread.c
--- ../gnumach/ddb/db_task_thread.c	2013-06-28 10:10:49.869024497 +0200
+++ ../gnumach1/ddb/db_task_thread.c	2013-07-01 11:50:28.951340095 +0200
@@ -212,7 +212,7 @@ db_get_next_thread(threadp, position)
 	thread_t	thread;
 
 	*threadp = THREAD_NULL;
-	if (db_expression(&value)) {
+	if (db_logical_or_expr(&value)) {
 	    thread = (thread_t) value;
 	    if (!db_check_thread_address_valid(thread)) {
 		db_flush_lex();
diff -x ChangeLog -Nurp ../gnumach/ddb/db_variables.c ../gnumach1/ddb/db_variables.c
--- ../gnumach/ddb/db_variables.c	2013-06-28 10:10:49.870024481 +0200
+++ ../gnumach1/ddb/db_variables.c	2013-07-01 11:50:56.160919434 +0200
@@ -229,7 +229,7 @@ db_set_cmd()
 	if (t != tEQ)
 	    db_unread_token(t);
 
-	if (!db_expression(&value)) {
+	if (!db_logical_or_expr(&value)) {
 	    db_error("No value\n");
 	    return;
 	}
diff -x ChangeLog -Nurp ../gnumach/ddb/db_watch.c ../gnumach1/ddb/db_watch.c
--- ../gnumach/ddb/db_watch.c	2013-06-28 10:10:49.870024481 +0200
+++ ../gnumach1/ddb/db_watch.c	2013-07-01 11:54:00.061076743 +0200
@@ -189,7 +189,7 @@ db_get_task(modif, taskp, addr)
 
 	user_space = db_option(modif, 'T');
 	if (user_space) {
-	    if (db_expression(&value)) {
+	    if (db_logical_or_expr(&value)) {
 		task = (task_t)value;
 		if (db_lookup_task(task) < 0) {
 		    db_printf("bad task address %X\n", task);
@@ -246,7 +246,7 @@ db_watchpoint_cmd(addr, have_addr, count
 
 	if (db_get_task(modif, &task, addr) < 0)
 	    return;
-	if (db_expression(&value))
+	if (db_logical_or_expr(&value))
 	    size = (vm_size_t) value;
 	else
 	    size = sizeof(int);
diff -x ChangeLog -Nurp ../gnumach/ddb/db_write_cmd.c ../gnumach1/ddb/db_write_cmd.c
--- ../gnumach/ddb/db_write_cmd.c	2013-06-28 10:10:49.870024481 +0200
+++ ../gnumach1/ddb/db_write_cmd.c	2013-07-01 11:52:57.126049649 +0200
@@ -88,7 +88,7 @@ db_write_cmd(address, have_addr, count,
 	  return;
 	}
 
-	while (db_expression(&new_value)) {
+	while (db_logical_or_expr(&new_value)) {
 	    old_value = db_get_task_value(addr, size, FALSE, task);
 	    db_task_printsym(addr, DB_STGY_ANY, task);
 	    db_printf("\t\t%#*N\t=\t%#*N\n",

Reply via email to