[mw-devel] MW3 r1113 - trunk/src

arthur at sucs.org arthur at sucs.org
Thu Nov 26 15:12:32 GMT 2009


Author: arthur
Date: 2009-11-26 15:12:32 +0000 (Thu, 26 Nov 2009)
New Revision: 1113

Modified:
   trunk/src/expand.c
   trunk/src/hash.c
Log:
fix some of the sparse warnings


Modified: trunk/src/expand.c
===================================================================
--- trunk/src/expand.c	2009-11-26 13:50:17 UTC (rev 1112)
+++ trunk/src/expand.c	2009-11-26 15:12:32 UTC (rev 1113)
@@ -15,11 +15,11 @@
 
 #define SHOWSTATE() /* printf("%-20s%20s\n", exp_buf.start, in) */
 
-static struct expand_buf exp_buf = {0,0,0};
+static struct expand_buf exp_buf = {NULL,NULL,0};
 static var_op_t exp_var;
-static char *var_key = 0;
+static char *var_key = NULL;
 
-static void expand_init();
+static void expand_init(void);
 static void ensure_capacity(int cap);
 static void append_chars(const char *str, int len);
 static void append_string(const char *str);
@@ -33,7 +33,7 @@
 static const char *eval_expr(const char *in);
 static void argv_squish(int offset);
 
-static void expand_init()
+static void expand_init(void)
 {
     exp_buf.pos = exp_buf.start;
     ensure_capacity(0);
@@ -52,7 +52,7 @@
     if (expand_arg(arg, EA_BRACE|EA_BRACKET|EA_PAREN))
 	return exp_buf.start;
     else
-	return 0;
+	return NULL;
 }
 
 int eval_var(char *name, var_op_t *op)
@@ -189,7 +189,7 @@
 	    case '[':
 		/*printf("Encountered '['; Expanding arithmetic expression\n");*/
 		in = expand_infix(++in); /* Quoted variable name */
-		if (!in) return 0; /* Parse error */
+		if (!in) return NULL; /* Parse error */
 		if (*in) /* Allow omitting ']' at the end of an expression */
 		{
 		    if (*in == ']') ++in; /* Skip over ']' */
@@ -197,14 +197,14 @@
 		    {
 			SHOWSTATE();
 			/*printf("ERROR: ']' expected\n");*/
-			return 0; /* Parse error */
+			return NULL; /* Parse error */
 		    }
 		}
 		break;
 	    case '|': /* Shortcut for 'strlen' or array size */
 		ensure_capacity(30); /* Make room for the number */
 		in = expand_variable(++in);
-		if (!in) return(0);
+		if (!in) return(NULL);
 		if (VAR_TYPE_STR(&exp_var) || VAR_TYPE_INT(&exp_var))
 		{
 		    /*printf("Inserting string length\n");*/
@@ -229,7 +229,7 @@
 		break;
 	    default:
 		in = expand_variable(in);
-		if (!in) return 0;
+		if (!in) return NULL;
 		/* We should have a string now */
 		if (VAR_TYPE_STR(&exp_var) || VAR_TYPE_INT(&exp_var))
 		    append_string(var_str_val(&exp_var));
@@ -271,7 +271,7 @@
 	    {
 		SHOWSTATE();
 		/*printf("ERROR: '}' expected\n");*/
-		return 0; /* Parse error */
+		return NULL; /* Parse error */
 	    }
 	}
 	break;
@@ -306,7 +306,7 @@
 	    {
 		SHOWSTATE();
 		/*printf("ERROR: ']' expected\n");*/
-		return 0; /* Parse error */
+		return NULL; /* Parse error */
 	    }
 	}
     }
@@ -347,7 +347,7 @@
         int len = strlen(in);
 	if (len>10) len=10;
 	snprintf(parse_error, 79, "Expected identifer, found \"%*s\"", len, in);
-        return 0;
+        return NULL;
     } else
     {
 	/*printf("Looking up key: %s.\n", name_start);*/
@@ -369,12 +369,12 @@
     saved_op = exp_var;
     saved_key = var_key;
     name_start = exp_buf.pos;
-    var_key = 0;
+    var_key = NULL;
     in = expand_arg(in, EA_BRACKET|EA_PAREN);
     if (var_key) free(var_key);
     var_key = saved_key;
     exp_var = saved_op;
-    if (!in) return 0; /* Propagate parse errors */
+    if (!in) return NULL; /* Propagate parse errors */
     /* We have an identifier; look it up in the variable list */
     do_lookup(name_start, exp_buf.pos);
     SHOWSTATE();
@@ -406,12 +406,12 @@
     saved_op = exp_var;
     saved_key = var_key;
     name_start = exp_buf.pos;
-    var_key = 0;
+    var_key = NULL;
     in = expand_arg(in, EA_BRACE|EA_PAREN);
     if (var_key) free(var_key);
     var_key = saved_key;
     exp_var = saved_op;
-    if (!in) return 0; /* Propagate parse errors */
+    if (!in) return NULL; /* Propagate parse errors */
 
     /* We have a key; look it up in the array */
     if (var_key) free(var_key);
@@ -594,7 +594,7 @@
     }
 }
 
-static int push_paren()
+static int push_paren(void)
 {
     if (complete)
     {
@@ -622,7 +622,7 @@
     expr_start = exp_buf.pos;
     saved_op = exp_var;
     saved_key = var_key;
-    var_key = 0;
+    var_key = NULL;
     saved_limit = stack_limit;
     stack_limit = opcount;
     in = expand_arg(in, EA_PAREN|EA_BRACE);
@@ -631,7 +631,7 @@
     if (var_key) free(var_key);
     var_key = saved_key;
     exp_var = saved_op;
-    if (!in) return 0; /* Propagate parse errors */
+    if (!in) return NULL; /* Propagate parse errors */
 
     /* We have an expression; Copy and evaluate it */
     SHOWSTATE();
@@ -643,7 +643,7 @@
     if (!eval_expr(expr_text))
     { /* Error in expression */
 	free(expr_text);
-	return 0;
+	return NULL;
     }
     SHOWSTATE();
     /*printf("Leaving expand_infix()\n");*/
@@ -664,11 +664,11 @@
 	{
 	    /* Parse & push a number */
 	    if (!push_num(strtol(in, (char **)&in, 0)))
-	        return 0; /* Parse error */
+	        return NULL; /* Parse error */
 	} else if (isalpha(*in) || *in == '{')
 	{
 	    /* Parse & push a variable. */
-	    if ((in = expand_variable(in)) != 0)
+	    if ((in = expand_variable(in)) != NULL)
 	    {
 		/*printf("Checking variable '%s'.\n", VAR_STR_KEY(&exp_var));*/
 	        if (var_isanum(&exp_var, &num, 0))
@@ -683,12 +683,12 @@
 			    snprintf(parse_error, 79, "Value '%s' of variable '%s' is not a number", var_str_val(&exp_var), VAR_STR_KEY(&exp_var));
 		    else
 			    snprintf(parse_error, 79, "Variable '%s' not found", var_key);
-		    return 0; /* Not a number */
+		    return NULL; /* Not a number */
 		}
 	    } else
 	    {
 		snprintf(parse_error, 79, "expand_variable() failed");
-		return 0; /* Parse error */
+		return NULL; /* Parse error */
 	    }
 	} else if (isspace(*in))
 	{
@@ -696,7 +696,7 @@
 	} else switch (*in++)
 	{
 	case '(':
-	    if (push_paren()) break; else return 0;
+	    if (push_paren()) break; else return NULL;
 	case ')':
 	    if (push_op(op_paren)) 
 	    {
@@ -705,43 +705,43 @@
 	    } else
 	    {
 	        /*printf("Push of ')' failed!\n");*/
-	       return 0;
+	       return NULL;
 	    }
 	case '~': /* ~ is always unary */
-	    if (push_op(op_notb)) break; else return 0;
+	    if (push_op(op_notb)) break; else return NULL;
 	case '+': /* + and - have unary and binary variants */
 	    if (complete)
 	    {
 	        if (!push_op(op_plus))
-		    return 0;
+		    return NULL;
 	    } else
 	        if (!push_op(op_uplus))
-		    return 0;
+		    return NULL;
 	    break;
 	case '-':
 	    if (complete)
 	    {
 	        if (!push_op(op_minus))
-		    return 0;
+		    return NULL;
 	    } else
 	        if (!push_op(op_uminus))
-		    return 0;
+		    return NULL;
 	    break;
 	case '*': /* Others are always binary */
-	    if (push_op(op_times)) break; else return 0;
+	    if (push_op(op_times)) break; else return NULL;
 	case '/':
-	    if (push_op(op_div)) break; else return 0;
+	    if (push_op(op_div)) break; else return NULL;
 	case '%':
-	    if (push_op(op_mod)) break; else return 0;
+	    if (push_op(op_mod)) break; else return NULL;
 	case '^':
-	    if (push_op(op_xorb)) break; else return 0;
+	    if (push_op(op_xorb)) break; else return NULL;
 	case '&':
-	    if (push_op(op_andb)) break; else return 0;
+	    if (push_op(op_andb)) break; else return NULL;
 	case '|':
-	    if (push_op(op_orb)) break; else return 0;
+	    if (push_op(op_orb)) break; else return NULL;
 	default:
 	    snprintf(parse_error, 79, "Unexpected char in expression: \"%-12s...\"", --in);
-	    return 0; /* Parse error */
+	    return NULL; /* Parse error */
 	}
     }
 
@@ -756,6 +756,6 @@
 	/* Stop errors affecting later expansions */
 	opcount = numcount = stack_limit = 0;
 	snprintf(parse_error, 79, "Unexpected end of expression");
-        return 0;
+        return NULL;
     }
 }

Modified: trunk/src/hash.c
===================================================================
--- trunk/src/hash.c	2009-11-26 13:50:17 UTC (rev 1112)
+++ trunk/src/hash.c	2009-11-26 15:12:32 UTC (rev 1113)
@@ -13,7 +13,7 @@
 #define INITIALBUCKETS 256
 #define INITIALFIELDS 64
 
-bucket_t *buckets;
+static bucket_t *buckets;
 union fieldrec *fields;
 static int capacity;
 static int maxfields; /* Size of the allocated array */
@@ -26,9 +26,9 @@
 static struct hashrec *hash_enter(const hash_op_t *op);
 
 /*static struct hashrec *freerecs = 0;*/
-static union fieldrec *freefields = 0;
+static union fieldrec *freefields = NULL;
 
-void hash_setup()
+void hash_setup(void)
 {
     maxfields = INITIALFIELDS;
     fields = calloc(maxfields , sizeof(*fields));
@@ -37,13 +37,13 @@
     buckets = calloc(capacity, sizeof(*buckets));
 }
 
-void hash_shutdown()
+void hash_shutdown(void)
 {
     free(buckets);
     free(fields);
 }
 
-int hash_alloc()
+int hash_alloc(void)
 {
     int newfield;
 
@@ -81,8 +81,8 @@
 
 void hash_op_init (hash_op_t *op, int field)
 {
-    op->key = 0;
-    op->rec = 0;
+    op->key = NULL;
+    op->rec = NULL;
     op->field = field;
 }
 
@@ -99,15 +99,15 @@
     while (*rec && (cmp=reccmp(*rec, field, key)) != 0)
 	rec = &(**rec).bnext;
     op->rec = rec;
-    return (*rec != 0);
+    return (*rec != NULL);
 }
 
 void hash_op_forgetkey(hash_op_t *op)
 {
-    op->key = 0;
+    op->key = NULL;
 }
 
-int hash_search_quick(hash_op_t *op, const char *key, struct hashrec *target)
+static int hash_search_quick(hash_op_t *op, const char *key, struct hashrec *target)
 {
     static struct hashrec **rec;
     static int field;
@@ -118,7 +118,7 @@
     while (*rec && *rec != target)
 	rec = &(**rec).bnext;
     op->rec = rec;
-    return (*rec != 0);
+    return (*rec != NULL);
 }
 
 void hash_iterate(struct hashrec ***iter, int field)




More information about the mw-devel mailing list