#!../src/tops  -s ../sys  -u ../usr  -in1 -in2 -in2
#!/usr/local/bin/tops -in1 -in2 -in2

{ Notes: 

     1. To see argvs from command line and #! line, invoke this 
        script with something like: myprog -out1 -out2

     2. To test running in background, try: 

           nohup myprog -o1 -o2; vi nohup.out

        to look at output in file nohup.out.
}

   " This is myprog." nl . nl

   " These are the ARGV args:" nl . nl
   ARGV 5 indent . nl
 
   " Here is the underscore env variable: " nl . '_' env any? 
   IF . nl ELSE "it is not defined" . nl THEN nl

\  Showing syspath and usrpath environment variables:

   sp "TOPS_SYSPATH" dup . ": " . env . nl
   sp "TOPS_USRPATH" dup . ": " . env . nl

   no catmsg
   inline: you_there? (qS --- ) 
      dup exists? IF " Yes " ELSE " No " THEN swap cat . nl
   end

   nl
\  See who is here:

   "ureset" you_there?
   "file" you_there?
   "console" you_there?
   "hash_make" you_there?
   "ALARM" you_there?
   "fft" you_there?

   catnames rows nl .i " words in catalog:" . 
   fence_at .i " native, and" .
   catnames rows fence_at less .i " defined" . nl nl
   

   " Memory for cataloged stack items (ctype: DEFN, INLI, MATR, STRI," 
      . nl
   "    VARI, VOLU) is" .
   memcat MILLION star, dup (mem) .i " bytes" . nl nl

   " Average bytes per cataloged stack item is" .
   (mem) catnames rows slash .i nl nl

   halt

\-----------------------------------------------------------------------

How argv works, using debug print in main.c.

Things noted when comparing behavior from command line vs. from script:
   1. For command line and script, argv[0] is the program being run.
   2. For a script, there are only three args.  The second one, argv[1],
      holds the entire remainder of the #! line.
   3. For a script, the last argv, argv[2], is the name of the script 
      file.
   4. For a script, with no additional words on the #! line, the script
      file name would be argv[1], and the program works ok when the file
      to be sourced is argv[1].  But not allowing additional words on 
      #! means no command line style args can be defined in scripts.

Based on 4 above, the file to be sourced by tops will be the LAST argv,
not the first.  Then full use of argvs can be made with scripts or com-
mand line.

Function setargs() in main.c fills an array with each blank delimited 
word in the phrase of args, as the ARGV display below demonstrates for 
both command line and script cases.

In the case of a script, the last ARGV generated by setargs() will be
the file name, so tops will run it.

In the case of a command, the last ARGV may be a file.  If it is not 
a file, then key.v is sourced for an interactive session.  That is 
the case below, because -e, the last ARGV, is not a file.  

[Temporarily something obviously not a path or a file, like -e, must be 
the last argument because word file? cannot differentiate a file from a
path.]


For this alias:

alias tops='/opt/tops-2.4.1/opn/tops -s /opt/tops-2.4.1/sys -u /opt/mytops/usr -e > /dev/null'

here is argv running from the command line:

[dale@clacker] /home/dale > tops
 args = 6
 argv[0]: /opt/tops-2.4.1/opn/tops
 argv[1]: -s
 argv[2]: /opt/tops-2.4.1/sys
 argv[3]: -u
 argv[4]: /opt/mytops/usr
 argv[5]: -e
          Tops 2.4.1
Tue Jan 15 21:58:06 PST 2002
[tops@clacker] ready > " ARGV:" . nl ARGV 5 indent . 
 ARGV:
     /opt/tops-2.4.1/opn/tops
     -s
     /opt/tops-2.4.1/sys
     -u
     /opt/mytops/usr
     -e                         <<< -e is not a file, so source key.v
[tops@clacker] ready > 


Here is argv running from a script like this one:

[dale@clacker] /opt/tops-2.4.1/usr > myprog
 args = 3
 argv[0]: /opt/tops-2.4.1/opn/tops
 argv[1]: -argv stuff here and here
 argv[2]: ./myprog 
 argv[3]: (null)
 argv[4]: PWD=/opt/tops-2.4.1/usr
 argv[5]: COLORFGBG=15;default;0

 ARGV:
     /opt/tops-2.4.1/opn/tops
     -argv
     stuff
     here
     and
     here
     ./myprog              <<< this is a file, so it is sourced

[dale@clacker] /opt/tops-2.4.1/usr > 


Nothing is a slam-dunk.  Here's a new wrinkle when there are command
line arguments for a script file:

This is the first line of the script file:
#!/opt/tops-2.4.1/opn/tops 100 400

Running the script with command line arguments:
[dale@clacker] /home/dale > shoot m n o
 argv[0]=/opt/tops-2.4.1/opn/tops
 argv[1]=100 400
 argv[2]=./shoot
 argv[3]=m
 argv[4]=n
 argv[5]=o
 argv[6]=(null)

The command line arguments, m, n, o,  get tacked on the end, so the 
script file name (./shoot) is not last.

In fact, the script file name will always be the second or third argv
(second if nothing else on #! line).






