Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #5522

Re: how to use a sysvar in Basic

Date 2018-09-08 10:32 +0100
From Matthew Phillips <spam2011m@yahoo.co.uk>
Newsgroups comp.sys.acorn.programmer
Subject Re: how to use a sysvar in Basic
Message-ID <1873403457.Matthew@sinenomine.freeserve.co.uk> (permalink)
References <d1fd503257.jim@6.abbeypress.net> <pmmdnd$14pp$1@gioia.aioe.org> <b8a8d93257.jim@6.abbeypress.net> <a0afea3257.Matthew@sinenomine.freeserve.co.uk> <pmquuq$e36$1@gioia.aioe.org>

Show all headers | View raw


In message <pmquuq$e36$1@gioia.aioe.org>
 on 6 Sep 2018 Steve Drain  wrote:

> On 05/09/2018 20:19, Matthew Phillips wrote:
> > on 5 Sep 2018 Jim Nagel wrote >> It would be more useful for my present purpose if, instead of that
> >> error message, I could make the function return some arbitrary
> >> value (such as "") and exit.  I tried PRINT ERR -- nothing was
> >> printed. Any suggestions?
> > You want the X form of the SWI to avoid generating an error, and you
> > need to look at the value in R2 to see if it is zero, as that
> > indicates the variable does not exist:
> > 
> > DEFFNval(v$)
> >   LOCAL len%
> >   SYS"XOS_ReadVarVal",v$,END,-1,0,3 TO ,,len%
> >   IF len%=0 THEN =""
> >   SYS"OS_ReadVarVal",v$,END,256,0,3 TO ,v$
> > =v$
> > 
> > Note the value of 3 in R4 which will force the call to convert the
> > variable value into a string. That avoids problems if the variable is
> > an integer or a macro (unless, of course, you want the value in the
> > original form).
> 
> If you are happy to return a null string if the variable does not exist,
> I think this can just be:
> 
>   DEFFNval(v$)
>    SYS"XOS_ReadVarVal",v$,END,256,,3 TO ,v$
>   =v$
> 
> I would be interested to find the flaws here.

I think the only doubt in my mind is the state of the memory at END, because
if the variable does not exist, XOS_ReadVarVal does not alter the contents of
the buffer at all.  So v$ would get the string that happened to be at END (if
there was one) when the call was entered.

This may or may not be documented, but if it isn't documented I would not
like to rely on it.
 
> I have left the R4=3 for the reasons you state, but any numerical value 
> will have to be converted back from the string.
> 
> > The printed PRM on page 1-310 does say ominously that "returned
> > strings are not terminated and you should use the length returned in
> > R2 when reading them" so it is possible that the code above might
> > fail. If the strings really are not terminated then the TO part of
> > the SYS which puts the value into v$ would not work.
> 
> Yes, that is a puzzle, but I have always found them terminated, so what 
> do you assume?

Perhaps the SWI documentation is unnecessarily cautious.  We can not inspect
the source to see what the OS really does.  If it does terminate the strings
with a null byte, and always has, it would be good to update the
documentation so that people know they can rely on the behaviour.

> It also seems to be that R2 returns 0 when the variable does not exist, 
> even when you are not explicitly testing for existence.

Yes, that much is reasonable, and is implied by the PRM which says that R2 on
exit is the number of bytes read, which would be zero if it can't read any.

-- 
Matthew Phillips
Durham

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to use a sysvar in Basic Jim Nagel <jimnewsm13c@abbeypress.co.uk> - 2018-09-04 16:20 +0100
  Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-04 18:00 +0100
    Re: how to use a sysvar in Basic Jim Nagel <jimnewsm13c@abbeypress.co.uk> - 2018-09-04 18:54 +0100
      Re: how to use a sysvar in Basic Julian Fry <julianfry@orpheusmail.co.uk> - 2018-09-08 21:03 +0100
    Re: how to use a sysvar in Basic Jim Nagel <jimnewsm13c@abbeypress.co.uk> - 2018-09-05 17:13 +0100
      Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-05 20:19 +0100
        Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-06 11:19 +0100
          Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-08 10:32 +0100
            Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-08 14:56 +0100
              Re: how to use a sysvar in Basic Alan Adams <alan@adamshome.org.uk> - 2018-09-08 19:39 +0100
              Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-10 07:27 +0100
                Re: /  not  (OT) Jim Nagel <jnews18c@abbeypress.co.uk> - 2018-09-10 11:37 +0100
                Re: /  not  (OT) News <chrisjohnson@spamcop.net> - 2018-09-10 14:34 +0100
    Re: how to use a sysvar in Basic Alan Adams <alan@adamshome.org.uk> - 2018-09-08 11:20 +0100
      Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-08 14:40 +0100
  Re: how to use a sysvar in Basic "John Williams (News)" <UCEbin@tiscali.co.uk> - 2018-09-04 18:16 +0100
    Re: how to use a sysvar in Basic Alan Adams <alan@adamshome.org.uk> - 2018-09-04 22:04 +0100
      Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-05 08:03 +0100
        Re: how to use a sysvar in Basic Martin Wuerthner <spamtrap@mw-software.com> - 2018-09-05 14:39 +0200
          Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-05 19:45 +0100
            Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-06 11:24 +0100
    Re: how to use a sysvar in Basic "John Williams (News)" <UCEbin@tiscali.co.uk> - 2018-09-05 20:56 +0100
      Re: how to use a sysvar in Basic svrsig <chris@svrsig.org> - 2018-09-05 20:13 -0700
        Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-06 07:21 +0100
  Re: how to use a sysvar in Basic A. N. Other <ANOther@argonet.co.uk> - 2018-09-04 18:11 +0100
    Re: how to use a sysvar in Basic Jim Nagel <jimnewsm13c@abbeypress.co.uk> - 2018-09-04 18:42 +0100
      Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-05 08:08 +0100
  Re: how to use a sysvar in Basic jgh@mdfs.net - 2018-09-06 17:12 -0700

csiph-web