Beispiel #1
0
bool option_parser::check_required() const
{
	for (auto it = categories_.begin(); it != categories_.end(); ++it) {
		if (!check_required(*it)) {
			return false;
		}
	}

	return true;
}
Beispiel #2
0
bool option_parser::parse(int argc, char * argv[])
{
	build_maps();

	int argi = PARSE_STARTING_INDEX;
	while (argi < argc) {

		switch (type(argv[argi])) {
			case ARGUMENT: {
				parse_arguments(argc, argv, argi);
				return check_required();
			}
			case SHORT_OPTION: {
				argi = parse_short_options(argc, argv, argi);
				if (argi == PARSE_ERROR) {
					return false;
				}
				break;
			}
			case LONG_OPTION: {
				argi = parse_long_option(argc, argv, argi);
				if (argi == PARSE_ERROR) {
					return false;
				}
				break;
			}
			case DELIMITER_OPTION: {
				parse_arguments(argc, argv, argi + 1);
				return check_required();
			}
			default: {
				// huh. out of enumeration?
				assert(false);
			}
		}

	}

	return check_required();
}
bool app_arguments (int argc, char **argv, AppArgument *arguments)
{
        int argi = 1;
        int order = 1;

        if (argc < 0) {
                error_code (InvalidArgument, 1);
                return false;
        }
        if (!argv) {
                error_code (InvalidArgument, 2);
                return false;
        }
        if (!arguments) {
                error_code (InvalidArgument, 3);
                return false;
        }
        if (!arguments_validate (arguments)) {
                error_code (FunctionCall, 1);
                return false;
        }
        set_ordinal (arguments);
        set_default (arguments);
        app_arguments_default_reset ();
        while (argi < argc) {
                if (string_begins_with (argv[argi], "-")) {
                        if (!argument_named (argc, argv, &argi, arguments)) {
                                error_code (FunctionCall, 2);
                                return false;
                        }
                }
                else {
                        if (!argument_ordinal (argc, argv, &argi, arguments, &order)) {
                                error_code (FunctionCall, 3);
                                return false;
                        }
                }
        }
        if (!app_arguments_default (argc, argv, arguments)) {
                error_code (FunctionCall, 4);
                return false;
        }
        if (!check_required (arguments)) {
                error_code (FunctionCall, 5);
                return false;
        }
        return true;
}
Beispiel #4
0
static GKeyFile *
get_session_keyfile (const char *session,
                     char      **actual_session,
                     gboolean   *is_fallback)
{
        GKeyFile *keyfile;
        gboolean  session_runnable;
        char     *value;
        GError *error = NULL;

        *actual_session = NULL;

        g_debug ("fill: *** Getting session '%s'", session);

        keyfile = find_valid_session_keyfile (session);

        if (!keyfile)
                return NULL;

        session_runnable = TRUE;

        value = g_key_file_get_string (keyfile,
                                       GSM_KEYFILE_SESSION_GROUP, GSM_KEYFILE_RUNNABLE_KEY,
                                       NULL);
        if (!IS_STRING_EMPTY (value)) {
                g_debug ("fill: *** Launching helper '%s' to know if session is runnable", value);
                session_runnable = gsm_process_helper (value, GSM_RUNNABLE_HELPER_TIMEOUT, &error);
                if (!session_runnable) {
                        g_warning ("Session '%s' runnable check failed: %s", session,
                                   error->message);
                        g_clear_error (&error);
                }
        }
        g_free (value);

        if (session_runnable) {
                session_runnable = check_required (keyfile);
        }

        if (session_runnable) {
                *actual_session = g_strdup (session);
                if (is_fallback)
                        *is_fallback = FALSE;
                return keyfile;
        }

        g_debug ("fill: *** Session is not runnable");

        /* We can't run this session, so try to use the fallback */
        value = g_key_file_get_string (keyfile,
                                       GSM_KEYFILE_SESSION_GROUP, GSM_KEYFILE_FALLBACK_KEY,
                                       NULL);

        g_key_file_free (keyfile);
        keyfile = NULL;

        if (!IS_STRING_EMPTY (value)) {
                if (is_fallback)
                        *is_fallback = TRUE;
                keyfile = get_session_keyfile (value, actual_session, NULL);
        }
        g_free (value);

        return keyfile;
}
Beispiel #5
0
/** main */
int main (int argc, char * argv[]) {
  const char *infilename = NULL;
  const char *outfilename= NULL;
  //opterr = 0;
  int c;
  int flag_substitute_only=UNFLAGGED;
  int flag_baseline_cleanup=UNFLAGGED;
  int flag_tagorder=UNFLAGGED;
  int flag_check_only=UNFLAGGED;
  int clean_tag=UNFLAGGED;
  flag_be_verbose = FLAGGED;
  while ((c = getopt (argc, argv, "s::cbqt::hi:o:x:")) != -1) {
      switch (c)
           {
           case 'h': /* help */
             help();
             exit (0);
           case 's': /* inplace file substitution (no new output file is written) */
             flag_substitute_only = FLAGGED;
             break;
           case 'b': /* clean up to be baseline tiff conform */
             flag_baseline_cleanup=FLAGGED;
             break;
           case 't': /* try to fix tagorder */
             flag_tagorder=FLAGGED;
             break;
           case 'c': /* reports only if repair needed */
             flag_check_only = FLAGGED; 
             break;
           case 'q': /* disables describing messages */
             flag_be_verbose = UNFLAGGED;
             break;
           case 'i': /* expects infile */
             infilename=optarg;
             break;
           case 'o': /* expects outfile */
             outfilename=optarg;
	     break;
	   case 'x': /* expects tagnumber */
	     clean_tag =atoi(optarg);
	     break;			
           case '?': /* something goes wrong */
             if (optopt == 'i' || optopt == 'o' || optopt == 'x')
               fprintf (stderr, "Option -%c requires an argument.\n", optopt);
             else if (isprint (optopt))
               fprintf (stderr, "Unknown option `-%c'.\n", optopt);
             else if (0 !=optopt) {
               fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
               return (-1);
             }
             break;
           default:
             abort();
           }
  }
  /* added additional checks */
  /* TODO: add check that no inline and no check if cleantag */
  if ((UNFLAGGED != clean_tag) && (clean_tag < 254) && (clean_tag > 65535)) {
    fprintf(stderr, "The option '-x' expects a value in range 254..65535, see '%s -h' for details\n", argv[0]);
    exit(FIXIT_TIFF_CMDLINE_ARGUMENTS_ERROR);
  }
  if ((FLAGGED == flag_substitute_only) && (FLAGGED == flag_check_only)) {
    fprintf (stderr, "The options '-s' and '-c' could not be used in combination, see '%s -h' for details\n", argv[0]);
    exit (FIXIT_TIFF_CMDLINE_ARGUMENTS_ERROR);
  }
  if (NULL == infilename) {
    fprintf (stderr, "You need to specify infile with '-i filename', see '%s -h' for details\n", argv[0]);
    exit (FIXIT_TIFF_MISSED_INFILE);
  }
  if ((FLAGGED!=flag_substitute_only) && (FLAGGED!=flag_check_only)) {
    if (NULL == outfilename) {
      fprintf (stderr, "You need to specify outfile with '-o outfilename', see '%s -h' for details\n", argv[0]);
      exit (FIXIT_TIFF_MISSED_OUTFILE);
    }
  }
  if (FLAGGED == flag_be_verbose) printf ("infile='%s', outfile='%s'\n", infilename, outfilename);
  /* check only if file is valid */
  if (FLAGGED == flag_check_only) {
    /*
     exit (
        check_required(infilename));
        */
    
    exit (
        check_required(infilename) ||
        check_baseline(infilename) || 
        check_datetime(infilename) 
        );
    
  }
  /* try to fix tag order */
  if (FLAGGED == flag_tagorder) {
        copy_file (infilename, outfilename);
	if (FLAGGED == flag_be_verbose) printf ("tagorder cleanup infile='%s', outfile='%s'\n", infilename, outfilename);
        cleanup_tagorder(outfilename);
        exit (FIXIT_TIFF_IS_CORRECTED);
  }
  if (UNFLAGGED != clean_tag) { /* explicite correction via source target, clean given tag */
    copy_file (infilename, outfilename);
    if (FLAGGED == flag_be_verbose) printf ("tag cleanup infile='%s', outfile='%s'\n", infilename, outfilename);
    cleanup_tag(outfilename, clean_tag);
    exit (FIXIT_TIFF_IS_CORRECTED);
  }
  /* inplace correction */
  if (FLAGGED == flag_substitute_only) { /* inplace correction */
    cleanup_datetime(infilename);
    if (FLAGGED == flag_baseline_cleanup) { /* baseline tiff cleanup */
      cleanup_baseline(infilename);
    }
  } else { /* explicite correction via source target */
    copy_file (infilename, outfilename);
    cleanup_datetime(outfilename);
    if (FLAGGED == flag_baseline_cleanup) { /* baseline tiff cleanup */
      if (FLAGGED == flag_be_verbose) printf ("baseline cleanup infile='%s', outfile='%s'\n", infilename, outfilename);
      cleanup_baseline(outfilename);
    }
  }
  exit (FIXIT_TIFF_IS_CORRECTED);
}
Beispiel #6
0
void supersection_t::parse(secfile_t &inf)
{
	std::string s;
	cur_type_t cur;

	int idx = -1; // TODO: size_t

	while(cur_type_t::unknown != (cur = check_string(inf, s))) // TODO: while type = inf.read_string_no_clear() ...
	{
		std::cerr << "Trying to parse section/leaf: " << s << std::endl;

		switch(cur)
		{
		case cur_type_t::multi:
		{
			idx = std::stoi(s);
			std::cerr << "Reading multi object: " << idx << "..." << std::endl;
			auto ptr = leaf_factory->make();
			ptr->_parse(inf);
			multi_sections[idx] = ptr;
		}
		break;

		case cur_type_t::batch:
		{
			auto ptr = leaf_factory->make();
			ptr->_parse(inf);
			multi_sections[++idx] = ptr;
		}
		break;

		case cur_type_t::super:
			super_itr->second->_parse(inf);
			{
				const auto pr = hooks.find(super_itr->second);
				if(pr != hooks.end())
				 (this->*(pr->second))();
			}
			break;

		case cur_type_t::leaf:
			leaf_itr->second->_parse(inf);
			{
				const auto pr = hooks.find(leaf_itr->second);
				if(pr != hooks.end())
				 (this->*(pr->second))();
			}
			break;

		default:
			throw "Impossible";
			break;
		}

	}
	std::cerr << "Left on reading: " << s << ":" << std::endl
		<< " - `" << s << "' is no known super section or leaf" << std::endl;
	if(type == type_t::multi)
	{
		std::cerr << " - `" << s << "' is no number" << std::endl;
	}
	else if(type == type_t::batch)
	{
		std::cerr << " - `" << s << "' does not match the batch string `" << batch_str << "'" << std::endl;
	}
	std::cerr << std::endl;

	if(!check_required() || inf.stream.eof())
	 inf.set_bad();

	process();
}