This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The URL for the dist source repo changed
[metaconfig.git] / U / modified / i_dirent.U
1 ?RCS: $Id: i_dirent.U,v 3.0.1.4 1994/10/29 16:20:01 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: i_dirent.U,v $
12 ?RCS: Revision 3.0.1.4  1994/10/29  16:20:01  ram
13 ?RCS: patch36: failed scanning for 'd_namlen' with missing <dirent.h> (ADO)
14 ?RCS:
15 ?RCS: Revision 3.0.1.3  1994/06/20  07:01:25  ram
16 ?RCS: patch30: added direntrytype for hints, merely for NeXT (ADO)
17 ?RCS: patch30: now checks for both struct dirent and direct (ADO)
18 ?RCS:
19 ?RCS: Revision 3.0.1.2  1994/05/13  15:22:37  ram
20 ?RCS: patch27: new variable direntrytype for proper type setting (ADO)
21 ?RCS:
22 ?RCS: Revision 3.0.1.1  1994/01/24  14:11:15  ram
23 ?RCS: patch16: added new Direntry_t pseudo-type for directory entries
24 ?RCS:
25 ?RCS: Revision 3.0  1993/08/18  12:08:17  ram
26 ?RCS: Baseline for dist 3.0 netwide release.
27 ?RCS:
28 ?X:
29 ?X: This unit looks whether there is a dirent system or not
30 ?X:
31 ?MAKE:i_dirent d_dirnamlen direntrytype: test contains Setvar \
32         Myread Findhdr cppstdin cppflags cppminus rm_try
33 ?MAKE:  -pick add $@ %<
34 ?S:i_dirent:
35 ?S:     This variable conditionally defines I_DIRENT, which indicates
36 ?S:     to the C program that it should include <dirent.h>.
37 ?S:.
38 ?S:d_dirnamlen:
39 ?S:     This variable conditionally defines DIRNAMLEN, which indicates
40 ?S:     to the C program that the length of directory entry names is
41 ?S:     provided by a d_namelen field.
42 ?S:.
43 ?S:direntrytype:
44 ?S:     This symbol is set to 'struct direct' or 'struct dirent' depending on
45 ?S:     whether dirent is available or not. You should use this pseudo type to
46 ?S:     portably declare your directory entries.
47 ?S:.
48 ?C:I_DIRENT:
49 ?C:     This symbol, if defined, indicates to the C program that it should
50 ?C:     include <dirent.h>. Using this symbol also triggers the definition
51 ?C:     of the Direntry_t define which ends up being 'struct dirent' or
52 ?C:     'struct direct' depending on the availability of <dirent.h>.
53 ?C:.
54 ?C:DIRNAMLEN:
55 ?C:     This symbol, if defined, indicates to the C program that the length
56 ?C:     of directory entry names is provided by a d_namlen field.  Otherwise
57 ?C:     you need to do strlen() on the d_name field.
58 ?C:.
59 ?C:Direntry_t:
60 ?C:     This symbol is set to 'struct direct' or 'struct dirent' depending on
61 ?C:     whether dirent is available or not. You should use this pseudo type to
62 ?C:     portably declare your directory entries.
63 ?C:.
64 ?H:#$i_dirent I_DIRENT          /**/
65 ?H:#$d_dirnamlen DIRNAMLEN      /**/
66 ?H:?%<:@if I_DIRENT && Direntry_t
67 ?H:?%<:#define Direntry_t $direntrytype
68 ?H:?%<:@end
69 ?H:.
70 ?T:xinc guess1 guess2
71 ?LINT:set i_dirent d_dirnamlen
72 : see if this is a dirent system
73 echo " "
74 if xinc=`./findhdr dirent.h`; $test "$xinc"; then
75         val="$define"
76         echo "<dirent.h> found." >&4
77 else
78         val="$undef"
79         if xinc=`./findhdr sys/dir.h`; $test "$xinc"; then
80                 echo "<sys/dir.h> found." >&4
81                 echo " "
82         else
83                 xinc=`./findhdr sys/ndir.h`
84         fi
85         echo "<dirent.h> NOT found." >&4
86 fi
87 set i_dirent
88 eval $setvar
89
90 ?X: Use struct dirent or struct direct?   If we're using dirent.h,
91 ?X: it's probably struct dirent, but apparently not always.
92 ?X: Assume $xinc still contains the name of the header file we're using.
93 @if direntrytype || Direntry_t
94 : Look for type of directory structure.
95 echo " "
96 $cppstdin $cppflags $cppminus < "$xinc" > try.c
97
98 case "$direntrytype" in
99 ''|' ')
100         case "$i_dirent" in
101         $define) guess1='struct dirent' ;;
102         *) guess1='struct direct'  ;;
103         esac
104         ;;
105 *)      guess1="$direntrytype"
106         ;;
107 esac
108
109 case "$guess1" in
110 'struct dirent') guess2='struct direct' ;;
111 *) guess2='struct dirent' ;;
112 esac
113
114 if $contains "$guess1" try.c >/dev/null 2>&1; then
115         direntrytype="$guess1"
116         echo "Your directory entries are $direntrytype." >&4
117 elif $contains "$guess2" try.c >/dev/null 2>&1; then
118         direntrytype="$guess2"
119         echo "Your directory entries seem to be $direntrytype." >&4
120 else
121         echo "I don't recognize your system's directory entries." >&4
122         rp="What type is used for directory entries on this system?"
123         dflt="$guess1"
124         . ./myread
125         direntrytype="$ans"
126 fi
127 $rm_try
128
129 @end
130 @if d_dirnamlen || DIRNAMLEN
131 : see if the directory entry stores field length
132 echo " "
133 $cppstdin $cppflags $cppminus < "$xinc" > try.c
134 if $contains 'd_namlen' try.c >/dev/null 2>&1; then
135         echo "Good, your directory entry keeps length information in d_namlen." >&4
136         val="$define"
137 else
138         echo "Your directory entry does not know about the d_namlen field." >&4
139         val="$undef"
140 fi
141 set d_dirnamlen
142 eval $setvar
143 $rm_try
144
145 @end