Welcome, Guest. Please login or register.

AuthorTopic: Some questions about Amiga E  (Read 404 times)

0 Members and 1 Guest are viewing this topic.

Offline PanterHZ

Some questions about Amiga E
« on: February 18, 2018, 03:51:49 AM »
I have just started programming in Amiga E, and in this regard I have a couple of questions:

1. I have the following lines in my code:

StringF(dfile,'Ram:Test')
filehandle:=Open(dfile, NEWFILE)

Close(filehandle)

With this my program is able to create a new Ram:Test file, but how do I write the contents of a estring into it? There is no explenation to be found about this in the documentation included with Amiga E. The only thing I could find was this:

Out(filehandle,char)

Which I could have used for writing all bytes one by one from the estring to the file. But the problem is that this command expects an ASCII number as argument.
For really simple stuff, I can just use this instead:

StringF(command,'Echo >Ram:Test "\s" NOLINE\n',linje)
Execute(command,0,stdout)

But I want to know how to do this properly for the more advanced stuff.


2. I now know how to both read from and (somehow) write to a file, but how do I delete a file from within a program?

3. I also know how to check if a file exists or not, but what about checking if a directory exists? And a device/volume/assign?
 

Offline AmigaEd

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 511
  • Total likes: 0
Re: Some questions about Amiga E
« Reply #1 on: February 18, 2018, 05:50:32 AM »
I have no specific answers to your questions but I remembered the following link which has some examples that might be useful to you.

http://cshandley.co.uk/portable/examples/
"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - PrĂ­stino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebowski - August 2005
A3K - October 2010
y mas...
 

Offline SamuraiCrow

Some questions about Amiga E
« Reply #2 on: February 18, 2018, 07:55:11 PM »
A better link for a beginner would be http://cshandley.co.uk/JasonHulance which is also in AmigaGuide format with the main AmigaE download.  To answer the question more directly, you need to include the module called 'dos/dos.m' to allow direct access to DOS.library functions.  VfPrintF is the equivalent of PrintF but to a file handle.  If you need to compile a Kickstart 1.3 compatible executable, pass the file handle, the EString itself, and the length of the EString to Fwrite.

Note that system functions must start with a capital letter followed by a lowercase letter.  If you can't figure out the correct case sensitive spelling, use showmodule on the library's module file.
 

Offline PanterHZ

Re: Some questions about Amiga E
« Reply #3 on: February 19, 2018, 03:11:51 AM »
Quote from: AmigaEd;836253
I have no specific answers to your questions but I remembered the following link which has some examples that might be useful to you.

http://cshandley.co.uk/portable/examples/

Not everything there is of relevance to what I'm doing, but some useful stuff can be found there nevertheless.

Quote from: SamuraiCrow;836261
A better link for a beginner would be http://cshandley.co.uk/JasonHulance which is also in AmigaGuide format with the main AmigaE download.  To answer the question more directly, you need to include the module called 'dos/dos.m' to allow direct access to DOS.library functions.  VfPrintF is the equivalent of PrintF but to a file handle.  If you need to compile a Kickstart 1.3 compatible executable, pass the file handle, the EString itself, and the length of the EString to Fwrite.

Note that system functions must start with a capital letter followed by a lowercase letter.  If you can't figure out the correct case sensitive spelling, use showmodule on the library's module file.

I had a feeling that including a module was required. But this will have to wait, since I'm just sticking to the basic stuff right now. It turned out that it's VfPrintf and not VfPrintF, but what's frustrating is that it's not mentioned anywhere in the documentation of Amiga E. All I could find was it being used in two of the sources included with the package. Anyway, I tried the following:

VfPrintf(filehandle,'\s',linje)

But all I got was some garbled text in the file. The following did work however:

oldstdout:=SetStdOut(filehandle)
PrintF('\s',linje)
SetStdOut(oldstdout)


After some testing, I found out that this could be used as a simple way of checking if a dir or device/volume/assign exists:  

eirik:='Ram:Stuff/'
len:=FileLength(eirik)

eirik:='Env:'
len:=FileLength(eirik)

Both will return 0 if they exist, and -1 if they don't. So this isn't for files only.


Thanks for the help :)
 

Offline PanterHZ

Re: Some questions about Amiga E
« Reply #4 on: February 20, 2018, 05:40:38 AM »
Finally got it to work :)
It turned out that I had to do it like this:

VfPrintf(filehandle,'\s',[linje]:LONG)

Although it also works if :LONG isn't included. In case anybody is interested, the only files in the Amiga E package that mentions VfPrintf is the Src/Utils/D.e and Src/Various/freq.e files in the Src.lha archive.
 

Offline SamuraiCrow

Re: Some questions about Amiga E
« Reply #5 on: February 20, 2018, 06:18:16 PM »
Good show!  ELists are the way E implements varargs and tagitems also.  VfPrintf is a kickstart routine in DOS.library that normally uses varargs so it makes sense to pass the parameters in an EList.
 

Offline AmigaEd

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 511
  • Total likes: 0
Re: Some questions about Amiga E
« Reply #6 on: February 21, 2018, 04:07:05 AM »
I would be interested in knowing how you get on with E.

I had considered E and studied the tutorials some years back but decided to focus my energies elsewhere.
"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - PrĂ­stino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebowski - August 2005
A3K - October 2010
y mas...
 

Offline PanterHZ

Re: Some questions about Amiga E
« Reply #7 on: February 24, 2018, 05:06:50 AM »
Quote from: SamuraiCrow;836360
Good show!  ELists are the way E implements varargs and tagitems also.  VfPrintf is a kickstart routine in DOS.library that normally uses varargs so it makes sense to pass the parameters in an EList.

Yes, I will have to look more into ELists later :)
 

Offline PanterHZ

Re: Some questions about Amiga E
« Reply #8 on: February 24, 2018, 05:12:53 AM »
Quote from: AmigaEd;836374
I would be interested in knowing how you get on with E.

I had considered E and studied the tutorials some years back but decided to focus my energies elsewhere.

Well, I'm not entirely new to programming since I have made quite a few Shell and Gui4Cli scripts over the years, so I guess this helps a bit (I recognize While/EndWhile loops whenever I see them for example). But this type of programming takes a while to get used to, where the case-sensitivity of everything, and the fact that contents of variables cannot be accessed by using a "$" in front of them, are just two examples of this.

Some years ago I installed the Amiga E package since I needed to create a very small and simple executable for a project I was working on. After this was done, I intended to learn more about E programming later, but other stuff got in the way.

But recently, the need for yet another new executable appeared, so I decided to finally have a go at it again. My first project is related to the fact that I use IDer as a MultiView substitute on my OS2.1 Amigas, where it uses a text viewer as the last default option in its prefs file.
The thing is that it may not be safe to open binary files in text viewers, so I created a simple program (ASCorBIN) that checks if the given file is either ASCII or Binary, Now the last line in IDer.prefs executes a script that uses ASCorBIN for checking the file, and if it seems to be ASCII, it gets opened by the viewer. Otherwise, an error message is given.

Then I decided to go a step further and create a program that accepts a text viewer and a file as arguments, where the viewer automatically gets launched if the file seems to be ASCII. And I actually got it to work! But the problem is just that Amiga E executables doesn't seem to like being started by using "Run >NIL:" since this corrupts the EStrings in some way.
The thing is that IDer uses "Run >NIL:", so although my program works fine otherwise, it doesn't work when used in the context it was created for.

I have tried everything I can think of to get this working, but to no avail. Everything goes fine in the program when an EString is initialized for the first time, but not when others are afterwards. It doesn't help to re-use the first EString either. I don't know if normal Strings are affected by this as well, but in case they are not, maybe something like the below can be used instead of constructing the command line as an EString:

Execute('viewer "tfile"',0,stdout)

But this of course depends upon if there is a way to make it use the contents of the viewer and tfile variables instead of just the names.


As for what I think about Amiga E so far, I will take the positive first:
1. I find it much easier to understand the concepts of this programming language when compared to other similar ones.
2. It comes with comprehensive documentation and lots of example sourcecode.
3. I really like the compiler because of the info it provides when there's something wrong in the sourcecode.

Now over to the negative:
1. I find the fact that Amiga E executables cannot safely be started by using "Run >NIL:" to be VERY limiting.
2. There doesn't seem to be a way of expressing a character by using its ASCII decimal value.
3. Although the included documention is comprehensive, certain functionality is only vaguely mentioned, or not mentioned at all.
 

Offline SamuraiCrow

Some questions about Amiga E
« Reply #9 on: February 24, 2018, 07:11:18 AM »
Re:character value representation
E doesn't support unsigned numbers so you need to represent bytes greater than 127 as negative numbers.