static char *SccsId = "@(#)getcmd.c 4.5 (TU-Delft) 06/30/93";
/**********************************************************

Name/Version      : sls/4.5

Language          : C
Operating system  : UNIX SYSTEM V
Host machine      : HP9000

Author(s)         : A.C. de Graaf, A.J. van Genderen
Creation date     : 10-Jul-1986
Modified by       : S. de Graaf
Modification date : 10-Jul-1986


        Delft University of Technology
        Department of Electrical Engineering
        Network Theory Section
        Mekelweg 4 - P.O.Box 5031
        2600 GA DELFT
        The Netherlands

        Phone : 015 - 786234

        COPYRIGHT (C) 1986 , All rights reserved
**********************************************************/
#include "extern.h"

extern  FILE * yy0in;
extern  int yy0lineno;
extern  int try_sta_file;

getcommands () {
    DM_STREAM * dsp_cmd;
    char fn_stat[40];
    char *fn_save;
    struct stat sbuf;

    if (monitoring) {
	monitime ("B getcommands");
    }

    cmdinits ();

    if (use_io_views) {
	dsp_cmd = dmOpenStream (stimuli_key, "cmd", "r");
	yy0in = dsp_cmd -> dmfp;
    }
    else
	OPENR (yy0in, fn_cmd);

    yy0parse ();

    if (use_io_views) {
	dmCloseStream (dsp_cmd, COMPLETE);
	yy0in = NULL;
    }
    else
	CLOSE (yy0in);

    if (try_sta_file) {
	sprintf (fn_stat, "%s.sta", netwname);
	/* Look if a file is present that contains state definitions */
	if (stat (fn_stat, &sbuf) == 0) {

	    fn_save = fn_cmd;
	    fn_cmd = fn_stat;
	    OPENR (yy0in, fn_cmd);

            /* this function re-initializes the lex scanner: */
            restart_scanner(yy0in);

	    yy0parse ();

	    CLOSE (yy0in);
	    fn_cmd = fn_save;
	}
    }

    if (fatalerror)
        die (1);

    if (monitoring) {
	monitime ("E getcommands");
    }
}
