home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / perl / patch / U / byteorder.U next >
Encoding:
Text File  |  1995-12-06  |  2.6 KB  |  93 lines

  1. ?RCS: $Id: byteorder.U,v 3.0.1.1 1994/10/29 16:02:58 ram Exp $
  2. ?RCS:
  3. ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
  4. ?RCS: 
  5. ?RCS: You may redistribute only under the terms of the Artistic Licence,
  6. ?RCS: as specified in the README file that comes with the distribution.
  7. ?RCS: You may reuse parts of this distribution only within the terms of
  8. ?RCS: that same Artistic Licence; a copy of which may be found at the root
  9. ?RCS: of the source tree for dist 3.0.
  10. ?RCS:
  11. ?RCS: $Log: byteorder.U,v $
  12. ?RCS: Revision 3.0.1.1  1994/10/29  16:02:58  ram
  13. ?RCS: patch36: added ?F: line for metalint file checking
  14. ?RCS:
  15. ?RCS: Revision 3.0  1993/08/18  12:05:28  ram
  16. ?RCS: Baseline for dist 3.0 netwide release.
  17. ?RCS:
  18. ?MAKE:byteorder: cat Myread Oldconfig Loc +cc +ccflags rm
  19. ?MAKE:    -pick add $@ %<
  20. ?S:byteorder:
  21. ?S:    This variable holds the byte order. In the following, larger digits
  22. ?S:    indicate more significance.  The variable byteorder is either 4321
  23. ?S:    on a big-endian machine, or 1234 on a little-endian, or 87654321
  24. ?S:    on a Cray ... or 3412 with weird order !
  25. ?S:.
  26. ?C:BYTEORDER:
  27. ?C:    This symbol hold the hexadecimal constant defined in byteorder,
  28. ?C:    i.e. 0x1234 or 0x4321, etc...
  29. ?C:.
  30. ?H:#ifndef NeXT
  31. ?H:# define BYTEORDER 0x$byteorder    /* large digits for MSB */
  32. ?H:#elif defined(__BIG_ENDIAN__)     /* must be NeXT */
  33. ?H:# define BYTEORDER 0x4321
  34. ?H:#else /* NeXT && __LITTLE_ENDIAN__ */
  35. ?H:# define BYTEORDER 0x1234
  36. ?H:#endif /* !NeXT */
  37. ?H:.
  38. ?F:!try
  39. : check for ordering of bytes in a long
  40. case "$byteorder" in
  41. '')
  42.     $cat <<'EOM'
  43.   
  44. In the following, larger digits indicate more significance.  A big-endian
  45. machine like a Pyramid or a Motorola 680?0 chip will come out to 4321. A
  46. little-endian machine like a Vax or an Intel 80?86 chip would be 1234. Other
  47. machines may have weird orders like 3412.  A Cray will report 87654321. If
  48. the test program works the default is probably right.
  49. I'm now running the test program...
  50. EOM
  51.     $cat >try.c <<'EOCP'
  52. #include <stdio.h>
  53. main()
  54. {
  55.     int i;
  56.     union {
  57.         unsigned long l;
  58.         char c[sizeof(long)];
  59.     } u;
  60.  
  61.     if (sizeof(long) > 4)
  62.         u.l = (0x08070605L << 32) | 0x04030201L;
  63.     else
  64.         u.l = 0x04030201L;
  65.     for (i = 0; i < sizeof(long); i++)
  66.         printf("%c", u.c[i]+'0');
  67.     printf("\n");
  68. }
  69. EOCP
  70.     if $cc $ccflags try.c -o try >/dev/null 2>&1 ; then
  71.         dflt=`./try`
  72.         case "$dflt" in
  73.         ????|????????) echo "(The test program ran ok.)";;
  74.         *) echo "(The test program didn't run right for some reason.)";;
  75.         esac
  76.     else
  77.         dflt='4321'
  78.         cat <<'EOM'
  79. (I can't seem to compile the test program.  Guessing big-endian...)
  80. EOM
  81.     fi
  82.     ;;
  83. *)
  84.     echo " "
  85.     dflt="$byteorder"
  86.     ;;
  87. esac
  88. rp="What is the order of bytes in a long?"
  89. . ./myread
  90. byteorder="$ans"
  91. $rm -f try.c try
  92.  
  93.