English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 11 December 2021, 12:40   #1
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
input/output file handles and wb startup

Hi all,

I'm in the process of adding complete wb startup support for all my programs so i need to be cautious.

Here it's about input/output file handles normal cli processes all have : if run from wb i see null value for both.
If would however be handly for me to be able to continue using things such as PutStr directly. Would remove lots of special cases.

Can i just open a console window and set them ? Any particular precaution to take ?
(Most notably : is same handle allowed for both, must i restore anything upon exit and if so, is simple clearing ok to do.)

In addition if i open a console window, is there a simple and clean way to duplicate the "output window" wb opens by itself when running a program from a pseudo-icon ?
(Instead of using hard-coded values.)
meynaf is offline  
Old 11 December 2021, 16:24   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,245
Quote:
Originally Posted by meynaf View Post
If would however be handly for me to be able to continue using things such as PutStr directly. Would remove lots of special cases.
The typical approach is to allow a WINDOW tooltype, and the application opens that as stream when run from workbench. If the tooltype is not present, some kind of default is used. Typically, these windows use AUTO/CLOSE/WAIT modifiers such that the console only opens if something is printed, and stays present even after the program exits, so the user can continue to read.


Quote:
Originally Posted by meynaf View Post
Can i just open a console window and set them ? Any particular precaution to take ?
Only that you should only close the streams if you also opened them, and do not accidentially close the stream the shell provided.




Quote:
Originally Posted by meynaf View Post

Most notably : is same handle allowed for both, must i restore anything upon exit and if so, is simple clearing ok to do.
The same is allowed for both. System/Execute have some limitations on this, but not regular processes. Actually, the two handlers are just.. two handles that are used by some dos.library functions, e.g. Printf() uses the output handle, and ReadArgs() uses the input handle, though the latter is not very useful for wb started programs.


Again, just be careful to only close what you opened. The workbench does not care about the handles there, it neither touches them, so in principle, dangling pointers in there are allowed - but I'd still call this "bad style". Clean up after you.




Quote:
Originally Posted by meynaf View Post


In addition if i open a console window, is there a simple and clean way to duplicate the "output window" wb opens by itself when running a program from a pseudo-icon ?
CLICon/IconX is just a regular program that does nothing fancy, it just opens a window from the WINDOW tool type and creates a shell and then runs your program from that shell. It's not that the workbench does anything magic or fancy there.



Thus, that is the very same thing you get when your program is run from an "interactive" shell, no difference.


If you want to open a stream in both cases, one possibility is to open "*" in the shell startup instead of the workbench startup, but this always gives you the console, and not the output file handle (i.e. there will be a difference if your output has been redirected). There is unfortunately no generally valid way how to "clone" a file handle, only for interactive handles (such as the console, SER: or AUX:



A generally nice way to have a unique startup code is to create from the tool types array arguments and create a ReadArgs structure from them, then pass the same thing into the shell startup. This way, you don't have to write two argument parsers. (This is one of the unorthonogalities of AmigaOs I consider an issue of bad design, i.e. such a function should be somewhere in the Os rather than having to rewrite it every time again).
Thomas Richter is offline  
Old 11 December 2021, 17:26   #3
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
Quote:
Originally Posted by Thomas Richter View Post
The typical approach is to allow a WINDOW tooltype, and the application opens that as stream when run from workbench. If the tooltype is not present, some kind of default is used. Typically, these windows use AUTO/CLOSE/WAIT modifiers such that the console only opens if something is printed, and stays present even after the program exits, so the user can continue to read.
Sure, but it's that "some kind of default" that looks problematic.
Workbench won't automatically parse that tooltype and open the console window with safe default values, especially the title bar using the system's locale.


Quote:
Originally Posted by Thomas Richter View Post
Only that you should only close the streams if you also opened them, and do not accidentially close the stream the shell provided.
Well, in that case there is no shell so i can't close anything - both handles are null. If not run from WB i have no need to touch them.


Quote:
Originally Posted by Thomas Richter View Post
The same is allowed for both. System/Execute have some limitations on this, but not regular processes. Actually, the two handlers are just.. two handles that are used by some dos.library functions, e.g. Printf() uses the output handle, and ReadArgs() uses the input handle, though the latter is not very useful for wb started programs.
That's some relief. Thanks.


Quote:
Originally Posted by Thomas Richter View Post
Again, just be careful to only close what you opened. The workbench does not care about the handles there, it neither touches them, so in principle, dangling pointers in there are allowed - but I'd still call this "bad style". Clean up after you.
I have internal resource tracking in my code, so cleanup is hardly a problem


Quote:
Originally Posted by Thomas Richter View Post
CLICon/IconX is just a regular program that does nothing fancy, it just opens a window from the WINDOW tool type and creates a shell and then runs your program from that shell. It's not that the workbench does anything magic or fancy there.

Thus, that is the very same thing you get when your program is run from an "interactive" shell, no difference.
Right but IconX does not mimic WB's Output Window. Neither can I, apparently.


Quote:
Originally Posted by Thomas Richter View Post
If you want to open a stream in both cases, one possibility is to open "*" in the shell startup instead of the workbench startup, but this always gives you the console, and not the output file handle (i.e. there will be a difference if your output has been redirected). There is unfortunately no generally valid way how to "clone" a file handle, only for interactive handles (such as the console, SER: or AUX:
It's wb's console window appearance i need to clone, not a file handle.
Opening "*" is of no use - if run from cli i already have everything at hand, and from WB it doesn't work (gives a valid handle but output goes nowhere).


Quote:
Originally Posted by Thomas Richter View Post
A generally nice way to have a unique startup code is to create from the tool types array arguments and create a ReadArgs structure from them, then pass the same thing into the shell startup. This way, you don't have to write two argument parsers. (This is one of the unorthonogalities of AmigaOs I consider an issue of bad design, i.e. such a function should be somewhere in the Os rather than having to rewrite it every time again).
This is what i've done. I create a string from tool types (also from selected files) and then call ReadArgs with non-zero RDArgs parameter.
ReadArgs is great, tooltypes are great, but we really lack a unified scheme...
meynaf is offline  
Old 11 December 2021, 19:39   #4
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,245
Quote:
Originally Posted by meynaf View Post
Sure, but it's that "some kind of default" that looks problematic.
Workbench won't automatically parse that tooltype and open the console window with safe default values, especially the title bar using the system's locale.
Correct, the workbench does not care about this tool type, and it neither provides a default for it.



Strangely, there is a field do_ToolWindow in the disk object (see workbench/icon.h), which is read and written by the icon.library as a 0-terminated string, but the workbench provides no means to edit it and neither populates or uses it. Thus, potentially, there was quite a long way ago a plan to provide something like this, but the idea apparently got lost.
Thomas Richter is offline  
Old 11 December 2021, 19:56   #5
a4k-oerx
Registered User
 
Join Date: Oct 2008
Location: EU
Posts: 163
Quote:
Originally Posted by Thomas Richter View Post
Strangely, there is a field do_ToolWindow in the disk object (see workbench/icon.h), ... Thus, potentially, there was quite a long way ago a plan to provide something like this, but the idea apparently got lost.
AMIGA Datenstrukturen - Lexikon. Das Nachschlagewerk für alle Programmierer | Lukowicz, Paul, Pfeiffer, Olaf | ISBN: 9783890902500 | archive.org
Quote:
Originally Posted by AMIGA Datenstrukturen - Lexikon, page 273
do_ToolWindow 0x0046 (70) - Ein Adreßzeiger auf eine C-Zeichenkette, die ein CON:- oder RAW:-Fenster beschreibt, das beim Start des zu diesem Icon gehörigen Programms als Standardein-/Ausgabedatei geöffnet werden soll. Der Adreßzeiger auf die Window-Datenstruktur (siehe »Intuition«) des neuen Fensters wird dabei automatisch in die Komponente pr_WindowPtr der Process-Datenstruktur (siehe »Dos«) des Programms eingetragen. Um kein Fenster automatisch öffnen zu lassen, trägt man hier den Wert NULL ein. Dieser Adreßzeiger ist nur für Icons vom Typ WBTOOL von Bedeutung.
Sorry for german quote, the book is written in german, feel free to do a full translation.

It basically says, the field contains a pointer to a string with a CON:/RAW: window definition which should be used for standard in/output of the program and the window pointer will be written to some other structures automatically.

Edit: Some further research shows, that Directory Opus 5 obviously respected do_ToolWindow also with other values than NULL, file dopus5allamigas/source/Library/wb.c:1639 at github.com
Code:
// Tool window?
if (icon->do_ToolWindow &&
	(copy->doc_DiskObject.do_ToolWindow = L_AllocMemH(data->memory, strlen(icon->do_ToolWindow) + 1)))
	strcpy(copy->doc_DiskObject.do_ToolWindow, icon->do_ToolWindow);

Last edited by a4k-oerx; 11 December 2021 at 21:57. Reason: Directory Opus 5 sourcecode
a4k-oerx is offline  
Old 12 December 2021, 00:17   #6
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,245
What you see there in the German manual is just a direct copy/translation of what the RKRMs 1st edition stated about the field, literally. The 3rd edition just states (correctly) that this field is "reserved for future use". Actually, it was never used and was always reserved.

What DOpus does here is pretty much the same what the icon.library does: It carries the field around, but it doesn't touch or interpret it. Even the llatest icon.library copies the data, and the data is also part of the .info file and will be written and read back from disk. Just that it's of no particular use, and cannot be set from the user.
Thomas Richter is offline  
Old 12 December 2021, 17:35   #7
a4k-oerx
Registered User
 
Join Date: Oct 2008
Location: EU
Posts: 163
My RKRMs 1st edition actually state something different (did not even bother to look there first), main difference marked in quote.
Quote:
do_ToolWindow
By default, Workbench will start a program without a window. If ToolWindow is set, this file will be opened and made the standard input and output of the program. This window will also be put into the process's pr_WindowPtr variable and will be used for all system requesters. Note that this work is actually done in the language-dependent startup script; if you are coding in assembly or an unsupported language, you will have to do the work yourself. The only two files that it makes sense to open are "CON:" or "RAW:". See the AmigaDOS manual for the full syntax that these devices accept.
The quote in AMIGA Datenstrukturen - Lexikon says, pointers are set automatically - without any note about language etc.

So I guess nothing besides the field in structure was implemented at any time on OS side. On the other hand, especially with Amiga you never know, what has actually been done but later dropped due to ROM space or similar etc. or if/where this "startup script" was actually available or wasn't

Last edited by a4k-oerx; 12 December 2021 at 17:46.
a4k-oerx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there some compiler providing resource tracking for malloc/free/FILE* handles? jotd Coders. C/C++ 3 29 December 2018 11:58
Two input, Single Output - Mouse/Joystick Auto Switching solidcore Hardware mods 14 24 May 2018 22:33
Two input, Single Output - Mouse/Joystick Auto Switch solidcore MarketPlace 0 02 April 2018 01:30
startup-sequence file help sb1987 New to Emulation or Amiga scene 3 04 January 2012 06:56
File input with Blitz MelOtt Coders. General 0 05 January 2005 17:48

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:16.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07610 seconds with 15 queries