| ︙ | | | ︙ | |
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
|
#define jim_ext_regexp
#define jim_ext_file
#define jim_ext_exec
#define jim_ext_clock
#define jim_ext_array
#define jim_ext_stdlib
#define jim_ext_tclcompat
#if defined(__MINGW32__)
#define TCL_PLATFORM_OS "mingw"
#define TCL_PLATFORM_PLATFORM "windows"
#define TCL_PLATFORM_PATH_SEPARATOR ";"
#define HAVE_MKDIR_ONE_ARG
#define HAVE_SYSTEM
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#define TCL_PLATFORM_OS "unknown"
#define TCL_PLATFORM_PLATFORM "unix"
#define TCL_PLATFORM_PATH_SEPARATOR ":"
#define HAVE_VFORK
#define HAVE_WAITPID
#endif
#ifndef UTF8_UTIL_H
#define UTF8_UTIL_H
int utf8_fromunicode(char *p, unsigned short uc);
#ifndef JIM_UTF8
|
>
>
>
>
>
>
|
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
#define jim_ext_regexp
#define jim_ext_file
#define jim_ext_exec
#define jim_ext_clock
#define jim_ext_array
#define jim_ext_stdlib
#define jim_ext_tclcompat
#if defined(_MSC_VER)
#define TCL_PLATFORM_OS "windows"
#define TCL_PLATFORM_PLATFORM "windows"
#define TCL_PLATFORM_PATH_SEPARATOR ";"
#define HAVE_MKDIR_ONE_ARG
#define HAVE_SYSTEM
#elif defined(__MINGW32__)
#define TCL_PLATFORM_OS "mingw"
#define TCL_PLATFORM_PLATFORM "windows"
#define TCL_PLATFORM_PATH_SEPARATOR ";"
#define HAVE_MKDIR_ONE_ARG
#define HAVE_SYSTEM
#define HAVE_SYS_TIME_H
#define HAVE_DIRENT_H
#define HAVE_UNISTD_H
#else
#define TCL_PLATFORM_OS "unknown"
#define TCL_PLATFORM_PLATFORM "unix"
#define TCL_PLATFORM_PATH_SEPARATOR ":"
#define HAVE_VFORK
#define HAVE_WAITPID
#define HAVE_SYS_TIME_H
#define HAVE_DIRENT_H
#define HAVE_UNISTD_H
#endif
#ifndef JIM_WIN32COMPAT_H
#define JIM_WIN32COMPAT_H
#if defined(_WIN32) || defined(WIN32)
#define HAVE_DLOPEN
void *dlopen(const char *path, int mode);
int dlclose(void *handle);
void *dlsym(void *handle, const char *symbol);
char *dlerror(void);
#ifdef _MSC_VER
#if _MSC_VER >= 1000
#pragma warning(disable:4146)
#endif
#include <limits.h>
#define jim_wide _int64
#ifndef LLONG_MAX
#define LLONG_MAX 9223372036854775807I64
#endif
#ifndef LLONG_MIN
#define LLONG_MIN (-LLONG_MAX - 1I64)
#endif
#define JIM_WIDE_MIN LLONG_MIN
#define JIM_WIDE_MAX LLONG_MAX
#define JIM_WIDE_MODIFIER "I64d"
#define strcasecmp _stricmp
#define strtoull _strtoui64
#define snprintf _snprintf
#include <io.h>
struct timeval {
long tv_sec;
long tv_usec;
};
int gettimeofday(struct timeval *tv, void *unused);
#define HAVE_OPENDIR
struct dirent {
char *d_name;
};
typedef struct DIR {
long handle;
struct _finddata_t info;
struct dirent result;
char *name;
} DIR;
DIR *opendir(const char *name);
int closedir(DIR *dir);
struct dirent *readdir(DIR *dir);
#endif
#endif
#endif
#ifndef UTF8_UTIL_H
#define UTF8_UTIL_H
int utf8_fromunicode(char *p, unsigned short uc);
#ifndef JIM_UTF8
|
| ︙ | | | ︙ | |
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# define strtoull strtoul
# endif
#endif
#define UCHAR(c) ((unsigned char)(c))
#define JIM_VERSION 72
#define JIM_OK 0
#define JIM_ERR 1
#define JIM_RETURN 2
#define JIM_BREAK 3
#define JIM_CONTINUE 4
#define JIM_SIGNAL 5
|
|
|
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# define strtoull strtoul
# endif
#endif
#define UCHAR(c) ((unsigned char)(c))
#define JIM_VERSION 73
#define JIM_OK 0
#define JIM_ERR 1
#define JIM_RETURN 2
#define JIM_BREAK 3
#define JIM_CONTINUE 4
#define JIM_SIGNAL 5
|
| ︙ | | | ︙ | |
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
|
typedef struct {
const char *cmd;
const char *args;
tclmod_cmd_function *function;
short minargs;
short maxargs;
unsigned flags;
const char *description;
} jim_subcmd_type;
const jim_subcmd_type *
Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv);
int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
int Jim_CallSubCmd(Jim_Interp *interp, const jim_subcmd_type *ct, int argc, Jim_Obj *const *argv);
int
Jim_CheckCmdUsage(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv);
#ifdef __cplusplus
}
#endif
#endif
#ifndef JIMREGEXP_H
#define JIMREGEXP_H
|
|
<
<
<
<
|
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
|
typedef struct {
const char *cmd;
const char *args;
tclmod_cmd_function *function;
short minargs;
short maxargs;
unsigned short flags;
} jim_subcmd_type;
const jim_subcmd_type *
Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv);
int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
int Jim_CallSubCmd(Jim_Interp *interp, const jim_subcmd_type *ct, int argc, Jim_Obj *const *argv);
#ifdef __cplusplus
}
#endif
#endif
#ifndef JIMREGEXP_H
#define JIMREGEXP_H
|
| ︙ | | | ︙ | |
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
|
"\n"
"proc {info nameofexecutable} {} {\n"
" if {[info exists ::jim_argv0]} {\n"
" if {[string match \"*/*\" $::jim_argv0]} {\n"
" return [file join [pwd] $::jim_argv0]\n"
" }\n"
" foreach path [split [env PATH \"\"] $::tcl_platform(pathSeparator)] {\n"
" set exec [file join [pwd] $path $::jim_argv0]\n"
" if {[file executable $exec]} {\n"
" return $exec\n"
" }\n"
" }\n"
" }\n"
" return \"\"\n"
"}\n"
|
|
|
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
|
"\n"
"proc {info nameofexecutable} {} {\n"
" if {[info exists ::jim_argv0]} {\n"
" if {[string match \"*/*\" $::jim_argv0]} {\n"
" return [file join [pwd] $::jim_argv0]\n"
" }\n"
" foreach path [split [env PATH \"\"] $::tcl_platform(pathSeparator)] {\n"
" set exec [file join [pwd] [string map {\\\\ /} $path] $::jim_argv0]\n"
" if {[file executable $exec]} {\n"
" return $exec\n"
" }\n"
" }\n"
" }\n"
" return \"\"\n"
"}\n"
|
| ︙ | | | ︙ | |
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
|
" }\n"
" file delete $path\n"
"}\n"
);
}
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_SELECT) && defined(HAVE_NETINET_IN_H) && defined(HAVE_NETDB_H) && defined(HAVE_ARPA_INET_H)
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
#else
#define JIM_ANSIC
#endif
|
<
>
|
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
|
" }\n"
" file delete $path\n"
"}\n"
);
}
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_SELECT) && defined(HAVE_NETINET_IN_H) && defined(HAVE_NETDB_H) && defined(HAVE_ARPA_INET_H)
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
#else
#define JIM_ANSIC
#endif
|
| ︙ | | | ︙ | |
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
|
static void JimAioDelProc(Jim_Interp *interp, void *privData)
{
AioFile *af = privData;
JIM_NOTUSED(interp);
Jim_DecrRefCount(interp, af->filename);
if (!(af->OpenFlags & AIO_KEEPOPEN)) {
fclose(af->fp);
}
#ifdef jim_ext_eventloop
if (af->rEvent) {
Jim_DeleteFileHandler(interp, af->fp);
}
if (af->wEvent) {
Jim_DeleteFileHandler(interp, af->fp);
|
<
<
>
>
>
|
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
|
static void JimAioDelProc(Jim_Interp *interp, void *privData)
{
AioFile *af = privData;
JIM_NOTUSED(interp);
if (!(af->OpenFlags & AIO_KEEPOPEN)) {
fclose(af->fp);
}
Jim_DecrRefCount(interp, af->filename);
#ifdef jim_ext_eventloop
if (af->rEvent) {
Jim_DeleteFileHandler(interp, af->fp);
}
if (af->wEvent) {
Jim_DeleteFileHandler(interp, af->fp);
|
| ︙ | | | ︙ | |
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
|
AioFile *af = Jim_CmdPrivData(interp);
return aio_eventinfo(interp, af, JIM_EVENT_EXCEPTION, &af->wEvent, argc, argv);
}
#endif
static const jim_subcmd_type aio_command_table[] = {
{ .cmd = "read",
.args = "?-nonewline? ?len?",
.function = aio_cmd_read,
.minargs = 0,
.maxargs = 2,
.description = "Read and return bytes from the stream. To eof if no len."
},
{ .cmd = "copyto",
.args = "handle ?size?",
.function = aio_cmd_copy,
.minargs = 1,
.maxargs = 2,
.description = "Copy up to 'size' bytes to the given filehandle, or to eof if no size."
},
{ .cmd = "gets",
.args = "?var?",
.function = aio_cmd_gets,
.minargs = 0,
.maxargs = 1,
.description = "Read one line and return it or store it in the var"
},
{ .cmd = "puts",
.args = "?-nonewline? str",
.function = aio_cmd_puts,
.minargs = 1,
.maxargs = 2,
.description = "Write the string, with newline unless -nonewline"
},
{ .cmd = "flush",
.function = aio_cmd_flush,
.description = "Flush the stream"
},
{ .cmd = "eof",
.function = aio_cmd_eof,
.description = "Returns 1 if stream is at eof"
},
{ .cmd = "close",
.flags = JIM_MODFLAG_FULLARGV,
.function = aio_cmd_close,
.description = "Closes the stream"
},
{ .cmd = "seek",
.args = "offset ?start|current|end",
.function = aio_cmd_seek,
.minargs = 1,
.maxargs = 2,
.description = "Seeks in the stream (default 'current')"
},
{ .cmd = "tell",
.function = aio_cmd_tell,
.description = "Returns the current seek position"
},
{ .cmd = "filename",
.function = aio_cmd_filename,
.description = "Returns the original filename"
},
#ifdef O_NDELAY
{ .cmd = "ndelay",
.args = "?0|1?",
.function = aio_cmd_ndelay,
.minargs = 0,
.maxargs = 1,
.description = "Set O_NDELAY (if arg). Returns current/new setting."
},
#endif
{ .cmd = "buffering",
.args = "none|line|full",
.function = aio_cmd_buffering,
.minargs = 1,
.maxargs = 1,
.description = "Sets buffering"
},
#ifdef jim_ext_eventloop
{ .cmd = "readable",
.args = "?readable-script?",
.minargs = 0,
.maxargs = 1,
.function = aio_cmd_readable,
.description = "Returns script, or invoke readable-script when readable, {} to remove",
},
{ .cmd = "writable",
.args = "?writable-script?",
.minargs = 0,
.maxargs = 1,
.function = aio_cmd_writable,
.description = "Returns script, or invoke writable-script when writable, {} to remove",
},
{ .cmd = "onexception",
.args = "?exception-script?",
.minargs = 0,
.maxargs = 1,
.function = aio_cmd_onexception,
.description = "Returns script, or invoke exception-script when oob data, {} to remove",
},
#endif
{ 0 }
};
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, aio_command_table, argc, argv), argc, argv);
}
static int JimAioOpenCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
FILE *fp;
const char *hdlfmt;
const char *mode;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?");
return JIM_ERR;
}
mode = (argc == 3) ? Jim_String(argv[2]) : "r";
hdlfmt = Jim_String(argv[1]);
if (Jim_CompareStringImmediate(interp, argv[1], "stdin")) {
fp = stdin;
}
else if (Jim_CompareStringImmediate(interp, argv[1], "stdout")) {
fp = stdout;
}
else if (Jim_CompareStringImmediate(interp, argv[1], "stderr")) {
fp = stderr;
}
else {
const char *filename = Jim_String(argv[1]);
#ifdef jim_ext_tclcompat
if (*filename == '|') {
Jim_Obj *evalObj[3];
evalObj[0] = Jim_NewStringObj(interp, "popen", -1);
evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1);
evalObj[2] = Jim_NewStringObj(interp, mode, -1);
return Jim_EvalObjVector(interp, 3, evalObj);
}
#endif
hdlfmt = "aio.handle%ld";
fp = NULL;
}
return JimMakeChannel(interp, fp, -1, argv[1], hdlfmt, 0, mode);
}
static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode)
{
AioFile *af;
char buf[AIO_CMD_LEN];
int OpenFlags = 0;
Jim_IncrRefCount(filename);
if (fh == NULL) {
if (fd < 0) {
fh = fopen(Jim_String(filename), mode);
}
else {
fh = fdopen(fd, mode);
}
}
else {
OpenFlags = AIO_KEEPOPEN;
}
if (fh == NULL) {
JimAioSetError(interp, filename);
close(fd);
Jim_DecrRefCount(interp, filename);
return JIM_ERR;
}
af = Jim_Alloc(sizeof(*af));
memset(af, 0, sizeof(*af));
af->fp = fh;
af->fd = fileno(fh);
af->filename = filename;
#ifdef FD_CLOEXEC
if ((OpenFlags & AIO_KEEPOPEN) == 0) {
fcntl(af->fd, F_SETFD, FD_CLOEXEC);
af->OpenFlags = OpenFlags;
}
#endif
#ifdef O_NDELAY
af->flags = fcntl(af->fd, F_GETFL);
#endif
af->addr_family = family;
snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
>
>
|
|
>
|
>
>
|
|
|
|
>
>
>
|
|
|
|
|
|
|
|
>
|
>
>
|
|
>
|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
|
>
>
|
|
|
<
<
|
>
>
|
|
|
<
<
|
>
>
|
|
<
|
|
<
<
<
<
<
<
<
<
<
<
<
|
<
|
|
|
|
|
|
|
|
<
<
<
<
<
|
>
>
>
>
>
|
>
<
>
|
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
|
AioFile *af = Jim_CmdPrivData(interp);
return aio_eventinfo(interp, af, JIM_EVENT_EXCEPTION, &af->wEvent, argc, argv);
}
#endif
static const jim_subcmd_type aio_command_table[] = {
{ "read",
"?-nonewline? ?len?",
aio_cmd_read,
0,
2,
},
{ "copyto",
"handle ?size?",
aio_cmd_copy,
1,
2,
},
{ "gets",
"?var?",
aio_cmd_gets,
0,
1,
},
{ "puts",
"?-nonewline? str",
aio_cmd_puts,
1,
2,
},
{ "flush",
NULL,
aio_cmd_flush,
0,
0,
},
{ "eof",
NULL,
aio_cmd_eof,
0,
0,
},
{ "close",
NULL,
aio_cmd_close,
0,
0,
JIM_MODFLAG_FULLARGV,
},
{ "seek",
"offset ?start|current|end",
aio_cmd_seek,
1,
2,
},
{ "tell",
NULL,
aio_cmd_tell,
0,
0,
},
{ "filename",
NULL,
aio_cmd_filename,
0,
0,
},
#ifdef O_NDELAY
{ "ndelay",
"?0|1?",
aio_cmd_ndelay,
0,
1,
},
#endif
{ "buffering",
"none|line|full",
aio_cmd_buffering,
1,
1,
},
#ifdef jim_ext_eventloop
{ "readable",
"?readable-script?",
aio_cmd_readable,
0,
1,
},
{ "writable",
"?writable-script?",
aio_cmd_writable,
0,
1,
},
{ "onexception",
"?exception-script?",
aio_cmd_onexception,
0,
1,
},
#endif
{ NULL }
};
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, aio_command_table, argc, argv), argc, argv);
}
static int JimAioOpenCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *mode;
const char *filename;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?");
return JIM_ERR;
}
mode = (argc == 3) ? Jim_String(argv[2]) : "r";
filename = Jim_String(argv[1]);
#ifdef jim_ext_tclcompat
if (*filename == '|') {
Jim_Obj *evalObj[3];
evalObj[0] = Jim_NewStringObj(interp, "popen", -1);
evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1);
evalObj[2] = Jim_NewStringObj(interp, mode, -1);
return Jim_EvalObjVector(interp, 3, evalObj);
}
#endif
return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode);
}
static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode)
{
AioFile *af;
char buf[AIO_CMD_LEN];
int OpenFlags = 0;
if (filename == NULL) {
filename = Jim_NewStringObj(interp, hdlfmt, -1);
}
Jim_IncrRefCount(filename);
if (fh == NULL) {
if (fd < 0) {
fh = fopen(Jim_String(filename), mode);
}
else {
fh = fdopen(fd, mode);
}
}
else {
OpenFlags = AIO_KEEPOPEN;
}
if (fh == NULL) {
JimAioSetError(interp, filename);
if (fd >= 0) {
close(fd);
}
Jim_DecrRefCount(interp, filename);
return JIM_ERR;
}
af = Jim_Alloc(sizeof(*af));
memset(af, 0, sizeof(*af));
af->fp = fh;
af->fd = fileno(fh);
af->filename = filename;
#ifdef FD_CLOEXEC
if ((OpenFlags & AIO_KEEPOPEN) == 0) {
fcntl(af->fd, F_SETFD, FD_CLOEXEC);
}
#endif
af->OpenFlags = OpenFlags;
#ifdef O_NDELAY
af->flags = fcntl(af->fd, F_GETFL);
#endif
af->addr_family = family;
snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
|
| ︙ | | | ︙ | |
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
|
Jim_CreateCommand(interp, "open", JimAioOpenCommand, NULL, NULL);
#ifndef JIM_ANSIC
Jim_CreateCommand(interp, "socket", JimAioSockCommand, NULL, NULL);
#endif
Jim_EvalGlobal(interp, "open stdin; open stdout; open stderr");
return JIM_OK;
}
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
int Jim_ReaddirCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *dirPath;
DIR *dirPtr;
struct dirent *entryPtr;
int nocomplain = 0;
|
|
>
>
|
>
>
>
|
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
|
Jim_CreateCommand(interp, "open", JimAioOpenCommand, NULL, NULL);
#ifndef JIM_ANSIC
Jim_CreateCommand(interp, "socket", JimAioSockCommand, NULL, NULL);
#endif
JimMakeChannel(interp, stdin, -1, NULL, "stdin", 0, "r");
JimMakeChannel(interp, stdout, -1, NULL, "stdout", 0, "w");
JimMakeChannel(interp, stderr, -1, NULL, "stderr", 0, "w");
return JIM_OK;
}
#include <errno.h>
#include <stdio.h>
#include <string.h>
#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;
|
| ︙ | | | ︙ | |
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
|
return JIM_OK;
}
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/time.h>
# ifndef MAXPATHLEN
# define MAXPATHLEN JIM_PATH_LEN
# endif
static const char *JimGetFileType(int mode)
{
if (S_ISREG(mode)) {
return "file";
}
else if (S_ISDIR(mode)) {
return "directory";
}
else if (S_ISCHR(mode)) {
return "characterSpecial";
}
else if (S_ISBLK(mode)) {
return "blockSpecial";
}
else if (S_ISFIFO(mode)) {
return "fifo";
#ifdef S_ISLNK
}
else if (S_ISLNK(mode)) {
return "link";
#endif
#ifdef S_ISSOCK
}
else if (S_ISSOCK(mode)) {
return "socket";
#endif
}
return "unknown";
}
static int set_array_int_value(Jim_Interp *interp, Jim_Obj *container, const char *key,
jim_wide value)
{
|
|
|
>
>
>
|
>
>
|
>
|
|
>
>
>
>
>
>
>
>
>
>
<
>
>
>
<
<
>
|
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
|
return JIM_OK;
}
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#ifdef HAVE_UTIMES
#include <sys/time.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#elif defined(_MSC_VER)
#include <direct.h>
#define F_OK 0
#define W_OK 2
#define R_OK 4
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
# ifndef MAXPATHLEN
# define MAXPATHLEN JIM_PATH_LEN
# endif
static const char *JimGetFileType(int mode)
{
if (S_ISREG(mode)) {
return "file";
}
else if (S_ISDIR(mode)) {
return "directory";
}
#ifdef S_ISCHR
else if (S_ISCHR(mode)) {
return "characterSpecial";
}
#endif
#ifdef S_ISBLK
else if (S_ISBLK(mode)) {
return "blockSpecial";
}
#endif
#ifdef S_ISFIFO
else if (S_ISFIFO(mode)) {
return "fifo";
}
#endif
#ifdef S_ISLNK
else if (S_ISLNK(mode)) {
return "link";
}
#endif
#ifdef S_ISSOCK
else if (S_ISSOCK(mode)) {
return "socket";
}
#endif
return "unknown";
}
static int set_array_int_value(Jim_Interp *interp, Jim_Obj *container, const char *key,
jim_wide value)
{
|
| ︙ | | | ︙ | |
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
|
if (!p) {
Jim_SetResultString(interp, ".", -1);
}
else if (p == path) {
Jim_SetResultString(interp, "/", -1);
}
#if defined(__MINGW32__)
else if (p[-1] == ':') {
Jim_SetResultString(interp, path, p - path + 1);
}
#endif
else {
Jim_SetResultString(interp, path, p - path);
|
|
|
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
|
if (!p) {
Jim_SetResultString(interp, ".", -1);
}
else if (p == path) {
Jim_SetResultString(interp, "/", -1);
}
#if defined(__MINGW32__) || defined(_MSC_VER)
else if (p[-1] == ':') {
Jim_SetResultString(interp, path, p - path + 1);
}
#endif
else {
Jim_SetResultString(interp, path, p - path);
|
| ︙ | | | ︙ | |
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
|
int len;
const char *part = Jim_GetString(argv[i], &len);
if (*part == '/') {
last = newname;
}
#if defined(__MINGW32__)
else if (strchr(part, ':')) {
last = newname;
}
#endif
else if (part[0] == '.') {
if (part[1] == '/') {
|
|
|
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
|
int len;
const char *part = Jim_GetString(argv[i], &len);
if (*part == '/') {
last = newname;
}
#if defined(__MINGW32__) || defined(_MSC_VER)
else if (strchr(part, ':')) {
last = newname;
}
#endif
else if (part[0] == '.') {
if (part[1] == '/') {
|
| ︙ | | | ︙ | |
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
|
static int file_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return file_access(interp, argv[0], W_OK);
}
static int file_cmd_executable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return file_access(interp, argv[0], X_OK);
}
static int file_cmd_exists(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return file_access(interp, argv[0], F_OK);
}
|
>
>
>
>
>
|
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
|
static int file_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return file_access(interp, argv[0], W_OK);
}
static int file_cmd_executable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
#ifdef X_OK
return file_access(interp, argv[0], X_OK);
#else
Jim_SetResultBool(interp, 1);
return JIM_OK;
#endif
}
static int file_cmd_exists(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return file_access(interp, argv[0], F_OK);
}
|
| ︙ | | | ︙ | |
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
|
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
return JIM_ERR;
}
return StoreStatData(interp, argv[1], &sb);
}
static const jim_subcmd_type file_command_table[] = {
{ .cmd = "atime",
.args = "name",
.function = file_cmd_atime,
.minargs = 1,
.maxargs = 1,
.description = "Last access time"
},
{ .cmd = "mtime",
.args = "name ?time?",
.function = file_cmd_mtime,
.minargs = 1,
.maxargs = 2,
.description = "Get or set last modification time"
},
{ .cmd = "copy",
.args = "?-force? source dest",
.function = file_cmd_copy,
.minargs = 2,
.maxargs = 3,
.description = "Copy source file to destination file"
},
{ .cmd = "dirname",
.args = "name",
.function = file_cmd_dirname,
.minargs = 1,
.maxargs = 1,
.description = "Directory part of the name"
},
{ .cmd = "rootname",
.args = "name",
.function = file_cmd_rootname,
.minargs = 1,
.maxargs = 1,
.description = "Name without any extension"
},
{ .cmd = "extension",
.args = "name",
.function = file_cmd_extension,
.minargs = 1,
.maxargs = 1,
.description = "Last extension including the dot"
},
{ .cmd = "tail",
.args = "name",
.function = file_cmd_tail,
.minargs = 1,
.maxargs = 1,
.description = "Last component of the name"
},
{ .cmd = "normalize",
.args = "name",
.function = file_cmd_normalize,
.minargs = 1,
.maxargs = 1,
.description = "Normalized path of name"
},
{ .cmd = "join",
.args = "name ?name ...?",
.function = file_cmd_join,
.minargs = 1,
.maxargs = -1,
.description = "Join multiple path components"
},
{ .cmd = "readable",
.args = "name",
.function = file_cmd_readable,
.minargs = 1,
.maxargs = 1,
.description = "Is file readable"
},
{ .cmd = "writable",
.args = "name",
.function = file_cmd_writable,
.minargs = 1,
.maxargs = 1,
.description = "Is file writable"
},
{ .cmd = "executable",
.args = "name",
.function = file_cmd_executable,
.minargs = 1,
.maxargs = 1,
.description = "Is file executable"
},
{ .cmd = "exists",
.args = "name",
.function = file_cmd_exists,
.minargs = 1,
.maxargs = 1,
.description = "Does file exist"
},
{ .cmd = "delete",
.args = "?-force|--? name ...",
.function = file_cmd_delete,
.minargs = 1,
.maxargs = -1,
.description = "Deletes the files or directories (must be empty unless -force)"
},
{ .cmd = "mkdir",
.args = "dir ...",
.function = file_cmd_mkdir,
.minargs = 1,
.maxargs = -1,
.description = "Creates the directories"
},
#ifdef HAVE_MKSTEMP
{ .cmd = "tempfile",
.args = "?template?",
.function = file_cmd_tempfile,
.minargs = 0,
.maxargs = 1,
.description = "Creates a temporary filename"
},
#endif
{ .cmd = "rename",
.args = "?-force? source dest",
.function = file_cmd_rename,
.minargs = 2,
.maxargs = 3,
.description = "Renames a file"
},
#if defined(HAVE_READLINK)
{ .cmd = "readlink",
.args = "name",
.function = file_cmd_readlink,
.minargs = 1,
.maxargs = 1,
.description = "Value of the symbolic link"
},
#endif
{ .cmd = "size",
.args = "name",
.function = file_cmd_size,
.minargs = 1,
.maxargs = 1,
.description = "Size of file"
},
{ .cmd = "stat",
.args = "name var",
.function = file_cmd_stat,
.minargs = 2,
.maxargs = 2,
.description = "Stores results of stat in var array"
},
{ .cmd = "lstat",
.args = "name var",
.function = file_cmd_lstat,
.minargs = 2,
.maxargs = 2,
.description = "Stores results of lstat in var array"
},
{ .cmd = "type",
.args = "name",
.function = file_cmd_type,
.minargs = 1,
.maxargs = 1,
.description = "Returns type of the file"
},
#ifdef HAVE_GETEUID
{ .cmd = "owned",
.args = "name",
.function = file_cmd_owned,
.minargs = 1,
.maxargs = 1,
.description = "Returns 1 if owned by the current owner"
},
#endif
{ .cmd = "isdirectory",
.args = "name",
.function = file_cmd_isdirectory,
.minargs = 1,
.maxargs = 1,
.description = "Returns 1 if name is a directory"
},
{ .cmd = "isfile",
.args = "name",
.function = file_cmd_isfile,
.minargs = 1,
.maxargs = 1,
.description = "Returns 1 if name is a file"
},
{
.cmd = 0
}
};
static int Jim_CdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *path;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
>
|
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
|
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
return JIM_ERR;
}
return StoreStatData(interp, argv[1], &sb);
}
static const jim_subcmd_type file_command_table[] = {
{ "atime",
"name",
file_cmd_atime,
1,
1,
},
{ "mtime",
"name ?time?",
file_cmd_mtime,
1,
2,
},
{ "copy",
"?-force? source dest",
file_cmd_copy,
2,
3,
},
{ "dirname",
"name",
file_cmd_dirname,
1,
1,
},
{ "rootname",
"name",
file_cmd_rootname,
1,
1,
},
{ "extension",
"name",
file_cmd_extension,
1,
1,
},
{ "tail",
"name",
file_cmd_tail,
1,
1,
},
{ "normalize",
"name",
file_cmd_normalize,
1,
1,
},
{ "join",
"name ?name ...?",
file_cmd_join,
1,
-1,
},
{ "readable",
"name",
file_cmd_readable,
1,
1,
},
{ "writable",
"name",
file_cmd_writable,
1,
1,
},
{ "executable",
"name",
file_cmd_executable,
1,
1,
},
{ "exists",
"name",
file_cmd_exists,
1,
1,
},
{ "delete",
"?-force|--? name ...",
file_cmd_delete,
1,
-1,
},
{ "mkdir",
"dir ...",
file_cmd_mkdir,
1,
-1,
},
#ifdef HAVE_MKSTEMP
{ "tempfile",
"?template?",
file_cmd_tempfile,
0,
1,
},
#endif
{ "rename",
"?-force? source dest",
file_cmd_rename,
2,
3,
},
#if defined(HAVE_READLINK)
{ "readlink",
"name",
file_cmd_readlink,
1,
1,
},
#endif
{ "size",
"name",
file_cmd_size,
1,
1,
},
{ "stat",
"name var",
file_cmd_stat,
2,
2,
},
{ "lstat",
"name var",
file_cmd_lstat,
2,
2,
},
{ "type",
"name",
file_cmd_type,
1,
1,
},
#ifdef HAVE_GETEUID
{ "owned",
"name",
file_cmd_owned,
1,
1,
},
#endif
{ "isdirectory",
"name",
file_cmd_isdirectory,
1,
1,
},
{ "isfile",
"name",
file_cmd_isfile,
1,
1,
},
{
NULL
}
};
static int Jim_CdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *path;
|
| ︙ | | | ︙ | |
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
|
const int cwd_len = 2048;
char *cwd = malloc(cwd_len);
if (getcwd(cwd, cwd_len) == NULL) {
Jim_SetResultString(interp, "Failed to get pwd", -1);
return JIM_ERR;
}
#if defined(__MINGW32__)
{
char *p = cwd;
while ((p = strchr(p, '\\')) != NULL) {
*p++ = '/';
}
}
|
|
|
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
|
const int cwd_len = 2048;
char *cwd = malloc(cwd_len);
if (getcwd(cwd, cwd_len) == NULL) {
Jim_SetResultString(interp, "Failed to get pwd", -1);
return JIM_ERR;
}
#if defined(__MINGW32__) || defined(_MSC_VER)
{
char *p = cwd;
while ((p = strchr(p, '\\')) != NULL) {
*p++ = '/';
}
}
|
| ︙ | | | ︙ | |
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
|
}
#else
#include <errno.h>
#include <signal.h>
#define XXX printf("@%s:%d\n", __FILE__, __LINE__); fflush(stdout);
#if defined(__MINGW32__)
#include <fcntl.h>
typedef HANDLE fdtype;
typedef HANDLE pidtype;
#define JIM_BAD_FD INVALID_HANDLE_VALUE
#define JIM_BAD_PID INVALID_HANDLE_VALUE
#define JimCloseFd CloseHandle
|
<
<
>
>
>
>
>
|
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
|
}
#else
#include <errno.h>
#include <signal.h>
#if defined(__MINGW32__)
#ifndef STRICT
#define STRICT
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <fcntl.h>
typedef HANDLE fdtype;
typedef HANDLE pidtype;
#define JIM_BAD_FD INVALID_HANDLE_VALUE
#define JIM_BAD_PID INVALID_HANDLE_VALUE
#define JimCloseFd CloseHandle
|
| ︙ | | | ︙ | |
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
|
#define _XOPEN_SOURCE 500
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
static int clock_cmd_format(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
char buf[100];
time_t t;
long seconds;
|
|
>
>
>
|
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
|
#define _XOPEN_SOURCE 500
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
static int clock_cmd_format(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
char buf[100];
time_t t;
long seconds;
|
| ︙ | | | ︙ | |
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
|
Jim_SetResultInt(interp, (jim_wide) tv.tv_sec * 1000 + tv.tv_usec / 1000);
return JIM_OK;
}
static const jim_subcmd_type clock_command_table[] = {
{ .cmd = "seconds",
.function = clock_cmd_seconds,
.minargs = 0,
.maxargs = 0,
.description = "Returns the current time as seconds since the epoch"
},
{ .cmd = "clicks",
.function = clock_cmd_micros,
.minargs = 0,
.maxargs = 0,
.description = "Returns the current time in 'clicks'"
},
{ .cmd = "microseconds",
.function = clock_cmd_micros,
.minargs = 0,
.maxargs = 0,
.description = "Returns the current time in microseconds"
},
{ .cmd = "milliseconds",
.function = clock_cmd_millis,
.minargs = 0,
.maxargs = 0,
.description = "Returns the current time in milliseconds"
},
{ .cmd = "format",
.args = "seconds ?-format format?",
.function = clock_cmd_format,
.minargs = 1,
.maxargs = 3,
.description = "Format the given time"
},
#ifdef HAVE_STRPTIME
{ .cmd = "scan",
.args = "str -format format",
.function = clock_cmd_scan,
.minargs = 3,
.maxargs = 3,
.description = "Determine the time according to the given format"
},
#endif
{ 0 }
};
int Jim_clockInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "clock", "1.0", JIM_ERRMSG))
return JIM_ERR;
Jim_CreateCommand(interp, "clock", Jim_SubCmdProc, (void *)clock_command_table, NULL);
return JIM_OK;
}
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
static int array_cmd_exists(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_SetResultInt(interp, Jim_GetVariable(interp, argv[0], 0) != 0);
|
|
>
|
|
|
|
|
>
|
|
|
|
|
>
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
|
Jim_SetResultInt(interp, (jim_wide) tv.tv_sec * 1000 + tv.tv_usec / 1000);
return JIM_OK;
}
static const jim_subcmd_type clock_command_table[] = {
{ "seconds",
NULL,
clock_cmd_seconds,
0,
0,
},
{ "clicks",
NULL,
clock_cmd_micros,
0,
0,
},
{ "microseconds",
NULL,
clock_cmd_micros,
0,
0,
},
{ "milliseconds",
NULL,
clock_cmd_millis,
0,
0,
},
{ "format",
"seconds ?-format format?",
clock_cmd_format,
1,
3,
},
#ifdef HAVE_STRPTIME
{ "scan",
"str -format format",
clock_cmd_scan,
3,
3,
},
#endif
{ NULL }
};
int Jim_clockInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "clock", "1.0", JIM_ERRMSG))
return JIM_ERR;
Jim_CreateCommand(interp, "clock", Jim_SubCmdProc, (void *)clock_command_table, NULL);
return JIM_OK;
}
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
static int array_cmd_exists(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_SetResultInt(interp, Jim_GetVariable(interp, argv[0], 0) != 0);
|
| ︙ | | | ︙ | |
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
|
rc = Jim_SetDictKeysVector(interp, argv[0], &nameObj, 1, valueObj, JIM_ERRMSG);
}
return rc;
}
static const jim_subcmd_type array_command_table[] = {
{ .cmd = "exists",
.args = "arrayName",
.function = array_cmd_exists,
.minargs = 1,
.maxargs = 1,
.description = "Does array exist?"
},
{ .cmd = "get",
.args = "arrayName ?pattern?",
.function = array_cmd_get,
.minargs = 1,
.maxargs = 2,
.description = "Array contents as name value list"
},
{ .cmd = "names",
.args = "arrayName ?pattern?",
.function = array_cmd_names,
.minargs = 1,
.maxargs = 2,
.description = "Array keys as a list"
},
{ .cmd = "set",
.args = "arrayName list",
.function = array_cmd_set,
.minargs = 2,
.maxargs = 2,
.description = "Set array from list"
},
{ .cmd = "size",
.args = "arrayName",
.function = array_cmd_size,
.minargs = 1,
.maxargs = 1,
.description = "Number of elements in array"
},
{ .cmd = "unset",
.args = "arrayName ?pattern?",
.function = array_cmd_unset,
.minargs = 1,
.maxargs = 2,
.description = "Unset elements of an array"
},
{ .cmd = 0,
}
};
int Jim_arrayInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "array", "1.0", JIM_ERRMSG))
return JIM_ERR;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
|
rc = Jim_SetDictKeysVector(interp, argv[0], &nameObj, 1, valueObj, JIM_ERRMSG);
}
return rc;
}
static const jim_subcmd_type array_command_table[] = {
{ "exists",
"arrayName",
array_cmd_exists,
1,
1,
},
{ "get",
"arrayName ?pattern?",
array_cmd_get,
1,
2,
},
{ "names",
"arrayName ?pattern?",
array_cmd_names,
1,
2,
},
{ "set",
"arrayName list",
array_cmd_set,
2,
2,
},
{ "size",
"arrayName",
array_cmd_size,
1,
1,
},
{ "unset",
"arrayName ?pattern?",
array_cmd_unset,
1,
2,
},
{ NULL
}
};
int Jim_arrayInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "array", "1.0", JIM_ERRMSG))
return JIM_ERR;
|
| ︙ | | | ︙ | |
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
|
#include <ctype.h>
#include <limits.h>
#include <assert.h>
#include <errno.h>
#include <time.h>
#include <setjmp.h>
#include <unistd.h>
#include <sys/time.h>
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#endif
#ifdef HAVE_CRT_EXTERNS_H
#include <crt_externs.h>
#endif
|
|
>
|
<
|
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
|
#include <ctype.h>
#include <limits.h>
#include <assert.h>
#include <errno.h>
#include <time.h>
#include <setjmp.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#endif
#ifdef HAVE_CRT_EXTERNS_H
#include <crt_externs.h>
#endif
|
| ︙ | | | ︙ | |
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
|
*indexPtr = objPtr->internalRep.indexValue;
return JIM_OK;
}
static const char * const jimReturnCodes[] = {
[JIM_OK] = "ok",
[JIM_ERR] = "error",
[JIM_RETURN] = "return",
[JIM_BREAK] = "break",
[JIM_CONTINUE] = "continue",
[JIM_SIGNAL] = "signal",
[JIM_EXIT] = "exit",
[JIM_EVAL] = "eval",
NULL
};
#define jimReturnCodesSize (sizeof(jimReturnCodes)/sizeof(*jimReturnCodes))
static int SetReturnCodeFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
|
|
|
|
|
|
|
|
|
|
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
|
*indexPtr = objPtr->internalRep.indexValue;
return JIM_OK;
}
static const char * const jimReturnCodes[] = {
"ok",
"error",
"return",
"break",
"continue",
"signal",
"exit",
"eval",
NULL
};
#define jimReturnCodesSize (sizeof(jimReturnCodes)/sizeof(*jimReturnCodes))
static int SetReturnCodeFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
|
| ︙ | | | ︙ | |
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
|
enum
{
JIM_EXPROP_MUL = JIM_TT_EXPR_OP,
JIM_EXPROP_DIV,
JIM_EXPROP_MOD,
JIM_EXPROP_SUB,
JIM_EXPROP_ADD,
JIM_EXPROP_LSHIFT,
JIM_EXPROP_RSHIFT,
JIM_EXPROP_ROTL,
|
|
|
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
|
enum
{
JIM_EXPROP_MUL = JIM_TT_EXPR_OP,
JIM_EXPROP_DIV,
JIM_EXPROP_MOD,
JIM_EXPROP_SUB,
JIM_EXPROP_ADD,
JIM_EXPROP_LSHIFT,
JIM_EXPROP_RSHIFT,
JIM_EXPROP_ROTL,
|
| ︙ | | | ︙ | |
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
|
JIM_EXPROP_COLON,
JIM_EXPROP_COLON_LEFT,
JIM_EXPROP_COLON_RIGHT,
JIM_EXPROP_POW,
JIM_EXPROP_STREQ,
JIM_EXPROP_STRNE,
JIM_EXPROP_STRIN,
JIM_EXPROP_STRNI,
JIM_EXPROP_NOT,
JIM_EXPROP_BITNOT,
JIM_EXPROP_UNARYMINUS,
JIM_EXPROP_UNARYPLUS,
JIM_EXPROP_FUNC_FIRST,
JIM_EXPROP_FUNC_INT = JIM_EXPROP_FUNC_FIRST,
JIM_EXPROP_FUNC_ABS,
JIM_EXPROP_FUNC_DOUBLE,
JIM_EXPROP_FUNC_ROUND,
JIM_EXPROP_FUNC_RAND,
JIM_EXPROP_FUNC_SRAND,
JIM_EXPROP_FUNC_SIN,
JIM_EXPROP_FUNC_COS,
JIM_EXPROP_FUNC_TAN,
JIM_EXPROP_FUNC_ASIN,
JIM_EXPROP_FUNC_ACOS,
JIM_EXPROP_FUNC_ATAN,
JIM_EXPROP_FUNC_SINH,
JIM_EXPROP_FUNC_COSH,
|
|
|
|
|
|
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
|
JIM_EXPROP_COLON,
JIM_EXPROP_COLON_LEFT,
JIM_EXPROP_COLON_RIGHT,
JIM_EXPROP_POW,
JIM_EXPROP_STREQ,
JIM_EXPROP_STRNE,
JIM_EXPROP_STRIN,
JIM_EXPROP_STRNI,
JIM_EXPROP_NOT,
JIM_EXPROP_BITNOT,
JIM_EXPROP_UNARYMINUS,
JIM_EXPROP_UNARYPLUS,
JIM_EXPROP_FUNC_FIRST,
JIM_EXPROP_FUNC_INT = JIM_EXPROP_FUNC_FIRST,
JIM_EXPROP_FUNC_ABS,
JIM_EXPROP_FUNC_DOUBLE,
JIM_EXPROP_FUNC_ROUND,
JIM_EXPROP_FUNC_RAND,
JIM_EXPROP_FUNC_SRAND,
JIM_EXPROP_FUNC_SIN,
JIM_EXPROP_FUNC_COS,
JIM_EXPROP_FUNC_TAN,
JIM_EXPROP_FUNC_ASIN,
JIM_EXPROP_FUNC_ACOS,
JIM_EXPROP_FUNC_ATAN,
JIM_EXPROP_FUNC_SINH,
JIM_EXPROP_FUNC_COSH,
|
| ︙ | | | ︙ | |
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
|
{
LAZY_NONE,
LAZY_OP,
LAZY_LEFT,
LAZY_RIGHT
};
static const struct Jim_ExprOperator Jim_ExprOperators[] = {
[JIM_EXPROP_FUNC_INT] = {"int", 400, 1, JimExprOpNumUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_DOUBLE] = {"double", 400, 1, JimExprOpNumUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_ABS] = {"abs", 400, 1, JimExprOpNumUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_ROUND] = {"round", 400, 1, JimExprOpNumUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_RAND] = {"rand", 400, 0, JimExprOpNone, LAZY_NONE},
[JIM_EXPROP_FUNC_SRAND] = {"srand", 400, 1, JimExprOpIntUnary, LAZY_NONE},
#ifdef JIM_MATH_FUNCTIONS
[JIM_EXPROP_FUNC_SIN] = {"sin", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_COS] = {"cos", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_TAN] = {"tan", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_ASIN] = {"asin", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_ACOS] = {"acos", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_ATAN] = {"atan", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_SINH] = {"sinh", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_COSH] = {"cosh", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_TANH] = {"tanh", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_CEIL] = {"ceil", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_FLOOR] = {"floor", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_EXP] = {"exp", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_LOG] = {"log", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_LOG10] = {"log10", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_SQRT] = {"sqrt", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
[JIM_EXPROP_FUNC_POW] = {"pow", 400, 2, JimExprOpBin, LAZY_NONE},
#endif
[JIM_EXPROP_NOT] = {"!", 300, 1, JimExprOpNumUnary, LAZY_NONE},
[JIM_EXPROP_BITNOT] = {"~", 300, 1, JimExprOpIntUnary, LAZY_NONE},
[JIM_EXPROP_UNARYMINUS] = {NULL, 300, 1, JimExprOpNumUnary, LAZY_NONE},
[JIM_EXPROP_UNARYPLUS] = {NULL, 300, 1, JimExprOpNumUnary, LAZY_NONE},
[JIM_EXPROP_POW] = {"**", 250, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_MUL] = {"*", 200, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_DIV] = {"/", 200, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_MOD] = {"%", 200, 2, JimExprOpIntBin, LAZY_NONE},
[JIM_EXPROP_SUB] = {"-", 100, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_ADD] = {"+", 100, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_ROTL] = {"<<<", 90, 2, JimExprOpIntBin, LAZY_NONE},
[JIM_EXPROP_ROTR] = {">>>", 90, 2, JimExprOpIntBin, LAZY_NONE},
[JIM_EXPROP_LSHIFT] = {"<<", 90, 2, JimExprOpIntBin, LAZY_NONE},
[JIM_EXPROP_RSHIFT] = {">>", 90, 2, JimExprOpIntBin, LAZY_NONE},
[JIM_EXPROP_LT] = {"<", 80, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_GT] = {">", 80, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_LTE] = {"<=", 80, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_GTE] = {">=", 80, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_NUMEQ] = {"==", 70, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_NUMNE] = {"!=", 70, 2, JimExprOpBin, LAZY_NONE},
[JIM_EXPROP_STREQ] = {"eq", 60, 2, JimExprOpStrBin, LAZY_NONE},
[JIM_EXPROP_STRNE] = {"ne", 60, 2, JimExprOpStrBin, LAZY_NONE},
[JIM_EXPROP_STRIN] = {"in", 55, 2, JimExprOpStrBin, LAZY_NONE},
[JIM_EXPROP_STRNI] = {"ni", 55, 2, JimExprOpStrBin, LAZY_NONE},
[JIM_EXPROP_BITAND] = {"&", 50, 2, JimExprOpIntBin, LAZY_NONE},
[JIM_EXPROP_BITXOR] = {"^", 49, 2, JimExprOpIntBin, LAZY_NONE},
[JIM_EXPROP_BITOR] = {"|", 48, 2, JimExprOpIntBin, LAZY_NONE},
[JIM_EXPROP_LOGICAND] = {"&&", 10, 2, NULL, LAZY_OP},
[JIM_EXPROP_LOGICOR] = {"||", 9, 2, NULL, LAZY_OP},
[JIM_EXPROP_TERNARY] = {"?", 5, 2, JimExprOpNull, LAZY_OP},
[JIM_EXPROP_COLON] = {":", 5, 2, JimExprOpNull, LAZY_OP},
[JIM_EXPROP_TERNARY_LEFT] = {NULL, 5, 2, JimExprOpTernaryLeft, LAZY_LEFT},
[JIM_EXPROP_TERNARY_RIGHT] = {NULL, 5, 2, JimExprOpNull, LAZY_RIGHT},
[JIM_EXPROP_COLON_LEFT] = {NULL, 5, 2, JimExprOpColonLeft, LAZY_LEFT},
[JIM_EXPROP_COLON_RIGHT] = {NULL, 5, 2, JimExprOpNull, LAZY_RIGHT},
[JIM_EXPROP_LOGICAND_LEFT] = {NULL, 10, 2, JimExprOpAndLeft, LAZY_LEFT},
[JIM_EXPROP_LOGICAND_RIGHT] = {NULL, 10, 2, JimExprOpAndOrRight, LAZY_RIGHT},
[JIM_EXPROP_LOGICOR_LEFT] = {NULL, 9, 2, JimExprOpOrLeft, LAZY_LEFT},
[JIM_EXPROP_LOGICOR_RIGHT] = {NULL, 9, 2, JimExprOpAndOrRight, LAZY_RIGHT},
};
#define JIM_EXPR_OPERATORS_NUM \
(sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator))
static int JimParseExpression(struct JimParserCtx *pc)
{
|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
|
{
LAZY_NONE,
LAZY_OP,
LAZY_LEFT,
LAZY_RIGHT
};
static const struct Jim_ExprOperator Jim_ExprOperators[] = {
{"*", 200, 2, JimExprOpBin, LAZY_NONE},
{"/", 200, 2, JimExprOpBin, LAZY_NONE},
{"%", 200, 2, JimExprOpIntBin, LAZY_NONE},
{"-", 100, 2, JimExprOpBin, LAZY_NONE},
{"+", 100, 2, JimExprOpBin, LAZY_NONE},
{"<<", 90, 2, JimExprOpIntBin, LAZY_NONE},
{">>", 90, 2, JimExprOpIntBin, LAZY_NONE},
{"<<<", 90, 2, JimExprOpIntBin, LAZY_NONE},
{">>>", 90, 2, JimExprOpIntBin, LAZY_NONE},
{"<", 80, 2, JimExprOpBin, LAZY_NONE},
{">", 80, 2, JimExprOpBin, LAZY_NONE},
{"<=", 80, 2, JimExprOpBin, LAZY_NONE},
{">=", 80, 2, JimExprOpBin, LAZY_NONE},
{"==", 70, 2, JimExprOpBin, LAZY_NONE},
{"!=", 70, 2, JimExprOpBin, LAZY_NONE},
{"&", 50, 2, JimExprOpIntBin, LAZY_NONE},
{"^", 49, 2, JimExprOpIntBin, LAZY_NONE},
{"|", 48, 2, JimExprOpIntBin, LAZY_NONE},
{"&&", 10, 2, NULL, LAZY_OP},
{NULL, 10, 2, JimExprOpAndLeft, LAZY_LEFT},
{NULL, 10, 2, JimExprOpAndOrRight, LAZY_RIGHT},
{"||", 9, 2, NULL, LAZY_OP},
{NULL, 9, 2, JimExprOpOrLeft, LAZY_LEFT},
{NULL, 9, 2, JimExprOpAndOrRight, LAZY_RIGHT},
{"?", 5, 2, JimExprOpNull, LAZY_OP},
{NULL, 5, 2, JimExprOpTernaryLeft, LAZY_LEFT},
{NULL, 5, 2, JimExprOpNull, LAZY_RIGHT},
{":", 5, 2, JimExprOpNull, LAZY_OP},
{NULL, 5, 2, JimExprOpColonLeft, LAZY_LEFT},
{NULL, 5, 2, JimExprOpNull, LAZY_RIGHT},
{"**", 250, 2, JimExprOpBin, LAZY_NONE},
{"eq", 60, 2, JimExprOpStrBin, LAZY_NONE},
{"ne", 60, 2, JimExprOpStrBin, LAZY_NONE},
{"in", 55, 2, JimExprOpStrBin, LAZY_NONE},
{"ni", 55, 2, JimExprOpStrBin, LAZY_NONE},
{"!", 300, 1, JimExprOpNumUnary, LAZY_NONE},
{"~", 300, 1, JimExprOpIntUnary, LAZY_NONE},
{NULL, 300, 1, JimExprOpNumUnary, LAZY_NONE},
{NULL, 300, 1, JimExprOpNumUnary, LAZY_NONE},
{"int", 400, 1, JimExprOpNumUnary, LAZY_NONE},
{"abs", 400, 1, JimExprOpNumUnary, LAZY_NONE},
{"double", 400, 1, JimExprOpNumUnary, LAZY_NONE},
{"round", 400, 1, JimExprOpNumUnary, LAZY_NONE},
{"rand", 400, 0, JimExprOpNone, LAZY_NONE},
{"srand", 400, 1, JimExprOpIntUnary, LAZY_NONE},
#ifdef JIM_MATH_FUNCTIONS
{"sin", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"cos", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"tan", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"asin", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"acos", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"atan", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"sinh", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"cosh", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"tanh", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"ceil", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"floor", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"exp", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"log", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"log10", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"sqrt", 400, 1, JimExprOpDoubleUnary, LAZY_NONE},
{"pow", 400, 2, JimExprOpBin, LAZY_NONE},
#endif
};
#define JIM_EXPR_OPERATORS_NUM \
(sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator))
static int JimParseExpression(struct JimParserCtx *pc)
{
|
| ︙ | | | ︙ | |
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
|
static int JimParseExprOperator(struct JimParserCtx *pc)
{
int i;
int bestIdx = -1, bestLen = 0;
for (i = JIM_TT_EXPR_OP; i < (signed)JIM_EXPR_OPERATORS_NUM; i++) {
const char *opname;
int oplen;
opname = Jim_ExprOperators[i].name;
if (opname == NULL) {
continue;
}
oplen = strlen(opname);
if (strncmp(opname, pc->p, oplen) == 0 && oplen > bestLen) {
bestIdx = i;
bestLen = oplen;
}
}
if (bestIdx == -1) {
return JIM_ERR;
}
|
|
|
|
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
|
static int JimParseExprOperator(struct JimParserCtx *pc)
{
int i;
int bestIdx = -1, bestLen = 0;
for (i = 0; i < (signed)JIM_EXPR_OPERATORS_NUM; i++) {
const char *opname;
int oplen;
opname = Jim_ExprOperators[i].name;
if (opname == NULL) {
continue;
}
oplen = strlen(opname);
if (strncmp(opname, pc->p, oplen) == 0 && oplen > bestLen) {
bestIdx = i + JIM_TT_EXPR_OP;
bestLen = oplen;
}
}
if (bestIdx == -1) {
return JIM_ERR;
}
|
| ︙ | | | ︙ | |
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
|
pc->tt = bestIdx;
return JIM_OK;
}
static const struct Jim_ExprOperator *JimExprOperatorInfoByOpcode(int opcode)
{
return &Jim_ExprOperators[opcode];
}
const char *jim_tt_name(int type)
{
static const char * const tt_names[JIM_TT_EXPR_OP] =
{ "NIL", "STR", "ESC", "VAR", "ARY", "CMD", "SEP", "EOL", "EOF", "LIN", "WRD", "(((", ")))", ",,,", "INT",
"DBL", "$()" };
if (type < JIM_TT_EXPR_OP) {
return tt_names[type];
}
else {
const struct Jim_ExprOperator *op = JimExprOperatorInfoByOpcode(type);
static char buf[20];
if (op && op->name) {
return op->name;
}
sprintf(buf, "(%d)", type);
return buf;
}
}
|
>
>
>
>
|
|
|
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
|
pc->tt = bestIdx;
return JIM_OK;
}
static const struct Jim_ExprOperator *JimExprOperatorInfoByOpcode(int opcode)
{
static Jim_ExprOperator dummy_op;
if (opcode < JIM_TT_EXPR_OP) {
return &dummy_op;
}
return &Jim_ExprOperators[opcode - JIM_TT_EXPR_OP];
}
const char *jim_tt_name(int type)
{
static const char * const tt_names[JIM_TT_EXPR_OP] =
{ "NIL", "STR", "ESC", "VAR", "ARY", "CMD", "SEP", "EOL", "EOF", "LIN", "WRD", "(((", ")))", ",,,", "INT",
"DBL", "$()" };
if (type < JIM_TT_EXPR_OP) {
return tt_names[type];
}
else {
const struct Jim_ExprOperator *op = JimExprOperatorInfoByOpcode(type);
static char buf[20];
if (op->name) {
return op->name;
}
sprintf(buf, "(%d)", type);
return buf;
}
}
|
| ︙ | | | ︙ | |
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
|
int stacklen = 0;
int ternary = 0;
for (i = 0; i < expr->len; i++) {
ScriptToken *t = &expr->token[i];
const struct Jim_ExprOperator *op = JimExprOperatorInfoByOpcode(t->type);
if (op) {
stacklen -= op->arity;
if (stacklen < 0) {
break;
}
if (t->type == JIM_EXPROP_TERNARY || t->type == JIM_EXPROP_TERNARY_LEFT) {
ternary++;
}
else if (t->type == JIM_EXPROP_COLON || t->type == JIM_EXPROP_COLON_LEFT) {
ternary--;
}
}
stacklen++;
}
if (stacklen != 1 || ternary != 0) {
return JIM_ERR;
|
<
|
|
|
|
|
|
|
|
|
<
|
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
|
int stacklen = 0;
int ternary = 0;
for (i = 0; i < expr->len; i++) {
ScriptToken *t = &expr->token[i];
const struct Jim_ExprOperator *op = JimExprOperatorInfoByOpcode(t->type);
stacklen -= op->arity;
if (stacklen < 0) {
break;
}
if (t->type == JIM_EXPROP_TERNARY || t->type == JIM_EXPROP_TERNARY_LEFT) {
ternary++;
}
else if (t->type == JIM_EXPROP_COLON || t->type == JIM_EXPROP_COLON_LEFT) {
ternary--;
}
stacklen++;
}
if (stacklen != 1 || ternary != 0) {
return JIM_ERR;
|
| ︙ | | | ︙ | |
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
|
expr->token[expr->len].objPtr = interp->emptyObj;
expr->token[expr->len].type = t->type + 2;
expr->len++;
for (i = leftindex - 1; i > 0; i--) {
if (JimExprOperatorInfoByOpcode(expr->token[i].type)->lazy == LAZY_LEFT) {
if (JimWideValue(expr->token[i - 1].objPtr) + i - 1 >= leftindex) {
JimWideValue(expr->token[i - 1].objPtr) += 2;
}
}
}
return JIM_OK;
}
|
|
>
|
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
|
expr->token[expr->len].objPtr = interp->emptyObj;
expr->token[expr->len].type = t->type + 2;
expr->len++;
for (i = leftindex - 1; i > 0; i--) {
const struct Jim_ExprOperator *op = JimExprOperatorInfoByOpcode(expr->token[i].type);
if (op->lazy == LAZY_LEFT) {
if (JimWideValue(expr->token[i - 1].objPtr) + i - 1 >= leftindex) {
JimWideValue(expr->token[i - 1].objPtr) += 2;
}
}
}
return JIM_OK;
}
|
| ︙ | | | ︙ | |
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
|
expr->inUse = 1;
expr->len = 0;
Jim_InitStack(&stack);
for (i = 0; i < tokenlist->count; i++) {
ParseToken *t = &tokenlist->list[i];
if (JimExprOperatorInfoByOpcode(t->type)->lazy == LAZY_OP) {
count += 2;
if (t->type == JIM_EXPROP_TERNARY) {
have_ternary = 1;
}
}
}
|
>
|
|
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
|
expr->inUse = 1;
expr->len = 0;
Jim_InitStack(&stack);
for (i = 0; i < tokenlist->count; i++) {
ParseToken *t = &tokenlist->list[i];
const struct Jim_ExprOperator *op = JimExprOperatorInfoByOpcode(t->type);
if (op->lazy == LAZY_OP) {
count += 2;
if (t->type == JIM_EXPROP_TERNARY) {
have_ternary = 1;
}
}
}
|
| ︙ | | | ︙ | |
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
|
if (argc % 2) {
Jim_WrongNumArgs(interp, 2, argv, "?key value ...?");
return JIM_ERR;
}
objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2);
Jim_SetResult(interp, objPtr);
return JIM_OK;
default:
abort();
}
}
static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
static const char * const options[] = {
"-nobackslashes", "-nocommands", "-novariables", NULL
|
|
|
<
<
|
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
|
if (argc % 2) {
Jim_WrongNumArgs(interp, 2, argv, "?key value ...?");
return JIM_ERR;
}
objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2);
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
return JIM_ERR;
}
static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
static const char * const options[] = {
"-nobackslashes", "-nocommands", "-novariables", NULL
|
| ︙ | | | ︙ | |
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
|
static int subcmd_null(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JIM_OK;
}
static const jim_subcmd_type dummy_subcmd = {
.cmd = "dummy",
.function = subcmd_null,
.flags = JIM_MODFLAG_HIDDEN,
};
static void add_commands(Jim_Interp *interp, const jim_subcmd_type * ct, const char *sep)
{
const char *s = "";
for (; ct->cmd; ct++) {
|
<
<
|
|
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
|
static int subcmd_null(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JIM_OK;
}
static const jim_subcmd_type dummy_subcmd = {
"dummy", NULL, subcmd_null, 0, 0, JIM_MODFLAG_HIDDEN
};
static void add_commands(Jim_Interp *interp, const jim_subcmd_type * ct, const char *sep)
{
const char *s = "";
for (; ct->cmd; ct++) {
|
| ︙ | | | ︙ | |
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
|
}
Jim_AppendStrings(interp, Jim_GetResult(interp), ct->cmd, NULL);
if (ct->args && *ct->args) {
Jim_AppendStrings(interp, Jim_GetResult(interp), " ", ct->args, NULL);
}
}
static void show_full_usage(Jim_Interp *interp, const jim_subcmd_type * ct, int argc,
Jim_Obj *const *argv)
{
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
for (; ct->cmd; ct++) {
if (!(ct->flags & JIM_MODFLAG_HIDDEN)) {
add_cmd_usage(interp, ct, argv[0]);
if (ct->description) {
Jim_AppendStrings(interp, Jim_GetResult(interp), "\n\n ", ct->description, NULL);
}
Jim_AppendStrings(interp, Jim_GetResult(interp), "\n\n", NULL);
}
}
}
static void set_wrong_args(Jim_Interp *interp, const jim_subcmd_type * command_table, Jim_Obj *subcmd)
{
Jim_SetResultString(interp, "wrong # args: must be \"", -1);
add_cmd_usage(interp, command_table, subcmd);
Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
}
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
|
}
Jim_AppendStrings(interp, Jim_GetResult(interp), ct->cmd, NULL);
if (ct->args && *ct->args) {
Jim_AppendStrings(interp, Jim_GetResult(interp), " ", ct->args, NULL);
}
}
static void set_wrong_args(Jim_Interp *interp, const jim_subcmd_type * command_table, Jim_Obj *subcmd)
{
Jim_SetResultString(interp, "wrong # args: must be \"", -1);
add_cmd_usage(interp, command_table, subcmd);
Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
}
|
| ︙ | | | ︙ | |
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
|
cmdname = Jim_String(argv[0]);
if (argc < 2) {
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_AppendStrings(interp, Jim_GetResult(interp), "wrong # args: should be \"", cmdname,
" command ...\"\n", NULL);
Jim_AppendStrings(interp, Jim_GetResult(interp), "Use \"", cmdname, " -help\" or \"",
cmdname, " -help command\" for help", NULL);
return 0;
}
cmd = argv[1];
if (argc == 2 && Jim_CompareStringImmediate(interp, cmd, "-usage")) {
show_full_usage(interp, command_table, argc, argv);
return &dummy_subcmd;
}
if (Jim_CompareStringImmediate(interp, cmd, "-help")) {
if (argc == 2) {
show_cmd_usage(interp, command_table, argc, argv);
return &dummy_subcmd;
}
|
|
<
<
<
<
<
<
<
|
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
|
cmdname = Jim_String(argv[0]);
if (argc < 2) {
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_AppendStrings(interp, Jim_GetResult(interp), "wrong # args: should be \"", cmdname,
" command ...\"\n", NULL);
Jim_AppendStrings(interp, Jim_GetResult(interp), "Use \"", cmdname, " -help ?command?\" for help", NULL);
return 0;
}
cmd = argv[1];
if (Jim_CompareStringImmediate(interp, cmd, "-help")) {
if (argc == 2) {
show_cmd_usage(interp, command_table, argc, argv);
return &dummy_subcmd;
}
|
| ︙ | | | ︙ | |
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
|
return 0;
}
if (help) {
Jim_SetResultString(interp, "Usage: ", -1);
add_cmd_usage(interp, ct, argv[0]);
if (ct->description) {
Jim_AppendStrings(interp, Jim_GetResult(interp), "\n\n", ct->description, NULL);
}
return &dummy_subcmd;
}
if (argc - 2 < ct->minargs || (ct->maxargs >= 0 && argc - 2 > ct->maxargs)) {
Jim_SetResultString(interp, "wrong # args: must be \"", -1);
|
<
<
<
|
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
|
return 0;
}
if (help) {
Jim_SetResultString(interp, "Usage: ", -1);
add_cmd_usage(interp, ct, argv[0]);
return &dummy_subcmd;
}
if (argc - 2 < ct->minargs || (ct->maxargs >= 0 && argc - 2 > ct->maxargs)) {
Jim_SetResultString(interp, "wrong # args: must be \"", -1);
|
| ︙ | | | ︙ | |
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
|
{
const jim_subcmd_type *ct =
Jim_ParseSubCmd(interp, (const jim_subcmd_type *)Jim_CmdPrivData(interp), argc, argv);
return Jim_CallSubCmd(interp, ct, argc, argv);
}
int
Jim_CheckCmdUsage(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc,
Jim_Obj *const *argv)
{
if (argc == 2) {
if (Jim_CompareStringImmediate(interp, argv[1], "-usage")
|| Jim_CompareStringImmediate(interp, argv[1], "-help")) {
Jim_SetResultString(interp, "Usage: ", -1);
add_cmd_usage(interp, command_table, NULL);
if (command_table->description) {
Jim_AppendStrings(interp, Jim_GetResult(interp), "\n\n", command_table->description,
NULL);
}
return JIM_OK;
}
}
if (argc >= 2 && command_table->function) {
Jim_Obj *nargv[4];
int nargc = 0;
const char *subcmd = NULL;
if (Jim_CompareStringImmediate(interp, argv[1], "-subcommands")) {
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
add_commands(interp, (jim_subcmd_type *) command_table->function, " ");
return JIM_OK;
}
if (Jim_CompareStringImmediate(interp, argv[1], "-subhelp")
|| Jim_CompareStringImmediate(interp, argv[1], "-help")) {
subcmd = "-help";
}
else if (Jim_CompareStringImmediate(interp, argv[1], "-subusage")) {
subcmd = "-usage";
}
if (subcmd) {
nargv[nargc++] = Jim_NewStringObj(interp, "$handle", -1);
nargv[nargc++] = Jim_NewStringObj(interp, subcmd, -1);
if (argc >= 3) {
nargv[nargc++] = argv[2];
}
Jim_ParseSubCmd(interp, (jim_subcmd_type *) command_table->function, nargc, nargv);
Jim_FreeNewObj(interp, nargv[0]);
Jim_FreeNewObj(interp, nargv[1]);
return 0;
}
}
if (argc - 1 < command_table->minargs || (command_table->maxargs >= 0
&& argc - 1 > command_table->maxargs)) {
set_wrong_args(interp, command_table, NULL);
Jim_AppendStrings(interp, Jim_GetResult(interp), "\nUse \"", Jim_String(argv[0]),
" -help\" for help", NULL);
return JIM_ERR;
}
return -1;
}
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
|
{
const jim_subcmd_type *ct =
Jim_ParseSubCmd(interp, (const jim_subcmd_type *)Jim_CmdPrivData(interp), argc, argv);
return Jim_CallSubCmd(interp, ct, argc, argv);
}
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
|
| ︙ | | | ︙ | |
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
|
void regfree(regex_t *preg)
{
free(preg->program);
}
#endif
#ifndef JIM_BOOTSTRAP_LIB_ONLY
#include <errno.h>
#include <string.h>
#ifdef USE_LINENOISE
#include <unistd.h>
#include "linenoise.h"
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
|
void regfree(regex_t *preg)
{
free(preg->program);
}
#endif
#if defined(_WIN32) || defined(WIN32)
#ifndef STRICT
#define STRICT
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#if defined(HAVE_DLOPEN_COMPAT)
void *dlopen(const char *path, int mode)
{
JIM_NOTUSED(mode);
return (void *)LoadLibraryA(path);
}
int dlclose(void *handle)
{
FreeLibrary((HANDLE)handle);
return 0;
}
void *dlsym(void *handle, const char *symbol)
{
return GetProcAddress((HMODULE)handle, symbol);
}
char *dlerror(void)
{
static char msg[121];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
LANG_NEUTRAL, msg, sizeof(msg) - 1, NULL);
return msg;
}
#endif
#ifdef _MSC_VER
#include <sys/timeb.h>
int gettimeofday(struct timeval *tv, void *unused)
{
struct _timeb tb;
_ftime(&tb);
tv->tv_sec = tb.time;
tv->tv_usec = tb.millitm * 1000;
return 0;
}
DIR *opendir(const char *name)
{
DIR *dir = 0;
if (name && name[0]) {
size_t base_length = strlen(name);
const char *all =
strchr("/\\", name[base_length - 1]) ? "*" : "/*";
if ((dir = (DIR *) Jim_Alloc(sizeof *dir)) != 0 &&
(dir->name = (char *)Jim_Alloc(base_length + strlen(all) + 1)) != 0) {
strcat(strcpy(dir->name, name), all);
if ((dir->handle = (long)_findfirst(dir->name, &dir->info)) != -1)
dir->result.d_name = 0;
else {
Jim_Free(dir->name);
Jim_Free(dir);
dir = 0;
}
}
else {
Jim_Free(dir);
dir = 0;
errno = ENOMEM;
}
}
else {
errno = EINVAL;
}
return dir;
}
int closedir(DIR * dir)
{
int result = -1;
if (dir) {
if (dir->handle != -1)
result = _findclose(dir->handle);
Jim_Free(dir->name);
Jim_Free(dir);
}
if (result == -1)
errno = EBADF;
return result;
}
struct dirent *readdir(DIR * dir)
{
struct dirent *result = 0;
if (dir && dir->handle != -1) {
if (!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) {
result = &dir->result;
result->d_name = dir->info.name;
}
}
else {
errno = EBADF;
}
return result;
}
#endif
#endif
#ifndef JIM_BOOTSTRAP_LIB_ONLY
#include <errno.h>
#include <string.h>
#ifdef USE_LINENOISE
#include <unistd.h>
#include "linenoise.h"
|
| ︙ | | | ︙ | |