#module    GloCmd    "1-001"
/*
 ***********************************************************************
 *                                                                     *
 * The software was developed at the Monsanto Company and is provided  *
 * "as-is".  Monsanto Company and the auther disclaim all warranties   *
 * on the software, including without limitation, all implied warran-  *
 * ties or merchantabilitiy and fitness.                               *
 *                                                                     *
 * This software does not contain any technical data or information    *
 * that is proprietary in nature.  It may be copied, modified, and     *
 * distributed on a non-profit basis and with the inclusion of this    *
 * notice.                                                             *
 *                                                                     *
 ***********************************************************************
 */

/*+
 * Module Name:	GloCmd
 *
 * Author:	R L Aurbach	CR&DS MIS Group    18-Aug-1986
 *
 * Function:
 *	This routine parses the GloTeX Command Line, and returns the name of
 *	the input file, a flag which specifies the style of treatment for the
 *	output file, and optionally, a list of files for the glossary definition
 *	file.
 *
 * Modification History:
 *
 * Version     Initials	   Date		Description
 * ------------------------------------------------------------------------
 * 1-001	RLA	18-Aug-1986	Original Code
-*/

/*
 * Module GloCmd - Module-Wide Data Description Section
 *
 * Include Files:
 */
#include	descrip
#include	"GloDef.H"

/*
 * Module Definitions:
 */

/*
 * Global Declarations:
 */

/*
 * Static Declarations:
 */
    static $DESCRIPTOR		    (prefix, "GloTeX ");
    static struct dsc$descriptor    command_line = STRDYN;
    static struct dsc$descriptor    temp	 = STRDYN;
    static struct dsc$descriptor    str_dyn	 = STRDYN;
    static $DESCRIPTOR		    (p1, "File");
    static $DESCRIPTOR		    (style, "STYLE");
    static $DESCRIPTOR		    (glossary, "GLOSSARY");

/*
 * External References:
 */
    globalref int		    glotbl;
    globalref int		    lib$get_input;
    globalref int		    lib$sig_to_stop;

    extern STRING_PTR		    filelist;
    extern int			    flag;
    extern char			    infile[256];

/*
 * Functions Called:
 */
    int				    lib$get_foreign();
    int				    cli$dcl_parse();
    int				    str$prefix();
    int				    lib$establish();

/*+
 * Function Glo_Command - Documentation Section
 *
 * Discussion:
 *	This routine uses lib$get_foreign to read the command line.  It
 *	prefixes the command line with "GloTeX ", so that the CLI routines
 *	will have the appropriate information on which to operate. It then
 *	parses the command line and returns the appropriate information to the
 *	program.
 *
 *	Since the routine establishes LIB$SIG_TO_STOP as a condition handler,
 *	syntax errors detected during processing result in program exit.  
 *
 * Calling Synopsis:
 *	Call Glo_Command ()
 *
 * Inputs:
 *	none
 *
 * Outputs:
 *	none
 *
 * Return Value:
 *	none
 *
 * Global Data:
 *	infile	    ->	contains the name of the input file as an ASCIZ string.
 *
 *	flag	    ->	indicates the value of the /STYLE qualifier.
 *
 *	filelist    ->	is updated to contain a list of file specifications.
 *
 * Files Used:
 *	none
 *
 * Assumed Entry State:
 *	GloTeX is invoked as a foreign DCL command.
 *
 * Normal Exit State:
 *	The routine returns to the caller.  The global variables are set up
 *	appropriately.
 *
 * Error Conditions:
 *	For the majority of the processing of the routine, LIB$SIG_TO_STOP
 *	is established as the condition handler.  Therefore, any errors cause
 *	an immediate exit.  

 *
 * Algorithm:
 *	A. Call Lib$Get_Foreign to retrieve the command line.
 *	B. Prefix the command line with the command verb.
 *	C. Call Cli$DCL_Parse to parse the command line.
 *	D. Process the file name.
 *	    1. Get the file name.
 *	    2. Convert it to an ASCIZ string.
 *	E. Process the /STYLE qualifier.
 *	F. Process the /GLOSSARY qualifier.
 *
 * Special Notes:
 *	This routine is based on the LIB_PARSE_FOREIGN routine, suitably 
 *	modified.
-*/

/*
 * Function Glo_Command - Code Section
 */

void	Glo_Command ()
{
/*
 * Local Declarations
 */
    int		status;
    STRING_PTR	file;
    STRING_PTR	old;
/*
 * Module Body
 */

lib$establish(&lib$sig_to_stop);

/* Get the command line							    */

status = lib$get_foreign(&command_line);
if (!(status & TRUE))	    lib$signal(status);

str$prefix(&command_line, &prefix);

/* Parse the command line						    */

cli$dcl_parse(&command_line, &glotbl, &lib$get_input);

/* Get the filename string						    */

cli$get_value(&p1, &temp);
strncpy(infile, temp.dsc$a_pointer, temp.dsc$w_length);
infile[temp.dsc$w_length] = '\0';

/* Process the /STYLE qualifier						    */

flag = NONE;
if (cli$present(&style) & TRUE)
    {
    cli$get_value(&style, &temp);
    if (temp.dsc$a_pointer[0] == 'A')  flag = ARTICLE;
    if (temp.dsc$a_pointer[0] == 'R')  flag = REPORT;
    }


/* Process the /GLOSSARY qualifier					    */

if (cli$present(&glossary) & TRUE)
    {
    while (TRUE)
	{
	file = (STRING_PTR) malloc (sizeof(STRING));
	if (file == 0)	break;
	file->next = 0;
	file->desc = str_dyn;
	status = cli$get_value(&glossary, &file->desc);
	if (!(status & TRUE))	return;
	old = filelist;
	if (filelist == 0)
	    {
	    filelist = file;
	    }
	else
	    {
	    while (old->next != 0)	old = old->next;
	    old->next = file;
	    }
	}
    }
}
