HP3000-L Archives

September 2000, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Stan Sieler <[log in to unmask]>
Reply To:
Stan Sieler <[log in to unmask]>
Date:
Mon, 25 Sep 2000 12:01:40 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (83 lines)
Re:
> equivalent.  I have the procedure to do this.  However, how do I move or
> copy the value in a pointer to a string variable?

The key is that it isn't just "a pointer" you've got...it's a pointer
to a "char_array".


   strmove (#chars, source, source index, dest, dest index).

E.g.:

   setstrlen (hold_ipadd, len);
   strmove (len, char_star^ {source}, 1, hold_ipadd {dest}, 1);

I *always* comment the source/dest on a strmove, because I never
remember which is which!

Here's a sample that compiles/runs...
----------------------------cut here----------------------
program getenv (output);

type
                  {I usually append "_type" or "_ptr_type" to most}
                  {type, except pac## and str## (and a few others)}

   ip_name_type   = string [15];
   pac80          = packed array [1..80] of char;
   pac80_ptr_type = ^pac80;

var
   env_name       : pac80_ptr_type;
   envtoget       : pac80;
   ip_name        : ip_name_type;
   len            : integer;

Function getenv (envname : pac80): pac80_ptr_type;
   external;

begin

envtoget := 'server_name'#0;           {null-terminated, for getenv()}

env_name := getenv (envtoget);

if env_name = nil then
   writeln ('getenv() call failed to get anything...')

else
   begin
         {Find trailing null...}

   len := 0;
   while (len < sizeof (env_name^)) and
                  (env_name^ [len + 1] <> chr (0)) do
      len := len + 1;

         {Note: the above code will stop with   }
         {   len := sizeof (env_name)           }
         {if no null was found before the limit!}

         {We might have been given a server name that's}
         {small enough to fit within a pac80, but too  }
         {big for an ip_name...check/warn/truncate...  }

   if len > strmax (ip_name) then
      begin
      writeln ('oops, found server_name: ', env_name^);
      writeln ('truncating it to ', strmax (ip_name):1, ' chars');
      len := strmax (ip_name);
      end;

   setstrlen (ip_name, len);
   strmove (len, env_name^, 1, ip_name, 1);

   writeln ('env_name = ', env_name^);
   writeln ('ip_name  = "', ip_name, '", length = ', len:1);
   end;

end.
Stan Sieler                                           [log in to unmask]
www.allegro.com/sieler/wanted/index.html          www.allegro.com/sieler

ATOM RSS1 RSS2