예제 #1
0
 args_t::args_t( int argc, const char * argv[] ) :
 output( stdout ),
 input1( stdin ),
 input2( NULL ),
 distance( DEFAULT_DISTANCE ),
 min_distance( DEFAULT_MIN_DISTANCE ),
 ambig( DEFAULT_AMBIG ),
 format ( DEFAULT_FORMAT ),
 overlap ( DEFAULT_OVERLAP ),
 do_bootstrap( false ),
 do_bootstrap_two_files ( false ),
 do_count( false ),
 quiet( false ),
 do_fst( false ),
 report_self ( false ),
 counts_in_name ( DEFAULT_COUNTS_IN_NAME ),
 include_prob( DEFAULT_INCLUDE_PROB ),
 ambigs_to_resolve(NULL),
 resolve_fraction(DEFAULT_FRACTION)
 {
     // skip arg[0], it's just the program name
   for (int i = 1; i < argc; ++i ) {
     const char * arg = argv[i];
     
     if ( arg[0] == '-' && arg[1] == '-' ) {
       if ( !strcmp( &arg[2], "help" ) ) help();
       else if ( !strcmp( &arg[2], "version" ) ) version();
       else
         ERROR( "unknown argument: %s", arg );
     }
     else if ( arg[0] == '-' ) {
       if ( !strcmp( &arg[1], "h" ) ) help();
       else if (  arg[1] == 'v' ) version();
       else if (  arg[1] == 'o' ) parse_output( next_arg (i, argc, argv) );
       else if (  arg[1] == 't' ) parse_distance ( next_arg (i, argc, argv) );
       else if (  arg[1] == 'w' ) parse_min_distance ( next_arg (i, argc, argv) );
       else if (  arg[1] == 'l')  parse_overlap( next_arg (i, argc, argv) );
       else if (  arg[1] == 'f')  parse_format( next_arg (i, argc, argv) );
       else if (  arg[1] == 'a')  parse_ambig( next_arg (i, argc, argv) );
       else if (  arg[1] == 's')  parse_second_in( next_arg (i, argc, argv) );
       else if (  arg[1] == 'd')  parse_counts_in_name( next_arg (i, argc, argv) );
       else if (  arg[1] == 'u')  parse_include_prob( next_arg (i, argc, argv) );
       else if (  arg[1] == 'b')  parse_bootstrap();
       else if (  arg[1] == 'r')  parse_bootstrap_two_files ();
       else if (  arg[1] == 'c')  parse_count();
       else if (  arg[1] == 'q')  parse_quiet();
       else if (  arg[1] == 'm')  parse_fst();
       else if (  arg[1] == '0')  parse_report_self();
       else if (  arg[1] == 'g')  parse_fraction( next_arg (i, argc, argv) );
       else
         ERROR( "unknown argument: %s", arg );
     }
     else
       if (i == argc-1) {
         parse_input (arg);
       } else {
         ERROR( "unknown argument: %s", arg );
       }
   }
 }
예제 #2
0
/**
 * random_cor_tool_ok_clicked_cb:
 * @button:
 * @state:
 *
 * Retrieve the information from the dialog and call the appropriate tool.
 * Note that we assume that the ok_button is only active if the entry fields
 * contain sensible data.
 **/
static void
random_cor_tool_ok_clicked_cb (GtkWidget *button, RandomCorToolState *state)
{
	data_analysis_output_t  *dao;
	tools_data_random_cor_t  *data;
	gint err;

	data = g_new0 (tools_data_random_cor_t, 1);

	dao  = parse_output ((GnmGenericToolState *)state, NULL);
	err = entry_to_int (GTK_ENTRY (state->count_entry), &data->count, FALSE);
	data->matrix = gnm_expr_entry_parse_as_value
		(GNM_EXPR_ENTRY (state->base.input_entry),
		 state->base.sheet);

	data->variables = data->matrix->v_range.cell.b.row -
		data->matrix->v_range.cell.a.row + 1;

	data->matrix_type = gnm_gui_group_value
		(state->base.gui, matrix_group);


	if (!cmd_analysis_tool (GNM_WBC (state->base.wbcg),
				state->base.sheet,
				dao, data, tool_random_cor_engine, TRUE) &&
	    (button == state->base.ok_button))
		gtk_widget_destroy (state->base.dialog);
}
예제 #3
0
파일: argparse_cf.cpp 프로젝트: spond/TN93
 args_t::args_t( int argc, const char * argv[] ) :
 output( stdout ),
 input( stdin ),
 ambig( DEFAULT_AMBIG ),
 data ( DEFAULT_DATA ),
 counts_in_name ( DEFAULT_COUNTS_IN_NAME ),
 quiet (false)
 {
     // skip arg[0], it's just the program name
   for (int i = 1; i < argc; ++i ) {
     const char * arg = argv[i];
     
     if ( arg[0] == '-' && arg[1] == '-' ) {
       if ( !strcmp( &arg[2], "help" ) ) help();
       else
         ERROR( "unknown argument: %s", arg );
     }
     else if ( arg[0] == '-' ) {
       if ( !strcmp( &arg[1], "h" ) ) help();
       else if (  arg[1] == 'o' ) parse_output( next_arg (i, argc, argv) );
       else if (  arg[1] == 'a')  parse_ambig( next_arg (i, argc, argv) );
       else if (  arg[1] == 't')  parse_data ( next_arg (i, argc, argv) );
       else if (  arg[1] == 'd')  parse_counts_in_name( next_arg (i, argc, argv) );
       else if (  arg[1] == 'q')  parse_quiet ( );
       else
         ERROR( "unknown argument: %s", arg );
     }
     else
       if (i == argc-1) {
         parse_input (arg);
       } else {
         ERROR( "unknown argument: %s", arg );
       }
   }
 }
예제 #4
0
CommandBlock *new_command_block(LinkedList *tokens) {
	CommandBlock *result = malloc(sizeof(CommandBlock));
	result->valid = true;
	result->input = NULL;
	result->output = NULL;
	result->command = NULL;

	int success = parse_command(result, tokens);
	if (success == -1) {
		result->valid = false;
		return result;
	}
	
	while (get_length(tokens) > 0) {
		char *tok = (char *) pop_front(tokens);
		if (tok[0] == '>') {
			free(tok);
			if (parse_output(result, tokens) == -1) {
				result->valid = false;
				return result;
			}
		} else if (tok[0] == '<') {
			free(tok);
			if (parse_input(result, tokens) == -1) {
				result->valid = false;
				return result;
			}
		} else {
			free(tok);
			exit(1);
		}
	}

	return result;
}
/**
 * kaplan_meier_tool_ok_clicked_cb:
 * @button:
 * @state:
 *
 * Retrieve the information from the dialog and call the kaplan_meier_tool.
 * Note that we assume that the ok_button is only active if the entry fields
 * contain sensible data.
 **/
static void
kaplan_meier_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
			      KaplanMeierToolState *state)
{
	data_analysis_output_t  *dao;
	analysis_tools_data_kaplan_meier_t  *data;

	data = g_new0 (analysis_tools_data_kaplan_meier_t, 1);
	dao  = parse_output ((GenericToolState *)state, NULL);


	data->base.wbc = WORKBOOK_CONTROL (state->base.wbcg);

	if (state->base.warning_dialog != NULL)
		gtk_widget_destroy (state->base.warning_dialog);

	data->base.range_1 = gnm_expr_entry_parse_as_value
		(GNM_EXPR_ENTRY (state->base.input_entry), state->base.sheet);

	data->censored = gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (state->censorship_button));

	if (data->censored)
		data->base.range_2 =  gnm_expr_entry_parse_as_value
			(GNM_EXPR_ENTRY (state->base.input_entry_2), state->base.sheet);
	else
		data->base.range_2 = NULL;

	data->censor_mark = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (state->censor_spin_from));
	data->censor_mark_to = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (state->censor_spin_to));

	data->group_list = kaplan_meier_tool_get_groups (state);
	if (data->group_list == NULL) {
		data->range_3 = NULL;
		data->logrank_test = FALSE;
	} else {
		data->range_3 = gnm_expr_entry_parse_as_value
			(GNM_EXPR_ENTRY (state->groups_input), state->base.sheet);
		data->logrank_test = gtk_toggle_button_get_active (
			GTK_TOGGLE_BUTTON (state->logrank_button));
	}

	data->median = gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (glade_xml_get_widget
				   (state->base.gui,
				    "median-button")));
	data->chart = gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (state->graph_button));
	data->ticks = gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (state->tick_button));
	data->std_err = gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (state->std_error_button));

	if (!cmd_analysis_tool (WORKBOOK_CONTROL (state->base.wbcg), state->base.sheet,
				dao, data, analysis_tool_kaplan_meier_engine))
		gtk_widget_destroy (state->base.dialog);

	return;
}
예제 #6
0
void test_parse_output_gets_impossible_halts(CuTest *tc) {
    FILE * output;
    char param[] = "/tmp";

    int expected = 1;
    int actual = parse_output( param, &output );

    CuAssertIntEquals(tc, expected, actual);
}
예제 #7
0
void test_parse_output_gets_dash_returns_stdout(CuTest *tc) {
    FILE * actual_output;
    char param[] = "-";

    FILE * expected_output = stdout;
    int result = parse_output( param, &actual_output );

    CuAssertPtrEquals(tc, expected_output, actual_output);
}
예제 #8
0
int main (int argc, char **argv) {
    isotopes_t *isotopes=load_isotope_table(XSTR(MASSES_DATA));
    if(!isotopes) {
        fprintf(stderr, "Could not load table of isotopes from %s!\n", XSTR(MASSES_DATA));
        return 0;
    }
    int Z1, Z2, i, j;
    /*
    for(i=0; i<isotopes->n_isotopes; i++) {
        isotope=&isotopes->i[i];
        if(isotope->abundance > 1e-4) {
            fprintf(stdout, "%i %i %i %s %lf %lf\n", isotope->N, isotope->A, isotope->Z, isotope->name, isotope->mass, isotope->abundance);
        }
    }
    */
    double xmin=10.0; /* keV/amu */
    double xmax=10000.0; 
    int xsteps=XSTEPS; /* steps numbered 0, 1, 2, ...., vsteps-1 */
    int z_max=Z_MAX; /* 1 < Z < z_max */ 
    isotope_t *ion, *target;
    i=0;

    fprintf(stdout, "source=srim\nz1-min=%i\nz1-max=%i\nz2-min=%i\nz2-max=%i\nsto-unit=eV/(1e15 atoms/cm2)\nx-unit=keV/u\nformat=ascii\nx-min=%e\nx-max=%e\nx-points=%i\nx-scale=log10\n==END-OF-HEADER==\n", 1, z_max, 1, z_max, xmin, xmax, xsteps);
    for(Z1=1; Z1<=z_max; Z1++) {
        ion = find_most_abundant_isotope(isotopes, Z1);
        for(Z2=1; Z2<=z_max; Z2++) {
            i++;
            target = find_most_abundant_isotope(isotopes, Z2);
            fprintf(stdout, "#STOPPING IN Z1=%i Z2=%i\n", Z1, Z2);
            if(ion && target) {
                fprintf(stderr, "SR.IN will be generated for %s in %s.\n", ion->name, target->name);
                generate_sr_in(SR_FILE_PATH, ion, target, xsteps, xmin, xmax);
                fprintf(stderr, "Running SRModule, please wait.\n");
                if(run_srim(SR_MODULE_PATH)) {
                    if(parse_output(SR_OUTPUT_FILE, ion, xsteps)) {
                        fprintf(stderr, "Z1=%i. Z2=%i. OK. %i/%i.\n", Z1, Z2, i, (z_max-1)*(z_max-1));
                    } else {
                        fprintf(stderr, "Not OK.");
                    }
                } else {
                    fprintf(stderr, "Error in running SRModule. You should really consider running this program in the working directory of SR Module.\n");
                    exit(0);
                }
            } else {
                for(j=0; j<xsteps; j++) {
                    fprintf(stdout, "%e\n", 0.0); /* no isotopes found for either Z1 or Z2, fill with zeros */
                }
                fflush(stdout);
            }
        }
    }
    free(isotopes);
    return 1;
}
예제 #9
0
/**
 * advanced_filter_ok_clicked_cb:
 * @button:
 * @state:
 *
 * Retrieve the information from the dialog and call the advanced_filter.
 * Note that we assume that the ok_button is only active if the entry fields
 * contain sensible data.
 **/
static void
advanced_filter_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
			       AdvancedFilterState *state)
{
	data_analysis_output_t  dao;
	GnmValue                   *input;
	GnmValue                   *criteria;
	char                    *text;
	GtkWidget               *w;
	int                     err = 0;
	gboolean                unique;

	input = gnm_expr_entry_parse_as_value (
		GNM_EXPR_ENTRY (state->input_entry), state->sheet);

	criteria = gnm_expr_entry_parse_as_value
		(state->input_entry_2, state->sheet);

        parse_output ((GenericToolState *) state, &dao);

	w = glade_xml_get_widget (state->gui, "unique-button");
	unique = (1 == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)));

	err = advanced_filter (WORKBOOK_CONTROL (state->wbcg),
			       &dao, input, criteria, unique);

	value_release (input);
	value_release (criteria);

	switch (err) {
	case OK:
		gtk_widget_destroy (state->dialog);
		break;
	case ERR_INVALID_FIELD:
		error_in_entry ((GenericToolState *) state,
				GTK_WIDGET (state->input_entry_2),
				_("The given criteria are invalid."));
		break;
	case NO_RECORDS_FOUND:
		go_gtk_notice_nonmodal_dialog ((GtkWindow *) state->dialog,
					  &(state->warning_dialog),
					  GTK_MESSAGE_INFO,
					  _("No matching records were found."));
		break;
	default:
		text = g_strdup_printf (_("An unexpected error has occurred: "
					  "%d."), err);
		error_in_entry ((GenericToolState *) state,
				GTK_WIDGET (state->input_entry), text);
		g_free (text);
		break;
	}
	return;
}
scanning_for_playlists_dlg::scanning_for_playlists_dlg(wxWindow *parent,
                                                       wxString const &original_file_name,
                                                       wxArrayString const &original_output,
                                                       std::vector<wxString> const &other_file_names)
  : wxDialog{parent, wxID_ANY, Z("Scanning directory")}
#if defined(SYS_WINDOWS)
  , m_taskbar_progress{}
#endif  // SYS_WINDOWS
  , m_scanner{new scan_directory_thread_c{this, other_file_names}}
  , m_aborted{}
  , m_progress{}
  , m_max_progress{other_file_names.size()}
  , m_start_time{}
  , m_next_remaining_time_update{}
{
	m_st_progress           = new wxStaticText(this, wxID_ANY,    wxU(boost::format(NY("%1% of %2% file processed", "%1% of %2% files processed", other_file_names.size())) % 0 % other_file_names.size()));
	m_g_progress            = new wxGauge(     this, wxID_ANY,    m_max_progress);
  auto st_remaining_label = new wxStaticText(this, wxID_ANY,    Z("Remaining time:"));
	m_st_remaining_time     = new wxStaticText(this, wxID_ANY,    Z("is being estimated"));
	m_b_abort               = new wxButton(    this, wxID_CANCEL, Z("&Abort"));

#if defined(SYS_WINDOWS)
  if (get_windows_version() >= WINDOWS_VERSION_7) {
    m_taskbar_progress = new taskbar_progress_c(mdlg);
    m_taskbar_progress->set_state(TBPF_NORMAL);
    m_taskbar_progress->set_value(0, other_file_names.size());
  }
#endif  // SYS_WINDOWS

  auto siz_remaining_time = new wxBoxSizer(wxHORIZONTAL);
  siz_remaining_time->Add(st_remaining_label,  0, wxALL, 5);
  siz_remaining_time->Add(m_st_remaining_time, 0, wxALL, 5);

	auto siz_button = new wxBoxSizer(wxHORIZONTAL);
	siz_button->AddStretchSpacer();
	siz_button->Add(m_b_abort, 0, wxALL, 5);
	siz_button->AddStretchSpacer();

	auto siz_all = new wxBoxSizer(wxVERTICAL);
	siz_all->Add(m_st_progress,      0, wxALL,            5);
	siz_all->Add(m_g_progress,       0, wxALL | wxEXPAND, 5);
	siz_all->Add(siz_remaining_time, 0, wxALL,            5);
	siz_all->Add(siz_button,         1, wxEXPAND,         5);

	SetSizerAndFit(siz_all);
  auto min_size = GetMinSize();
  SetSize(wxSize{min_size.GetWidth() + 50, min_size.GetHeight()});
	Layout();

	Centre(wxBOTH);

  parse_output(original_file_name, original_output);
}
예제 #11
0
static void
monitor_get_status(const gchar *monitor_cmd, service_info_t *si)
{
	gchar *str_si;

	if (strlen(monitor_cmd) > 0) {
		TRACE("Collecting the service state");
		parse_output(monitor_cmd, si);
		str_si =  service_info_to_string(si);
		DEBUG("SVC state: %s", str_si);
		g_free(str_si);
	}
}
std::vector<std::vector<std::bitset<8>>>
	IcarusFitnessCalculator::simular(int index) {
	auto individuo_file = std::string("individuo") + to_string(index);
	std::string program_call = std::string("vvp ") + individuo_file;
	FILE* simulador = popen(program_call.c_str(), "r");
	if (simulador == nullptr) {
		std::cerr << "Nao consegui executar o simulador vvp.\n";
		std::exit(1);
	}
	auto parsed_output = parse_output(simulador);
	pclose(simulador);
	return parsed_output;
}
예제 #13
0
void TinySpawn::run()
{
  // Working directory.
  const gchar *workingdirectory = NULL;
  if (!myworkingdirectory.empty())
    workingdirectory = myworkingdirectory.c_str();
  // Store arguments in argv.
  char *argv [arguments.size() + 2];
  argv[0] = (char *)myprogram;
  for (unsigned int i = 0; i < arguments.size(); i++) {
    argv[i + 1] = (char *)arguments[i].c_str();
  }
  // Terminate argv.
  argv[arguments.size() + 1] = NULL;
  // Spawn flags.
  int flags = G_SPAWN_SEARCH_PATH;
  // Possible pipes.
  gchar *standard_output = NULL;
  gchar *standard_error = NULL;
  gchar **standard_output_pointer = NULL;
  gchar **standard_error_pointer = NULL;
  if (myread) {
    standard_output_pointer = &standard_output;
    standard_error_pointer = &standard_error;
  }
  // Spawn process.
  result = g_spawn_sync(workingdirectory, argv, NULL, (GSpawnFlags) flags, NULL, NULL, standard_output_pointer, standard_error_pointer, &exitstatus, NULL);
  // Handle case we didn't spawn the process.
  if (!result) {
    exitstatus = -1;
    string message = myprogram;
    message.append(_(" didn't spawn"));
    g_critical("%s", message.c_str());
    return;
  }
  // Handle reading the output.
  if (myread) {
    // In sync mode we have gchar * output.
    ParseLine parse_output (standard_output);
    standardout = parse_output.lines;
    ParseLine parse_error (standard_error);
    standarderr = parse_error.lines;
    // Free data.
    if (standard_output)
      g_free(standard_output);
    if (standard_error)
      g_free(standard_error);
  }
}
예제 #14
0
void query(const std::string& sql_query) {
        try {
                parsed_query p = parser(sql_query);
                std::cout << parse_output(p);
                std::cout << "===========================================" << std::endl;
                if(p.is_join) {
                        execute_join(p);
                        return;
                }
                execute(p);
                std::cout << "===========================================" << std::endl;
        } catch(std::string& s) {
                std::cout << "Error: " << s << std::endl;
        }
        catch(char const* s) {
                std::cout << "Error: " << s << std::endl;
        }
}
int
scanning_for_playlists_dlg::scan() {
  m_start_time                 = get_current_time_millis();
  m_next_remaining_time_update = m_start_time + 8000;

  m_scanner->Create();
  m_scanner->Run();
  ShowModal();

  if (m_aborted)
    return wxID_CANCEL;

  for (auto &pair : m_scanner->get_output())
    parse_output(pair.first, pair.second);

  brng::sort(m_playlists, [](playlist_file_cptr const &a, playlist_file_cptr const &b) { return a->file_name < b->file_name; });

  return wxID_OK;
}
예제 #16
0
void SHDLParser::parse()
{
    std::string line;
    unsigned int num = 0;

    out << "include \"base.scdl\"" << std::endl;

    try {
        while (!in.eof()) {
            getline(in, line);
            if (line.empty())
                continue;

            std::vector<std::string> components;
            boost::split(components, line, boost::is_any_of(":"));

            if (components[0] == "input") {
                parse_input(components);
            }
            else if (components[0] == "result") {
                outputs_to_process.push_back(components);
            }
            else if (components[0] == "gate") {
                parse_gate(components);
            }
        }
        std::vector<std::vector<std::string> >::iterator itr;
        for (itr = outputs_to_process.begin(); itr != outputs_to_process.end();
             itr++) {
            std::vector<std::string> components = *itr;
            parse_output(components);
        }
    }
    catch (const char *s) {
        throw s;
    }

}
예제 #17
0
static void
cb_fill_series_ok_clicked (G_GNUC_UNUSED GtkWidget *button,
			   FillSeriesState *state)
{
	GtkWidget       *radio;
	fill_series_t           *fs;
	data_analysis_output_t  *dao;

	fs = g_new0 (fill_series_t, 1);
	dao  = parse_output ((GenericToolState *)state, NULL);

	/* Read the `Series in' radio buttons. */
	radio = go_gtk_builder_get_widget (state->base.gui, "series_in_rows");
	fs->series_in_rows = ! gnm_gtk_radio_group_get_selected
	        (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)));

	/* Read the `Type' radio buttons. */
	radio = go_gtk_builder_get_widget (state->base.gui, "type_linear");
	fs->type = gnm_gtk_radio_group_get_selected
	        (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)));

	/* Read the `Date unit' radio buttons. */
	radio = go_gtk_builder_get_widget (state->base.gui, "unit_day");
	fs->date_unit = gnm_gtk_radio_group_get_selected
	        (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)));

	fs->is_step_set = ! entry_to_float (GTK_ENTRY (state->step_entry),
					    &fs->step_value, TRUE);
	fs->is_stop_set = ! entry_to_float (GTK_ENTRY (state->stop_entry),
					    &fs->stop_value, TRUE);
	entry_to_float (GTK_ENTRY (state->start_entry),
			&fs->start_value, TRUE);

	if (!cmd_analysis_tool (WORKBOOK_CONTROL (state->base.wbcg),
				state->base.sheet,
				dao, fs, fill_series_engine, TRUE))
		gtk_widget_destroy (state->base.dialog);
}
int
scanning_for_playlists_dlg::scan() {
  m_start_time                 = get_current_time_millis();
  m_next_remaining_time_update = m_start_time + 8000;

  m_scanner->Create();
  m_scanner->Run();
  ShowModal();

#if defined(SYS_WINDOWS)
  if (m_taskbar_progress)
    m_taskbar_progress->set_state(TBPF_NOPROGRESS);
#endif  // SYS_WINDOWS

  if (m_aborted)
    return wxID_CANCEL;

  for (auto &pair : m_scanner->get_output())
    parse_output(pair.first, pair.second);

  brng::sort(m_playlists, [](playlist_file_cptr const &a, playlist_file_cptr const &b) { return a->file_name < b->file_name; });

  return wxID_OK;
}
예제 #19
0
static void
parse_named_action(enum ofputil_action_code code,
                   char *arg, struct ofpbuf *ofpacts)
{
    struct ofpact_tunnel *tunnel;
    uint16_t vid;
    uint16_t ethertype;
    ovs_be32 ip;
    uint8_t pcp;
    uint8_t tos;

    switch (code) {
    case OFPUTIL_ACTION_INVALID:
        NOT_REACHED();

    case OFPUTIL_OFPAT10_OUTPUT:
    case OFPUTIL_OFPAT11_OUTPUT:
        parse_output(arg, ofpacts);
        break;

    case OFPUTIL_OFPAT10_SET_VLAN_VID:
    case OFPUTIL_OFPAT11_SET_VLAN_VID:
        vid = str_to_u32(arg);
        if (vid & ~VLAN_VID_MASK) {
            ovs_fatal(0, "%s: not a valid VLAN VID", arg);
        }
        ofpact_put_SET_VLAN_VID(ofpacts)->vlan_vid = vid;
        break;

    case OFPUTIL_OFPAT10_SET_VLAN_PCP:
    case OFPUTIL_OFPAT11_SET_VLAN_PCP:
        pcp = str_to_u32(arg);
        if (pcp & ~7) {
            ovs_fatal(0, "%s: not a valid VLAN PCP", arg);
        }
        ofpact_put_SET_VLAN_PCP(ofpacts)->vlan_pcp = pcp;
        break;

    case OFPUTIL_OFPAT12_SET_FIELD:
        set_field_parse(arg, ofpacts);
        break;

    case OFPUTIL_OFPAT10_STRIP_VLAN:
    case OFPUTIL_OFPAT11_POP_VLAN:
        ofpact_put_STRIP_VLAN(ofpacts);
        break;

    case OFPUTIL_OFPAT11_PUSH_VLAN:
        ethertype = str_to_u16(arg, "ethertype");
        if (ethertype != ETH_TYPE_VLAN_8021Q) {
            /* XXX ETH_TYPE_VLAN_8021AD case isn't supported */
            ovs_fatal(0, "%s: not a valid VLAN ethertype", arg);
        }
        ofpact_put_PUSH_VLAN(ofpacts);
        break;

    case OFPUTIL_OFPAT11_SET_QUEUE:
        ofpact_put_SET_QUEUE(ofpacts)->queue_id = str_to_u32(arg);
        break;


    case OFPUTIL_OFPAT10_SET_DL_SRC:
    case OFPUTIL_OFPAT11_SET_DL_SRC:
        str_to_mac(arg, ofpact_put_SET_ETH_SRC(ofpacts)->mac);
        break;

    case OFPUTIL_OFPAT10_SET_DL_DST:
    case OFPUTIL_OFPAT11_SET_DL_DST:
        str_to_mac(arg, ofpact_put_SET_ETH_DST(ofpacts)->mac);
        break;

    case OFPUTIL_OFPAT10_SET_NW_SRC:
    case OFPUTIL_OFPAT11_SET_NW_SRC:
        str_to_ip(arg, &ip);
        ofpact_put_SET_IPV4_SRC(ofpacts)->ipv4 = ip;
        break;

    case OFPUTIL_OFPAT10_SET_NW_DST:
    case OFPUTIL_OFPAT11_SET_NW_DST:
        str_to_ip(arg, &ip);
        ofpact_put_SET_IPV4_DST(ofpacts)->ipv4 = ip;
        break;

    case OFPUTIL_OFPAT10_SET_NW_TOS:
    case OFPUTIL_OFPAT11_SET_NW_TOS:
        tos = str_to_u32(arg);
        if (tos & ~IP_DSCP_MASK) {
            ovs_fatal(0, "%s: not a valid TOS", arg);
        }
        ofpact_put_SET_IPV4_DSCP(ofpacts)->dscp = tos;
        break;

    case OFPUTIL_OFPAT11_DEC_NW_TTL:
        NOT_REACHED();

    case OFPUTIL_OFPAT10_SET_TP_SRC:
    case OFPUTIL_OFPAT11_SET_TP_SRC:
        ofpact_put_SET_L4_SRC_PORT(ofpacts)->port = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT10_SET_TP_DST:
    case OFPUTIL_OFPAT11_SET_TP_DST:
        ofpact_put_SET_L4_DST_PORT(ofpacts)->port = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT10_ENQUEUE:
        parse_enqueue(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_RESUBMIT:
        parse_resubmit(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL:
    case OFPUTIL_NXAST_SET_TUNNEL64:
        tunnel = ofpact_put_SET_TUNNEL(ofpacts);
        tunnel->ofpact.compat = code;
        tunnel->tun_id = str_to_u64(arg);
        break;

    case OFPUTIL_NXAST_WRITE_METADATA:
        parse_metadata(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_SET_QUEUE:
        ofpact_put_SET_QUEUE(ofpacts)->queue_id = str_to_u32(arg);
        break;

    case OFPUTIL_NXAST_POP_QUEUE:
        ofpact_put_POP_QUEUE(ofpacts);
        break;

    case OFPUTIL_NXAST_REG_MOVE:
        nxm_parse_reg_move(ofpact_put_REG_MOVE(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_REG_LOAD:
        nxm_parse_reg_load(ofpact_put_REG_LOAD(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_NOTE:
        parse_note(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_MULTIPATH:
        multipath_parse(ofpact_put_MULTIPATH(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_BUNDLE:
        bundle_parse(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_BUNDLE_LOAD:
        bundle_parse_load(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_RESUBMIT_TABLE:
    case OFPUTIL_NXAST_OUTPUT_REG:
    case OFPUTIL_NXAST_DEC_TTL_CNT_IDS:
        NOT_REACHED();

    case OFPUTIL_NXAST_LEARN:
        learn_parse(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_EXIT:
        ofpact_put_EXIT(ofpacts);
        break;

    case OFPUTIL_NXAST_DEC_TTL:
        parse_dec_ttl(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_SET_MPLS_TTL:
    case OFPUTIL_OFPAT11_SET_MPLS_TTL:
        parse_set_mpls_ttl(ofpacts, arg);
        break;

    case OFPUTIL_OFPAT11_DEC_MPLS_TTL:
    case OFPUTIL_NXAST_DEC_MPLS_TTL:
        ofpact_put_DEC_MPLS_TTL(ofpacts);
        break;

    case OFPUTIL_NXAST_FIN_TIMEOUT:
        parse_fin_timeout(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_CONTROLLER:
        parse_controller(ofpacts, arg);
        break;

    case OFPUTIL_OFPAT11_PUSH_MPLS:
    case OFPUTIL_NXAST_PUSH_MPLS:
        ofpact_put_PUSH_MPLS(ofpacts)->ethertype =
            htons(str_to_u16(arg, "push_mpls"));
        break;

    case OFPUTIL_OFPAT11_POP_MPLS:
    case OFPUTIL_NXAST_POP_MPLS:
        ofpact_put_POP_MPLS(ofpacts)->ethertype =
            htons(str_to_u16(arg, "pop_mpls"));
        break;

    case OFPUTIL_NXAST_STACK_PUSH:
        nxm_parse_stack_action(ofpact_put_STACK_PUSH(ofpacts), arg);
        break;
    case OFPUTIL_NXAST_STACK_POP:
        nxm_parse_stack_action(ofpact_put_STACK_POP(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_SAMPLE:
        parse_sample(ofpacts, arg);
        break;
    }
}
예제 #20
0
glibtop_open_files_entry *
glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf,	pid_t pid)
{
#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
	struct kinfo_file *freep, *kif;
#ifndef HAVE_KINFO_GETFILE
	int name[4];
	size_t len;
#else
	int cnt;
#endif
	ssize_t i;
#else
	char *output;
#endif
	GArray *entries;

	memset(buf, 0, sizeof (glibtop_proc_open_files));

#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
#ifndef HAVE_KINFO_GETFILE
	name[0] = CTL_KERN;
	name[1] = KERN_PROC;
	name[2] = KERN_PROC_FILEDESC;
	name[3] = pid;

	if (sysctl(name, 4, NULL, &len, NULL, 0) < 0)
		return NULL;

	freep = kif = g_malloc(len);
	if (sysctl(name, 4, kif, &len, NULL, 0) < 0) {
		g_free(freep);
		return NULL;
	}
#else
	freep = kinfo_getfile(pid, &cnt);
#endif

	entries = g_array_new(FALSE, FALSE, sizeof(glibtop_open_files_entry));

#ifndef HAVE_KINFO_GETFILE
	for (i = 0; i < len / sizeof(*kif); i++, kif++) {
		glibtop_open_files_entry entry = {0};

		if (kif->kf_structsize != sizeof(*kif))
			continue;
#else
	for (i = 0; i < cnt; i++) {
		glibtop_open_files_entry entry = {0};

		kif = &freep[i];
#endif

		if (kif->kf_fd < 0)
			continue;

		if (kif->kf_type == KF_TYPE_SOCKET) {
			if (kif->kf_sock_domain == AF_LOCAL) {
				struct sockaddr_un *sun;

				entry.type = GLIBTOP_FILE_TYPE_LOCALSOCKET;
				sun = (struct sockaddr_un *)&kif->kf_sa_local;

				if (sun->sun_path[0]) {
					char *addrstr;

					addrstr = addr_to_string(&kif->kf_sa_local);
					g_strlcpy(entry.info.localsock.name,
						  addrstr,
						  sizeof(entry.info.localsock.name));
					g_free(addrstr);
				} else {
					char *addrstr;

					addrstr = addr_to_string(&kif->kf_sa_peer);
					g_strlcpy(entry.info.localsock.name,
						  addrstr,
						  sizeof(entry.info.localsock.name));
					g_free(addrstr);
				}
			} else if (kif->kf_sock_domain == AF_INET ||
				   kif->kf_sock_domain == AF_INET6) {
				char *addrstr;

				if (kif->kf_sock_domain == AF_INET)
					entry.type = GLIBTOP_FILE_TYPE_INETSOCKET;
				else
					entry.type = GLIBTOP_FILE_TYPE_INET6SOCKET;
				addrstr = addr_to_string(&kif->kf_sa_peer);
				g_strlcpy(entry.info.sock.dest_host,
					  addrstr,
					  sizeof(entry.info.sock.dest_host));
				g_free(addrstr);
				entry.info.sock.dest_port = addr_to_port(&kif->kf_sa_peer);
			}
		} else if (kif->kf_type == KF_TYPE_PIPE) {
			entry.type = GLIBTOP_FILE_TYPE_PIPE;
		} else if (kif->kf_type == KF_TYPE_VNODE) {
			entry.type = GLIBTOP_FILE_TYPE_FILE;
			g_strlcpy(entry.info.file.name, kif->kf_path,
				  sizeof(entry.info.file.name));
		} else
			continue;

		entry.fd = kif->kf_fd;

		g_array_append_val(entries, entry);
	}
	g_free(freep);
#else

	output = execute_lsof(pid);
	if (output == NULL) return NULL;

	entries = parse_output(output);

	g_free(output);
#endif

	buf->flags = _glibtop_sysdeps_proc_open_files;
	buf->number = entries->len;
	buf->size = sizeof(glibtop_open_files_entry);
	buf->total = buf->number * buf->size;

	return (glibtop_open_files_entry*)g_array_free(entries, FALSE);
}
예제 #21
0
/**
 * @brief Slot called when the quest execution produced some output lines.
 * @param lines The lines read from the standard output of the quest.
 */
void Console::quest_output_produced(const QStringList& lines) {

    Q_FOREACH (const QString& line, lines) {
        parse_output(line);
    }
예제 #22
0
static void
parse_named_action(enum ofputil_action_code code, const struct flow *flow,
                   struct ofpbuf *b, char *arg)
{
    struct ofp_action_dl_addr *oada;
    struct ofp_action_vlan_pcp *oavp;
    struct ofp_action_vlan_vid *oavv;
    struct ofp_action_nw_addr *oana;
    struct ofp_action_tp_port *oata;

    switch (code) {
    case OFPUTIL_OFPAT_OUTPUT:
        parse_output(b, arg);
        break;

    case OFPUTIL_OFPAT_SET_VLAN_VID:
        oavv = ofputil_put_OFPAT_SET_VLAN_VID(b);
        oavv->vlan_vid = htons(str_to_u32(arg));
        break;

    case OFPUTIL_OFPAT_SET_VLAN_PCP:
        oavp = ofputil_put_OFPAT_SET_VLAN_PCP(b);
        oavp->vlan_pcp = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT_STRIP_VLAN:
        ofputil_put_OFPAT_STRIP_VLAN(b);
        break;

    case OFPUTIL_OFPAT_SET_DL_SRC:
    case OFPUTIL_OFPAT_SET_DL_DST:
        oada = ofputil_put_action(code, b);
        str_to_mac(arg, oada->dl_addr);
        break;

    case OFPUTIL_OFPAT_SET_NW_SRC:
    case OFPUTIL_OFPAT_SET_NW_DST:
        oana = ofputil_put_action(code, b);
        str_to_ip(arg, &oana->nw_addr);
        break;

    case OFPUTIL_OFPAT_SET_NW_TOS:
        ofputil_put_OFPAT_SET_NW_TOS(b)->nw_tos = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT_SET_TP_SRC:
    case OFPUTIL_OFPAT_SET_TP_DST:
        oata = ofputil_put_action(code, b);
        oata->tp_port = htons(str_to_u32(arg));
        break;

    case OFPUTIL_OFPAT_ENQUEUE:
        parse_enqueue(b, arg);
        break;

    case OFPUTIL_NXAST_RESUBMIT:
        parse_resubmit(b, arg);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL:
        parse_set_tunnel(b, arg);
        break;

    case OFPUTIL_NXAST_SET_QUEUE:
        ofputil_put_NXAST_SET_QUEUE(b)->queue_id = htonl(str_to_u32(arg));
        break;

    case OFPUTIL_NXAST_POP_QUEUE:
        ofputil_put_NXAST_POP_QUEUE(b);
        break;

    case OFPUTIL_NXAST_REG_MOVE:
        nxm_parse_reg_move(ofputil_put_NXAST_REG_MOVE(b), arg);
        break;

    case OFPUTIL_NXAST_REG_LOAD:
        nxm_parse_reg_load(ofputil_put_NXAST_REG_LOAD(b), arg);
        break;

    case OFPUTIL_NXAST_NOTE:
        parse_note(b, arg);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL64:
        ofputil_put_NXAST_SET_TUNNEL64(b)->tun_id = htonll(str_to_u64(arg));
        break;

    case OFPUTIL_NXAST_MULTIPATH:
        multipath_parse(ofputil_put_NXAST_MULTIPATH(b), arg);
        break;

    case OFPUTIL_NXAST_AUTOPATH:
        autopath_parse(ofputil_put_NXAST_AUTOPATH(b), arg);
        break;

    case OFPUTIL_NXAST_BUNDLE:
        bundle_parse(b, arg);
        break;

    case OFPUTIL_NXAST_BUNDLE_LOAD:
        bundle_parse_load(b, arg);
        break;

    case OFPUTIL_NXAST_RESUBMIT_TABLE:
    case OFPUTIL_NXAST_OUTPUT_REG:
        NOT_REACHED();

    case OFPUTIL_NXAST_LEARN:
        learn_parse(b, arg, flow);
        break;

    case OFPUTIL_NXAST_EXIT:
        ofputil_put_NXAST_EXIT(b);
        break;
    }
}
예제 #23
0
/**
 * advanced_filter_ok_clicked_cb:
 * @button:
 * @state:
 *
 * Retrieve the information from the dialog and call the advanced_filter.
 * Note that we assume that the ok_button is only active if the entry fields
 * contain sensible data.
 **/
static void
advanced_filter_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
			       AdvancedFilterState *state)
{
	data_analysis_output_t  *dao;
	GnmValue                   *input;
	GnmValue                   *criteria;
	char                    *text;
	GtkWidget               *w;
	int                     err = 0;
	gboolean                unique;

	input = gnm_expr_entry_parse_as_value (
		GNM_EXPR_ENTRY (state->input_entry), state->sheet);

	criteria = gnm_expr_entry_parse_as_value
		(state->input_entry_2, state->sheet);

        dao  = parse_output ((GenericToolState *) state, NULL);

	w = go_gtk_builder_get_widget (state->gui, "unique-button");
	unique = (1 == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)));

	if (dao->type == InPlaceOutput)
		err = advanced_filter (WORKBOOK_CONTROL (state->wbcg),
				       dao, input, criteria, unique);
	else {
		analysis_tools_data_advanced_filter_t  *
			data = g_new0 (analysis_tools_data_advanced_filter_t, 1);
		data->base.wbc = WORKBOOK_CONTROL (state->wbcg);
		data->base.range_1 = input;
		data->base.range_2 = criteria;
		data->unique_only_flag = unique;

		if (cmd_analysis_tool (WORKBOOK_CONTROL (state->wbcg), state->sheet,
				       dao, data, analysis_tool_advanced_filter_engine, FALSE)) {
			err = data->base.err;
			g_free (data);
		} else
			err = analysis_tools_noerr;

	}

	if (dao->type == InPlaceOutput || err != analysis_tools_noerr) {
		value_release (input);
		value_release (criteria);
		g_free (dao);
	}

	switch (err) {
	case analysis_tools_noerr:
		gtk_widget_destroy (state->dialog);
		break;
	case analysis_tools_invalid_field:
		error_in_entry ((GenericToolState *) state,
				GTK_WIDGET (state->input_entry_2),
				_("The given criteria are invalid."));
		break;
	case analysis_tools_no_records_found:
		go_gtk_notice_nonmodal_dialog ((GtkWindow *) state->dialog,
					  &(state->warning_dialog),
					  GTK_MESSAGE_INFO,
					  _("No matching records were found."));
		break;
	default:
		text = g_strdup_printf (_("An unexpected error has occurred: "
					  "%d."), err);
		error_in_entry ((GenericToolState *) state,
				GTK_WIDGET (state->input_entry), text);
		g_free (text);
		break;
	}
	return;
}
예제 #24
0
void print_nvidia_temperature_info(
        yajl_gen json_gen,
        char *buffer,
        int interval,
        const char *format,
        int max_threshold
) {
        char *outwalk = buffer;

        static int pipefd[2];
        static int forked = false;
        pid_t cpid = 1;
        char temp_buff[4096];

        // if the nvidia-smi process hasn't been spawned
        if (!forked) {
            if (pipe(pipefd) == -1) {
                    perror("pipe");
                    return;
            }

            cpid = fork();
            forked = true;
        }

        switch (cpid) {
                case -1:
                        perror("fork");
                        return;

                case 0:
                        close(pipefd[0]);
                        dup2(pipefd[1], 1);

                        char buff[16];
                        sprintf(buff, "%d", interval);
                        default_command[2] = buff;

                        execve(*default_command, default_command, default_command + 6);

                        perror("execve");
                        exit(0);
        }

        struct pollfd poll_fd = { pipefd[0], POLLIN };
        int poll_st = poll(&poll_fd, 1, 0);

        if (poll_st < 0) {
                perror("poll");
                return;
        }

        if (poll_st == 0) {
                return;
        }



        for (const char * walk = format; *walk != 0; walk++) {
                if (*walk != '%') {
                        *(outwalk++) = *walk;
                        continue;
                }

                if (BEGINS_WITH(walk + 1, "degrees")) {
                        bool colorful_output = false;

                        int read_st = read(pipefd[0], temp_buff, sizeof(temp_buff));
                        if (read_st < 0) {
                                perror("read");
                                return;
                        }

                        // TODO: check if failed
                        int temp;
                        parse_output(temp_buff, &temp);

                        if (temp >= max_threshold) {
                            START_COLOR("color_bad");
                            colorful_output = true;
                        }

                        outwalk += sprintf(outwalk, "%d", temp);

                        if (colorful_output) {
                                END_COLOR;
                        }

                        walk += strlen("degrees");
                }
        }

        OUTPUT_FULL_TEXT(buffer);
}
예제 #25
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);
}