예제 #1
0
  void PCI_Device::probe_resources() noexcept {
    //Find resources on this PCI device (scan the BAR's)
    uint32_t value {PCI::WTF};
  
    uint32_t reg {0};
    uint32_t len {0};

    for(int bar {0}; bar < 6; ++bar) {
      //Read the current BAR register 
      reg = PCI::CONFIG_BASE_ADDR_0 + (bar << 2);
      value = read_dword(reg);

      if (!value) continue;

      //Write all 1's to the register, to get the length value (osdev)
      write_dword(reg, 0xFFFFFFFF);
      len = read_dword(reg);
    
      //Put the value back
      write_dword(reg, value);
    
      uint32_t unmasked_val  {0};
      uint32_t pci__size     {0};

      if (value & 1) {  // Resource type IO

        unmasked_val = value & PCI::BASE_ADDRESS_IO_MASK;
        pci__size = pci_size(len, PCI::BASE_ADDRESS_IO_MASK & 0xFFFF);
      
        // Add it to resource list
        add_resource(new Resource(unmasked_val, pci__size), res_io_);
        assert(res_io_ != nullptr);        
      
      } else { //Resource type Mem

        unmasked_val = value & PCI::BASE_ADDRESS_MEM_MASK;
        pci__size = pci_size(len, PCI::BASE_ADDRESS_MEM_MASK);

        //Add it to resource list
        add_resource(new Resource(unmasked_val, pci__size), res_mem_);
        assert(res_mem_ != nullptr);
      }

      INFO2("");
      INFO2("[ Resource @ BAR %i ]", bar);
      INFO2("  Address:  0x%x Size: 0x%x", unmasked_val, pci__size);
      INFO2("  Type: %s", value & 1 ? "IO Resource" : "Memory Resource");   
    }
  
    INFO2("");
  }
예제 #2
0
rd_t open_buf_stream(char *buf) {
    struct buf_stream *env = malloc(sizeof(struct buf_stream)); 
    if (!env) {
        printk("OOPS: Could not allocate space for buffer stream resource.\r\n");
        return -1;
    }

    resource *new_r = create_new_resource();
    if (!new_r) {
        printk("OOPS: Unable to allocate space for buffer stream resource.\r\n");
        free(env);
        return -1;
    }

    env->buf = buf;

    new_r->env    = env;
    new_r->writer = &buf_stream_write;
    new_r->swriter = NULL;
    new_r->reader = &buf_stream_read;
    new_r->closer = &buf_stream_close;
    new_r->sem    = malloc(sizeof(semaphore));
    if (new_r->sem) {
        init_semaphore(new_r->sem);
    }
    else {
        printk("OOPS: Unable to allocate memory for buffer stream semaphore.\r\n");
        kfree(new_r);
        free(env);
        return -1;
    }

    return add_resource(curr_task->task, new_r);
}
예제 #3
0
파일: region.c 프로젝트: Xolgrim/server
void region_setresource(region * r, const resource_type * rtype, int value)
{
    rawmaterial *rm = r->resources;
    while (rm) {
        if (rm->type->rtype == rtype) {
            rm->amount = value;
            break;
        }
        rm = rm->next;
    }
    if (!rm) {
        if (rtype == get_resourcetype(R_SILVER))
            rsetmoney(r, value);
        else if (rtype == get_resourcetype(R_PEASANT))
            rsetpeasants(r, value);
        else if (rtype == get_resourcetype(R_HORSE))
            rsethorses(r, value);
        else {
            int i;
            for (i = 0; r->terrain->production[i].type; ++i) {
                const terrain_production *production = r->terrain->production + i;
                if (production->type == rtype) {
                    add_resource(r, 1, value, dice_rand(production->divisor), rtype);
                    break;
                }
            }
        }
    }
}
예제 #4
0
void ResourcePreloader::add_resource(const StringName& p_name,const RES& p_resource) {


	ERR_FAIL_COND(p_resource.is_null());
	if (resources.has(p_name)) {


		StringName new_name;
		int idx=2;

		while(true) {

			new_name=p_name.operator String()+" "+itos(idx);
			if (resources.has(new_name)) {
				idx++;
				continue;
			}

			break;

		}

		add_resource(new_name,p_resource);
	} else {

		resources[p_name]=p_resource;
	}



}
예제 #5
0
파일: resources.c 프로젝트: Xolgrim/server
void terraform_resources(region * r)
{
    int i;
    const terrain_type *terrain = r->terrain;
    static int terraform_all = -1;
    if (terraform_all < 0) {
        terraform_all = get_param_int(global.parameters, "rules.terraform.all", 0);
    }

    if (terrain->production == NULL)
        return;
    for (i = 0; terrain->production[i].type; ++i) {
        rawmaterial *rm;
        const terrain_production *production = terrain->production + i;
        const resource_type *rtype = production->type;

        for (rm = r->resources; rm; rm = rm->next) {
            if (rm->type->rtype == rtype)
                break;
        }
        if (rm) {
            continue;
        }

        if (terraform_all || chance(production->chance)) {
            add_resource(r, dice_rand(production->startlevel),
                dice_rand(production->base), dice_rand(production->divisor),
                production->type);
        }
    }
}
예제 #6
0
파일: res32.c 프로젝트: r6144/wine
/* load the next resource from the current file */
static void load_next_resource( DLLSPEC *spec )
{
    unsigned int hdr_size;
    struct resource *res = add_resource( spec );

    res->data_size = get_dword();
    hdr_size = get_dword();
    if (hdr_size & 3) fatal_error( "%s header size not aligned\n", input_buffer_filename );
    if (hdr_size < 32) fatal_error( "%s invalid header size %u\n", input_buffer_filename, hdr_size );

    res->data = input_buffer + input_buffer_pos - 2*sizeof(unsigned int) + hdr_size;
    if ((const unsigned char *)res->data < input_buffer ||
        (const unsigned char *)res->data >= input_buffer + input_buffer_size)
        fatal_error( "%s invalid header size %u\n", input_buffer_filename, hdr_size );
    get_string( &res->type );
    get_string( &res->name );
    if (input_buffer_pos & 2) get_word();  /* align to dword boundary */
    get_dword();                        /* skip data version */
    res->mem_options = get_word();
    res->lang = get_word();
    get_dword();                        /* skip version */
    get_dword();                        /* skip characteristics */

    input_buffer_pos = ((const unsigned char *)res->data - input_buffer) + ((res->data_size + 3) & ~3);
    input_buffer_pos = (input_buffer_pos + 3) & ~3;
    if (input_buffer_pos > input_buffer_size)
        fatal_error( "%s is a truncated file\n", input_buffer_filename );
}
예제 #7
0
void ResourcesDock::save_resource_as(const Ref<Resource>& p_resource) {


	add_resource(p_resource);
	TreeItem *root=resources->get_root();
	ERR_FAIL_COND(!root);

	TreeItem *existing=root->get_children();

	while(existing) {

		Ref<Resource> r = existing->get_metadata(0);
		if (r==p_resource) {
			//existing->move_to_top();
			existing->select(0);
			resources->ensure_cursor_is_visible();
			return; // existing
		}
		existing=existing->get_next();
	}

	ERR_FAIL_COND(!existing);

	existing->select(0);

	_tool_selected(TOOL_SAVE_AS);




}
예제 #8
0
파일: resman.c 프로젝트: jtsiomb/libresman
int resman_add(struct resman *rman, const char *fname, void *data)
{
	int ridx;

	if((ridx = find_resource(rman, fname)) != -1) {
		return ridx;
	}

	/* resource not found, create a new one and start a loading job */
	return add_resource(rman, fname, data);
}
예제 #9
0
void ResourcePreloader::rename_resource(const StringName& p_from_name,const StringName& p_to_name) {

	ERR_FAIL_COND( !resources.has(p_from_name) );

	RES res = resources[p_from_name];

	resources.erase(p_from_name);
	add_resource(p_to_name,res);



}
예제 #10
0
파일: autoseed.c 프로젝트: philbooth/server
int seed_adamantium(region * r, int base)
{
    const resource_type *rtype = rt_find("adamantium");
    rawmaterial *rm;
    for (rm = r->resources; rm; rm = rm->next) {
        if (rm->type->rtype == rtype)
            break;
    }
    if (!rm) {
        add_resource(r, 1, base, 150, rtype);
    }
    return 0;
}
예제 #11
0
return_type fsOpen(const int nparams, arg_type *a) {
    if (nparams != 2) {
        r.return_val = set_error(EINVAL);
        r.in_error = 1;
        r.return_size = sizeof(int);
        return r;
    }

    char * folderName = a->arg_val;
    int mode = *(int*)a->next->arg_val;

    struct resource_queue * resource = find_resource(folderName, FILTER_BY_PATH);

    if (client_use_resource(resource, current_client, mode)) {
        char * serverFolder = append_local_path(folderName);

        int flag;
        if (mode == 0) {
            flag = O_RDONLY;
        } else {
            flag = O_WRONLY | O_CREAT;
        }

        int *fileDescriptor = (int*)malloc(sizeof(int));
        *fileDescriptor = open(serverFolder, flag, S_IRWXU);

        if (*fileDescriptor < 0) {
            r.return_val = set_error(EBADF);
            r.in_error = 1;
            r.return_size = sizeof(int);
        } else {
            resource = add_resource(folderName, *fileDescriptor, mode, current_client);

            r.return_val = (void *)fileDescriptor;
            r.return_size = sizeof(int);
            r.in_error = 0;
        }

        free(serverFolder);
    } else {
        add_client_to_resource(resource, current_client);
        r.return_val = set_error(EBUSY);
        r.return_size = sizeof(int);
        r.in_error = 1;
    }

    return r;
}
예제 #12
0
	ResourcePtr ResourceProvider::get( const ResourceInfo& resource_infos )
	{
		auto resource = find( resource_infos );

		if( resource )
			return resource;

		resource = create_resource( resource_infos );

		if( resource )
		{
			add_resource( resource_infos, resource );
		}

		return resource;
	}
예제 #13
0
		void environment::start()
		{
			end();

			m_time = 0;
			m_running = true;

			m_world.resize(settings::world_width, settings::world_height);
			m_world.generate(m_settings.seed());

			spawn_player(m_world.spawn() * point2(settings::cell_width, settings::cell_height));

			// ui
			tie_map();
			m_ui->deactivate("title");
			m_ui->activate("ingame");

			// make chest
			auto chest = m_factory->produce();
			chest->add_appearance('$', { 1, 1, 1 });
			chest->add_location({ 2, 2 });
			auto body = chest->add_body(250, 150);
			body->set_name("Iron chest");
			chest->add_container();
			m_terrain.add(*chest);

			auto ore = std::make_shared<body_component::item_type>();
			ore->add({ rl::effect::ore_power, 0x00, 10 });
			ore->add({ rl::effect::value, 0x00, 5 });
			ore->add({ rl::effect::weight, 0x00, 1 });
			ore->set_name("Copper ore");
			ore->set_tag("ore_copper");
			auto vein = m_factory->produce();
			vein->add_appearance('0');
			vein->add_location({ 3, 3 });
			vein->add_body();
			auto v = vein->add_resource();
			v->deposit(ore);
			m_terrain.add(*vein);

			auto anvil = m_factory->produce();
			anvil->add_appearance('t');
			anvil->add_location({ 3, 0 });
			anvil->add_body();
			anvil->add_container();
			m_terrain.add(*anvil);
		}
예제 #14
0
int				ser_prend(t_env *env, t_fd *fd, char *cmd)
{
	t_square	*sq;
	int			quantity_sq;
	t_resource	res;

	sq = get_square(env, fd->trantor.pos_x, fd->trantor.pos_y);
	res = str_to_resource(cmd + 6);
	quantity_sq = nb_res_in_inventory(&sq->content, res);
	if (quantity_sq < 1)
	{
		send_cmd_to_client(fd, MSG_KO);
		return (-1);
	}
	add_resource(&fd->trantor.inventory, res);
	del_resource(&sq->content, res);
	send_infos(env, fd, res);
	return (0);
}
예제 #15
0
bunsan::dcs::hub_interfaces::xmlrpc::xmlrpc(const boost::property_tree::ptree &config, const hub_ptr &hub__):
    hub_(hub__), port(config.get<unsigned int>("server.port")), registry(new xmlrpc_c::registry)
{
    xmlrpc_c::methodPtr
        add_machine(new method_add_machine(hub_)),
        set_capacity(new method_set_capacity(hub_)),
        remove_machine(new method_remove_machine(hub_)),
        clear(new method_clear(hub_)),
        add_resource(new method_add_resource(hub_)),
        set_resource_uri(new method_set_resource_uri(hub_)),
        remove_resource(new method_remove_resource(hub_)),
        select_resource(new method_select_resource(hub_));
    registry->addMethod("add_machine", add_machine);
    registry->addMethod("set_capacity", set_capacity);
    registry->addMethod("remove_machine", remove_machine);
    registry->addMethod("clear", clear);
    registry->addMethod("add_resource", add_resource);
    registry->addMethod("set_resource_uri", set_resource_uri);
    registry->addMethod("remove_resource", remove_resource);
    registry->addMethod("select_resource", select_resource);
}
예제 #16
0
rd_t open_px4_mpu6000(void) {
    /* Set up CS pin and set high */
    *RCC_AHB1ENR |= RCC_AHB1ENR_GPIOBEN;

    /* PB0 */
    gpio_moder(GPIOB, 0, GPIO_MODER_OUT);
    gpio_otyper(GPIOB, 0, GPIO_OTYPER_PP);
    gpio_pupdr(GPIOB, 0, GPIO_PUPDR_NONE);
    gpio_ospeedr(GPIOB, 0, GPIO_OSPEEDR_50M);
    
    /* idle CS */
    cs_high();

    resource *new_r = create_new_resource();
    if (!new_r) {
        printk("OOPS: Could not allocate space for mpu6000 resource.\r\n");
        return -1;
    }

    struct mpu6000 *env = (struct mpu6000 *) kmalloc(sizeof(struct mpu6000));
    if (!env) {
        printk("OOPS: Could not allocate space for mpu6000 resource.\r\n");
        kfree(new_r);
        return -1;
    }

    env->spi_port = &spi1;
    if (!env->spi_port->ready) {
        env->spi_port->init();
    }

    env->spi_dev.cs_high = &cs_high;
    env->spi_dev.cs_low = &cs_low;
    env->read_ctr = 0;

    acquire(&spi1_semaphore);

    /* Active mode, clock with gyro X reference */
    uint8_t data = MPU6000_PWR_MGMT_1_CLK_PLLGYROX;
    if (spi_write(env->spi_port, &env->spi_dev, MPU6000_PWR_MGMT_1, &data, 1) != 1) {
        /* Unable to activate :( */
        release(&spi1_semaphore);
        kfree(env);
        kfree(new_r);
        return -1;
    }

    release(&spi1_semaphore);

    /* Let clock settle */
    usleep(1000);

    acquire(&spi1_semaphore);

    /* 100Hz LPF, Gyro range +- 500deg/s, Accel range +-4g */
    uint8_t config[3] = {MPU6000_CONFIG_LPF_100HZ, MPU6000_GYRO_CONFIG_500DPS, MPU6000_ACCEL_CONFIG_4G};
    if (spi_write(env->spi_port, &env->spi_dev, MPU6000_CONFIG, config, 3) != 3) {
        data = MPU6000_PWR_MGMT_1_SLEEP;    /* Sleep mode */
        spi_write(env->spi_port, &env->spi_dev, MPU6000_PWR_MGMT_1, &data, 1);
        release(&spi1_semaphore);
        kfree(env);
        kfree(new_r);
        return -1;
    }

    release(&spi1_semaphore);

    new_r->env = (void *) env;
    new_r->reader = &px4_mpu6000_read;
    new_r->writer = &px4_mpu6000_write;
    new_r->closer = &px4_mpu6000_close;
    new_r->sem = &spi1_semaphore;

    return add_resource(curr_task->task, new_r);
}
예제 #17
0
파일: auvirt.c 프로젝트: yubo/audit
int process_resource_event(auparse_state_t *au)
{
	uid_t uid;
	time_t time;
	const char *res_type, *uuid, *name;
	char field[64];
	const char *reason;
	int success;

	/* Just skip this record if it failed to get some of the fields */
	if (extract_virt_fields(au, &uuid, &uid, &time, &name, &success))
		return 0;

	/* Get the resource type */
	auparse_first_record(au);
	res_type = auparse_find_field(au, "resrc");
	reason = auparse_find_field(au, "reason");
	if (res_type == NULL) {
		if (debug)
			fprintf(stderr, "Invalid resrc field.\n");
		return 0;
	}

	/* Resource records with these types have old and new values. New
	 * values indicate resources assignments and are added to the event
	 * list. Old values are used to update the end time of a resource
	 * assignment.
	 */
	int rc = 0;
	if (strcmp("disk", res_type) == 0 ||
	    strcmp("vcpu", res_type) == 0 ||
	    strcmp("mem", res_type) == 0 ||
	    strcmp("rng", res_type) == 0 ||
	    strcmp("net", res_type) == 0) {
		const char *res = NULL;
		/* Resource removed */
		snprintf(field, sizeof(field), "old-%s", res_type);
		if(auparse_find_field(au, field))
			res = auparse_interpret_field(au);
		if (res == NULL && debug) {
			fprintf(stderr, "Failed to get %s field.\n", field);
		} else {
			rc += update_resource(au, uuid, uid, time, name,
					success, reason, res_type, res);
		}

		/* Resource added */
		res = NULL;
		snprintf(field, sizeof(field), "new-%s", res_type);
		if (auparse_find_field(au, field))
			res = auparse_interpret_field(au);
		if (res == NULL && debug) {
			fprintf(stderr, "Failed to get %s field.\n", field);
		} else {
			rc += add_resource(au, uuid, uid, time, name, success,
					reason, res_type, res);
		}
	} else if (strcmp("cgroup", res_type) == 0) {
		auparse_first_record(au);
		const char *cgroup = NULL;
		if (auparse_find_field(au, "cgroup"))
			cgroup = auparse_interpret_field(au);
		rc += add_resource(au, uuid, uid, time, name, success, reason,
				res_type, cgroup);
	} else if (debug) {
		fprintf(stderr, "Found an unknown resource: %s.\n",
				res_type);
	}
	return rc;
}
예제 #18
0
파일: glue.c 프로젝트: hharte/c3270
void
parse_xrm(const char *arg, const char *where)
{
	const char *name;
	unsigned rnlen;
	const char *s;
	int i;
	char *t;
	void *address = NULL;
	enum resource_type type = XRM_STRING;
	Boolean quoted;
	char c;
#if defined(C3270) /*[*/
	char *hide;
	Boolean arbitrary = False;
#endif /*]*/

	/* Validate and split. */
	if (validate_and_split_resource(where, arg, &name, &rnlen, &s) < 0)
	    	return;

	/* Look up the name. */
	for (i = 0; resources[i].name != CN; i++) {
		if (!strncapcmp(resources[i].name, name, rnlen)) {
			address = resources[i].address;
			type = resources[i].type;
			break;
		}
	}
	if (address == NULL) {
		for (i = 0; toggle_names[i].name != NULL; i++) {
			if (!strncapcmp(toggle_names[i].name, name, rnlen)) {
				address =
				    &appres.toggle[toggle_names[i].index].value;
				type = XRM_BOOLEAN;
				break;
			}
		}
	}
	/* XXX: This needs to work for s3270, too. */
#if defined(C3270) /*[*/
	if (address == NULL && valid_explicit(name, rnlen) == 0) {
		/*
		 * Handle resources that are accessed only via get_resource().
		 */
		address = &hide;
		type = XRM_STRING;
		arbitrary = True;
	}
#endif /*]*/
	if (address == NULL) {
		xs_warning("%s: Unknown resource name: %.*s",
		    where, (int)rnlen, name);
		return;
	}
	switch (type) {
	case XRM_BOOLEAN:
		if (!strcasecmp(s, "true") ||
		    !strcasecmp(s, "t") ||
		    !strcmp(s, "1")) {
			*(Boolean *)address = True;
		} else if (!strcasecmp(s, "false") ||
		    !strcasecmp(s, "f") ||
		    !strcmp(s, "0")) {
			*(Boolean *)address = False;
		} else {
			xs_warning("%s: Invalid Boolean value: %s", where, s);
			*(Boolean *)address = False;
		}
		break;
	case XRM_STRING:
		t = Malloc(strlen(s) + 1);
		*(char **)address = t;
		quoted = False;
#if defined(WC3270) /*[*/
		/*
		 * Hack to allow unquoted UNC-path printer names from older
		 * versions of the Session Wizard to continue to work, even
		 * though the rules now require quoted backslashes in resource
		 * values.
		 */
		if (!strncapcmp(ResPrinterName, name, rnlen) &&
		    s[0] == '\\' &&
		    s[1] == '\\' &&
		    s[2] != '\\' &&
		    strchr(s + 2, '\\') != NULL) {
			strcpy(t, s);
			break;
		}
#endif /*]*/

		while ((c = *s++) != '\0') {
			if (quoted) {
				switch (c) {
				case 'b':
					*t++ = '\b';
					break;
				case 'f':
					*t++ = '\f';
					break;
				case 'n':
					*t++ = '\n';
					break;
				case 'r':
					*t++ = '\r';
					break;
				case 't':
					*t++ = '\t';
					break;
				case '\\':
					/* Quote the backslash. */
					*t++ = '\\';
					break;
				default:
					/* Eat the backslash. */
					*t++ = c;
					break;
				}
				quoted = False;
			} else if (c == '\\') {
				quoted = True;
			} else {
				*t++ = c;
			}
		}
		*t = '\0';
		break;
	case XRM_INT: {
		long n;
		char *ptr;

		n = strtol(s, &ptr, 0);
		if (*ptr != '\0') {
			xs_warning("%s: Invalid Integer value: %s", where, s);
		} else {
			*(int *)address = (int)n;
		}
		break;
		}
	}

#if defined(C3270) /*[*/
	/* Add a new, arbitrarily-named resource. */
	if (arbitrary) {
		char *rsname;

		rsname = Malloc(rnlen + 1);
		(void) strncpy(rsname, name, rnlen);
		rsname[rnlen] = '\0';
		add_resource(rsname, hide);
	}
#endif /*]*/
}
예제 #19
0
 // Functions to add processing units to thread pools via
 // the pu/core/numa_domain API
 void add_resource(hpx::resource::pu const& p,
     std::string const& pool_name, std::size_t num_threads = 1)
 {
     add_resource(p, pool_name, true, num_threads);
 }
예제 #20
0
파일: glue.c 프로젝트: hharte/c3270
/*
 * Pick out command-line options and set up appres.
 */
static void
parse_options(int *argcp, const char **argv)
{
	int i, j;
	int argc_out = 0;
	const char **argv_out =
	    (const char **) Malloc((*argcp + 1) * sizeof(char *));

	/* Parse the command-line options. */
	argv_out[argc_out++] = argv[0];

	for (i = 1; i < *argcp; i++) {
		for (j = 0; opts[j].name != CN; j++) {
			if (!strcmp(argv[i], opts[j].name))
				break;
		}
		if (opts[j].name == CN) {
			argv_out[argc_out++] = argv[i];
			continue;
		}

		switch (opts[j].type) {
		    case OPT_BOOLEAN:
			*(Boolean *)opts[j].aoff = opts[j].flag;
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].name),
					     opts[j].flag? "True": "False");
			break;
		    case OPT_STRING:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			*(const char **)opts[j].aoff = argv[++i];
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].res_name),
					     NewString(argv[i]));
			break;
		    case OPT_XRM:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			parse_xrm(argv[++i], "-xrm");
			break;
		    case OPT_SKIP2:
			argv_out[argc_out++] = argv[i++];
			if (i < *argcp)
				argv_out[argc_out++] = argv[i];
			break;
		    case OPT_NOP:
			break;
		    case OPT_INT:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			*(int *)opts[j].aoff = atoi(argv[++i]);
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].name),
					     NewString(argv[i]));
			break;
		    case OPT_V:
			dump_version();
			break;
		    case OPT_DONE:
			while (i < *argcp)
				argv_out[argc_out++] = argv[i++];
			break;
		}
	}
	*argcp = argc_out;
	argv_out[argc_out] = CN;
	(void) memcpy((char *)argv, (char *)argv_out,
	    (argc_out + 1) * sizeof(char *));
	Free((char *)argv_out);
}
예제 #21
0
파일: 9dof_gyro.c 프로젝트: checko/F4OS
rd_t open_sfe9dof_gyro(void) {
    rd_t ret;

    sfe9dof_gyro *gyro = kmalloc(sizeof(sfe9dof_gyro));
    if (!gyro) {
        ret = -1;
        goto err;
    }

    resource *new_r = create_new_resource();
    if(!new_r) {
        ret = -1;
        goto err_free_gyro;
    }

    /* We expect that spi1 was init'd in bootmain.c */
    gyro->i2c_port = &i2c1;
    gyro->addr_ctr = 0;
    /* Address on I2C bus of gyro. */
    gyro->device_addr = 0x68;
    gyro->tmp_addr = 0x1D;

    if (!(gyro->i2c_port->ready)) {
        gyro->i2c_port->init();
    }

    acquire(&i2c1_semaphore);

    /* Fire it up, fire it up/ When we finally turn it over, make a b-line towards the boat, or... */
    uint8_t packet[2];
    packet[0] = 0x15;
    packet[1] = 0x07;
    if (i2c_write(gyro->i2c_port, gyro->device_addr, packet, 2) != 2) {
        ret = -1;
        goto err_release_sem;
    }

    packet[0] = 0x16;
    packet[1] = 0x18;
    if (i2c_write(gyro->i2c_port, gyro->device_addr, packet, 2) != 2) {
        ret = -1;
        goto err_release_sem;
    }

    release(&i2c1_semaphore);

    new_r->env = gyro;
    new_r->writer = &sfe9dof_gyro_write;
    new_r->reader = &sfe9dof_gyro_read;
    new_r->closer = &sfe9dof_gyro_close;
    new_r->read_sem = &i2c1_semaphore;
    new_r->write_sem = &i2c1_semaphore;

    ret = add_resource(curr_task, new_r);
    if (ret < 0) {
        goto err_free_new_r;
    }

    return ret;

err_release_sem:
    release(&i2c1_semaphore);
err_free_new_r:
    kfree(new_r);
err_free_gyro:
    kfree(gyro);
err:
    printk("OOPS: Unable to open 9DOF gyro,\r\n");
    return ret;
}
예제 #22
0
void ResourcesDock::_tool_selected(int p_tool) {

	current_action=p_tool;

	switch(p_tool) {

		case TOOL_NEW: {

			create_dialog->popup_centered_ratio();
		} break;
		case TOOL_OPEN: {
			editor->open_resource();

		} break;
		case TOOL_SAVE: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);


			if (current_res->get_path()!="" && current_res->get_path().find("::")==-1) {
				_file_action(current_res->get_path());
				break;
			};

		}; /* fallthrough */
		case TOOL_SAVE_AS: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;

			save_resource_as(ti->get_metadata(0));


		} break;
		case TOOL_MAKE_LOCAL: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);
			current_res->set_path("");
			_update_name(ti);
		} break;
		case TOOL_COPY: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);
			EditorSettings::get_singleton()->set_resource_clipboard(current_res);

		} break;
		case TOOL_PASTE: {

			add_resource(EditorSettings::get_singleton()->get_resource_clipboard());
		} break;

	}
}
예제 #23
0
파일: glue.c 프로젝트: Oxyoptia/x3270
/*
 * Pick out command-line options and set up appres.
 */
static void
parse_options(int *argcp, const char **argv)
{
    int i;
    unsigned j;
    int argc_out = 0;
    const char **argv_out =
	(const char **) Malloc((*argcp + 1) * sizeof(char *));
    optlist_t *o;
    opt_t *opts;

    /* Parse the command-line options. */
    argv_out[argc_out++] = argv[0];

    for (i = 1; i < *argcp; i++) {
	bool found = false;

	for (o = optlist; o != NULL && !found; o = o->next) {
	    opts = o->opts;
	    for (j = 0; j < o->count; j++) {
		if (!strcmp(argv[i], opts[j].name)) {
		    found = true;
		    break;
		}
	    }
	}
	if (!found) {
	    argv_out[argc_out++] = argv[i];
	    continue;
	}

	switch (opts[j].type) {
	case OPT_BOOLEAN:
	    *(bool *)opts[j].aoff = opts[j].flag;
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].name),
			opts[j].flag? "true": "false");
	    }
	    break;
	case OPT_STRING:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    *(const char **)opts[j].aoff = argv[++i];
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].res_name), NewString(argv[i]));
	    }
	    break;
	case OPT_XRM:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    parse_xrm(argv[++i], "-xrm");
	    break;
	case OPT_SKIP2:
	    argv_out[argc_out++] = argv[i++];
	    if (i < *argcp) {
		argv_out[argc_out++] = argv[i];
	    }
	    break;
	case OPT_NOP:
	    break;
	case OPT_INT:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    *(int *)opts[j].aoff = atoi(argv[++i]);
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].name), NewString(argv[i]));
	    }
	    break;
	case OPT_V:
	    dump_version();
	    break;
	case OPT_DONE:
	    while (i < *argcp) {
		argv_out[argc_out++] = argv[i++];
	    }
	    break;
	}
    }
    *argcp = argc_out;
    argv_out[argc_out] = NULL;
    (void) memcpy((char *)argv, (char *)argv_out,
    (argc_out + 1) * sizeof(char *));
    Free((char *)argv_out);
}
예제 #24
0
void ResourcesDock::_tool_selected(int p_tool) {

	current_action=p_tool;

	switch(p_tool) {

		case TOOL_NEW: {

			create_dialog->popup_centered_ratio();
		} break;
		case TOOL_OPEN: {
			editor->open_resource();

		} break;
		case TOOL_SAVE: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);


			if (current_res->get_path()!="" && current_res->get_path().find("::")==-1) {
				_file_action(current_res->get_path());
				break;
			};

		}; /* fallthrough */
		case TOOL_SAVE_AS: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);

			RES res(current_res);

			List<String> extensions;
			ResourceSaver::get_recognized_extensions(res,&extensions);
			file->set_mode(FileDialog::MODE_SAVE_FILE);
			//not for now?

			if (current_res->get_path()!="" && current_res->get_path().find("::")==-1) {

				file->set_current_path(current_res->get_path());
			} else {

				String existing;
				if (extensions.size()) {
					existing="new_"+res->get_type().to_lower()+"."+extensions.front()->get().to_lower();
				}

				file->set_current_file(existing);
			}

			file->clear_filters();
			for(int i=0;i<extensions.size();i++) {

				file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
			}

			//file->set_current_path(current_path);
			file->popup_centered_ratio();


		} break;
		case TOOL_MAKE_LOCAL: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);
			current_res->set_path("");
			_update_name(ti);
		} break;
		case TOOL_COPY: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);
			EditorSettings::get_singleton()->set_resource_clipboard(current_res);

		} break;
		case TOOL_PASTE: {

			add_resource(EditorSettings::get_singleton()->get_resource_clipboard());
		} break;

	}
}
예제 #25
0
파일: glue.c 프로젝트: laubstein/pw3270
void
parse_xrm(const char *arg, const char *where)
{
	static char me_dot[] = ME ".";
	static char me_star[] = ME "*";
	unsigned match_len;
	const char *s;
	unsigned rnlen;
	int i;
	char *t;
	void *address = NULL;
	enum resource_type type = XRM_STRING;
#if defined(C3270) /*[*/
	char *add_buf = CN;
	char *hide;
	Boolean arbitrary = False;
#endif /*]*/

	/* Enforce "-3270." or "-3270*" or "*". */
	if (!strncmp(arg, me_dot, sizeof(me_dot)-1))
		match_len = sizeof(me_dot)-1;
	else if (!strncmp(arg, me_star, sizeof(me_star)-1))
		match_len = sizeof(me_star)-1;
	else if (arg[0] == '*')
		match_len = 1;
	else {
		xs_warning("%s: Invalid resource syntax '%.*s', name must "
		    "begin with '%s'",
		    where, (int) sizeof(me_dot)-1, arg, me_dot);
		return;
	}

	/* Separate the parts. */
	s = arg + match_len;
	while (*s && *s != ':' && !isspace(*s))
		s++;
	rnlen = s - (arg + match_len);
	if (!rnlen) {
		xs_warning("%s: Invalid resource syntax, missing resource "
		    "name", where);
		return;
	}
	while (isspace(*s))
		s++;
	if (*s != ':') {
		xs_warning("%s: Invalid resource syntax, missing ':'", where);
		return;
	}
	s++;
	while (isspace(*s))
		s++;

	/* Look up the name. */
	for (i = 0; resources[i].name != CN; i++) {
		if (!strncapcmp(resources[i].name, arg + match_len, rnlen)) {
			address = resources[i].address;
			type = resources[i].type;
#if defined(C3270) /*[*/
			if (address == NULL) {
				add_buf = Malloc(strlen(s) + 1);
				address = add_buf;
			}
#endif /*]*/
			break;
		}
	}

#if defined(C3270) /*[*/
	if (address == NULL) {
		if (!strncasecmp(ResKeymap ".", arg + match_len,
		                 strlen(ResKeymap ".")) ||
		    !strncasecmp(ResCharset ".", arg + match_len,
		                 strlen(ResCharset ".")) ||
		    !strncasecmp(ResDisplayCharset ".", arg + match_len,
		                 strlen(ResDisplayCharset ".")) ||
		    !strncasecmp(ResCodepage ".", arg + match_len,
		                 strlen(ResCodepage ".")) ||
		    !strncasecmp("host.", arg + match_len, 5) ||
		    !strncasecmp("printer.", arg + match_len, 8) ||
#if defined(_WIN32) /*[*/
		    !strncasecmp(ResHostColorFor, arg + match_len,
			    strlen(ResHostColorFor)) ||
		    !strncasecmp(ResConsoleColorForHostColor, arg + match_len,
			    strlen(ResConsoleColorForHostColor))
#else /*][*/
		    !strncasecmp(ResCursesColorFor, arg + match_len,
			    strlen(ResCursesColorFor))
#endif /*]*/
		    ) {
			address = &hide;
			type = XRM_STRING;
			arbitrary = True;
		}
	}
#endif /*]*/
	if (address == NULL) {
		xs_warning("%s: Unknown resource name: %.*s",
		    where, (int)rnlen, arg + match_len);
		return;
	}
	switch (type) {
	case XRM_BOOLEAN:
		if (!strcasecmp(s, "true") ||
		    !strcasecmp(s, "t") ||
		    !strcmp(s, "1")) {
			*(Boolean *)address = True;
		} else if (!strcasecmp(s, "false") ||
		    !strcasecmp(s, "f") ||
		    !strcmp(s, "0")) {
			*(Boolean *)address = False;
		} else {
			xs_warning("%s: Invalid Boolean value: %s", where, s);
		}
		break;
	case XRM_STRING:
		t = Malloc(strlen(s) + 1);
		*(char **)address = t;
		if (*s == '"') {
			Boolean quoted = False;
			char c;

			s++;
			while ((c = *s++) != '\0') {
				if (quoted) {
					switch (c) {
					case 'n':
						*t++ = '\n';
						break;
					case 'r':
						*t++ = '\r';
						break;
					case 'b':
						*t++ = '\b';
						break;
					default:
						*t++ = c;
						break;
					}
					quoted = False;
				} else if (c == '\\') {
					quoted = True;
				} else if (c == '"') {
					break;
				} else {
					*t++ = c;
				}
			}
			*t = '\0';
		} else {
			(void) strcpy(t, s);
		}
		break;
	case XRM_INT: {
		long n;
		char *ptr;

		n = strtol(s, &ptr, 0);
		if (*ptr != '\0') {
			xs_warning("%s: Invalid Integer value: %s", where, s);
		} else {
			*(int *)address = (int)n;
		}
		break;
		}
	}

#if defined(C3270) /*[*/
	/* Add a new, arbitrarily-named resource. */
	if (arbitrary) {
		char *rsname;

		rsname = Malloc(rnlen + 1);
		(void) strncpy(rsname, arg + match_len, rnlen);
		rsname[rnlen] = '\0';
		add_resource(rsname, hide);
	}
#endif /*]*/
}