示例#1
0
int main(int argc, char *argv[]) {
	int c;                          /* character for getopt processing */
	/* command argument variables */
	char *first_file = NULL;
	char *second_file = NULL;
	char *a_output_file = NULL;
	char *b_output_file = NULL;
	char *c_output_file = NULL;
	FILE *a_output_fp = NULL;
	FILE *b_output_fp = NULL;
	FILE *c_output_fp = NULL;
	int use_header = 0;
	int only_summarize = 0;

	/* internal variables */
	seqdiff_results_t *results;
	results = seqdiff_results_init();

	extern char *optarg; /* external from getopt */

	verbose_flag = 0; /* assume not verbose */
	progname = argv[0]; /* capture the program name */
	if (argc < 2) {
		show_usage(EXIT_FAILURE);
	}

	while(1) {
		static struct option long_options[] =
		{
			{"verbose",    no_argument, 0, 'v'},
			{"version",    no_argument, 0, 'V'},
			{"help",       no_argument, 0, 'h'},
			{"summary",    no_argument, 0, 's'},
			{"headers",    no_argument, 0, 'd'},
			{"first",      required_argument, 0, '1'},
			{"second",     required_argument, 0, '2'},
			{"a_output",   required_argument, 0, 'a'},
			{"b_output",   required_argument, 0, 'b'},
			{"c_output",   required_argument, 0, 'c'},
			{0, 0, 0, 0}
		};

		/* getopt_long stores the option index here. */
		int option_index = 0;

		c = getopt_long(argc, argv, "vVh?sd1:2:a:b:c:", long_options, &option_index);

		/* Detect the end of the options. */
		if (c == -1)
			break;

		switch (c) {
			case 'v':
				verbose_flag = 1;
				break;

			case 'V':
				/* version */
				printf("Version is %f\n",VERSION);
				break;

			case 'h':
				show_usage(EXIT_FAILURE);
				break;

			case '?':
				/* getopt_long already printed an error message. */
				break;

			case 's':
				only_summarize = 1;
				break;

			case 'd':
				use_header = 1;
				break;

			case '1':
				first_file = (char*) malloc(strlen(optarg)+1);
				strcpy(first_file,optarg);
				break;

			case '2':
				second_file = (char*) malloc(strlen(optarg)+1);
				strcpy(second_file,optarg);
				break;

			case 'a':
				a_output_file = (char*) malloc(strlen(optarg)+1);
				strcpy(a_output_file,optarg);
				break;

			case 'b':
				b_output_file = (char*) malloc(strlen(optarg)+1);
				strcpy(b_output_file,optarg);
				break;

			case 'c':
				c_output_file = (char*) malloc(strlen(optarg)+1);
				strcpy(c_output_file,optarg);
				break;

			default:
				abort ();
		}
	}

	/* Instead of reporting '--verbose'
	   and '--brief' as they are encountered,
	   we report the final status resulting from them. */
	if (verbose_flag) {
		fprintf(stderr, "verbose flag is set\n");
		fprintf(stderr,"First file is %s\n", first_file);
		fprintf(stderr,"Second file is %s\n", second_file);
		if (a_output_file != NULL && a_output_file != NULL && a_output_file != NULL) {
			fprintf(stderr, "Output will be written to files:\n");
			fprintf(stderr, "  first file uniques: %s\n", a_output_file);
			fprintf(stderr, "  second file uniques: %s\n", b_output_file);
			fprintf(stderr, "  common to both input files: %s\n", c_output_file);
		} else
			fprintf(stderr,"No output files will be generated\n");

		if (use_header)
			fprintf(stderr,"Processing will be done using headers, not sequences\n");
		else
			fprintf(stderr,"Processing will be done using sequences\n");
		if (only_summarize)
			fprintf(stderr,"Only showing summary information\n");
	}

	/* check validity of given argument combination */
	if (! first_file) {
		fprintf (stderr, "Error: First sequence file is required.\n");
		return EXIT_FAILURE;
	}

	if (! second_file) {
		fprintf (stderr, "Error: First sequence file is required.\n");
		return EXIT_FAILURE;
	}

	results->first_file = first_file;
	results->second_file = second_file;
	results->use_header = use_header;
	results->only_summarize = only_summarize;
	if (a_output_file != NULL && b_output_file != NULL && c_output_file != NULL) {
		results->a_output_fp = fopen(a_output_file,"w+");
		if (!results->a_output_fp) {
			fprintf(stderr,"%s - failed to open file %s\n",progname,a_output_file);
			exit(EXIT_FAILURE);
		}
		results->b_output_fp = fopen(b_output_file,"w+");
		if (!results->b_output_fp) {
			fprintf(stderr,"%s - failed to open file %s\n",progname,b_output_file);
			exit(EXIT_FAILURE);
		}
		results->c_output_fp = fopen(c_output_file,"w+");
		if (!results->c_output_fp) {
			fprintf(stderr,"%s - failed to open file %s\n",progname,c_output_file);
			exit(EXIT_FAILURE);
		}
	}

	/* do the comparison */
	cmpseq(results);

	if (a_output_file != NULL && b_output_file != NULL && c_output_file != NULL) {
		fclose(results->a_output_fp);
		fclose(results->b_output_fp);
		fclose(results->c_output_fp);
	}

	/* report results */
	fprintf(stderr, " first_file_total = %d\n", results->first_file_total);
	fprintf(stderr, "  first_file_uniq = %d\n", results->first_file_uniq);
	fprintf(stderr, "second_file_total = %d\n", results->second_file_total);
	fprintf(stderr, " second_file_uniq = %d\n", results->second_file_uniq);
	fprintf(stderr, "           common = %d\n",           results->common);

	free(first_file);
	free(second_file);
	if (a_output_file != NULL)
		free(a_output_file);
	if (b_output_file != NULL)
		free(b_output_file);
	if (c_output_file != NULL)
		free(c_output_file);

	/* clean up */
	seqdiff_results_destroy(results);
	fclose(stderr);
	fclose(stdout);
	fclose(stdin);
	return EXIT_SUCCESS;
}
示例#2
0
int cmdline(int argc, char *argv[], np_data *np)
{

	if (argc<6 || argc>7)
	{
		show_usage();
		return -1;
	}
	
	if (strlen(argv[1])>8)
	{
		printf("Start address page error!\n");
		return -1;
	}
	spage = atoi(argv[1]);
	if (spage > MAX_PAGE)
	{
		printf("Start address page error!\n");
		return -1;
	}

	if (strlen(argv[2])>8)
	{
		printf("End address page error!\n");
		return -1;
	}
	epage = atoi(argv[2]);
	if (epage > MAX_PAGE)
	{
		printf("End address page error!\n");
		return -1;
	}

	if (strlen(argv[3])>1)
	{
		printf("Operation type error!\n");
		return -1;
	}
	if (argv[3][0] == 'r') 
		ops_t = READ_FLASH;
	else if (argv[3][0] == 'w')
		ops_t = WRITE_FLASH;
	else
	{
		printf("Operation type error!\n");
		return -1;
	}

	if (strlen(argv[4])>20)
	{
		printf("Source or object file name error!\n");
		return -1;
	}
	filename = (unsigned char *)argv[4];

	if (strlen(argv[5])>2)
	{
		printf("Chip select number error!\n");
		return -1;
	}
	cs_index = atoi(argv[5]);

	if (epage <= spage)
	{
		printf("End page number must larger than start page number!\n");
		return -1;
	}

	if (argc == 7)
	{
		args_num = 7;
		if (strlen(argv[6])>3)
		{
			printf("Processor type error!\n");
			return -1;
		}
		idx = atoi(argv[6]);
		if (idx > 20)
		{
			printf("Processor type error!\n");
			return -1;
		}
	}
	else args_num = 6;

	printf("Deal command line: spage%d epage%d ops%d file:%s cs%d\n",
	       spage,epage,ops_t,filename,cs_index);

	return 0;
}
示例#3
0
int main(int argc, char **argv, char **envp)
{
  struct termios tty;
  char filename[MAX_FILEPATH];
  char ch;
  int  speed;
  int  opt;
  int  oflags;
  int  ret;

  while ((opt = getopt(argc, argv, ":dt:b:hl:")) != -1)
    {
      switch(opt)
        {
        case 'd':
          debug++;
          break;

        case 't':
          g_ttydev = optarg;
          break;

        case 'b':
          g_baud = atoi(optarg);
          break;

        case 'h':
          show_usage(argv[0], 0);
          break;

        case 'l':
          g_logfile = optarg;
          break;

        case ':':
          fprintf(stderr, "ERROR: Missing argument to option '%c'\n", optopt);
          show_usage(argv[0], 1);
          break;

        case '?':
          fprintf(stderr, "ERROR: Unrecognized option '%c'\n", optopt);
          show_usage(argv[0], 2);
          break;
        }
    }

  if (optind < argc)
    {
      fprintf(stderr, "ERROR: Unexpected arguments at end of line\n");
      show_usage(argv[0], 3);
    }

  switch (g_baud)
    {
    case 0:      speed = B0;      break;
    case 50:     speed = B50;     break;
    case 75:     speed = B75;     break;
    case 110:    speed = B110;    break;
    case 134:    speed = B134;    break;
    case 150:    speed = B150;    break;
    case 200:    speed = B200;    break;
    case 300:    speed = B300;    break;
    case 600:    speed = B600;    break;
    case 1200:   speed = B1200;   break;
    case 1800:   speed = B1800;   break;
    case 2400:   speed = B2400;   break;
    case 4800:   speed = B4800;   break;
    case 9600:   speed = B9600;   break;
    case 19200:  speed = B19200;  break;
    case 38400:  speed = B38400;  break;
    case 57600:  speed = B57600;  break;
    case 115200: speed = B115200; break;
    case 230400: speed = B230400; break;

    default:
      fprintf(stderr, "ERROR: Unsupported BAUD=%d\n", g_baud);
      show_usage(argv[0], 4);
    }

  /* Was a log file specified? */

  if (g_logfile)
    {
      g_logstream = fopen(g_logfile, "w");
      if (!g_logstream)
        {
          fprintf(stderr, "ERROR: Failed to open '%s' for writing\n", g_logfile);
          return 5;
        }
    }

  /* Set the host stdin to O_NONBLOCK */

  oflags = fcntl(0, F_GETFL, 0);
  if (oflags == -1)
    {
      fprintf(stderr, "ERROR: fnctl(F_GETFL) failed: %s\n", strerror(errno));
      return 6;
    }

  ret = fcntl(0, F_SETFL, oflags | O_NONBLOCK);
  if (ret < 0)
    {
      fprintf(stderr, "ERROR: fnctl(F_SETFL) failed: %s\n", strerror(errno));
      return 7;
    }

  /* Open the selected serial port (blocking)*/

  g_fd = open(g_ttydev, O_RDWR);
  if (g_fd < 0)
    {
      printconsole("ERROR: Failed to open %s: %s\n", g_ttydev, strerror(errno));
      return 8;
    }

  /* Configure the serial port in at the selected baud in 8-bit, no-parity, raw mode
   * and turn off echo, etc.
   */

  ret = tcgetattr(g_fd, &g_termios);
  if (ret < 0)
    {
      printconsole("ERROR: Failed to get termios for %s: %s\n", g_ttydev, strerror(errno));
      close(g_fd);
      return 9;
    }

  memcpy(&tty, &g_termios, sizeof(struct termios));
  tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
  tty.c_oflag &= ~OPOST;
  tty.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
  tty.c_cflag &= ~(CSIZE|PARENB);
  tty.c_cflag |= CS8;

 (void)cfsetispeed(&tty, speed);
 (void)cfsetospeed(&tty, speed);

  ret = tcsetattr(g_fd, TCSANOW, &tty);
  if (ret < 0)
    {
      printconsole("ERROR: Failed to set termios for %s: %s\n", g_ttydev, strerror(errno));
      close(g_fd);
      return 10;
    }

#if 1
  /* Open the selected serial port (non-blocking)*/

  g_fdnb = open(g_ttydev, O_RDONLY | O_NONBLOCK);
  if (g_fdnb < 0)
    {
      printconsole("ERROR: Failed to open %s: %s\n", g_ttydev, strerror(errno));
      return 11;
    }
#else
  /* Create a non-blocking copy of the configure tty descriptor */

  g_fdnb = dup(g_fd);
  if (g_fdnb < 0)
    {
      printconsole("ERROR: Failed to dup %s fd=%d: %s\n", g_ttydev, g_fd, strerror(errno));
      close_tty();
      return 12;
    }

  oflags = fcntl(g_fdnb, F_GETFL, 0);
  if (oflags == -1)
    {
      fprintf(stderr, "ERROR: fnctl(F_GETFL) failed: %s\n", strerror(errno));
      close_tty();
      return 13;
    }

  ret = fcntl(g_fdnb, F_SETFL, oflags | O_NONBLOCK);
  if (ret < 0)
    {
      fprintf(stderr, "ERROR: fnctl(F_SETFL) failed: %s\n", strerror(errno));
      close_tty();
      return 14;
    }
#endif

  /* Catch attempts to control-C out of the program so that we can restore
   * the TTY settings.
   */

  signal(SIGINT, interrupt);

  /* Loopo until control-C */

  for (;;)
    {
      /* Read characters from the console, and echo them to the target tty */

      ret = readbyte(0, &ch);
      if (ret == 0)
        {
          printconsole("End-of-file: exitting\n");
          close_tty();
          return 0;
        }
      else if (ret == 1)
        {
          writebyte(g_fd, ch);
        }

      /* Read characters from target TTY and echo them on the console */

      ret = readbyte(g_fdnb, &ch);
      if (ret == 0)
        {
          printconsole("ERROR: Unexpected number of bytes read(%d) from %s\n", ret, g_ttydev);
          close_tty();
          return 15;
        }
      else if (ret == 1)
        {
          if (ch == ENQ)
            {
              char ch1;
              char ch2;

              writebyte(g_fd, '*');
              ret = readbyte(g_fd, &ch1);
              if (ret != 1)
                {
                  printconsole("ERROR: Unexpected number of bytes read(%d) from %s\n", ret, g_ttydev);
                  close_tty();
                  return 15;
                }
              ret = readbyte(g_fd, &ch2);
              if (ret != 1)
                {
                  printconsole("ERROR: Unexpected number of bytes read(%d) from %s\n", ret, g_ttydev);
                  close_tty();
                  return 16;
                }

              getfilename(g_fd, filename);

              if (ch1 == 'l' || ch1 == 'L')
                {
                  sendfile(g_fd, filename, 0);
                }
              else if (ch1 == 'v' || ch1 == 'V')
                {
                  sendfile(g_fd, filename, 1);
                }
              else if (ch1 == 's' || ch1 == 'S')
                {
                  receivefile(g_fd, filename);
                }
            }
          else
            {
              putconsole(ch);
              flushconsole();
            }
        }
    }
  return 0;
}
示例#4
0
文件: daemon.c 项目: milabs/hntlogd
int main(int argc, char * argv[])
{
	int result = 0;
	static struct option options[] = {
		{ "help",	0, NULL, 'h' },
		{ "info",	0, NULL, 'i' },
		{ "fork",	0, NULL, 'f' },
		{ "server",	1, NULL, 's' },
		{ "pidfile",	1, NULL, 'p' },
		{ "timeout",	1, NULL, 't' },
		{ "verbose",	1, NULL, 'v' },
		{  NULL,	0, NULL,  0  },
	};

	while ((result = getopt_long(argc, argv, "+hfis:p:t:v:", options, NULL)) != -1) {
		switch (result) {
		case 'h':
			show_usage(STATUS_SUCCESS);
			break;
		case 'i':
			show_author(STATUS_SUCCESS);
			break;
		case 'f':
			gDaemonState |= DSTATE_DOFORK;
			break;
		case 's':
			gServerAddress = optarg;
			break;
		case 'p':
			gPidFileName = optarg;
			break;
		case 't':
			gEventTimeout = atoi(optarg);
			if (gEventTimeout < 1)
				gEventTimeout = 1;
			if (gEventTimeout > 60)
				gEventTimeout = 60;
			break;
		case 'v':
			gVerboseLevel = atoi(optarg);
			if (gVerboseLevel < 0)
				gVerboseLevel = 1;	/* LOG_ERR */
			if (gVerboseLevel > 5)
				gVerboseLevel = 5;	/* LOG_DBG */
			break;
		default:
			show_usage(STATUS_FAILURE);
		}
	}


	if (optind < argc) {
		gUserPassword = argv[optind++];
		if (optind < argc)
			show_usage(STATUS_FAILURE);
	}

	/*
	 * OK, let's validate the data and do all the work
	 */

	if (validate())
		return STATUS_FAILURE;

	return do_the_work();
}
示例#5
0
int
main(int argc, char **argv)
{
        // Standard command line parsing.
        HASH_T *options = parse_cmdline(argc, argv, arg_opts);
        if(options == NULL || hash_get(options, "help") != NULL) {
                show_usage(argc, argv, arg_opts);
                return 1;
        }

        char *url = hash_get(options, "url");
        const char *principal = hash_get(options, "principal");
        CREDENTIALS_T *credentials = NULL;
        const char *password = hash_get(options, "credentials");
        if(password != NULL) {
                credentials = credentials_create_password(password);
        }
        char *topic = hash_get(options, "topic");

        // Setup for condition variable.
        apr_initialize();
        apr_pool_create(&pool, NULL);
        apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_UNNESTED, pool);
        apr_thread_cond_create(&cond, pool);

        // Create a session with Diffusion.
        SESSION_T *session = NULL;
        DIFFUSION_ERROR_T error;
        session = session_create(url, principal, credentials, NULL, NULL, &error);
        if(session == NULL) {
                fprintf(stderr, "TEST: Failed to create session\n");
                fprintf(stderr, "ERR : %s\n", error.message);
                return 1;
        }

        // Create a payload.
        char *data = hash_get(options, "data");
        BUF_T *payload = buf_create();
        buf_write_bytes(payload, data, strlen(data));

        // Build up some headers to send with the message.
        LIST_T *headers = list_create();
        list_append_last(headers, "apple");
        list_append_last(headers, "train");

        // Parameters for send_msg() call.
        SEND_MSG_PARAMS_T params = {
                .topic_path = topic,
                .payload = *payload,
                .headers = headers,
                .priority = CLIENT_SEND_PRIORITY_NORMAL,
                .on_send = on_send,
                .context = "FOO"
        };

        // Send the message and wait for the callback to acknowledge delivery.
        apr_thread_mutex_lock(mutex);
        send_msg(session, params);
        apr_thread_cond_wait(cond, mutex);
        apr_thread_mutex_unlock(mutex);

        // Politely close the client connection.
        session_close(session, &error);

        return 0;
}
示例#6
0
int main(int argc,char **argv)
{
  FILE *fp,*gp;
  long p;
  int32_t be64;
  size_t len;
  size_t i;
  unsigned char *dta = NULL;
  genidl_read_config ("./genidl.conf");
  if (scanArgs (--argc, ++argv) < 0)
    {
       show_usage ();
    }
#ifdef REDIRECTOR
  doredirect(use_redirector);
#endif
  for (i = 0; i < file_args_cnt; i++)
    {
      char s[1024], *idl_basename,*org_basename;
      int start, end;
      gp = fopen (file_args[i], "rb");
      if (!gp)
	{
	  fprintf (stderr, "Failed to open file ,%s'.\n", file_args[i]);
	  continue;
	}
      p = genidl_ispe (gp, &be64);

      if (is_verbose)
        fprintf (stderr, "Found PE at %ld (%s bits)\n", p, !be64 ? "32" : "64");

      end = genidl_pe_typelib_resource_count (gp);

      if (is_verbose)
	fprintf (stderr, "Contains %d typelib resource(s)\n", end);
      org_basename = get_idl_basename (file_args[i]);
      idl_basename = strdup (org_basename);
      if (strrchr (idl_basename, '.') != NULL)
	*strrchr (idl_basename, '.') = 0;

      for (start = 0; start < end; start++)
	{
	  genidl_pe_typelib_resource_read (gp, start, &dta, &len);
	  if (generate_header == 0)
	  {
	    if (end != 1)
	      sprintf (s, "%s%s_%d.idl", idl_basename, basedumpname, start);
	    else
	      sprintf (s, "%s%s.idl", idl_basename, basedumpname);
	    fp = fopen (s, "wb");
	    if (fp)
	      {
		sTI2TypLib *tl = TI2_typlib_init (dta, (size_t) len);
		if (tl)
	      {
		TI2_typlib_idl (fp, tl, org_basename);
		TI2_typlib_dest (tl);
	      }
	      if (show_dump_too)
		dumpInfo (fp, dta, len);
	      fclose (fp);
	    }
	}
	else if (generate_header == 1)
	{
	    if (end != 1)
	      sprintf (s, "%s%s_%d.h", idl_basename, basedumpname, start);
	    else
	      sprintf (s, "%s%s.h", idl_basename, basedumpname);
	    fp = fopen (s, "wb");
	    if (fp)
		  {
		    sTI2TypLib *tl = TI2_typlib_init (dta, (size_t) len);
		    if (tl)
		  {
		    TI2_typlib_hdr (fp, tl, org_basename);
		    TI2_typlib_dest (tl);
		  }
		  fclose (fp);
		}
	    }
	}
	free (idl_basename);
	free (org_basename);
	fclose (gp);
      }
  /* genidl_save_config_fp (stderr); */
  genidl_save_config ("./genidl.conf");
  return 0;
}
示例#7
0
文件: main.c 项目: huayl/pelikan
int
main(int argc, char **argv)
{
    rstatus_i status = CC_OK;
    FILE *fp = NULL;

    if (argc > 2) {
        show_usage();
        exit(EX_USAGE);
    }

    if (argc == 1) {
        log_stderr("launching server with default values.");
    }

    if (argc == 2) {
        if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
            show_usage();
            exit(EX_OK);
        }
        if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
            show_version();
            exit(EX_OK);
        }
        if (strcmp(argv[1], "-c") == 0 || strcmp(argv[1], "--config") == 0) {
            option_describe_all((struct option *)&setting, nopt);
            exit(EX_OK);
        }
        if (strcmp(argv[1], "-s") == 0 || strcmp(argv[1], "--stats") == 0) {
            metric_describe_all((struct metric *)&stats, nmetric);
            exit(EX_OK);
        }
        fp = fopen(argv[1], "r");
        if (fp == NULL) {
            log_stderr("cannot open config: incorrect path or doesn't exist");
            exit(EX_DATAERR);
        }
    }

    if (option_load_default((struct option *)&setting, nopt) != CC_OK) {
        log_stderr("failed to load default option values");
        exit(EX_CONFIG);
    }

    if (fp != NULL) {
        log_stderr("load config from %s", argv[1]);
        status = option_load_file(fp, (struct option *)&setting, nopt);
        fclose(fp);
    }
    if (status != CC_OK) {
        log_stderr("failed to load config");
        exit(EX_DATAERR);
    }

    setup();
    option_print_all((struct option *)&setting, nopt);

    core_run(&worker_processor);

    exit(EX_OK);
}
示例#8
0
void e_usage(void)
{
    show_usage();
    e_exit(EXIT_USAGE);
}
示例#9
0
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
    MPI_Init(&argc, &argv);
#endif

    std::string in_type  = "exodus";
    std::string out_type = "exodus";

    Globals globals;

    codename   = argv[0];
    size_t ind = codename.find_last_of('/', codename.size());
    if (ind != std::string::npos) {
        codename = codename.substr(ind + 1, codename.size());
    }

    Ioss::Init::Initializer io;

    std::string input_file;
    globals.scale_factor = 8.0;

    // Skip past any options...
    int i = 1;
    while (i < argc && argv[i][0] == '-') {
        if (std::strcmp("-directory", argv[i]) == 0 || std::strcmp("--directory", argv[i]) == 0 ||
                std::strcmp("-d", argv[i]) == 0) {
            i++;
            globals.working_directory = argv[i++];
        }
        else if (std::strcmp("--in_type", argv[i]) == 0) {
            i++;
            in_type = argv[i++];
        }
        else if (std::strcmp("--out_type", argv[i]) == 0) {
            i++;
            out_type = argv[i++];
        }
        else if (std::strcmp("-i", argv[i]) == 0 || std::strcmp("--input", argv[i]) == 0) {
            i++;
            input_file = argv[i++];
        }
        else if (std::strcmp("--scale_factor", argv[i]) == 0) {
            i++;
            globals.scale_factor = std::strtod(argv[i++], nullptr);
        }

        // Found an option.  See if it has an argument...
        else if (i + 1 < argc && argv[i + 1][0] == '-') {
            // No argument, another option
            i++;
        }
        else {
            // Skip the argument...
            i += 2;
        }
    }

    std::string in_file;
    std::string out_file;

    // If two or more arguments are specified at end of command line, they are
    // the input and output files to be converted.
    // The file types are assumed to be as 'hardwired' above...

    std::string cwd = globals.working_directory;

    if (input_file.empty()) {
        if (argc - i == 2) {
            in_file  = Ioss::Utils::local_filename(argv[i++], in_type, cwd);
            out_file = Ioss::Utils::local_filename(argv[i++], out_type, cwd);
        }
    }

    if (in_file.empty() || out_file.empty()) {
        show_usage(codename);
        return (EXIT_FAILURE);
    }

    OUTPUT << "Input:    '" << in_file << "', Type: " << in_type << '\n';
    OUTPUT << "Output:   '" << out_file << "', Type: " << out_type << '\n';
    OUTPUT << '\n';

    create_sph(in_file, in_type, out_file, out_type, globals);

    OUTPUT << "\n" << codename << " execution successful.\n";
#ifdef HAVE_MPI
    MPI_Finalize();
#endif
    return EXIT_SUCCESS;
}
示例#10
0
int main(int argc, char **argv) {
  int c = 0, res = 0;
  int verbose = FALSE;
  char *cp, *progname = *argv;
  const char *cmdopts = "c:f:hv";

  cp = strrchr(progname, '/');
  if (cp != NULL)
    progname = cp+1;

  opterr = 0;
  while ((c =
#ifdef HAVE_GETOPT_LONG
	 getopt_long(argc, argv, cmdopts, opts, NULL)
#else /* HAVE_GETOPT_LONG */
	 getopt(argc, argv, cmdopts)
#endif /* HAVE_GETOPT_LONG */
	 ) != -1) {
    switch (c) {
      case 'h':
        show_usage(progname, 0);
        break;

      case 'f':
        util_set_scoreboard(optarg);
        break;

      case 'c':
        config_filename = strdup(optarg);
        break;

      case 'v':
        verbose = TRUE;
        break;

      case '?':
        fprintf(stderr, "unknown option: %c\n", (char) optopt);
        show_usage(progname, 1);
        break;
    }
  }

  /* First attempt to check the supplied/default scoreboard path.  If this is
   * incorrect, try the config file kludge.
   */
  if (check_scoreboard_file() < 0) {
    char *path;

    path = util_scan_config(config_filename, "ScoreboardFile");
    if (path) {
      util_set_scoreboard(path);
      free(path);
    }

    if (check_scoreboard_file() < 0) {
      fprintf(stderr, "%s: %s\n", util_get_scoreboard(), strerror(errno));
      fprintf(stderr, "(Perhaps you need to specify the ScoreboardFile with -f, or change\n");
      fprintf(stderr," the compile-time default directory?)\n");
      exit(1);
    }
  }

  res = util_scoreboard_scrub(verbose);
  if (res < 0) {
    fprintf(stderr, "error scrubbing scoreboard %s: %s\n",
      util_get_scoreboard(), strerror(errno));
    return 1;
  }

  return 0;
}
示例#11
0
int cpp_main(int argc, char* argv[])
{
   //
   // Before anything else replace Boost.filesystem's file
   // name checker with one that does nothing (we only deal
   // with files that already exist, if they're not portable
   // names it's too late for us to do anything about it).
   //
   /*boost::filesystem::path::default_name_check(filesystem_name_check);*/
   //
   // without arguments just show help:
   //
   if(argc < 2)
   {
      std::cout << "Error: insufficient arguments, don't know what to do." << std::endl;
      show_usage();
      return 1;
   }
   //
   // create the application object:
   //
   pbcp_application papp(bcp_application::create());
   //
   // work through args, and tell the application
   // object what ir needs to do:
   //
   bool list_mode = false;
   std::list<const char*> positional_args;
   for(int i = 1; i < argc; ++i)
   {
      if(0 == std::strcmp("-h", argv[i])
         || 0 == std::strcmp("--help", argv[i]))
      {
         show_usage();
         return 0;
      }
      if(0 == std::strcmp("-v", argv[i])
         || 0 == std::strcmp("--version", argv[i]))
      {
         std::cout << "bcp " << (BOOST_VERSION / 100000) << "." << (BOOST_VERSION / 100 % 1000) << "." << (BOOST_VERSION % 100) << std::endl;
         std::cout << __DATE__ << std::endl;
         return 0;
      }
      else if(0 == std::strcmp("--list", argv[i]))
      {
         list_mode = true;
         papp->enable_list_mode();
      }
      else if(0 == std::strcmp("--list-short", argv[i]))
      {
         list_mode = true;
         papp->enable_summary_list_mode();
      }
      else if(0 == std::strcmp("--report", argv[i]))
      {
         papp->enable_license_mode();
      }
      else if(0 == std::strcmp("--cvs", argv[i]))
      {
         papp->enable_cvs_mode();
      }
      else if(0 == std::strcmp("--svn", argv[i]))
      {
         papp->enable_svn_mode();
      }
      else if(0 == std::strcmp("--scan", argv[i]))
      {
         papp->enable_scan_mode();
      }
      else if(0 == std::strcmp("--bsl-convert", argv[i]))
      {
         papp->enable_bsl_convert_mode();
      }
      else if(0 == std::strcmp("--bsl-summary", argv[i]))
      {
         papp->enable_bsl_summary_mode();
      }
      else if(0 == std::strcmp("--unix-lines", argv[i]))
      {
         papp->enable_unix_lines();
      }
      else if(0 == std::strncmp("--boost=", argv[i], 8))
      {
         papp->set_boost_path(argv[i] + 8);
      }
      else if(0 == std::strncmp("--namespace=", argv[i], 12))
      {
         papp->set_namespace(argv[i] + 12);
      }
      else if(0 == std::strncmp("--namespace-alias", argv[i], 17))
      {
         papp->set_namespace_alias(true);
      }
      else if(0 == std::strncmp("--list-namespaces", argv[i], 17))
      {
         list_mode = true;
         papp->set_namespace_list(true);
      }
      else if(0 == std::strncmp("--module-list-file=", argv[i], 19))
      {
         papp->set_module_list_file(argv[i] + 19);
      }
      else if(argv[i][0] == '-')
      {
         std::cout << "Error: Unknown argument " << argv[i] << std::endl;
         show_usage();
         return 1;
      }
      else
      {
         positional_args.push_back(argv[i]);
      }
   }
   //
   // Handle positional args last:
   //
   for(std::list<const char*>::const_iterator i = positional_args.begin();
      i != positional_args.end(); ++i)
   {
      if(!list_mode && (i == --positional_args.end()))
         papp->set_destination(*i);
      else
         papp->add_module(*i);
   }
   //
   // run the application object:
   //
   return papp->run();
}
示例#12
0
int main(int argc, char *argv[])
{
  extern int optind;
  int i = 0;
  int c;
  gp_boolean usage = false;
  gp_boolean update_archive = false;
  gp_boolean no_index = false;
  gp_archive_type *object = NULL;

  gp_init();

  /* symbols are case sensitive */
  definition_tbl = push_symbol_table(NULL, false);
  symbol_index = push_symbol_table(NULL, false);

  while ((c = GETOPT_FUNC) != EOF) {
    switch (c) {
    case '?':
    case 'h':
      usage = true;
      break;
    case 'c':
      select_mode(ar_create);
      break;
    case 'd':
      select_mode(ar_delete);
      break;
    case 'n':
      no_index = true;
      break;
    case 'q':
      gp_quiet = true;
      break;
    case 'r':
      select_mode(ar_replace);
      break;
    case 's':
      select_mode(ar_symbols);
      break;
    case 't':
      select_mode(ar_list);
      break;
    case 'v':
      fprintf(stderr, "%s\n", GPLIB_VERSION_STRING);
      exit(0);
      break;
    case 'x':
      select_mode(ar_extract);
      break;
    }
    if (usage)
      break;
  }

  if (optind < argc) {
    /* fetch the library name */
    state.filename = argv[optind++];
    /* some operations require object filenames or membernames */
    for ( ; optind < argc; optind++) {
      state.objectname[state.numobjects] = argv[optind];
      if (state.numobjects >= MAX_OBJ_NAMES) {
        gp_error("exceeded maximum number of object files");
        break;
      }
      state.numobjects++;
    }
  } else {
    usage = true;
  }

  /* User did not select an operation */
  if (state.mode == ar_null) {
    usage = true;
  }

  /* User did not provide object names */
  if ((state.mode != ar_list) && 
      (state.mode != ar_symbols) && 
      (state.numobjects == 0)) {
    usage = true;
  }

  if (usage) {
    show_usage();
  }

  /* if we are not creating a new archive, we have to read an existing one */
  if (state.mode != ar_create) {
    if (gp_identify_coff_file(state.filename) != archive_file) {
      gp_error("\"%s\" is not a valid archive file", state.filename);
      exit(1);
    } else {
      state.archive = gp_archive_read(state.filename);
    }
  }
    
  /* process the option */
  i = 0;
  switch (state.mode) {
  case ar_create: 
  case ar_replace:
    while (i < state.numobjects) {
      if (gp_identify_coff_file(state.objectname[i]) != object_file) {
        gp_error("\"%s\" is not a valid object file", state.objectname[i]);
        break;
      } else {
        state.archive = gp_archive_add_member(state.archive, 
                                              state.objectname[i],
                                              object_name(state.objectname[i]));
      }
      i++;
    }
    update_archive = true;
    break;

  case ar_delete: 
    while (i < state.numobjects) {
      if (has_path(state.objectname[i])) {
        gp_error("invalid object name \"%s\"", state.objectname[i]);
        break;
      }
      object = gp_archive_find_member(state.archive, state.objectname[i]);
      if (object == NULL) {
        gp_error("object \"%s\" not found", state.objectname[i]);
        break;
      } else {
        state.archive = gp_archive_delete_member(state.archive, 
                                                 state.objectname[i]);
      }
      i++;
    }
    update_archive = true;
    break;

  case ar_extract:
    while (i < state.numobjects) {
      if (has_path(state.objectname[i])) {
        gp_error("invalid object name \"%s\"", state.objectname[i]);
        break;
      }
      object = gp_archive_find_member(state.archive, state.objectname[i]);
      if (object == NULL) {
        gp_error("object \"%s\" not found", state.objectname[i]);
        break;
      } else {
        if (gp_archive_extract_member(state.archive, state.objectname[i])) {
          gp_error("can't write file \"%s\"", state.objectname[i]);
          break;
        }
      }
      i++;
    } 
    break;

  case ar_list:
    gp_archive_list_members(state.archive);
    break;

  case ar_symbols:
    if (gp_archive_have_index(state.archive) == 0) {
      gp_error("this archive has no symbol index");
    } else {
      gp_archive_read_index(symbol_index, state.archive);
      gp_archive_print_table(symbol_index);
    }
    break;

  case ar_null:
  default:
    assert(0);
  }

  /* If the archive is being modified remove the old symbol index */
  if (update_archive) {
    state.archive = gp_archive_remove_index(state.archive);
  }

  /* check for duplicate symbols */
  gp_archive_make_index(state.archive, definition_tbl);

  /* add the symbol index to the archive */      
  if (update_archive && (!no_index)) {
    state.archive = gp_archive_add_index(definition_tbl, state.archive);
  }

  /* write the new or modified archive */
  if (update_archive && (gp_num_errors == 0)) {
    if (gp_archive_write(state.archive, state.filename))
      gp_error("can't write the new archive file");
  }

  if (gp_num_errors > 0)
    return EXIT_FAILURE;
  else
    return EXIT_SUCCESS;

}
示例#13
0
文件: main.c 项目: sutajiokousagi/cpi
int main(int argc, char **argv)
{
    /*! default at failure */
    int main_ret = 1;

    /*! input XML file, if specified */
    FILE *inp_xml_file = 0;

    /*! output XML file, if specified */
    FILE *out_xml_file = 0;

	/*! serial device path */
	const char *serial_device_path = SERIAL_DEVICE_PATH;

    /*! CPI instance */
    cpi_t *p_cpi = 0;

    /*! options for stdout */
    int print_putative_id = 0;
    int print_all = 0;
    int print_usage = 0;

    /*! options for power down and alarm */
    int do_shutdown = 0;
    int do_alarm = 0;
    uint32_t alarm_time = 0;

    /*! key id */
    uint16_t key_id = 0;

    /*! raw buffer, used to parse results */
    uint8_t *tmp_buffer1 = 0, *tmp_buffer2 = 0, *tmp_buffer3 = 0;

    /*! @hack @todo thread for monitoring timeout */
    pthread_t timeout_thread;

    /*! initialize timeout thread */
    pthread_create(&timeout_thread, 0, timeout_hack, 0);

    /*! print usage if there are no arguments */
    if(argc <= 1) { print_usage = 1; }

    /*! initialize temporary buffers */
    {
        tmp_buffer1 = (uint8_t*)malloc(CPI_MAX_RESULT_SIZE);

        if(tmp_buffer1 == 0)
        {
            fprintf(stderr, "Error: could not allocate %d bytes for tmp_buffer1\n", CPI_MAX_RESULT_SIZE);
            return 1;
        }

        tmp_buffer2 = (uint8_t*)malloc(CPI_MAX_RESULT_SIZE);

        if(tmp_buffer2 == 0)
        {
            fprintf(stderr, "Error: could not allocate %d bytes for tmp_buffer2\n", CPI_MAX_RESULT_SIZE);
            return 1;
        }

        tmp_buffer3 = (uint8_t*)malloc(CPI_MAX_RESULT_SIZE);

        if(tmp_buffer3 == 0)
        {
            fprintf(stderr, "Error: could not allocate %d bytes for tmp_buffer3\n", CPI_MAX_RESULT_SIZE);
            return 1;
        }
    }

    /*! parse command line */
    {
        int cur_arg = 0;

        for(cur_arg = 1; cur_arg < argc; cur_arg++)
        {
            /*! expect all options to begin with '-' character */
            if(argv[cur_arg][0] != '-')
            {
                fprintf(stderr, "Warning: Unrecognized option \"%s\"\n", argv[cur_arg]);
                continue;
            }

            /*! process command options */
            switch(argv[cur_arg][1])
            {
                case 'k':
                {
                    /*! skip over to key ID */
                    if(++cur_arg >= argc) { break; }

                    /*! attempt to parse key ID */
                    sscanf(argv[cur_arg], "%hu", &key_id);
                }
                break;

				case 't':
				{
					/*! Skip to port path */
					if (++cur_arg >= argc) { break; }

					serial_device_path = argv[cur_arg];
					fprintf( stderr, "Using non-default serial port %s\n", serial_device_path );
				}
				break;

                case 'r':
                {
                    /*! skip over to filename */
                    if(++cur_arg >= argc) { break; }

                    /*! attempt to open inpt file */
                    inp_xml_file = fopen(argv[cur_arg], "rt");

                    /*! report file open error to user */
                    if(inp_xml_file == 0)
                    {
                        fprintf(stderr, "Error: Could not open \"%s\" for reading.\n", argv[cur_arg]);
                    }
                }
                break;

                case 'w':
                {
                    /*! skip over to filename */
                    if(++cur_arg >= argc) { break; }

                    /*! attempt to open output file */
                    out_xml_file = fopen(argv[cur_arg], "wt");

                    /*! report file open error to user */
                    if(out_xml_file == 0)
                    {
                        fprintf(stderr, "Error: Could not open \"%s\" for writing\n", argv[cur_arg]);
                    }
                }
                break;

                case 'i':
                {
                    if(inp_xml_file == 0) { inp_xml_file = stdin; }
                }
                break;

                case 'o':
                {
                    if(out_xml_file == 0) { out_xml_file = stdout; }
                }
                break;

                case 'p':
                    print_putative_id = 1;
                    break;

                case 'a':
                {
                    do_alarm = 1;

                    /*! skip over to alarm time */
                    if(++cur_arg >= argc) { break; }

                    /*! attempt to parse key ID */
                    sscanf(argv[cur_arg], "%u", &alarm_time);
                }
                break;

                case 's':
                    do_shutdown = 1;
                    break;

                case 'd':
                    print_all = 1;
                    break;

                case '-':
                    print_usage = 1;
                    break;

                default:
                    fprintf(stderr, "Warning: Unrecognized option \"%s\"\n", argv[cur_arg]);
                    break;
            }
        }
    }

    /*! optionally, print usage */
    if(print_usage)
    {
        show_usage();
        goto cleanup;
    }

    /*! create CPI instance */
    {
        cpi_info_t cpi_info = { 0 };

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_create(&cpi_info, &p_cpi);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_create failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }
    }

    /*! initialize CPI instance */
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_init(p_cpi, serial_device_path);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_init failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }
    }

    /*! optionally read input XML data */
    if(inp_xml_file != 0)
    {
        int size = 0;

        /*! read up to max buffer size minus null terminator */
        {
            size_t ret = fread(tmp_buffer1, 1, CPI_MAX_RESULT_SIZE-1, inp_xml_file);

            /*! update size */
            if(ret > 0) { size = ret; }

            /*! append null terminator */
            tmp_buffer1[size] = '\0';
        }

        /*! process XML data */
        {
            /*!< @hack @todo enable hung CPI timeout */
            enable_timeout(10);

            int ret = cpi_process_xml(p_cpi, (char*)tmp_buffer1, (char*)tmp_buffer2);

            if(CPI_FAILED(ret))
            {
                fprintf(stderr, "Error: cpi_process_xml failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
                goto cleanup;
            }
        }

        /*! optionally write XML output */
        if(out_xml_file != 0)
        {
            int size = strlen((char*)tmp_buffer2);

            /*! write output data to out_xml_file */
            if(size > 0)
            {
                size_t ret = fwrite(tmp_buffer2, 1, size, out_xml_file);

                if(ret != size)
                {
                    fprintf(stderr, "Error: fwrite returned %d, expected %d\n", ret, size);
                    goto cleanup;
                }
            }
        }

    }

    /*! get putative ID */
    if(print_all || print_putative_id)
    {
        char str[CPI_PUTATIVE_ID_SIZE];

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(4);

        int ret = cpi_get_putative_id(p_cpi, key_id, str);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_putative_id failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        /*! print to stdout in all format */
        if(print_all)
        {
            printf("Putative ID : %s\n", str);
        }
        /*! print only putative ID */
        else if(print_putative_id)
        {
            printf("%s\n", str);
        }
    }

    /*! get public key */
    if(print_all)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_public_key(p_cpi, key_id, (char*)tmp_buffer1);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_public_key failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        /*! public key contains an endline already */
        printf("Public Key : \n%s", tmp_buffer1);
    }

    /*! get version data */
    if(print_all)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_version_data(p_cpi, tmp_buffer1);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_version_data failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Version Data :\n");

        print_raw(tmp_buffer1, CPI_VERSION_SIZE);
    }

    /*! get current time */
    if(print_all)
    {
        uint32_t cur_time = 0;

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_current_time(p_cpi, &cur_time);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_current_time failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Current Time : %d seconds since last reboot\n", cur_time);
    }

    /*! get current owner key index */
    if(print_all)
    {
        uint32_t cur_oki = 0;

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_owner_key_index(p_cpi, &cur_oki);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_owner_key_index failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Current Owner Key Index : %d\n", cur_oki);
    }

    /*! get serial number data */
    if(print_all)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_serial_number(p_cpi, tmp_buffer1);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_serial_number failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Serial Number :\n");

        print_raw(tmp_buffer1, CPI_SERIAL_NUMBER_SIZE);
    }

    /*! get hardware version data */
    if(print_all)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_hardware_version_data(p_cpi, tmp_buffer1);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_hardware_version_data failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Hardware Version Data :\n");

        print_raw(tmp_buffer1, CPI_HARDWARE_VERSION_SIZE);
    }

    /*! issue challenge */
    if(print_all)
    {
        uint8_t rand_data[0x10] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

        memset(tmp_buffer1, 0, CPI_MAX_RESULT_SIZE);
        memset(tmp_buffer2, 0, CPI_MAX_RESULT_SIZE);
        memset(tmp_buffer3, 0, CPI_MAX_RESULT_SIZE);

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_issue_challenge(p_cpi, key_id, rand_data, tmp_buffer1, tmp_buffer2, tmp_buffer3);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_issue_challenge failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("result1 : \n");

        /*! print result1 */
        print_raw(tmp_buffer1, CPI_RESULT1_SIZE);

        printf("result2 : \n");

        /*! print result1 */
        print_raw(tmp_buffer2, CPI_RESULT2_SIZE);

#if defined(CNPLATFORM_falconwing)        
	printf("result3 : \n");

        /*! print result1 */
        print_raw(tmp_buffer3, CPI_RESULT3_SIZE);
#endif
    }

    /*! set alarm */
    if(do_alarm)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_set_alarm_time(p_cpi, alarm_time);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_set_alarm_time failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Alarm was set for %d seconds from now\n", alarm_time);
    }

    /*! optionally, power down */
    if(do_shutdown)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_trigger_power_down(p_cpi);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_trigger_power_down failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }
    }

    main_ret = 0;

cleanup:

    /*! cleanup input file handle(s) */
    if( (inp_xml_file != 0) && (inp_xml_file != stdin) )
    {
        fclose(inp_xml_file);
        inp_xml_file = 0;
    }

    /*! cleanup file handle(s) */
    if( (out_xml_file != 0) && (out_xml_file != stdout) )
    {
        fclose(out_xml_file);
        out_xml_file = 0;
    }

    if(tmp_buffer2 != 0)
    {
        free(tmp_buffer2);
        tmp_buffer2 = 0;
    }

    if(tmp_buffer1 != 0)
    {
        free(tmp_buffer1);
        tmp_buffer1 = 0;
    }

    /*! cleanup CPI instance */
    if(p_cpi != 0)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_close(p_cpi);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Warning: cpi_close failed (0x%.08X)\n", ret);
            return 1;
        }
    }

    /*! cleanup timeout thread */
    {
        timeout_hack_stop = 1;
        pthread_join(timeout_thread, 0);
    }

    return main_ret;
}
/*
 * ===  FUNCTION  ======================================================================
 *         Name:  init_arguments
 *  Description:  初始化和解释命令行的字符串。getopt_long
 * =====================================================================================
 */
void init_arguments(int *argc, char ***argv)
{
    /* Option struct for progrm run arguments */
    static struct option long_options[] =
        {
        {"help",        no_argument,        0,              'h'},
        {"background",  no_argument,        &background,    1},
        {"dhcp",        no_argument,        &dhcp_on,       1},
        {"device",      required_argument,  0,              2},
        {"ver",         required_argument,  0,              3},
        {"username",    required_argument,  0,              'u'},
        {"password",    required_argument,  0,              'p'},
        {"ip",          required_argument,  0,              4},
        {"mask",        required_argument,  0,              5},
        {"gateway",     required_argument,  0,              'g'},
        {"dns",         required_argument,  0,              'd'},
        {0, 0, 0, 0}
        };
    int c;
    while (1) {

        /* getopt_long stores the option index here. */
        int option_index = 0;
        c = getopt_long ((*argc), (*argv), "u:p:g:d:hbl",
                        long_options, &option_index);
        if (c == -1)
            break;
        switch (c) {
            case 0:
               break;
            case 'b':
                background = 1;
                break;
            case 2:
                dev = optarg;
                break;
            case 3:
                client_ver = optarg;
                break;
            case 4:
                user_ip = optarg;
                break;
            case 5:
                user_mask = optarg;
                break;
            case 'u':
                username = optarg;
                break;
            case 'p':
                password = optarg;
                break;
            case 'g':
                user_gateway = optarg;
                break;
            case 'd':
                user_dns = optarg;
                break;
            case 'l':
                exit_flag = 1;
                break;
            case 'h':
                show_usage();
                exit(EXIT_SUCCESS);
                break;
            case '?':
                if (optopt == 'u' || optopt == 'p'|| optopt == 'g'|| optopt == 'd')
                    fprintf (stderr, "Option -%c requires an argument.\n", optopt);
                exit(EXIT_FAILURE);
                break;
            default:
                fprintf (stderr,"Unknown option character `\\x%x'.\n", c);
                exit(EXIT_FAILURE);
        }
    }
}
示例#15
0
static int
pass_args (int argc, char **argv)
{
  int has_file = 0;
  int has_error = 0;
  while (argc-- > 0)
    {
      int is_pos = 1;
      char *h = *argv++;
      if (h[0] != '-')
        {
	  has_file = 1;
	  file_name = h;
	  continue;
	}
      switch (h[1])
        {
	case 'p':
	  if (h[2] != 0)
	    goto error_point;
	  if (argc == 0)
	    {
	      fprintf (stderr, "Missing argument for -p\n");
	      show_usage ();
	    }
	  h = *argv++; argc--;
	  while (*h != 0)
	    {
	      if (*h == '-') is_pos = 0;
	      else if (*h == '+') is_pos = 1;
	      else if (*h == 'l')
		{
		  if (is_pos)
		    set_pe_hdr_chara |= 0x20;
		  else
		    mask_pe_hdr_chara &= ~0x20;
		}
	      else if (*h == 'r')
		{
		  if (is_pos)
		    set_pe_hdr_chara |= 0x400;
		  else
		    mask_pe_hdr_chara &= ~0x400;
		}
	      else if (*h == 'n')
		{
		  if (is_pos)
		    set_pe_hdr_chara |= 0x800;
		  else
		    mask_pe_hdr_chara &= ~0x800;
		}
	      else if (*h == 's')
		{
		  if (is_pos)
		    set_pe_hdr_chara |= 0x1000;
		  else
		    mask_pe_hdr_chara &= ~0x1000;
		}
	      else if (*h == 'u')
		{
		  if (is_pos)
		    set_pe_hdr_chara |= 0x4000;
		  else
		    mask_pe_hdr_chara &= ~0x4000;
		}
	      else
		{
		  fprintf (stderr, "Unknown flag-option '%c' for -p\n", *h);
		  has_error = 1;
		}
	      ++h;
	    }
	  break;
	case 'd':
	  if (h[2] != 0)
	    goto error_point;
	  if (argc == 0)
	    {
	      fprintf (stderr, "Missing argument for -d\n");
	      show_usage ();
	    }
	  h = *argv++; argc--;
	  while (*h != 0)
	    {
	      switch (*h)
	        {
		case '-': is_pos = 0; break;
		case '+': is_pos = 1; break;
		case 'd':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x40;
		  else mask_pe_opt_hdr_dll_chara &= ~0x40;
		  break;
		case 'f':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x80;
		  else mask_pe_opt_hdr_dll_chara &= ~0x80;
		  break;
		case 'n':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x100;
		  else mask_pe_opt_hdr_dll_chara &= ~0x100;
		  break;
		case 'i':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x200;
		  else mask_pe_opt_hdr_dll_chara &= ~0x200;
		  break;
		case 's':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x400;
		  else mask_pe_opt_hdr_dll_chara &= ~0x400;
		  break;
		case 'b':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x800;
		  else mask_pe_opt_hdr_dll_chara &= ~0x800;
		  break;
		case 'a':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x1000;
		  else mask_pe_opt_hdr_dll_chara &= ~0x1000;
		  break;
		case 'w':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x2000;
		  else mask_pe_opt_hdr_dll_chara &= ~0x2000;
		  break;
		case 't':
		  if (is_pos) set_pe_opt_hdr_dll_chara |= 0x8000;
		  else mask_pe_opt_hdr_dll_chara &= ~0x8000;
		  break;
		default:
		  fprintf (stderr, "Unknown flag-option '%c' for -d\n", *h);
		  has_error = 1;
		  break;
		}
	      ++h;
	    }
	  break;
	case 'x':
	  if (h[2] == 0)
	    {
	      dump_information = 1;
	      break;
	    }
	  goto error_point;
	case 'h':
	  if (h[2] == 0)
	    show_usage ();
	  /* fallthru */
	default:
error_point:
	  fprintf (stderr, "Unknown option ,%s'\n", h);
	  has_error = 1;
	  break;
	}
    }
  if (has_error)
    show_usage ();
  if (!has_file)
    {
      fprintf (stderr, "File argument missing\n");
      show_usage ();
    }
  return 1;
}
示例#16
0
int main(int argc, char *argv[])
{
  const char *p;
  unsigned long options = 0;
  int verbose = 0;
  int c;

  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);

  if (argc < 1)
    show_usage(_("Not enough arguments"));

  p = program_invocation_short_name;
  if (!strcmp(p, "setarch")) {
    argv++;
    argc--;
    if (argc < 1)
      show_usage(_("Not enough arguments"));
    p = argv[0];
    argv[0] = argv[-1];      /* for getopt_long() to get the program name */
    if (!strcmp(p, "-h") || !strcmp(p, "--help"))
      show_help();
  #if defined(__sparc64__) || defined(__sparc__)
  } else if (!strcmp(p,"sparc64")) {
      options |= ADDR_LIMIT_32BIT;
  #endif
  }
  #if defined(__sparc64__) || defined(__sparc__)
   if (!strcmp(p, "sparc32bash")) {
       if (set_arch(p, 0L))
           err(EXIT_FAILURE, _("Failed to set personality to %s"), p);
       execl("/bin/bash", NULL);
       err(EXIT_FAILURE, "/bin/bash");
   }
  #endif

  while ((c = getopt_long(argc, argv, "+hv3BFILRSTXZ", longopts, NULL)) != -1) {
    switch (c) {
    case 'h':
      show_help();
      break;
    case 'v':
      verbose = 1;
      break;
    case 'R':
	turn_on(ADDR_NO_RANDOMIZE, options);
	break;
    case 'F':
	turn_on(FDPIC_FUNCPTRS, options);
	break;
    case 'Z':
	turn_on(MMAP_PAGE_ZERO, options);
	break;
    case 'L':
	turn_on(ADDR_COMPAT_LAYOUT, options);
	break;
    case 'X':
	turn_on(READ_IMPLIES_EXEC, options);
	break;
    case 'B':
	turn_on(ADDR_LIMIT_32BIT, options);
	break;
    case 'I':
	turn_on(SHORT_INODE, options);
	break;
    case 'S':
	turn_on(WHOLE_SECONDS, options);
	break;
    case 'T':
	turn_on(STICKY_TIMEOUTS, options);
	break;
    case '3':
	turn_on(ADDR_LIMIT_3GB, options);
	break;
    case OPT_4GB:          /* just ignore this one */
      break;
    case OPT_UNAME26:
	turn_on(UNAME26, options);
	break;
    }
  }

  argc -= optind;
  argv += optind;

  if (set_arch(p, options))
    err(EXIT_FAILURE, _("Failed to set personality to %s"), p);

  if (!argc) {
    execl("/bin/sh", "-sh", NULL);
    err(EXIT_FAILURE, "/bin/sh");
  }

  execvp(argv[0], argv);
  err(EXIT_FAILURE, "%s", argv[0]);
  return EXIT_FAILURE;
}
示例#17
0
文件: uname.c 项目: Saruta/ToyOS
int main(int argc, char * argv[]) {
	struct utsname u;

	int c;
	int flags = 0;
	int space = 0;

	while ((c = getopt(argc, argv, "ahmnrsv")) != -1) {
		switch (c) {
			case 'a':
				flags |= FLAG_ALL;
				break;
			case 's':
				flags |= FLAG_SYSNAME;
				break;
			case 'n':
				flags |= FLAG_NODENAME;
				break;
			case 'r':
				flags |= FLAG_RELEASE;
				break;
			case 'v':
				flags |= FLAG_VERSION;
				break;
			case 'm':
				flags |= FLAG_MACHINE;
				break;
			case 'h':
			default:
				show_usage(argc, argv);
				break;
		}
	}

	uname(&u);

	if (!flags) {
		/* By default, we just print the kernel name */
		flags = FLAG_SYSNAME;
	}

	if (flags & FLAG_SYSNAME) {
		if (space++) printf(" ");
		printf("%s", u.sysname);
	}

	if (flags & FLAG_NODENAME) {
		if (space++) printf(" ");
		printf("%s", u.nodename);
	}

	if (flags & FLAG_RELEASE) {
		if (space++) printf(" ");
		printf("%s", u.release);
	}

	if (flags & FLAG_VERSION) {
		if (space++) printf(" ");
		printf("%s", u.version);
	}

	if (flags & FLAG_MACHINE) {
		if (space++) printf(" ");
		printf("%s", u.machine);
	}

	printf("\n");

	return 0;
}
示例#18
0
static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t* cmdCxt)
{
    char *opt;
    RK_U32 optindex, handleoptions = 1, ret =0;

    if ((argc <2) || (cmdCxt == NULL)) {
        VPU_DEMO_LOG("vpu api demo, input parameter invalid\n");
        show_usage();
        return ERROR_INVALID_PARAM;
    }

    /* parse options */
    optindex = 1;
    while (optindex < argc) {
        opt = argv[optindex++];

        if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
            if (opt[1] == '-') {
                if (opt[2] != '\0') {
                    opt++;
                } else {
                     handleoptions = 0;
                    continue;
                }
            }

            opt++;

            switch (*opt) {
                case 'i':
                    if (argv[optindex]) {
                        memcpy(cmdCxt->input_file, argv[optindex], strlen(argv[optindex]));
                        cmdCxt->input_file[strlen(argv[optindex])] = '\0';
                        cmdCxt->have_input = 1;
                    } else {
                        VPU_DEMO_LOG("input file is invalid\n");
                        ret = -1;
                        goto PARSE_OPINIONS_OUT;
                    }
                    break;
                case 'o':
                    if (argv[optindex]) {
                        memcpy(cmdCxt->output_file, argv[optindex], strlen(argv[optindex]));
                        cmdCxt->output_file[strlen(argv[optindex])] = '\0';
                        cmdCxt->have_output = 1;
                        break;
                    } else {
                        VPU_DEMO_LOG("out file is invalid\n");
                        ret = -1;
                        goto PARSE_OPINIONS_OUT;
                    }
                case 'd':
                    cmdCxt->disable_debug = 1;
                    break;
                case 'w':
                    if (argv[optindex]) {
                        cmdCxt->width = atoi(argv[optindex]);
                        break;
                    } else {
                        VPU_DEMO_LOG("input width is invalid\n");
                        ret = -1;
                        goto PARSE_OPINIONS_OUT;
                    }
                case 'h':
                    if ((*(opt+1) != '\0') && !strncmp(opt, "help", 4)) {
                        show_help();
                        ret = VPU_DEMO_PARSE_HELP_OK;
                        goto PARSE_OPINIONS_OUT;
                    } else if (argv[optindex]) {
                        cmdCxt->height = atoi(argv[optindex]);
                    } else {
                        VPU_DEMO_LOG("input height is invalid\n");
                        ret = -1;
                        goto PARSE_OPINIONS_OUT;
                    }
                    break;
                case 't':
                    if (argv[optindex]) {
                        cmdCxt->codec_type = atoi(argv[optindex]);
                        break;
                    } else {
                        VPU_DEMO_LOG("input codec_type is invalid\n");
                        ret = -1;
                        goto PARSE_OPINIONS_OUT;
                    }

                default:
                    if ((*(opt+1) != '\0') && argv[optindex]) {
                        if (!strncmp(opt, "coding", 6)) {
                            VPU_DEMO_LOG("coding, argv[optindex]: %s",
                                    argv[optindex]);
                            cmdCxt->coding = atoi(argv[optindex]);
                        } else if (!strncmp(opt, "vframes", 7)) {
                            cmdCxt->record_frames = atoi(argv[optindex]);
                        } else if (!strncmp(opt, "ss", 2)) {
                            cmdCxt->record_start_ms = atoi(argv[optindex]);
                        } else {
                            ret = -1;
                            goto PARSE_OPINIONS_OUT;
                        }
                    } else {
                        ret = -1;
                        goto PARSE_OPINIONS_OUT;
                    }
                    break;
            }

            optindex += ret;
        }
    }

PARSE_OPINIONS_OUT:
    if (ret <0) {
        VPU_DEMO_LOG("vpu api demo, input parameter invalid\n");
        show_usage();
        return ERROR_INVALID_PARAM;
    }
    return ret;
}
示例#19
0
int main(int argc, char *argv[])
{
    int default_in;
    int default_out;
    int i = 0, n = 0;
    char line[STRING_MAX];
    int test_input = 0, test_output = 0, test_both = 0, somethingStupid = 0;
    int stream_test = 0;
    int latency_valid = FALSE;
    
    if (sizeof(void *) == 8) 
        printf("Apparently this is a 64-bit machine.\n");
    else if (sizeof(void *) == 4) 
        printf ("Apparently this is a 32-bit machine.\n");
    
    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-h") == 0) {
            show_usage();
        } else if (strcmp(argv[i], "-l") == 0 && (i + 1 < argc)) {
            i = i + 1;
            latency = atoi(argv[i]);
            printf("Latency will be %ld\n", (long) latency);
            latency_valid = TRUE;
        } else {
            show_usage();
        }
    }

    while (!latency_valid) {
        int lat; // declared int to match "%d"
        printf("Latency in ms: ");
        if (scanf("%d", &lat) == 1) {
            latency = (int32_t) lat; // coerce from "%d" to known size
	    latency_valid = TRUE;
        }
    }

    /* determine what type of test to run */
    printf("begin portMidi test...\n");
    printf("%s%s%s%s%s",
           "enter your choice...\n    1: test input\n",
           "    2: test input (fail w/assert)\n",
           "    3: test input (fail w/NULL assign)\n",
           "    4: test output\n    5: test both\n",
           "    6: stream test\n");
    while (n != 1) {
        n = scanf("%d", &i);
        fgets(line, STRING_MAX, stdin);
        switch(i) {
        case 1: 
            test_input = 1;
            break;
        case 2: 
            test_input = 1;
            somethingStupid = 1;
            break;
        case 3: 
            test_input = 1;
            somethingStupid = 2;
            break;
        case 4: 
            test_output = 1;
            break;
        case 5:
            test_both = 1;
            break;
		case 6:
			stream_test = 1;
			break;
        default:
            printf("got %d (invalid input)\n", n);
            break;
        }
    }
    
    /* list device information */
    default_in = Pm_GetDefaultInputDeviceID();
    default_out = Pm_GetDefaultOutputDeviceID();
    for (i = 0; i < Pm_CountDevices(); i++) {
        char *deflt;
        const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
        if (((test_input  | test_both) & info->input) |
            ((test_output | test_both | stream_test) & info->output)) {
            printf("%d: %s, %s", i, info->interf, info->name);
            if (info->input) {
                deflt = (i == default_in ? "default " : "");
                printf(" (%sinput)", deflt);
            }
            if (info->output) {
                deflt = (i == default_out ? "default " : "");
                printf(" (%soutput)", deflt);
            }
            printf("\n");
        }
    }
    
    /* run test */
    if (stream_test) {
        main_test_stream();
    } else if (test_input) {
        main_test_input(somethingStupid);
    } else if (test_output) {
        main_test_output();
    } else if (test_both) {
        main_test_both();
    }
    
    printf("finished portMidi test...type ENTER to quit...");
    fgets(line, STRING_MAX, stdin);
    return 0;
}
示例#20
0
文件: 4.c 项目: macsual/COMP2130
/* TODO: account for comments beginning in a single line comment and in string
 * literals or any other areas where they are invalid */
int
main(int argc, char *argv[])
{
    int c;

    /* flag to indicate the prescence of its namesake. */
    int unclosed_comment = 0;

    /* stream for user provided file */
    FILE *fp;
    
    /* stores the path of the user provided file */
    char *filename;

    if (argc && argv[0])
        prog_name = argv[0];
    else
        prog_name = "";

    if (argc != 2) {
        show_usage();
        
        return EXIT_FAILURE;
    }

    filename = malloc(strlen(argv[1]) + 1);
    if (NULL == filename) {
        fprintf(stderr, "malloc failed\n");

        return EXIT_FAILURE;
    }
    
    (void)snprintf(filename, strlen(argv[1]) + 1, "%s", argv[1]);

    fp = fopen(filename, "r");
    if (NULL == fp) {
        fprintf(stderr, "fopen failed\n");

        return EXIT_FAILURE;
    }

    do {
        c = fgetc(fp);

        /* search for beginning of comment */
        if ('/' == (char)c) { /* potentially the beginning of a comment */
            /* advance to next character in stream */
            c = fgetc(fp);

            if ('*' == (char)c)
                unclosed_comment = 1;
            /* the asterisk must immediately follow the forward slash */
            else
                /* continue searching for comments */
                continue;

            c = fgetc(fp);

            /* search for end of comment */
            while ((char)c != EOF) {
                c = fgetc(fp);

                /* potentially the beginning of comment closing */
                if ('*' == (char)c) {
                    c = fgetc(fp);
                    
                    /* the forward slash must immediately follow the asterisk */
                    if ('/' == (char)c) {
                        unclosed_comment = 0;

                        /* continue searching for comments */
                        break;
                    }
                }
            }
        }
    } while (c != EOF);

    if (feof(fp)) { /* end of file */
        if (unclosed_comment) {
            fprintf(stderr, "There is an unclosed comment\n");

            return EXIT_FAILURE;
        }

        return EXIT_SUCCESS;
    } else if (ferror(fp)) { /* file error */
        fprintf(stderr, "An error occurred while reading the file\n");

        return EXIT_FAILURE;
    } else { /* received a character that resembles EOF */
        fprintf(stderr, "A character that resembles EOF was encountered\n");

        return EXIT_FAILURE;
    }
}
示例#21
0
int main(int argc, char **argv)
{
	int bus_num = 0;
	unsigned char i2c_addr = MLX90614_I2CADDR;

	int op_read = 1;
	int write_arg_set = 0;

	unsigned char command = 0x00;
	unsigned short write_arg = 0x00;

	static struct option long_options[] = {
		{ "help", no_argument, NULL, 'h' },
		{ "bus", required_argument, NULL, 'b' },
		{ "i2c_addr", required_argument, NULL, 'c' },
		{ "new_addr", required_argument, NULL, 'r'},
		{ "write", no_argument, NULL, 'w' },
		{ "get_ir_temp", no_argument, NULL, 'i' },
		{ "get_ambient_temp", no_argument, NULL, 'a' },
		{ "emissivity_coefficient", optional_argument, NULL, 'e'},
		{ "pwm_mode", optional_argument, NULL,'p'},
		{ "debug", no_argument, NULL, 'd' }
	};

	int option_index = 0;
	int opt = getopt_long(argc, argv, "hbc:r:wiae:p:d", long_options, &option_index);

	while (opt != -1) {
		switch (opt) {
			case 'h':
				show_usage();
				return 0;

			case 'b':
				bus_num = atoi(optarg);
				break;

			case 'c':
				i2c_addr = strtol(optarg, NULL, 16);
				break;

			case 'r':
				write_arg = strtol(optarg, NULL, 16);;
				write_arg_set = 1;
				command = MLX90614_ADDR;
				break;

			case 'w':
				op_read = 0;
				break;

			case 'i':
				command = MLX90614_TOBJ1;
				break;

			case 'a':
				command = MLX90614_TA;
				break;

			case 'e':
				command = MLX90614_EMISS;

				if (optarg) {
					write_arg = atoi(optarg);
					printf("%i\n", write_arg);
					write_arg_set = 1;
				}

				break;

			case 'p':
				command = MLX90614_PWMCTRL;

				if (optarg) {
					write_arg = atoi(optarg);
					write_arg_set = 1;
				}

				break;

			case 'd':
				DEBUG_MODE = 1;
				break;

			default:
				show_usage();
				abort();
		}

		opt = getopt_long(argc, argv, "bc:wiaep", long_options, &option_index);
	}

	if (check_args(bus_num, i2c_addr) < 0) {
		return -1;
	}

	if (!op_read && (command == MLX90614_TOBJ1 || command == MLX90614_TA)) {
		fprintf(stderr, "Read only data!\n");
		return -1;
	}

	if (!op_read && !write_arg_set) {
		fprintf(stderr, "Plese set parameter value for writing\n");
		return -1;
	}

	int fdev = get_device(bus_num, i2c_addr);

	if (fdev < 0) {
		return -1;
	}

	int res;

	if (op_read) {
		res = read_data_from_sensor(fdev, command);
	} else {
		res = write_data_to_sensor(fdev, command, write_arg);
	}

	close(fdev);

	return res;
}
示例#22
0
int hex2bin_main(int argc, char **argv)
#endif
{
  struct lib_stdinstream_s stdinstream;
  struct lib_stdsostream_s stdoutstream;
  FAR const char *hexfile;
  FAR const char *binfile;
  FAR char *endptr;
  FAR FILE *instream;
  FAR FILE *outstream;
  unsigned long baseaddr;
  unsigned long endpaddr;
  unsigned long swap;
  int option;
  int ret;

  /* Parse the command line options */

  baseaddr = CONFIG_SYSTEM_HEX2BIN_BASEADDR;
  endpaddr = CONFIG_SYSTEM_HEX2BIN_ENDPADDR;
  swap     = CONFIG_SYSTEM_HEX2BIN_SWAP;

  while ((option = getopt(argc, argv, ":hs:e:w:")) != ERROR)
    {
      switch (option)
        {
#ifdef CONFIG_SYSTEM_HEX2BIN_USAGE
        case 'h':
          show_usage(argv[0], EXIT_SUCCESS);
          break;
#endif

        case 's':
          baseaddr = strtoul(optarg, &endptr, 16);
          if (endptr == optarg)
            {
              fprintf(stderr, "ERROR: Invalid argument to the -s option\n");
              show_usage(argv[0], EXIT_FAILURE);
            }
          break;

        case 'e':
          endpaddr = strtoul(optarg, &endptr, 16);
          if (endptr == optarg)
            {
              fprintf(stderr, "ERROR: Invalid argument to the -e option\n");
              show_usage(argv[0], EXIT_FAILURE);
            }
          break;

        case 'w':
          swap = strtoul(optarg, &endptr, 16);
          if (endptr == optarg || swap > (unsigned long)HEX2BIN_SWAP32)
            {
              fprintf(stderr, "ERROR: Invalid argument to the -w option\n");
              show_usage(argv[0], EXIT_FAILURE);
            }
          break;

        case ':':
          fprintf(stderr, "ERROR: Missing required argument\n");
          show_usage(argv[0], EXIT_FAILURE);
          break;

        default:
        case '?':
          fprintf(stderr, "ERROR: Unrecognized option\n");
          show_usage(argv[0], EXIT_FAILURE);
          break;
        }
    }

  /* There should be two final parameters remaining on the command line */

  if (optind >= argc)
    {
      printf("ERROR: Missing required <hexfile> and <binfile> arguments\n");
      show_usage(argv[0], EXIT_FAILURE);
    }

  hexfile = argv[optind];
  optind++;

  if (optind >= argc)
    {
      printf("ERROR: Missing required <binfile> argument\n");
      show_usage(argv[0], EXIT_FAILURE);
    }

  binfile = argv[optind];
  optind++;

  if (optind < argc)
    {
      printf("ERROR: Garbage at end of command line\n");
      show_usage(argv[0], EXIT_FAILURE);
    }

  /* Open the HEX file for reading */

  instream = fopen(hexfile, "r");
  if (instream == NULL)
    {
      int errcode = errno;
      DEBUGASSERT(errcode > 0);

      fprintf(stderr, "ERROR: Failed to open \"%s\" for reading: %d\n",
              hexfile, errcode);
      return -errcode;
    }

  /* Open the BIN file for reading */

  outstream = fopen(binfile, "wb");
  if (outstream == NULL)
    {
      int errcode = errno;
      DEBUGASSERT(errcode > 0);

      fprintf(stderr, "ERROR: Failed to open \"%s\" for writing: %d\n",
              binfile, errcode);
      fclose(instream);
      return -errcode;
    }

  /* Wrap the FILE streams as standard streams */

  lib_stdinstream(&stdinstream, instream);
  lib_stdsostream(&stdoutstream, outstream);

  /* And do the deed */

  ret = hex2bin(&stdinstream.public, &stdoutstream.public,
                (uint32_t)baseaddr, (uint32_t)endpaddr,
                (enum hex2bin_swap_e)swap);
  if (ret < 0)
    {
      fprintf(stderr, "ERROR: Failed to convert \"%s\" to binary: %d\n",
              ret);
    }

  /* Clean up and return */

  fflush(outstream);
  fclose(instream);
  fclose(outstream);
  return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
示例#23
0
文件: OSEmu.c 项目: subixonfire/OSEmu
int main(int argc, char **argv)
{
	int bg = 0, n, opt, port = 0, accountok = 0;
	struct sockaddr_in servaddr;
	socklen_t len;
	char mbuf[1000];
	unsigned char md5tmp[MD5_DIGEST_LENGTH];

	while((opt = getopt(argc, argv, "bva:p:")) != -1)
	{
		switch(opt)
		{
                case 'b':
                        bg = 1;
                        break;
		case 'a':
		{
			char *ptr = strtok(optarg, ":");
			cs_strncpy((char *)&cl_user, ptr, sizeof(cl_user));
			ptr = strtok(NULL, ":");
			if(ptr)
			{
				cs_strncpy((char *)&cl_passwd, ptr, sizeof(cl_passwd));
				accountok = 1;
			}
			break;
		}
		case 'p':
			port = atoi(optarg);
			break;
		case 'v':
			debuglog = 1;
			break;
		default:
			show_usage(argv[0]);
			exit(0);
		}
	}
	if(port == 0 || accountok == 0)
	{
		show_usage(argv[0]);
		exit(0);
	}

	if (bg && do_daemon(1, 0))
	{
	fprintf(stderr, "Couldn't start as a daemon\n");	
	exit(0);
	}
	
	get_random_bytes_init();

	cl_sockfd = socket(AF_INET, SOCK_DGRAM, 0);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(port);
	bind(cl_sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));

	aes_set_key(&cl_aes_keys, (char *) MD5(cl_passwd, strlen((char *)cl_passwd), md5tmp));

	for(;;)
	{
		len = sizeof(cl_socket);
		n = recvfrom(cl_sockfd, mbuf, sizeof(mbuf), 0, (struct sockaddr *)&cl_socket, &len);

		camd35_recv(mbuf, n);

		if(mbuf[0] == 0 || mbuf[0] == 3)
		{
			camd35_process_ecm(mbuf, n);
		}
		else
		{
			cs_log("unknown/not implemented camd35 command! (%d) n=%d", mbuf[0], n);
		}
	}
}
示例#24
0
int sysio_main(int argc, char *argv[])
#endif
{
	int result = SYSIO_RESULT_FAIL;
	int cmdtype = 0;			/* 1: gpio, 2: pwm, 3: i2c, 4: spi, 5: uart */
	int ret = 0;
	char fail_reason[32] = { 0, };
	char *test_title;

	g_debug = 0;
	switch (argc) {
	case 3:
		g_debug = atoi(argv[2]);
	/* Fall Through */

	case 2:
		if (strcmp(argv[1], "gpio") == 0) {
			cmdtype = 1;
		} else if (strcmp(argv[1], "pwm") == 0) {
			cmdtype = 2;
		} else if (strcmp(argv[1], "i2c") == 0) {
			cmdtype = 3;
		} else if (strcmp(argv[1], "spi") == 0) {
			cmdtype = 4;
		} else if (strcmp(argv[1], "uart") == 0) {
			cmdtype = 5;
		} else {
			show_usage(argv[0]);
		}
		break;

	default:
		show_usage(argv[0]);
		break;
	}

	switch (cmdtype) {
	case 1:					/* gpio */
		test_title = "GPIO";
		ret = systemio_test_gpio(fail_reason);
		break;

	case 2:					/* pwm */
		test_title = "PWM";
		ret = systemio_test_pwm(fail_reason);
		break;

	case 3:					/* i2c */
		test_title = "I2C";
		ret = systemio_test_i2c(fail_reason);
		break;

	case 4:					/* spi */
		test_title = "SPI";
		ret = systemio_test_spi(fail_reason);
		break;

	case 5:					/* uart */
		test_title = "UART";
		ret = systemio_test_uart(fail_reason);
		break;

	default:
		test_title = "N/A";
		goto done;

	}

	/* result is success */
	if (ret == SYSIO_RESULT_SUCCESS) {
		result = SYSIO_RESULT_SUCCESS;
	}

done:
	SYSIO_PRINT("- %s Test Result : %s ",
				test_title,
				result == SYSIO_RESULT_SUCCESS ? "SUCCESS" : "FAIL");
	if (result == SYSIO_RESULT_FAIL) {
		SYSIO_PRINT("(reason : %s) \n", fail_reason);
	} else {
		SYSIO_PRINT("\n");
	}

	return result;
}
示例#25
0
int
tmain(int argc, tchar *argv[])
{
	struct options options;
	int opt_char;
	int i;
	int ret;

	program_invocation_name = get_filename(argv[0]);

	options.to_stdout = false;
	options.decompress = is_gunzip();
	options.force = false;
	options.keep = false;
	options.compression_level = 6;
	options.suffix = T("gz");

	while ((opt_char = tgetopt(argc, argv, optstring)) != -1) {
		switch (opt_char) {
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			options.compression_level =
				parse_compression_level(opt_char, toptarg);
			if (options.compression_level == 0)
				return -1;
			break;
		case 'c':
			options.to_stdout = true;
			break;
		case 'd':
			options.decompress = true;
			break;
		case 'f':
			options.force = true;
			break;
		case 'h':
			show_usage(stdout);
			return 0;
		case 'k':
			options.keep = true;
			break;
		case 'S':
			options.suffix = toptarg;
			break;
		case 'V':
			show_version();
			return 0;
		default:
			show_usage(stderr);
			return 1;
		}
	}

	argv += toptind;
	argc -= toptind;

	if (argc == 0) {
		show_usage(stderr);
		return 1;
	}
	for (i = 0; i < argc; i++) {
		if (argv[i][0] == '-' && argv[i][1] == '\0') {
			msg("This implementation of gzip does not yet "
			    "support reading from standard input.");
			return 1;
		}
	}

	ret = 0;
	if (options.decompress) {
		struct deflate_decompressor *d;

		d = alloc_decompressor();
		if (d == NULL)
			return 1;

		for (i = 0; i < argc; i++)
			ret |= -decompress_file(d, argv[i], &options);

		deflate_free_decompressor(d);
	} else {
		struct deflate_compressor *c;

		c = alloc_compressor(options.compression_level);
		if (c == NULL)
			return 1;

		for (i = 0; i < argc; i++)
			ret |= -compress_file(c, argv[i], &options);

		deflate_free_compressor(c);
	}

	/*
	 * If ret=0, there were no warnings or errors.  Exit with status 0.
	 * If ret=2, there was at least one warning.  Exit with status 2.
	 * Else, there was at least one error.  Exit with status 1.
	 */
	if (ret != 0 && ret != 2)
		ret = 1;

	return ret;
}
示例#26
0
文件: simplelog.c 项目: beekhof/libqb
int32_t
main(int32_t argc, char *argv[])
{
	const char *options = "vhteobdf:";
	int32_t opt;
	int32_t tracer;
	int32_t do_stderr = QB_FALSE;
	int32_t do_stdout = QB_FALSE;
	int32_t do_dump_blackbox = QB_FALSE;
	char *logfile = NULL;
	int32_t log_fd = -1;

	while ((opt = getopt(argc, argv, options)) != -1) {
		switch (opt) {
		case 'd':
			do_dump_blackbox = QB_TRUE;
			break;
		case 't':
			do_threaded = QB_TRUE;
			break;
		case 'e':
			do_stderr = QB_TRUE;
			break;
		case 'o':
			do_stdout = QB_TRUE;
			break;
		case 'b':
			do_blackbox = QB_TRUE;
			break;
		case 'f':
			logfile = optarg;
			break;
		case 'v':
			_log_priority++;
			break;
		case 'h':
		default:
			show_usage(argv[0]);
			exit(0);
			break;
		}
	}

	if (do_dump_blackbox) {
		qb_log_blackbox_print_from_file("simple-log.fdata");
		exit(0);
	}

	signal(SIGSEGV, sigsegv_handler);

	qb_log_init("simple-log", LOG_USER, LOG_INFO);
	qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_THREADED, do_threaded);
	qb_log_tags_stringify_fn_set(my_tags_stringify);

	if (do_stderr) {
		qb_log_filter_fn_set(m_filter);
		qb_log_format_set(QB_LOG_STDERR, "[%p] %4g: %f:%l %b");
		qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);

		tracer = qb_log_custom_open(trace_logger, NULL, NULL, NULL);
		qb_log_ctl(tracer, QB_LOG_CONF_ENABLED, QB_TRUE);
		qb_log_format_set(tracer, "%4g: %n() %b");
		qb_log_filter_ctl2(tracer, QB_LOG_FILTER_ADD,
				   QB_LOG_FILTER_FILE, __FILE__,
				   LOG_TRACE, 200);
	}
	if (do_stdout) {
		qb_log_filter_ctl2(QB_LOG_STDOUT, QB_LOG_FILTER_ADD,
				   QB_LOG_FILTER_FILE, __FILE__,
				   LOG_ALERT, QB_MIN(LOG_DEBUG, _log_priority));
		qb_log_format_set(QB_LOG_STDOUT, "[%p] %4g: %f:%l %b");
		qb_log_ctl(QB_LOG_STDOUT, QB_LOG_CONF_ENABLED, QB_TRUE);
	}
	if (do_blackbox) {
		qb_log_filter_ctl(QB_LOG_BLACKBOX, QB_LOG_FILTER_ADD,
				  QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, 4096);
		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_THREADED, QB_FALSE);
		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE);
	}
	if (logfile) {
		log_fd = qb_log_file_open(logfile);
		qb_log_filter_ctl(log_fd, QB_LOG_FILTER_ADD,
				  QB_LOG_FILTER_FILE, __FILE__, _log_priority);
		qb_log_format_set(log_fd, "[%N] %t %n() [%p] %b");
		qb_log_ctl(log_fd, QB_LOG_CONF_THREADED, do_threaded);
		qb_log_ctl(log_fd, QB_LOG_CONF_ENABLED, QB_TRUE);
	}
	if (do_threaded) {
		qb_log_thread_start();
	}
	qb_log(LOG_DEBUG, "hello");
	qb_log(LOG_INFO, "this is an info");
	qb_log(LOG_NOTICE, "hello - notice?");
	{
		char * str = NULL;
		qb_log(LOG_ERR,
		       "%s-%d-%s-%u",
		       NULL, 952, str, 56);
	}
	func_one();
	func_two();

	if (!do_threaded) {
		/* Disabling syslog here will prevent the logs from
		 * getting flushed in qb_log_fini() if threaded
		 * logging is on.
		 */
		qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);

		qb_log(LOG_WARNING, "no syslog");
		qb_log(LOG_ERR, "no syslog");
	}

#if 0
	// test blackbox
	logfile = NULL;
	logfile[5] = 'a';
#endif
	if (do_blackbox) {
		qb_log_blackbox_write_to_file("simple-log.fdata");
		qb_log_blackbox_print_from_file("simple-log.fdata");
		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_FALSE);
		unlink("simple-log.fdata");
	}
	qb_log_fini();
	return 0;
}
示例#27
0
文件: mkatr.c 项目: dmsc/mkatr
int main(int argc, char **argv)
{
    char *out = 0;
    int i;
    unsigned boot_addr = 0x07; // Standard boot address: $800
    int boot_file = 0; // Next file is boot file
    int exact_size = 0; // Use image of exact size
    int min_size = 0; // Minimum image size

    prog_name = argv[0];

    file_list flist;
    darray_init(flist, 1);
    flist_add_main_dir(&flist);

    for(i=1; i<argc; i++)
    {
        char *arg = argv[i];
        if( arg[0] == '-' )
        {
            char op;
            while( 0 != (op = *++arg) )
            {
                if( op == 'h' || op == '?' )
                    show_usage();
                else if( op == 'b' )
                {
                    if( boot_file )
                        show_error("can specify only one boot file\n");
                    boot_file = 1;
                }
                else if( op == 'x' )
                    exact_size = 1;
                else if( op == 'B' )
                {
                    char *ep;
                    if( i+1 >= argc )
                        show_error("option '-B' needs an argument\n");
                    i++;
                    boot_addr = strtol(argv[i], &ep, 0);
                    if( boot_addr <= 3 || boot_addr >= 0xF0 || !ep || *ep )
                        show_error("argument for option '-B' must be from 3 to 240\n");
                }
                else if( op == 's' )
                {
                    char *ep;
                    if( i+1 >= argc )
                        show_error("option '-s' needs an argument\n");
                    i++;
                    min_size = strtol(argv[i], &ep, 0);
                    if( min_size <= 0 || !ep || *ep )
                        show_error("argument for option '-s' must be a positive integer\n");
                    if( min_size > 65535 * 256 )
                        show_error("maximum image size is 16776960 bytes\n");
                }
                else if( op == 'v' )
                    show_version();
                else
                    show_error("invalid command line option '-%c'. Try '%s -h' for help.\n",
                               op, prog_name);
            }
        }
        else if( !out && boot_file != 1 )
            out = arg;
        else
        {
            flist_add_file(&flist, arg, boot_file == 1);
            if( boot_file )
                boot_file = -1;
        }
    }
    if( !out )
        show_error("missing output file name. Try '%s -h' for help.\n", prog_name);

    struct sfs *sfs = 0;
    if( exact_size )
    {
        // Try biggest size and the try reducing:
        if( min_size < 128*65535 )
            sfs = build_spartafs(128, 65535, boot_addr, &flist);
        if( !sfs )
            sfs = build_spartafs(256, 65535, boot_addr, &flist);
        if( sfs )
        {
            int nsec = 65535 - sfs_get_free_sectors(sfs);
            int ssec = sfs_get_sector_size(sfs);

            if( nsec*ssec < min_size )
                nsec = (min_size + ssec - 1) / ssec;

            for(; nsec>5 && (nsec*ssec)>=min_size; nsec--)
            {
                struct sfs *n = build_spartafs(ssec, nsec, boot_addr, &flist);
                if( !n )
                    break;
                sfs_free(sfs);
                sfs = n;
                if( sfs_get_free_sectors(sfs) > 0 && (nsec-1)*ssec > min_size )
                {
                    nsec = nsec - sfs_get_free_sectors(sfs) + 1;
                    if( nsec*ssec < min_size )
                        nsec = 1 + (min_size + ssec - 1) / ssec;
                }
            }
        }
    }
    else
    {
        for(i=0; !sfs && sectors[i].size; i++)
        {
            if( sectors[i].size * sectors[i].num < min_size )
                continue;
            sfs = build_spartafs(sectors[i].size, sectors[i].num, boot_addr, &flist);
        }
    }
    if( sfs )
        write_atr(out, sfs_get_data(sfs), sfs_get_sector_size(sfs), sfs_get_num_sectors(sfs));
    else
        show_error("can't create an image big enough\n");
    return 0;
}
示例#28
0
int main(int argc, char *argv[])
{
    int     opt, num_thread;
    char    server_url[URL_LENGTH_MAX], ext[UPLOAD_EXT_LENGTH_MAX];
    double  latency, speed, download_speed, upload_speed;
    int     dsize, sindex;

    sindex      = -1;
    num_thread  = 4;
    dsize       = INIT_DOWNLOAD_FILE_RESOLUTION;
    memset(server_url, 0, sizeof(server_url));
    memset(ext, 0, sizeof(ext));

    while ( (opt = getopt(argc, argv, "p:s:lh")) > 0) {

        switch (opt) {
            case 'p':
                if (atoi(optarg) > THREAD_NUM_MAX) {

                    fprintf(stderr, "Only support %d threads meanwhile", THREAD_NUM_MAX);
                    exit(-1);
                }
                num_thread = atoi(optarg);
                break;
            case 's':
                strncpy(server_url, optarg, URL_LENGTH_MAX);
                break;
            case 'l':
                break;
            case 'h':
                show_usage(argv);
                break;
        }
    }

    if (server_url[0] == 0) {
        printf("Retrieving speedtest.net configuration...\n");
        get_client_info(&client);
        printf("Retrieving speedtest.net server list...\n");
        get_closest_server();
        printf("Testing from %s (%s)...\n", client.isp, client.ip);
        printf("Selecting best server based on ping...\n");
        get_best_server(&sindex);
        sscanf(servers[sindex].url, "http://%[^/]/speedtest/upload.%4s", server_url, ext);
        printf("Bestest server: %s(%0.2fKM)\n", server_url, servers[sindex].distance);
    }

    /* Must initialize libcurl before any threads are started */
    curl_global_init(CURL_GLOBAL_ALL);

    latency = test_latency(server_url);
    if (latency == DBL_MAX)
        exit(-1);
    printf("Server latency is %0.0fms\n", latency);

    speed = test_download(server_url, num_thread, dsize, 0);

    dsize = get_download_filename(speed, num_thread);
    fprintf(stderr, "Testing download speed");
    download_speed = test_download(server_url, num_thread, dsize, 1);

    printf("Download speed: %0.2fMbps\n", ((download_speed*8)/(1024*1024)));

    if (ext[0] == 0 && get_upload_extension(server_url, ext) != OK)
        exit(-1);

    speed = test_upload(server_url, num_thread, speed, ext, 0);

    fprintf(stderr, "Testing upload speed");
    upload_speed = test_upload(server_url, num_thread, speed*SPEEDTEST_TIME_MAX, ext, 1);

    printf("Upload speed: %0.2fMbps\n", ((upload_speed*8)/(1024*1024)));

}
示例#29
0
static void parse_args(int argc, char **argv)
{
  char *args = NULL;
  int argidx;

  /* Accumulate CFLAGS up to "--" */

  for (argidx = 1; argidx < argc; argidx++)
    {
      if (strcmp(argv[argidx], "--") == 0)
        {
          g_cc = g_cflags;
          g_cflags = args;
          args = NULL;
        }
      else if (strcmp(argv[argidx], "--dep-debug") == 0)
        {
          g_debug++;
        }
      else if (strcmp(argv[argidx], "--dep-path") == 0)
        {
          argidx++;
          if (argidx >= argc)
            {
              show_usage(argv[0], "ERROR: Missing argument to --dep-path", EXIT_FAILURE);
            }

          if (args)
            {
              append(&args, argv[argidx]);
            }
          else
            {
              append(&g_altpath, argv[argidx]);              
            }
        }
      else if (strcmp(argv[argidx], "--winnative") == 0)
        {
          g_winnative = true;
        }
#ifdef HAVE_WINPATH
      else if (strcmp(argv[argidx], "--winpath") == 0)
        {
          g_winpath = true;
          if (g_topdir)
            {
              free(g_topdir);
            }

          argidx++;
          if (argidx >= argc)
            {
              show_usage(argv[0], "ERROR: Missing argument to --winpath", EXIT_FAILURE);
            }

          g_topdir = strdup(argv[argidx]);
        }
#endif
      else if (strcmp(argv[argidx], "--help") == 0)
        {
          show_usage(argv[0], NULL, EXIT_SUCCESS);
        }
      else
        {
          append(&args, argv[argidx]);
        }
    }

  /* The final thing accumulated is the list of files */

  g_files = args;

  /* If no paths were specified, then look in the current directory only */

  if (!g_altpath)
    {
      g_altpath = strdup(".");
    }

  if (g_debug)
    {
      fprintf(stderr, "SELECTIONS\n");
      fprintf(stderr, "  CC             : \"%s\"\n", g_cc ? g_cc : "(None)");
      fprintf(stderr, "  CFLAGS         : \"%s\"\n", g_cflags ? g_cflags : "(None)");
      fprintf(stderr, "  FILES          : \"%s\"\n", g_files ? g_files : "(None)");
      fprintf(stderr, "  PATHS          : \"%s\"\n", g_altpath ? g_altpath : "(None)");
#ifdef HAVE_WINPATH
      fprintf(stderr, "  Windows Paths  : \"%s\"\n", g_winpath ? "TRUE" : "FALSE");
      if (g_winpath)
        {
          fprintf(stderr, "  TOPDIR         : \"%s\"\n", g_topdir);
        }
#endif
      fprintf(stderr, "  Windows Native : \"%s\"\n", g_winnative ? "TRUE" : "FALSE");
    }

  /* Check for required paramters */

  if (!g_cc)
    {
      show_usage(argv[0], "ERROR: No compiler specified", EXIT_FAILURE);
    }

  if (!g_files)
    {
      /* Don't report an error -- this happens normally in some configurations */

      printf("# No files specified for dependency generataion\n");
      exit(EXIT_SUCCESS);
    }

#ifdef HAVE_WINPATH
  if (g_winnative && g_winpath)
    {
      show_usage(argv[0], "ERROR: Both --winnative and --winpapth makes no sense", EXIT_FAILURE);
    }
#endif
}
示例#30
0
static int process_arg(std::string		&basename,
	std::string		&foutbasename,
	const int		argc,
	char			*argv[],
	std::vector<int> &targets,
	int				&sfid,
	int				&efid)
{
	for (int i = 1; i < argc; ++i)
	{
		std::string arg = argv[i];
		if ((arg == "-h") || (arg == "--help"))
		{
			show_usage(argv[0]);
			return 0;
		}
		else if ((arg == "-i") || (arg == "--input"))
		{
			if (i + 1 < argc){
				basename = argv[i + 1];
				i++;
			}
			else
			{
				std::cerr << "--input option requires one argument." << std::endl;
				return 1;
			}
		}
		else if ((arg == "-o") || (arg == "--output"))
		{
			if (i + 1 < argc){
				foutbasename = argv[i + 1];
				i++;
			}
			else
			{
				std::cerr << "--output option requires one argument." << std::endl;
				return 1;
			}
		}
		else if ((arg == "-t") || (arg == "--target"))
		{
			if (i + 1 < argc){
				int assign = int(strtof(argv[i + 1], NULL));
				targets.push_back(assign);
				i++;
			}
			else
			{
				std::cerr << "--output option requires one argument." << std::endl;
				return 1;
			}
		}
		else if ((arg == "-s") || (arg == "--start")){
			if (i + 1 < argc){
				sfid = int(strtod(argv[i + 1], NULL));
				i++;
			}
			else {
				std::cerr << "--input option requires one argument." << std::endl;
				return 1;
			}
		}
		else if ((arg == "-e") || (arg == "--end")){
			if (i + 1 < argc){
				efid = int(strtod(argv[i + 1], NULL));
				i++;
			}
			else {
				std::cerr << "--input option requires one argument." << std::endl;
				return 1;
			}
		}
		else
		{
			foutbasename = "follow";
			return 2;
		}
	}
}