File: directory-depth.sgm

package info (click to toggle)
docbook-dsssl-doc 1.79-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,736 kB
  • sloc: makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,618 bytes parent folder | download | duplicates (8)
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
<RefEntry id="directory-depth">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename directory-depth.html>

<RefMeta>
  <RefEntryTitle>directory-depth</RefEntryTitle>
  <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>

<RefNameDiv>
  <RefName>directory-depth</RefName>
  <RefPurpose>Count the directory depth of a path name</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(directory-depth pathname)
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Returns the number of directory levels in <literal>pathname</literal>
</para>
<para>
The pathname must end in a filename.
Further, this function assumes that directories in a pathname are 
separated by forward slashes ("/").</para>


</RefSect1>

<RefSect1><Title>Example</Title>

<para>
"filename" => 0, 
"foo/filename" => 1, 
"foo/bar/filename => 2, 
"foo/bar/../filename => 1.
</para>


</RefSect1>

<RefSect1><Title>Author</Title>

<para>
Norman Walsh, &lt;ndw@nwalsh.com&gt;
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>

<ProgramListing>
(define (directory-depth pathname)
  ;; Count the directory depth of a path name
  (let loop ((count 0) (pathlist (match-split pathname "/")))
    (if (null? pathlist)
	(- count 1) ;; pathname should always end in a filename
	(if (or (equal? (car pathlist) "/") (equal? (car pathlist) "."))
	    (loop count (cdr pathlist))
	    (if (equal? (car pathlist) "..")
		(loop (- count 1) (cdr pathlist))
		(loop (+ count 1) (cdr pathlist)))))))
</ProgramListing>
</RefSect1>

</RefEntry>