#!/usr/local/bin/tops -i -s /usr/local/tops/sys -u /opt/mytops/usr/
/* GNU General Public License

Program Tops - a stack-based computing environment
Copyright (C) 1999-2006  Dale R. Williamson

Author: Dale R. Williamson <dale.williamson@prodigy.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

----------------------------------------------------------------------*/

# File: Xserver  January 2006
# Copyright (C) 2006  D. R. Williamson

# Start a tops Xserver.

# Default PORT is 9870 if not set by command line switch -port:
   (PORT,f) = (9870,number(argv("-port")));

# Vector output to log file /tmp/XserverPORT.log:
   set_sysout("/tmp" + "/Xserver" + intstr(PORT) + ".log");

# Write the first lines in the log file:
   nl(dot(nl,cats("-",72)));
   nl(dot("PID " + spaced(intstr(getpid)) + date));

# Command line switch -wtrace gives wtrace output, a moderate amount 
# of tracing for window and network events:
   if(argv("-wtrace")!="") wtrace();

# Command line switch -ntrace gives detailed network trace output that 
# includes wtrace; the log file will grow rapidly:
   if(argv("-ntrace")!="") ntrace();

# Source Xserver words in file server.v:
   msource(catmsg(yes),"server.v","Xserver Words");
   Xserver.daemon=yes; 
   Xserver.SSL=yes;       # SSL option
   XclientConnect.WSEC=20;# time for Xhost node to start
/*
  Function CONN() created next will connect this run to an instance of 
  tops listening on port 9877.  From that server we can later remote-
  prompt to this Xserver and run interactive commands for maintenance 
  or debugging: */
function CONN() 
{ 
   if(port_listening((P=9877))) # if 9877 is a listening port, then
      CLIENT(IPloop,P);         # connect as a tops client
}
# An alarm is used to run CONN() after the Xserver daemon has started:
   ALARM(5,"CONN"); # delay connecting until after daemon starts

# Start the Xserver daemon listening on PORT:
   Xserver(PORT);

/*----------------------------------------------------------------------

For connecting with remoteprompt and running interactive commands on 
this Xserver, see notes in script usr/telserver.

----------------------------------------------------------------------*/
