🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.listserv.simula
Article #460

Re: Procedure redefinition

#460
From: Gorel Hedin
Date: Thu, 09 Dec 1993 16:38
98 lines
3820 bytes
In article 229@ugle.unit.no, chris@mtdhp1.marintek.sintef.no (Christian Steinebach) writes:
> 
> Hi gurus out there (anybody listening?)
> 
> I'm in the situation where I have to convert a Simula program from
> reading and writing from and to a flat file to accessing a database.
> In principle it's not a big problem, I'm able to write the functions
> I need in C. But, in one case output of the Simula program is
> scattered all over the source files, it's some trace option. There are
> __many__ lines with s.th. like
> 	Tracefile.outtext("xxx yyy zzz");
>  	Tracefile.outfix(var, 2,5);
> 	Tracefile.outtext(" ");
> 	Tracefile.outint(ivar,3);
> 	....
> 	Tracefile.outimage;
> 
> I'm not a Simula hacker and so finally, the question:
>  
> 	Is it possible to redefine outtext, outint, outfix, outimage
> 	in a class in a way that these functions fill up a buffer
> 	(Could be done in C) and outimage will write the buffer
> 	to the database instead of to the File?         
> 
> That way I could leave most of the original Simula source untouched.
> In C++ it would be easy, in Simula I don't know what to look for in 
> the books.
> 
> 	Thanks
> 		Christian


You can write a new class OutFile which redefines the procedures of
OutFile.  Implement outtext, outint, etc to fill in a Simula text
buffer "Image" by using the corresponding routines puttext, putint,
etc. Redefine Outimage to call a suitable external C procedure which
writes the "Image" to the database.  Redefine the procedure Open in a
suitable way (maybe it should initialize/open the database or such).

Like this:

   class OutFile;
   begin
      text Image;
      
      external C procedure SomeCRoutine = "SomeCRoutine"
      is procedure SomeCRoutine(str); text str;;
      
      procedure outtext(T); text T;
      begin
         Image.PutText(T);
      end;
      
      ...
   	
      procedure outimage;
      begin
         outchar('!0!'); ! Put a NULL character at the end of the Image buffer;
         SomeCRoutine(Image);
      end;
      
      procedure open(fileimage); text fileimage;
      begin
         image :- fileimage;
      end;
   end;

The Lund compiler handles text arguments to external C procedures by
automatically converting the Simula text to a C string. If your
C-routine relies on null-termination of the C-string, the null has to
be put in explicitly as shown above.  The Simula runtime system will
malloc space for the C string and copy it from the Simula text. It is
also possible to avoid copying by specifying the str parameter as a
name-parameter. However, because the Simula text may be moved around by
the garbage collector you should do this only if you are SURE that the
C routine does not keep a pointer to the string and/or change the
string.

I hope I have got the details right. I can't find the manual on external
C procedures.

Put together your new program as follows:

begin
   class OutFile; ! Hides the standard OutFile class;
   begin
      ... as above ...
   end;

%include YourOldProgram.sim
end;

Good luck.

--------
Gorel Hedin
Dept of Computer Science
Lund University
Technical Details
Message-ID: <2e7k9q$d8p@nic.lth.se>
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!pipex!sunic!news.lth.se!niping!gorel
References: <2e4ogo$229@ugle.unit.no>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113dd9,4d03a03e12031393
X-Google-Attributes: gid113dd9,public
X-Google-ArrivalTime: 1993-12-10 06:56:01 PST
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!pipex!sunic!news.lth.se!niping!gorel
From: gorel@dna.lth.se (Gorel Hedin)
Newsgroups: bit.listserv.simula
Subject: Re: Procedure redefinition
Date: 9 Dec 1993 16:38:18 GMT
Organization: Dept of Comp Science, LTH
Lines: 100
Distribution: world
Message-ID: <2e7k9q$d8p@nic.lth.se>
References: <2e4ogo$229@ugle.unit.no>
Reply-To: gorel@dna.lth.se
NNTP-Posting-Host: niping.dna.lth.se