summaryrefslogtreecommitdiff
path: root/mcon/U/i_dirent.U
blob: 65e192e8b76be7bf5d4cecbc72f1920187ef7175 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
?RCS: $Id$
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS: 
?RCS: You may redistribute only under the terms of the Artistic Licence,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic Licence; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: $Log: i_dirent.U,v $
?RCS: Revision 3.0.1.4  1994/10/29  16:20:01  ram
?RCS: patch36: failed scanning for 'd_namlen' with missing <dirent.h> (ADO)
?RCS:
?RCS: Revision 3.0.1.3  1994/06/20  07:01:25  ram
?RCS: patch30: added direntrytype for hints, merely for NeXT (ADO)
?RCS: patch30: now checks for both struct dirent and direct (ADO)
?RCS:
?RCS: Revision 3.0.1.2  1994/05/13  15:22:37  ram
?RCS: patch27: new variable direntrytype for proper type setting (ADO)
?RCS:
?RCS: Revision 3.0.1.1  1994/01/24  14:11:15  ram
?RCS: patch16: added new Direntry_t pseudo-type for directory entries
?RCS:
?RCS: Revision 3.0  1993/08/18  12:08:17  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?X:
?X: This unit looks whether there is a dirent system or not
?X:
?MAKE:i_dirent d_dirnamlen direntrytype: test contains Setvar \
	Myread Findhdr cppstdin cppflags cppminus rm
?MAKE:	-pick add $@ %<
?S:i_dirent:
?S:	This variable conditionally defines I_DIRENT, which indicates
?S:	to the C program that it should include <dirent.h>.
?S:.
?S:d_dirnamlen:
?S:	This variable conditionally defines DIRNAMLEN, which indicates
?S:	to the C program that the length of directory entry names is
?S:	provided by a d_namelen field.
?S:.
?S:direntrytype:
?S:	This symbol is set to 'struct direct' or 'struct dirent' depending on
?S:	whether dirent is available or not. You should use this pseudo type to
?S:	portably declare your directory entries.
?S:.
?C:I_DIRENT:
?C:	This symbol, if defined, indicates to the C program that it should
?C:	include <dirent.h>. Using this symbol also triggers the definition
?C:	of the Direntry_t define which ends up being 'struct dirent' or
?C:	'struct direct' depending on the availability of <dirent.h>.
?C:.
?C:DIRNAMLEN:
?C:	This symbol, if defined, indicates to the C program that the length
?C:	of directory entry names is provided by a d_namlen field.  Otherwise
?C:	you need to do strlen() on the d_name field.
?C:.
?C:Direntry_t:
?C:	This symbol is set to 'struct direct' or 'struct dirent' depending on
?C:	whether dirent is available or not. You should use this pseudo type to
?C:	portably declare your directory entries.
?C:.
?H:#$i_dirent I_DIRENT		/**/
?H:#$d_dirnamlen DIRNAMLEN	/**/
?H:?%<:@if I_DIRENT && Direntry_t
?H:?%<:#define Direntry_t $direntrytype
?H:?%<:@end
?H:.
?T:xinc guess1 guess2
?LINT:set i_dirent d_dirnamlen
: see if this is a dirent system
echo " "
if xinc=`./findhdr dirent.h`; $test "$xinc"; then
	val="$define"
	echo "<dirent.h> found." >&4
else
	val="$undef"
	if xinc=`./findhdr sys/dir.h`; $test "$xinc"; then
		echo "<sys/dir.h> found." >&4
		echo " "
	else
		xinc=`./findhdr sys/ndir.h`
	fi
	echo "<dirent.h> NOT found." >&4
fi
set i_dirent
eval $setvar

?X: Use struct dirent or struct direct?   If we're using dirent.h, 
?X: it's probably struct dirent, but apparently not always.
?X: Assume $xinc still contains the name of the header file we're using.
@if direntrytype || Direntry_t
: Look for type of directory structure.
echo " "
$cppstdin $cppflags $cppminus < "$xinc" > try.c

case "$direntrytype" in
''|' ')
	case "$i_dirent" in
	$define) guess1='struct dirent' ;;
	*) guess1='struct direct'  ;;
	esac
	;;
*)	guess1="$direntrytype"
	;;
esac

case "$guess1" in
'struct dirent') guess2='struct direct' ;;
*) guess2='struct dirent' ;;
esac
		
if $contains "$guess1" try.c >/dev/null 2>&1; then
	direntrytype="$guess1"
	echo "Your directory entries are $direntrytype." >&4
elif $contains "$guess2" try.c >/dev/null 2>&1; then
	direntrytype="$guess2"
	echo "Your directory entries seem to be $direntrytype." >&4
else
	echo "I don't recognize your system's directory entries." >&4
	rp="What type is used for directory entries on this system?"
	dflt="$guess1"
	. ./myread
	direntrytype="$ans"
fi
$rm -f try.c

@end

@if d_dirnamlen || DIRNAMLEN
: see if the directory entry stores field length
echo " "
$cppstdin $cppflags $cppminus < "$xinc" > try.c
if $contains 'd_namlen' try.c >/dev/null 2>&1; then
	echo "Good, your directory entry keeps length information in d_namlen." >&4
	val="$define"
else
	echo "Your directory entry does not know about the d_namlen field." >&4
	val="$undef"
fi
set d_dirnamlen
eval $setvar
$rm -f try.c

@end