Example #1
0
paudio_settings_t paudio_settings_of_json(Json::Value &root, portaudio::System &pa_system) {
    paudio_settings_t ret;

    try {
        ret.sample_rate   = root["sample_rate"].asDouble();

        ret.host_api = static_cast<PaHostApiTypeId>(
            lookup_by_name(paudio_api_names, root["host_api"].asCString())
        );

        ret.device = 0;
        auto &host_api = pa_system.hostApiByTypeId(ret.host_api);
        const char *device_name = root["device"].asCString();
        for (auto idx = host_api.devicesBegin(); idx != host_api.devicesEnd(); ++idx) {
            if (strcmp(device_name, idx->name()) == 0) {
                ret.device = idx->index();
            }
        }

        ret.latency       = root["latency"].asDouble();
        ret.buffer_length = root["buffer_length"].asUInt();
        ret.channels      = root["channels"].asUInt();
    } catch (std::runtime_error e) {
        ret.sample_rate        = 0;
        ret.host_api           = paInDevelopment;
        ret.device             = 0;
        ret.latency            = 0;
        ret.buffer_length      = 0;
        ret.channels           = 0;
    }
    return ret;
}
Example #2
0
uint16_t
rrclass_from_string(const char *name)
{
        char *end;
        long rrclass;
	lookup_table_type *entry;

	entry = lookup_by_name(dns_rrclasses, name);
	if (entry) {
		return (uint16_t) entry->id;
	}

	if (strlen(name) < 6)
		return 0;

	if (strncasecmp(name, "CLASS", 5) != 0)
		return 0;

	if (!isdigit((unsigned char)name[5]))
		return 0;

	/* The rest from the string must be a number.  */
	rrclass = strtol(name + 5, &end, 10);
	if (*end != '\0')
		return 0;
	if (rrclass < 0 || rrclass > 65535L)
		return 0;

	return (uint16_t) rrclass;
}
Example #3
0
static boolean lookup_variable(char *name, lispobj *result)
{
    struct var *var = lookup_by_name(name);

    if (var == NULL)
        return 0;
    else {
        *result = var_value(var);
        return 1;
    }
}
Example #4
0
uint16_t *
zparser_conv_algorithm(region_type *region, const char *text)
{
	const lookup_table_type *alg;
	uint8_t id;

	alg = lookup_by_name(dns_algorithms, text);
	if (alg) {
		id = (uint8_t) alg->id;
	} else {
		char *end;
		id = (uint8_t) strtol(text, &end, 10);
		if (*end != '\0') {
			zc_error_prev_line("algorithm is expected");
			return NULL;
		}
	}

	return alloc_rdata_init(region, &id, sizeof(id));
}
Example #5
0
uint16_t *
zparser_conv_certificate_type(region_type *region, const char *text)
{
	/* convert an algorithm string to integer */
	const lookup_table_type *type;
	uint16_t id;

	type = lookup_by_name(dns_certificate_types, text);
	if (type) {
		id = htons((uint16_t) type->id);
	} else {
		char *end;
		id = htons((uint16_t) strtol(text, &end, 10));
		if (*end != '\0') {
			zc_error_prev_line("certificate type is expected");
			return NULL;
		}
	}

	return alloc_rdata_init(region, &id, sizeof(id));
}
Example #6
0
/*
 * Implements lookup by name for scoped names
 */
AST_Decl *
UTL_Scope::lookup_by_name(UTL_ScopedName *e, idl_bool treat_as_ref, 
                          idl_bool in_parent)
{
   AST_Decl *d;
   UTL_Scope *t = NULL;

   /*
    * Empty name? error
    */

   if (e == NULL)
   {
      return NULL;
   }

   /*
    * If name starts with "::" or "" start search up in global scope
    */
   if (is_global_name(e->head()))
   {
      /*
       * Get parent scope
       */
      d = ScopeAsDecl(this);

      if (d == NULL)
         return NULL;

      t = d->defined_in();

      /*
       * If this is the global scope..
       */
      if (t == NULL)
      {
         /*
          * Look up tail of name starting here
          */
         d = lookup_by_name((UTL_ScopedName *) e->tail(), treat_as_ref);
         /*
          * Now return whatever we have
          */ 
         return d;
      }

      /*
       * OK, not global scope yet, so simply iterate with parent scope
       */
      d = t->lookup_by_name(e, treat_as_ref);

      /*
       * If treat_as_ref is true and d is not NULL, add d to
       * set of nodes referenced here
       */
      if (treat_as_ref && d != NULL)
         add_to_referenced(d, I_FALSE);

      /*
       * Now return what we have
       */ 
      return d;
   }

   /*
    * The name does not start with "::"
    *
    * Is name defined here?
    */
   d = lookup_by_name_local (e->head ());

   /*
    * Special case for scope which is an interface. We have to look
    * in the inherited interfaces as well..
    */
   if (d == NULL)
   {
      if (pd_scope_node_type == AST_Decl::NT_interface)
      {
         d = look_in_inherited(e, treat_as_ref);

         if (treat_as_ref && d != NULL)
         {
            add_to_referenced(d, I_FALSE);
            /*
             * OK, now return whatever we found
             */ 
            return d;
         }
      }
   }

   /* Only traverse parent scope chain if not in inherited interface. */
   if (d == NULL && !in_parent)
   {
      /*
       * OK, not found. Go down parent scope chain.
       */
      d = ScopeAsDecl(this);

      if (d != NULL)
      {
         t = d->defined_in();

         if (t == NULL)
            d = NULL;
         else
            d = t->lookup_by_name(e, treat_as_ref);
      }

      /*
       * If treat_as_ref is true and d is not NULL, add d to
       * set of nodes referenced here
       */
      if (treat_as_ref && d != NULL)
         add_to_referenced(d, I_FALSE);

      /*
       * OK, now return whatever we found
       */ 
      return d;
   }

   /*
    * OK, start of name is defined. Now loop doing local lookups
    * of subsequent elements of the name
    */
   d = iter_lookup_by_name_local(d, e, treat_as_ref);

   /*
    * If treat_as_ref is true and d is not NULL, add d to set
    * of nodes referenced here.
    */
   if (treat_as_ref && d != NULL)
      add_to_referenced(d, I_FALSE);

   /*
    * All OK, name fully resolved
    */ 
   return d;
}