Created
August 16, 2016 01:38
-
-
Save PsichiX/fc456c8a0244ea4f77af3148fec3142f to your computer and use it in GitHub Desktop.
Intuicio4 Protocols Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env i4s | |
#intuicio 4.0; | |
#stack 8k; | |
#memory 16k; | |
#entry @Main; | |
#pointersize 32; | |
#import from [IO:print] routine print(format:*i8, ...):; | |
#import from [IO:get_line_new] routine get_line_new():*i8; | |
#import from [IO:scan_i8_bool] routine scan_i8_bool():i8; | |
#import from [String:string_format_new] routine string_firmat_new(format:*i8, ...):*i8; | |
#import from [ResourcesManager:initialize] routine ResourcesManager_initialize():; | |
#import from [ResourcesManager:cleanup] routine ResourcesManager_cleanup():; | |
#import from [ResourcesManager:loadProtocol] routine ResourcesManager_loadProtocol(id:*i8, path:*i8):i8; | |
#import from "protocols/file.i4s" routine file_exists(path:*i8, space:*i8):i8; | |
#import from "protocols/file.i4s" routine file_write_contents(path:*i8, space:*i8, contents:*i8):i8; | |
#import from "protocols/http.i4s" routine http_get_contents_new(url:*i8):*i8; | |
routine Main():i32 | |
<status:i8, user:*i8, params:*i8, hello:*i8> | |
{ | |
call @ResourcesManager_initialize(); | |
// ensure that protocols will be loaded if script is running not through IPM. | |
call @ResourcesManager_loadProtocol("file":*i8, "I4Protocol_file":*i8) => $status; | |
call @ResourcesManager_loadProtocol("http":*i8, "I4Protocol_http":*i8) => $status; | |
call @print("Write IPM user info into file? (no) [yes/no] ":*i8); | |
call @scan_i8_bool() => $status; | |
jif $status %write %exists; | |
write: | |
call @print("IPM user name: ":*i8); | |
call @get_line_new() => $user; | |
call @string_format_new("action=info_user&user=${*}":*i8, $user) => $params; | |
del $user; | |
call @http_post_contents_new("ipm.psichix.hekko24.pl":*i8, $params) => $hello; | |
del $params; | |
nil $hello => $status; | |
jif $status %exists %continue; | |
continue: | |
call @print("Write to file: ${*}\n":*i8, $hello); | |
call @file_write_contents("hello.txt":*i8, "localuser":*i8, $hello) => $status; | |
del $hello; | |
exists: | |
call @file_exists("hello.txt":*i8, "localuser":*i8) => $status; | |
call @print("Does file exists: ${i8}\n":*i8, $status); | |
ret 0:i32; | |
}[{ | |
call @ResourcesManager_cleanup(); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment