/*
** opt.c
** 
** Started on  Fri Nov  2 15:17:02 2001 mayhem
** Last update Sun Mar 24 13:26:42 2002 mayhem
*/
#include "elfsh.h"




/*
** getopt sucks
*/
void		get_options(int argc, char **argv, argv_t *cmdarg)
{
  int		index;

  bzero(cmdarg, sizeof(argv_t));

  for (index = 1; index < argc; index++)
    {
      if (!strcmp(ELF, argv[index]) || !strcmp(ELF2, argv[index]))
	cmdarg->elf = 1;
      else if (!strcmp(PHT, argv[index]) || !strcmp(PHT2, argv[index]))
	cmdarg->pht = 1;
      else if (!strcmp(INTERP, argv[index]) || !strcmp(INTERP2, argv[index]))
	cmdarg->interp = 1;
      else if (!strcmp(GOT, argv[index]) || !strcmp(GOT2, argv[index]))
	GETOPT(cmdarg->got);
      else if (!strcmp(CTORS, argv[index]) || !strcmp(CTORS2, argv[index]))
	GETOPT(cmdarg->ctors);
      else if (!strcmp(DTORS, argv[index]) || !strcmp(DTORS2, argv[index]))
	GETOPT(cmdarg->dtors);
      else if (!strcmp(NOTE, argv[index]) || !strcmp(NOTE2, argv[index]))
	GETOPT(cmdarg->notes);
      else if (!strcmp(SYM, argv[index]) || !strcmp(SYM2, argv[index]))
	GETOPT(cmdarg->sym);
      else if (!strcmp(DYNAMIC, argv[index]) || !strcmp(DYNAMIC2, argv[index]))
	GETOPT(cmdarg->dyn);
      else if (!strcmp(DYNSYM, argv[index]) || !strcmp(DYNSYM2, argv[index]))
	GETOPT(cmdarg->dynsym);
      else if (!strcmp(SHT, argv[index]) || !strcmp(SHT2, argv[index]))
	GETOPT(cmdarg->sht);
      else if (!strcmp(STAB, argv[index]) || !strcmp(STAB2, argv[index]))
	GETOPT(cmdarg->stab);
      else if (!strcmp(REL, argv[index]) || !strcmp(REL2, argv[index]))
	GETOPT(cmdarg->rel);
      else if (!strcmp(HEXA, argv[index]) || !strcmp(HEXA2, argv[index]))
	ADD_HEXA_ENTRY();
      else if (!strcmp(DISASM, argv[index]) || !strcmp(DISASM2, argv[index]))
	ADD_DISASM_ENTRY();
      else if (!strcmp(SORT, argv[index]) || !strcmp(SORT2, argv[index]))
	GETOPTION(cmdarg->sort);
      else if (!strcmp(BINFILE, argv[index]))
        GETOPTION(cmdarg->filename);
      else if (!strcmp(ALL, argv[index]) || !strcmp(ALL2, argv[index]))
	GETALLOPT();
      else 
	usage(argv[0]);
    }

  
  if ((argc != 1 && cmdarg->filename == NULL) || (argc == 3 && cmdarg->filename))
    usage(argv[0]);

  else if (argc == 1)
    imode();
  
}

