Exemple #1
0
int parse_line(Variable_List * vars, char * line)
{
    int i, j;
    int len;
    int token_len;
    char temp[13];
    
    if((len = check_errors(line)) == ERROR)
    {
	printf("ERROR: Syntax error\n");
        return 0;
    }

    i = 0;
    while(i < len)
    {
	// variable
	if(line[i] == '$')
	{
            i++;
	    for (j = 0; j < length_token(i,line); j++)
                temp[j] = line[i+j];
	    temp[j] = '\0';
	    i+=j;

	    if(find_next(i,'=',line) > 0)
		new_var(vars, temp, INTEGER, 0);
	}
        // statement / function call
	if((line[i] >= 'a' && line[i] <= 'z') ||
	   (line[i] >= 'A' && line[i] <= 'Z') ||
	   line[i] == '_')
	{
	    token_len = length_token(i, line);
	    for (j = 0; j < token_len; j++)
                temp[j] = line[i+j];
	    temp[j] = '\0';
	    i+=j;

	    if (strcmp("list", temp) == 0)
		list_vars(vars);

	    if (strcmp("help", temp) == 0)
		help();

	    if (strcmp("exit", temp) == 0 || strcmp(temp,"quit") == 0)
		return -1;
	
	}
        i++;
    }
    return 0;
}
BinaryTreeNode *BTIterator::find_parent(BinaryTreeNode *root, char *target)
{
	BinaryTreeNode *current = find_next(root, target);
	if(current == NULL)
	{
		return NULL;
	}
	else
	{
		current = root;
        while(!examin_children(current, target))
        {
			current = find_next(current, target);
			if(current == NULL)
			{
				return NULL;
			}
        }
		return current;
    }

}
Exemple #3
0
CubitSense PartitionShell::find_sense( const PartitionSurface* surf ) const
{
  PartitionCoSurf* cos = find_first( surf );
  if( ! cos )
    return CUBIT_UNKNOWN;
  
  CubitSense result = cos->sense();
  while( (cos = find_next( cos )) )
    if( cos->sense() != result )
      return CUBIT_UNKNOWN;
  
  return result;
}
Exemple #4
0
unsigned char __code *
get_interface_desc(unsigned char val, unsigned char num, unsigned char alt)
{
	unsigned char __code *p;
	pDesc = &descs[0];
	get_config_desc(val, 0);
	while (p = find_next(DESC_TYPE_INTERFACE, DESC_TYPE_CONFIG)) {
		if (num == ((struct interface_desc __code *)p)->bInterfaceNumber && 
		    alt == ((struct interface_desc __code *)p)->bAlternateSetting) 
			return p;
	}
	return 0;
}
Exemple #5
0
const char * find_next()
{
    entry = readdir(dp);
    if (entry == NULL)
        return NULL;
    else {
        const char * name = make_find_res(entry->d_name);
        if ( wildcmp(find_pattern, name) ) {
            return name;
        } else
            return find_next();
    }
};
/*
 * Make sure the format string is well formed, and parse out
 * the used atoms.
 */
static int verify_format(const char *format)
{
	const char *cp, *sp;
	for (cp = format; *cp && (sp = find_next(cp)); ) {
		const char *ep = strchr(sp, ')');
		if (!ep)
			return error("malformed format string %s", sp);
		/* sp points at "%(" and ep points at the closing ")" */
		parse_atom(sp + 2, ep);
		cp = ep + 1;
	}
	return 0;
}
Exemple #7
0
boolvec * area_read(const char * filename, const char * areaname,
                    int col1, int col2,
                    const char* delimiter, int skip_lines, int grow_by)
{

    boolvec * res = create_boolvec();
    const char * fname = find_first(filename);

    while (fname != NULL) {

        d_area * area = _area_read(fname, areaname,
                                   col1, col2, skip_lines,
                                   grow_by, delimiter);

        if (area != NULL)
            surfit_areas->push_back(area);
        else {
            writelog(LOG_WARNING,"failed to read area from file %s", fname);
            res->push_back(false);
            fname = find_next();
            continue;
        }

        if (areaname == NULL)
        {
            char * name = get_name(fname);
            area->setName( name );
            sstuff_free_char(name);
        }

        res->push_back(true);
        fname = find_next();

    }

    find_close();
    return res;

};
Exemple #8
0
/**
 * Find number of entries for specific filename
 * 
 * \param match Filename to count
 * \return Number of matching directory entries
 * 
 */
int num_direntries(char *match)
{
    int res, max = 0;
    fatffdata_t ff; /** \todo ! no good with this static alloc, dynamic is also crap, see if other solution can be used. */

    res = find_first(match,&ff);
    while (res != -1)
    {
        res = find_next(&ff);
        max++;
    }
    return max; 
}
Exemple #9
0
DrawTextResult
text_draw(i32 x, i32 y, char *text, u8 cf, u8 cb)
{
    ASSERT(PROGRAM->font);

    V4i r = v4i_make_size(x, y, PROGRAM->font->cw, PROGRAM->font->ch);

    if ((x + PROGRAM->tx) < PROGRAM->bitmap_rect.max_x &&
        (y + PROGRAM->ty) < PROGRAM->bitmap_rect.max_y)
    {
        // rect_tr(&r, PROGRAM->tx, PROGRAM->ty);

        V4i rect;
        ImageSet *font = PROGRAM->font;
        char *anchor = text;
        for (;;)
        {
            text = find_next(anchor, '\n');

            if (cb) {
                rect.min_x = x - font->padding.min_x;
                rect.min_y = y - font->padding.min_y;
                rect.max_x = x + (text - anchor) * font->cw + font->padding.max_x;
                rect.max_y = y + font->ch + font->padding.max_y;
                rect_draw(rect, cb);
            }
            i32 xp = x;
            while (anchor != text) {
                if (*anchor != ' ') {
                    image_set_draw(xp,
                                y,
                                PROGRAM->font,
                                *anchor,
                                DrawSpriteMode_Mask,
                                cf);
                }
                anchor++;
                xp += PROGRAM->font->cw;
            }
            if (*text == 0) {
                break;
            }
            text++;
            anchor = text;
            rect_tr(&r, 0, PROGRAM->font->ch);
        }
    }

    DrawTextResult res = { r.max_x, r.min_y };
    return res;
}
Exemple #10
0
unsigned char __xdata *
get_string_desc(unsigned char ind)
{
	unsigned char __code *p;
	pDesc = &descs[0];
	for (;;) {
		p = find_next(DESC_TYPE_STRING, 0);
		if (!p)
			return 0;
		if (ind == 0)
			return copy_to_xdata(p, p[0]);
		ind--;
	}
}
Exemple #11
0
void match(){
    node* now = root;
    int matched = 0, last_part = 0;
    //try to match the pattern[i]
    //the now is the matched node of pattern[i - 1]
    //last_part is the remain part along the now node
    //matched is the current total matched length
    //if match is not possible, then now = root, last_part = 0;
    for(int i = 0; i < pattern_len; ++i){
        find_next(&now, matched, last_part, i);
        //printf("now matched last_part, %d %d %d\n", now->leaf_index, matched, last_part);
        ans = std::max(ans, matched);
    }
}
Exemple #12
0
//free the chunk in the middle of three busy chunks
void free_without_merging() {
	three_malloc();
    Busy_Header *b_1 = get_heap_base();
    Busy_Header *b_2 = find_next(b_1);
    Busy_Header *b_3 = find_next(b_2);

	Free_Header *freelist0 = get_freelist(); //get the head of freelist, which is at the end of allocated chunks
	assert_addr_equal(freelist0, find_next(b_3));
	free(b_2);   //free the chunk in the middle, which becomes the head of the new freelist
	Free_Header *freelist1 = get_freelist();  //get the new freelist

	assert_addr_not_equal(freelist1, b_1);
	assert_addr_not_equal(freelist0, freelist1);
    assert_addr_equal(freelist1, b_2);
    assert_addr_equal(freelist1->next, freelist0); //two free chunks in the list
    assert_equal(chunksize(b_1) + chunksize(b_2) + chunksize(b_3) + chunksize(freelist0), HEAP_SIZE);
    assert_equal(chunksize(b_1) + chunksize(b_3) + chunksize(freelist1) + chunksize(freelist0), HEAP_SIZE);

	Heap_Info info = verify_heap();
	assert_equal(info.busy, 2);
	assert_equal(info.busy_size, chunksize(b_1) + chunksize(b_3));
	assert_equal(info.free, 2); // 2 free chunks not next to each other
	assert_equal(info.free_size, chunksize(freelist1) + chunksize(freelist1->next));
}
Exemple #13
0
boolvec * area_load_bln(const char * filename, const char * areaname) 
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {
		d_area * area = _area_load_bln(fname, areaname);
		if (area)
			surfit_areas->push_back(area);
		res->push_back( area != NULL );
		fname = find_next();	
	}
	find_close();
	return res;
};
Exemple #14
0
void
cmdfindnext_clicked (GtkWidget *widget)
{
    const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry_text));
    GtkTextSearchFlags flags = GTK_TEXT_SEARCH_TEXT_ONLY;
    
    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chkCase)))
        flags = flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE;

    if (!find_next (text_view, text, flags))
    {
        //Status Bar show cannot find text
    }
    search_text = g_strdup (text);
}
Exemple #15
0
static int
find_text(int index)
{
 int i = 0, value = index, max_y = 0, max_x = 0, c = 0, y = 0, x = 0;
 unsigned long keymask = (F3_BIT|F10_BIT);
 char buf[256];

 (void)memset(buf, '\0', 256);

 getmaxyx(stdscr, max_y, max_x);
 if ( (max_y < MIN_Y) || (max_x < MIN_X) ) {
     return (-1);
 }
 move(max_y-10, 0); clrtobot();
 mvaddch(max_y-10, 0, '+');
 mvaddch(max_y-10, max_x-1, '+');
 mvaddch(max_y-1, 0, '+');
 mvaddch(max_y-1, max_x-1, '+');
 for ( x = 1; x < max_x-1; x++ ) {
     mvaddch(max_y-10, x, '-'); mvaddch(max_y-1, x, '-');
 }
 for ( y = max_y-9; y < max_y-1; y++ ) {
     mvaddch(y, 0, '|'); mvaddch(y, max_x-1, '|');
 }
 mvaddstr(max_y-9, (max_x/2)-2, "Find");
 refresh();

 c = io_text(max_y-7, 4, buf, 256, keymask);

 if ( KEY_F(3) == c ) {
     value = FIND_CANCEL;
 } else if ( KEY_F(10) == c ) {
     value = FIND_EXIT;
 } else if ( KEY_ENTER == c ) {
     if ( '\0' != buf[0] ) {
         if ( NULL != (srch_txt = strdup(buf)) ) {
             value = find_next(index);
         } else {
             value = FIND_CANCEL;
         }
     } else {
         value = FIND_CANCEL;
     }
 } else {
     value = FIND_CANCEL;
 }
 move(max_y-10, 0); clrtobot(); return (value);
}
Exemple #16
0
int		last_yank_key(t_sh *shell, t_term *term, long key)
{
	char	*comp;

	if ((key == KEY_CTRL_MAJ_Y || key == KEY_CTRL_Y) && shell->yank)
		insert_yank(shell, term);
	else if (key == KEY_TAB)
	{
		comp = get_prev_chars(term);
		find_next(shell, term, comp);
		ft_strdel(&comp);
	}
	else
		return (0);
	return (1);
}
Exemple #17
0
unsigned char __xdata *
get_config_desc(unsigned char val, unsigned char ind)
{
	unsigned char __code *p;
	pDesc = &descs[0];
	while (p =  find_next(DESC_TYPE_CONFIG, 0)) {
		if (val) {
			if (val == ((struct configuration_desc __code *)p)->bConfigurationValue) 
				return copy_to_xdata(p, p[2]);
		} else {
			if (!ind)
				return copy_to_xdata(p, p[2]);
			ind--;
		}
	}
	return 0;
}
Exemple #18
0
void cmex_object_list(int nlhs, mxArray *plhs[], /**< entlist */
					  int nrhs, const mxArray *prhs[] ) /**< () */
{
	OBJECT *obj;
	char criteria[1024]="(undefined)";
	FINDPGM *search = NULL;
	char *fields[] = {"name","class","parent","flags","location","service","rank","clock","handle"};
	FINDLIST *list = NULL;
	if (nrhs>0 && mxGetString(prhs[0],criteria,sizeof(criteria))!=0)
		output_error("gl('list',type='object'): unable to read search criteria (arg 2)");
	else if (nrhs>0 && (search=find_mkpgm(criteria))==NULL)
		output_error("gl('list',type='object'): unable to run search '%s'",criteria);
	else if (search==NULL && (list=find_objects(NULL,NULL))==NULL)
		output_error("gl('list',type='object'): unable to obtain default list");
	else if (list==NULL && (list=find_runpgm(NULL,search))==NULL)
		output_error("gl('list',type='object'): unable search failed");
	else if ((plhs[0] = mxCreateStructMatrix(list->hit_count,1,sizeof(fields)/sizeof(fields[0]),fields))==NULL)
		output_error("gl('list',type='object'): unable to allocate memory for result list");
	else
	{
		unsigned int n;
		for (n=0, obj=find_first(list); obj!=NULL; n++, obj=find_next(list,obj))
		{
			char tmp[1024];
			mxArray *data;
			double *pDouble;
			unsigned int *pInt;
			mxSetFieldByNumber(plhs[0], n, 0, mxCreateString(object_name(obj)));
			mxSetFieldByNumber(plhs[0], n, 1, mxCreateString(obj->oclass->name));
			mxSetFieldByNumber(plhs[0], n, 2, mxCreateString(obj->parent?object_name(obj->parent):NONE));
			mxSetFieldByNumber(plhs[0], n, 3, mxCreateString(convert_from_set(tmp,sizeof(tmp),&(obj->flags),object_flag_property())?tmp:ERROR));
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,2,mxREAL)); pDouble[0] = obj->longitude; pDouble[1] = obj->latitude;
			mxSetFieldByNumber(plhs[0], n, 4, data);
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,2,mxREAL)); pDouble[0] = (double)obj->in_svc/TS_SECOND; pDouble[1] = (double)obj->out_svc/TS_SECOND;
			mxSetFieldByNumber(plhs[0], n, 5, data);
			pInt = (unsigned int*)mxGetPr(data=mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL)); pInt[0] = obj->rank;
			mxSetFieldByNumber(plhs[0], n, 6, data);
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,1,mxREAL)); pDouble[0] = (double)obj->clock/TS_SECOND; 
			mxSetFieldByNumber(plhs[0], n, 7, data);
			mxSetFieldByNumber(plhs[0], n, 8, make_handle(MH_OBJECT,obj));
		}
	}
}
Exemple #19
0
boolvec * cntr_load(const char * filename, const char * cntrname) 
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {
		d_cntr * contour = _cntr_load(fname, cntrname);
		if (contour) {
			surfit_cntrs->push_back(contour);
			res->push_back(true);
		} else
			res->push_back(false);

		fname = find_next();
	}

	find_close();
	return res;
};
Exemple #20
0
static
struct rpc_xprt *xprt_switch_set_next_cursor(struct list_head *head,
		struct rpc_xprt **cursor,
		xprt_switch_find_xprt_t find_next)
{
	struct rpc_xprt *cur, *pos, *old;

	cur = READ_ONCE(*cursor);
	for (;;) {
		old = cur;
		pos = find_next(head, old);
		if (pos == NULL)
			break;
		cur = cmpxchg_relaxed(cursor, old, pos);
		if (cur == old)
			break;
	}
	return pos;
}
Exemple #21
0
void create_random_gate( gate& g, unsigned lines, bool negative, std::default_random_engine& generator )
{
  std::uniform_int_distribution<unsigned> dist( 0u, lines - 1u );
  std::uniform_int_distribution<unsigned> bdist( 0u, 1u );

  auto controls = random_bitset( lines, generator );
  auto target   = dist( generator );

  g.set_type( toffoli_tag() );
  g.add_target( target );
  auto pos = controls.find_first();
  while ( pos != controls.npos )
  {
    if ( pos != target )
    {
      g.add_control( make_var( pos, negative ? ( bdist( generator ) == 1u ) : true ) );
    }
    pos = controls.find_next( pos );
  }
}
Exemple #22
0
static void
config_endpoints(struct interface_desc __code *pi)
{
	unsigned char n;

	for (n = 0; n < pi->bNumEndpoints; n++) {
		struct endpoint_desc __code *pe;
		if (pe = (struct endpoint_desc __code *)find_next(DESC_TYPE_ENDPOINT, 0)) {
			unsigned char endpoint;
			unsigned int maxpRegValue;
			unsigned char csRegValue;

			endpoint = pe->bEndpointAddress & 0x0F;
			USBINDEX = endpoint;
			csRegValue = 0x00;
			maxpRegValue = (pe->wMaxPacketSize + 7) >> 3;

			if (pe->bEndpointAddress&0x80) {	// in
				USBCSIL = USBCSIL_CLR_DATA_TOG | USBCSIL_FLUSH_PACKET;
				USBCSIL = USBCSIL_FLUSH_PACKET;
				if ((pe->bmAttributes&EP_ATTR_TYPE_BM) == EP_ATTR_ISO)
					csRegValue |= USBCSIH_ISO;  // ISO flag
				if (endpoint >= 4)
					csRegValue |= USBCSIH_IN_DBL_BUF;          // Double buffering
				USBCSIH = csRegValue;
				USBMAXI = maxpRegValue;
				pEpInStatus[endpoint - 1] = EP_IDLE;
			} else {
				USBCSOL = USBCSOL_CLR_DATA_TOG | USBCSOL_FLUSH_PACKET;
				USBCSOL = USBCSOL_FLUSH_PACKET;
				if ((pe->bmAttributes&EP_ATTR_TYPE_BM) == EP_ATTR_ISO)
					csRegValue |= USBCSOH_ISO;  // ISO flag
				if (endpoint >= 4)
					csRegValue |= USBCSOH_OUT_DBL_BUF;        // Double buffering
				USBCSOH = csRegValue;
				USBMAXO = maxpRegValue;
				pEpOutStatus[endpoint - 1] = EP_IDLE;
			}
			USBINDEX = 0;
		}
	}
Exemple #23
0
/*
 * Make sure the format string is well formed, and parse out
 * the used atoms.
 */
static int verify_format(const char *format)
{
	const char *cp, *sp;
	static const char color_reset[] = "color:reset";

	need_color_reset_at_eol = 0;
	for (cp = format; *cp && (sp = find_next(cp)); ) {
		const char *ep = strchr(sp, ')');
		int at;

		if (!ep)
			return error("malformed format string %s", sp);
		/* sp points at "%(" and ep points at the closing ")" */
		at = parse_atom(sp + 2, ep);
		cp = ep + 1;

		if (starts_with(used_atom[at], "color:"))
			need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
	}
	return 0;
}
Exemple #24
0
int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *next) {
        struct tm tm;
        time_t t;
        int r;

        assert(spec);
        assert(next);

        t = (time_t) (usec / USEC_PER_SEC) + 1;
        assert_se(localtime_or_gmtime_r(&t, &tm, spec->utc));

        r = find_next(spec, &tm);
        if (r < 0)
                return r;

        t = mktime_or_timegm(&tm, spec->utc);
        if (t == (time_t) -1)
                return -EINVAL;

        *next = (usec_t) t * USEC_PER_SEC;
        return 0;
}
Exemple #25
0
/**
 * Map from index to fatfind structure.
 * Return the fatfind struct for the file with the given index in the current directory.
 * 
 * \param match     The filename mask to apply in the search
 * \param fileindex Index of file to find
 * \return FatFind helper structure
 */
fatffdata_t * index_to_ff(char *match, int fileindex)
{
    int res;
    fatffdata_t *ff = (fatffdata_t*) malloc(sizeof(fatffdata_t));
    if (ff)
    {
        res = find_first(match,ff);
        while (res != -1)
        {
            if (fileindex == 0)
                break;
            fileindex--;
            res = find_next(ff);
        }
        if (res == -1)
        {
            free(ff);
            return NULL;
        }
    }
    return ff;
}
Exemple #26
0
	void solve()
	{
		value[++total] = -99999999;
		count[total] = 1;
		root = total;

		int N;
		std::scanf("%d", &N);
		for(int i = 0; i != N; ++i)
		{
			int opt, x;
			std::scanf("%d %d", &opt, &x);
			switch(opt)
			{
			case 1:
				insert(x);
				break;
			case 2:
				remove(x);
				break;
			case 3:
				std::printf("%d\n", find_rank(x) - 1);
				break;
			case 4:
				std::printf("%d\n", find_kth(x + 1));
				break;
			case 5:
				opt = find_prev(x);
				splay(opt);
				std::printf("%d\n", value[opt]);
				break;
			case 6:
				opt = find_next(x);
				splay(opt);
				std::printf("%d\n", value[opt]);
				break;
			}
		}
	}
Exemple #27
0
//skip first free chunk, which is not big enough
void search_along_list() {
    printf("after allocation:\n");
    Busy_Header* b[4];
    for(int i = 0; i < 4; i++){
        b[i] = malloc(450);
        printf("b[%d]: %p\n", i, b[i]);
    }
    assert_equal(b[0]->size & SIZEMASK, request2size(450));
    assert_equal(b[1]->size & SIZEMASK, request2size(450));
    assert_equal(b[2]->size & SIZEMASK, request2size(450));
    assert_equal(b[3]->size & SIZEMASK, request2size(450));
    Free_Header* f4 = find_next(b[3]);
    printf("head: %p\n", f4);

    Heap_Info info = verify_heap();
    assert_equal(info.busy, 4);
    assert_equal(info.free, 1);
    assert_equal(info.busy_size, 1824);
    assert_equal(info.free_size, 176);
    assert_addr_equal(get_freelist(), f4);
    assert_addr_equal(get_freelist()->next, NULL);
    assert_addr_equal(get_freelist()->prev, NULL);

    //after malloc, free b3, b0
    free(b[3]);
    free(b[0]);
    Busy_Header *skip = malloc(600);

    printf("after malloc(600)\n");
    Free_Header *head = get_freelist();
    print_both_ways(head);

    info = verify_heap();
    assert_equal(info.busy, 3);
    assert_equal(info.free, 2);
    assert_equal(info.busy_size + info.free_size, get_heap_info().heap_size);
}
Exemple #28
0
const char * find_first(const char * pattern)
{
    file_handle = _findfirst(pattern, &ff);
    if (file_handle == -1) {
        writelog(LOG_ERROR,"%s",strerror(errno));
        return NULL;
    }
    find_pattern = strdup(pattern);

    int path_pos1 = 0;
    if ( strrchr(find_pattern+path_pos1, '/') != NULL )
        path_pos1 = strrchr(find_pattern+path_pos1, '/') - find_pattern + 1;

    int path_pos2 = 0;
    if ( strrchr(find_pattern+path_pos2, '\\') != NULL )
        path_pos2 = strrchr(find_pattern+path_pos2, '\\') - find_pattern + 1;

    path_pos = MAX(path_pos1, path_pos2);
    strncpy(find_res, find_pattern, path_pos);

    if (ff.attrib &= _A_SUBDIR)
        return find_next();
    return make_find_res(ff.name);
};
STATUS original_test_end(int argc, char *argv[])
{
	FINDLIST *find = find_objects(FL_GROUP,"class=node;");
	OBJECT *obj;
	AGGREGATION *aggr;
	char *exp = "class=node";
	char *agg = "max(V.ang)";

	for (obj=find_first(find); obj!=NULL; obj=find_next(find,obj))
		output_message("object %s found", object_name(obj));
	free(find);

	output_message("Aggregation of %s over %s...", agg,exp);
	aggr = aggregate_mkgroup(agg,exp);
	if (aggr)
		output_message("Result is %lf", aggregate_value(aggr));
	else
		output_message("Aggregation failed!");

	if (!saveall("-"))
		perror("save failed");

	return SUCCESS;
}
Exemple #30
0
/** This function performs an aggregate calculation given by the aggregation 
 **/
double aggregate_value(AGGREGATION *aggr) /**< the aggregation to perform */
{
	OBJECT *obj;
	double numerator=0, denominator=0, secondary=0, third=0, fourth=0;
	double scale = (aggr->punit ? aggr->scale : 1.0);

	/* non-constant groups need search program rerun */
	if ((aggr->group->constflags & CF_CONSTANT) != CF_CONSTANT){
		aggr->last = find_runpgm(NULL,aggr->group); /** @todo use constant part instead of NULL (ticket #3) */
	}

	for(obj = find_first(aggr->last); obj != NULL; obj = find_next(aggr->last, obj)){
		double value=0;
		double *pdouble = NULL;
		complex *pcomplex = NULL;

		/* add time-sensitivity to verify that we are only aggregating objects that are in-service and not out-service. */
		if(obj->in_svc >= global_clock || obj->out_svc <= global_clock)
			continue;

		switch (aggr->pinfo->ptype) {
		case PT_complex:
		case PT_enduse:
			pcomplex = object_get_complex(obj,aggr->pinfo);
			if (pcomplex!=NULL)
			{
				switch (aggr->part) {
				case AP_REAL: value=pcomplex->r; break;
				case AP_IMAG: value=pcomplex->i; break;
				case AP_MAG: value=mag(pcomplex); break;
				case AP_ARG: value=arg(pcomplex); break;
				case AP_ANG: value=arg(pcomplex)*180/PI;  break;
				default: pcomplex = NULL; break; /* invalidate the result */
				}
			}
			break;
		case PT_double:
		case PT_loadshape:
		case PT_random:
			pdouble = object_get_double(obj,aggr->pinfo);
			if (pdouble!=NULL){
				value = *pdouble;
				if(aggr->pinfo->unit != 0 && aggr->punit != 0){
					int rv = unit_convert_ex(aggr->pinfo->unit, aggr->punit, &value);
					if(rv == 0){ // error
						;
					}
				} // else don't worry
			}
			break;
		default:
			break;
		}

		if (pdouble!=NULL || pcomplex!=NULL) /* valid value */
		{
			if ((aggr->flags&AF_ABS)==AF_ABS) value=fabs(value);
			switch (aggr->op) {
			case AGGR_MIN:
				if (value<numerator || denominator==0) numerator=value;
				denominator = 1;
				break;
			case AGGR_MAX:
				if (value>numerator || denominator==0) numerator=value;
				denominator = 1;
				break;
			case AGGR_COUNT:
				numerator++;
				denominator=1;
				break;
			case AGGR_MBE:
				denominator++;
				numerator += value;
				secondary += (value-secondary)/denominator;
				break;
			case AGGR_AVG:
			case AGGR_MEAN:
				numerator+=value;
				denominator++;
				break;
			case AGGR_SUM:
				numerator+=value;
				denominator = 1;
				break;
			case AGGR_PROD:
				numerator*=value;
				denominator = 1;
				break;
			case AGGR_GAMMA:
				denominator+=log(value);
				if (numerator==0 || secondary>value)
					secondary = value;
				numerator++;
				break;
			case AGGR_STD:
			case AGGR_VAR:
				denominator++;
				// note this uses a compensated on-line algorithm (see Knuth 1998)
				// it's better than the obvious method because it doesn't suffer from numerical instability when mean(x)-x is near zero
				{	double delta = value-secondary;
					secondary += delta/denominator;
					numerator += delta*(value-secondary);
				}
				break;
			case AGGR_SKEW:
			case AGGR_KUR:
			default:
				break;
			}
		}
	}
	switch (aggr->op) {
		double v = 0.0, t = 0.0, m = 0.0;
	case AGGR_GAMMA:
		return 1 + numerator/(denominator-numerator*log(secondary));
	case AGGR_STD:
		return sqrt(numerator/(denominator-1));// * scale;
	case AGGR_MBE:
		return numerator/denominator - secondary;
	case AGGR_SKEW:
		/** @todo implement skewness aggregate (no ticket) */
		throw_exception("skewness aggregation is not implemented");
		/* TROUBLESHOOT
			An attempt to use the skew aggregator failed because it is not implemented yet.
			Remove or replace the reference to the skew aggregate and try again.
		 */
	case AGGR_KUR:
		/** @todo implement kurtosis aggregate (no ticket) */
		throw_exception("kurtosis aggregation is not implemented");
		/* TROUBLESHOOT
			An attempt to use the kurtosis aggregator failed because it is not implemented yet.
			Remove or replace the reference to the
		 */
	default:
		return numerator/denominator;// * scale;
	}
}