From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,6f94a58adaa49034 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-16 09:23:23 PST Newsgroups: comp.lang.ada Path: archiver1.sj.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.onemain.com!feed1.onemain.com!uunet!dca.uu.net!ash.uu.net!xyzzy!nntp From: Jeffrey Carter Subject: Re: Return value of system call (newbie question) X-Nntp-Posting-Host: e246420.msc.az.boeing.com Content-Type: text/plain; charset=iso-8859-1 Message-ID: <3B02A608.EAC44C76@boeing.com> Sender: nntp@news.boeing.com (Boeing NNTP News Access) Content-Transfer-Encoding: 8bit Organization: The Boeing Company X-Accept-Language: en References: Mime-Version: 1.0 Date: Wed, 16 May 2001 16:08:40 GMT X-Mailer: Mozilla 4.5 [en]C-CCK-MCD Boeing Kit (WinNT; U) Xref: archiver1.sj.google.com comp.lang.ada:7568 Date: 2001-05-16T16:08:40+00:00 List-Id: Torbj�rn Karfunkel wrote: > > I'm executing an external program from within an Ada program by using > > function OtterCall(Value : String) return Integer; > pragma Import(C, OtterCall, "system"); > > The program that is called upon, Otter, is called with the syntax > > otter output-file > > and the calls look like this (several calls to each are made) > > Result := OtterCall(Value => > ("/home/toka/otter/otter-3.0.6/source/otter " & > "< > /home/toka/exjobb/model_checker/nyare/" & > ("sat" & > Natural'Image(K)(2..Natural'Image(K)'Last) & ".in") & > " > > /home/toka/exjobb/model_checker/nyare/" & > ("satresult" & > Natural'Image(K)(2..Natural'Image(K)'Last) & ".oout"))); > > Result := OtterCall(Value => > ("/home/toka/otter/otter-3.0.6/source/otter " & > "< > /home/toka/exjobb/model_checker/nyare/" & > ("taut" & > Natural'Image(K)(2..Natural'Image(K)'Last) & ".in") & > " > > /home/toka/exjobb/model_checker/nyare/" & > ("tautresult" & > Natural'Image(K)(2..Natural'Image(K)'Last) & ".oout"))); > > Two problems have arisen: > 1) The first call to otter was executed normally and produced the > outfile satresult0.oout, > but the second call, which I thought would produce the outfile > tautresult0.oout, produced > an outfile named tautresult0.oout0.oout. > It seems that some part of the Value string from the previous call > is appended to the end > of the next. I solved this problem by appending a sequence of > blanks to the end of the Value > strings, but this seems unnecessary. Could anyone give an > explanation to this behavior? I suspect this is caused because you are not NUL terminating your strings. The C "system" function takes a C string (a pointer to the 1st character of a NUL-terminated string). Pragma Import will take care of providing the pointer to C, but will not add the NUL. If we simplify your code a bit: Program_Path : constant String := "/home/toka/otter/otter-3.0.6/source/otter"; File_Path : constant String := "/home/toka/exjobb/model_checker/nyare/"; function Image_NLB (Value : Natural) return String is Image : constant String := Natural'Image (Value); begin -- Image_NLB return Image (Image'First + 1 .. Image'Last); end Image_NLB; function In_Name (Prefix : String; Number : Natural) return String is -- null; begin -- In_Name return File_Path & Prefix & Image_NLB (Number) & ".in"; end In_Name; function Out_Name (Prefix : String; Number : Natural) return String is -- null; begin -- Out_Name return File_Path & Prefix & Image_NLB (Number) & ".oout"; end Out_Name; Result := Ottercall (Program_Path & " < " & In_Name ("sat", K) & " > " & Out_Name ("satresult", K) & Ada.Characters.Latin_1.NUL); This should correct the problem. You could also use "Interfaces.C.Char_Array" in place of "String" in your specification of Ottercall, and convert your strings using function Interfaces.C.To_C: Result := Ottercall (Interfaces.C.To_C (Program_Path & " < " & In_Name ("sat", K) & " > " & Out_Name ("satresult", K) ) ); -- Jeffrey Carter