/* -*- Mode: C -*-
 *
 * $Header: /home/gene/library/website/docsrc/lizard/src/RCS/make-data-files.c,v 395.1 2008/04/20 17:25:55 gene Exp $
 *
 * Copyright (c) 2005--2006 Gene Michael Stover.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */
 /*
 * Create all the static data files needed by the Lisp test programs.
 * Run this once & it creates all the files.
 */

#include "this.h"

/*
 */
static int
S_Init ()
{
  int rc = 0;

  setbuf (stdout, NULL);
  return rc;
}

/*
 */
static void
S_Uninit ()
{
}

/*
 * Write seven opaque octets.  That should create a file of 8 octets
 * because XDR writes blocks of 4 octets.
 */
static int
S_Make0010 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  static char arr[] = { 1, 2, 3, 4 };

  fp = fopen ("test0010.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_opaque (&xdrs, arr, 4)) {     /* write four octets */
      if (xdr_opaque (&xdrs, arr, 3)) {   /* write three octets */
        /* success */
      } else {
        printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
        rc = 3;
      }
    } else {
      printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write opaque data of length 1, contents = { 1 }.
 */
static int
S_Make0011 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  static char a[1] = { 1 };

  fp = fopen ("test0011.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_opaque (&xdrs, a, 1)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write opaque data of length 3, contents = { 1, 2, 3 }.
 */
static int
S_Make0012 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  static char a[] = { 1, 2, 3 };
  int alen = sizeof a / sizeof a[0];

  fp = fopen ("test0012.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_opaque (&xdrs, a, alen)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write opaque data of length 100, contents = { 1, 2, ... 99, 100 }.
 */
static int
S_Make0013 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  char a[100];
  int alen = sizeof a / sizeof a[0], i;

  fp = fopen ("test0013.data", "wb");
  if (fp != NULL) {
    for (i = 0; i < alen; ++i) a[i] = i + 1;
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_opaque (&xdrs, a, alen)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write opaque data of length 1024, contents = { 1, 2, ... 1023, 1024 }.
 */
static int
S_Make0014 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  char a[1024];
  int alen = sizeof a / sizeof a[0], i;

  fp = fopen ("test0014.data", "wb");
  if (fp != NULL) {
    for (i = 0; i < alen; ++i) a[i] = i + 1;
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_opaque (&xdrs, a, alen)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write an unsigned integer to a file.
 */
static int
S_Make0023 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  unsigned i = 1025;

  fp = fopen ("test0023.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_u_int (&xdrs, &i)) {
      /* success */
    } else {
      printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write two unsigned integers to a file.
 */
static int
S_Make0024 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  unsigned i = 123, j = 2049;

  fp = fopen ("test0024.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_u_int (&xdrs, &i) && xdr_u_int (&xdrs, &j)) {
      /* success */
    } else {
      printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write an unsigned integer to a file.
 */
static int
S_Make0027 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  unsigned i = 0x01020304;

  fp = fopen ("test0027.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_u_int (&xdrs, &i)) {
      /* success */
    } else {
      printf ("\n%s:%d: xdr_opaque failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write signed integer 0 to a file.
 */
static int
S_Make0050 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  int i = 0;

  fp = fopen ("test0050.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_int (&xdrs, &i)) {
      /* success */
    } else {
      printf ("\n%s:%d: xdr_int failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write signed integer -1 to a file.
 */
static int
S_Make0051 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  int i = -1;

  fp = fopen ("test0051.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_int (&xdrs, &i)) {
      /* success */
    } else {
      printf ("\n%s:%d: xdr_int failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write signed integer -2 to a file.
 */
static int
S_Make0052 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  int i = -2;

  fp = fopen ("test0052.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_int (&xdrs, &i)) {
      /* success */
    } else {
      printf ("\n%s:%d: xdr_int failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write the most negative signed integer allowed by XDR.
 */
static int
S_Make0053 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  int i = 0x80000000;

  fp = fopen ("test0053.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_int (&xdrs, &i)) {
      /* success */
    } else {
      printf ("\n%s:%d: xdr_int failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write the most positive signed integer allowed by XDR.
 */
static int
S_Make0054 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  int i = 0x7FFFFFFF;

  fp = fopen ("test0054.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_int (&xdrs, &i)) {
      /* success */
    } else {
      printf ("\n%s:%d: xdr_int failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write the string "hello" to a file called "test0110.data".
 */
static int
S_Make0110 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  char *str = "hello";

  fp = fopen ("test0110.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    /*
     * The maximum string doesn't matter here as long as it's
     * longer than the string.
     */
    if (xdr_string (&xdrs, &str, 100)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_string failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write the string "hello" to a file called "test0111.data".
 */
static int
S_Make0111 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  char *str = "hello";

  fp = fopen ("test0111.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_string (&xdrs, &str, 5)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_string failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write the string "hello" to a file called "test0113.data".
 */
static int
S_Make0113 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  char *str0 = "abcdefg";
  char *str1 = "ABCDEFGH";

  fp = fopen ("test0113.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_string (&xdrs, &str0, 100) &&
        xdr_string (&xdrs, &str1, 100)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_string failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a 32-bit floating point value 2.0 to a file.
 */
static int
S_Make0201 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  float x = 2.0;

  fp = fopen ("test0201.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_float (&xdrs, &x)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_float failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a 32-bit floating point value 0 to a file.
 */
static int
S_Make0202 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  float x = 0.0;

  fp = fopen ("test0202.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_float (&xdrs, &x)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_float failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a 32-bit floating point value to a file.
 */
static int
S_Make0203 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  float x = -2.0;

  fp = fopen ("test0203.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_float (&xdrs, &x)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_float failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a 32-bit floating point value to a file.
 */
static int
S_Make0204 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  float x = -0.5;

  fp = fopen ("test0204.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_float (&xdrs, &x)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_float failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a 32-bit floating point value to a file.
 */
static int
S_Make0205 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  float x = 1.5;

  fp = fopen ("test0205.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_float (&xdrs, &x)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_float failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a 32-bit floating point value to a file.
 */
static int
S_Make0206 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  float x = 1.55;

  fp = fopen ("test0206.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_float (&xdrs, &x)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_float failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a 32-bit floating point value to a file.
 */
static int
S_Make0207 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  float x = 1.555;

  fp = fopen ("test0207.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_float (&xdrs, &x)) {
        /* success */
    } else {
      printf ("\n%s:%d: xdr_float failed", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a 32-bit floating point value to a file.
 */
static int
S_Make0208 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  static float a[] = { 1.23e30, 1.23e17, 1.23e7, 123456.0, 1234.0,
                       13.0, 7.0, 0.0, 0.5, 0.05, 0.0123, 0.0123456 };
  size_t alen = sizeof a / sizeof a[0], i;

  fp = fopen ("test0208.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    for (i = 0; rc == 0 && i < alen; ++i) {
      if (xdr_float (&xdrs, &a[i])) {
        /* good so far */
      } else {
        printf ("\n%s:%d: xdr_float failed. i is %d.", __FILE__, __LINE__, i);
        rc = -42;
      }
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write JPEG from enumeration Format0337
 */
static int
S_Make0337 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  Format0337 x = jpeg;

  fp = fopen ("test0337.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_Format0337 (&xdrs, &x)) {
      /* good so far */
    } else {
      printf ("\n%s:%d: xdr_ug0331 failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a bunch of values from Format0337.
 */
static int
S_Make0338 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  Format0337 a0 = gif, a1 = jpeg, a2 = mpeg, a3 = mp3, a4 = mpeg;

  fp = fopen ("test0338.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_Format0337 (&xdrs, &a0) && xdr_Format0337 (&xdrs, &a1) &&
        xdr_Format0337 (&xdrs, &a2) && xdr_Format0337 (&xdrs, &a3) &&
        xdr_Format0337 (&xdrs, &a4)) {
      /* good so far */
    } else {
      printf ("\n%s:%d: xdr_Format0337 failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write an variable-length opaque of length 1, contents = { 1 }.
 */
static int
S_Make0351 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  static char a[] = { 1 };
  int alen = sizeof a / sizeof a[0];
  char *p;
  size_t sz = alen;

  fp = fopen ("test0351.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    p = a;
    if (xdr_bytes (&xdrs, &p, &sz, alen)) {
      /* good so far */
    } else {
      printf ("\n%s:%d: xdr_bytes failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * 
 */
static int
S_Make0353 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  int i;
  char a[100];
  int alen = sizeof a / sizeof a[0];
  char *p;
  size_t sz = alen;

  /*
   * Initialize a[].
   */
  for (i = 0; i < alen; ++i) {
    a[i] = i;
  }
  /*
   * Create the file.
   */
  fp = fopen ("test0353.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    for (i = 0; i < alen; ++i) {
      sz = i;
      p = a;
      if (xdr_bytes (&xdrs, &p, &sz, i)) {
        /* good so far */
      } else {
        printf ("\n%s:%d: xdr_bytes failed.", __FILE__, __LINE__);
        rc = -42;
      }
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write an array of 3 integers.
 */
static int
S_Make0371 ()
{
  int rc = 0;
  FILE *fp;
  XDR xdrs;
  static int a[3] = { 200, 201, 202 };
  int alen = sizeof a / sizeof a[0];

  fp = fopen ("test0371.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_vector (&xdrs, (char *) a, alen, sizeof a[0],
                    (xdrproc_t) &xdr_int)) {
      /* good so far */
    } else {
      printf ("\n%s:%d: xdr_vector failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write an Ug0581
 */
static int
S_Make0583 ()
{
  int rc = 0;
  Ug0581 x;
  FILE *fp;
  XDR xdrs;

  x.a = 5; x.b = 3.14; x.c = "yonkers";
  fp = fopen ("test0583.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_Ug0581 (&xdrs, &x)) {
      /* good */
    } else {
      printf ("\n%s:%d: xdr_Ug0581 failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write an onion.  Descriminant = 1, so value is an integer.
 */
static int
S_Make0603 ()
{
  int rc = 0;
  Onion x;
  FILE *fp;
  XDR xdrs;

  x.layers = 1; x.Onion_u.i = 5;
  fp = fopen ("test0603.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_Onion (&xdrs, &x)) {
      /* good */
    } else {
      printf ("\n%s:%d: xdr_Onion failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write an onion.  Descriminant = 2, which is illegal in the
 * version of Onion which Lisp knows.  We do this to verify
 * that Lisp will signal an error if we give it a descriminant
 * it doesn't know.
 */
static int
S_Make0604 ()
{
  int rc = 0;
  Onion x;
  FILE *fp;
  XDR xdrs;

  x.layers = 2; x.Onion_u.j = -10;
  fp = fopen ("test0604.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_Onion (&xdrs, &x)) {
      /* good */
    } else {
      printf ("\n%s:%d: xdr_Onion failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write an onion.  Descriminant = 3.  Value is a string,
 * "burger".
 */
static int
S_Make0609 ()
{
  int rc = 0;
  Onion x;
  FILE *fp;
  XDR xdrs;

  x.layers = 3; x.Onion_u.s31 = "burger";
  fp = fopen ("test0609.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_Onion (&xdrs, &x)) {
      /* good */
    } else {
      printf ("\n%s:%d: xdr_Onion failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a simple Linked.
 */
static int
S_Make0634 ()
{
  int rc = 0;
  Linked lnk;
  FILE *fp;
  XDR xdrs;

  lnk.x = "shaggy and Scooby"; lnk.link = NULL;
  fp = fopen ("test0634.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_Linked (&xdrs, &lnk)) {
      /* good */
    } else {
      printf ("\n%s:%d: xdr_Linked failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

/*
 * Write a three-node Linked.
 */
static int
S_Make0635 ()
{
  int rc = 0;
  static Linked third = { "third", NULL };
  static Linked second = { "second", &third };
  static Linked first = { "first", &second };
  FILE *fp;
  XDR xdrs;

  fp = fopen ("test0635.data", "wb");
  if (fp != NULL) {
    xdrstdio_create (&xdrs, fp, XDR_ENCODE);
    if (xdr_Linked (&xdrs, &first)) {
      /* good */
    } else {
      printf ("\n%s:%d: xdr_Linked failed.", __FILE__, __LINE__);
      rc = -42;
    }
    xdr_destroy (&xdrs);
    fclose (fp);
  } else {
    printf ("\n%s:%d:", __FILE__, __LINE__);
    printf (" fopen: %s", strerror (errno));
    rc = 3;
  }
  return rc;
}

static struct {
  char *name;
  int (*fn) ();
} S_lst[] = {
  { "S_Make0010", &S_Make0010 },
  { "S_Make0011", &S_Make0011 },
  { "S_Make0012", &S_Make0012 },
  { "S_Make0013", &S_Make0013 },
  { "S_Make0014", &S_Make0014 },
  { "S_Make0023", &S_Make0023 },
  { "S_Make0024", &S_Make0024 },
  { "S_Make0027", &S_Make0027 },
  { "S_Make0050", &S_Make0050 },
  { "S_Make0051", &S_Make0051 },
  { "S_Make0052", &S_Make0052 },
  { "S_Make0053", &S_Make0053 },
  { "S_Make0054", &S_Make0054 },
  { "S_Make0110", &S_Make0110 },
  { "S_Make0111", &S_Make0111 },
  { "S_Make0113", &S_Make0113 },
  { "S_Make0201", &S_Make0201 },
  { "S_Make0202", &S_Make0202 },
  { "S_Make0203", &S_Make0203 },
  { "S_Make0204", &S_Make0204 },
  { "S_Make0205", &S_Make0205 },
  { "S_Make0206", &S_Make0206 },
  { "S_Make0207", &S_Make0207 },
  { "S_Make0208", &S_Make0208 },
  { "S_Make0337", &S_Make0337 },
  { "S_Make0338", &S_Make0338 },
  { "S_Make0351", &S_Make0351 },
  { "S_Make0353", &S_Make0353 },
  { "S_Make0371", &S_Make0371 },
  { "S_Make0583", &S_Make0583 },
  { "S_Make0603", &S_Make0603 },
  { "S_Make0604", &S_Make0604 },
  { "S_Make0609", &S_Make0609 },
  { "S_Make0634", &S_Make0634 },
  { "S_Make0635", &S_Make0635 },
  { NULL, NULL }
};

int
main ()
{
  int rc = 0, i;

  if (S_Init () == 0) {
    for (i = 0; rc == 0 && S_lst[i].fn != NULL; ++i) {
      rc = (*S_lst[i].fn) ();
      if (rc != 0) {
        printf ("\n%s:%d:", __FILE__, __LINE__);
        printf (" %s failed", S_lst[i].name);
      }
    }
    S_Uninit ();
  } else {
    printf ("\n%s:%d: S_Init failed", __FILE__, __LINE__);
    rc = 231;
  }
  return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

/* --- end of file --- */
