Skip to content

Commit 09417a2

Browse files
committed
stdlib system
1 parent 4e24f08 commit 09417a2

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/lib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ libFunction_t ric_library[] = {
4141
DECLARE_LIB_FUNCTION("sort", 1, ric_sort),
4242
DECLARE_LIB_FUNCTION("join", 2, ric_join),
4343
DECLARE_LIB_FUNCTION("cachepot", 0, ric_cachepot),
44+
DECLARE_LIB_FUNCTION("system", 1, ric_system),
4445
// libjson
4546
DECLARE_LIB_FUNCTION("jsonLoad", 1, ric_json_load),
4647
DECLARE_LIB_FUNCTION("jsonConvert", 1, ric_json_convert),

src/library/libstd.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,3 +1713,32 @@ int ric_get_env(LIBRARY_PARAMS()) {
17131713

17141714
return 0;
17151715
}
1716+
1717+
int ric_system(LIBRARY_PARAMS()) {
1718+
stackval_t stv;
1719+
char *argText;
1720+
int result = 0;
1721+
void *sp = PROVIDE_CONTEXT()->sp;
1722+
size_t *sc = PROVIDE_CONTEXT()->sc;
1723+
1724+
// pop arg 1 - directory to search in
1725+
POP_VAL(&stv, sp, sc);
1726+
1727+
switch (stv.type) {
1728+
case TEXT:
1729+
argText = stv.t;
1730+
break;
1731+
default: {
1732+
fprintf(stderr,
1733+
"error: function call '%s' got unexpected data type as argument, string expected.\n",
1734+
LIBRARY_FUNC_NAME());
1735+
exit(1);
1736+
} break;
1737+
}
1738+
1739+
result = system(argText);
1740+
1741+
/* Pushing the result */
1742+
PUSH_INT(result, sp, sc);
1743+
return 0;
1744+
}

src/library/libstd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ int ric_sort(LIBRARY_PARAMS());
4141
int ric_join(LIBRARY_PARAMS());
4242
int ric_cachepot(LIBRARY_PARAMS());
4343
int ric_get_env(LIBRARY_PARAMS());
44+
int ric_system(LIBRARY_PARAMS());
4445

4546
#endif

0 commit comments

Comments
 (0)