Beispiel #1
0
bool ini_addSection(Ini* ini, const char* sectionName) {
	if (ini == NULL) {
		logWarn("Invalid ini object");
		return false;
	}

	if (sectionName == NULL) {
		logWarn("Section name is NULL");
		return false;
	}

	if (ini_get(ini, sectionName) != NULL) {
		logWarn("Section '%s' already exist", sectionName);
		return false;
	}

	Section* section = memory_new(Section, true);
	str_ncpy(section->name, sectionName, sizeof(section->name));
	section->keys = list_new(true);
	section->values = list_new(true);

	list_add(ini->sections, (Any)section);

	return true;
}
Beispiel #2
0
void adplib_init(toptions *opts, tsequence *seq, char **z, int *n){
  *z = (char *) seq->seq - 1;
  if (opts->window_mode) {
    *n = min(opts->window_size, seq->length);
  }
  else {
    *n = seq->length;
    opts->window_size = seq->length;
  }
  opts->window_size = min(opts->window_size, seq->length);
  adp_dynmem  = memory_new();  
  adp_statmem = memory_new();  
  libPP_init(seq);

  setOutputMode(1);
  init_iupac_base();
  fs_init_leading_space(1,1,1,1,1,1);
}
Beispiel #3
0
static n_object * object_new(void)
{
    n_object * return_object = (n_object *)memory_new(sizeof(n_object));
    if (return_object)
    {
        object_erase(return_object);
    }
    return return_object;
}
Beispiel #4
0
void shares_init(Configuration* conf) {
	shareList = memory_new(ShareList, true);
	shareList->needReload = true;
	shareList->list = list_new(false);
	shareList->shareFile = str_dup(conf->shareFile);
	shareList->shareDirectory = str_dup(conf->source_path);
	shareList->shareGrace = conf->shareGrace;

	pthread_mutex_init(&shareMutex, NULL);
}
Beispiel #5
0
static void * ar_pass_through(void * ptr)
{
    if (ptr == 0L)
    {
        ptr = memory_new(sizeof(n_array));
        if (ptr)
        {
            memory_erase((n_byte *)ptr, sizeof(n_array));
        }
    }
    return ptr;
}
Beispiel #6
0
static void
update_processor (AppData *data)
{
  if (data->mem)
    memory_free (data->mem);
  if (data->regs)
    registers_free (data->regs);
  if (data->symtable)
    symbol_table_free (data->symtable);

  /* Create empty symbol table (to be populated during parse) */
  data->symtable = symbol_table_new ();

  /* Create registers */
  data->regs = registers_new (g_key_file_get_integer (data->settings,
						      "processor",
						      "no_registers",
						      NULL));
  /* Create designated memory segments */
  data->mem = memory_new ();
  memory_add_data_segment (data->mem, MEM_SEG_DATA,
			   g_key_file_get_integer (data->settings,
						   "data segment",
						   "origin",
						   NULL),
			   g_key_file_get_integer (data->settings,
						   "data segment",
						   "size",
						   NULL));
  memory_add_data_segment (data->mem, MEM_SEG_CODE,
			   g_key_file_get_integer (data->settings,
						   "code segment",
						   "origin",
						   NULL),
			   g_key_file_get_integer (data->settings,
						   "code segment",
						   "size",
						   NULL));
  update_symtable (data);
  update_mcode (data);
  update_data (data);
  update_regs (data);
}
Beispiel #7
0
void shares_parse(char* line) {
	List* l;
	Share* s;
	char* strSpaceUsed = NULL;
	char* strQuota = NULL;

	if (line == NULL)
		return;

	str_trim(line);

	if (str_len(line) == 0 || line[0] == ';' || line[0] == '#')
		return;

	l = str_split(line, ',');

	if (l->size != 2) {
		logWarn("Share entry '%s' is not well formated", line);
		return;
	}

	s = memory_new(Share, true);

	s->name = str_dup((char*)list_get(l, 0));
	s->quota = str_toSize((char*)list_get(l, 1));
	s->path = fs_join(shareList->shareDirectory, s->name);
	s->spaceUsed = fs_getSpace(s->path);

	strSpaceUsed = str_fromSize(s->spaceUsed);
	strQuota = str_fromSize(s->quota);

	logDebug("new share %s: %s/%s", s->name, strSpaceUsed, strQuota);
	memory_free(strSpaceUsed);
	memory_free(strQuota);


	list_add(shareList->list, (Any)s);
}
Beispiel #8
0
n_int	tranfer_in(n_file * input_file)
{
    n_int  ret_val;
    n_byte *temp_store = 0L;
    n_uint ape_count = 0;
    n_uint social_count = 0;
    n_uint episodic_count = 0;

    noble_simulation * local_sim = sim_sim();
    n_uint  size_buffer = io_find_size_data((noble_file_entry *)noble_file_format);

    temp_store = (n_byte *)memory_new(size_buffer);

    if (temp_store == 0L)
    {
        return SHOW_ERROR("No temporary storage memory available");
    }

    io_whitespace(input_file);

    input_file->location = 0;

    ret_val = io_read_buff(input_file, temp_store, noble_file_format);

    if(ret_val != FIL_VER) /* signature must be first */
        return SHOW_ERROR("Signature not first in file");

    {
        n_byte2	*signature = (n_byte2 *)temp_store;

        if(signature[0] != NOBLE_APE_SIGNATURE) /* not a Noble Ape file */
            return SHOW_ERROR("Not a Noble Ape File");

        if(signature[1] > VERSION_NUMBER) /* file version greater than this version */
            return SHOW_ERROR("File newer than Simulation");
    }

    do
    {
        n_byte *temp = 0L;
        ret_val = io_read_buff(input_file, temp_store, noble_file_format);
        if (ret_val == -1)
            SHOW_ERROR("Failure in file load");
        if (ret_val < FILE_EOF)
        {
            n_uint	loop_end = 0;
            switch (ret_val)
            {
            case FIL_LAN:
                temp = (n_byte*)land_ptr();
                loop_end = 11; /* Needs to be fixed */
                break;
            case FIL_BEI:
                temp = (n_byte*) &(local_sim->beings[ape_count]);
                loop_end = sizeof(noble_being);
                break;
            case FIL_SOE:
            {
                noble_social * local_social = being_social(&(local_sim->beings[ape_count]));
                temp = (n_byte*)(&local_social[social_count]);
                loop_end = sizeof(noble_social);
            }
            break;
            case FIL_EPI:
            {
                noble_episodic * local_episodic = being_episodic(&(local_sim->beings[ape_count]));
                temp = (n_byte*)(&local_episodic[episodic_count]);
                loop_end = sizeof(noble_episodic);
            }
            break;
            default:
            {
                return SHOW_ERROR("Unknown file kind"); /*unknown kind*/
            }
            break;
            }
            if(temp != 0L)
            {
                memory_copy(temp_store, temp, loop_end);
            }
            if (ret_val == FIL_BEI)
            {
                ape_count ++;
                if (ape_count == local_sim->max)
                {
                    local_sim->num = ape_count;
                    return SHOW_ERROR("Too many apes for memory");
                }
            }
            if (ret_val == FIL_SOE)
            {
                social_count ++;
                if (social_count == (local_sim->max * SOCIAL_SIZE))
                {
                    local_sim->num = ape_count;
                    return SHOW_ERROR("Too many social graph events for memory");
                }
            }
            if (ret_val == FIL_EPI)
            {
                episodic_count ++;
                if (episodic_count == (local_sim->max * EPISODIC_SIZE))
                {
                    local_sim->num = ape_count;
                    return SHOW_ERROR("Too many episodic events for memory");
                }
            }

        }

    }
    while (ret_val < FILE_EOF);

    if (ret_val == FILE_EOF)
    {
        local_sim->num = ape_count;
        return 0;
    }
    return SHOW_ERROR("Process file failed");
}
Beispiel #9
0
void memory_new_detail( void** p, int size, char* file, char* function, int line, char* name )
{
	char temp[128];
	sprintf( temp, "[%s]%s(%d) %s", file, function, line, name );
	memory_new( p, size, temp );
}