/************************************************************************/
/*	Routing Protocol Simulator	Relese 1.0	1994/3/17	*/
/*									*/
/*		module 	: main routine				       	*/
/*		file	: rps_main.c				        */
/*									*/
/*   Copyright (c) 1994 by Systems Development Laboratory Hitachi,Ltd.	*/
/*   All rights reserved.						*/
/*----------------------------------------------------------------------*/
/*	UPDATE HISTORY							*/
/*									*/
/************************************************************************/
static char copyright[]=
  "@(#)Copyright (c) 1994 by Systems Development Laboratory Hitachi,Ltd.\n All rights researved.\n";

static char version[]=  "Routing Protocol Simulator  Version 1.1.0";

#ifdef VXWORKS

#include "stdioLib.h"
#include "rps_token.h"
#include "netDrv.h"
#include "hostLib.h"
#include "strLib.h"

#else

#include <stdio.h>
#include "rps_token.h"

#endif

void usage();
void print_copyright();

char cmd_file[64];


int used_memory = 0;

#ifndef VXWORKS

main(argc,argv)
int argc;
char **argv;

#else

rps_task(file)
char *file;

#endif
{
    int rt;
    int cmd;
    FILE *fp;
    int line;
    char tmparg[64],command[64];
	
#ifndef VXWORKS

    if(argc < 2) {
	printf("no argument\n");
	usage();
	exit(1);

    }
    strcpy(cmd_file,argv[1]);

#else
/*
     netDevCreate (argv[1], argv[1], 0);

    strcpy(tmparg, argv[1]);
    strcat(tmparg, argv[2]);
*/
    strcpy(cmd_file,file);

#endif

    print_copyright();
    
    if((fp = fopen(cmd_file, "r")) == NULL) {
	printf("command sequence file open error\n");
	return -1;
    }

    time_init();
    sock_init();
	
/*    signal_init();*/

    line=1;
    used_memory = 0;
    while((cmd = get_cmd(fp,command)) != EOF) {
	if(cmd != NOCOMMAND) {
	    rt = run_command(command,fp); 
	    if(rt == T_CMD_UNKNOWN) {
		log_trace(stderr,"Unknown Command <%s> at line %d\n",command,line);
	    }
	    else if(rt == T_CMD_END) break;
	}
/*	else if(cmd == -1 || cmd == T_CMD_UNKNOWN) {
	    log_trace(stderr,"Unknown Command <%s> at line %d\n",command,line);
	}*/
	line++;
    }

    fclose(fp);

#ifdef VXWORKS
    
    printf("used memory = %d byte \n",used_memory);

#endif
    
/*    time_term();*/
    sock_term();
#ifdef VXWORKS

/*    sys_timer_delete();*/

#endif

    log_trace(stderr,"\n Finished ..\n\n");
}


void usage()
{
  fprintf(stderr,"Usage: rps cmd_file\n");
  exit(1);
}

char *get_cmd_file()
{
    return cmd_file;
}


void print_copyright()
{
    log_trace(stderr,"\n %s",version);
    log_trace(stderr,
	    "\n All Rights Reserved, Copyright(c)1994, Hitachi, Ltd.\n");

}
