3 * (c) 2008 Steve Bennett <steveb@worware.net.au>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * The views and conclusions contained in the software and documentation
34 * are those of the authors and should not be interpreted as representing
35 * official policies, either expressed or implied, of the Jim Tcl Project.
37 * Based on original work by:
38 *-----------------------------------------------------------------------------
39 * Copyright 1991-1994 Karl Lehenbauer and Mark Diekhans.
41 * Permission to use, copy, modify, and distribute this software and its
42 * documentation for any purpose and without fee is hereby granted, provided
43 * that the above copyright notice appear in all copies. Karl Lehenbauer and
44 * Mark Diekhans make no representations about the suitability of this
45 * software for any purpose. It is provided "as is" without express or
47 *-----------------------------------------------------------------------------
59 *-----------------------------------------------------------------------------
62 * Implements the rename TCL command:
63 * readdir ?-nocomplain? dirPath
66 * Standard TCL result.
67 *-----------------------------------------------------------------------------
69 int Jim_ReaddirCmd(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
73 struct dirent
*entryPtr
;
76 if (argc
== 3 && Jim_CompareStringImmediate(interp
, argv
[1], "-nocomplain")) {
79 if (argc
!= 2 && !nocomplain
) {
80 Jim_WrongNumArgs(interp
, 1, argv
, "?-nocomplain? dirPath");
84 dirPath
= Jim_GetString(argv
[1 + nocomplain
], NULL
);
86 dirPtr
= opendir(dirPath
);
91 Jim_SetResultString(interp
, strerror(errno
), -1);
94 Jim_SetResultString(interp
, strerror(errno
), -1);
96 Jim_SetResult(interp
, Jim_NewListObj(interp
, NULL
, 0));
98 while ((entryPtr
= readdir(dirPtr
)) != NULL
) {
99 if (entryPtr
->d_name
[0] == '.') {
100 if (entryPtr
->d_name
[1] == '\0') {
103 if ((entryPtr
->d_name
[1] == '.') && (entryPtr
->d_name
[2] == '\0'))
106 Jim_ListAppendElement(interp
, Jim_GetResult(interp
), Jim_NewStringObj(interp
,
107 entryPtr
->d_name
, -1));
114 int Jim_readdirInit(Jim_Interp
*interp
)
116 Jim_CreateCommand(interp
, "readdir", Jim_ReaddirCmd
, NULL
, NULL
);