Permalink
Browse files

Intrinsic variable getter egtm:iget introduced;

  • Loading branch information...
1 parent d3fbf72 commit b911885cf0fad600b04be9423b816e217fade020 Tomas Morstein committed Aug 10, 2012
Showing with 43 additions and 2 deletions.
  1. +23 −1 c_src/egtm_worker.c
  2. +1 −0 priv/calltab.ci
  3. +1 −0 priv/rtns/_egtmapi.m
  4. +17 −1 src/egtm.erl
  5. +1 −0 src/egtm_worker.erl
View
@@ -555,6 +555,27 @@ NIF (m_data) {
enif_make_string (env, emsg, ERL_NIF_LATIN1));
}
+NIF (m_iget) {
+
+ if (argc != 1) return enif_make_badarg (env);
+
+ char varnam [EGTM$BUFLEN];
+ if (enif_get_string (env, argv [0], varnam, EGTM$BUFLEN, ERL_NIF_LATIN1) < 0)
+ return enif_make_badarg (env);
+
+ char res [EGTM$BUFLENBIG]; res[0]='\0';
+ gtm_status_t status;
+ LOCK(status = gtm_ci ("m_iget", res, varnam);)
+
+ char emsg [EGTM$BUFLEN];
+ if (check_status (status, emsg) == 0)
+ return enif_make_tuple2 (env, c_AtomOK,
+ enif_make_string (env, res, ERL_NIF_LATIN1));
+ else
+ return enif_make_tuple2 (env, c_AtomError,
+ enif_make_string (env, emsg, ERL_NIF_LATIN1));
+}
+
static ErlNifFunc nif_funcs [] = {
{"m_set", 2, m_set},
{"m_setp", 4, m_setp},
@@ -576,7 +597,8 @@ static ErlNifFunc nif_funcs [] = {
{"m_data", 1, m_data},
{"m_horo", 0, m_horo},
{"m_zver", 0, m_zver},
- {"m_job", 0, m_job}
+ {"m_job", 0, m_job},
+ {"m_iget", 1, m_iget}
};
//ERL_NIF_INIT (egtm_worker, nif_funcs, &load, &reload, &upgrade, &unload);
View
@@ -20,3 +20,4 @@ m_xecute :void xecute^%egtmapi(I:gtm_char_t*)
m_horo :gtm_char_t* horo^%egtmapi()
m_zver :gtm_char_t* zver^%egtmapi()
m_job :gtm_char_t* job^%egtmapi()
+m_iget :gtm_char_t* iget^%egtmapi(I:gtm_char_t*)
View
@@ -27,6 +27,7 @@ trollback d txrollback() q
horo() q $h
zver() q $zver
job() q $j
+iget(v) q @("$"_v)
; TP emulation internals
txtest(k,d,p,w) d txsubmitcmd("w k,d,p,w,!") q
View
@@ -86,7 +86,7 @@
tstart/0, tstart/1, tcommit/0, trollback/0,
lock/1, lock/2, unlock/1, unlock/2,
data/1, data/2, xecute/1,
- zversion/0, horolog/0, job/0]).
+ zversion/0, horolog/0, job/0, iget/1, iget/2]).
-export ([fast_order/2, call_fast_order/2, xecute_fast_order/2]).
%-compile (export_all).
@@ -383,6 +383,19 @@ job () ->
?trace ("job"),
perform (job, []).
+%% @equiv iget (VarName)
+-spec iget (VarName::string (), Subs::subscripts ()) -> string ().
+iget (VarName, Subs) -> iget (format_gvn (VarName, Subs)).
+
+%% @doc Return a value of intrinsic (system) variable.
+%% Example: to get `$ZRO[utines]', just `egtm:iget ("ZRO")'.
+%% Note: to set an intrinsic variable, there's no `iset'
+%% supported, so feel free to use `xecute'.
+-spec iget (VarName::string ()) -> string ().
+iget (VarName) ->
+ ?trace ("iget"),
+ perform (iget, [VarName]).
+
%% @doc XXX: Alternative `egtm:order ()' experiment.
fast_order (Gvn, Subs) ->
Fmt = format_gvn (Gvn, Subs, true),
@@ -530,6 +543,9 @@ basic_test () ->
?assertEqual (ok, ?MODULE:zkill (Gvn, Subs)),
?assertEqual ("", ?MODULE:get (Gvn, Subs)),
+ ?assertEqual (?MODULE:zversion (), ?MODULE:iget ("zver")),
+ ?assertEqual (?MODULE:zversion (), ?MODULE:iget ("zversion")),
+
?MODULE:stop (),
ok.
View
@@ -96,6 +96,7 @@ m_xecute (_) -> not_loaded (?LINE).
m_horo () -> not_loaded (?LINE).
m_zver () -> not_loaded (?LINE).
m_job () -> not_loaded (?LINE).
+m_iget (_) -> not_loaded (?LINE).
%% --- NIF initialization ---------

0 comments on commit b911885

Please sign in to comment.