예제 #1
0
파일: main.c 프로젝트: lacombar/netbsd-alc
static void
command_fill(char *opt)
{
	char	*endptr;
	char	*p;
	char	*limit;
	int	c;

	p = (char *) strtoul(opt, &endptr, 16);
	if (opt == endptr) {
		bad_param();
		return;
	}

	opt = get_next_arg(opt);
	limit = (char *) strtoul(opt, &endptr, 16);
	if (opt == endptr) {
		bad_param();
		return;
	}

	opt = get_next_arg(opt);
	c = strtoul(opt, &endptr, 16);
	if (opt == endptr)
		c = '\0';

	memset(p, c, limit - p);
}
예제 #2
0
파일: main.c 프로젝트: lacombar/netbsd-alc
static void
command_write(char *opt)
{
	char		*endptr;
	u_int32_t	src;
	u_int32_t	dst;
	size_t		len;

	dst = strtoul(opt, &endptr, 16);
	if (opt == endptr)
		goto out;

	opt = get_next_arg(opt);
	src = strtoul(opt, &endptr, 16);
	if (opt == endptr)
		goto out;

	opt = get_next_arg(opt);
	len = strtoul(opt, &endptr, 16);
	if (opt == endptr)
		goto out;

	check_write_verify_flash(src, dst, len);
	return;

out:
	bad_param();
	return;
}
예제 #3
0
파일: main.c 프로젝트: lacombar/netbsd-alc
static void
opt_subcmd_bootp(char *opt)
{
	if (strcmp(opt, "yes") == 0) {
		bootopts.b_flags |= B_F_USE_BOOTP;
	} else if (strcmp(opt, "no") == 0) {
		bootopts.b_flags &= ~B_F_USE_BOOTP;
	} else {
		bad_param();
	}
}
    void TestMono1dSodiumBlockBySettingNamedParameter() throw(Exception)
    {
        CardiacSimulation simulation("heart/test/data/xml/monodomain1d_sodium_block.xml");
        TS_ASSERT( CompareFilesViaHdf5DataReader("heart/test/data/cardiac_simulations", "mono_1d_sodium_block", false,
                                                 "Mono1dSodiumBlock", "SimulationResults", true,
                                                 2.5e-3));

        // Test exception
        TS_ASSERT_THROWS_THIS(CardiacSimulation bad_param("heart/test/data/xml/bad_cell_parameter.xml"),
                              "No parameter named 'missing-parameter'.");
    }
예제 #5
0
파일: main.c 프로젝트: lacombar/netbsd-alc
static void
command_dump(char *opt)
{
	char		*endptr;
	const char	*p;
	const char	*line_fence;
	const char	*limit;

	p = (const char *) strtoul(opt, &endptr, 16);
	if (opt == endptr) {
		bad_param();
		return;
	}

	opt = get_next_arg(opt);
	limit = (const char *) strtoul(opt, &endptr, 16);
	if (opt == endptr) {
		limit = p + 256;
	}

	for (;;) {
		printhexul((u_int32_t) p);
		putchar(' ');
		line_fence = p + 16;
		while (p < line_fence) {
			printhexuc(*p++);
			putchar(' ');
			if (p >= limit) {
				putchar('\n');
				return;
			}
		}
		putchar('\n');
		if (ISKEY) {
			if (getchar() == '\x03')
				break;
		}
	}
}
예제 #6
0
shm_pair::shm_pair(shm_malloc& shm_mgr_, const string& com_key, int hash_size, int data_size, int data_len)
	: shm_mgr(shm_mgr_)
{
	GPT = gpt_ctx::instance();

	shp_data_t *shp_data;
	int i;

	if (hash_size % 2)
		hash_size++;

	if (data_size % 2)
		data_size++;

	data_len = common::round_up(data_len, static_cast<int>(sizeof(long)));

	size_t smsize = sizeof(shp_hdr) + sizeof(int) * hash_size + (offsetof(shp_data_t, data) + data_len) * data_size;

	shp_hdr = reinterpret_cast<shp_hdr_t *>(shm_mgr.find(com_key));
	if (shp_hdr == NULL) { // Not found, so we create one.
		if (hash_size == 0 || data_size == 0 || data_len == 0) {
			GPT->_GPT_error_code = GPEINVAL;
			throw bad_param(__FILE__, __LINE__, 0, (_("ERROR: hash_size, data_size or data_len is 0")).str(SGLOCALE));
		}

		shp_hdr = reinterpret_cast<shp_hdr_t *>(shm_mgr.malloc(smsize));
		if (shp_hdr == NULL)
			throw bad_system(__FILE__, __LINE__, bad_system::bad_other, 0, (_("ERROR: malloc() failed")).str(SGLOCALE));

		// It's locked by malloc automatically, so we can initialize it safely.
		shp_hdr->set_flags(SHM_KEY_INUSE);
		::strcpy(shp_hdr->key, com_key.c_str());
		shp_hdr->magic = SHP_MAGIC;
		shp_hdr->ref_count = 1;
		shp_hdr->total_size = smsize;
		shp_hdr->hash_size = hash_size;
		shp_hdr->data_size = data_size;
		shp_hdr->data_len = data_len;
		shp_hdr->free_link = 0;

		hash_table = reinterpret_cast<int *>(reinterpret_cast<char *>(shp_hdr) + sizeof(shp_hdr_t));
		shp_table = reinterpret_cast<char *>(hash_table + shp_hdr->hash_size);

		for (i = 0; i < hash_size; i++)
			hash_table[i] = -1;

		for (i = 0; i < data_size; i++) {
			shp_data = at(i);
			shp_data->flags = 0;
			shp_data->ref_count = 0;
			shp_data->prev = i - 1;
			shp_data->next = i + 1;
			shp_data->bucket = -1;
			shp_data->key_name[0] = '\0';
		}
		shp_data = at(data_size - 1);
		shp_data->next = -1;

		// Unlock it so others can use it.
		shp_hdr->lock.unlock();

		// Find again to see if someone has created another node with same key.
		shp_hdr_t *shp_hdr2 = reinterpret_cast<shp_hdr_t *>(shm_mgr.find(com_key));
		if (shp_hdr != shp_hdr2) { // Yes, someone created, so we free ourselves
			shm_mgr.free(shp_hdr);
			shp_hdr = shp_hdr2;
			// Wait for someone to finish initialization.
			shp_hdr->lock.lock();
			shp_hdr->ref_count++;
			shp_hdr->lock.unlock();
			hash_table = reinterpret_cast<int *>(reinterpret_cast<char *>(shp_hdr) + sizeof(shp_hdr_t));
			shp_table = reinterpret_cast<char *>(hash_table + shp_hdr->hash_size);
		}
	} else {
		hash_table = reinterpret_cast<int *>(reinterpret_cast<char *>(shp_hdr) + sizeof(shp_hdr_t));
		shp_table = reinterpret_cast<char *>(hash_table + shp_hdr->hash_size);
	}

	if ((shp_hdr->magic != SHP_MAGIC) || (hash_size != 0 && data_size != 0 && data_len != 0
		&& (shp_hdr->total_size != smsize || shp_hdr->hash_size != hash_size
		 || shp_hdr->data_size != data_size || shp_hdr->data_len != data_len))) {
		GPT->_GPT_error_code = GPESYSTEM;
		throw bad_msg(__FILE__, __LINE__, 0, (_("ERROR: shared memory insane")).str(SGLOCALE));
	}
}
예제 #7
0
void read_parameter_file(char * filename, int file_specified) {
    FILE * param_stream;
    char line[100];
    char part[14][100];
    int i, c;
    float value;
    
    param_stream = fopen(filename, "r");
    if (param_stream == NULL) {
	if (file_specified) {
	    printf("Warning: cannot open \"%s\".  Using defaults.\n", filename);
	} else {
	    /*      printf("Cannot open \"%s\".  Using defaults.\n", filename);       */
	}
	return;
    }
    /* printf("%%Reading parameters from file \"%s\".\n", filename); */
    while(fgets(line, sizeof(line), param_stream) != NULL) {
	for (i=0; isspace(line[i]); i++);
	if (line[i] == '%' || line[i] == '\0') continue;  /* ignore comment and blank lines */
	for (i=0; line[i] != '\0'; i++) if (line[i] == '=') line[i] = ' '; /* kill all '=' signs */
	if (sscanf(line, "%99s %99s %99s", part[0], part[1], part[2]) != 2) {
	  /* The line has more than two parts; it either has to be the compat parameter or its bad */
	  if(strcmp(part[0], "compat_values") == 0) {
	    if (sscanf(line, "%99s %99f %99f %99f %99f %99f %99f %99f %99f %99f %99f %99f %99f %99s ", part[0], 
		   &compat_value[0], &compat_value[1], &compat_value[2], &compat_value[3], &compat_value[4], &compat_value[5], &compat_value[6], &compat_value[7], &compat_value[8], &compat_value[9], &compat_value[10], &compat_value[11], part[13]) != 13) {
	      bad_param(line);
	      continue;
	    }
	    if(verbosity>0) {
	      printf("%compatibility values: ");
	      for(c=0; c<12; c++) printf("%6.3f ", compat_value[c]);
	      printf("\n");
	    }
	  }
	  else {
	    bad_param(line);
	  }
	  continue;
	}

	/* If we get this far, we know it's an ordinary parameter with one value */	  
	if (sscanf(part[1], "%f", &value) != 1) {
	    bad_param(line);
	    continue;
	} 
	if (strcmp(part[0], "verbosity") == 0) {
	    verbosity = value;
	    value = verbosity;  /* show the truncated value */
	} else if (strcmp(part[0], "tpc_var_factor") == 0) {
	    tpc_var_factor = value;
	} else if (strcmp(part[0], "buckets_per_unit_of_cog") == 0) {
	    buckets_per_unit_of_cog = value;
	} else if (strcmp(part[0], "half_life") == 0) {
	    half_life = value;
	} else if (strcmp(part[0], "pruning_cutoff") == 0) {
	    pruning_cutoff = value;
	} else if (strcmp(part[0], "print_tpc_notes") == 0) {
	    print_tpc_notes = value;
	} else if (strcmp(part[0], "print_chords") == 0) {
	    print_chords = value;
	} else if (strcmp(part[0], "print_beats") == 0) {
	    print_beats = value;
	} else if (strcmp(part[0], "round_to_beat") == 0) {
	    round_to_beat = value;
	} else if (strcmp(part[0], "har_var_factor") == 0) {
	    har_var_factor = value;
	} else if (strcmp(part[0], "odp_linear_factor") == 0) {
	    odp_linear_factor = value;
	} else if (strcmp(part[0], "odp_quadratic_factor") == 0) {
	    odp_quadratic_factor = value;
	} else if (strcmp(part[0], "odp_constant") == 0) {
	    odp_constant = value;
	} else if (strcmp(part[0], "sbp_weight") == 0) {
	    sbp_weight = value;
	} else if (strcmp(part[0], "sbp_constant") == 0) {
	    sbp_constant = value;
	} else if (strcmp(part[0], "compat_factor") == 0) {
	    compat_factor = value;
	} else if (strcmp(part[0], "voice_leading_time") == 0) {
	    voice_leading_time = value;
	} else if (strcmp(part[0], "voice_leading_penalty") == 0) {
	    voice_leading_penalty = value;
	} else if (strcmp(part[0], "prechord_mode") == 0) {
	    prechord_mode = value;
	} else {
	    bad_param(line);
	    continue;
	}
	if (verbosity > 0) {
	    printf("%%%s = %3.2f\n", part[0], value);
	}
    }
    fclose(param_stream);
}