Exemplo n.º 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->pb_start, SIGNAL(clicked()),this, SLOT(add_p()));
    connect(ui->pb_stop, SIGNAL(clicked()),this,SLOT(p_exit()));
}
Exemplo n.º 2
0
void p_resolveArguments(int argc, char** argv, struct p_arguments* pa) {
	if (( argc < 2 ) || (strcmp(argv[1],"-h") == 0)) {
		p_help();
	}

	if (argc < 3) {
		p_log(PLL_ERROR,"Not enough arguments.");
		p_exit(PR_ECLARGS);
	}

	if (strcmp(argv[1],"--powxa") == 0) {
		pa->computeFunction = re_powxa_va;
		if (argc < 4) {
			p_log(PLL_ERROR,"Not enough arguments. You need to specify the exponent. See -h");
			p_exit(PR_ECLARGS);
		} else {
			char* pch;
			*(pa->pd) = strtod(argv[3],&pch);
			if (*pch != '\0') {
				p_log(PLL_ERROR,"Wrong argmuent a. Should be double.");
				p_exit(PR_ECLARGS);
			}
		}
	} else if (strcmp(argv[1],"--etox") == 0) {
		pa->computeFunction = re_etox_va;
	} else if (strcmp(argv[1],"--ln") == 0) {
		pa->computeFunction = re_lnx_va;
	} else if (strcmp(argv[1],"--sqrt") == 0) {
		pa->computeFunction = re_sqrtx_va;
	} else if (strcmp(argv[1],"--argsinh") == 0) {
		pa->computeFunction = re_argsinhx_va;
	} else if (strcmp(argv[1],"--arctg") == 0) {
		pa->computeFunction = re_arctgx_va;
	} else {
		p_log(PLL_ERROR,"Wrong argument \"%s\".",argv[1]);
		p_exit(PR_ECLARGS);
	}

	if ((strToUint(argv[2],&pa->sigdig) != 0) || (pa->sigdig > DBL_DIG)) {
		p_log(PLL_ERROR,"Wrong sigdig, using default DBL_DIG = %d. See -h",DBL_DIG);
		pa->sigdig = DBL_DIG;
	}
}
Exemplo n.º 3
0
/**
	maybe_setup
	Creates the ~/.freenote/probe.team file, based on user input.
	Assumes that we are /not/ daemonized yet.
	Returns 0 for success (i.e., successful setup -or- the probe has
	already been set up), -1 for failure (ex., couldn't write to the file).
*/
int maybe_setup()
{
	fm_init_base();
	if(read_str_opt("auto-setup")) {
		return set_teamstring(read_str_opt("auto-setup"));
	}
	if(read_int_opt("setup") || 
		!(fm_exists(FM_TEAM_INFO) || read_int_opt("no-tokens"))) {
		try(do_setup());
		p_exit(PEXIT_NORMAL);
	}
	return 0;
}

/*
	do_setup
	Does the setup.  Returns 0 for success, -1 for failure.
	It doesn't use io_* because it's interactive.
*/
static int do_setup()
{
	char	team[TEAM_MAXLEN],
		pin[PIN_MAXLEN],
		*tmp = fm_abs(FM_TEAM_INFO);
	int	r;

	//  It's a little long.
	printf(	"FreeNote Probe Setup:\n"
		"Please follow the on-screen instructions.\n"
		"\n"
		"If you do not have a team, you can visit http://freenote."
		"petta-tech.com\nto register.\n"
		"If you don't want to register, you can run the probe with"
		"the\n'--no-tokens'/'-n' option, "
		"or add 'no-tokens' to ~/.freenote/rc.\n"
		"Please enter your team name:  ");
	fgets(team, TEAM_MAXLEN, stdin);
	chomp(team);
	printf("Please enter your team's pin code:  ");
	fgets(pin, PIN_MAXLEN, stdin);
	chomp(pin);
	printf("Writing the information to %s...\n", tmp);
	r = set_team_info(team, pin);
	try(r);
	printf("Ready to roll!  Run the probe again, without --setup.\n");

	return r;
}

/**
	set_team_info
	Generates ~/.freenote/probe.team from the two arguments (the team
	name and the pin code).  Returns 0 for success, -1 for failure.
*/
int set_team_info(const char *team_name, const char *pin_code)
{
	// strlen("team_name:", ";\n", "pin_code:", ";\n\0") = 24
	char buffer[TEAM_MAXLEN + PIN_MAXLEN + 24];

	sprintf(buffer, "team_name:%s;\npin_code:%s;\n", team_name, pin_code);
	return fm_write(FM_TEAM_INFO, buffer, strlen(buffer)) - 1;
}
Exemplo n.º 4
0
// Writes help and exits
void p_help() {
	printf("%s",P_HELPMSG);
	p_exit(PR_OK);
}