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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
79
83
84
85
86
87
94
95
96
97
107
108
109
110
111
112
113
114
115
/* ... */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <jim.h>
#include <jimautoconf.h>
5 includes
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
/* ... */
int Jim_ReaddirCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *dirPath;
DIR *dirPtr;
struct dirent *entryPtr;
int nocomplain = 0;
if (argc == 3 && Jim_CompareStringImmediate(interp, argv[1], "-nocomplain")) {
nocomplain = 1;
}if (argc == 3 && Jim_CompareStringImmediate(interp, argv[1], "-nocomplain")) { ... }
if (argc != 2 && !nocomplain) {
Jim_WrongNumArgs(interp, 1, argv, "?-nocomplain? dirPath");
return JIM_ERR;
}if (argc != 2 && !nocomplain) { ... }
dirPath = Jim_String(argv[1 + nocomplain]);
dirPtr = opendir(dirPath);
if (dirPtr == NULL) {
if (nocomplain) {
return JIM_OK;
}if (nocomplain) { ... }
Jim_SetResultString(interp, strerror(errno), -1);
return JIM_ERR;
}if (dirPtr == NULL) { ... }
else {
Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
while ((entryPtr = readdir(dirPtr)) != NULL) {
if (entryPtr->d_name[0] == '.') {
if (entryPtr->d_name[1] == '\0') {
continue;
}if (entryPtr->d_name[1] == '\0') { ... }
if ((entryPtr->d_name[1] == '.') && (entryPtr->d_name[2] == '\0'))
continue;
}if (entryPtr->d_name[0] == '.') { ... }
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, entryPtr->d_name, -1));
}while ((entryPtr = readdir(dirPtr)) != NULL) { ... }
closedir(dirPtr);
Jim_SetResult(interp, listObj);
return JIM_OK;
}else { ... }
}{ ... }
int Jim_readdirInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "readdir");
Jim_CreateCommand(interp, "readdir", Jim_ReaddirCmd, NULL, NULL);
return JIM_OK;
}{ ... }