This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: DOS/Windows patches, take 2



These are the patches for the gprof subdirectory:


2000-05-14  Eli Zaretskii  <eliz@is.elta.co.il>

	* configure.in: Check for setmode function.

	* gmon_io.h (SET_BINARY) [HAVE_SETMODE]: Define.

	* gmon_io.c (gmon_out_read) [SET_BINARY]: Switch stdin into binary
	mode.

	* source.c: Include filenames.h and sys/stat.h.
	(source_file_lookup_path, source_file_lookup_name): Use
	FILENAME_CMP to compare file names.
	(annotate_source) [__MSDOS__]: If "filename-ann" would overwrite
	"filename", replace the extension with ".ann".
	[HAVE_DOS_BASED_FILE_SYSTEM]: Support file names with
	backslashes and drive letters.
	Use IS_ABSOLUTE_PATH.

	* search_list.h (PATH_SEP_CHAR): Define.

	* search_list.c (search_list_append): Use PATH_SEP_CHAR.

	* hertz.c (HERTZ) [__MSDOS__]: Don't define unless they have
	neither HAVE_SETITIMER nor HAVE_SYSCONF.
	[HAVE_SETITIMER]: If they define both HAVE_SETITIMER and
	HAVE_SYSCONF, try setitimer and fall back on sysconf.


*** ./gprof/configure.in.orig	Sun Apr 16 09:39:14 2000
--- ./gprof/configure.in	Fri May 12 18:38:42 2000
*************** AC_PROG_CC
*** 18,23 ****
--- 18,24 ----
  AC_PROG_INSTALL
  
  AC_ISC_POSIX
+ AC_CHECK_FUNCS(setmode)
  
  ALL_LINGUAS=
  CY_GNU_GETTEXT
*** ./gprof/gconfig.in.orig	Mon May  3 03:29:10 1999
--- ./gprof/gconfig.in	Fri May 12 18:44:14 2000
***************
*** 73,78 ****
--- 73,81 ----
  /* Define if you have the setlocale function.  */
  #undef HAVE_SETLOCALE
  
+ /* Define if you have the setmode function.  */
+ #undef HAVE_SETMODE
+ 
  /* Define if you have the stpcpy function.  */
  #undef HAVE_STPCPY
  
*** ./gprof/gmon_io.c.orig	Fri Sep 24 05:03:48 1999
--- ./gprof/gmon_io.c	Fri May 12 18:38:42 2000
*************** DEFUN (gmon_out_read, (filename), const 
*** 72,77 ****
--- 72,80 ----
    if (strcmp (filename, "-") == 0)
      {
        ifp = stdin;
+ #ifdef SET_BINARY
+       SET_BINARY (fileno (stdin));
+ #endif
      }
    else
      {
*** ./gprof/gmon_io.h.orig	Mon May  3 03:29:10 1999
--- ./gprof/gmon_io.h	Fri May 12 18:43:02 2000
***************
*** 4,9 ****
--- 4,27 ----
  #include "bfd.h"
  #include "gmon.h"
  
+ /* Some platforms need to put stdin into binary mode, to read
+    binary files.  */
+ #include "sysdep.h"
+ #ifdef HAVE_SETMODE
+ #ifndef O_BINARY
+ #ifdef _O_BINARY
+ #define O_BINARY _O_BINARY
+ #define setmode _setmode
+ #else
+ #define O_BINARY 0
+ #endif
+ #endif
+ #if O_BINARY
+ #include <io.h>
+ #define SET_BINARY(f) do { if (!isatty(f)) setmode(f,O_BINARY); } while (0)
+ #endif
+ #endif
+ 
  #define INPUT_HISTOGRAM		(1<<0)
  #define INPUT_CALL_GRAPH	(1<<1)
  #define INPUT_BB_COUNTS		(1<<2)
*** ./gprof/hertz.c.orig	Mon May  3 03:29:10 1999
--- ./gprof/hertz.c	Fri May 12 18:38:42 2000
***************
*** 19,28 ****
  #include "hertz.h"
  
  
- #ifdef __MSDOS__
- #define HERTZ 18
- #endif
- 
  int
  hertz ()
  {
--- 19,24 ----
*************** hertz ()
*** 38,54 ****
    tim.it_value.tv_usec = 0;
    setitimer (ITIMER_REAL, &tim, 0);
    setitimer (ITIMER_REAL, 0, &tim);
!   if (tim.it_interval.tv_usec < 2)
      {
!       return HZ_WRONG;
      }
!   return 1000000 / tim.it_interval.tv_usec;
! #else /* ! defined (HAVE_SETITIMER) */
  #if defined (HAVE_SYSCONF) && defined (_SC_CLK_TCK)
    return sysconf (_SC_CLK_TCK);
  #else /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
    return HZ_WRONG;
  #endif /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
- #endif /* ! defined (HAVE_SETITIMER) */
  #endif /* ! defined (HERTZ) */
  }
--- 34,52 ----
    tim.it_value.tv_usec = 0;
    setitimer (ITIMER_REAL, &tim, 0);
    setitimer (ITIMER_REAL, 0, &tim);
!   if (tim.it_interval.tv_usec >= 2)
      {
!       return 1000000 / tim.it_interval.tv_usec;
      }
! #endif /* ! defined (HAVE_SETITIMER) */
  #if defined (HAVE_SYSCONF) && defined (_SC_CLK_TCK)
    return sysconf (_SC_CLK_TCK);
  #else /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
+ #ifdef __MSDOS__
+   return 18;
+ #else  /* ! defined (__MSDOS__) */
    return HZ_WRONG;
+ #endif /* ! defined (__MSDOS__) */
  #endif /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
  #endif /* ! defined (HERTZ) */
  }
*** ./gprof/search_list.c.orig	Mon May  3 03:29:10 1999
--- ./gprof/search_list.c	Fri May 12 18:38:42 2000
*************** DEFUN (search_list_append, (list, paths)
*** 15,21 ****
    do
      {
        beg = colon + 1;
!       colon = strchr (beg, ':');
        if (colon)
  	{
  	  len = colon - beg;
--- 15,21 ----
    do
      {
        beg = colon + 1;
!       colon = strchr (beg, PATH_SEP_CHAR);
        if (colon)
  	{
  	  len = colon - beg;
*** ./gprof/search_list.h.orig	Mon May  3 03:29:10 1999
--- ./gprof/search_list.h	Fri May 12 18:38:42 2000
***************
*** 1,6 ****
--- 1,14 ----
  #ifndef search_list_h
  #define search_list_h
  
+ /* Non-Posix systems use semi-colon as directory separator in lists,
+    since colon is part of drive letter spec.  */
+ #if defined (__MSDOS__) || defined (_WIN32)
+ #define PATH_SEP_CHAR ';'
+ #else
+ #define PATH_SEP_CHAR ':'
+ #endif
+ 
  typedef struct search_list_elem
    {
      struct search_list_elem *next;
*** ./gprof/source.c.orig	Mon May  3 03:29:10 1999
--- ./gprof/source.c	Fri May 12 18:38:42 2000
***************
*** 1,8 ****
--- 1,11 ----
  /*
   * Keeps track of source files.
   */
+ #include <sys/stat.h>
+ 
  #include "gprof.h"
  #include "libiberty.h"
+ #include "filenames.h"
  #include "search_list.h"
  #include "source.h"
  
*************** DEFUN (source_file_lookup_path, (path), 
*** 25,31 ****
  
    for (sf = first_src_file; sf; sf = sf->next)
      {
!       if (strcmp (path, sf->name) == 0)
  	{
  	  break;
  	}
--- 28,34 ----
  
    for (sf = first_src_file; sf; sf = sf->next)
      {
!       if (FILENAME_CMP (path, sf->name) == 0)
  	{
  	  break;
  	}
*************** DEFUN (source_file_lookup_name, (filenam
*** 66,72 ****
  	{
  	  fname = sf->name;
  	}
!       if (strcmp (filename, fname) == 0)
  	{
  	  break;
  	}
--- 69,75 ----
  	{
  	  fname = sf->name;
  	}
!       if (FILENAME_CMP (filename, fname) == 0)
  	{
  	  break;
  	}
*************** DEFUN (annotate_source, (sf, max_width, 
*** 95,101 ****
     * open succeeds or reaching end of list:
     */
    strcpy (fname, sf->name);
!   if (sf->name[0] == '/')
      {
        sle = 0;			/* don't use search list for absolute paths */
      }
--- 98,104 ----
     * open succeeds or reaching end of list:
     */
    strcpy (fname, sf->name);
!   if (IS_ABSOLUTE_PATH (sf->name))
      {
        sle = 0;			/* don't use search list for absolute paths */
      }
*************** DEFUN (annotate_source, (sf, max_width, 
*** 112,117 ****
--- 115,129 ----
        if (!sle && !name_only)
  	{
  	  name_only = strrchr (sf->name, '/');
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ 	  {
+ 	    char *bslash = strrchr (sf->name, '\\');
+ 	    if (bslash && bslash > name_only)
+ 	      name_only = bslash;
+ 	    if (name_only == NULL && sf->name[0] != '\0' && sf->name[1] == ':')
+ 	      name_only = (char *)sf->name + 1;
+ 	  }
+ #endif
  	  if (name_only)
  	    {
  	      /* try search-list again, but this time with name only: */
*************** DEFUN (annotate_source, (sf, max_width, 
*** 122,127 ****
--- 134,144 ----
        if (sle)
  	{
  	  strcpy (fname, sle->path);
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ 	  /* d:foo is not the same thing as d:/foo!  */
+ 	  if (fname[strlen (fname) - 1] == ':')
+ 	    strcat (fname, ".");
+ #endif
  	  strcat (fname, "/");
  	  if (name_only)
  	    {
*************** DEFUN (annotate_source, (sf, max_width, 
*** 156,161 ****
--- 173,187 ----
  
        /* create annotation files in the current working directory: */
        filename = strrchr (sf->name, '/');
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ 	{
+ 	  char *bslash = strrchr (sf->name, '\\');
+ 	  if (bslash && bslash > filename)
+ 	    filename = bslash;
+ 	  if (filename == NULL && sf->name[0] != '\0' && sf->name[1] == ':')
+ 	    filename = sf->name + 1;
+ 	}
+ #endif
        if (filename)
  	{
  	  ++filename;
*************** DEFUN (annotate_source, (sf, max_width, 
*** 167,172 ****
--- 193,215 ----
  
        strcpy (fname, filename);
        strcat (fname, EXT_ANNO);
+ #ifdef __MSDOS__
+       {
+ 	/* foo.cpp-ann can overwrite foo.cpp due to silent truncation of
+ 	   file names on 8+3 filesystems.  Their `stat' better be good...  */
+ 	struct stat buf1, buf2;
+ 
+ 	if (stat (filename, &buf1) == 0 && stat (fname, &buf2) == 0
+ 	    && buf1.st_ino == buf2.st_ino)
+ 	  {
+ 	    char *dot = strrchr (fname, '.');
+ 
+ 	    if (dot)
+ 	      *dot = '\0';
+ 	    strcat (fname, ".ann");
+ 	  }
+       }
+ #endif
        ofp = fopen (fname, "w");
        if (!ofp)
  	{
*** ./gprof/sym_ids.c.orig	Sun Jul 11 16:06:46 1999
--- ./gprof/sym_ids.c	Fri May 12 18:38:42 2000
*************** DEFUN (match, (pattern, sym), Sym * patt
*** 201,207 ****
  {
    return (pattern->file ? pattern->file == sym->file : TRUE)
      && (pattern->line_num ? pattern->line_num == sym->line_num : TRUE)
!     && (pattern->name ? strcmp (pattern->name, sym->name) == 0 : TRUE);
  }
  
  
--- 201,210 ----
  {
    return (pattern->file ? pattern->file == sym->file : TRUE)
      && (pattern->line_num ? pattern->line_num == sym->line_num : TRUE)
!     && (pattern->name
! 	? strcmp (pattern->name,
! 		  sym->name+(discard_underscores && sym->name[0] == '_')) == 0
! 	: TRUE);
  }
  
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]