Пример #1
0
int train_fs(const char* input_file_name, const char* model_file_name){
	// Initialization
	const char* error_msg;
	set_default_params();
	read_problem(input_file_name);
	error_msg = check_parameter(&prob,&param);
	if(error_msg){
		fprintf(stderr,"Error: %s\n",error_msg);
		return -1;
	}

	// Do the cross-validation and save accuracy
	double accuracy = do_cross_validation(nr_fold);
	std::string info_fpath = std::string(model_file_name) + ".info";
	FILE* info = fopen(info_fpath.c_str(), "w");
	fprintf(info, "Accuracy : %f", accuracy);
	//fflush(info);	
	fclose(info);

	// Train a model on the whole dataset
	model_train=train(&prob, &param);
	if(save_model(model_file_name, model_train)){
		fprintf(stderr,"can't save model to file %s\n",model_file_name);
		return -1;
	}

	// Free resources
	destroy_param(&param);
	free(prob.y);
	free(prob.x);
	free(x_space);
	free(line);
	
	return 0;
}
Пример #2
0
void setup() {

	gopts = (GOptions*)malloc(sizeof(GOptions));
	set_default_params(gopts);
	mc = (MContext*)create_mutator_context(gopts);

}
Пример #3
0
int main(int argc, char *argv[])
{
    Parameters *params; // user defined parameters
    double ***phi;      // flux array
    FILE *fp = NULL;    // output file

    // Get inputs
    params = set_default_params();
    parse_params("parameters", params);
    read_CLI(argc, argv, params);
    print_params(params);

    // Initial guess of flux
    phi = init_flux(params);

    solve(phi, params);

    printf("keff = %f\n", params->k);

    // Write solution
    if(params->write_flux == TRUE) {
        write_flux(phi, params, fp);
    }

    // Free memory
    free_flux(phi);
    free(params);

    return 0;
}
Пример #4
0
int
main(int argc, char **argv)
{
	int rc;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <dump>\n", argv[0]);
		return TEST_ERR;
	}

	rc = set_default_params();
	if (rc != TEST_OK) {
		perror("Cannot set default params");
		return rc;
	}

	rc = parse_params_file(&params, stdin);
	if (rc != TEST_OK)
		return rc;

	rc = setup_arch();
	if (rc != TEST_OK)
		return rc;

	if (vmcoreinfo_file) {
		vmcoreinfo.blob = slurp(vmcoreinfo_file);
		if (vmcoreinfo.blob == NULL)
			return TEST_ERR;
	}

	if (note_file) {
		notes.blob = slurp(note_file);
		if (notes.blob == NULL)
			return TEST_ERR;
	}

	if (eraseinfo_file) {
		eraseinfo.blob = slurp(eraseinfo_file);
		if (eraseinfo.blob == NULL)
			return TEST_ERR;
	}

	rc = create_file(argv[1]);
	if (rc != TEST_OK)
		return rc;

	return TEST_OK;
}
Пример #5
0
MotifSearch::MotifSearch(const vector<string>& names,
		const vector<string>& seqs,
		const int nc,
		const int order,
		const double sim_cut,
		const int maxm) :
nameset(names),
ngenes(names.size()),
seqset(seqs),
bgmodel(seqset, order),
motif(seqset, nc, params.pseudo, params.backfreq),
select_sites(seqset, nc, params.pseudo, params.backfreq),
archive(seqset, sim_cut, maxm, params.pseudo, params.backfreq),
seqscores(ngenes),
seqranks(ngenes),
bestpos(ngenes),
beststrand(ngenes){
	set_default_params();
}
Пример #6
0
static int
process_params(rdpSet * settings, rdpChanMan * chan_man, int argc, char ** argv, int * pindex)
{
	char * p;
	struct passwd * pw;
	RD_PLUGIN_DATA plugin_data[MAX_PLUGIN_DATA + 1];
	int index;
	int i, j;

	set_default_params(settings);
	pw = getpwuid(getuid());
	if (pw != 0)
	{
		if (pw->pw_name != 0)
		{
			strncpy(settings->username, pw->pw_name, sizeof(settings->username) - 1);
		}
	}
	printf("process_params\n");
	if (argc < *pindex + 1)
	{
		if (*pindex == 1)
			printf("no parameters specified\n");
		return 1;
	}
	while (*pindex < argc)
	{
		if (strcmp("-a", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing server depth\n");
				return 1;
			}
			settings->server_depth = atoi(argv[*pindex]);
		}
		else if (strcmp("-u", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing username\n");
				return 1;
			}
			strncpy(settings->username, argv[*pindex], sizeof(settings->username) - 1);
			settings->username[sizeof(settings->username) - 1] = 0;
		}
		else if (strcmp("-p", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing password\n");
				return 1;
			}
			strncpy(settings->password, argv[*pindex], sizeof(settings->password) - 1);
			settings->password[sizeof(settings->password) - 1] = 0;
			settings->autologin = 1;
		}
		else if (strcmp("-d", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing domain\n");
				return 1;
			}
			strncpy(settings->domain, argv[*pindex], sizeof(settings->domain) - 1);
			settings->domain[sizeof(settings->domain) - 1] = 0;
		}
		else if (strcmp("-s", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing shell\n");
				return 1;
			}
			strncpy(settings->shell, argv[*pindex], sizeof(settings->shell) - 1);
			settings->shell[sizeof(settings->shell) - 1] = 0;
		}
		else if (strcmp("-c", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing directory\n");
				return 1;
			}
			strncpy(settings->directory, argv[*pindex], sizeof(settings->directory) - 1);
			settings->directory[sizeof(settings->directory) - 1] = 0;
		}
		else if (strcmp("-g", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing width\n");
				return 1;
			}
			settings->width = strtol(argv[*pindex], &p, 10);
			if (*p == 'x')
			{
				settings->height = strtol(p + 1, &p, 10);
			}
			if ((settings->width < 16) || (settings->height < 16) ||
				(settings->width > 4096) || (settings->height > 4096))
			{
				printf("invalid dimensions\n");
				return 1;
			}
		}
		else if (strcmp("-t", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing port number\n");
				return 1;
			}
			settings->tcp_port_rdp = atoi(argv[*pindex]);
		}
		else if (strcmp("-n", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing hostname\n");
				return 1;
			}
			strncpy(settings->hostname, argv[*pindex], sizeof(settings->hostname) - 1);
			settings->directory[sizeof(settings->hostname) - 1] = 0;
		}
		else if (strcmp("-o", argv[*pindex]) == 0)
		{
			settings->console_audio = 1;
		}
		else if (strcmp("-0", argv[*pindex]) == 0)
		{
			settings->console_session = 1;
		}
		else if (strcmp("-z", argv[*pindex]) == 0)
		{
			settings->bulk_compression = 1;
		}
		else if (strcmp("-x", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing performance flag\n");
				return 1;
			}
			if (strncmp("m", argv[*pindex], 1) == 0) /* modem */
			{
				settings->performanceflags = PERF_DISABLE_WALLPAPER |
					PERF_DISABLE_FULLWINDOWDRAG | PERF_DISABLE_MENUANIMATIONS |
					PERF_DISABLE_THEMING;
			}
			else if (strncmp("b", argv[*pindex], 1) == 0) /* broadband */
			{
				settings->performanceflags = PERF_DISABLE_WALLPAPER;
			}
			else if (strncmp("l", argv[*pindex], 1) == 0) /* lan */
			{
				settings->performanceflags = PERF_FLAG_NONE;
			}
			else
			{
				settings->performanceflags = strtol(argv[*pindex], 0, 16);
			}
		}
		else if (strcmp("-plugin", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing plugin name\n");
				return 1;
			}
			index = *pindex;
			memset(plugin_data, 0, sizeof(plugin_data));
			if (*pindex < argc - 1 && strcmp("-data", argv[*pindex + 1]) == 0)
			{
				*pindex = *pindex + 2;
				i = 0;
				while (*pindex < argc && strcmp("--", argv[*pindex]) != 0 && i < MAX_PLUGIN_DATA)
				{
					plugin_data[i].size = sizeof(RD_PLUGIN_DATA);
					for (j = 0, p = argv[*pindex]; j < 4 && p != NULL; j++)
					{
						plugin_data[i].data[j] = p;
						p = strchr(plugin_data[i].data[j], ':');
						if (p != NULL)
							*p++ = 0;
					}
					*pindex = *pindex + 1;
					i++;
				}
			}
			freerdp_chanman_load_plugin(chan_man, settings, argv[index], plugin_data);
		}
		else
		{
			strncpy(settings->server, argv[*pindex], sizeof(settings->server) - 1);
			settings->server[sizeof(settings->server) - 1] = 0;
			p = strchr(settings->server, ':');
			if (p)
			{
				*p = 0;
				settings->tcp_port_rdp = atoi(p + 1);
			}
			/* server is the last argument for the current session. arguments
			   followed will be parsed for the next session. */
			*pindex = *pindex + 1;
			return 0;
		}
		*pindex = *pindex + 1;
	}
	printf("missing server name\n");
	return 1;
}
Пример #7
0
static int
process_params(wfInfo * wfi, int argc, char ** argv, int * pindex)
{
    rdpSet * settings;
    char * p;
    int i;
    char show_console = 1;

    /* Early scanning of options for stdout/console handling */
    for(i = 1; i < argc; i++)
        if (strcmp("--no-console", argv[i]) == 0)
        {
            show_console = 0;
        }
        else if (strcmp("--debug-log", argv[i]) == 0)
        {
            freopen("freerdp.log", "w", stdout);
            show_console = 0;
        }
    if (show_console && !GetConsoleWindow())
    {
        create_console();
        printf("(this console window can be redirected to freerdp.log with --debug-log\n"
               "or hidden with --no-debug)\n");
    }

    set_default_params(wfi);
    settings = wfi->settings;

    DEBUG("process_params\n");
    if (argc < *pindex + 1)
    {
        if (*pindex == 1)
            printf("no parameters specified\n");
        return 1;
    }
    while (*pindex < argc)
    {
        if (strcmp("-a", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing server depth\n");
                return 1;
            }
            settings->server_depth = atoi(argv[*pindex]);
        }
        else if (strcmp("-u", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing username\n");
                return 1;
            }
            strncpy(settings->username, argv[*pindex], sizeof(settings->username) - 1);
            settings->username[sizeof(settings->username) - 1] = 0;
        }
        else if (strcmp("-p", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing password\n");
                return 1;
            }
            strncpy(settings->password, argv[*pindex], sizeof(settings->password) - 1);
            settings->password[sizeof(settings->password) - 1] = 0;
            settings->autologin = 1;
        }
        else if (strcmp("-d", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing domain\n");
                return 1;
            }
            strncpy(settings->domain, argv[*pindex], sizeof(settings->domain) - 1);
            settings->domain[sizeof(settings->domain) - 1] = 0;
        }
        else if (strcmp("-s", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing shell\n");
                return 1;
            }
            strncpy(settings->shell, argv[*pindex], sizeof(settings->shell) - 1);
            settings->shell[sizeof(settings->shell) - 1] = 0;
        }
        else if (strcmp("-c", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing directory\n");
                return 1;
            }
            strncpy(settings->directory, argv[*pindex], sizeof(settings->directory) - 1);
            settings->directory[sizeof(settings->directory) - 1] = 0;
        }
        else if (strcmp("-g", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing width\n");
                return 1;
            }
            settings->width = strtol(argv[*pindex], &p, 10);
            if (*p == 'x')
            {
                settings->height = strtol(p + 1, &p, 10);
            }
            if (*p == '%')
            {
                wfi->percentscreen = settings->width;
            }
        }
        else if (strcmp("-t", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing port number\n");
                return 1;
            }
            settings->tcp_port_rdp = atoi(argv[*pindex]);
        }
        else if (strcmp("-T", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing window title\n");
                return 1;
            }
            strncpy(wfi->window_title, argv[*pindex], sizeof(wfi->window_title) - 1);
            wfi->window_title[sizeof(wfi->window_title) - 1] = 0;
        }
        else if (strcmp("-n", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing hostname\n");
                return 1;
            }
            strncpy(settings->hostname, argv[*pindex], sizeof(settings->hostname) - 1);
            settings->hostname[sizeof(settings->hostname) - 1] = 0;
        }
        else if (strcmp("-o", argv[*pindex]) == 0)
        {
            settings->console_audio = 1;
        }
        else if (strcmp("-0", argv[*pindex]) == 0)
        {
            settings->console_session = 1;
        }
        else if (strcmp("-z", argv[*pindex]) == 0)
        {
            settings->bulk_compression = 1;
        }
        else if (strcmp("--rfx", argv[*pindex]) == 0)
        {
            settings->rfx_flags = 1;
            settings->ui_decode_flags = 1;
            settings->use_frame_ack = 0;
            settings->server_depth = 32;
            settings->performanceflags = PERF_FLAG_NONE;
        }
        else if (strcmp("--gdi", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing GDI rendering\n");
                return 1;
            }
            if (strncmp("sw", argv[*pindex], 1) == 0) /* Software */
            {
                settings->software_gdi = 1;
            }
            else if (strncmp("hw", argv[*pindex], 1) == 0) /* Hardware */
            {
                settings->software_gdi = 0;
            }
            else
            {
                printf("unknown GDI rendering\n");
                return 1;
            }
        }
        else if (strcmp("--no-osb", argv[*pindex]) == 0)
        {
            settings->off_screen_bitmaps = 0;
        }
        else if (strcmp("-f", argv[*pindex]) == 0)
        {
            wfi->fullscreen = wfi->fs_toggle = 1;
            DEBUG("full screen option\n");
        }
        else if (strcmp("-x", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing performance flag\n");
                return 1;
            }
            if (strncmp("m", argv[*pindex], 1) == 0) /* modem */
            {
                settings->performanceflags = PERF_DISABLE_WALLPAPER |
                                             PERF_DISABLE_FULLWINDOWDRAG | PERF_DISABLE_MENUANIMATIONS |
                                             PERF_DISABLE_THEMING;
            }
            else if (strncmp("b", argv[*pindex], 1) == 0) /* broadband */
            {
                settings->performanceflags = PERF_DISABLE_WALLPAPER;
            }
            else if (strncmp("l", argv[*pindex], 1) == 0) /* lan */
            {
                settings->performanceflags = PERF_FLAG_NONE;
            }
            else
            {
                settings->performanceflags = strtol(argv[*pindex], 0, 16);
            }
        }
#ifndef DISABLE_TLS
        else if (strcmp("--no-rdp", argv[*pindex]) == 0)
        {
            settings->rdp_security = 0;
        }
        else if (strcmp("--no-tls", argv[*pindex]) == 0)
        {
            settings->tls_security = 0;
        }
        else if (strcmp("--no-nla", argv[*pindex]) == 0)
        {
            settings->nla_security = 0;
        }
        else if (strcmp("--sec", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing protocol security\n");
                return 1;
            }
            if (strncmp("rdp", argv[*pindex], 1) == 0) /* Standard RDP */
            {
                settings->rdp_security = 1;
                settings->tls_security = 0;
                settings->nla_security = 0;
            }
            else if (strncmp("tls", argv[*pindex], 1) == 0) /* TLS */
            {
                settings->rdp_security = 0;
                settings->tls_security = 1;
                settings->nla_security = 0;
            }
            else if (strncmp("nla", argv[*pindex], 1) == 0) /* NLA */
            {
                settings->rdp_security = 0;
                settings->tls_security = 0;
                settings->nla_security = 1;
            }
            else
            {
                printf("unknown protocol security\n");
                return 1;
            }
        }
#endif
        else if (strcmp("--plugin", argv[*pindex]) == 0)
        {
            *pindex = *pindex + 1;
            if (*pindex == argc)
            {
                printf("missing plugin name\n");
                return 1;
            }
            /* TODO: Handle --data ... -- */
            freerdp_chanman_load_plugin(wfi->chan_man, settings, argv[*pindex], NULL);
        }
        else if ((strcmp("-h", argv[*pindex]) == 0) || strcmp("--help", argv[*pindex]) == 0)
        {
            out_args();
            return 1;
        }
        else if (strcmp("--version", argv[*pindex]) == 0)
        {
            printf("This is FreeRDP version %s\n", PACKAGE_VERSION);
            return 1;
        }
        else if (argv[*pindex][0] != '-')
        {
            settings->server[sizeof(settings->server) - 1] = 0;
            if (argv[*pindex][0] == '[' && (p = strchr(argv[*pindex], ']'))
                    && (p[1] == 0 || (p[1] == ':' && !strchr(p + 2, ':'))))
            {
                /* Either "[...]" or "[...]:..." with at most one : after the brackets */
                strncpy(settings->server, argv[*pindex] + 1, sizeof(settings->server) - 1);
                if ((p = strchr(settings->server, ']')))
                {
                    *p = 0;
                    if (p[1] == ':')
                        settings->tcp_port_rdp = atoi(p + 2);
                }
            }
            else
            {
                /* Port number is cut off and used if exactly one : in the string */
                strncpy(settings->server, argv[*pindex], sizeof(settings->server) - 1);
                if ((p = strchr(settings->server, ':')) && !strchr(p + 1, ':'))
                {
                    *p = 0;
                    settings->tcp_port_rdp = atoi(p + 1);
                }
            }
            /* server is the last argument for the current session. arguments
               followed will be parsed for the next session. */
            *pindex = *pindex + 1;
            return 0;
        }
        else if ((strcmp("--no-console", argv[*pindex]) == 0) ||
                 (strcmp("--debug-log", argv[*pindex]) == 0))
        {
            /* Skip options that already has been processed */
        }
        else
        {
            printf("invalid option: %s\n", argv[*pindex]);
            return 1;
        }
        *pindex = *pindex + 1;
    }
    printf("missing server name\n");
    return 1;
}
Пример #8
0
static void
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
{
  static GimpParam  values[2];
  GimpRunMode       run_mode;
  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
  gint32            drawable_id;

  run_mode = param[0].data.d_int32;

  INIT_I18N ();

  set_default_params ();

  /*  Possibly retrieve data  */
  gimp_get_data (PLUG_IN_PROC, &curl);

  *nreturn_vals = 2;
  *return_vals = values;

  values[0].type = GIMP_PDB_STATUS;
  values[0].data.d_status = status;
  values[1].type = GIMP_PDB_LAYER;
  values[1].data.d_layer = -1;

  /*  Get the specified drawable  */
  drawable_id = param[2].data.d_drawable;
  image_id = param[1].data.d_image;

  if ((gimp_drawable_is_rgb (drawable_id) ||
       gimp_drawable_is_gray (drawable_id)) &&
      gimp_drawable_mask_intersect (drawable_id, &sel_x, &sel_y,
                                    &true_sel_width, &true_sel_height))
    {
      switch (run_mode)
	{
	case GIMP_RUN_INTERACTIVE:
	  /*  First acquire information with a dialog  */
	  if (! dialog ())
	    return;
	  break;

	case GIMP_RUN_NONINTERACTIVE:
	  /*  Make sure all the arguments are there!  */
	  if (nparams != 7)
	    status = GIMP_PDB_CALLING_ERROR;

	  if (status == GIMP_PDB_SUCCESS)
	    {
              curl.colors      = CLAMP (param[3].data.d_int32,
                                        0, CURL_COLORS_LAST);
              curl.edge        = CLAMP (param[4].data.d_int32,
                                        CURL_EDGE_FIRST, CURL_EDGE_LAST);
              curl.orientation = CLAMP (param[5].data.d_int32,
                                        0, CURL_ORIENTATION_LAST);
	      curl.shade       = param[6].data.d_int32 ? TRUE : FALSE;
	    }
	  break;

	case GIMP_RUN_WITH_LAST_VALS:
	  break;

	default:
	  break;
	}

      if (status == GIMP_PDB_SUCCESS)
	{
	  values[1].data.d_layer = page_curl (drawable_id);

	  if (run_mode != GIMP_RUN_NONINTERACTIVE)
            gimp_displays_flush ();

	  if (run_mode == GIMP_RUN_INTERACTIVE)
            gimp_set_data (PLUG_IN_PROC, &curl, sizeof (CurlParams));
	}
    }
  else
    /* Sorry - no indexed/noalpha images */
    status = GIMP_PDB_EXECUTION_ERROR;

  values[0].data.d_status = status;
}
Пример #9
0
static int
process_params(rdpSet * settings, rdpChanMan * chan_man, int argc, char ** argv, int * pindex)
{
	int index;
	int i, j;
	char * p;
	struct passwd * pw;
	int num_extensions;
	RD_PLUGIN_DATA plugin_data[MAX_PLUGIN_DATA + 1];

	num_extensions = 0;
	set_default_params(settings);

	p = getlogin();
	i = sizeof(settings->username) - 1;
	if (p != 0)
	{
		strncpy(settings->username, p, i);
	}
	else
	{
		pw = getpwuid(getuid());
		if (pw != 0)
		{
			if (pw->pw_name != 0)
			{
				strncpy(settings->username, pw->pw_name, i);
			}
		}
	}

	if (argc < *pindex + 1)
	{
		if (*pindex == 1)
			printf("no parameters specified\n");
		return 1;
	}
	while (*pindex < argc)
	{
		if (strcmp("-a", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing server depth\n");
				return 1;
			}
			settings->server_depth = atoi(argv[*pindex]);
		}
		else if (strcmp("-u", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing username\n");
				return 1;
			}
			strncpy(settings->username, argv[*pindex], sizeof(settings->username) - 1);
			settings->username[sizeof(settings->username) - 1] = 0;
		}
		else if (strcmp("-p", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing password\n");
				return 1;
			}
			strncpy(settings->password, argv[*pindex], sizeof(settings->password) - 1);
			settings->password[sizeof(settings->password) - 1] = 0;
			settings->autologin = 1;
		}
		else if (strcmp("-d", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing domain\n");
				return 1;
			}
			strncpy(settings->domain, argv[*pindex], sizeof(settings->domain) - 1);
			settings->domain[sizeof(settings->domain) - 1] = 0;
		}
		else if (strcmp("-s", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing shell\n");
				return 1;
			}
			strncpy(settings->shell, argv[*pindex], sizeof(settings->shell) - 1);
			settings->shell[sizeof(settings->shell) - 1] = 0;
		}
		else if (strcmp("-c", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing directory\n");
				return 1;
			}
			strncpy(settings->directory, argv[*pindex], sizeof(settings->directory) - 1);
			settings->directory[sizeof(settings->directory) - 1] = 0;
		}
		else if (strcmp("-g", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing width\n");
				return 1;
			}
			settings->width = strtol(argv[*pindex], &p, 10);
			if (*p == 'x')
			{
				settings->height = strtol(p + 1, &p, 10);
			}
			if ((settings->width < 16) || (settings->height < 16) ||
				(settings->width > 4096) || (settings->height > 4096))
			{
				printf("invalid dimensions\n");
				return 1;
			}
		}
		else if (strcmp("-t", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing port number\n");
				return 1;
			}
			settings->tcp_port_rdp = atoi(argv[*pindex]);
		}
		else if (strcmp("-n", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing hostname\n");
				return 1;
			}
			strncpy(settings->hostname, argv[*pindex], sizeof(settings->hostname) - 1);
			settings->directory[sizeof(settings->hostname) - 1] = 0;
		}
		else if (strcmp("-o", argv[*pindex]) == 0)
		{
			settings->console_audio = 1;
		}
		else if (strcmp("-0", argv[*pindex]) == 0)
		{
			settings->console_session = 1;
		}
		else if (strcmp("-z", argv[*pindex]) == 0)
		{
			settings->bulk_compression = 1;
		}
		else if (strcmp("--gdi", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing GDI rendering\n");
				return 1;
			}
			if (strncmp("sw", argv[*pindex], 1) == 0) /* Software */
			{
				settings->software_gdi = 1;
			}
			else if (strncmp("hw", argv[*pindex], 1) == 0) /* Hardware */
			{
				settings->software_gdi = 0;
			}
			else
			{
				printf("unknown GDI rendering\n");
				return 1;
			}
		}
		else if (strcmp("--no-osb", argv[*pindex]) == 0)
		{
			settings->off_screen_bitmaps = 0;
		}
		else if (strcmp("--rfx", argv[*pindex]) == 0)
		{
			settings->rfx_flags = 1;
			settings->ui_decode_flags = 1;
			settings->use_frame_ack = 0;
			settings->server_depth = 32;
			settings->performanceflags = PERF_FLAG_NONE;
		}
		else if ((strcmp("-h", argv[*pindex]) == 0) || strcmp("--help", argv[*pindex]) == 0)
		{
			out_args();
			return 1;
		}
		else if (strcmp("-x", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing performance flag\n");
				return 1;
			}
			if (strncmp("m", argv[*pindex], 1) == 0) /* modem */
			{
				settings->performanceflags = PERF_DISABLE_WALLPAPER |
					PERF_DISABLE_FULLWINDOWDRAG | PERF_DISABLE_MENUANIMATIONS |
					PERF_DISABLE_THEMING;
			}
			else if (strncmp("b", argv[*pindex], 1) == 0) /* broadband */
			{
				settings->performanceflags = PERF_DISABLE_WALLPAPER;
			}
			else if (strncmp("l", argv[*pindex], 1) == 0) /* lan */
			{
				settings->performanceflags = PERF_FLAG_NONE;
			}
			else
			{
				settings->performanceflags = strtol(argv[*pindex], 0, 16);
			}
		}
#ifndef DISABLE_TLS
		else if (strcmp("--no-rdp", argv[*pindex]) == 0)
		{
			settings->rdp_security = 0;
		}
		else if (strcmp("--no-tls", argv[*pindex]) == 0)
		{
			settings->tls_security = 0;
		}
		else if (strcmp("--no-nla", argv[*pindex]) == 0)
		{
			settings->nla_security = 0;
		}
		else if (strcmp("--sec", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing protocol security\n");
				return 1;
			}
			if (strncmp("rdp", argv[*pindex], 1) == 0) /* Standard RDP */
			{
				settings->rdp_security = 1;
				settings->tls_security = 0;
				settings->nla_security = 0;
			}
			else if (strncmp("tls", argv[*pindex], 1) == 0) /* TLS */
			{
				settings->rdp_security = 0;
				settings->tls_security = 1;
				settings->nla_security = 0;
			}
			else if (strncmp("nla", argv[*pindex], 1) == 0) /* NLA */
			{
				settings->rdp_security = 0;
				settings->tls_security = 0;
				settings->nla_security = 1;
			}
			else
			{
				printf("unknown protocol security\n");
				return 1;
			}
		}
#endif
		else if (strcmp("--plugin", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing plugin name\n");
				return 1;
			}
			index = *pindex;
			memset(plugin_data, 0, sizeof(plugin_data));
			if (*pindex < argc - 1 && strcmp("--data", argv[*pindex + 1]) == 0)
			{
				*pindex = *pindex + 2;
				i = 0;
				while (*pindex < argc && strcmp("--", argv[*pindex]) != 0 && i < MAX_PLUGIN_DATA)
				{
					plugin_data[i].size = sizeof(RD_PLUGIN_DATA);
					for (j = 0, p = argv[*pindex]; j < 4 && p != NULL; j++)
					{
						plugin_data[i].data[j] = p;
						if (j < 3)
						{
							p = strchr(plugin_data[i].data[j], ':');
							if (p != NULL)
								*p++ = 0;
						}
					}
					*pindex = *pindex + 1;
					i++;
				}
			}
			freerdp_chanman_load_plugin(chan_man, settings, argv[index], plugin_data);
		}
		else if (strcmp("--ext", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing extension name\n");
				return 1;
			}
			if (num_extensions >= sizeof(settings->extensions) / sizeof(struct rdp_ext_set))
			{
				printf("maximum extensions reached\n");
				return 1;
			}
			index = *pindex;
			snprintf(settings->extensions[num_extensions].name,
				sizeof(settings->extensions[num_extensions].name),
				"%s", argv[index]);
			settings->extensions[num_extensions].data = NULL;
			if (*pindex < argc - 1 && strcmp("--data", argv[*pindex + 1]) == 0)
			{
				*pindex = *pindex + 2;
				settings->extensions[num_extensions].data = argv[*pindex];
				i = 0;
				while (*pindex < argc && strcmp("--", argv[*pindex]) != 0)
				{
					*pindex = *pindex + 1;
					i++;
				}
			}
			num_extensions++;
		}
		else if ((strcmp("-h", argv[*pindex]) == 0) || strcmp("--help", argv[*pindex]) == 0)
		{
			out_args();
			return 1;
		}
		else if (strcmp("--version", argv[*pindex]) == 0)
		{
			printf("This is FreeRDP version %s\n", PACKAGE_VERSION);
			return 1;
		}
		else if (argv[*pindex][0] != '-')
		{
			settings->server[sizeof(settings->server) - 1] = 0;
			if (argv[*pindex][0] == '[' && (p = strchr(argv[*pindex], ']'))
				&& (p[1] == 0 || (p[1] == ':' && !strchr(p + 2, ':'))))
			{
				/* Either "[...]" or "[...]:..." with at most one : after the brackets */
				strncpy(settings->server, argv[*pindex] + 1, sizeof(settings->server) - 1);
				if ((p = strchr(settings->server, ']')))
				{
					*p = 0;
					if (p[1] == ':')
						settings->tcp_port_rdp = atoi(p + 2);
				}
			}
			else
			{
				/* Port number is cut off and used if exactly one : in the string */
				strncpy(settings->server, argv[*pindex], sizeof(settings->server) - 1);
				if ((p = strchr(settings->server, ':')) && !strchr(p + 1, ':'))
				{
					*p = 0;
					settings->tcp_port_rdp = atoi(p + 1);
				}
			}
			/* server is the last argument for the current session. arguments
			   followed will be parsed for the next session. */
			*pindex = *pindex + 1;

			return 0;
		}
		else
		{
			printf("invalid option: %s\n", argv[*pindex]);
			return 1;
		}
		*pindex = *pindex + 1;
	}
	printf("missing server name\n");
	return 1;
}
Пример #10
0
static int hva_open(struct file *file)
{
	struct hva_dev *hva = video_drvdata(file);
	struct device *dev = hva_to_dev(hva);
	struct hva_ctx *ctx;
	int ret;

	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
	if (!ctx) {
		ret = -ENOMEM;
		goto out;
	}
	ctx->hva_dev = hva;

	INIT_WORK(&ctx->run_work, hva_run_work);
	v4l2_fh_init(&ctx->fh, video_devdata(file));
	file->private_data = &ctx->fh;
	v4l2_fh_add(&ctx->fh);

	ret = hva_ctrls_setup(ctx);
	if (ret) {
		dev_err(dev, "%s [x:x] failed to setup controls\n",
			HVA_PREFIX);
		goto err_fh;
	}
	ctx->fh.ctrl_handler = &ctx->ctrl_handler;

	mutex_init(&ctx->lock);

	ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(hva->m2m_dev, ctx,
					    &hva_queue_init);
	if (IS_ERR(ctx->fh.m2m_ctx)) {
		ret = PTR_ERR(ctx->fh.m2m_ctx);
		dev_err(dev, "%s failed to initialize m2m context (%d)\n",
			HVA_PREFIX, ret);
		goto err_ctrls;
	}

	/* set the instance name */
	mutex_lock(&hva->lock);
	hva->instance_id++;
	snprintf(ctx->name, sizeof(ctx->name), "[%3d:----]",
		 hva->instance_id);
	mutex_unlock(&hva->lock);

	/* default parameters for frame and stream */
	set_default_params(ctx);

	dev_info(dev, "%s encoder instance created\n", ctx->name);

	return 0;

err_ctrls:
	v4l2_ctrl_handler_free(&ctx->ctrl_handler);
err_fh:
	v4l2_fh_del(&ctx->fh);
	v4l2_fh_exit(&ctx->fh);
	kfree(ctx);
out:
	return ret;
}
Пример #11
0
/* Returns "true" on errors or other reasons to not continue normal operation */
static int
process_params(xfInfo * xfi, int argc, char ** argv, int * pindex)
{
	rdpSet * settings;
	rdpKeyboardLayout * layouts;
	char * p;
	RD_PLUGIN_DATA plugin_data[MAX_PLUGIN_DATA + 1];
	int index;
	int i, j;
	struct passwd * pw;
	int num_extensions;
	int rv;

	set_default_params(xfi);
	settings = xfi->settings;
	num_extensions = 0;
	p = getlogin();
	i = sizeof(settings->username) - 1;
	if (p != 0)
	{
		strncpy(settings->username, p, i);
	}
	else
	{
		pw = getpwuid(getuid());
		if (pw != 0)
		{
			if (pw->pw_name != 0)
			{
				strncpy(settings->username, pw->pw_name, i);
			}
		}
	}

	if (argc < *pindex + 1)
	{
		if (*pindex == 1)
			printf("no parameters specified\n");
		return 1;
	}
	while (*pindex < argc)
	{
		if (strcmp("-a", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing server depth\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			settings->server_depth = atoi(argv[*pindex]);
		}
		else if (strcmp("-u", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing username\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			strncpy(settings->username, argv[*pindex], sizeof(settings->username) - 1);
			settings->username[sizeof(settings->username) - 1] = 0;
		}
		else if (strcmp("-p", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing password\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			strncpy(settings->password, argv[*pindex], sizeof(settings->password) - 1);
			settings->password[sizeof(settings->password) - 1] = 0;
			settings->autologin = 1;

			/*
			 * Overwrite original password which could be revealed by a simple "ps aux" command.
			 * This approach won't hide the password length, but it is better than nothing.
			 */

			memset(argv[*pindex], '*', strlen(argv[*pindex]));
		}
		else if (strcmp("-d", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing domain\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			strncpy(settings->domain, argv[*pindex], sizeof(settings->domain) - 1);
			settings->domain[sizeof(settings->domain) - 1] = 0;
		}
		else if (strcmp("-k", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing keyboard layout ID\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			sscanf(argv[*pindex], "%X", &(xfi->keyboard_layout_id));
			DEBUG_X11("keyboard layout ID: %X", xfi->keyboard_layout_id);
		}
		else if (strcmp("-K", argv[*pindex]) == 0)
		{
			xfi->grab_keyboard = 0;
		}
		else if (strcmp("--kbd-list", argv[*pindex]) == 0)
		{
			layouts = freerdp_kbd_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD);
			printf("\nKeyboard Layouts\n");
			for (i = 0; layouts[i].code; i++)
				printf("0x%08X\t%s\n", layouts[i].code, layouts[i].name);
			free(layouts);

			layouts = freerdp_kbd_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT);
			printf("\nKeyboard Layout Variants\n");
			for (i = 0; layouts[i].code; i++)
				printf("0x%08X\t%s\n", layouts[i].code, layouts[i].name);
			free(layouts);

			layouts = freerdp_kbd_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME);
			printf("\nKeyboard Input Method Editors (IMEs)\n");
			for (i = 0; layouts[i].code; i++)
				printf("0x%08X\t%s\n", layouts[i].code, layouts[i].name);
			free(layouts);

			return 1;
		}
		else if (strcmp("-s", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing shell\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			strncpy(settings->shell, argv[*pindex], sizeof(settings->shell) - 1);
			settings->shell[sizeof(settings->shell) - 1] = 0;
		}
		else if (strcmp("-c", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing directory\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			strncpy(settings->directory, argv[*pindex], sizeof(settings->directory) - 1);
			settings->directory[sizeof(settings->directory) - 1] = 0;
		}
		else if (strcmp("-g", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing width\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			settings->width = strtol(argv[*pindex], &p, 10);
			if (*p == 'x')
			{
				settings->height = strtol(p + 1, &p, 10);
			}
			if (*p == '%')
			{
				xfi->percentscreen = settings->width;
			}
		}
		else if (strcmp("-t", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing port number\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			settings->tcp_port_rdp = atoi(argv[*pindex]);
		}
		else if (strcmp("-T", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing window title\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			strncpy(xfi->window_title, argv[*pindex], sizeof(xfi->window_title) - 1);
			xfi->window_title[sizeof(xfi->window_title) - 1] = 0;
		}
		else if (strcmp("-n", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing hostname\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			strncpy(settings->hostname, argv[*pindex], sizeof(settings->hostname) - 1);
			settings->hostname[sizeof(settings->hostname) - 1] = 0;
		}
		else if (strcmp("-o", argv[*pindex]) == 0)
		{
			settings->console_audio = 1;
		}
		else if (strcmp("-0", argv[*pindex]) == 0)
		{
			settings->console_session = 1;
		}
		else if (strcmp("-z", argv[*pindex]) == 0)
		{
			settings->bulk_compression = 1;
		}
		else if (strcmp("--gdi", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing GDI rendering\n");
				return 1;
			}
			if (strncmp("sw", argv[*pindex], 1) == 0) /* Software */
			{
				settings->software_gdi = 1;
			}
			else if (strncmp("hw", argv[*pindex], 1) == 0) /* Hardware */
			{
				settings->software_gdi = 0;
			}
			else
			{
				printf("unknown GDI rendering\n");
				return 1;
			}
		}
		else if (strcmp("--no-osb", argv[*pindex]) == 0)
		{
			settings->off_screen_bitmaps = 0;
		}
		else if (strcmp("--rfx", argv[*pindex]) == 0)
		{
			settings->rfx_flags = 1;
			settings->ui_decode_flags = 1;
			settings->use_frame_ack = 0;
			settings->server_depth = 32;
			settings->performanceflags = PERF_FLAG_NONE;
			xfi->codec = XF_CODEC_REMOTEFX;
		}
		else if (strcmp("--app", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing application name\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			strncpy(settings->app_name, argv[*pindex], sizeof(settings->app_name) - 1);
			settings->app_name[sizeof(settings->app_name) - 1] = 0;
			settings->remote_app = 1;
		}
#ifdef HAVE_XV
		else if (strcmp("--xv-port", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			xfi->xv_port = atoi(argv[*pindex]);
		}
#endif
		else if (strcmp("-f", argv[*pindex]) == 0)
		{
			xfi->fullscreen = xfi->fs_toggle = 1;
			printf("full screen option\n");
		}
		else if (strcmp("-D", argv[*pindex]) == 0)
		{
			xfi->decoration = 0;
		}
		else if (strcmp("-x", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing performance flag\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			if (strncmp("m", argv[*pindex], 1) == 0) /* modem */
			{
				settings->performanceflags = PERF_DISABLE_WALLPAPER |
					PERF_DISABLE_FULLWINDOWDRAG | PERF_DISABLE_MENUANIMATIONS |
					PERF_DISABLE_THEMING;
			}
			else if (strncmp("b", argv[*pindex], 1) == 0) /* broadband */
			{
				settings->performanceflags = PERF_DISABLE_WALLPAPER;
			}
			else if (strncmp("l", argv[*pindex], 1) == 0) /* lan */
			{
				settings->performanceflags = PERF_FLAG_NONE;
			}
			else
			{
				settings->performanceflags = strtol(argv[*pindex], 0, 16);
			}
		} else if (strcmp("-X", argv[*pindex]) == 0) {
			*pindex = *pindex + 1;

			if (*pindex == argc) {
				printf("missing XID\n");
				exit(XF_EXIT_WRONG_PARAM);
			}

			xfi->embed = strtoul(argv[*pindex], NULL, 16);
			if (!xfi->embed) {
				printf("bad XID\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
		}
#ifndef DISABLE_TLS
		else if (strcmp("--no-rdp", argv[*pindex]) == 0)
		{
			settings->rdp_security = 0;
		}
		else if (strcmp("--no-tls", argv[*pindex]) == 0)
		{
			settings->tls_security = 0;
		}
		else if (strcmp("--no-nla", argv[*pindex]) == 0)
		{
			settings->nla_security = 0;
		}
		else if (strcmp("--sec", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing protocol security\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			if (strncmp("rdp", argv[*pindex], 1) == 0) /* Standard RDP */
			{
				settings->rdp_security = 1;
				settings->tls_security = 0;
				settings->nla_security = 0;
			}
			else if (strncmp("tls", argv[*pindex], 1) == 0) /* TLS */
			{
				settings->rdp_security = 0;
				settings->tls_security = 1;
				settings->nla_security = 0;
			}
			else if (strncmp("nla", argv[*pindex], 1) == 0) /* NLA */
			{
				settings->rdp_security = 0;
				settings->tls_security = 0;
				settings->nla_security = 1;
			}
			else
			{
				printf("unknown protocol security\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
		}
#endif
		else if (strcmp("--plugin", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing plugin name\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			index = *pindex;
			memset(plugin_data, 0, sizeof(plugin_data));
			if (*pindex < argc - 1 && strcmp("--data", argv[*pindex + 1]) == 0)
			{
				*pindex = *pindex + 2;
				i = 0;
				while (*pindex < argc && strcmp("--", argv[*pindex]) != 0 && i < MAX_PLUGIN_DATA)
				{
					plugin_data[i].size = sizeof(RD_PLUGIN_DATA);
					for (j = 0, p = argv[*pindex]; j < 4 && p != NULL; j++)
					{
						plugin_data[i].data[j] = p;
						if (j < 3)
						{
							p = strchr(plugin_data[i].data[j], ':');
							if (p != NULL)
								*p++ = 0;
						}
					}
					*pindex = *pindex + 1;
					i++;
				}
			}
			rv = freerdp_chanman_load_plugin(xfi->chan_man, settings, argv[index], plugin_data);
			if (rv)
				exit(XF_EXIT_WRONG_PARAM);
		}
		else if (strcmp("--ext", argv[*pindex]) == 0)
		{
			*pindex = *pindex + 1;
			if (*pindex == argc)
			{
				printf("missing extension name\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			if (num_extensions >= sizeof(settings->extensions) / sizeof(struct rdp_ext_set))
			{
				printf("maximum extensions reached\n");
				exit(XF_EXIT_WRONG_PARAM);
			}
			index = *pindex;
			snprintf(settings->extensions[num_extensions].name,
				sizeof(settings->extensions[num_extensions].name),
				"%s", argv[index]);
			settings->extensions[num_extensions].data = NULL;
			if (*pindex < argc - 1 && strcmp("--data", argv[*pindex + 1]) == 0)
			{
				*pindex = *pindex + 2;
				settings->extensions[num_extensions].data = argv[*pindex];
				i = 0;
				while (*pindex < argc && strcmp("--", argv[*pindex]) != 0)
				{
					*pindex = *pindex + 1;
					i++;
				}
			}
			num_extensions++;
		}
		else if ((strcmp("-h", argv[*pindex]) == 0) || strcmp("--help", argv[*pindex]) == 0)
		{
			out_args();
			return 1;
		}
		else if (strcmp("--version", argv[*pindex]) == 0)
		{
			printf("This is FreeRDP version %s\n", PACKAGE_VERSION);
			return 1;
		}
		else if (argv[*pindex][0] != '-')
		{
			settings->server[sizeof(settings->server) - 1] = 0;
			if (argv[*pindex][0] == '[' && (p = strchr(argv[*pindex], ']'))
				&& (p[1] == 0 || (p[1] == ':' && !strchr(p + 2, ':'))))
			{
				/* Either "[...]" or "[...]:..." with at most one : after the brackets */
				strncpy(settings->server, argv[*pindex] + 1, sizeof(settings->server) - 1);
				if ((p = strchr(settings->server, ']')))
				{
					*p = 0;
					if (p[1] == ':')
						settings->tcp_port_rdp = atoi(p + 2);
				}
			}
			else
			{
				/* Port number is cut off and used if exactly one : in the string */
				strncpy(settings->server, argv[*pindex], sizeof(settings->server) - 1);
				if ((p = strchr(settings->server, ':')) && !strchr(p + 1, ':'))
				{
					*p = 0;
					settings->tcp_port_rdp = atoi(p + 1);
				}
			}
			/* server is the last argument for the current session. arguments
			   followed will be parsed for the next session. */
			*pindex = *pindex + 1;

			return 0;
		}
		else
		{
			printf("invalid option: %s\n", argv[*pindex]);
			exit(XF_EXIT_WRONG_PARAM);
		}
		*pindex = *pindex + 1;
	}
	printf("missing server name\n");
	exit(XF_EXIT_WRONG_PARAM);
}
Пример #12
0
Emitter :: Emitter(float* field_f, int nx, int ny) : 
	f(field_f), field_nx(nx), field_ny(ny) 
{
	step = 0;
	set_default_params();
}