comp.lang.ada
 help / color / mirror / Atom feed
* Variable length strings??
@ 1993-05-05 10:49 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!agate
  0 siblings, 0 replies; 2+ messages in thread
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!agate @ 1993-05-05 10:49 UTC (permalink / raw)


I have a problem which has been causing me some headaches recently, and
i was hoping someone on here could help....

I am reading paths from a configuration file for the system i'm writing,
these paths are not of a set length, as they will depend on where the
system is installed.

I'm reading them into a long string, but ideally i need the string to be
the exact same length as the path. And i need this string variable to be
globally readable, not just for the scope of a particular function/procedure.

Any suggestions?? i've been messing with descriminate record types, but
with no success so far.

Any help greatly appriciated,

Thanks
Marc

 ------------------------------------------------------------------------------
      **     **      *  ****** ***    *   |             On the net,
     ** *    **     *** **     ** *   *   |     no-one can hear you scream!
    **   *   **     *** ****   **  *  *   |------------------------------------
   **     *  **     *** **     **   * *   |  email   marc@comp.lancs.ac.uk
  **       * ******  *  ****** **    **   |      marc@computing.lancaster.ac.uk
 ------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Variable length strings??
@ 1993-05-05 19:35 Robert I. Eachus
  0 siblings, 0 replies; 2+ messages in thread
From: Robert I. Eachus @ 1993-05-05 19:35 UTC (permalink / raw)


In article <1993May5.104941.14603@comp.lancs.ac.uk> marc@comp.lancs.ac.uk (Marc
 Goldman) writes:

   > I am reading paths from a configuration file for the system i'm
   > writing, these paths are not of a set length, as they will depend
   > on where the system is installed.

   > I'm reading them into a long string, but ideally i need the
   > string to be the exact same length as the path. And i need this
   > string variable to be globally readable, not just for the scope
   > of a particular function/procedure.

   > Any suggestions?? i've been messing with descriminate record
   > types, but with no success so far.

   First of all, this application seems to be perfect for some global
access-to-string variables:

   type String_Pointer is access String;
   ...
   Path: String_Pointer := ...;

   The only problem is that occasionally you will need to reference
Path.all instead of Path.  But the interesting trick come in the
initial value.  You imply that this should be read in during
elaboration time.  (i.e. Path will appear in a library package
specification, and you want all references to Path to "work.")
However none of the Get operations in Text_IO is a function, so you
need to roll your own:

    with Text_IO;
    function Get_Path return String is
      Temp: String(1..250);
      Last: Integer;
    begin
      Text_IO.Get_Line(Temp,Last);
      return Temp(1..Last);
    end Get_Path;

    (You might want to fancy it up by adding a prompt, a file
parameter, exception support, or handling of very long lines.)

    Add appropriate with clauses and pragma ELABORATEs, and you are
all set to go.

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1993-05-05 19:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-05-05 19:35 Variable length strings?? Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
1993-05-05 10:49 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!agate

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox