[comp.sys.amiga.tech] Tags - How do they work.

rwm@atronx.UUCP (Russell McOrmond) (10/29/90)

Well, it seems that I don't fully understand the concept of Tags. I am 
trying to make use of the 2.0 System() command, but my knowledge of Tags is
presenting me with a problem.

Here's a code sample.  What obvious thing am I doing wrong ;-)

#include <stdio.h>
#include <dos/dostags.h>
#include <clib/dos_protos.h>

main(argc, argv)
	int argc;
	char *argv[];

{
        FILE *outfile,*infile;
        int rc;

        if (!(outfile = fopen("tempout","w"))) {
             printf("error opening outfile\n");
             exit(1);
        }

        if (!(infile = fopen("tempin","r"))) {
             printf("error opening infile\n");
             fclose(outfile);
             exit(1);
        }
            
        rc = System(argv[1],
              (
              SYS_Input, infile,
              SYS_Output, outfile,
              SYS_Asynch, FALSE,    
              TAG_DONE
              )
            );


        printf("%d from %s\n",rc,argv[1]);
        fclose(infile);
        fclose(outfile);
}


---
  Opinions expressed in this message are my Own.  My Employer does not even
know what these networks ARE.

  Russell McOrmond   rwm@atronx.UUCP   {fts1,alzabo}!atronx!rwm 
  FidoNet 1:163/109  Net Support:

ken@cbmvax.commodore.com (Ken Farinsky - CATS) (10/31/90)

In article <53151.657181050@atronx.UUCP> rwm@atronx.UUCP (Russell McOrmond) writes:
>Well, it seems that I don't fully understand the concept of Tags. I am 
>trying to make use of the 2.0 System() command, but my knowledge of Tags is
>presenting me with a problem.
>            
>        rc = System(argv[1],
>              (
>              SYS_Input, infile,
>              SYS_Output, outfile,
>              SYS_Asynch, FALSE,    
>              TAG_DONE
>              )
>            );

Looks like an extra set of parenthesis.  Try:

rc = System(argv[1],
            SYS_Input, infile,
            SYS_Output, outfile,
            SYS_Asynch, FALSE,    
            TAG_DONE
            );


-- 
--
Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines
uucp: ken@cbmvax.commodore.com   or  ...{uunet,rutgers}!cbmvax!ken
bix:  kfarinsky

rwm@atronx.UUCP (Russell McOrmond) (10/31/90)

In a message posted on 30 Oct 90 19:11:14 GMT,
ken@cbmvax.commodore.com (Ken Farinsky - CATS) wrote:
KF-C>Looks like an extra set of parenthesis.  Try:

I tried the Below First, and only tried the above after the compiler (SAS 5.10)
gave me a pile of errors.

I have since tried it with Open()  (struct FileHandle), and still no go. (P.S.
This may seem like a silly question, but what function is used to Close a file
opened with Open()  Does the normal level 1 close() work?)

KF-C>rc = System(argv[1],
KF-C>            SYS_Input, infile,
KF-C>            SYS_Output, outfile,
KF-C>            SYS_Asynch, FALSE,    
KF-C>            TAG_DONE
KF-C>            );

Anyways, the program seems to run Syncronously, with input and output set to
the consol.

I am using the following to test:

	
#include <stdio.h>
main(argc, argv)
	int argc;
	char *argv[];
{ 
   int c;
   while ((c=getchar())!=EOF)
       putchar(c);
}



KF-C>Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines
KF-C>uucp: ken@cbmvax.commodore.com   or  ...{uunet,rutgers}!cbmvax!ken
KF-C>bix:  kfarinsky

Any chance you could drop out an example that Does work?  Am I possibly including
the wrong includes?  Has anyone else using SAS tried System()?

---
  Opinions expressed in this message are my Own.  My Employer does not even
know what these networks ARE.

  Russell McOrmond   rwm@atronx.UUCP   {fts1,alzabo}!atronx!rwm 
  FidoNet 1:163/109  Net Support: (613) 230-2282
  Amiga-Fidonet Support  1:1/109

ken@cbmvax.commodore.com (Ken Farinsky - CATS) (10/31/90)

I posted this the other day, which turned out to be wrong (as System()
will not handle tags on the stack...)

>>rc = System(argv[1],
>>            SYS_Input, infile,
>>            SYS_Output, outfile,
>>            SYS_Asynch, FALSE,    
>>            TAG_DONE
>>            );

Ewout sent me some mail, as follows:

>>Ken, System() is tag, not stack based. So he'd have to do something like
>>
>>struct TagItem tag[5];
>>
>>tag[0].ti_Tag = SYS_Input;
>>tag[0].ti_Data = infile;
>>	.
>>	.
>>tag[4].ti_Tag = TAG_END;
>>
>>But the whole thing that guy is trying to do is wrong anyway since you cannot
>>use a level 2 filehandle as an AmigaDOS BPTR filehandle.
>>---
>>Ewout Walraven - CATS			Commodore Business Machines, Inc.
>>215-431-9426				{uunet|rutgers}!cbmvax!ewout

So, you have to put the tags into an array, then call System() with a
pointer to the name of the command and a pointer to the tag array.
Live and learn.

>  Russell McOrmond   rwm@atronx.UUCP   {fts1,alzabo}!atronx!rwm 
>  FidoNet 1:163/109  Net Support: (613) 230-2282
>  Amiga-Fidonet Support  1:1/109
-- 
--
Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines
uucp: ken@cbmvax.commodore.com   or  ...{uunet,rutgers}!cbmvax!ken
bix:  kfarinsky

waggoner@dtg.nsc.com (Mark Waggoner) (11/01/90)

In article <53151.657181050@atronx.UUCP> rwm@atronx.UUCP (Russell McOrmond) writes:
>Well, it seems that I don't fully understand the concept of Tags. I am 
>trying to make use of the 2.0 System() command, but my knowledge of Tags is
>presenting me with a problem.

I don't know anything about tags and, therefore, my comments below
are no more than educated guesses...  
The program below has been edited down:

>        FILE *outfile,*infile;
>        int rc;
>
>        if (!(outfile = fopen("tempout","w"))) {
            ...
>        if (!(infile = fopen("tempin","r"))) {
            ...
>        rc = System(argv[1],
>              (
>              SYS_Input, infile,
>              SYS_Output, outfile,
>              SYS_Asynch, FALSE,    
>              TAG_DONE
>              )
>            );

It seems to me unlikely that the System call would use FILE arguments
(the infile and outfile parameters) and more likely that it would use 
a pointer or BPTR to a FileHandle returned by the Dos function Open().
A FILE is defined by the library provided by the compiler vendor and
the System() call wouldn't know how to use it.






-- 
Mark Waggoner  Santa Clara, CA    (408) 721-6306         waggoner@dtg.nsc.com 
 Unofficially representing National Semiconductor Local Area Networks Group
                   Officially misrepresenting myself.

dillon@overload.Berkeley.CA.US (Matthew Dillon) (11/02/90)

    It turns out that it is extremely easy to implement stack-based tags,
    as someone on BIX pointed out to me.  Under 2.0, the Amiga.Lib already
    has routines to do this for some commands.... for example,

	OpenWindowTags()        -stack based tags method, tags are
				 individual arguments to the routine

	OpenWindowTagList()     -pointer to array of tags method, you
				 pass a pointer to the tags array.

    One can easily implement one's own routine to convert a stack based
    tags list into an array pointer tags list using VAR ARGS.  For
    example, the implementation of SystemTags() would be:

	#include <stdio.h>
	#include <stdarg.h>

	long
	SystemTags(cmd, ...)
	char *cmd;
	{
	    va_list va;
	    long error;

	    va_start(va, cmd);
	    error = System(cmd, va);
	    va_end(va);
	    return(error);
	}



The messages:

In article <15486@cbmvax.commodore.com> ken@cbmvax.commodore.com (Ken Farinsky - CATS) writes:
>I posted this the other day, which turned out to be wrong (as System()
>will not handle tags on the stack...)
>
>>>rc = System(argv[1],
>>>	       SYS_Input, infile,
>>>	       SYS_Output, outfile,
>>>	       SYS_Asynch, FALSE,
>>>	       TAG_DONE
>>>	       );
>
>Ewout sent me some mail, as follows:
>
>>>Ken, System() is tag, not stack based. So he'd have to do something like
>>>
>>>struct TagItem tag[5];
>>>
>>>tag[0].ti_Tag = SYS_Input;
>>>tag[0].ti_Data = infile;
>>>	.
>>>	.
>>>tag[4].ti_Tag = TAG_END;
>>>
>>>But the whole thing that guy is trying to do is wrong anyway since you cannot
>>>use a level 2 filehandle as an AmigaDOS BPTR filehandle.
>>>---
>>>Ewout Walraven - CATS			Commodore Business Machines, Inc.
>>>215-431-9426 			{uunet|rutgers}!cbmvax!ewout
>
>So, you have to put the tags into an array, then call System() with a
>pointer to the name of the command and a pointer to the tag array.
>Live and learn.
>
>>  Russell McOrmond   rwm@atronx.UUCP	 {fts1,alzabo}!atronx!rwm
>>  FidoNet 1:163/109  Net Support: (613) 230-2282
>>  Amiga-Fidonet Support  1:1/109
>--
>--
>Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines
>uucp: ken@cbmvax.commodore.com   or  ...{uunet,rutgers}!cbmvax!ken
>bix:  kfarinsky

--

				    -Matt

    Matthew Dillon	    dillon@Overload.Berkeley.CA.US
    891 Regal Rd.	    uunet.uu.net!overload!dillon
    Berkeley, Ca. 94708
    USA

peter@cbmvax.commodore.com (Peter Cherna) (11/05/90)

In article <dillon.6960@overload.Berkeley.CA.US> dillon@overload.Berkeley.CA.US (Matthew Dillon) writes:
>
>    It turns out that it is extremely easy to implement stack-based tags,
>    as someone on BIX pointed out to me.  Under 2.0, the Amiga.Lib already
>    has routines to do this for some commands.... for example,
>
>	OpenWindowTags()        -stack based tags method, tags are
>				 individual arguments to the routine
>
>	OpenWindowTagList()     -pointer to array of tags method, you
>				 pass a pointer to the tags array.

Stubs will eventually be added to amiga.lib for DOS and ASL varargs
functions, too.

>    One can easily implement one's own routine to convert a stack based
>    tags list into an array pointer tags list using VAR ARGS.  For
>    example, the implementation of SystemTags() would be:

Here's a simpler way, that doesn't use ANSI-varargs but is perfectly
valid given the Amiga stack conventions:

#include <utility/tagitem.h>

LONG SystemTags( UBYTE *command, Tag firsttag, ...)
{
    return( System( command, &firsttag ) );
}


>				    -Matt

     Peter
--
     Peter Cherna, Software Engineer, Commodore-Amiga, Inc.
     {uunet|rutgers}!cbmvax!peter    peter@cbmvax.cbm.commodore.com
My opinions do not necessarily represent the opinions of my employer.
"She read him like a book:  she liked to peek at his end."

dzenc@gnu.ai.mit.edu (Dan Zenchelsky) (11/06/90)

In article <dillon.6960@overload.Berkeley.CA.US> dillon@overload.Berkeley.CA.US (Matthew Dillon) writes:
>
>    One can easily implement one's own routine to convert a stack based
>    tags list into an array pointer tags list using VAR ARGS.  For
>    example, the implementation of SystemTags() would be:
>
>	#include <stdio.h>
>	#include <stdarg.h>
>
>	long
>	SystemTags(cmd, ...)
>	char *cmd;
>	{
>	    va_list va;
>	    long error;
>
>	    va_start(va, cmd);
>	    error = System(cmd, va);
>	    va_end(va);
>	    return(error);
>	}
>
>
>				    -Matt
>

Although I haven't yet tried it, this routine should work for any Tag
based system call:

#include <stdio.h>               
#include <stdarg.h>              
                                 
long CallTags(long (*cmd)(), ...)
{                                
        va_list va;              
                                 
        long error;              
                                 
        va_start(va, cmd);       
        error = cmd(va);         
        va_end(va);              
                                 
        return(error);           
}

For example: CallTags(System,argv[1],SYS_Input,infile,SYS_Output,outfile,
                      SYS_Asynch,FALSE,TAG_DONE);

-Dan

--
 ___________________________________________________________________________
|  _______                         |________________________________________|
| ||    |o|     Dan Zenchelsky     |                                        |
| ||____| |                        |    Any sufficiently advanced bug is    |
| |  ___  |  dzenc@gnu.ai.mit.edu  |    indistinguishable from a feature.   |
| |_|___|_|                        |______________-- Rich Kulawiec__________|
|__________________________________|________________________________________|

K17CC@CUNYVM (11/16/90)

Sorry about using the reply command to ask a question, but I am kind of new to
this and don't know how to use very well.
Anyway, I just got DICE from the net and It works admirably well.  I am having
a problem with making the executables (dcc, dcpp,...) resident.  It just does n
ot work.  I used both the resi command from Wshell and the resident command fro
m Arp1.3.  Even though they appear on the resident list, dcc will not run them.
  Dcc will not even run itself from the resident list.  Is this a bug or am i d
oing something wrong?
thanks
Michel cole

P.S. I have heard that a new version of DICE is out. Have you posted it yet to
a site?  BTW I am a college student majoring in Comp. sci.  Thanks to you, I no
w have a very decent compiler wich allows me to work on my projects at home.  I
 truly appreciate your efforts and will register very soon.
michel cole
k17cc@cunyvm.cuny.edu