avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mas...@apache.org
Subject svn commit: r901421 [3/3] - in /hadoop/avro/trunk: ./ lang/c/ lang/c/src/ lang/c/tests/
Date Wed, 20 Jan 2010 22:58:23 GMT
Modified: hadoop/avro/trunk/lang/c/src/schema_printf.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/schema_printf.c?rev=901421&r1=901420&r2=901421&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/schema_printf.c (original)
+++ hadoop/avro/trunk/lang/c/src/schema_printf.c Wed Jan 20 22:58:22 2010
@@ -1,222 +1,177 @@
 /*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License. 
+ */
 
 #include "schema.h"
 #include "datum.h"
 
-struct avro_schema_args_t
-{
-  int depth;
-  FILE *fp;
+struct avro_schema_args_t {
+	int depth;
+	FILE *fp;
 };
 
-static void
-avro_schema_printf_internal (avro_schema_t schema,
-			     struct avro_schema_args_t *args);
+static void avro_schema_printf_internal(avro_schema_t schema, struct avro_schema_args_t
+					*args);
 
-static void
-avro_schema_printf_indent (struct avro_schema_args_t *args)
+static void avro_schema_printf_indent(struct avro_schema_args_t *args)
 {
-  int i;
-  for (i = 0; i < args->depth; i++)
-    {
-      fprintf (args->fp, "  ");
-    }
+	int i;
+	for (i = 0; i < args->depth; i++) {
+		fprintf(args->fp, "  ");
+	}
 }
 
 static void
-avro_schema_union_print (struct avro_union_schema_t *unionp,
-			 struct avro_schema_args_t *args)
+avro_schema_union_print(struct avro_union_schema_t *unionp,
+			struct avro_schema_args_t *args)
 {
-  fprintf (args->fp, "union");
+	fprintf(args->fp, "union");
 }
 
 static void
-avro_schema_array_print (struct avro_array_schema_t *array,
-			 struct avro_schema_args_t *args)
+avro_schema_array_print(struct avro_array_schema_t *array,
+			struct avro_schema_args_t *args)
 {
-  avro_schema_printf_indent (args);
-  fprintf (args->fp, "array\n");
-  args->depth++;
-  avro_schema_printf_internal (array->items, args);
-  args->depth--;
+	avro_schema_printf_indent(args);
+	fprintf(args->fp, "array\n");
+	args->depth++;
+	avro_schema_printf_internal(array->items, args);
+	args->depth--;
 }
 
 static void
-avro_schema_map_print (struct avro_map_schema_t *map,
-		       struct avro_schema_args_t *args)
+avro_schema_map_print(struct avro_map_schema_t *map,
+		      struct avro_schema_args_t *args)
 {
-  avro_schema_printf_indent (args);
-  fprintf (args->fp, "map\n");
-  args->depth++;
-  avro_schema_printf_internal (map->values, args);
-  args->depth--;
+	avro_schema_printf_indent(args);
+	fprintf(args->fp, "map\n");
+	args->depth++;
+	avro_schema_printf_internal(map->values, args);
+	args->depth--;
 }
 
 static void
-avro_schema_fixed_print (struct avro_fixed_schema_t *fixed,
-			 struct avro_schema_args_t *args)
+avro_schema_fixed_print(struct avro_fixed_schema_t *fixed,
+			struct avro_schema_args_t *args)
 {
-  fprintf (args->fp, "fixed \"%s\" size=%ld", fixed->name, fixed->size);
+	fprintf(args->fp, "fixed \"%s\" size=%ld", fixed->name, fixed->size);
 }
 
 static void
-avro_schema_enum_print (struct avro_enum_schema_t *enump,
-			struct avro_schema_args_t *args)
+avro_schema_enum_print(struct avro_enum_schema_t *enump,
+		       struct avro_schema_args_t *args)
 {
-  fprintf (args->fp, "enum \"%s\"", enump->name);
+	fprintf(args->fp, "enum \"%s\"", enump->name);
 }
 
 static void
-avro_schema_record_field_print (struct avro_record_field_t *field,
-				struct avro_schema_args_t *args)
+avro_schema_record_field_print(struct avro_record_field_t *field,
+			       struct avro_schema_args_t *args)
 {
-  avro_schema_printf_indent (args);
-  fprintf (args->fp, "field \"%s\"\n", field->name);
-  args->depth++;
-  avro_schema_printf_internal (field->type, args);
-  args->depth--;
+	avro_schema_printf_indent(args);
+	fprintf(args->fp, "field \"%s\"\n", field->name);
+	args->depth++;
+	avro_schema_printf_internal(field->type, args);
+	args->depth--;
 }
 
 static void
-avro_schema_record_print (struct avro_record_schema_t *record,
-			  struct avro_schema_args_t *args)
+avro_schema_record_print(struct avro_record_schema_t *record,
+			 struct avro_schema_args_t *args)
 {
-  struct avro_record_field_t *field;
-  avro_schema_printf_indent (args);
-  fprintf (args->fp, "record \"%s\"\n", record->name);
-  args->depth++;
-  for (field = STAILQ_FIRST (&record->fields);
-       field != NULL; field = STAILQ_NEXT (field, fields))
-    {
-      avro_schema_record_field_print (field, args);
-    }
-  args->depth--;
+	struct avro_record_field_t *field;
+	avro_schema_printf_indent(args);
+	fprintf(args->fp, "record \"%s\"\n", record->name);
+	args->depth++;
+	for (field = STAILQ_FIRST(&record->fields);
+	     field != NULL; field = STAILQ_NEXT(field, fields)) {
+		avro_schema_record_field_print(field, args);
+	}
+	args->depth--;
+}
+
+const char *avro_schema_name(const avro_schema_t schema)
+{
+	if (is_avro_record(schema)) {
+		return (avro_schema_to_record(schema))->name;
+	} else if (is_avro_enum(schema)) {
+		return (avro_schema_to_enum(schema))->name;
+	} else if (is_avro_fixed(schema)) {
+		return (avro_schema_to_fixed(schema))->name;
+	}
+	return NULL;
 }
 
-const char *
-avro_schema_name (const avro_schema_t schema)
+static void
+avro_schema_link_print(const struct avro_link_schema_t *link,
+		       struct avro_schema_args_t *args)
 {
-  if (is_avro_record (schema))
-    {
-      return (avro_schema_to_record (schema))->name;
-    }
-  else if (is_avro_enum (schema))
-    {
-      return (avro_schema_to_enum (schema))->name;
-    }
-  else if (is_avro_fixed (schema))
-    {
-      return (avro_schema_to_fixed (schema))->name;
-    }
-  return NULL;
+	avro_schema_printf_indent(args);
+	fprintf(args->fp, "linkto \"%s\"\n", avro_schema_name(link->to));
 }
 
 static void
-avro_schema_link_print (const struct avro_link_schema_t *link,
-			struct avro_schema_args_t *args)
+avro_schema_primitive_print(const char *type, struct avro_schema_args_t *args)
 {
-  avro_schema_printf_indent (args);
-  fprintf (args->fp, "linkto \"%s\"\n", avro_schema_name (link->to));
+	avro_schema_printf_indent(args);
+	fprintf(args->fp, "primitive %s\n", type);
 }
 
 static void
-avro_schema_primitive_print (const char *type,
-			     struct avro_schema_args_t *args)
-{
-  avro_schema_printf_indent (args);
-  fprintf (args->fp, "primitive %s\n", type);
-}
-
-static void
-avro_schema_printf_internal (avro_schema_t schema,
-			     struct avro_schema_args_t *args)
-{
-  if (is_avro_link (schema))
-    {
-      avro_schema_link_print (avro_schema_to_link (schema), args);
-    }
-  else if (is_avro_record (schema))
-    {
-      avro_schema_record_print (avro_schema_to_record (schema), args);
-    }
-  else if (is_avro_enum (schema))
-    {
-      avro_schema_enum_print (avro_schema_to_enum (schema), args);
-    }
-  else if (is_avro_fixed (schema))
-    {
-      avro_schema_fixed_print (avro_schema_to_fixed (schema), args);
-    }
-  else if (is_avro_map (schema))
-    {
-      avro_schema_map_print (avro_schema_to_map (schema), args);
-    }
-  else if (is_avro_array (schema))
-    {
-      avro_schema_array_print (avro_schema_to_array (schema), args);
-    }
-  else if (is_avro_union (schema))
-    {
-      avro_schema_union_print (avro_schema_to_union (schema), args);
-    }
-  else if (is_avro_string (schema))
-    {
-      avro_schema_primitive_print ("string", args);
-    }
-  else if (is_avro_bytes (schema))
-    {
-      avro_schema_primitive_print ("bytes", args);
-    }
-  else if (is_avro_int (schema))
-    {
-      avro_schema_primitive_print ("int", args);
-    }
-  else if (is_avro_long (schema))
-    {
-      avro_schema_primitive_print ("long", args);
-    }
-  else if (is_avro_float (schema))
-    {
-      avro_schema_primitive_print ("float", args);
-    }
-  else if (is_avro_double (schema))
-    {
-      avro_schema_primitive_print ("double", args);
-    }
-  else if (is_avro_boolean (schema))
-    {
-      avro_schema_primitive_print ("boolean", args);
-    }
-  else if (is_avro_null (schema))
-    {
-      avro_schema_primitive_print ("null", args);
-    }
-}
-
-void
-avro_schema_printf (avro_schema_t schema, FILE * fp)
-{
-  struct avro_schema_args_t args = {.depth = 0,.fp = fp };
-  if (fp)
-    {
-      avro_schema_printf_internal (schema, &args);
-      fprintf (fp, "\n");
-    }
+avro_schema_printf_internal(avro_schema_t schema,
+			    struct avro_schema_args_t *args)
+{
+	if (is_avro_link(schema)) {
+		avro_schema_link_print(avro_schema_to_link(schema), args);
+	} else if (is_avro_record(schema)) {
+		avro_schema_record_print(avro_schema_to_record(schema), args);
+	} else if (is_avro_enum(schema)) {
+		avro_schema_enum_print(avro_schema_to_enum(schema), args);
+	} else if (is_avro_fixed(schema)) {
+		avro_schema_fixed_print(avro_schema_to_fixed(schema), args);
+	} else if (is_avro_map(schema)) {
+		avro_schema_map_print(avro_schema_to_map(schema), args);
+	} else if (is_avro_array(schema)) {
+		avro_schema_array_print(avro_schema_to_array(schema), args);
+	} else if (is_avro_union(schema)) {
+		avro_schema_union_print(avro_schema_to_union(schema), args);
+	} else if (is_avro_string(schema)) {
+		avro_schema_primitive_print("string", args);
+	} else if (is_avro_bytes(schema)) {
+		avro_schema_primitive_print("bytes", args);
+	} else if (is_avro_int(schema)) {
+		avro_schema_primitive_print("int", args);
+	} else if (is_avro_long(schema)) {
+		avro_schema_primitive_print("long", args);
+	} else if (is_avro_float(schema)) {
+		avro_schema_primitive_print("float", args);
+	} else if (is_avro_double(schema)) {
+		avro_schema_primitive_print("double", args);
+	} else if (is_avro_boolean(schema)) {
+		avro_schema_primitive_print("boolean", args);
+	} else if (is_avro_null(schema)) {
+		avro_schema_primitive_print("null", args);
+	}
+}
+
+void avro_schema_printf(avro_schema_t schema, FILE * fp)
+{
+	struct avro_schema_args_t args = {.depth = 0,.fp = fp };
+	if (fp) {
+		avro_schema_printf_internal(schema, &args);
+		fprintf(fp, "\n");
+	}
 }

Modified: hadoop/avro/trunk/lang/c/src/schema_specific.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/schema_specific.c?rev=901421&r1=901420&r2=901421&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/schema_specific.c (original)
+++ hadoop/avro/trunk/lang/c/src/schema_specific.c Wed Jan 20 22:58:22 2010
@@ -1,21 +1,19 @@
 /*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License. 
+ */
 
 #include <stdio.h>
 #include <errno.h>
@@ -23,226 +21,210 @@
 #include "avro.h"
 #include "schema.h"
 
-enum specific_state
-{
-  START_STATE,
+enum specific_state {
+	START_STATE,
 };
 typedef enum specific_state specific_state;
 
-struct specific_ctx
-{
-  FILE *header;
-  FILE *source;
-  int depth;
-  specific_state state;
+struct specific_ctx {
+	FILE *header;
+	FILE *source;
+	int depth;
+	specific_state state;
 };
 typedef struct specific_ctx specific_ctx;
 
-static void
-indent (specific_ctx * ctx, FILE * fp)
+static void indent(specific_ctx * ctx, FILE * fp)
 {
-  int i;
-  for (i = 0; i < ctx->depth; i++)
-    {
-      fprintf (fp, "   ");
-    }
+	int i;
+	for (i = 0; i < ctx->depth; i++) {
+		fprintf(fp, "   ");
+	}
 }
 
-static int
-avro_schema_to_source (avro_schema_t schema, specific_ctx * ctx)
+static int avro_schema_to_source(avro_schema_t schema, specific_ctx * ctx)
 {
-  switch (schema->type)
-    {
-    default:
-      return 0;
-    }
-  return EINVAL;
+	switch (schema->type) {
+	default:
+		return 0;
+	}
+	return EINVAL;
 }
 
-static int
-avro_schema_to_header (avro_schema_t schema, specific_ctx * ctx)
+static int avro_schema_to_header(avro_schema_t schema, specific_ctx * ctx)
 {
-  size_t i;
-  FILE *fp = ctx->header;
-
-  indent (ctx, fp);
-  ctx->depth++;
+	size_t i;
+	FILE *fp = ctx->header;
 
-  if (is_avro_primitive (schema) && !ctx->name)
-    {
-      return 0;
-    }
-
-  switch (schema->type)
-    {
-    case AVRO_STRING:
-      fprintf (fp, "char *%s;\n", ctx->name);
-      break;
-
-    case AVRO_BYTES:
-      fprintf (fp, "struct %s { size_t %s_len; char *%s_val } %s;\n",
-	       ctx->name, ctx->name, ctx->name, ctx->name);
-      break;
-
-    case AVRO_INT:
-      fprintf (fp, "int %s;\n", ctx->name);
-      break;
-
-    case AVRO_LONG:
-      fprintf (fp, "long %s;\n", ctx->name);
-      break;
-
-    case AVRO_FLOAT:
-      fprintf (fp, "float %s;\n", ctx->name);
-      break;
-
-    case AVRO_DOUBLE:
-      fprintf (fp, "double %s;\n", ctx->name);
-      break;
-
-    case AVRO_BOOLEAN:
-      fprintf (fp, "int %s; /* boolean */\n", ctx->name);
-      break;
-
-    case AVRO_NULL:
-      break;
-
-    case AVRO_RECORD:
-      {
-	struct schema_record_t *record_schema =
-	  avro_schema_to_record (schema);
-	fprintf (fp, "struct %s {\n", record_schema->name);
-	for (i = 0; i < record_schema->num_fields; i++)
-	  {
-	    struct record_field_t *field = record_schema->fields[i];
-	    ctx->name = field->name;
-	    avro_schema_to_header (field->type, ctx);
-	    ctx->name = NULL;
-	  }
-	fprintf (fp, "};\n");
-	fprintf (fp, "typedef struct %s %s;\n\n", record_schema->name,
-		 record_schema->name);
-      }
-      break;
-
-    case AVRO_ENUM:
-      {
-	struct schema_enum_t *enum_schema = avro_schema_to_enum (schema);
-	fprintf (fp, "enum %s {\n", enum_schema->name);
+	indent(ctx, fp);
 	ctx->depth++;
-	for (i = 0; i < enum_schema->num_symbols; i++)
-	  {
-	    indent (ctx, fp);
-	    fprintf (fp, "%s = %ld,\n", enum_schema->symbols[i], i);
-	  }
-	ctx->depth--;
-	fprintf (fp, "};\n");
-	fprintf (fp, "typedef enum %s %s;\n\n", enum_schema->name,
-		 enum_schema->name);
-      }
-      break;
-
-    case AVRO_FIXED:
-      {
-	struct schema_fixed_t *fixed_schema = avro_schema_to_fixed (schema);
-	fprintf (fp, "char %s[%ld];\n", fixed_schema->name,
-		 fixed_schema->size);
-      }
-      break;
-
-    case AVRO_MAP:
-      {
-
-
-      }
-      break;
-
-    case AVRO_ARRAY:
-      {
-	struct schema_array_t *array_schema = avro_schema_to_array (schema);
-	if (!ctx->name)
-	  {
-	    break;
-	  }
-	fprintf (fp, "struct { size_t %s_len; ", ctx->name);
-	if (is_avro_named_type (array_schema->items))
-	  {
-	    fprintf (fp, "%s", avro_schema_name (array_schema->items));
-	  }
-	else if (is_avro_link (array_schema->items))
-	  {
-	    struct schema_link_t *link_schema =
-	      avro_schema_to_link (array_schema->items);
-	    fprintf (fp, "struct %s", avro_schema_name (link_schema->to));
-	  }
-	else
-	  {
-	    avro_schema_to_header (array_schema->items, ctx);
-	  }
-	fprintf (fp, " *%s_val;} %s;\n", ctx->name, ctx->name);
-      }
-      break;
-    case AVRO_UNION:
-      {
-	struct schema_union_t *union_schema = avro_schema_to_array (schema);
-	if (!ctx->name)
-	  {
-	    break;
-	  }
-	fprintf (fp, "union {\n");
-	for (i = 0; i < union_schema->num_schemas; i++)
-	  {
-	    avro_schema_to_header (union_schema->schemas[i], ctx);
-	  }
-	fprintf (fp, "%s_u;\n");
-      }
-      break;
-    case AVRO_LINK:
-      break;
-    default:
-      return EINVAL;
-    }
 
-  ctx->depth--;
-  return 0;
+	if (is_avro_primitive(schema) && !ctx->name) {
+		return 0;
+	}
+
+	switch (schema->type) {
+	case AVRO_STRING:
+		fprintf(fp, "char *%s;\n", ctx->name);
+		break;
+
+	case AVRO_BYTES:
+		fprintf(fp, "struct %s { size_t %s_len; char *%s_val } %s;\n",
+			ctx->name, ctx->name, ctx->name, ctx->name);
+		break;
+
+	case AVRO_INT:
+		fprintf(fp, "int %s;\n", ctx->name);
+		break;
+
+	case AVRO_LONG:
+		fprintf(fp, "long %s;\n", ctx->name);
+		break;
+
+	case AVRO_FLOAT:
+		fprintf(fp, "float %s;\n", ctx->name);
+		break;
+
+	case AVRO_DOUBLE:
+		fprintf(fp, "double %s;\n", ctx->name);
+		break;
+
+	case AVRO_BOOLEAN:
+		fprintf(fp, "int %s; /* boolean */\n", ctx->name);
+		break;
+
+	case AVRO_NULL:
+		break;
+
+	case AVRO_RECORD:
+		{
+			struct schema_record_t *record_schema =
+			    avro_schema_to_record(schema);
+			fprintf(fp, "struct %s {\n", record_schema->name);
+			for (i = 0; i < record_schema->num_fields; i++) {
+				struct record_field_t *field =
+				    record_schema->fields[i];
+				ctx->name = field->name;
+				avro_schema_to_header(field->type, ctx);
+				ctx->name = NULL;
+			}
+			fprintf(fp, "};\n");
+			fprintf(fp, "typedef struct %s %s;\n\n",
+				record_schema->name, record_schema->name);
+		}
+		break;
+
+	case AVRO_ENUM:
+		{
+			struct schema_enum_t *enum_schema =
+			    avro_schema_to_enum(schema);
+			fprintf(fp, "enum %s {\n", enum_schema->name);
+			ctx->depth++;
+			for (i = 0; i < enum_schema->num_symbols; i++) {
+				indent(ctx, fp);
+				fprintf(fp, "%s = %ld,\n",
+					enum_schema->symbols[i], i);
+			}
+			ctx->depth--;
+			fprintf(fp, "};\n");
+			fprintf(fp, "typedef enum %s %s;\n\n",
+				enum_schema->name, enum_schema->name);
+		}
+		break;
+
+	case AVRO_FIXED:
+		{
+			struct schema_fixed_t *fixed_schema =
+			    avro_schema_to_fixed(schema);
+			fprintf(fp, "char %s[%ld];\n", fixed_schema->name,
+				fixed_schema->size);
+		}
+		break;
+
+	case AVRO_MAP:
+		{
+
+		}
+		break;
+
+	case AVRO_ARRAY:
+		{
+			struct schema_array_t *array_schema =
+			    avro_schema_to_array(schema);
+			if (!ctx->name) {
+				break;
+			}
+			fprintf(fp, "struct { size_t %s_len; ", ctx->name);
+			if (is_avro_named_type(array_schema->items)) {
+				fprintf(fp, "%s",
+					avro_schema_name(array_schema->items));
+			} else if (is_avro_link(array_schema->items)) {
+				struct schema_link_t *link_schema =
+				    avro_schema_to_link(array_schema->items);
+				fprintf(fp, "struct %s",
+					avro_schema_name(link_schema->to));
+			} else {
+				avro_schema_to_header(array_schema->items, ctx);
+			}
+			fprintf(fp, " *%s_val;} %s;\n", ctx->name, ctx->name);
+		}
+		break;
+	case AVRO_UNION:
+		{
+			struct schema_union_t *union_schema =
+			    avro_schema_to_array(schema);
+			if (!ctx->name) {
+				break;
+			}
+			fprintf(fp, "union {\n");
+			for (i = 0; i < union_schema->num_schemas; i++) {
+				avro_schema_to_header(union_schema->schemas[i],
+						      ctx);
+			}
+			fprintf(fp, "%s_u;\n");
+		}
+		break;
+	case AVRO_LINK:
+		break;
+	default:
+		return EINVAL;
+	}
+
+	ctx->depth--;
+	return 0;
 }
 
-int
-avro_schema_to_specific (avro_schema_t schema, const char *prefix)
+int avro_schema_to_specific(avro_schema_t schema, const char *prefix)
 {
-  specific_ctx ctx;
-  char buf[1024];
-  int rval;
-
-  if (!schema)
-    {
-      return EINVAL;
-    }
-
-  memset (&ctx, 0, sizeof (ctx));
-  snprintf (buf, sizeof (buf), "%s_avro.h", prefix);
-  ctx.header = fopen (buf, "w");
-  if (!ctx.header)
-    {
-      return errno;
-    }
-  snprintf (buf, sizeof (buf), "%s_avro.c", prefix);
-  ctx.source = fopen (buf, "w");
-  if (!ctx.source)
-    {
-      return errno;
-    }
-
-  rval = avro_schema_to_header (schema, &ctx);
-  if (rval)
-    {
-      goto out;
-    }
-
-  rval = avro_schema_to_source (schema, &ctx);
-
-out:
-  fclose (ctx.header);
-  fclose (ctx.source);
-  return rval;
+	specific_ctx ctx;
+	char buf[1024];
+	int rval;
+
+	if (!schema) {
+		return EINVAL;
+	}
+
+	memset(&ctx, 0, sizeof(ctx));
+	snprintf(buf, sizeof(buf), "%s_avro.h", prefix);
+	ctx.header = fopen(buf, "w");
+	if (!ctx.header) {
+		return errno;
+	}
+	snprintf(buf, sizeof(buf), "%s_avro.c", prefix);
+	ctx.source = fopen(buf, "w");
+	if (!ctx.source) {
+		return errno;
+	}
+
+	rval = avro_schema_to_header(schema, &ctx);
+	if (rval) {
+		goto out;
+	}
+
+	rval = avro_schema_to_source(schema, &ctx);
+
+      out:
+	fclose(ctx.header);
+	fclose(ctx.source);
+	return rval;
 }

Modified: hadoop/avro/trunk/lang/c/src/st.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/st.c?rev=901421&r1=901420&r2=901421&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/st.c (original)
+++ hadoop/avro/trunk/lang/c/src/st.c Wed Jan 20 22:58:22 2010
@@ -1,6 +1,11 @@
-/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
+/*
+ * This is a public domain general purpose hash table package written by
+ * Peter Moore @ UCB. 
+ */
 
-/* static	char	sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
+/*
+ * static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; 
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -10,41 +15,42 @@
 
 typedef struct st_table_entry st_table_entry;
 
-struct st_table_entry
-{
-  unsigned int hash;
-  st_data_t key;
-  st_data_t record;
-  st_table_entry *next;
+struct st_table_entry {
+	unsigned int hash;
+	st_data_t key;
+	st_data_t record;
+	st_table_entry *next;
 };
 
 #define ST_DEFAULT_MAX_DENSITY 5
 #define ST_DEFAULT_INIT_TABLE_SIZE 11
 
-    /*
-     * DEFAULT_MAX_DENSITY is the default for the largest we allow the
-     * average number of items per bin before increasing the number of
-     * bins
-     *
-     * DEFAULT_INIT_TABLE_SIZE is the default for the number of bins
-     * allocated initially
-     *
-     */
-static int numcmp (long, long);
-static int numhash (long);
+	/*
+	 * DEFAULT_MAX_DENSITY is the default for the largest we allow the
+	 * average number of items per bin before increasing the number of
+	 * bins
+	 *
+	 * DEFAULT_INIT_TABLE_SIZE is the default for the number of bins
+	 * allocated initially
+	 *
+	 */
+static int numcmp(long, long);
+static int numhash(long);
 static struct st_hash_type type_numhash = {
-  numcmp,
-  numhash,
+	numcmp,
+	numhash,
 };
 
-/* extern int strcmp(const char *, const char *); */
-static int strhash (const char *);
+/*
+ * extern int strcmp(const char *, const char *); 
+ */
+static int strhash(const char *);
 static struct st_hash_type type_strhash = {
-  strcmp,
-  strhash,
+	strcmp,
+	strhash,
 };
 
-static void rehash (st_table *);
+static void rehash(st_table *);
 
 #ifdef RUBY
 #define malloc xmalloc
@@ -66,64 +72,63 @@
 #define MINSIZE 8
 
 /*
-Table of prime numbers 2^n+a, 2<=n<=30.
-*/
+ * Table of prime numbers 2^n+a, 2<=n<=30. 
+ */
 static long primes[] = {
-  8 + 3,
-  16 + 3,
-  32 + 5,
-  64 + 3,
-  128 + 3,
-  256 + 27,
-  512 + 9,
-  1024 + 9,
-  2048 + 5,
-  4096 + 3,
-  8192 + 27,
-  16384 + 43,
-  32768 + 3,
-  65536 + 45,
-  131072 + 29,
-  262144 + 3,
-  524288 + 21,
-  1048576 + 7,
-  2097152 + 17,
-  4194304 + 15,
-  8388608 + 9,
-  16777216 + 43,
-  33554432 + 35,
-  67108864 + 15,
-  134217728 + 29,
-  268435456 + 3,
-  536870912 + 11,
-  1073741824 + 85,
-  0
+	8 + 3,
+	16 + 3,
+	32 + 5,
+	64 + 3,
+	128 + 3,
+	256 + 27,
+	512 + 9,
+	1024 + 9,
+	2048 + 5,
+	4096 + 3,
+	8192 + 27,
+	16384 + 43,
+	32768 + 3,
+	65536 + 45,
+	131072 + 29,
+	262144 + 3,
+	524288 + 21,
+	1048576 + 7,
+	2097152 + 17,
+	4194304 + 15,
+	8388608 + 9,
+	16777216 + 43,
+	33554432 + 35,
+	67108864 + 15,
+	134217728 + 29,
+	268435456 + 3,
+	536870912 + 11,
+	1073741824 + 85,
+	0
 };
 
-static int
-new_size (size)
-     int size;
+static int new_size(size)
+int size;
 {
-  int i;
+	int i;
 
 #if 0
-  for (i = 3; i < 31; i++)
-    {
-      if ((1 << i) > size)
-	return 1 << i;
-    }
-  return -1;
+	for (i = 3; i < 31; i++) {
+		if ((1 << i) > size)
+			return 1 << i;
+	}
+	return -1;
 #else
-  int newsize;
+	int newsize;
 
-  for (i = 0, newsize = MINSIZE;
-       i < sizeof (primes) / sizeof (primes[0]); i++, newsize <<= 1)
-    {
-      if (newsize > size)
-	return primes[i];
-    }
-  /* Ran out of polynomials */
-  return -1;			/* should raise exception */
+	for (i = 0, newsize = MINSIZE;
+	     i < sizeof(primes) / sizeof(primes[0]); i++, newsize <<= 1) {
+		if (newsize > size)
+			return primes[i];
+	}
+	/*
+	 * Ran out of polynomials 
+	 */
+	return -1;		/* should raise exception */
 #endif
 }
 
@@ -131,93 +136,82 @@
 static int collision = 0;
 static int init_st = 0;
 
-static void
-stat_col ()
+static void stat_col()
 {
-  FILE *f = fopen ("/tmp/col", "w");
-  fprintf (f, "collision: %d\n", collision);
-  fclose (f);
+	FILE *f = fopen("/tmp/col", "w");
+	fprintf(f, "collision: %d\n", collision);
+	fclose(f);
 }
 #endif
 
-st_table *
-st_init_table_with_size (type, size)
-     struct st_hash_type *type;
-     int size;
+st_table *st_init_table_with_size(type, size)
+struct st_hash_type *type;
+int size;
 {
-  st_table *tbl;
+	st_table *tbl;
 
 #ifdef HASH_LOG
-  if (init_st == 0)
-    {
-      init_st = 1;
-      atexit (stat_col);
-    }
+	if (init_st == 0) {
+		init_st = 1;
+		atexit(stat_col);
+	}
 #endif
 
-  size = new_size (size);	/* round up to prime number */
+	size = new_size(size);	/* round up to prime number */
 
-  tbl = alloc (st_table);
-  tbl->type = type;
-  tbl->num_entries = 0;
-  tbl->num_bins = size;
-  tbl->bins = (st_table_entry **) Calloc (size, sizeof (st_table_entry *));
+	tbl = alloc(st_table);
+	tbl->type = type;
+	tbl->num_entries = 0;
+	tbl->num_bins = size;
+	tbl->bins = (st_table_entry **) Calloc(size, sizeof(st_table_entry *));
 
-  return tbl;
+	return tbl;
 }
 
-st_table *
-st_init_table (type)
-     struct st_hash_type *type;
+st_table *st_init_table(type)
+struct st_hash_type *type;
 {
-  return st_init_table_with_size (type, 0);
+	return st_init_table_with_size(type, 0);
 }
 
-st_table *
-st_init_numtable (void)
+st_table *st_init_numtable(void)
 {
-  return st_init_table (&type_numhash);
+	return st_init_table(&type_numhash);
 }
 
-st_table *
-st_init_numtable_with_size (size)
-     int size;
+st_table *st_init_numtable_with_size(size)
+int size;
 {
-  return st_init_table_with_size (&type_numhash, size);
+	return st_init_table_with_size(&type_numhash, size);
 }
 
-st_table *
-st_init_strtable (void)
+st_table *st_init_strtable(void)
 {
-  return st_init_table (&type_strhash);
+	return st_init_table(&type_strhash);
 }
 
-st_table *
-st_init_strtable_with_size (size)
-     int size;
+st_table *st_init_strtable_with_size(size)
+int size;
 {
-  return st_init_table_with_size (&type_strhash, size);
+	return st_init_table_with_size(&type_strhash, size);
 }
 
-void
-st_free_table (table)
-     st_table *table;
+void st_free_table(table)
+st_table *table;
 {
-  register st_table_entry *ptr, *next;
-  int i;
+	register st_table_entry *ptr, *next;
+	int i;
 
-  for (i = 0; i < table->num_bins; i++)
-    {
-      ptr = table->bins[i];
-      while (ptr != 0)
-	{
-	  next = ptr->next;
-	  free (ptr);
-	  ptr = next;
+	for (i = 0; i < table->num_bins; i++) {
+		ptr = table->bins[i];
+		while (ptr != 0) {
+			next = ptr->next;
+			free(ptr);
+			ptr = next;
+		}
 	}
-    }
-  free (table->bins);
-  free (table);
+	free(table->bins);
+	free(table);
 }
 
 #define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
@@ -241,28 +235,24 @@
     }\
 } while (0)
 
-int
-st_lookup (table, key, value)
-     st_table *table;
-     register st_data_t key;
-     st_data_t *value;
-{
-  unsigned int hash_val, bin_pos;
-  register st_table_entry *ptr;
-
-  hash_val = do_hash (key, table);
-  FIND_ENTRY (table, ptr, hash_val, bin_pos);
-
-  if (ptr == 0)
-    {
-      return 0;
-    }
-  else
-    {
-      if (value != 0)
-	*value = ptr->record;
-      return 1;
-    }
+int st_lookup(table, key, value)
+st_table *table;
+register st_data_t key;
+st_data_t *value;
+{
+	unsigned int hash_val, bin_pos;
+	register st_table_entry *ptr;
+
+	hash_val = do_hash(key, table);
+	FIND_ENTRY(table, ptr, hash_val, bin_pos);
+
+	if (ptr == 0) {
+		return 0;
+	} else {
+		if (value != 0)
+			*value = ptr->record;
+		return 1;
+	}
 }
 
 #define ADD_DIRECT(table, key, value, hash_val, bin_pos)\
@@ -283,334 +273,299 @@
     table->num_entries++;\
 } while (0)
 
-int
-st_insert (table, key, value)
-     register st_table *table;
-     register st_data_t key;
-     st_data_t value;
-{
-  unsigned int hash_val, bin_pos;
-  register st_table_entry *ptr;
-
-  hash_val = do_hash (key, table);
-  FIND_ENTRY (table, ptr, hash_val, bin_pos);
-
-  if (ptr == 0)
-    {
-      ADD_DIRECT (table, key, value, hash_val, bin_pos);
-      return 0;
-    }
-  else
-    {
-      ptr->record = value;
-      return 1;
-    }
-}
-
-void
-st_add_direct (table, key, value)
-     st_table *table;
-     st_data_t key;
-     st_data_t value;
-{
-  unsigned int hash_val, bin_pos;
-
-  hash_val = do_hash (key, table);
-  bin_pos = hash_val % table->num_bins;
-  ADD_DIRECT (table, key, value, hash_val, bin_pos);
-}
-
-static void
-rehash (table)
-     register st_table *table;
-{
-  register st_table_entry *ptr, *next, **new_bins;
-  int i, old_num_bins = table->num_bins, new_num_bins;
-  unsigned int hash_val;
-
-  new_num_bins = new_size (old_num_bins + 1);
-  new_bins =
-    (st_table_entry **) Calloc (new_num_bins, sizeof (st_table_entry *));
-
-  for (i = 0; i < old_num_bins; i++)
-    {
-      ptr = table->bins[i];
-      while (ptr != 0)
-	{
-	  next = ptr->next;
-	  hash_val = ptr->hash % new_num_bins;
-	  ptr->next = new_bins[hash_val];
-	  new_bins[hash_val] = ptr;
-	  ptr = next;
-	}
-    }
-  free (table->bins);
-  table->num_bins = new_num_bins;
-  table->bins = new_bins;
-}
-
-st_table *
-st_copy (old_table)
-     st_table *old_table;
-{
-  st_table *new_table;
-  st_table_entry *ptr, *entry;
-  int i, num_bins = old_table->num_bins;
-
-  new_table = alloc (st_table);
-  if (new_table == 0)
-    {
-      return 0;
-    }
-
-  *new_table = *old_table;
-  new_table->bins = (st_table_entry **)
-    Calloc ((unsigned) num_bins, sizeof (st_table_entry *));
-
-  if (new_table->bins == 0)
-    {
-      free (new_table);
-      return 0;
-    }
-
-  for (i = 0; i < num_bins; i++)
-    {
-      new_table->bins[i] = 0;
-      ptr = old_table->bins[i];
-      while (ptr != 0)
-	{
-	  entry = alloc (st_table_entry);
-	  if (entry == 0)
-	    {
-	      free (new_table->bins);
-	      free (new_table);
-	      return 0;
-	    }
-	  *entry = *ptr;
-	  entry->next = new_table->bins[i];
-	  new_table->bins[i] = entry;
-	  ptr = ptr->next;
-	}
-    }
-  return new_table;
-}
-
-int
-st_delete (table, key, value)
-     register st_table *table;
-     register st_data_t *key;
-     st_data_t *value;
-{
-  unsigned int hash_val;
-  st_table_entry *tmp;
-  register st_table_entry *ptr;
-
-  hash_val = do_hash_bin (*key, table);
-  ptr = table->bins[hash_val];
-
-  if (ptr == 0)
-    {
-      if (value != 0)
-	*value = 0;
-      return 0;
-    }
-
-  if (EQUAL (table, *key, ptr->key))
-    {
-      table->bins[hash_val] = ptr->next;
-      table->num_entries--;
-      if (value != 0)
-	*value = ptr->record;
-      *key = ptr->key;
-      free (ptr);
-      return 1;
-    }
-
-  for (; ptr->next != 0; ptr = ptr->next)
-    {
-      if (EQUAL (table, ptr->next->key, *key))
-	{
-	  tmp = ptr->next;
-	  ptr->next = ptr->next->next;
-	  table->num_entries--;
-	  if (value != 0)
-	    *value = tmp->record;
-	  *key = tmp->key;
-	  free (tmp);
-	  return 1;
-	}
-    }
-
-  return 0;
-}
-
-int
-st_delete_safe (table, key, value, never)
-     register st_table *table;
-     register st_data_t *key;
-     st_data_t *value;
-     st_data_t never;
-{
-  unsigned int hash_val;
-  register st_table_entry *ptr;
-
-  hash_val = do_hash_bin (*key, table);
-  ptr = table->bins[hash_val];
-
-  if (ptr == 0)
-    {
-      if (value != 0)
-	*value = 0;
-      return 0;
-    }
-
-  for (; ptr != 0; ptr = ptr->next)
-    {
-      if ((ptr->key != never) && EQUAL (table, ptr->key, *key))
-	{
-	  table->num_entries--;
-	  *key = ptr->key;
-	  if (value != 0)
-	    *value = ptr->record;
-	  ptr->key = ptr->record = never;
-	  return 1;
-	}
-    }
-
-  return 0;
-}
-
-static int
-delete_never (key, value, never)
-     st_data_t key, value, never;
-{
-  if (value == never)
-    return ST_DELETE;
-  return ST_CONTINUE;
-}
-
-void
-st_cleanup_safe (table, never)
-     st_table *table;
-     st_data_t never;
-{
-  int num_entries = table->num_entries;
-
-  st_foreach (table, delete_never, never);
-  table->num_entries = num_entries;
-}
-
-int
-st_foreach (table, func, arg)
-     st_table *table;
-     int (*func) ();
-     st_data_t arg;
-{
-  st_table_entry *ptr, *last, *tmp;
-  enum st_retval retval;
-  int i;
-
-  for (i = 0; i < table->num_bins; i++)
-    {
-      last = 0;
-      for (ptr = table->bins[i]; ptr != 0;)
-	{
-	  retval = (*func) (ptr->key, ptr->record, arg);
-	  switch (retval)
-	    {
-	    case ST_CHECK:	/* check if hash is modified during iteration */
-	      tmp = 0;
-	      if (i < table->num_bins)
-		{
-		  for (tmp = table->bins[i]; tmp; tmp = tmp->next)
-		    {
-		      if (tmp == ptr)
-			break;
-		    }
+int st_insert(table, key, value)
+register st_table *table;
+register st_data_t key;
+st_data_t value;
+{
+	unsigned int hash_val, bin_pos;
+	register st_table_entry *ptr;
+
+	hash_val = do_hash(key, table);
+	FIND_ENTRY(table, ptr, hash_val, bin_pos);
+
+	if (ptr == 0) {
+		ADD_DIRECT(table, key, value, hash_val, bin_pos);
+		return 0;
+	} else {
+		ptr->record = value;
+		return 1;
+	}
+}
+
+void st_add_direct(table, key, value)
+st_table *table;
+st_data_t key;
+st_data_t value;
+{
+	unsigned int hash_val, bin_pos;
+
+	hash_val = do_hash(key, table);
+	bin_pos = hash_val % table->num_bins;
+	ADD_DIRECT(table, key, value, hash_val, bin_pos);
+}
+
+static void rehash(table)
+register st_table *table;
+{
+	register st_table_entry *ptr, *next, **new_bins;
+	int i, old_num_bins = table->num_bins, new_num_bins;
+	unsigned int hash_val;
+
+	new_num_bins = new_size(old_num_bins + 1);
+	new_bins =
+	    (st_table_entry **) Calloc(new_num_bins, sizeof(st_table_entry *));
+
+	for (i = 0; i < old_num_bins; i++) {
+		ptr = table->bins[i];
+		while (ptr != 0) {
+			next = ptr->next;
+			hash_val = ptr->hash % new_num_bins;
+			ptr->next = new_bins[hash_val];
+			new_bins[hash_val] = ptr;
+			ptr = next;
 		}
-	      if (!tmp)
-		{
-		  /* call func with error notice */
-		  return 1;
+	}
+	free(table->bins);
+	table->num_bins = new_num_bins;
+	table->bins = new_bins;
+}
+
+st_table *st_copy(old_table)
+st_table *old_table;
+{
+	st_table *new_table;
+	st_table_entry *ptr, *entry;
+	int i, num_bins = old_table->num_bins;
+
+	new_table = alloc(st_table);
+	if (new_table == 0) {
+		return 0;
+	}
+
+	*new_table = *old_table;
+	new_table->bins = (st_table_entry **)
+	    Calloc((unsigned)num_bins, sizeof(st_table_entry *));
+
+	if (new_table->bins == 0) {
+		free(new_table);
+		return 0;
+	}
+
+	for (i = 0; i < num_bins; i++) {
+		new_table->bins[i] = 0;
+		ptr = old_table->bins[i];
+		while (ptr != 0) {
+			entry = alloc(st_table_entry);
+			if (entry == 0) {
+				free(new_table->bins);
+				free(new_table);
+				return 0;
+			}
+			*entry = *ptr;
+			entry->next = new_table->bins[i];
+			new_table->bins[i] = entry;
+			ptr = ptr->next;
 		}
-	      /* fall through */
-	    case ST_CONTINUE:
-	      last = ptr;
-	      ptr = ptr->next;
-	      break;
-	    case ST_STOP:
-	      return 0;
-	    case ST_DELETE:
-	      tmp = ptr;
-	      if (last == 0)
-		{
-		  table->bins[i] = ptr->next;
+	}
+	return new_table;
+}
+
+int st_delete(table, key, value)
+register st_table *table;
+register st_data_t *key;
+st_data_t *value;
+{
+	unsigned int hash_val;
+	st_table_entry *tmp;
+	register st_table_entry *ptr;
+
+	hash_val = do_hash_bin(*key, table);
+	ptr = table->bins[hash_val];
+
+	if (ptr == 0) {
+		if (value != 0)
+			*value = 0;
+		return 0;
+	}
+
+	if (EQUAL(table, *key, ptr->key)) {
+		table->bins[hash_val] = ptr->next;
+		table->num_entries--;
+		if (value != 0)
+			*value = ptr->record;
+		*key = ptr->key;
+		free(ptr);
+		return 1;
+	}
+
+	for (; ptr->next != 0; ptr = ptr->next) {
+		if (EQUAL(table, ptr->next->key, *key)) {
+			tmp = ptr->next;
+			ptr->next = ptr->next->next;
+			table->num_entries--;
+			if (value != 0)
+				*value = tmp->record;
+			*key = tmp->key;
+			free(tmp);
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+int st_delete_safe(table, key, value, never)
+register st_table *table;
+register st_data_t *key;
+st_data_t *value;
+st_data_t never;
+{
+	unsigned int hash_val;
+	register st_table_entry *ptr;
+
+	hash_val = do_hash_bin(*key, table);
+	ptr = table->bins[hash_val];
+
+	if (ptr == 0) {
+		if (value != 0)
+			*value = 0;
+		return 0;
+	}
+
+	for (; ptr != 0; ptr = ptr->next) {
+		if ((ptr->key != never) && EQUAL(table, ptr->key, *key)) {
+			table->num_entries--;
+			*key = ptr->key;
+			if (value != 0)
+				*value = ptr->record;
+			ptr->key = ptr->record = never;
+			return 1;
 		}
-	      else
-		{
-		  last->next = ptr->next;
+	}
+
+	return 0;
+}
+
+static int delete_never(key, value, never)
+st_data_t key, value, never;
+{
+	if (value == never)
+		return ST_DELETE;
+	return ST_CONTINUE;
+}
+
+void st_cleanup_safe(table, never)
+st_table *table;
+st_data_t never;
+{
+	int num_entries = table->num_entries;
+
+	st_foreach(table, delete_never, never);
+	table->num_entries = num_entries;
+}
+
+int st_foreach(table, func, arg)
+st_table *table;
+int (*func) ();
+st_data_t arg;
+{
+	st_table_entry *ptr, *last, *tmp;
+	enum st_retval retval;
+	int i;
+
+	for (i = 0; i < table->num_bins; i++) {
+		last = 0;
+		for (ptr = table->bins[i]; ptr != 0;) {
+			retval = (*func) (ptr->key, ptr->record, arg);
+			switch (retval) {
+			case ST_CHECK:	/* check if hash is modified during
+					 * iteration */
+				tmp = 0;
+				if (i < table->num_bins) {
+					for (tmp = table->bins[i]; tmp;
+					     tmp = tmp->next) {
+						if (tmp == ptr)
+							break;
+					}
+				}
+				if (!tmp) {
+					/*
+					 * call func with error notice 
+					 */
+					return 1;
+				}
+				/*
+				 * fall through 
+				 */
+			case ST_CONTINUE:
+				last = ptr;
+				ptr = ptr->next;
+				break;
+			case ST_STOP:
+				return 0;
+			case ST_DELETE:
+				tmp = ptr;
+				if (last == 0) {
+					table->bins[i] = ptr->next;
+				} else {
+					last->next = ptr->next;
+				}
+				ptr = ptr->next;
+				free(tmp);
+				table->num_entries--;
+			}
 		}
-	      ptr = ptr->next;
-	      free (tmp);
-	      table->num_entries--;
-	    }
 	}
-    }
-  return 0;
+	return 0;
 }
 
-static int
-strhash (string)
-     register const char *string;
+static int strhash(string)
+register const char *string;
 {
-  register int c;
+	register int c;
 
 #ifdef HASH_ELFHASH
-  register unsigned int h = 0, g;
+	register unsigned int h = 0, g;
 
-  while ((c = *string++) != '\0')
-    {
-      h = (h << 4) + c;
-      if (g = h & 0xF0000000)
-	h ^= g >> 24;
-      h &= ~g;
-    }
-  return h;
+	while ((c = *string++) != '\0') {
+		h = (h << 4) + c;
+		if (g = h & 0xF0000000)
+			h ^= g >> 24;
+		h &= ~g;
+	}
+	return h;
 #elif defined(HASH_PERL)
-  register int val = 0;
+	register int val = 0;
 
-  while ((c = *string++) != '\0')
-    {
-      val += c;
-      val += (val << 10);
-      val ^= (val >> 6);
-    }
-  val += (val << 3);
-  val ^= (val >> 11);
+	while ((c = *string++) != '\0') {
+		val += c;
+		val += (val << 10);
+		val ^= (val >> 6);
+	}
+	val += (val << 3);
+	val ^= (val >> 11);
 
-  return val + (val << 15);
+	return val + (val << 15);
 #else
-  register int val = 0;
+	register int val = 0;
 
-  while ((c = *string++) != '\0')
-    {
-      val = val * 997 + c;
-    }
+	while ((c = *string++) != '\0') {
+		val = val * 997 + c;
+	}
 
-  return val + (val >> 5);
+	return val + (val >> 5);
 #endif
 }
 
-static int
-numcmp (x, y)
-     long x, y;
+static int numcmp(x, y)
+long x, y;
 {
-  return x != y;
+	return x != y;
 }
 
-static int
-numhash (n)
-     long n;
+static int numhash(n)
+long n;
 {
-  return n;
+	return n;
 }

Modified: hadoop/avro/trunk/lang/c/src/st.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/st.h?rev=901421&r1=901420&r2=901421&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/st.h (original)
+++ hadoop/avro/trunk/lang/c/src/st.h Wed Jan 20 22:58:22 2010
@@ -1,6 +1,11 @@
-/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
-
-/* @(#) st.h 5.1 89/12/14 */
+/*
+ * This is a public domain general purpose hash table package written by
+ * Peter Moore @ UCB. 
+ */
+
+/*
+ * @(#) st.h 5.1 89/12/14 
+ */
 
 #ifndef ST_INCLUDED
 
@@ -16,24 +21,21 @@
 #define ST_DATA_T_DEFINED
 typedef struct st_table st_table;
 
-struct st_hash_type
-{
-  int (*compare) ();
-  int (*hash) ();
+struct st_hash_type {
+	int (*compare) ();
+	int (*hash) ();
 };
 
-struct st_table
-{
-  struct st_hash_type *type;
-  int num_bins;
-  int num_entries;
-  struct st_table_entry **bins;
+struct st_table {
+	struct st_hash_type *type;
+	int num_bins;
+	int num_entries;
+	struct st_table_entry **bins;
 };
 
 #define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0)
 
-enum st_retval
-{ ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK };
+enum st_retval { ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK };
 
 #ifndef _
 # define _(args) args
@@ -68,6 +70,6 @@
 #define st_numcmp	ST_NUMCMP
 #define st_numhash	ST_NUMHASH
 
-int st_strhash ();
+int st_strhash();
 
-#endif /* ST_INCLUDED */
+#endif				/* ST_INCLUDED */

Modified: hadoop/avro/trunk/lang/c/tests/test_avro_data.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/test_avro_data.c?rev=901421&r1=901420&r2=901421&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/test_avro_data.c (original)
+++ hadoop/avro/trunk/lang/c/tests/test_avro_data.c Wed Jan 20 22:58:22 2010
@@ -1,21 +1,19 @@
 /*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License. 
+ */
 #include <stdlib.h>
 #include <stdint.h>
 #include <time.h>
@@ -29,260 +27,225 @@
 typedef int (*avro_test) (void);
 
 void
-write_read_check (avro_schema_t writers_schema, avro_schema_t readers_schema,
-		  avro_datum_t datum, char *type)
+write_read_check(avro_schema_t writers_schema,
+		 avro_schema_t readers_schema, avro_datum_t datum, char *type)
 {
-  avro_datum_t datum_out;
-  reader = avro_reader_memory (buf, sizeof (buf));
-  writer = avro_writer_memory (buf, sizeof (buf));
-
-  if (avro_write_data (writer, writers_schema, datum))
-    {
-      fprintf (stderr, "Unable to write %s\n", type);
-      exit (EXIT_FAILURE);
-    }
-  if (avro_read_data (reader, writers_schema, readers_schema, &datum_out))
-    {
-      fprintf (stderr, "Unable to read %s\n", type);
-      exit (EXIT_FAILURE);
-    }
-  if (!avro_datum_equal (datum, datum_out))
-    {
-      fprintf (stderr, "Unable to encode/decode %s\n", type);
-      exit (EXIT_FAILURE);
-    }
-
-  avro_datum_decref (datum_out);
-  avro_reader_free (reader);
-  avro_writer_free (writer);
-}
-
-static int
-test_string (void)
-{
-  int i;
-  const char *strings[] = { "Four score and seven years ago",
-    "our father brought forth on this continent",
-    "a new nation", "conceived in Liberty",
-    "and dedicated to the proposition that all men are created equal."
-  };
-  for (i = 0; i < sizeof (strings) / sizeof (strings[0]); i++)
-    {
-      avro_schema_t writer_schema = avro_schema_string ();
-      avro_datum_t datum = avro_string (strings[i]);
-      write_read_check (writer_schema, NULL, datum, "string");
-      avro_datum_decref (datum);
-    }
-  return 0;
-}
-
-static int
-test_bytes (void)
-{
-  char bytes[] = { 0xDE, 0xAD, 0xBE, 0xEF };
-  avro_schema_t writer_schema = avro_schema_bytes ();
-  avro_datum_t datum = avro_bytes (bytes, sizeof (bytes));
-
-  write_read_check (writer_schema, NULL, datum, "bytes");
-  avro_datum_decref (datum);
-  return 0;
-}
-
-static int
-test_int (void)
-{
-  int i;
-  for (i = 0; i < 100; i++)
-    {
-      avro_schema_t writer_schema = avro_schema_int ();
-      avro_datum_t datum = avro_int (rand ());
-      write_read_check (writer_schema, NULL, datum, "int");
-      avro_datum_decref (datum);
-    }
-  return 0;
-}
-
-static int
-test_long (void)
-{
-  int i;
-  for (i = 0; i < 100; i++)
-    {
-      avro_schema_t writer_schema = avro_schema_long ();
-      avro_datum_t datum = avro_long (rand ());
-      write_read_check (writer_schema, NULL, datum, "long");
-      avro_datum_decref (datum);
-    }
-  return 0;
-}
-
-static
-test_double (void)
-{
-  int i;
-  for (i = 0; i < 100; i++)
-    {
-      avro_schema_t schema = avro_schema_double ();
-      avro_datum_t datum = avro_double ((double) (rand ()));
-      write_read_check (schema, NULL, datum, "double");
-      avro_datum_decref (datum);
-    }
-  return 0;
-}
-
-static int
-test_float (void)
-{
-  int i;
-  for (i = 0; i < 100; i++)
-    {
-      avro_schema_t schema = avro_schema_double ();
-      avro_datum_t datum = avro_double ((double) (rand ()));
-      write_read_check (schema, NULL, datum, "float");
-      avro_datum_decref (datum);
-    }
-  return 0;
-}
-
-static int
-test_boolean (void)
-{
-  int i;
-  for (i = 0; i < 100; i++)
-    {
-      avro_schema_t schema = avro_schema_boolean ();
-      avro_datum_t datum = avro_boolean (rand () % 2);
-      write_read_check (schema, NULL, datum, "boolean");
-      avro_datum_decref (datum);
-    }
-  return 0;
-}
-
-static int
-test_null (void)
-{
-  avro_schema_t schema = avro_schema_null ();
-  avro_datum_t datum = avro_null ();
-  write_read_check (schema, NULL, datum, "null");
-  avro_datum_decref (datum);
-  return 0;
-}
-
-int
-test_record (void)
-{
-  /* TODO */
-  return 0;
-}
-
-int
-test_enum (void)
-{
-  /* TODO */
-  return 0;
-}
-
-int
-test_array (void)
-{
-  int i, rval;
-  avro_schema_t schema = avro_schema_array (avro_schema_int ());
-  avro_datum_t datum = avro_array ();
-
-  for (i = 0; i < 10; i++)
-    {
-      rval = avro_array_append_datum (datum, avro_int (i));
-      if (rval)
-	{
-	  exit (rval);
-	}
-    }
-  write_read_check (schema, NULL, datum, "array");
-  avro_datum_decref (datum);
-  return 0;
-}
-
-int
-test_map (void)
-{
-  avro_schema_t schema = avro_schema_map (avro_schema_long ());
-  avro_datum_t datum = avro_map ();
-  int64_t i = 0;
-  char *nums[] =
-    { "zero", "one", "two", "three", "four", "five", "six", NULL };
-  while (nums[i])
-    {
-      avro_map_set (datum, nums[i], avro_long (i));
-      i++;
-    }
-  write_read_check (schema, NULL, datum, "map");
-  avro_datum_decref (datum);
-  return 0;
-}
-
-int
-test_union (void)
-{
-  /* TODO */
-  return 0;
-}
-
-int
-test_fixed (void)
-{
-  /* TODO */
-  return 0;
-}
-
-int
-main (void)
-{
-  int i;
-  struct avro_tests
-  {
-    char *name;
-    avro_test func;
-  } tests[] =
-  {
-    {
-    "string", test_string},
-    {
-    "bytes", test_bytes},
-    {
-    "int", test_int},
-    {
-    "long", test_long},
-    {
-    "float", test_float},
-    {
-    "double", test_double},
-    {
-    "boolean", test_boolean},
-    {
-    "null", test_null},
-    {
-    "record", test_record},
-    {
-    "enum", test_enum},
-    {
-    "array", test_array},
-    {
-    "map", test_map},
-    {
-    "fixed", test_fixed}
-  };
-
-  srandom (time (NULL));
-  for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
-    {
-      struct avro_tests *test = tests + i;
-      fprintf (stderr, "Running %s tests...\n", test->name);
-      if (test->func () != 0)
-	{
-	  fprintf (stderr, "failed!\n");
-	  return EXIT_FAILURE;
-	}
-      fprintf (stderr, "\t... %s tests passed!\n", test->name);
-    }
-  return EXIT_SUCCESS;
+	avro_datum_t datum_out;
+	reader = avro_reader_memory(buf, sizeof(buf));
+	writer = avro_writer_memory(buf, sizeof(buf));
+
+	if (avro_write_data(writer, writers_schema, datum)) {
+		fprintf(stderr, "Unable to write %s\n", type);
+		exit(EXIT_FAILURE);
+	}
+	if (avro_read_data(reader, writers_schema, readers_schema, &datum_out)) {
+		fprintf(stderr, "Unable to read %s\n", type);
+		exit(EXIT_FAILURE);
+	}
+	if (!avro_datum_equal(datum, datum_out)) {
+		fprintf(stderr, "Unable to encode/decode %s\n", type);
+		exit(EXIT_FAILURE);
+	}
+
+	avro_datum_decref(datum_out);
+	avro_reader_free(reader);
+	avro_writer_free(writer);
+}
+
+static int test_string(void)
+{
+	int i;
+	const char *strings[] = { "Four score and seven years ago",
+		"our father brought forth on this continent",
+		"a new nation", "conceived in Liberty",
+		"and dedicated to the proposition that all men are created equal."
+	};
+	for (i = 0; i < sizeof(strings) / sizeof(strings[0]); i++) {
+		avro_schema_t writer_schema = avro_schema_string();
+		avro_datum_t datum = avro_string(strings[i]);
+		write_read_check(writer_schema, NULL, datum, "string");
+		avro_datum_decref(datum);
+	}
+	return 0;
+}
+
+static int test_bytes(void)
+{
+	char bytes[] = { 0xDE, 0xAD, 0xBE, 0xEF };
+	avro_schema_t writer_schema = avro_schema_bytes();
+	avro_datum_t datum = avro_bytes(bytes, sizeof(bytes));
+
+	write_read_check(writer_schema, NULL, datum, "bytes");
+	avro_datum_decref(datum);
+	return 0;
+}
+
+static int test_int(void)
+{
+	int i;
+	for (i = 0; i < 100; i++) {
+		avro_schema_t writer_schema = avro_schema_int();
+		avro_datum_t datum = avro_int(rand());
+		write_read_check(writer_schema, NULL, datum, "int");
+		avro_datum_decref(datum);
+	}
+	return 0;
+}
+
+static int test_long(void)
+{
+	int i;
+	for (i = 0; i < 100; i++) {
+		avro_schema_t writer_schema = avro_schema_long();
+		avro_datum_t datum = avro_long(rand());
+		write_read_check(writer_schema, NULL, datum, "long");
+		avro_datum_decref(datum);
+	}
+	return 0;
+}
+
+static test_double(void)
+{
+	int i;
+	for (i = 0; i < 100; i++) {
+		avro_schema_t schema = avro_schema_double();
+		avro_datum_t datum = avro_double((double)(rand()));
+		write_read_check(schema, NULL, datum, "double");
+		avro_datum_decref(datum);
+	}
+	return 0;
+}
+
+static int test_float(void)
+{
+	int i;
+	for (i = 0; i < 100; i++) {
+		avro_schema_t schema = avro_schema_double();
+		avro_datum_t datum = avro_double((double)(rand()));
+		write_read_check(schema, NULL, datum, "float");
+		avro_datum_decref(datum);
+	}
+	return 0;
+}
+
+static int test_boolean(void)
+{
+	int i;
+	for (i = 0; i < 100; i++) {
+		avro_schema_t schema = avro_schema_boolean();
+		avro_datum_t datum = avro_boolean(rand() % 2);
+		write_read_check(schema, NULL, datum, "boolean");
+		avro_datum_decref(datum);
+	}
+	return 0;
+}
+
+static int test_null(void)
+{
+	avro_schema_t schema = avro_schema_null();
+	avro_datum_t datum = avro_null();
+	write_read_check(schema, NULL, datum, "null");
+	avro_datum_decref(datum);
+	return 0;
+}
+
+int test_record(void)
+{
+	/*
+	 * TODO 
+	 */
+	return 0;
+}
+
+int test_enum(void)
+{
+	/*
+	 * TODO 
+	 */
+	return 0;
+}
+
+int test_array(void)
+{
+	int i, rval;
+	avro_schema_t schema = avro_schema_array(avro_schema_int());
+	avro_datum_t datum = avro_array();
+
+	for (i = 0; i < 10; i++) {
+		rval = avro_array_append_datum(datum, avro_int(i));
+		if (rval) {
+			exit(rval);
+		}
+	}
+	write_read_check(schema, NULL, datum, "array");
+	avro_datum_decref(datum);
+	return 0;
+}
+
+int test_map(void)
+{
+	avro_schema_t schema = avro_schema_map(avro_schema_long());
+	avro_datum_t datum = avro_map();
+	int64_t i = 0;
+	char *nums[] =
+	    { "zero", "one", "two", "three", "four", "five", "six", NULL };
+	while (nums[i]) {
+		avro_map_set(datum, nums[i], avro_long(i));
+		i++;
+	}
+	write_read_check(schema, NULL, datum, "map");
+	avro_datum_decref(datum);
+	return 0;
+}
+
+int test_union(void)
+{
+	/*
+	 * TODO 
+	 */
+	return 0;
+}
+
+int test_fixed(void)
+{
+	/*
+	 * TODO 
+	 */
+	return 0;
+}
+
+int main(void)
+{
+	int i;
+	struct avro_tests {
+		char *name;
+		avro_test func;
+	} tests[] = {
+		{
+		"string", test_string}, {
+		"bytes", test_bytes}, {
+		"int", test_int}, {
+		"long", test_long}, {
+		"float", test_float}, {
+		"double", test_double}, {
+		"boolean", test_boolean}, {
+		"null", test_null}, {
+		"record", test_record}, {
+		"enum", test_enum}, {
+		"array", test_array}, {
+		"map", test_map}, {
+		"fixed", test_fixed}
+	};
+
+	srandom(time(NULL));
+	for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
+		struct avro_tests *test = tests + i;
+		fprintf(stderr, "Running %s tests...\n", test->name);
+		if (test->func() != 0) {
+			fprintf(stderr, "failed!\n");
+			return EXIT_FAILURE;
+		}
+		fprintf(stderr, "\t... %s tests passed!\n", test->name);
+	}
+	return EXIT_SUCCESS;
 }

Modified: hadoop/avro/trunk/lang/c/tests/test_avro_interop.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/test_avro_interop.c?rev=901421&r1=901420&r2=901421&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/test_avro_interop.c (original)
+++ hadoop/avro/trunk/lang/c/tests/test_avro_interop.c Wed Jan 20 22:58:22 2010
@@ -5,77 +5,72 @@
 apr_pool_t *pool;
 
 /*
-$ ant generate-test-data
-needs to be called to make sure that test data is created.
+ * $ ant generate-test-data needs to be called to make sure that test data 
+ * is created.
+ * 
+ * The test files are then in ./build/test/data-files 
+ */
 
-The test files are then in ./build/test/data-files 
-*/
-
-int
-main (void)
+int main(void)
 {
-  char *srcdir = getenv ("srcdir");
-  char *path;
-  char *jsontext;
-  apr_size_t jsonlen;
-  struct avro_value *value;
-  struct avro_reader *reader;
-  char *suffixes[] = { "py", "java" };
-  char *suffix;
-  int i;
-
-  if (!srcdir)
-    {
-      srcdir = ".";
-    }
-
-  avro_initialize ();
-  apr_pool_create (&pool, NULL);
-
-  path = apr_pstrcat (pool, srcdir, "/../test/schemata/interop.avsc", NULL);
-  if (!path)
-    {
-      fprintf (stderr, "Couldn't allocate memory for file path\n");
-      return EXIT_FAILURE;
-    }
-  jsontext = avro_util_file_read_full (pool, path, &jsonlen);
-  if (!jsontext)
-    {
-      fprintf (stderr,
-	       "Couldn't find file: %s. Can't run interop test out of tree\n",
-	       path);
-      return EXIT_SUCCESS;
-    }
-  value = avro_value_create (pool, jsontext, jsonlen);
-  if (!value)
-    {
-      fprintf (stderr, "Unable to parse the Avro schema in file %s\n", path);
-      return EXIT_FAILURE;
-    }
-
-  for (i = 0; i < sizeof (suffixes) / sizeof (suffixes[0]); i++)
-    {
-      suffix = suffixes[i];
-
-      path =
-	apr_pstrcat (pool, srcdir, "/../../build/test/data-files/test.",
-		     suffix, ".avro", NULL);
-      if (!path)
-	{
-	  return EXIT_FAILURE;
+	char *srcdir = getenv("srcdir");
+	char *path;
+	char *jsontext;
+	apr_size_t jsonlen;
+	struct avro_value *value;
+	struct avro_reader *reader;
+	char *suffixes[] = { "py", "java" };
+	char *suffix;
+	int i;
+
+	if (!srcdir) {
+		srcdir = ".";
+	}
+
+	avro_initialize();
+	apr_pool_create(&pool, NULL);
+
+	path =
+	    apr_pstrcat(pool, srcdir, "/../test/schemata/interop.avsc", NULL);
+	if (!path) {
+		fprintf(stderr, "Couldn't allocate memory for file path\n");
+		return EXIT_FAILURE;
 	}
-      fprintf (stderr, "Running test on %s...\n", path);
-      reader =
-	avro_reader_file_container_create (pool, path, APR_READ,
-					   APR_OS_DEFAULT);
-      if (!reader)
-	{
-	  fprintf (stderr, "Failed to open data file %s\n", path);
-	  return EXIT_FAILURE;
+	jsontext = avro_util_file_read_full(pool, path, &jsonlen);
+	if (!jsontext) {
+		fprintf(stderr,
+			"Couldn't find file: %s. Can't run interop test out of tree\n",
+			path);
+		return EXIT_SUCCESS;
+	}
+	value = avro_value_create(pool, jsontext, jsonlen);
+	if (!value) {
+		fprintf(stderr, "Unable to parse the Avro schema in file %s\n",
+			path);
+		return EXIT_FAILURE;
+	}
+
+	for (i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); i++) {
+		suffix = suffixes[i];
+
+		path =
+		    apr_pstrcat(pool, srcdir,
+				"/../../build/test/data-files/test.", suffix,
+				".avro", NULL);
+		if (!path) {
+			return EXIT_FAILURE;
+		}
+		fprintf(stderr, "Running test on %s...\n", path);
+		reader =
+		    avro_reader_file_container_create(pool, path, APR_READ,
+						      APR_OS_DEFAULT);
+		if (!reader) {
+			fprintf(stderr, "Failed to open data file %s\n", path);
+			return EXIT_FAILURE;
+		}
+		avro_value_read_data(value, reader);
+		avro_value_print_info(value, stderr);
 	}
-      avro_value_read_data (value, reader);
-      avro_value_print_info (value, stderr);
-    }
-  apr_pool_destroy (pool);
-  return EXIT_SUCCESS;
+	apr_pool_destroy(pool);
+	return EXIT_SUCCESS;
 }

Modified: hadoop/avro/trunk/lang/c/tests/test_avro_schema.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/test_avro_schema.c?rev=901421&r1=901420&r2=901421&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/test_avro_schema.c (original)
+++ hadoop/avro/trunk/lang/c/tests/test_avro_schema.c Wed Jan 20 22:58:22 2010
@@ -1,21 +1,19 @@
 /*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License. 
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -25,108 +23,99 @@
 
 int test_cases = 0;
 
-static void
-run_tests (char *dirpath, int should_pass)
+static void run_tests(char *dirpath, int should_pass)
 {
-  char jsontext[4096];
-  size_t jsonlen, rval;
-  char filepath[1024];
-  DIR *dir;
-  struct dirent *dent;
-  FILE *fp;
-  avro_schema_t schema;
-  avro_schema_error_t avro_schema_error;
-
-  dir = opendir (dirpath);
-  if (dir == NULL)
-    {
-      fprintf (stderr, "Unable to open '%s'\n", dirpath);
-      exit (EXIT_FAILURE);
-    }
-  do
-    {
-      dent = readdir (dir);
-      if (dent && dent->d_name[0] != '.')
-	{
-	  int test_rval;
-	  snprintf (filepath, sizeof (filepath), "%s/%s", dirpath,
-		    dent->d_name);
-	  fprintf (stderr, "TEST %s...", filepath);
-	  jsonlen = 0;
-	  fp = fopen (filepath, "r");
-	  if (!fp)
-	    {
-	      fprintf (stderr, "can't open!\n");
-	      exit (EXIT_FAILURE);
-	    }
-	  rval = fread (jsontext, 1, sizeof (jsontext) - 1, fp);
-	  jsontext[rval] = '\0';
-	  test_rval =
-	    avro_schema_from_json (jsontext, jsonlen, &schema,
-				   &avro_schema_error);
-	  test_cases++;
-	  if (test_rval == 0)
-	    {
-	      if (should_pass)
-		{
-		  avro_schema_t schema_copy = avro_schema_copy (schema);
-		  fprintf (stderr, "pass\n");
-		  avro_schema_printf (schema, stderr);
-		  if (!avro_schema_equal (schema, schema_copy))
-		    {
-		      fprintf (stderr,
-			       "failed to avro_schema_equal(schema,avro_schema_copy())\n");
-		      exit (EXIT_FAILURE);
-		    }
-		}
-	      else
-		{
-		  /* Unexpected success */
-		  fprintf (stderr, "fail! (shouldn't succeed but did)\n");
-		  exit (EXIT_FAILURE);
-		}
-	    }
-	  else
-	    {
-	      if (should_pass)
-		{
-		  fprintf (stderr,
-			   "fail! (should have succeeded but didn't)\n");
-		  exit (EXIT_FAILURE);
-		}
-	      else
-		{
-		  fprintf (stderr, "pass\n");
+	char jsontext[4096];
+	size_t jsonlen, rval;
+	char filepath[1024];
+	DIR *dir;
+	struct dirent *dent;
+	FILE *fp;
+	avro_schema_t schema;
+	avro_schema_error_t avro_schema_error;
+
+	dir = opendir(dirpath);
+	if (dir == NULL) {
+		fprintf(stderr, "Unable to open '%s'\n", dirpath);
+		exit(EXIT_FAILURE);
+	}
+	do {
+		dent = readdir(dir);
+		if (dent && dent->d_name[0] != '.') {
+			int test_rval;
+			snprintf(filepath, sizeof(filepath), "%s/%s", dirpath,
+				 dent->d_name);
+			fprintf(stderr, "TEST %s...", filepath);
+			jsonlen = 0;
+			fp = fopen(filepath, "r");
+			if (!fp) {
+				fprintf(stderr, "can't open!\n");
+				exit(EXIT_FAILURE);
+			}
+			rval = fread(jsontext, 1, sizeof(jsontext) - 1, fp);
+			jsontext[rval] = '\0';
+			test_rval =
+			    avro_schema_from_json(jsontext, jsonlen, &schema,
+						  &avro_schema_error);
+			test_cases++;
+			if (test_rval == 0) {
+				if (should_pass) {
+					avro_schema_t schema_copy =
+					    avro_schema_copy(schema);
+					fprintf(stderr, "pass\n");
+					avro_schema_printf(schema, stderr);
+					if (!avro_schema_equal
+					    (schema, schema_copy)) {
+						fprintf(stderr,
+							"failed to avro_schema_equal(schema,avro_schema_copy())\n");
+						exit(EXIT_FAILURE);
+					}
+				} else {
+					/*
+					 * Unexpected success 
+					 */
+					fprintf(stderr,
+						"fail! (shouldn't succeed but did)\n");
+					exit(EXIT_FAILURE);
+				}
+			} else {
+				if (should_pass) {
+					fprintf(stderr,
+						"fail! (should have succeeded but didn't)\n");
+					exit(EXIT_FAILURE);
+				} else {
+					fprintf(stderr, "pass\n");
+				}
+			}
 		}
-	    }
 	}
-    }
-  while (dent != NULL);
+	while (dent != NULL);
 }
 
-int
-main (int argc, char *argv[])
+int main(int argc, char *argv[])
 {
-  char *srcdir = getenv ("srcdir");
-  char path[1024];
+	char *srcdir = getenv("srcdir");
+	char path[1024];
+
+	if (!srcdir) {
+		srcdir = ".";
+	}
 
-  if (!srcdir)
-    {
-      srcdir = ".";
-    }
-
-  /* Run the tests that should pass */
-  snprintf (path, sizeof (path), "%s/schema_tests/pass", srcdir);
-  fprintf (stderr, "RUNNING %s\n", path);
-  run_tests (path, 1);
-  snprintf (path, sizeof (path), "%s/schema_tests/fail", srcdir);
-  fprintf (stderr, "RUNNING %s\n", path);
-  run_tests (path, 0);
-
-  fprintf (stderr, "==================================================\n");
-  fprintf (stderr, "Finished running %d schema test cases successfully \n",
-	   test_cases);
-  fprintf (stderr, "==================================================\n");
+	/*
+	 * Run the tests that should pass 
+	 */
+	snprintf(path, sizeof(path), "%s/schema_tests/pass", srcdir);
+	fprintf(stderr, "RUNNING %s\n", path);
+	run_tests(path, 1);
+	snprintf(path, sizeof(path), "%s/schema_tests/fail", srcdir);
+	fprintf(stderr, "RUNNING %s\n", path);
+	run_tests(path, 0);
+
+	fprintf(stderr, "==================================================\n");
+	fprintf(stderr,
+		"Finished running %d schema test cases successfully \n",
+		test_cases);
+	fprintf(stderr, "==================================================\n");
 
-  return EXIT_SUCCESS;
+	return EXIT_SUCCESS;
 }



Mime
View raw message