OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [cris/] [rvdummy.c] - Diff between revs 227 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 227 Rev 816
/* Test-driver for the remote-virtual-component simulator framework
/* Test-driver for the remote-virtual-component simulator framework
   for GDB, the GNU Debugger.
   for GDB, the GNU Debugger.
 
 
   Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
   Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
/* Avoid any problems whatsoever building this program if we're not
/* Avoid any problems whatsoever building this program if we're not
   also building hardware support.  */
   also building hardware support.  */
 
 
#if !WITH_HW
#if !WITH_HW
int
int
main (int argc, char *argv[])
main (int argc, char *argv[])
{
{
  return 2;
  return 2;
}
}
#else
#else
 
 
#ifdef HAVE_CONFIG_H
#ifdef HAVE_CONFIG_H
#include "cconfig.h"
#include "cconfig.h"
#include "tconfig.h"
#include "tconfig.h"
#endif
#endif
 
 
#include "getopt.h"
#include "getopt.h"
#include "libiberty.h"
#include "libiberty.h"
 
 
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdio.h>
 
 
#ifdef HAVE_UNISTD_H
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#include <unistd.h>
#endif
#endif
#ifdef HAVE_STDLIB_H
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#include <stdlib.h>
#endif
#endif
#ifdef HAVE_STRING_H
#ifdef HAVE_STRING_H
#include <string.h>
#include <string.h>
#endif
#endif
 
 
#ifdef HAVE_SYS_TYPES_H
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#include <sys/types.h>
#endif
#endif
 
 
#ifdef HAVE_SYS_TIME_H
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#include <sys/time.h>
#endif
#endif
 
 
#ifdef HAVE_SYS_SELECT_H
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#include <sys/select.h>
#endif
#endif
 
 
#ifdef HAVE_ERRNO_H
#ifdef HAVE_ERRNO_H
#include <errno.h>
#include <errno.h>
#endif
#endif
 
 
/* Not guarded in dv-sockser.c, so why here.  */
/* Not guarded in dv-sockser.c, so why here.  */
#include <netinet/in.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/socket.h>
 
 
enum rv_command {
enum rv_command {
  RV_READ_CMD = 0,
  RV_READ_CMD = 0,
  RV_WRITE_CMD = 1,
  RV_WRITE_CMD = 1,
  RV_IRQ_CMD = 2,
  RV_IRQ_CMD = 2,
  RV_MEM_RD_CMD = 3,
  RV_MEM_RD_CMD = 3,
  RV_MEM_WR_CMD = 4,
  RV_MEM_WR_CMD = 4,
  RV_MBOX_HANDLE_CMD = 5,
  RV_MBOX_HANDLE_CMD = 5,
  RV_MBOX_PUT_CMD = 6,
  RV_MBOX_PUT_CMD = 6,
  RV_WATCHDOG_CMD = 7
  RV_WATCHDOG_CMD = 7
};
};
 
 
enum opts { OPT_PORT = 1, OPT_TIMEOUT, OPT_VERBOSE };
enum opts { OPT_PORT = 1, OPT_TIMEOUT, OPT_VERBOSE };
 
 
struct option longopts[] =
struct option longopts[] =
  {
  {
    {"port", required_argument, NULL, OPT_PORT},
    {"port", required_argument, NULL, OPT_PORT},
    {"timeout", required_argument, NULL, OPT_TIMEOUT},
    {"timeout", required_argument, NULL, OPT_TIMEOUT},
    {"verbose", no_argument, NULL, OPT_VERBOSE},
    {"verbose", no_argument, NULL, OPT_VERBOSE},
    {NULL, 0, NULL, 0}
    {NULL, 0, NULL, 0}
  };
  };
 
 
int port = 10000;
int port = 10000;
time_t timeout = 30000;
time_t timeout = 30000;
char *progname = "(unknown)";
char *progname = "(unknown)";
int verbose = 0;
int verbose = 0;
 
 
/* Required forward-declarations.  */
/* Required forward-declarations.  */
static void handle_input_file (int, char *);
static void handle_input_file (int, char *);
 
 
/* Set up a "server" listening to the port in PORT for a raw TCP
/* Set up a "server" listening to the port in PORT for a raw TCP
   connection.  Return a file descriptor for the connection or -1 on
   connection.  Return a file descriptor for the connection or -1 on
   error.  */
   error.  */
 
 
int setupsocket (void)
int setupsocket (void)
{
{
  int s;
  int s;
  socklen_t len;
  socklen_t len;
  int reuse = 1;
  int reuse = 1;
  struct sockaddr_in sa_in;
  struct sockaddr_in sa_in;
  struct sockaddr_in from;
  struct sockaddr_in from;
 
 
  len = sizeof (from);
  len = sizeof (from);
  memset (&from, 0, len);
  memset (&from, 0, len);
  memset (&sa_in, 0, sizeof (sa_in));
  memset (&sa_in, 0, sizeof (sa_in));
 
 
  s = socket (AF_INET, SOCK_STREAM, 0);
  s = socket (AF_INET, SOCK_STREAM, 0);
  if (s < 0)
  if (s < 0)
    return -1;
    return -1;
 
 
  if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof reuse) != 0)
  if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof reuse) != 0)
    return -1;
    return -1;
 
 
  sa_in.sin_port = htons (port);
  sa_in.sin_port = htons (port);
  sa_in.sin_family = AF_INET;
  sa_in.sin_family = AF_INET;
 
 
  if (bind (s, (struct sockaddr *) & sa_in, sizeof sa_in) < 0)
  if (bind (s, (struct sockaddr *) & sa_in, sizeof sa_in) < 0)
    return -1;
    return -1;
 
 
  if (listen (s, 1) < 0)
  if (listen (s, 1) < 0)
    return -1;
    return -1;
 
 
  return accept (s, (struct sockaddr *) &from, &len);
  return accept (s, (struct sockaddr *) &from, &len);
}
}
 
 
/* Basic host-to-little-endian 32-bit value.  Could use the BFD
/* Basic host-to-little-endian 32-bit value.  Could use the BFD
   machinery, but let's avoid it for this only dependency.  */
   machinery, but let's avoid it for this only dependency.  */
 
 
static void
static void
h2le32 (unsigned char *dest, unsigned int val)
h2le32 (unsigned char *dest, unsigned int val)
{
{
  dest[0] = val & 255;
  dest[0] = val & 255;
  dest[1] = (val >> 8) & 255;
  dest[1] = (val >> 8) & 255;
  dest[2] = (val >> 16) & 255;
  dest[2] = (val >> 16) & 255;
  dest[3] = (val >> 24) & 255;
  dest[3] = (val >> 24) & 255;
}
}
 
 
/* Send a blob of data.  */
/* Send a blob of data.  */
 
 
static void
static void
send_output (int fd, unsigned char *buf, int nbytes)
send_output (int fd, unsigned char *buf, int nbytes)
{
{
  while (nbytes > 0)
  while (nbytes > 0)
    {
    {
      ssize_t written = write (fd, buf, nbytes);
      ssize_t written = write (fd, buf, nbytes);
      if (written < 0)
      if (written < 0)
        {
        {
          fprintf (stderr, "%s: write to socket failed: %s\n",
          fprintf (stderr, "%s: write to socket failed: %s\n",
                  progname, strerror (errno));
                  progname, strerror (errno));
          exit (2);
          exit (2);
        }
        }
      nbytes -= written;
      nbytes -= written;
    }
    }
}
}
 
 
/* Receive a blob of data, NBYTES large.  Compare to the first NCOMP
/* Receive a blob of data, NBYTES large.  Compare to the first NCOMP
   bytes of BUF; if not a match, write error message to stderr and
   bytes of BUF; if not a match, write error message to stderr and
   exit (2).  Else put it in buf.  */
   exit (2).  Else put it in buf.  */
 
 
static void
static void
expect_input (int fd, unsigned char *buf, int nbytes, int ncomp)
expect_input (int fd, unsigned char *buf, int nbytes, int ncomp)
{
{
  unsigned char byt;
  unsigned char byt;
  int i;
  int i;
 
 
  for (i = 0; i < nbytes; i++)
  for (i = 0; i < nbytes; i++)
    {
    {
      int r;
      int r;
 
 
      do
      do
        {
        {
          errno = 0;
          errno = 0;
          r = read (fd, &byt, 1);
          r = read (fd, &byt, 1);
        }
        }
      while (r <= 0 && (r == 0 || errno == EAGAIN));
      while (r <= 0 && (r == 0 || errno == EAGAIN));
 
 
      if (r != 1)
      if (r != 1)
        {
        {
          fprintf (stderr, "%s: read from socket failed: %s",
          fprintf (stderr, "%s: read from socket failed: %s",
                  progname, strerror (errno));
                  progname, strerror (errno));
          exit (2);
          exit (2);
        }
        }
 
 
      if (i < ncomp && byt != buf[i])
      if (i < ncomp && byt != buf[i])
        {
        {
          int j;
          int j;
          fprintf (stderr, "%s: unexpected input,\n ", progname);
          fprintf (stderr, "%s: unexpected input,\n ", progname);
          if (i == 0)
          if (i == 0)
            fprintf (stderr, "nothing,");
            fprintf (stderr, "nothing,");
          else
          else
            for (j = 0; j < i; j++)
            for (j = 0; j < i; j++)
              fprintf (stderr, "%02x", buf[j]);
              fprintf (stderr, "%02x", buf[j]);
          fprintf (stderr, "\nthen %02x instead of %02x\n", byt, buf[i]);
          fprintf (stderr, "\nthen %02x instead of %02x\n", byt, buf[i]);
          exit (2);
          exit (2);
        }
        }
      else
      else
        buf[i] = byt;
        buf[i] = byt;
    }
    }
}
}
 
 
/* Handle everything about a nil-terminated line of input.
/* Handle everything about a nil-terminated line of input.
   Call exit (2) on error with error text on stderr.  */
   Call exit (2) on error with error text on stderr.  */
 
 
static void
static void
handle_input (int fd, char *buf, char *fname, int lineno)
handle_input (int fd, char *buf, char *fname, int lineno)
{
{
  int nbytes = 0;
  int nbytes = 0;
  int n = -1;
  int n = -1;
  char *s = buf + 2;
  char *s = buf + 2;
  unsigned int data;
  unsigned int data;
  static unsigned char bytes[1024];
  static unsigned char bytes[1024];
  int i;
  int i;
 
 
  memset (bytes, 0, sizeof bytes);
  memset (bytes, 0, sizeof bytes);
  lineno++;
  lineno++;
 
 
  if (buf[1] != ',')
  if (buf[1] != ',')
    goto syntax_error;
    goto syntax_error;
 
 
  switch (buf[0])
  switch (buf[0])
    {
    {
      /* Comment characters and empty lines.  */
      /* Comment characters and empty lines.  */
    case 0: case '!': case '#':
    case 0: case '!': case '#':
      break;
      break;
 
 
      /* Include another file.  */
      /* Include another file.  */
    case '@':
    case '@':
      handle_input_file (fd, s);
      handle_input_file (fd, s);
      break;
      break;
 
 
      /* Raw input (to be expected).  */
      /* Raw input (to be expected).  */
    case 'i':
    case 'i':
      do
      do
        {
        {
          n = -1;
          n = -1;
          sscanf (s, "%02x%n", &data, &n);
          sscanf (s, "%02x%n", &data, &n);
          s += n;
          s += n;
          if (n > 0)
          if (n > 0)
            bytes[nbytes++] = data;
            bytes[nbytes++] = data;
        }
        }
      while (n > 0);
      while (n > 0);
      expect_input (fd, bytes, nbytes, nbytes);
      expect_input (fd, bytes, nbytes, nbytes);
      if (verbose)
      if (verbose)
        {
        {
          printf ("i,");
          printf ("i,");
          for (i = 0; i < nbytes; i++)
          for (i = 0; i < nbytes; i++)
            printf ("%02x", bytes[i]);
            printf ("%02x", bytes[i]);
          printf ("\n");
          printf ("\n");
        }
        }
      break;
      break;
 
 
      /* Raw output (to be written).  */
      /* Raw output (to be written).  */
    case 'o':
    case 'o':
      do
      do
        {
        {
          n = -1;
          n = -1;
          sscanf (s, "%02x%n", &data, &n);
          sscanf (s, "%02x%n", &data, &n);
          if (n > 0)
          if (n > 0)
            {
            {
              s += n;
              s += n;
              bytes[nbytes++] = data;
              bytes[nbytes++] = data;
            }
            }
        }
        }
      while (n > 0);
      while (n > 0);
      if (*s != 0)
      if (*s != 0)
        goto syntax_error;
        goto syntax_error;
      send_output (fd, bytes, nbytes);
      send_output (fd, bytes, nbytes);
      if (verbose)
      if (verbose)
        {
        {
          printf ("o,");
          printf ("o,");
          for (i = 0; i < nbytes; i++)
          for (i = 0; i < nbytes; i++)
            printf ("%02x", bytes[i]);
            printf ("%02x", bytes[i]);
          printf ("\n");
          printf ("\n");
        }
        }
      break;
      break;
 
 
      /* Read a register.  */
      /* Read a register.  */
    case 'r':
    case 'r':
      {
      {
        unsigned int addr;
        unsigned int addr;
        sscanf (s, "%x,%x%n", &addr, &data, &n);
        sscanf (s, "%x,%x%n", &addr, &data, &n);
        if (n < 0 || s[n] != 0)
        if (n < 0 || s[n] != 0)
          goto syntax_error;
          goto syntax_error;
        bytes[0] = 11;
        bytes[0] = 11;
        bytes[1] = 0;
        bytes[1] = 0;
        bytes[2] = RV_READ_CMD;
        bytes[2] = RV_READ_CMD;
        h2le32 (bytes + 3, addr);
        h2le32 (bytes + 3, addr);
        expect_input (fd, bytes, 11, 7);
        expect_input (fd, bytes, 11, 7);
        h2le32 (bytes + 7, data);
        h2le32 (bytes + 7, data);
        send_output (fd, bytes, 11);
        send_output (fd, bytes, 11);
        if (verbose)
        if (verbose)
          printf ("r,%x,%x\n", addr, data);
          printf ("r,%x,%x\n", addr, data);
      }
      }
      break;
      break;
 
 
      /* Write a register.  */
      /* Write a register.  */
    case 'w':
    case 'w':
      {
      {
        unsigned int addr;
        unsigned int addr;
        sscanf (s, "%x,%x%n", &addr, &data, &n);
        sscanf (s, "%x,%x%n", &addr, &data, &n);
        if (n < 0 || s[n] != 0)
        if (n < 0 || s[n] != 0)
          goto syntax_error;
          goto syntax_error;
        bytes[0] = 11;
        bytes[0] = 11;
        bytes[1] = 0;
        bytes[1] = 0;
        bytes[2] = RV_WRITE_CMD;
        bytes[2] = RV_WRITE_CMD;
        h2le32 (bytes + 3, addr);
        h2le32 (bytes + 3, addr);
        h2le32 (bytes + 7, data);
        h2le32 (bytes + 7, data);
        expect_input (fd, bytes, 11, 11);
        expect_input (fd, bytes, 11, 11);
        send_output (fd, bytes, 11);
        send_output (fd, bytes, 11);
        if (verbose)
        if (verbose)
          printf ("w,%x,%x\n", addr, data);
          printf ("w,%x,%x\n", addr, data);
      }
      }
      break;
      break;
 
 
      /* Wait for some milliseconds.  */
      /* Wait for some milliseconds.  */
    case 't':
    case 't':
      {
      {
        int del = 0;
        int del = 0;
        struct timeval to;
        struct timeval to;
        sscanf (s, "%d%n", &del, &n);
        sscanf (s, "%d%n", &del, &n);
        if (n < 0 || s[n] != 0 || del == 0)
        if (n < 0 || s[n] != 0 || del == 0)
          goto syntax_error;
          goto syntax_error;
 
 
        to.tv_sec = del / 1000;
        to.tv_sec = del / 1000;
        to.tv_usec = (del % 1000) * 1000;
        to.tv_usec = (del % 1000) * 1000;
 
 
        if (select (0, NULL, NULL, NULL, &to) != 0)
        if (select (0, NULL, NULL, NULL, &to) != 0)
          {
          {
            fprintf (stderr, "%s: problem waiting for %d ms:\n %s\n",
            fprintf (stderr, "%s: problem waiting for %d ms:\n %s\n",
                     progname, del, strerror (errno));
                     progname, del, strerror (errno));
            exit (2);
            exit (2);
          }
          }
        if (verbose)
        if (verbose)
          printf ("t,%d\n", del);
          printf ("t,%d\n", del);
      }
      }
      break;
      break;
 
 
      /* Expect a watchdog command.  */
      /* Expect a watchdog command.  */
    case 'W':
    case 'W':
      if (*s != 0)
      if (*s != 0)
        goto syntax_error;
        goto syntax_error;
      bytes[0] = 3;
      bytes[0] = 3;
      bytes[1] = 0;
      bytes[1] = 0;
      bytes[2] = RV_WATCHDOG_CMD;
      bytes[2] = RV_WATCHDOG_CMD;
      expect_input (fd, bytes, 3, 3);
      expect_input (fd, bytes, 3, 3);
      if (verbose)
      if (verbose)
        printf ("W\n");
        printf ("W\n");
      break;
      break;
 
 
      /* Send an IRQ notification.  */
      /* Send an IRQ notification.  */
    case 'I':
    case 'I':
      sscanf (s, "%x%n", &data, &n);
      sscanf (s, "%x%n", &data, &n);
      if (n < 0 || s[n] != 0)
      if (n < 0 || s[n] != 0)
        goto syntax_error;
        goto syntax_error;
      bytes[0] = 7;
      bytes[0] = 7;
      bytes[1] = 0;
      bytes[1] = 0;
      bytes[2] = RV_IRQ_CMD;
      bytes[2] = RV_IRQ_CMD;
      h2le32 (bytes + 3, data);
      h2le32 (bytes + 3, data);
      send_output (fd, bytes, 7);
      send_output (fd, bytes, 7);
      if (verbose)
      if (verbose)
        printf ("I,%x\n", data);
        printf ("I,%x\n", data);
      break;
      break;
 
 
      /* DMA store (to CPU).  */
      /* DMA store (to CPU).  */
    case 's':
    case 's':
      {
      {
        unsigned int addr;
        unsigned int addr;
        sscanf (s, "%x,%n", &addr, &n);
        sscanf (s, "%x,%n", &addr, &n);
 
 
        if (n < 0 || s[n] == 0)
        if (n < 0 || s[n] == 0)
          goto syntax_error;
          goto syntax_error;
        s += n;
        s += n;
        do
        do
          {
          {
            n = -1;
            n = -1;
            sscanf (s, "%02x%n", &data, &n);
            sscanf (s, "%02x%n", &data, &n);
            if (n > 0)
            if (n > 0)
              {
              {
                s += n;
                s += n;
                bytes[11 + nbytes++] = data;
                bytes[11 + nbytes++] = data;
              }
              }
          }
          }
        while (n > 0);
        while (n > 0);
 
 
        if (*s != 0)
        if (*s != 0)
          goto syntax_error;
          goto syntax_error;
        h2le32 (bytes, nbytes + 11);
        h2le32 (bytes, nbytes + 11);
        bytes[2] = RV_MEM_WR_CMD;
        bytes[2] = RV_MEM_WR_CMD;
        h2le32 (bytes + 3, addr);
        h2le32 (bytes + 3, addr);
        h2le32 (bytes + 7, nbytes);
        h2le32 (bytes + 7, nbytes);
        send_output (fd, bytes, nbytes + 11);
        send_output (fd, bytes, nbytes + 11);
        if (verbose)
        if (verbose)
          {
          {
            printf ("s,%x,", addr);
            printf ("s,%x,", addr);
            for (i = 0; i < nbytes; i++)
            for (i = 0; i < nbytes; i++)
              printf ("%02x", bytes[i]);
              printf ("%02x", bytes[i]);
            printf ("\n");
            printf ("\n");
          }
          }
      }
      }
      break;
      break;
 
 
      /* DMA load (from CPU).  */
      /* DMA load (from CPU).  */
    case 'l':
    case 'l':
      {
      {
        unsigned int addr;
        unsigned int addr;
        sscanf (s, "%x,%n", &addr, &n);
        sscanf (s, "%x,%n", &addr, &n);
 
 
        if (n < 0 || s[n] == 0)
        if (n < 0 || s[n] == 0)
          goto syntax_error;
          goto syntax_error;
        s += n;
        s += n;
        do
        do
          {
          {
            n = -1;
            n = -1;
            sscanf (s, "%02x%n", &data, &n);
            sscanf (s, "%02x%n", &data, &n);
            if (n > 0)
            if (n > 0)
              {
              {
                s += n;
                s += n;
                bytes[11 + nbytes++] = data;
                bytes[11 + nbytes++] = data;
              }
              }
          }
          }
        while (n > 0);
        while (n > 0);
 
 
        if (*s != 0)
        if (*s != 0)
          goto syntax_error;
          goto syntax_error;
        h2le32 (bytes, nbytes + 11);
        h2le32 (bytes, nbytes + 11);
        bytes[0] = 11;
        bytes[0] = 11;
        bytes[1] = 0;
        bytes[1] = 0;
        bytes[2] = RV_MEM_RD_CMD;
        bytes[2] = RV_MEM_RD_CMD;
        h2le32 (bytes + 3, addr);
        h2le32 (bytes + 3, addr);
        h2le32 (bytes + 7, nbytes);
        h2le32 (bytes + 7, nbytes);
        send_output (fd, bytes, 11);
        send_output (fd, bytes, 11);
        bytes[0] = (nbytes + 11) & 255;
        bytes[0] = (nbytes + 11) & 255;
        bytes[1] = ((nbytes + 11) >> 8) & 255;
        bytes[1] = ((nbytes + 11) >> 8) & 255;
        expect_input (fd, bytes, nbytes + 11, nbytes + 11);
        expect_input (fd, bytes, nbytes + 11, nbytes + 11);
        if (verbose)
        if (verbose)
          {
          {
            printf ("l,%x,", addr);
            printf ("l,%x,", addr);
            for (i = 0; i < nbytes; i++)
            for (i = 0; i < nbytes; i++)
              printf ("%02x", bytes[i]);
              printf ("%02x", bytes[i]);
            printf ("\n");
            printf ("\n");
          }
          }
      }
      }
      break;
      break;
 
 
    syntax_error:
    syntax_error:
    default:
    default:
      fprintf (stderr, "%s: invalid command line in %s:%d:\n %s",
      fprintf (stderr, "%s: invalid command line in %s:%d:\n %s",
               progname, fname, lineno, strerror (errno));
               progname, fname, lineno, strerror (errno));
      exit (2);
      exit (2);
    }
    }
}
}
 
 
/* Loop over the contents of FNAME, using handle_input to parse each line.
/* Loop over the contents of FNAME, using handle_input to parse each line.
   Errors to stderr, exit (2).  */
   Errors to stderr, exit (2).  */
 
 
static void
static void
handle_input_file (int fd, char *fname)
handle_input_file (int fd, char *fname)
{
{
  static char buf[2048] = {0};
  static char buf[2048] = {0};
  int lineno = 0;
  int lineno = 0;
  FILE *f = fopen (fname, "r");
  FILE *f = fopen (fname, "r");
 
 
  if (f == NULL)
  if (f == NULL)
    {
    {
      fprintf (stderr, "%s: problem opening %s: %s\n",
      fprintf (stderr, "%s: problem opening %s: %s\n",
               progname, fname, strerror (errno));
               progname, fname, strerror (errno));
      exit (2);
      exit (2);
    }
    }
 
 
  /* Let's cut the buffer short, so we always get a newline.  */
  /* Let's cut the buffer short, so we always get a newline.  */
  while (fgets (buf, sizeof (buf) - 1, f) != NULL)
  while (fgets (buf, sizeof (buf) - 1, f) != NULL)
    {
    {
      buf[strlen (buf) - 1] = 0;
      buf[strlen (buf) - 1] = 0;
      lineno++;
      lineno++;
      handle_input (fd, buf, fname, lineno);
      handle_input (fd, buf, fname, lineno);
    }
    }
 
 
  fclose (f);
  fclose (f);
}
}
 
 
int
int
main (int argc, char *argv[])
main (int argc, char *argv[])
{
{
  int optc;
  int optc;
  int fd;
  int fd;
  FILE *f;
  FILE *f;
  int i;
  int i;
 
 
  progname = argv[0];
  progname = argv[0];
  while ((optc = getopt_long (argc, argv, "", longopts, NULL)) != -1)
  while ((optc = getopt_long (argc, argv, "", longopts, NULL)) != -1)
    switch (optc)
    switch (optc)
      {
      {
      case OPT_PORT:
      case OPT_PORT:
        port = atoi (optarg);
        port = atoi (optarg);
        break;
        break;
 
 
      case OPT_TIMEOUT:
      case OPT_TIMEOUT:
        timeout = (time_t) atoi (optarg);
        timeout = (time_t) atoi (optarg);
        break;
        break;
 
 
      case OPT_VERBOSE:
      case OPT_VERBOSE:
        verbose = 1;
        verbose = 1;
        break;
        break;
      }
      }
 
 
  fd = setupsocket ();
  fd = setupsocket ();
  if (fd < 0)
  if (fd < 0)
    {
    {
      fprintf (stderr, "%s: problem setting up the connection: %s\n",
      fprintf (stderr, "%s: problem setting up the connection: %s\n",
               progname, strerror (errno));
               progname, strerror (errno));
      exit (2);
      exit (2);
    }
    }
 
 
  for (i = optind; i < argc; i++)
  for (i = optind; i < argc; i++)
    handle_input_file (fd, argv[i]);
    handle_input_file (fd, argv[i]);
 
 
  /* FIXME: option-controlled test for remaining input?  */
  /* FIXME: option-controlled test for remaining input?  */
  close (fd);
  close (fd);
  return 1;
  return 1;
}
}
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.