any way to call programs as subroutines?

56 views
Skip to first unread message

Leon Kupski

unread,
May 23, 2015, 12:51:05 PM5/23/15
to ticalcorg...@googlegroups.com
Hello

I have Ti89Titanium and am looking for way to execute a program from another program. Isn't there really a way? I saw in TIGCC help an example of such a thing in section "How can I create a program that is bigger than 24K and works on AMS 2.xx?", but I don't understand it at all. I want to get numeric values from the other program. I tried both push_parse_text and manually pushing tags, with kernel or without. Nothing worked. Either "illegal instruction" or "address error".


#define MIN_AMS 300
#define RETURN_VALUE wynib
//#define USE_KERNEL         
#define ENABLE_ERROR_RETURN
#include <tigcclib.h>
#define fatal(s) ({ST_showHelp (s); return;})


void _main (void)
{
     push_END_TAG();
     push_shortint(n);
     push_expression(arg);
   push_ANSI_string("fa");   
     delete_between(top_estack-1,top_estack);//remove str_tag
     push_quantum(USERFUNC_TAG);
     HANDLE handle=HS_popEStack();
   
     NG_execute(handle,0);
     return top_estack;
    }


Thanks in advance!
Leon

Lionel Debroux

unread,
May 23, 2015, 4:31:43 PM5/23/15
to ticalcorg...@googlegroups.com
Hello,

> I have Ti89Titanium and am looking for way to execute a program from
> another program. Isn't there really a way?
TI intentionally made executing ASM programs from other ASM programs one
of the hardest things on the TI-68k/AMS platform.
Executing BASIC programs from ASM programs is worse. TICT-Explorer
sidesteps the issue by pasting the relevant text onto the Home Screen
Line, and bailing out.

> I saw in TIGCC help an example of such a thing in section "How can I
> create a program that is bigger than 24K and works on AMS 2.xx?", but
> I don't understand it at all.
That particular example doesn't work at all on a 89T anyway, not even
after installing HW3Patch. It uses an area of the address space which
simply isn't mapped any longer on the 89T.
The proper way to do it without depending on HW2/3Patch is far more
complicated:
https://github.com/debrouxl/gcc4ti/blob/next/trunk/tigcc/starters/pstarter.s
HW2/3Patch makes launchers' lives slightly easier.

> I want to get numeric values from the other program. I tried both
> push_parse_text and manually pushing tags, with kernel or without.
> Nothing worked. Either "illegal instruction" or "address error".
> [snip program]
Could you tell me a bit more about what you want to do ? :)

How are your programs organized ?
Could you use a single front-end program (ala FLib) to implement
multiple functions ? I doubt you want to do that, but that's one of the
possible workarounds.
Or you could make a FlashApp exporting multiple TI-Basic functions,
that's the topic of my ongoing discussion with Ralph Schenn. I still do
usually not recommend the approach, for a variety of reasons mentioned
in the other discussion.


Bye,
Lionel.

Leon Kupski

unread,
May 25, 2015, 6:48:16 AM5/25/15
to ticalcorg...@googlegroups.com


W dniu sobota, 23 maja 2015 22:31:43 UTC+2 użytkownik Lionel Debroux napisał:
Hello,

Thank you for your answer

1. Doesn't printing on Home screen take some additional time? If it would be long list of floating point numbers? Or maybe should I print less decimal digits? I will also have a few other questions about efficiency.
2. Doesn't Your TIOS patch change this calling behaviour? On Titanium or different platforms? How about this program size limitation and ghost space thing?
3. Doesn't runprog by Kevin Koffler work on Titanium? I couldn't make it work but as for now there's a lot things I can't. How about other calculators?
4. I wanted to have a group of programs. For example one building some stochastic trajectory or performing Monte Carlo integration and calling another for a list of random numbers. Wouldn't it be possible to store commands for this rng in some other variable, run "runprog("rng")" and then look into some lists where this rng puts result. Clearly, I'm not capable of this now. For the time being I will use amazing mathtools for some of the things I wanted to do (while others will have to wait).
5. Questions about efficiency:  What are the costs of:
calling TI-Basic function
calling TI-Basic  program
storing things in variable
reading a variable
calling asm program (with runprog or whatever)
performing some math calculations on lists using map_tail and  vs doing the very same calculations in pure C? I mean having some functions predefined inside C file, not parsing like rng(1000, "x^2*sin(beta(x))") but for example rng(1000,"pois(4)")?
6. By FLib kind of program you mean one program for all and something like FLib("do this, and then this and finally do that")? But on Titanium I can't break program size limitation or can I with Your patch?
 

Ralph Schenn

unread,
May 25, 2015, 8:25:13 AM5/25/15
to ticalcorg...@googlegroups.com
Hi Leon,

im still unsure what architecture will be best for your application...

You could develop ASM programs using TIGCC. Than you could write programs or fuctions in Basic to make use of your ASM programs. I think these ASM programs will be non-interactive accepting parameters and returning some result to the stack (behaving like functions). Returning results works when you use HW3 patch and Kerno for example. TIGCC doc has a chapter about returning values.

In fact fiddling around with TIGCC or Flash Studio is worth the time spent only when you can expect the performance will be much better than in Basic. Coding in C you also get programs that are bigger than Basic usually.

As long as you are dealing with numeric lists or matrices (real or complex numbers as elements) it may really be possible to get much better performance in C. When storing the data in arrays you get random access to the cells with simple address arithmetic because all cells have the same length. If you would store the same data on the EStack you have the freedom that not all cells have to be of the same type (and can also be symbolic expressions) - but you get this at the expense of more overhead to access your data randomly.

I have never tried to call ASM programs from ASM programs directly from C code. But it should be possible to concatenate the calls in Basic: PROG2(PROG1(ARG1))... You can also use vars fot intermediate results. This may involve conversion from array to estack and vice versa which is much more overhead than calling a function in C and passing pointer to array and dimensions of array.

I have switched to Flash Studio because i expexted that it will become easier to share code between functions (for example i need function to get list from stack in moving average and convolution functions) and TIGCC does not support shared libs very well (you can load only one simultnously and that single lib would become to big and give unacceptable performance because of size). The size of ASM programs really matters with respect to performance - especially when you call them many times in a Basic loop. Flash Apps are executed in place, so size does not impact performance so much.

Regards
Ralph
--
You received this message because you are subscribed to the Google Groups "ticalc.org-advanced" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ticalcorg-advan...@googlegroups.com.
To post to this group, send email to ticalcorg...@googlegroups.com.
Visit this group at http://groups.google.com/group/ticalcorg-advanced.

Lionel Debroux

unread,
May 25, 2015, 2:27:10 PM5/25/15
to ticalcorg...@googlegroups.com
Hello,

> Thank you for your answer
You're welcome.

> 1. Doesn't printing on Home screen take some additional time? If it
> would be long list of floating point numbers? Or maybe should I print
> less decimal digits? I will also have a few other questions about
> efficiency.
The time spent by the user launching the program in a manual way will
dwarf the small amount of time taken by generating the contents of the
Home Screen Line.

> 2. Doesn't Your TIOS patch change this calling behaviour?
> On Titanium or different platforms? How about this program size
> limitation and ghost space thing?
Do you mean tiosmod+amspatch ? While that one is a strict superset of
HW2/3Patch, IPR (killing the stupid restriction calling ASM programs
returning a value from TI-Basic programs) and others, it does not make
it easier (or harder) to call TI-Basic programs from ASM programs.

> 3. Doesn't runprog by Kevin Koffler work on Titanium?
> I couldn't make it work but as for now there's a lot things I can't.
> How about other calculators?
The archive on ticalc.org predates the advent of the 89T.
runprog can be made to work on the 89T, but it won't help with your
initial stated goal of launching ASM or TI-Basic programs from ASM
programs, AFAICT.

> 4. I wanted to have a group of programs. For example one building
> some stochastic trajectory or performing Monte Carlo integration and
> calling another for a list of random numbers. Wouldn't it be possible
> to store commands for this rng in some other variable, run
> "runprog("rng")" and then look into some lists where this rng puts
> result. Clearly, I'm not capable of this now. For the time being I
> will use amazing mathtools for some of the things I wanted to do
> (while others will have to wait).
A group of programs which call into each other is no problem: MathTools
is one of the largest such groups.
Having TI-Basic programs call ASM programs is no problem (once one lifts
the silly "Invalid Program Reference").
Having TI-Basic programs call into FlashApp BASIC extensions is no problem.
Having ASM programs call other ASM programs is a headache.
Having ASM programs call back into the BASIC interpreter is worse.
I don't know about having FlashApp BASIC extensions call back into the
TI-Basic interpreter.

On the TI-68k/AMS platform, ASM programs are the best, and by far the
most popular way to achieve most native programming purposes, thanks to
the superior toolchain and tools. However, heavy mathematical
computations, as Ralph Schenn is doing, and you may be doing (we need
more information about that), are an area where ASM programs are not
always the best choice.

> 5. Questions about efficiency: What are the costs of:
This benchmarking question is very generic...
> calling TI-Basic function
> calling TI-Basic program
> storing things in variable
> reading a variable
Storing things to / reading from variables is usually faster than
calling a TI-Basic function / program or an ASM program.
> calling asm program (with runprog or whatever)
No, not with runprog. Either directly from TI-Basic, or through the
generic program launchers: ttstart or SuperStart.
> performing some math calculations on lists using map_tail and vs
> doing the very same calculations in pure C? I mean having some
> functions predefined inside C file, not parsing like
> rng(1000, "x^2*sin(beta(x))") but for example rng(1000,"pois(4)")?
EStack processing obviously brings some overhead. Depending on what kind
of computations you're making, it makes sense to convert the data on the
EStack to C structures, as Ralph Schenn did.

> 6. By FLib kind of program you mean one program for all and something
> like FLib("do this, and then this and finally do that")?
Yes.
> But on Titanium I can't break program size limitation or can I with
> Your patch?
There is effectively no program size limitation on the 89T. That is, the
size check still wastes several dozen bytes inside the OS, but the
boundary is set of 65536 bytes, whereas no valid variable and RAM-borne
block of memory can exceed 65518 / 65520 bytes (depending on how you count).


Bye,
Lionel.

Lionel Debroux

unread,
May 25, 2015, 2:27:45 PM5/25/15
to ticalcorg...@googlegroups.com
Hi,

> im still unsure what architecture will be best for your
> application...
As much as I usually don't like suggesting FlashApps, because TIFS and
the Sierra C toolchain are inferior to, and less portable than, GCC4TI /
TIEmu, I think that the best course of action for achieving what he
seems to want to achieve could be the same as it is for you...

> You could develop ASM programs using TIGCC.
GCC4TI, rather - newer, more functions, fewer bugs ;)

> Than you could write programs or fuctions in Basic to make use of
> your ASM programs. I think these ASM programs will be non-interactive
> accepting parameters and returning some result to the stack (behaving
> like functions).
Correct.

> Returning results works when you use HW3 patch and Kerno for example.
HW2/3Patch has no impact on lifting the Invalid Program Reference
limitation. That's the duty of IPR, KerNO, PreOS or tiosmod+amspatch :)

> TIGCC doc has a chapter about returning values. In fact fiddling
> around with TIGCC or Flash Studio is worth the time spent only when
> you can expect the performance will be much better than in Basic.
Exactly. If the performance of the TI-Basic program is good, and can't
be made much better (lower algorithmic complexity) by using lower-level
functions, don't bother making a native code program.

> Coding in C you also get programs that are bigger than Basic
> usually.
Usually, yes. Tokenized languages and all kinds of bytecode are very small.
My C implementation of the Aitken delta^2 algorithm isn't much larger
than the TI-Basic version.

> As long as you are dealing with numeric lists or matrices (real or
> complex numbers as elements) it may really be possible to get much
> better performance in C. When storing the data in arrays you get
> random access to the cells with simple address arithmetic because all
> cells have the same length. If you would store the same data on the
> EStack you have the freedom that not all cells have to be of the same
> type (and can also be symbolic expressions) - but you get this at the
> expense of more overhead to access your data randomly.
init_list_indices(), only documented and properly available in GCC4TI,
helps accessing data randomly.

> I have never tried to call ASM programs from ASM programs directly
> from C code. But it should be possible to concatenate the calls in
> Basic: PROG2(PROG1(ARG1))... You can also use vars fot intermediate
> results. This may involve conversion from array to estack and vice
> versa which is much more overhead than calling a function in C and
> passing pointer to array and dimensions of array.
Yup.

> I have switched to Flash Studio because i expexted that it will
> become easier to share code between functions (for example i need
> function to get list from stack in moving average and convolution
> functions) and TIGCC does not support shared libs very well (you can
> load only one simultanously and that single lib would become to big
> and give unacceptable performance because of size).
TIGCC/GCC4TI does have support for "kernel"-based libraries, which
aren't subject to the single library at a time limitation of the
TIGCC/GCC4TI fake shared library support. And if one can rely on
HW2/3Patch, loading multiple libraries is relatively easy:
http://tict.ticalc.org/downloads/launchmultiple.tar.bz2 .
However, the fact that the ASM program + libraries need to be loaded and
unloaded remain, though. What's more, when using "kernel"-based
libraries, the user has to install PreOS.

> The size of ASM programs really matters with respect to performance -
> especially when you call them many times in a Basic loop. Flash Apps
> are executed in place, so size does not impact performance so much.
It's a fact.


To sum up, Leon: _if_ your computations would really benefit from being
written in C/ASM to take advantage of higher performance through the
lower-level API, then you should set to make a FlashApp exposing
TI-Basic extensions, instead of separate ASM programs.
Even if making FlashApps implies withstanding an inferior programming
environment, see the other recent thread.


Bye,
Lionel.

Calvin Henderson

unread,
May 25, 2015, 6:52:19 PM5/25/15
to ticalcorg...@googlegroups.com
Hey guys, I've been quite inactive for the past couple months, but I've finally had more time to program.
Is there a way to include basic programs in axe programs, or vise versa?

Calvin Henderson

Ralph Schenn

unread,
May 26, 2015, 11:45:44 AM5/26/15
to ticalcorg...@googlegroups.com
Hi Calvin,

have a look at the TIGCC doc. I think you mean calling, not including.
At least one direction (ASM->Basic) you asked for is explained there.

"Q: Is there any way to execute a file (i.e. another ASM or TI-Basic
program) from a C program?
A: There are a lot of methods for doing this. The most obvious method to
do this is usage of a function like this one:
void progrun(const char *name)
{
char fname[25];
HANDLE h;
strcpy (fname, name);
strcat (fname, "()");
push_parse_text (fname);
h = HS_popEStack ();
TRY
NG_execute (h, FALSE);
FINALLY
HeapFree (h);
ENDFINAL
}

The usage of it is straightforward, for example:
progrun ("testprog");

Note that the program you call may throw errors. If you understand this
function, you can easily expand it to accept arguments, etc.
Principally, using NG_execute you can execute any particular sequence of
TI-Basic statements. "

Calling ASM programs or Basic Extensions provided by Flash Apps from
Basic is much easier. Depending on AMS version returning results from
ASM programs may not work. But there are workarounds which work reliably
(see "How to make a program return a value" in TIGCC doc). Basic
Extensions do not require any workarounds to return results, but they
may be harder to program in other areas.

Regards
Ralph

Ralph Schenn

unread,
May 26, 2015, 12:49:23 PM5/26/15
to ticalcorg...@googlegroups.com
Hi Lionel,
Hi Leon,

the most important disadvantages of TI Flash Studio in my opinion are:

- no builtin complex datatype, operators are working only on double.
Using struct for storage and self-coded functions for +,-,*,/. Still
code is less readable with concatenated funcs instead operators. And
yes, this limits portability. It would run on complilers supporting
complex but it would not be the most obvious was to code it there and
may give somewhat poorer performance
- you must use push_internal_simplify on allmost all of your function
arguments. In TIGCC this was not necessary
- you can not call function (basic extension) automatically from the IDE
(even without passing arguments) for testing
- the debugger has some severe bugs (especially crashing sometimes when
trying to watch content of variable)
- keyboard shortcuts are ugly (at least using DE keyboard, there are
config files to change but i have not figured out until now)
- compiler errors are harder to interpret than those from TIGCC
- some ROM calls are missing in the header
- some macros/funcs of TIGCC are missing
- you have to maintain a declarative part which determines which
functions are exposed to the user
- you have to sign your app to be able to install to real hardware
- the IDE runs only up to Windows XP and requires ancient Java VM
(Sierra C runs on newer OS also - personally i was not able to get it to
run without IDE in the past). Consider it abandonware without any
support from TI. Even in the community very few people may use it - do
not expect much support there also. Look at how few Flash Apps are
offered at ticalc.org.
- i do not know any official source to download Flash Studio. I do not
even remember where i got my copy. The first version i downloded would
not run. The second try with a somewhat newer version was more successfull.

Btw. i consider performance of both compilers quite similar. But i use
many ROM calls that may limit performance so much that differences in
optimization do not show up.

When it comes to statistics at least you should be able to use my
functions for popping/pushing lists and matrices from estack while using
internal array representation (there is even support for complex
numbers). You find the code for TIGCC in CUtils and the code for Flash
Studio in Basic Extensions package on ticalc.org.

I think there is a cmd_* call for executing basic commands from C. I
think this should work in Flash App like it works in ASM progs. But i
have not tried and do not remember the exact name.

Regards
Ralph

Ralph Schenn

unread,
May 26, 2015, 1:43:42 PM5/26/15
to ticalcorg...@googlegroups.com
Hi Leon,

do you know this app and checked if it has what you want? Its quite big but i have no personal experience with it.

http://education.ti.com/en/us/software/details/en/31FC737C43CF43B0ADA1CF67420C3AA8/89statisticswithlisteditor


Regards
Ralph


On 05/25/2015 12:48 PM, Leon Kupski wrote:
--

Ralph Schenn

unread,
May 27, 2015, 12:37:19 PM5/27/15
to ticalcorg...@googlegroups.com
Hi Leon,

I meant NG_execute yesterday. See

http://tigcc.ticalc.org/doc/faq.html#50

Have not used it until now.

Regards
Ralph

Calvin Henderson

unread,
May 27, 2015, 1:12:12 PM5/27/15
to ticalcorg...@googlegroups.com
Hello, I was also wandering if there was a simple 3d graphics engine I could learn or whatever for either basic or axe. I don't program in asm, because I see it too much work with little profit, if you take my meaning. Thank you!

Calvin Henderson

Ralph Schenn

unread,
Jun 3, 2015, 3:40:02 AM6/3/15
to ticalcorg...@googlegroups.com
Hi Calvin,

personally i have no experience with 3d graphics at all. But there are enough games for TI-89 around - maybe you can ask their authors :-)

Regards
Ralph

Ralph Schenn

unread,
Jun 5, 2015, 1:07:48 PM6/5/15
to ticalcorg...@googlegroups.com
Hi Lionel,

have added init_list_indices to my personal header also :-)

Here an example is shown in which the number of elments is known in
advance (because the whole list ist hardcoded).

http://tict.ticalc.org/gcc4ti/doc/estack.html#init_list_indices

In the real world the list will be passed as arg to the function and i
do not know the length. So i must use HeapAlloc to allocate the array of
pointers to elements. I know how i could get the number of elments
before calling HeapAlloc... But im still wondering if there is a chance
to avoid iterating over the list only to get the length and to know how
much memory i must allocate?

Personally i would have preferrred a init_list_indices that handles
memory allocation itself (calling HeapRealloc for every element). But
when i really want to do that i have to write my own function - isnt it?

Thanks.

Regards
Ralph


On 05/25/2015 08:27 PM, 'Lionel Debroux' via ticalc.org-advanced wrote:

Lionel Debroux

unread,
Jun 7, 2015, 4:08:43 PM6/7/15
to ticalcorg...@googlegroups.com
Hi Ralph,

> have added init_list_indices to my personal header also :-)
> Here an example is shown in which the number of elments is known in
> advance (because the whole list is hardcoded).
>
> http://tict.ticalc.org/gcc4ti/doc/estack.html#init_list_indices
>
> In the real world the list will be passed as arg to the function and
> i do not know the length. So i must use HeapAlloc to allocate the
> array of pointers to elements. I know how i could get the number of
> elments before calling HeapAlloc... But im still wondering if there
> is a chance to avoid iterating over the list only to get the length
> and to know how much memory i must allocate?
In the general case, nope. You could use a statically-sized array, and
error out when iterating over an over-large list would end up
overflowing the array, but that's not very pretty.

> Personally i would have preferrred a init_list_indices that handles
> memory allocation itself (calling HeapRealloc for every element). But
> when i really want to do that i have to write my own function - isnt
> it?
Either write your own function, or use get_list_indices(), which uses
init_list_indices().
The correct prototype seems to be
void get_list_indices(CESI expr, uint16_t count, ESI * indices);
where expr and indices have the same meaning as for init_list_indices(),
and count is the number of elements in the indices array.
If count = 0, *indices is not set by the function.
get_list_indices allocates the indices array on the EStack; you have to
clean up afterwards.


Bye,
Lionel.

Ralph Schenn

unread,
Jun 11, 2015, 4:05:35 AM6/11/15
to ticalcorg...@googlegroups.com
Hi Lionel,

thank you for your answer.
Does it allocate the array on estack as list?

And how does the prototype for get_matrix_indices look like?

How does it behave when count >0 but < lenght of list is passed?
> get_list_indices allocates the indices array on the EStack; you have to
> clean up afterwards.
>
>
Have written my own function

/* get list of expressions
content is written to output (size of array is adjusted automatically)
returns number of elements */
unsigned short GetExpressionListArg(EStackIndex ptr,
volatile HANDLE *output) //
{
Access_AMS_Global_Variables;

// pointer to simplified list
EStackIndex topPtr;

// number of elements in list
unsigned short i = 0;

// array for elements of list
EStackIndex *array;

// expand variable name to list if necessary
push_simplify_statements (ptr);

// do not manipulate top_estack directly
topPtr = top_estack;

// wrong argument type
if (ESTACK (topPtr) != LIST_TAG) {
ER_throwVar (ER_ARGUMENT_MUST_BE_LIST);
}

// move index to first element of list
// (without decrement we start at END_TAG and are not looping)
topPtr--;

// just in case the caller has not initialized the handle
// (otherwise we will get an address error when trying to
reallocate an invalid handle)
*output = H_NULL;

// while not at end of list
while (ESTACK (topPtr) != END_TAG) {
// allocate space for additional list element
*output = HeapReallocThrow(*output, (i + 1) * sizeof
(EStackIndex));

array = HeapDeref (*output);

// store pointer to current list element in array
array[i++] = topPtr;

// so me must advance the pointer to next element explicitly
topPtr = next_expression_index (topPtr);
}

// delete simplified copy of list
delete_expression (top_estack);

// return length of list
return i;
}

Also have written function for pushing array of pointers to expression
to estack

/* push array of expressions to estack creating list */
void push_expression_list(EStackIndex input[],
short length) // ok
{
// end of list
push_quantum (END_TAG);

// loop over float array
while (--length >= 0) {
push_expression (input[length]);
}

// beginning of list
push_quantum (LIST_TAG);
}

Both seem to work.

Have tried to program some wrapper to make the interface of the
sorta/sortd commands more useable. At the moment they only accept name
of var as arg. I want them to also work when passing list as constant
(or passing func call returning list). So i tried to use VarStore to
store the constant list to variable before. That didnt work - i got the
message that VarStore is not allowed in basic extension function (it may
be allowed in basic extension program).

So i tried using code for quicksort instead of builtin sorta/sortd

static void Swap(EStackIndex v[],
int i,
int j)
{
EStackIndex temp;

temp = v[i];
v[i] = v[j];
v[j] = temp;
}

/* qsort: sort v[left]...v[right] into increasing order
Kernighan & Ritchie: The C programming language */
void QSort(EStackIndex v[],
short left,
short right)
{
short i, last;

// do nothing if array contains
if (left >= right) {
// fewer than two elements
return;
}

// move partition elem
Swap (v, left, (left + right) / 2);

// to v[0]
last = left;

// partition
for (i = left + 1; i <= right; i++) {
if (compare_expressions (v[i], v[left]) < 0) {
Swap (v, ++last, i);
}
}

// restore partition elem
Swap (v, left, last);
QSort (v, left, last - 1);
QSort (v, last + 1, right);
}

This doesnt work. When i pass {2,1} i get {2,2} as result.

Strangely it works when i force the list to be all float and use
comparison operator instead of compare_expressions.

Here is the function im using to call QSort

void zzz(void)
{
Access_AMS_Global_Variables;

volatile HANDLE hdl;
EStackIndex *ptr;
//double *ptr;
unsigned short length;

CheckNumArgs (1);

TRY
length = GetExpressionListArg (top_estack, &hdl);
//length = GetFloatListArg (top_estack, &hdl);

ptr = HeapDeref (hdl);

QSort (ptr, 0, length - 1);

push_expression_list (ptr, length);
//push_float_list (ptr, length);
FINALLY
HeapFreeIndir ((HANDLE *)&hdl);
ENDFINAL
}

Regards
Ralph


Ralph Schenn

unread,
Jun 12, 2015, 4:06:53 AM6/12/15
to ticalcorg...@googlegroups.com
Hi Lionel,

do you have any info about push_var? Im searching for a function to push
\0 terminated C string as valid (multibyte) variable name.

Btw. im trying to use InputStr to get string from user

void push_zstr_as_var(char *str)
{
push_quantum (VAR_TAG);
push_zstr (str);
push_quantum (VAR_TAG);
}

#define FILE "tmp"

/* prompt user for string */
void InputStr(char *prompt,
char buf[],
unsigned short len)
{
Access_AMS_Global_Variables;

FILES file;

TRY
// prompt user for string and store string in file
// ??? the expected variable is not created
push_zstr_as_var (FILE);
push_zstr (prompt);
cmd_inputstr (top_estack);

// file exists and could be opened
// ??? maybe type is wrong
if (FOpen (FILE, &file, FM_READ, "STR") == FS_OK) {
// get string from file
FRead (buf, len, &file);
FClose (&file);
} else {
buf[0] = '\0';
}
FINALLY
FDelete (FILE);
delete_between (next_expression_index (top_estack), top_estack);
ENDFINAL
}


Even

push_quantum (X_VAR_TAG);
push_zstr ("Enter string");
cmd_inputstr (top_estack);

alone gives "invalid command".

This code seems quite complex. Suggestions for a simpler solution are
also welcome.

Thanks.

Regards
Ralph
Reply all
Reply to author
Forward
0 new messages