예제 #1
0
파일: nvc.c 프로젝트: jkone27/nvc
static int syntax_cmd(int argc, char **argv)
{
   static struct option long_options[] = {
      { 0, 0, 0, 0 }
   };

   const int next_cmd = scan_cmd(2, argc, argv);
   int c, index = 0;
   const char *spec = "";
   while ((c = getopt_long(next_cmd, argv, spec, long_options, &index)) != -1) {
      switch (c) {
      case 0:
         // Set a flag
         break;
      case '?':
         fatal("unrecognised syntax option %s", argv[optind - 1]);
      default:
         abort();
      }
   }

   for (int i = optind; i < next_cmd; i++) {
      input_from_file(argv[i]);
      (void)parse();
   }

   if (parse_errors() > 0)
      return EXIT_FAILURE;

   argc -= next_cmd - 1;
   argv += next_cmd - 1;

   return argc > 1 ? process_command(argc, argv) : EXIT_SUCCESS;
}
예제 #2
0
파일: errc.cpp 프로젝트: rsandila/errconv
int C_Errors::execute()
{
  int result;
  if (!isOk()) 
    {
      fprintf( stderr, _("Class did not initialize properly.\n") );
      return( 1 );
    }
  result=create_files();
  if (result) return( result );
  result=parse_errors();
  if (result) { close_files(); return( result ); }
  return( close_files() );
}
예제 #3
0
static int32_t
snmptool_parse_options(struct snmp_toolinfo *snmptoolctx, int argc, char **argv)
{
	int32_t count, optnum = 0;
	int ch;
	const char *opts;

	switch (program) {
		case BSNMPWALK:
			opts = "dhnKA:b:C:I:i:l:M:N:o:P:p:r:s:t:U:v:";
			break;
		case BSNMPGET:
			opts = "aDdehnKA:b:C:I:i:l:M:N:o:P:p:r:s:t:U:v:";
			break;
		case BSNMPSET:
			opts = "adehnKA:b:C:I:i:l:o:P:r:s:t:U:v:";
			break;
		default:
			return (-1);
	}

	while ((ch = getopt(argc, argv, opts)) != EOF) {
		switch (ch) {
		case 'A':
			count = parse_authentication(snmptoolctx, optarg);
			break;
		case 'a':
			count = parse_skip_access(snmptoolctx);
			break;
		case 'b':
			count = parse_buflen(optarg);
			break;
		case 'D':
			count = parse_discovery(snmptoolctx);
			break;
		case 'd':
			count = parse_debug();
			break;
		case 'e':
			count = parse_errors(snmptoolctx);
			break;
		case 'h':
			usage();
			return (-2);
		case 'C':
			count = parse_context(snmptoolctx, optarg);
			break;
		case 'I':
			count = parse_include(snmptoolctx, optarg);
			break;
		case 'i':
			count = parse_file(snmptoolctx, optarg);
			break;
		case 'K':
			count = parse_local_key(snmptoolctx);
			break;
		case 'l':
			count = parse_local_path(optarg);
			break;
		case 'M':
			count = parse_max_repetitions(snmptoolctx, optarg);
			break;
		case 'N':
			count = parse_non_repeaters(snmptoolctx, optarg);
			break;
		case 'n':
			count = parse_num_oids(snmptoolctx);
			break;
		case 'o':
			count = parse_output(snmptoolctx, optarg);
			break;
		case 'P':
			count = parse_privacy(snmptoolctx, optarg);
			break;
		case 'p':
			count = parse_pdu_type(snmptoolctx, optarg);
			break;
		case 'r':
			count = parse_retry(optarg);
			break;
		case 's':
			count = parse_server(optarg);
			break;
		case 't':
			count = parse_timeout(optarg);
			break;
		case 'U':
			count = parse_user_security(snmptoolctx, optarg);
			break;
		case 'v':
			count = parse_version(optarg);
			break;
		case '?':
		default:
			usage();
			return (-1);
		}
		if (count < 0)
			return (-1);
	    optnum += count;
	}

	return (optnum);
}
예제 #4
0
static int analyse(int argc, char **argv)
{
   set_work_lib();

   static struct option long_options[] = {
      { "bootstrap",       no_argument, 0, 'b' },
      { "dump-llvm",       no_argument, 0, 'd' },
      { "prefer-explicit", no_argument, 0, 'p' },
      { 0, 0, 0, 0 }
   };

   int c, index = 0;
   const char *spec = "";
   optind = 1;
   while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) {
      switch (c) {
      case 0:
         // Set a flag
         break;
      case '?':
         // getopt_long already printed an error message
         exit(EXIT_FAILURE);
      case 'b':
         opt_set_int("bootstrap", 1);
         break;
      case 'd':
         opt_set_int("dump-llvm", 1);
         break;
      case 'p':
         opt_set_int("prefer-explicit", 1);
         break;
      default:
         abort();
      }
   }

   size_t unit_list_sz = 32;
   tree_t *units LOCAL = xmalloc(sizeof(tree_t) * unit_list_sz);
   int n_units = 0;

   for (int i = optind; i < argc; i++) {
      input_from_file(argv[i]);

      tree_t unit;
      while ((unit = parse()) && sem_check(unit))
         ARRAY_APPEND(units, unit, n_units, unit_list_sz);
   }

   for (int i = 0; i < n_units; i++) {
      simplify(units[i]);
      bounds_check(units[i]);
   }

   if (parse_errors() + sem_errors() + bounds_errors() > 0)
      return EXIT_FAILURE;

   for (int i = 0; i < n_units; i++) {
      tree_kind_t kind = tree_kind(units[i]);
      const bool need_cgen =
         (kind == T_PACK_BODY)
         || ((kind == T_PACKAGE) && pack_needs_cgen(units[i]));
      if (need_cgen)
         opt(units[i]);
      else
         units[i] = NULL;
   }

   lib_save(lib_work());

   for (int i = 0; i < n_units; i++) {
      if (units[i] != NULL)
         cgen(units[i]);
   }

   return EXIT_SUCCESS;
}
예제 #5
0
파일: nvc.c 프로젝트: ifreemyli/nvc
static int analyse(int argc, char **argv)
{
   set_work_lib();

   static struct option long_options[] = {
      { "bootstrap",       no_argument,       0, 'b' },
      { "dump-llvm",       no_argument,       0, 'd' },
      { "dump-vcode",      optional_argument, 0, 'v' },
      { "prefer-explicit", no_argument,       0, 'p' },   // DEPRECATED
      { "relax",           required_argument, 0, 'r' },
      { 0, 0, 0, 0 }
   };

   int c, index = 0;
   const char *spec = "";
   optind = 1;
   while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) {
      switch (c) {
      case 0:
         // Set a flag
         break;
      case '?':
         fatal("unrecognised analyse option %s", argv[optind - 1]);
      case 'b':
         opt_set_int("bootstrap", 1);
         break;
      case 'd':
         opt_set_int("dump-llvm", 1);
         break;
      case 'v':
         opt_set_str("dump-vcode", optarg ?: "");
         break;
      case 'p':
         warnf("the --prefer-explict option is deprecated: use "
               "--relax=prefer-explict instead");
         opt_set_int("relax", RELAX_PREFER_EXPLICT);
         break;
      case 'r':
         opt_set_int("relax", parse_relax(optarg));
         break;
      default:
         abort();
      }
   }

   size_t unit_list_sz = 32;
   tree_t *units LOCAL = xmalloc(sizeof(tree_t) * unit_list_sz);
   int n_units = 0;

   for (int i = optind; i < argc; i++) {
      input_from_file(argv[i]);

      tree_t unit;
      while ((unit = parse()) && sem_check(unit))
         ARRAY_APPEND(units, unit, n_units, unit_list_sz);
   }

   for (int i = 0; i < n_units; i++) {
      simplify(units[i]);
      bounds_check(units[i]);
   }

   if (parse_errors() + sem_errors() + bounds_errors() > 0)
      return EXIT_FAILURE;

   for (int i = 0; i < n_units; i++) {
      tree_kind_t kind = tree_kind(units[i]);
      const bool need_cgen =
         (kind == T_PACK_BODY)
         || ((kind == T_PACKAGE) && pack_needs_cgen(units[i]));
      if (need_cgen)
         opt(units[i]);
      else
         units[i] = NULL;
   }

   lib_save(lib_work());

   for (int i = 0; i < n_units; i++) {
      if (units[i] != NULL) {
         lower_unit(units[i]);
         cgen(units[i]);
      }
   }

   return EXIT_SUCCESS;
}