The problem is not with Ada (or Ada.Command_Line) but rather that p2ada doesn't understand reset or rewrite (!). But it does understand Open and Create (and Append for cases where the file already exists). P2ada is not prefect and it does require manual intervention though it will do a reasonable job most times. Don't be discouraged by this less than ideal translation for your short program (I agree it doesn't look like a promising start). Here is a short variation on the original program that will be correctly translated to Ada by p2ada,
program shell; var afile: text; begin Create(afile,"foo.txt"); writeln(afile, 'shell output'); end.
Two points to note 1) don't include *any* file variables in the Program name, 2) you must provide a file name for each call Open/Create/Append.
If you do decide to continue exploring p2ada I can give you some hints on other quirks in the p2ada process.
Cheers, Leo
On 4 January 2017 at 19:22, Gale Paeper gpaeper@empirenet.com wrote:
On Jan 3, 2017, at 10:08 PM, Schneider schneidt@mail.nih.gov wrote:
Leo:
https://sourceforge.net/p/p2ada/code/HEAD/tree/ http://p2ada.sourceforge.net/pascada.htm
I looked into this last July. I got the converter going and I got the compiler running. My final note:
2016 Jul 18
Currently hung because ada cannot handle files other than input and
output.
That is, it crashes if one tries to writeln(afile, 'something');
Example:
program shell(afile, output); var afile: text; begin rewrite(afile); writeln(afile, 'shell output'); end.
This produces a file called 'afile' with contents 'shell output'. It compiles with FPC and translates to c and compiles with p2c. Ada can't handle it. I suspect there is a way to do it but could not find the documentation.
Hmm... While I don't know Ada well enough to be even considered dangerous, I think the solution you're looking for lies in Ada'a Ada.Command_Line package which has the procedures that provide for reading the command line parameter text file name that Pascal's runtime system automatically associates to the "afile" file variable. Once you have the name then you use Ada.Text_IO package's procedures to create the file and output to it.
Ada'a mechanism for connecting to external command line parameters has more of a C argv argc style of parameter associating mechanism than Pascal's program parameter list of file variable names where the runtime system automatically associates the external command line parameter with the program's internal fileparameter.
I'm not sure how Ada's file handling procedures deal with the legal usage possibilities of Pascal's rewrite procedure. Rewrite does the "Right thing" regardless whether the file already exits or not. I don't know if both cases are automatically handled by Ada's runtime system in a similar Pascal runtime system manner or if you have to check which case you have and then have code to deal separately with each case.
Gale Paeper gpaeper@empirenet.com
Gpc mailing list Gpc@gnu.de https://www.g-n-u.de/mailman/listinfo/gpc