From mint-bounce@lists.fishpool.fi  Sun Oct 24 01:41:58 2004
X-Original-To: fnaumann@mail.boerde.de
Delivered-To: fnaumann@mail.boerde.de
X-Envelope-From: Martin_Elsaesser@ll.maus.de
X-Envelope-To: <mint@fishpool.com>
From: Martin_Elsaesser@ll.maus.de (=?ISO-8859-1?Q?Martin_Els=E4sser?=)
To: mint@fishpool.com
Subject: [MiNT] shel_write questions
Message-ID: <200410220850.p61399@ll.maus.de>
In-Reply-To: <opsf8gsizh8yw5lr@localhost.localdomain>
Date: Fri, 22 Oct 2004 08:50:00 +0200
Organization: MAUS Schondorf/Landsberg (+49-8192-9969999)
X-Gateway: b3.maus.de gb1.1r 102698.1858
X-Gateway-Administrator: postmaster@b3.maus.de
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Lines: 214
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by hirsch.in-berlin.de id i9NNe1jK029725
X-ecartis-version: Ecartis v1.0.0
Sender: mint-bounce@lists.fishpool.fi
Errors-To: mint-bounce@lists.fishpool.fi
X-original-sender: Martin_Elsaesser@ll.maus.de
Precedence: bulk
List-help: <mailto:ecartis@lists.fishpool.fi?Subject=help>
List-unsubscribe: <mailto:mint-request@lists.fishpool.fi?Subject=unsubscribe>
List-Id: <mint.lists.fishpool.fi>
X-List-ID: <mint.lists.fishpool.fi>
X-Virus-Scanned: by amavisd-new at relay.boerde.de
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on relay.boerde.de
X-Spam-Status: No, hits=-1.0 tagged_above=-50.5 required=3.8 tests=BAYES_00
X-Spam-Level: 

Hallo Arnaud,

AB>#define SWM_THRCREATE           20      /**< create a new thread, see
AB>mt_shel_write() */

In my MagiC docu this is named SHW_THR_CREATE.

AB>is there any "official" constant name ?

In the MagiC docu I found these names:

	#define SHW_THR_CREATE	20		/* doex */
	#define SHW_THR_EXIT	21
	#define SHW_THR_KILL	22


AB>What about mode 21 (thread terminate) and 22 (thread terminated by
AB>parent)

In the (german) MagiC docu I found this here for mode 21:

----------------------------------- schnipp
-----------------------------------
Wie beende ich einen Thread ?
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D

Normalerweise wird der Thread mit dem Ende der Prozedur <proc>, d.h. mit
dem CPU- Befehl "rts", automatisch beendet. Dies ist die sicherste und
beste Methode.

Alternativ kann sich ein Thread selbst beenden mit:

shel_write(SHW_THR_EXIT, 0, 0, errcode, NULL);

R=FCckgabewert (wenn OK, kehrt die Funktion nicht zur=FCck):

	0 Fehler

Ein Fehler kann auftreten, wenn

	-	der Aufrufer kein Thread ist, sondern etwas anderes
	-	der Thread inzwischen Pexec() gemacht hat

Wenn der Thread Pexec() gemacht hat, mu=DF erst der laufende Proze=DF per
Pterm() beendet werden, bevor sich der Thread beenden kann.
----------------------------------- schnapp
-----------------------------------

And this here for mode 22:

----------------------------------- schnipp
-----------------------------------
Im Notfall kann ein Thread auch vom Hauptprogramm aus beendet werden.
Normalerweise ist dies nicht notwendig, weil beim Beenden des Hauptprogra=
mms
automatisch alle zugeh=F6rigen Threads mit beendet werden.
Das Hauptprogramm beendet den Thread mit:

shel_write(SHW_THR_KILL, 0, ap_id, NULL, NULL);

R=FCckgabewert:

	0 Fehler
	1 OK

Ein Fehler kann auftreten, wenn

	-	die ap_id ung=FCltig ist
	-	der Thread sich bereits beendet hat
	-	unter der ap_id kein Thread l=E4uft, sondern etwas anderes
	-	der Thread nicht dem Aufrufer geh=F6rt

Auch wenn der R=FCckgabewert 1 ist, ist zu beachten, da=DF f=FCr den Fall=
,
da=DF der Thread inzwischen per Pexec() ein anderes Programm gestartet
hat, nur dieses Programm per Pterm(EBREAK) beendet wird. Der Thread ist
erst dann beendet, wenn der Aufrufer THR_EXIT empfangen hat.

Achtung:	Man beachte, da=DF Speicher, den der Thread alloziert, dem
		Proze=DF geh=F6rt, d.h. bei Beendigung des Threads nicht
		automatisch freigegeben wird. Gleiches gilt f=FCr offene Dateien,
		die erst bei Programmbeendigung geschlossen werden.
----------------------------------- schnapp
-----------------------------------

The Thread is terminated, if the called procedure returns. But the Thread
can terminated itself with SHW_THR_EXIT. If the main program wants to
terminate a thread, the mode SHW_THR_KILL is used.

AB>I'm looking for documentation on the THREADINFO structure: /**
AB>description of a thread, see mt_shel_write() with #SWM_THRCREATE mode

>From the magiC docu:

----------------------------------- schnipp
-----------------------------------
Ist <user_stack> =3D NULL, legt das System selbst den Stack an. Terminier=
t
der Thread, gibt das System den Stack in jedem Fall frei. <stacksize> ist=
 in
jedem Fall anzugeben, damit das System den Stackpointer des Threads auf d=
as
Ende des Stacks setzen kann. Der Systemstapel (supervisor stack) wird vom
System selbst festgelegt, die Gr=F6=DFe kann nicht beeinflu=DFt werden.
----------------------------------- schnapp
-----------------------------------

For <user_stack> =3DNULL the System creates the Stack. When the thread
terminates, the systems frees the stack in all cases! The stacksize must =
be
valid. The system sets the stackpointer to the end of the stack.

AB>what shall we set in user_stack : the address of the top or the bottom
AB>of  the memory allocated for the stack ? Is NULL a value allowed ?

The address is the beginning of the stack. With the correct value of the
stacksize the system sets the stackpointer correctly.

AB>What are mode and res1 fields for ?

They are reserved for future purposes. From the MagiC docu:

----------------------------------- schnipp
-----------------------------------
<mode> und <res1> sind f=FCr m=F6gliche Erweiterungen reserviert. In Sola=
ris 2.x
kann man damit z.B. einen Thread bis zum endg=FCltigen Start anhalten.
----------------------------------- schnapp
-----------------------------------

AB>In gemlib, there is a SHELTAIL structure: what's for ?

This is the structure for the desktop for the mode SHW_CHAIN and
SHW_SINGLE. in the MagiC docu there is a document about the "single mode"
of MagiC when starting applications:

----------------------------------- schnipp
-----------------------------------
Wie starte ich nun ein Programm im "single mode":

a)   Sicherstellen, da=DF ich Applikation #0 bin (d.h. ap_id =3D=3D 0).
b)   Pfade und Laufwerk f=FCr das neue Programm setzen.
c)   shel_write(TRUE, isgr, SHW_SINGLE, cmd, path);
d)   alle wichtigen Einstellungen in tempor=E4re Datei bzw. Shell- Puffer
e)   appl_exit()/v_clsvwk()/Pterm0

Wie starte ich nun ein Programm im "chain mode":

a)   ggf. Pfade und Laufwerk f=FCr das neue Programm setzen und einen
     Aufruf
          shel_write(TRUE, dummy, SHW_SINGLE, dummy2, dummy3);
     machen, um die Pfade f=FCr das neue Programm zu setzen.
     (inkompatibel zu TOS)
b)   shel_write(TRUE, isgr, SHW_CHAIN, cmd, path);
c)   alle wichtigen Einstellungen in tempor=E4re Datei bzw. Shell- Puffer
d)   appl_exit()/v_clsvwk()/Pterm0

Nach Beendigung des Programms wird automatisch wieder die Shell geladen.
Beim Aufruf der Shell bekommt man in der Kommandozeile (->shel_read) die
"magische" Sequenz (magx.h):

/* tail for default shell */

typedef struct
     {
     int  dummy;                   /* ein Nullwort               */
     long magic;                   /* 'SHEL', wenn ist Shell     */
     int  isfirst;                 /* erster Aufruf der Shell    */
     long lasterr;                 /* letzter Fehler             */
     int  wasgr;                   /* Programm war Grafikapp.    */
     } SHELTAIL;

Wenn <isfirst> gesetzt ist, ist der Status etwa aus DESKTOP.INF zu lesen,
ist <isfirst> nicht gesetzt, nimmt man die tempor=E4re Datei bzw. den
Shell- Puffer.
<lasterr> ist der R=FCckgabewert des vorher gelaufenen Programms. Wenn di=
es
ein
GEM-Programm war, ist der Fehler bereits per Alertbox angezeigt worden.
Bekannlich ist das Langwort negativ, wenn der Fehler beim Pexec selbst
auftrat, ein Programm-R=FCckgabewert hat immer Hiword 0.
----------------------------------- schnapp
-----------------------------------

First of all only ap_id=3D0, the desktop, may start applications in singl=
e
mode. The desktop starts the application with the following method:

How to start a application in "single mode":

a)   Check that desktop is applikation #0 (i.e. ap_id =3D=3D 0).
b)   Set the paths and drives for the new program
c)   shel_write(TRUE, isgr, SHW_SINGLE, cmd, path);
d)   Save all options in temporary files or the shell buffer
e)   appl_exit()/v_clsvwk()/Pterm0

How to start a application in "chain mode":

a)   set path and drive for the new program and call
          shel_write(TRUE, dummy, SHW_SINGLE, dummy2, dummy3);
     to set the paths for the new program
     (incompatibel zu TOS!)
b)   shel_write(TRUE, isgr, SHW_CHAIN, cmd, path);
c)   save all options in temporary file or the shel buffer
d)   appl_exit()/v_clsvwk()/Pterm0

When the started program terminates, the desktop is started again. In the
commandloine (shel_read!) the desktop gets a SHELTAIL-Structure. <isfirst=
>
is set, it is the first start of the desktop (read options from
DESKTOP.INF). If it's cleared, the temporary options should be used.
<lasterr> contains the return value of the started program. If a GEM
applications was started, errors were already shown in alertboxes.

AB>the following constant seems to be a message value to terminate the
AB>AES (that mean that any AES application may terminate the AES???)

Yes! The docu of N.AES discribes this!

Gru=DF

     Martin    [PGP-Key available]
---
F=FCr Mails >16 kByte: martin@melsaesser.de


