Example #1
0
static PFieldWrapper *
create_pfield(const Arg args[], const int nargs)
{
	if (nargs < 1)
		return _display_usage();

	if (!args[0].isType(HandleType)) {
		die("makemonitor (display)", "First argument must be a valid pfield handle.");
		return NULL;
	}
	PField *pfield = (PField *) args[0];

	const char *prefix = NULL, *units = NULL;
	int precision = 3;

	// Handle the optional arguments.
	// <prefix> and <units> strings must appear in that order.  <precision>
	// follows either or both of the strings, or replaces both.  (I.e., it
	// appears after of a list of 0, 1, or 2 strings.)
	if (nargs > 1) {
		if (args[1].isType(StringType)) {
			prefix = args[1];
			if (nargs > 2) {
				if (args[2].isType(StringType)) {
					units = args[2];
					if (nargs > 3) {
						if (args[3].isType(DoubleType))
							precision = (int) args[3];
						else
							return _display_usage();
					}
				}
				else
					precision = (int) args[2];
			}
		}
		else
			precision = (int) args[1];
	}

	static RTcmixDisplay *displaywin = NULL;
	if (displaywin == NULL)					// first time, so make window
		displaywin = createDisplayWindow();
	if (displaywin == NULL) {
		die("makemonitor (display)", "Failed to create display window");
		return NULL;
	}

	return new DisplayPField(pfield, displaywin, prefix, units, precision);
}
Example #2
0
File: main.c Project: 2hdddg/chili
static int _handle_help_command(int argc, char *argv[])
{
    const char *command;

    if (argc < 2){
        _display_usage();
        return 1;
    }

    command = argv[1];

    if (strcmp(command, "all") == 0){
        _display_all_usage();
        return 1;
    }
    if (strcmp(command, "named") == 0){
        _display_named_usage();
        return 1;
    }
    if (strcmp(command, "debug") == 0){
        _display_debug_usage();
        return 1;
    }
    if (strcmp(command, "list") == 0){
        _display_list_usage();
        return 1;
    }


    printf("Unknown help topic: %s\n", command);
    return -1;
}
Example #3
0
int main(int argc, char**argv) {
	int option;
    const char* conf_file = NULL;
    const char* output_dir = NULL;
    const char options[]="c:o:h";

    while ((option = getopt(argc, argv, options)) != -1) {
		switch (option) {
		case 'c':
			conf_file = optarg;
			break;
		case 'o':
			output_dir = optarg;
			break;
		case 'h':
			_display_usage();
			return true;
			break;
		default:
			break;
		}
	}

	if (output_dir == NULL ) {
		printf("No output option found\n");
		_display_usage();
		exit(1);
	}

    if ( conf_file == NULL ) {
		printf("No Configuration file is given\n");
		_display_usage();
		exit(1);
	}

    if ( parse_config_file(output_dir, conf_file, OUTPUT_ALL) == false ) {
        exit(1);
    }

    display_data_from_directory(output_dir, DISPLAY_ALL);

	exit(0);
}
Example #4
0
File: main.c Project: 2hdddg/chili
int main(int argc, char *argv[])
{
    const char *command;

    if (argc == 1){
        printf("Specify command\n");
        goto on_error;
    }

    command = argv[1];
    /* Adjust for using getopt in command
     * parsers */
    argc = argc - 1;
    argv = argv + 1;

    if (strcmp(command, "all") == 0){
        return _handle_all_command(argc, argv) > 0 ?
            0 : 1;
    }
    else if (strcmp(command, "named") == 0){
        return _handle_named_command(argc, argv) > 0 ?
            0 : 1;
    }
    else if (strcmp(command, "list") == 0){
        return _handle_list_command(argc, argv) >= 0 ?
            0 : 1;
    }
    else if (strcmp(command, "debug") == 0){
        /* Debugger needs path to chili */
        return _handle_debug_command(argv[0], argc, argv) >= 0 ?
            0 : 1;
    }
    else if (strcmp(command, "help") == 0){
        return _handle_help_command(argc, argv) >= 0 ?
            0 : 1;
    }

    printf("Unknown command: %s\n", command);

on_error:
    _display_usage();
    return 1;
}
Example #5
0
int main (int argc, char * const argv[])
{
  enum usim_command {
    USIM_COMMAND_NONE,
    USIM_COMMAND_PRINT,
    USIM_COMMAND_GEN,
  } command = USIM_COMMAND_NONE;

  char *output_dir = NULL;
  char *conf_file = NULL;
  const char options[]="gpc:o:h";
  const struct option options_long_option[] = {
    {"gen",    no_argument, NULL, 'g'},
    {"print",  no_argument, NULL, 'p'},
    {"conf",   required_argument, NULL, 'c'},
    {"output", required_argument, NULL, 'o'},
    {"help",   no_argument, NULL, 'h'},
    {NULL,     0,           NULL, 0}
  };
  int option_index;
  char option_short;

  /*
   * Read command line parameters
   */
  while ( true ) {
    option_short = getopt_long(argc, argv, options, options_long_option, &option_index );

    if ( option_short == -1 )
      break;

    switch (option_short) {
      case 'c':
        conf_file = optarg;
        break;
      case 'g':
        command = USIM_COMMAND_GEN;
        break;
      case 'p':
        command = USIM_COMMAND_PRINT;
        break;
      case 'o':
        output_dir = optarg;
        break;
      default:
        break;
    }
  }

  if ( command == USIM_COMMAND_NONE ) {
    _display_usage(argv[0]);
    exit(EXIT_SUCCESS);
  }

  /* compute default data directory if no output_dir is given */
  if ( output_dir == NULL ) {
    output_dir = getenv(OUTPUT_DIR_ENV);

    if (output_dir == NULL) {
      output_dir = getenv(DEFAULT_NAS_PATH);
    }

    if (output_dir == NULL) {
      fprintf(stderr, "%s and %s environment variables are not defined trying local directory",
              OUTPUT_DIR_ENV, DEFAULT_NAS_PATH);
      output_dir = ".";
    }
  }

  if ( command == USIM_COMMAND_GEN ) {
    if ( conf_file == NULL ) {
      printf("No Configuration file is given\n");
      _display_usage(argv[0]);
      exit(EXIT_FAILURE);
    }

    if ( parse_config_file(output_dir, conf_file, OUTPUT_USIM) == false ) {
      exit(EXIT_FAILURE);
    }
  }

  if ( display_data_from_directory(output_dir, DISPLAY_USIM) == 0) {
    fprintf(stderr, "No USIM files found in %s\n", output_dir);
  }

  exit(EXIT_SUCCESS);
}