mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-25 12:42:02 +03:00
commit
f04af3dd56
@ -36,9 +36,9 @@ getArgs = primIO prim__getArgs
|
||||
prim_getEnv : String -> PrimIO (Ptr String)
|
||||
%foreign support "idris2_getEnvPair"
|
||||
prim_getEnvPair : Int -> PrimIO (Ptr String)
|
||||
%foreign libc "setenv"
|
||||
%foreign support "idris2_setenv"
|
||||
prim_setEnv : String -> String -> Int -> PrimIO Int
|
||||
%foreign libc "setenv"
|
||||
%foreign support "idris2_unsetenv"
|
||||
prim_unsetEnv : String -> PrimIO Int
|
||||
|
||||
export
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
extern char **_environ;
|
||||
@ -73,3 +74,19 @@ int idris2_time() {
|
||||
char* idris2_getEnvPair(int i) {
|
||||
return *(environ + i);
|
||||
}
|
||||
|
||||
int idris2_setenv(const char *name, const char *value, int overwrite) {
|
||||
#ifdef _WIN32
|
||||
return win32_modenv(name, value, overwrite);
|
||||
#else
|
||||
return setenv(name, value, overwrite);
|
||||
#endif
|
||||
}
|
||||
|
||||
int idris2_unsetenv(const char *name) {
|
||||
#ifdef _WIN32
|
||||
return win32_modenv(name, "", 1);
|
||||
#else
|
||||
return unsetenv(name);
|
||||
#endif
|
||||
}
|
@ -67,9 +67,14 @@ void win32_gettime(int64_t* sec, int64_t* nsec)
|
||||
|
||||
*nsec = (t.QuadPart % 10000000)*100;
|
||||
*sec = t.QuadPart / 10000000;
|
||||
*sec -= 11644473600; // LDAP epoch to Unix epoch
|
||||
*sec -= 11644473600; // LDAP epoch to Unix epoch
|
||||
}
|
||||
|
||||
void win32_sleep(int ms) {
|
||||
Sleep(ms);
|
||||
}
|
||||
|
||||
int win32_modenv(const char* name, const char* value, int overwrite) {
|
||||
if (!overwrite && getenv(name)) return 0;
|
||||
return _putenv_s(name, value);
|
||||
}
|
@ -8,3 +8,4 @@ FILE *win32_u8fopen(const char *path, const char *mode);
|
||||
FILE *win32_u8popen(const char *path, const char *mode);
|
||||
void win32_gettime(int64_t* sec, int64_t* nsec);
|
||||
void win32_sleep(int ms);
|
||||
int win32_modenv(const char* name, const char* value, int overwrite);
|
||||
|
@ -113,7 +113,7 @@ chezTests
|
||||
= ["chez001", "chez002", "chez003", "chez004", "chez005", "chez006",
|
||||
"chez007", "chez008", "chez009", "chez010", "chez011", "chez012",
|
||||
"chez013", "chez014", "chez015", "chez016", "chez017", "chez018",
|
||||
"chez019", "chez020", "chez021", "chez022", "chez023",
|
||||
"chez019", "chez020", "chez021", "chez022", "chez023", "chez024",
|
||||
"reg001"]
|
||||
|
||||
ideModeTests : List String
|
||||
|
26
tests/chez/chez024/Envy.idr
Normal file
26
tests/chez/chez024/Envy.idr
Normal file
@ -0,0 +1,26 @@
|
||||
module Main
|
||||
|
||||
import System
|
||||
|
||||
main : IO ()
|
||||
main = do
|
||||
ok <- setEnv "HELLO" "HI" True
|
||||
printLn ok
|
||||
Just str <- getEnv "HELLO"
|
||||
| Nothing => pure ()
|
||||
putStrLn str
|
||||
ok <- setEnv "HELLO" "HO" False
|
||||
printLn ok
|
||||
Just str <- getEnv "HELLO"
|
||||
| Nothing => pure ()
|
||||
putStrLn str
|
||||
ok <- setEnv "HELLO" "EH" True
|
||||
printLn ok
|
||||
Just str <- getEnv "HELLO"
|
||||
| Nothing => pure ()
|
||||
putStrLn str
|
||||
ok <- unsetEnv "HELLO"
|
||||
printLn ok
|
||||
Just str <- getEnv "HELLO"
|
||||
| Nothing => putStrLn "Nothing there"
|
||||
pure ()
|
10
tests/chez/chez024/expected
Normal file
10
tests/chez/chez024/expected
Normal file
@ -0,0 +1,10 @@
|
||||
True
|
||||
HI
|
||||
True
|
||||
HI
|
||||
True
|
||||
EH
|
||||
True
|
||||
Nothing there
|
||||
1/1: Building Envy (Envy.idr)
|
||||
Main> Main> Bye for now!
|
2
tests/chez/chez024/input
Normal file
2
tests/chez/chez024/input
Normal file
@ -0,0 +1,2 @@
|
||||
:exec main
|
||||
:q
|
3
tests/chez/chez024/run
Normal file
3
tests/chez/chez024/run
Normal file
@ -0,0 +1,3 @@
|
||||
$1 --no-banner Envy.idr < input
|
||||
|
||||
rm -rf build
|
Loading…
Reference in New Issue
Block a user