%  BAISLEY$PAPERS:CCNOTES.TeX
%
%  This file is the preliminary version of the session notes for a talk 
%  given at the Fall '86 DECUS in San Francisco by Wayne E. Baisley, 
%  Rockwell International / Graphic Systems Division, Lombard, Illinois.
%
%  This file, when run through LaTeX, will be formatted as described below.
%  It uses the macro package DEPROC.TeX plus a few locally defined macros,
%  all of which are given at the top of the file.
%
%  Wayne E. Baisley
%  Rockwell International / Graphic Systems Division
%  455 Eisenhower Lane
%  Lombard, Illinois  60148-5410
%
%
%  WARNING!  DO NOT TYPE ANY OF THE FOLLOWING 10 CHARACTERS EXCEPT AS DIRECTED:
%                &   $   #   %   _   {   }   ^   ~   \   

\magnification=1200
%\input deproc

%\SpeechFormat
\hoffset=-.25truein
%\voffset=-1.2truein
\hsize=7truein
%\vsize=8.75truein

%	macros needed for this article

\font\twlvbf=cmbx12
\font\twlvrm=cmr12
\font\big=cmr17
\font\btt=cmss12
\font\bigtt=cmss17
%\def\GSD{Rockwell~International / Graphic~Systems~Division}
%\def\Proc{Proceedings}
%\def\DP{{\tt DEPROC}}
%\def\DProc{{\sl DECUS \Proc}}
%\def\POBox{P.\thinspace O.~Box }
%\def\TB{{\sl The \TeX book}}
%\def\TUB{TUGboat}
%\def\TUG{\TeX\ Users Group}
\def\vax{\leavevmode\hbox{\btt V\kern-.4em A\kern-.15em X}}
\def\vaxc{\leavevmode\hbox{\btt V\kern-.4em A\kern-.15em X ~C}}
\def\VAX{\leavevmode\hbox{\bigtt V\kern-.4em A\kern-.15em X}}
\def\VAXC{\leavevmode\hbox{\bigtt V\kern-.4em A\kern-.15em X ~C}}
\def\system{\leavevmode\hbox{\bigtt system}}

\def\\{\hfil\break}

%\def\<#1>{$\langle${#1}$\rangle$}
%\def\cs{\<cs>}
%\def\css{\cs es}
%\def\cs{{\tt cs}}
%\def\css{\cs-es}
%\def\CR{\<\smc cr>}
%\def\tab{\<\smc tab>}
%\def\ttvert{{\tt\char'174 }\ignorespaces}

\def\headme#1{\vbox{\hbox{\kern5pt#1\kern5pt}\hrule}\vskip .5truein}
\def\boxit#1{\vbox{\hrule\hbox{\vrule\kern5pt\vbox{\kern5pt#1\kern5pt}\kern5pt\vrule}\hrule}}
%\setbox4=\vbox{\hsize 2.5truein \noindent \strut

%\title{Filling Some Holes In The \VAXC\ Run-Time Library ---
%    The ``\system'' function and related support routines}
%\author{Wayne~E.~Baisley\\
%    \GSD\\
%    Lombard,~Illinois}

\big
%\begin{document}

\footline={\twlvrm\hss Filling Some Holes In \vaxc\ RTL \hfil\folio\hfil\btt L \& T \twlvrm - October 1986\hss}
\baselineskip=25pt plus 1.5pt
\vskip 1truein
%\maketitle

\centerline {Filling Some Holes In The \VAXC\ Run-Time Library ---}

\vskip .5truein

\centerline {The \system\ function and related support routines}
\vskip 1truein

\centerline {Wayne E. Baisley}
\centerline {Rockwell International}
\centerline {Graphic Systems Division}
\centerline {Lombard, Illinois}
\vfill\hrule\eject
\headme{UNIX${^{\dag}}$ is the source of many useful programs and ideas}
%\hrule


%\vskip 1truein
\itemitem{--}		Make
\itemitem{--}		Source Code Control System - SCCS
\itemitem{--}		The Shells
\itemitem{--}		Pipes
\itemitem{--}		Grep, Who, and other utilities
\itemitem{--}		And, of course, the {\hbox{\bigtt C}} language
\vskip 4.5truein
\footnoterule
\line{\tenrm ${^{\dag}}$ \twlvrm UNIX is a trademark of AT\&T Bell Laboratories\hfil}



\vfill\hrule\eject
\headme{VMS is flexible enough to capitalize on, \\
or at least to accommodate, UNIX ideas}
%\hrule



%\vskip 1truein
\itemitem{--}		Module Management System - MMS
\itemitem{--}		Code Management System - CMS
\itemitem{--}		DEC/Shell, with pipes
\itemitem{--}		Grep, Who, and other utilities
\itemitem{--}		\VAXC\
\itemitem{--}		The \VAXC\ Run-Time Library


\vfill\hrule\eject
\headme{Therefore, I conclude that}
%\hrule




%\vskip 1truein
\centerline{VMS can do anything UNIX can do better}



\vfill\hrule\eject
\headme{The \VAXC\ Run-Time Library provides most of the useful\\
UNIX {\hbox{\bigtt C}} features}
%\hrule




%\vskip 1truein

\itemitem{--}		The string functions
\itemitem{--}		The standard I/O functions
\itemitem{--}		The UNIX I/O functions
\itemitem{--}		The curses windowing functions
\itemitem{--}		Many others
\vskip 25pt
\itemitem{--}		Not to mention unique VMS features




\vfill\hrule\eject
\headme{The \VAXC\ Run-Time Library omits at least one of\\
the commonly-used UNIX {\hbox{\bigtt C}} features}
%\hrule
%\vskip 1truein



\centerline{The \system\ function ---}
\vskip 1truein
\item{}		a means of ``easily'' passing a command to the Command
Line Interpreter (CLI).  For example,
\vskip 1truein

\itemitem{}	status = system (``\hbox{\btt A COMMAND I WANT DONE}'');

\vfill\hrule\eject
\headme{The \system\ function provides a very useful service}
%\hrule
%\vskip 1truein



		We first used \system\ on \hbox{\btt RSX-11M} to integrate separate 
C compiler components.  A single 
command could then be issued -
\itemitem{}		\$ pcc -fps xyz.c
\vskip .5truein
\line{- to produce a sequence of CLI commands - \hfill}
\vskip .5truein
\itemitem{}	pcc$>$ cpp -xi qr:[301,376] -o xyz.tm1 $>$xyz.er0 xyz.c
\itemitem{}	pcc$>$ del xyz.er0;*
\itemitem{}	pcc$>$ cp1 -o xyz.tm2 $>$xyz.er1 xyz.tm1
\itemitem{} $\vdots$
\itemitem{}	pcc$>$ del xyz.tm4;*
\vskip .5truein\\
- thereby integrating the components in a
straightforward and ``portable'' manner.

\vfill\hrule\eject
\headme{We had to reinvent the \system\ function for VMS}
%\hrule



	Later, we began using a \VAX\ for RSX development, 
and had to reinvent the \system\ function

\vskip 1truein

	The \hbox{\btt LIB\$SPAWN} routine in the VMS Run-Time Library can
be used to do nearly all that \system\ requires.  It
creates a subprocess, copies logical names and DCL 
symbols, et cetera.
\vskip 1truein
$$\boxit{\vbox{\hsize 2.5truein \vsize 1.5truein \noindent \strut Process
\vskip .5truein system (``\hbox{\btt TIME}'')}}\hskip 1truein
\boxit{\vbox{\hsize 2.5truein \vsize 1.5truein \noindent \strut Subprocess
\vskip .5truein \$ TIME}}$$
%		   Process			  Subprocess
%		+------------+			+------------+	
%		|	     |			|	     |	
%		|   \system\   |			|   	     |	
%		|  (``\hbox{\btt TIME}''); +-----------------$>$|  \$ \hbox{\btt TIME}    |	
%		|	     |			|	     |	
%		|	     |			|	     |	
%		+------------+			+------------+	
\vfill\hrule\eject
\headme{And then performance was improved greatly}
%\hrule
%\vskip 1truein

%Making \system\ perform ``well'' on VMS required some effort
%\vskip 1truein

	By creating a subprocess once and reusing it
as a ``server'' for DCL commands.
\vskip 1truein

	Mailboxes are used to feed commands to the ``server''
and to retrieve output and status information.
\vskip 1truein
$$\boxit{\vbox{\hsize 2.5truein \vsize 1.5truein \noindent \strut Process
\vskip .5truein \system\ calls}}\hskip 1truein
\boxit{\vbox{\hsize 2.5truein \vsize 1.5truein \noindent \strut Subprocess
\vskip .5truein DCL Server}}$$
{\obeylines\obeyspaces
%		   Process			  Subprocess
%		+------------+			+------------+	
%		|	     |	   Commands	|	     |	
%		|  	     +-----------------$>$|   	     |	
%		|  \system\  |			|    DCL     |	
%		|   calls    |<-----------------+   Server   |	
%		|	     |	Output, Status 	|	     |	
%		+------------+			+------------+	
}
\vfill\hrule\eject
\headme{The implementation of \system\ on VMS was complicated,\\
though straightforward}
%\hrule
%\vskip 1truein


	Many factors contributed to the difficulty
\vskip 1truein

\itemitem{--}		Creating mailboxes
\itemitem{--}		Passing arguments by descriptor
\itemitem{--}		Obtaining the image exit status
\itemitem{--}		Handling unexpected subprocess termination
\itemitem{--}		Handling \^{}Y and \^{}C aborts
\itemitem{--}		Cleaning up on exit


\vfill\hrule\eject
\headme{The \system\ function serves as a useful example}
%\hrule
%\vskip 1truein



\itemitem{--}	How to use \hbox{\btt LIB\$SPAWN}
\itemitem{--}	Calling VMS System Services from C
\itemitem{--}	Using descriptors in C
\itemitem{--}	Writing AST service routines
\itemitem{--}	Writing exit handlers
\itemitem{--}	Using the VMS Message facility
\itemitem{--}	How VMS can be difficult for programming

\vfill\hrule\eject
\headme{Other related functions were developed along with \system}
%\hrule
%\vskip 1truein



\itemitem{--}	cimageid	- returns the name of the currently 
executing image as a string
\vskip .5truein
\itemitem{--}	complain	- a simple way to produce VMS-style
error messages
\vskip .5truein
\itemitem{--}	crembx		- create a mailbox

\vskip .5truein
\itemitem{--}	chain		- execute a single DCL command and
exit (uses \hbox{\btt LIB\$DO\_COMMAND})


\vfill\hrule\eject
\headme{Now it's my turn to grouse about UNIX C}
%\hrule
%\vskip 1truein



		The string functions
\vskip .5truein

\itemitem{--}	strcat		- concatenate two strings
\itemitem{--}	strcpy		- copy a string
\vskip .5truein

\line{and their bounded counterparts\hfill}
\vskip .5truein

\itemitem{--}	strncat		- concatenate up to `n' characters
\itemitem{--}	strncpy		- copy up to `n' characters
\vskip .5truein\\
return the address of the beginning of the output 
string.  The ending address is far more useful.

\vfill\hrule\eject
\headme{So some new string functions were invented}
%\hrule
%\vskip 1truein

\vskip .5truein

\itemitem{--}	strzcat		- concatenate two strings
\itemitem{--}	strzcpy		- copy a string
%\vskip 1truein
\vskip .5truein

\line{and their bounded counterparts\hfill}
%\vskip 1truein
\vskip .5truein

\itemitem{--}	strxcat		- concatenate up to `n' characters
\itemitem{--}	strxcpy		- copy up to `n' characters
%\vskip 1truein
\vskip .5truein

	These functions perform exactly as the standard versions 
but return the address of the terminating \hbox{\btt NUL} byte.

\vfill\hrule\eject
\headme{These new functions make constructing a string so easy $\ldots$}
%\hrule
%\vskip 1truein



	An example from PCC (the output of which is 
passed to \system)
\vskip 1truein

\itemitem{}	cp = strzcpy (\&cmdbuf, ``cpp -xo'');
\itemitem{}	cp = strzcpy (cp, outname);
\itemitem{}	cp = strzcpy (cp, ``.tm1'');
\itemitem{}	$\vdots$


\vfill\hrule\eject
\headme{So once again I conclude that}
%\hrule
%\vskip 1truein




\centerline{VMS can do anything UNIX can do better}




\vfill\hrule\eject
\headme{Future enhancements which I am unlikely to make}
%\hrule




\itemitem{--}	The popen (and pclose) function, which could be
		implemented as a variation of the \system\ function

\vskip 1truein

\itemitem{--}	Any number of esoteric UNIX functions which the\\
		\VAXC\ developers weren't interested in either

\vfill\hrule\eject
\headme{DECUS has it now}
%\hrule
%\vskip 1truein



	This software is available on the Symposium 
Languages and Tools tape, in the directories
[\hbox{\btt RIGS.CCLIB} . . . ].
\vskip 1truein

\itemitem{--}		Sources
\itemitem{--}		Command and MMS Procedures
\itemitem{--}		Object Library
\itemitem{--}		Documentation

	
\vfill\hrule\eject
%\headme{Questions ?}
%\hrule
%\vskip 1truein
%
%
%	Where'd you get such a stupid idea ?
%
\end
