


/*--------------------------------------------------
 * File: print-ids.cc
 *
 * Description:
 * Prints all identifiers found in a test suite.
 *
 */



#include		<stdio.h>
#include		<strings.h> // For strcmp et al
#include		<time.h>
#include		<access.hh>


/* Declarations */
void init_application();
void printids_pre_Identifier( const Identifier& Myself );



/* Definitions */

int main(int argc, char **argv)
{
  AccessSuite suite;
  char *argv0 = argv[0];
  char *asn1modulelistfile = NULL;

  /* Switches. */
  if ( argc > 2 && strcmp(argv[1], "-A") == 0 )
    {
      argc -= 2;
      argv += 2;
      asn1modulelistfile = argv[0];
    }

  /* Soundness of arguments. */
  if ( argc < 2 )
    {
      fprintf( stderr, "Usage: %s [-A listfile] suitename {id}\n", argv0 );
      return 1;
    }

  if ( ! suite->open( argv[1], asn1modulelistfile ) )
    {
      fprintf( stderr, "Initiator failed!\n" );
      return 1;
    }

  /* initialise the user defined pre post functions */
  init_application();


  if ( argc == 2 )
    {
      suite->trav_root();
    }
  else
    for ( int i = 2 ; i < argc ; i++ )
      {
	if ( ! suite->trav_reference( argv[i] ))
	  fprintf( stderr, "%s could not be found.\n",
		   argv[i] );
      }
  
  fprintf( stdout, "DONE!\n" );
  
  suite->close();
  
  return 0;
}


void printids_pre_Identifier( const Identifier& Myself )
{
  fprintf( stdout, "Identifier: '%s'\n", (const char*) Myself );
}


void init_application()
{
  pre_Identifier = printids_pre_Identifier;
}
