/*
 * This file is part of some an snmpquery application.
 * This is the main file... head honcho... big cheese...
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 *
 * Tom Coppeto
 * MIT Network Services
 * 15 April 1990
 *
 *    $Source: /afs/net.mit.edu/tools/src/simon/RCS/main.c,v $
 *    $Author: tom $
 *    $Locker:  $
 *    $Log:	main.c,v $
 * Revision 1.5  90/07/25  10:30:18  tom
 * attempts to read in cluster definitions upon startup
 * 
 * Revision 1.4  90/07/20  23:29:16  tom
 * *** empty log message ***
 * 
 * Revision 1.3  90/07/20  22:51:19  tom
 * print header
 * 
 * Revision 1.2  90/07/20  22:17:19  tom
 * quiet on startup
 * 
 * Revision 1.1  90/07/20  21:17:36  tom
 * Initial revision
 * 
 *
 */

#ifndef lint
static char *rcsid = "$Header: /afs/net.mit.edu/tools/src/simon/RCS/main.c,v 1.5 90/07/25 10:30:18 tom Exp $";
#endif


#include <ss/ss.h>
#include <signal.h>
#include <simon.h>
#include <mit-copyright.h>

char *argptr[100];
char cmdbuf[BUF_SIZE];
char *pname;

extern ss_request_table PROC_TABLE;
static int sci_idx;


main(argc, argv)
     int argc;
     char **argv;
{
  char  *initial_request[100];
  int   num_reqs = 0;
  int   code;
  int   i;

  while (++argv, --argc) 
    {
      if (!strcmp(*argv, "-request") || !strcmp(*argv, "-rq")) 
	{
	  if (argc == 1) 
	    {
	      (void) fprintf(stderr, "No string supplied with -request.\n");
	      exit(1);
	    }
	  argc--; argv++;
	  initial_request[num_reqs] = *argv;
	  ++num_reqs;
	}

      if(!strcmp(*argv, "-file"))
	{
	  if(argc == 1)
	    {
	      (void) fprintf(stderr, "No filename specified with -file.\n");
	      exit(1);
	    }
	  argc--; argv++;
/*	  execute_file(*argv, sci_idx);*/
	}
    }


  bzero(&stuff, sizeof(stuff));
  read_vardefs(DFLT_VARDEFS);
  read_agentdefs(DFLT_AGDEFS);
  cmd_reset_parameters(0,0);

  sci_idx = ss_create_invocation("simon", VERSION_STRING,
				 (char *) NULL, &PROC_TABLE, &code);
  if (code) 
    {
      (void) fprintf(stderr,"%s: error creating ss invocation.\n");
      exit(1);
    }
  
  (void) ss_add_info_dir(sci_idx, INFO_DIR, &code);
  if (code) 
    ss_perror(sci_idx, code, INFO_DIR);

  for(i=0; i < num_reqs; i++)
    {
      (void) ss_execute_line(sci_idx, initial_request[i], &code);
      if (code != 0)
	ss_perror(sci_idx, code, initial_request[i]);
    }
  if(num_reqs > 0)
    exit(0);

  printf("SNMP query program (%s).\n\n", VERSION_STRING);
  (void) ss_listen(sci_idx);
  return(0);
}



