OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gdb/] [gdb-6.8/] [gdb-6.8.openrisc-2.1/] [readline/] [examples/] [rl-fgets.c] - Diff between revs 24 and 33

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

Rev 24 Rev 33
/*
/*
Date: Tue, 16 Mar 2004 19:38:40 -0800
Date: Tue, 16 Mar 2004 19:38:40 -0800
From: Harold Levy <Harold.Levy@synopsys.com>
From: Harold Levy <Harold.Levy@synopsys.com>
Subject: fgets(stdin) --> readline() redirector
Subject: fgets(stdin) --> readline() redirector
To: chet@po.cwru.edu
To: chet@po.cwru.edu
 
 
Hi Chet,
Hi Chet,
 
 
Here is something you may find useful enough to include in the readline
Here is something you may find useful enough to include in the readline
distribution.  It is a shared library that redirects calls to fgets(stdin)
distribution.  It is a shared library that redirects calls to fgets(stdin)
to readline() via LD_PRELOAD, and it supports a custom prompt and list of
to readline() via LD_PRELOAD, and it supports a custom prompt and list of
command names.  Many people have asked me for this file, so I thought I'd
command names.  Many people have asked me for this file, so I thought I'd
pass it your way in hope of just including it with readline to begin with.
pass it your way in hope of just including it with readline to begin with.
 
 
Best Regards,
Best Regards,
 
 
-Harold
-Harold
*/
*/
 
 
/******************************************************************************
/******************************************************************************
*******************************************************************************
*******************************************************************************
 
 
  FILE NAME:    fgets.c                  TARGET:   libfgets.so
  FILE NAME:    fgets.c                  TARGET:   libfgets.so
  AUTHOR:       Harold Levy              VERSION:  1.0
  AUTHOR:       Harold Levy              VERSION:  1.0
                hlevy@synopsys.com
                hlevy@synopsys.com
 
 
  ABSTRACT:  Customize fgets() behavior via LD_PRELOAD in the following ways:
  ABSTRACT:  Customize fgets() behavior via LD_PRELOAD in the following ways:
 
 
    -- If fgets(stdin) is called, redirect to GNU readline() to obtain
    -- If fgets(stdin) is called, redirect to GNU readline() to obtain
       command-line editing, file-name completion, history, etc.
       command-line editing, file-name completion, history, etc.
 
 
    -- A list of commands for command-name completion can be configured by
    -- A list of commands for command-name completion can be configured by
       setting the environment-variable FGETS_COMMAND_FILE to a file containing
       setting the environment-variable FGETS_COMMAND_FILE to a file containing
       the list of commands to be used.
       the list of commands to be used.
 
 
    -- Command-line editing with readline() works best when the prompt string
    -- Command-line editing with readline() works best when the prompt string
       is known; you can set this with the FGETS_PROMPT environment variable.
       is known; you can set this with the FGETS_PROMPT environment variable.
 
 
    -- There special strings that libfgets will interpret as internal commands:
    -- There special strings that libfgets will interpret as internal commands:
 
 
           _fgets_reset_    reset the command list
           _fgets_reset_    reset the command list
 
 
           _fgets_dump_     dump status
           _fgets_dump_     dump status
 
 
           _fgets_debug_    toggle debug messages
           _fgets_debug_    toggle debug messages
 
 
  HOW TO BUILD:  Here are examples of how to build libfgets.so on various
  HOW TO BUILD:  Here are examples of how to build libfgets.so on various
  platforms; you will have to add -I and -L flags to configure access to
  platforms; you will have to add -I and -L flags to configure access to
  the readline header and library files.
  the readline header and library files.
 
 
  (32-bit builds with gcc)
  (32-bit builds with gcc)
  AIX:   gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lreadline -ltermcap
  AIX:   gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lreadline -ltermcap
  HP-UX: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldld -lreadline
  HP-UX: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldld -lreadline
  Linux: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lreadline
  Linux: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lreadline
  SunOS: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lgen -lreadline
  SunOS: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lgen -lreadline
 
 
  (64-bit builds without gcc)
  (64-bit builds without gcc)
  SunOS: SUNWspro/bin/cc -D_LARGEFILE64_SOURCE=1 -xtarget=ultra -xarch=v9 \
  SunOS: SUNWspro/bin/cc -D_LARGEFILE64_SOURCE=1 -xtarget=ultra -xarch=v9 \
           -KPIC fgets.c -Bdynamic -lc -ldl -lgen -ltermcap -lreadline
           -KPIC fgets.c -Bdynamic -lc -ldl -lgen -ltermcap -lreadline
 
 
  HOW TO USE:  Different operating systems have different levels of support
  HOW TO USE:  Different operating systems have different levels of support
  for the LD_PRELOAD concept.  The generic method for 32-bit platforms is to
  for the LD_PRELOAD concept.  The generic method for 32-bit platforms is to
  put libtermcap.so, libfgets.so, and libreadline.so (with absolute paths)
  put libtermcap.so, libfgets.so, and libreadline.so (with absolute paths)
  in the LD_PRELOAD environment variable, and to put their parent directories
  in the LD_PRELOAD environment variable, and to put their parent directories
  in the LD_LIBRARY_PATH environment variable.  Unfortunately there is no
  in the LD_LIBRARY_PATH environment variable.  Unfortunately there is no
  generic method for 64-bit platforms; e.g. for 64-bit SunOS, you would have
  generic method for 64-bit platforms; e.g. for 64-bit SunOS, you would have
  to build both 32-bit and 64-bit libfgets and libreadline libraries, and
  to build both 32-bit and 64-bit libfgets and libreadline libraries, and
  use the LD_FLAGS_32 and LD_FLAGS_64 environment variables with preload and
  use the LD_FLAGS_32 and LD_FLAGS_64 environment variables with preload and
  library_path configurations (a mix of 32-bit and 64-bit calls are made under
  library_path configurations (a mix of 32-bit and 64-bit calls are made under
  64-bit SunOS).
  64-bit SunOS).
 
 
  EXAMPLE WRAPPER:  Here is an example shell script wrapper around the
  EXAMPLE WRAPPER:  Here is an example shell script wrapper around the
  program "foo" that uses fgets() for command-line input:
  program "foo" that uses fgets() for command-line input:
 
 
      #!/bin/csh
      #!/bin/csh
      #### replace this with the libtermcap.so directory:
      #### replace this with the libtermcap.so directory:
      set dir1 = "/usr/lib"
      set dir1 = "/usr/lib"
      #### replace this with the libfgets.so directory:
      #### replace this with the libfgets.so directory:
      set dir2 = "/usr/fgets"
      set dir2 = "/usr/fgets"
      #### replace this with the libreadline.so directory:
      #### replace this with the libreadline.so directory:
      set dir3 = "/usr/local/lib"
      set dir3 = "/usr/local/lib"
      set lib1 = "${dir1}/libtermcap.so"
      set lib1 = "${dir1}/libtermcap.so"
      set lib2 = "${dir2}/libfgets.so"
      set lib2 = "${dir2}/libfgets.so"
      set lib3 = "${dir3}/libreadline.so"
      set lib3 = "${dir3}/libreadline.so"
      if ( "${?LD_PRELOAD}" ) then
      if ( "${?LD_PRELOAD}" ) then
        setenv LD_PRELOAD "${lib1}:${lib2}:${lib3}:${LD_PRELOAD}"
        setenv LD_PRELOAD "${lib1}:${lib2}:${lib3}:${LD_PRELOAD}"
      else
      else
        setenv LD_PRELOAD "${lib1}:${lib2}:${lib3}"
        setenv LD_PRELOAD "${lib1}:${lib2}:${lib3}"
      endif
      endif
      if ( "${?LD_LIBRARY_PATH}" ) then
      if ( "${?LD_LIBRARY_PATH}" ) then
        setenv LD_LIBRARY_PATH "${dir1}:${dir2}:${dir3}:${LD_LIBRARY_PATH}"
        setenv LD_LIBRARY_PATH "${dir1}:${dir2}:${dir3}:${LD_LIBRARY_PATH}"
      else
      else
        setenv LD_LIBRARY_PATH "${dir1}:${dir2}:${dir3}"
        setenv LD_LIBRARY_PATH "${dir1}:${dir2}:${dir3}"
      endif
      endif
      setenv FGETS_COMMAND_FILE "${dir2}/foo.commands"
      setenv FGETS_COMMAND_FILE "${dir2}/foo.commands"
      setenv FGETS_PROMPT       "foo> "
      setenv FGETS_PROMPT       "foo> "
      exec "foo" $*
      exec "foo" $*
 
 
  Copyright (C)©2003-2004 Harold Levy.
  Copyright (C)©2003-2004 Harold Levy.
 
 
  This code links to the GNU readline library, and as such is bound by the
  This code links to the GNU readline library, and as such is bound by the
  terms of the GNU General Public License as published by the Free Software
  terms of the GNU General Public License as published by the Free Software
  Foundation, either version 2 or (at your option) any later version.
  Foundation, either version 2 or (at your option) any later version.
 
 
  The GNU General Public License is often shipped with GNU software, and is
  The GNU General Public License is often shipped with GNU software, and is
  generally kept in a file called COPYING or LICENSE.  If you do not have a
  generally kept in a file called COPYING or LICENSE.  If you do not have a
  copy of the license, write to the Free Software Foundation, 59 Temple Place,
  copy of the license, write to the Free Software Foundation, 59 Temple Place,
  Suite 330, Boston, MA 02111 USA.
  Suite 330, Boston, MA 02111 USA.
 
 
  This program is distributed in the hope that it will be useful, but WITHOUT
  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
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.
  details.
 
 
*******************************************************************************
*******************************************************************************
******************************************************************************/
******************************************************************************/
 
 
 
 


#include <dlfcn.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdio.h>
#include <strings.h>
#include <strings.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
 
 
#include <readline/readline.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <readline/history.h>
 
 
 
 


/* for dynamically connecting to the native fgets() */
/* for dynamically connecting to the native fgets() */
#if defined(RTLD_NEXT)
#if defined(RTLD_NEXT)
#define REAL_LIBC RTLD_NEXT
#define REAL_LIBC RTLD_NEXT
#else
#else
#define REAL_LIBC ((void *) -1L)
#define REAL_LIBC ((void *) -1L)
#endif
#endif
typedef char * ( * fgets_t ) ( char * s, int n, FILE * stream ) ;
typedef char * ( * fgets_t ) ( char * s, int n, FILE * stream ) ;
 
 
 
 


/* private data */
/* private data */
/* -- writeable data is stored in the shared library's data segment
/* -- writeable data is stored in the shared library's data segment
   -- every process that uses the shared library gets a private memory copy of
   -- every process that uses the shared library gets a private memory copy of
      its entire data segment
      its entire data segment
   -- static data in the shared library is not copied to the application
   -- static data in the shared library is not copied to the application
   -- only read-only (i.e. 'const') data is stored in the shared library's
   -- only read-only (i.e. 'const') data is stored in the shared library's
      text segment
      text segment
*/
*/
static char ** my_fgets_names           = NULL ;
static char ** my_fgets_names           = NULL ;
static int     my_fgets_number_of_names = 0    ;
static int     my_fgets_number_of_names = 0    ;
static int     my_fgets_debug_flag      = 0    ;
static int     my_fgets_debug_flag      = 0    ;
 
 
 
 


/* invoked with _fgets_reset_ */
/* invoked with _fgets_reset_ */
static void
static void
my_fgets_reset (
my_fgets_reset (
  void
  void
) {
) {
  if ( my_fgets_names && (my_fgets_number_of_names > 0) ) {
  if ( my_fgets_names && (my_fgets_number_of_names > 0) ) {
    int i ;
    int i ;
    if ( my_fgets_debug_flag ) {
    if ( my_fgets_debug_flag ) {
      printf ( "libfgets:  removing command list\n" ) ;
      printf ( "libfgets:  removing command list\n" ) ;
    }
    }
    for ( i = 0 ; i < my_fgets_number_of_names ; i ++ ) {
    for ( i = 0 ; i < my_fgets_number_of_names ; i ++ ) {
      if ( my_fgets_names[i] ) free ( my_fgets_names[i] ) ;
      if ( my_fgets_names[i] ) free ( my_fgets_names[i] ) ;
    }
    }
    free ( my_fgets_names ) ;
    free ( my_fgets_names ) ;
  }
  }
  my_fgets_names = NULL ;
  my_fgets_names = NULL ;
  my_fgets_number_of_names = 0 ;
  my_fgets_number_of_names = 0 ;
}
}
 
 
 
 


/* invoked with _fgets_dump_ */
/* invoked with _fgets_dump_ */
static void
static void
my_fgets_dump (
my_fgets_dump (
  void
  void
) {
) {
  char * s ;
  char * s ;
  printf ( "\n" ) ;
  printf ( "\n" ) ;
  s = getenv ( "FGETS_PROMPT" ) ;
  s = getenv ( "FGETS_PROMPT" ) ;
  printf ( "FGETS_PROMPT       = %s\n", s ? s : "" ) ;
  printf ( "FGETS_PROMPT       = %s\n", s ? s : "" ) ;
  s = getenv ( "FGETS_COMMAND_FILE" ) ;
  s = getenv ( "FGETS_COMMAND_FILE" ) ;
  printf ( "FGETS_COMMAND_FILE = %s\n", s ? s : "" ) ;
  printf ( "FGETS_COMMAND_FILE = %s\n", s ? s : "" ) ;
  printf ( "debug flag         = %d\n", my_fgets_debug_flag ) ;
  printf ( "debug flag         = %d\n", my_fgets_debug_flag ) ;
  printf ( "#commands          = %d\n", my_fgets_number_of_names ) ;
  printf ( "#commands          = %d\n", my_fgets_number_of_names ) ;
  if ( my_fgets_debug_flag ) {
  if ( my_fgets_debug_flag ) {
    if ( my_fgets_names && (my_fgets_number_of_names > 0) ) {
    if ( my_fgets_names && (my_fgets_number_of_names > 0) ) {
      int i ;
      int i ;
      for ( i = 0 ; i < my_fgets_number_of_names ; i ++ ) {
      for ( i = 0 ; i < my_fgets_number_of_names ; i ++ ) {
        printf ( "%s\n", my_fgets_names[i] ) ;
        printf ( "%s\n", my_fgets_names[i] ) ;
      }
      }
    }
    }
  }
  }
  printf ( "\n" ) ;
  printf ( "\n" ) ;
}
}
 
 
 
 


/* invoked with _fgets_debug_ */
/* invoked with _fgets_debug_ */
static void
static void
my_fgets_debug_toggle (
my_fgets_debug_toggle (
  void
  void
) {
) {
  my_fgets_debug_flag = my_fgets_debug_flag ? 0 : 1 ;
  my_fgets_debug_flag = my_fgets_debug_flag ? 0 : 1 ;
  if ( my_fgets_debug_flag ) {
  if ( my_fgets_debug_flag ) {
    printf ( "libfgets:  debug flag = %d\n", my_fgets_debug_flag ) ;
    printf ( "libfgets:  debug flag = %d\n", my_fgets_debug_flag ) ;
  }
  }
}
}
 
 
 
 


/* read the command list if needed, return the i-th name */
/* read the command list if needed, return the i-th name */
static char *
static char *
my_fgets_lookup (
my_fgets_lookup (
  int index
  int index
) {
) {
  if ( (! my_fgets_names) || (! my_fgets_number_of_names) ) {
  if ( (! my_fgets_names) || (! my_fgets_number_of_names) ) {
    char * fname ;
    char * fname ;
    FILE * fp ;
    FILE * fp ;
    fgets_t _fgets ;
    fgets_t _fgets ;
    int i ;
    int i ;
    char buf1[256], buf2[256] ;
    char buf1[256], buf2[256] ;
    fname = getenv ( "FGETS_COMMAND_FILE" ) ;
    fname = getenv ( "FGETS_COMMAND_FILE" ) ;
    if ( ! fname ) {
    if ( ! fname ) {
      if ( my_fgets_debug_flag ) {
      if ( my_fgets_debug_flag ) {
        printf ( "libfgets:  empty or unset FGETS_COMMAND_FILE\n" ) ;
        printf ( "libfgets:  empty or unset FGETS_COMMAND_FILE\n" ) ;
      }
      }
      return NULL ;
      return NULL ;
    }
    }
    fp = fopen ( fname, "r" ) ;
    fp = fopen ( fname, "r" ) ;
    if ( ! fp ) {
    if ( ! fp ) {
      if ( my_fgets_debug_flag ) {
      if ( my_fgets_debug_flag ) {
        printf ( "libfgets:  cannot open '%s' for reading\n", fname ) ;
        printf ( "libfgets:  cannot open '%s' for reading\n", fname ) ;
      }
      }
      return NULL ;
      return NULL ;
    }
    }
    _fgets = (fgets_t) dlsym ( REAL_LIBC, "fgets" ) ;
    _fgets = (fgets_t) dlsym ( REAL_LIBC, "fgets" ) ;
    if ( ! _fgets ) {
    if ( ! _fgets ) {
      fprintf ( stderr,
      fprintf ( stderr,
        "libfgets:  failed to dynamically link to native fgets()\n"
        "libfgets:  failed to dynamically link to native fgets()\n"
      ) ;
      ) ;
      return NULL ;
      return NULL ;
    }
    }
    for ( i = 0 ; _fgets(buf1,255,fp) ; i ++ ) ;
    for ( i = 0 ; _fgets(buf1,255,fp) ; i ++ ) ;
    if ( ! i ) { fclose(fp) ; return NULL ; }
    if ( ! i ) { fclose(fp) ; return NULL ; }
    my_fgets_names = (char**) calloc ( i, sizeof(char*) ) ;
    my_fgets_names = (char**) calloc ( i, sizeof(char*) ) ;
    rewind ( fp ) ;
    rewind ( fp ) ;
    i = 0 ;
    i = 0 ;
    while ( _fgets(buf1,255,fp) ) {
    while ( _fgets(buf1,255,fp) ) {
      buf1[255] = 0 ;
      buf1[255] = 0 ;
      if ( 1 == sscanf(buf1,"%s",buf2) ) {
      if ( 1 == sscanf(buf1,"%s",buf2) ) {
        my_fgets_names[i] = strdup(buf2) ;
        my_fgets_names[i] = strdup(buf2) ;
        i ++ ;
        i ++ ;
      }
      }
    }
    }
    fclose ( fp ) ;
    fclose ( fp ) ;
    my_fgets_number_of_names = i ;
    my_fgets_number_of_names = i ;
    if ( my_fgets_debug_flag ) {
    if ( my_fgets_debug_flag ) {
      printf ( "libfgets:  successfully read %d commands\n", i ) ;
      printf ( "libfgets:  successfully read %d commands\n", i ) ;
    }
    }
  }
  }
  if ( index < my_fgets_number_of_names ) {
  if ( index < my_fgets_number_of_names ) {
    return my_fgets_names[index] ;
    return my_fgets_names[index] ;
  } else {
  } else {
    return NULL ;
    return NULL ;
  }
  }
}
}
 
 
 
 


/* generate a list of partial name matches for readline() */
/* generate a list of partial name matches for readline() */
static char *
static char *
my_fgets_generator (
my_fgets_generator (
  const char * text,
  const char * text,
  int          state
  int          state
)
)
{
{
  static int list_index, len ;
  static int list_index, len ;
  char *     name ;
  char *     name ;
  if ( ! state ) {
  if ( ! state ) {
    list_index = 0 ;
    list_index = 0 ;
    len = strlen ( text ) ;
    len = strlen ( text ) ;
  }
  }
  while ( ( name = my_fgets_lookup(list_index) ) ) {
  while ( ( name = my_fgets_lookup(list_index) ) ) {
    list_index ++ ;
    list_index ++ ;
    if ( ! strncmp ( name, text, len ) ) {
    if ( ! strncmp ( name, text, len ) ) {
      return ( strdup ( name ) ) ;
      return ( strdup ( name ) ) ;
    }
    }
  }
  }
  return ( NULL ) ;
  return ( NULL ) ;
}
}
 
 
 
 


/* partial name completion callback for readline() */
/* partial name completion callback for readline() */
static char **
static char **
my_fgets_completion (
my_fgets_completion (
  const char * text,
  const char * text,
  int          start,
  int          start,
  int          end
  int          end
)
)
{
{
  char ** matches ;
  char ** matches ;
  matches = NULL ;
  matches = NULL ;
  if ( ! start ) {
  if ( ! start ) {
    matches = rl_completion_matches ( text, my_fgets_generator ) ;
    matches = rl_completion_matches ( text, my_fgets_generator ) ;
  }
  }
  return ( matches ) ;
  return ( matches ) ;
}
}
 
 
 
 


/* fgets() intercept */
/* fgets() intercept */
char *
char *
fgets (
fgets (
  char * s,
  char * s,
  int    n,
  int    n,
  FILE * stream
  FILE * stream
)
)
{
{
  if ( ! s ) return NULL ;
  if ( ! s ) return NULL ;
  if ( stream == stdin ) {
  if ( stream == stdin ) {
    char * prompt ;
    char * prompt ;
    char * my_fgets_line ;
    char * my_fgets_line ;
    rl_already_prompted = 1 ;
    rl_already_prompted = 1 ;
    rl_attempted_completion_function = my_fgets_completion ;
    rl_attempted_completion_function = my_fgets_completion ;
    rl_catch_signals = 1 ;
    rl_catch_signals = 1 ;
    rl_catch_sigwinch = 1 ;
    rl_catch_sigwinch = 1 ;
    rl_set_signals () ;
    rl_set_signals () ;
    prompt = getenv ( "FGETS_PROMPT" ) ;
    prompt = getenv ( "FGETS_PROMPT" ) ;
    for (
    for (
      my_fgets_line = 0 ; ! my_fgets_line ; my_fgets_line=readline(prompt)
      my_fgets_line = 0 ; ! my_fgets_line ; my_fgets_line=readline(prompt)
    ) ;
    ) ;
    if ( ! strncmp(my_fgets_line, "_fgets_reset_", 13) ) {
    if ( ! strncmp(my_fgets_line, "_fgets_reset_", 13) ) {
      my_fgets_reset () ;
      my_fgets_reset () ;
      free ( my_fgets_line ) ;
      free ( my_fgets_line ) ;
      strcpy ( s, "\n" ) ;
      strcpy ( s, "\n" ) ;
      return ( s ) ;
      return ( s ) ;
    }
    }
    if ( ! strncmp(my_fgets_line, "_fgets_dump_", 12) ) {
    if ( ! strncmp(my_fgets_line, "_fgets_dump_", 12) ) {
      my_fgets_dump () ;
      my_fgets_dump () ;
      free ( my_fgets_line ) ;
      free ( my_fgets_line ) ;
      strcpy ( s, "\n" ) ;
      strcpy ( s, "\n" ) ;
      return ( s ) ;
      return ( s ) ;
    }
    }
    if ( ! strncmp(my_fgets_line, "_fgets_debug_", 13) ) {
    if ( ! strncmp(my_fgets_line, "_fgets_debug_", 13) ) {
      my_fgets_debug_toggle () ;
      my_fgets_debug_toggle () ;
      free ( my_fgets_line ) ;
      free ( my_fgets_line ) ;
      strcpy ( s, "\n" ) ;
      strcpy ( s, "\n" ) ;
      return ( s ) ;
      return ( s ) ;
    }
    }
    (void) strncpy ( s, my_fgets_line, n-1 ) ;
    (void) strncpy ( s, my_fgets_line, n-1 ) ;
    (void) strcat ( s, "\n" ) ;
    (void) strcat ( s, "\n" ) ;
    if ( *my_fgets_line ) add_history ( my_fgets_line ) ;
    if ( *my_fgets_line ) add_history ( my_fgets_line ) ;
    free ( my_fgets_line ) ;
    free ( my_fgets_line ) ;
    return ( s ) ;
    return ( s ) ;
  } else {
  } else {
    static fgets_t _fgets ;
    static fgets_t _fgets ;
    _fgets = (fgets_t) dlsym ( REAL_LIBC, "fgets" ) ;
    _fgets = (fgets_t) dlsym ( REAL_LIBC, "fgets" ) ;
    if ( ! _fgets ) {
    if ( ! _fgets ) {
      fprintf ( stderr,
      fprintf ( stderr,
        "libfgets:  failed to dynamically link to native fgets()\n"
        "libfgets:  failed to dynamically link to native fgets()\n"
      ) ;
      ) ;
      strcpy ( s, "\n" ) ;
      strcpy ( s, "\n" ) ;
      return ( s ) ;
      return ( s ) ;
    }
    }
    return (
    return (
      _fgets ( s, n, stream )
      _fgets ( s, n, stream )
    ) ;
    ) ;
  }
  }
}
}
 
 

powered by: WebSVN 2.1.0

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