Ejemplo n.º 1
0
static
char* parser_get_param_name(char* line, char **end, char **buf)
{
    char* next; 
    char *str;

    next = parser_get_next_char('=',line,1);

    *buf = 0;
    if (next == 0) {
	return 0;
    }

    str = make_segment(line,next);
    *end = next+1;
    if (**end == '"') {
        *end = *end+1;
	    next = parser_get_next_char('"',*end,0);
	    if (next == 0) {
		    return 0;
	    }

	    *buf = *end = make_segment(*end,next);
    }

    return str;
}
Ejemplo n.º 2
0
static
char* parser_get_prop_name(char* line, char** end)
{
    char* p;
    char* v;
    char *str;

    p = parser_get_next_char(';',line,1); 
    v = parser_get_next_char(':',line,1); 
    if (p== 0 && v == 0) {
	return 0;
    }

    /* There is no ';' or, it is after the ';' that marks the beginning of
       the value */
    if (v!=0 && ( p == 0 || p > v)){
	str = make_segment(line,v);
	*end = v+1;
    } else {
	str = make_segment(line,p);
	*end = p+1;
    }

    return str;
}
Ejemplo n.º 3
0
static char *parser_get_param_name_heap(char *line, char **end)
{
    /* This is similar to parser_get_param_name_stack except it returns heap
       objects in the return value and the end parameter. This is used in case
       the name or value is longer than the stack-allocated string.
    */
    char *next;
    char *str;

    next = parser_get_next_char('=', line, 1);

    if (next == 0) {
        return 0;
    }

    str = make_segment(line, next);
    *end = next + 1;
    if (**end == '"') {
        *end = *end + 1;
        next = parser_get_next_char('"', *end, 0);
        if (next == 0) {
            free(str);
            *end = NULL;
            return 0;
        }

        *end = make_segment(*end, next);
    } else {
        *end = make_segment(*end, *end + strlen(*end));
    }

    parser_decode_param_value(*end);

    return str;
}
Ejemplo n.º 4
0
static char *parser_get_next_parameter(char *line, char **end)
{
    char *next;
    char *v;
    char *str;

    v = parser_get_next_char(':', line, 1);
    next = parser_get_next_char(';', line, 1);

    /* There is no ';' or, it is after the ':' that marks the beginning of
       the value */

    if (next == 0 || next > v) {
        next = parser_get_next_char(':', line, 1);
    }

    if (next != 0) {
        str = make_segment(line, next);
        *end = next + 1;
        return str;
    } else {
        *end = line;
        return 0;
    }
}
Ejemplo n.º 5
0
Heap::Heap(int _segment_size)
{
	count_segments = 0;
	segment_size = _segment_size;
	current = 0;
	make_segment();
}
Ejemplo n.º 6
0
// ------------------------------------------------------------------- init ---
void init( void )
{
    glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
    glDisable( GL_DEPTH_TEST );
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    // Make program
    program = build_program( vertex_shader_source, fragment_shader_source );
    //GLuint attrib = glGetAttribLocation(program, "thickness");
    //printf("%d\n", attrib);

    // Make lines
    lines = vertex_buffer_new( "v2f:t2f:c4f:1g1f" );
    float r=0.0f, g=0.0f, b=0.0f, a=1.0f;
    size_t i;
    for( i=0; i<57; ++i)
    {
        float thickness = (i+1)*0.2;
        float x0 = 2+i*10+0.315;
        float y0 = 5+0.315;
        float x1 = 35+i*10+0.315;
        float y1 = 170+0.315;
        make_segment(lines, x0,y0, x1,y1, thickness, r,g,b,a);
    }
}
Ejemplo n.º 7
0
		//! Generate a new item to visit based on the adjacent triangle at index next.
		boost::optional<edge_item> prepare_adjacent_traversal( std::size_t next, const edge_item& item )
		{
			comparison_policy cmp( 0 );
			bool allAround = get<0>( item.lo ) == constants::infinity<coordinate_type>() && get<0>( item.hi ) == constants::negative_infinity<coordinate_type>();

			const std::size_t* fromIndices = m_mesh.get_triangle_indices( item.to );
			const std::size_t* toIndices = m_mesh.get_triangle_indices( next );
						
			std::size_t side = get_triangle_adjacent_side( fromIndices, toIndices );
			auto pointLo = m_mesh.get_triangle_vertices( item.to )[side];
			auto pointHi = m_mesh.get_triangle_vertices( item.to )[(side + 1) % 3];

			if( exterior_product_area( pointHi - pointLo, m_origin - pointLo ) < constants::zero<decltype(std::declval<coordinate_type>() * std::declval<coordinate_type>())>() )
				std::swap( pointLo, pointHi );

			if (!is_segment_in_range_2d(make_segment(pointLo, pointHi), item.lo, item.hi, m_origin)) 
				return boost::none;

#if GEOMETRIX_TEST_ENABLED(GEOMETRIX_DEBUG_VISIBLE_VERTICES_MESH_SEARCH)
			//polygon2 pTri(mMesh.get_triangle_vertices(item.from), mMesh.get_triangle_vertices(item.from) + 3);
			typedef std::vector<point_t> polygon2;
			typedef segment<point_t> segment2;
			polygon2 cTri(m_mesh.get_triangle_vertices(item.to), m_mesh.get_triangle_vertices(item.to) + 3);
			polygon2 nTri(m_mesh.get_triangle_vertices(next), m_mesh.get_triangle_vertices(next) + 3);
			segment2 sLo{ m_origin, m_origin + item.lo };
			segment2 sHi{ m_origin, m_origin + item.hi };
			segment2 cLo{ m_origin, pointLo };
			segment2 cHi{ m_origin, pointHi };
#endif

			vector_t vecLo, vecHi;
			if( !numeric_sequence_equals_2d(m_origin, pointLo, cmp) && !numeric_sequence_equals_2d(m_origin, pointHi, cmp) )
			{
				assign( vecLo, pointLo - m_origin );
				assign( vecHi, pointHi - m_origin );
				
				if (!allAround)
				{
					vecLo = is_vector_between(item.lo, item.hi, vecLo, false, cmp) ? vecLo : item.lo;
					vecHi = is_vector_between(item.lo, item.hi, vecHi, false, cmp) ? vecHi : item.hi;
				}

				if (get_orientation(vecHi, vecLo, cmp) == geometrix::oriented_left)
					return boost::none;
			}
			else
			{
				assign( vecLo, constants::infinity<coordinate_type>(), constants::zero<coordinate_type>() );
				assign( vecHi, constants::negative_infinity<coordinate_type>(), constants::zero<coordinate_type>() );
			}
			
#if GEOMETRIX_TEST_ENABLED(GEOMETRIX_DEBUG_VISIBLE_VERTICES_MESH_SEARCH)
			segment2 nLo{ m_origin, m_origin + vecLo };
			segment2 nHi{ m_origin, m_origin + vecHi };
#endif			
			return edge_item( item.to, next, vecLo, vecHi );
		}
Ejemplo n.º 8
0
/*
 *	Process WM_TERM records
 *	  Add the termination code to the reqinfo node.
 */
static void wm_term(struct wkmgmtbs *wbuf)
{
	struct	wkmgmtbs *riptr;
	struct	wmreq	*rqptr;

	if (db_flag > 8) {
		Ndebug("wm_term(9): TERM - reqid(%lld), arrayid(%d).\n",
		       wbuf->reqid, wbuf->arrayid);
	}

	if ((rqptr = find_request(wbuf->reqid, wbuf->arrayid)) == NULL) {
		make_request(NORM_REQ);
		rqptr = rhead->last;
		rqptr->reqid = wbuf->reqid;
		rqptr->arrayid = wbuf->arrayid;
		riptr = rqptr->slast->riptr;
		init_wkmgmtbs(riptr, wbuf);

	} else if (rqptr->slast == NULL) {
		make_segment(rqptr, NORM_REQ);
		riptr = rqptr->slast->riptr;
		init_wkmgmtbs(riptr, wbuf);

	} else {
		riptr = rqptr->slast->riptr;
	}

	/*
	 *	The last node on the segment list should be
	 *	what we want.  If not, the records in the file
	 *	are out of order.
	 */
	if (riptr->term_subtype == WM_NO_TERM) {
		riptr->code = wbuf->code;
		riptr->utime = wbuf->utime;
		riptr->stime = wbuf->stime;
		riptr->term_subtype = wbuf->subtype;
	} else {
		if (db_flag > 2) {
			Ndebug("wm_term(3): reqinfo node not "
			       "at end of segment list.\n"
			       "\triptr: term_subtype(%d), jid(0x%llx), "
			       "wbuf->jid(0x%llx), rqptr->ltype(%d).\n",
			       riptr->term_subtype, riptr->jid,
			       wbuf->jid, rqptr->ltype);
		}
		return;	/* ignore this record */
	}

	rqptr->ltype    = wbuf->type;
	rqptr->lsubtype = wbuf->subtype;

	return;
}
Ejemplo n.º 9
0
float rad_bin_search(struct Point* points, struct Segment* segments,
                     size_t number_of_points, size_t number_of_points_to_cover) {
    float mid, left = 0, right = 10000;
    for (size_t i = 0; i < 32; ++i) {
        mid = (left + right) / 2.0f;
        make_segment (points, segments, mid, number_of_points);
        sort_segment (segments, 0, 2 * number_of_points - 1);
        if (predicat (number_of_points_to_cover, segments, 2 * number_of_points)) right = mid;
        else  left = mid;
    }
    return mid;
}
Ejemplo n.º 10
0
char* icalparser_get_value(char* line, char **end, icalvalue_kind kind)
{
    char *str;
    size_t length = strlen(line);

    if (length == 0){
        return 0;
    } 

    *end = line+length;
    str = make_segment(line, *end);

    return str;
}
Ejemplo n.º 11
0
/*keep for historical sake*/
static char *parser_get_next_paramvalue(char *line, char **end)
{
    char *next;
    char *str;

    next = parser_get_next_char(',', line, 1);

    if (next == 0) {
        next = (char *)(size_t) line + (size_t) strlen(line);
    }

    if (next == line) {
        return 0;
    } else {
        str = make_segment(line, next);
        *end = next + 1;
        return str;
    }
}
Ejemplo n.º 12
0
/*
 *	Process WM_RECV records
 *	  If a request node does not exist for the request ID,
 *	  add one to the end of the request linked list.  Update
 *	  necessary fields.
 *
 *	  If there are multiple WM_RECV records (request moves from pipe
 *	  to batch queue), the start queue wait time (sqtime) is set to the
 *	  time of the first record (usually pipe queue).  Also update the
 *	  queue type and name so we always have the most current type and
 *	  name.
 *
 *	  The initial time stamp for this segment is set to the time of
 *	  the most recent WM_RECV record.
 *
 *	  NOTE: WM_RECV records do not contain valid jids.
 */
static void wm_recv(struct wkmgmtbs *wbuf)
{
	struct wkmgmtbs	*riptr;
	struct wmreq	*rqptr;

	if (db_flag > 8) {
		Ndebug("wm_recv(9): RECV - reqid(%lld), arrayid(%d).\n",
		       wbuf->reqid, wbuf->arrayid);
	}

	if ((rqptr = find_request(wbuf->reqid, wbuf->arrayid)) == NULL) {
		make_request(NORM_REQ);
		rqptr = rhead->last;	
		rqptr->reqid = wbuf->reqid;
		rqptr->arrayid = wbuf->arrayid;
		rqptr->stime = wbuf->time;
		riptr = rqptr->slast->riptr;
		init_wkmgmtbs(riptr, wbuf);
		riptr->jid = WM_NO_JID;

	} else if (rqptr->slast == NULL) {
		rqptr->stime = wbuf->time;	/* update */
		make_segment(rqptr, NORM_REQ);
		riptr = rqptr->slast->riptr;
		init_wkmgmtbs(riptr, wbuf);
		riptr->jid = WM_NO_JID;

	} else {
		riptr = rqptr->slast->riptr;

	}

	riptr->qtype = wbuf->qtype;
	strcpy(riptr->quename, wbuf->quename);

	rqptr->ltype    = wbuf->type;
	rqptr->lsubtype = wbuf->subtype;

	return;
}
Ejemplo n.º 13
0
/*
 *	Add a request node (and its associated segment and wkmgmtbs(c) nodes)
 *	to the end of the linked list
 */
static void make_request(int typ)
{
	struct	wmreq	*nw_req;

	/*
	 *	Allocate space for the new request node and zero it out
	 */
	if ((nw_req = (struct wmreq *)malloc(sizeof(struct wmreq))) == NULL) {
		acct_perr(ACCT_ABORT, errno,
		  _("There was insufficient memory available when allocating '%s'."),
		    "wmreq node");
	}
	memset((char *)nw_req, '\0', sizeof(struct wmreq));

	/*
	 *	Link the new node to the end of the list
	 */

	nw_req->nptr = NULL;
	if (rhead->last != NULL) {
		rhead->last->nptr = nw_req;
		nw_req->bptr = rhead->last;
		rhead->last = nw_req;
	} else {
		rhead->first = rhead->last = nw_req;
		nw_req->bptr = NULL;
	}

	/*
	 *	Now add the segment and wkmgmtbs nodes
	 */
	nw_req->sfirst = nw_req->slast = NULL;
	nw_req->ppfirst = nw_req->pplast = NULL;
	make_segment(nw_req, typ);
	nw_req->ltype = WM_NO_LTYPE;

	return;
}
Ejemplo n.º 14
0
/*
 *	Process WM_INIT records
 */
static void wm_init(struct wkmgmtbs *wbuf)
{
	struct wkmgmtbs	*riptr;
	struct wmreq	*rqptr;
	struct wmseg	*sptr;

	if (db_flag > 8) {
		Ndebug("wm_init(9): INIT - reqid(%lld), arrayid(%d).\n",
		       wbuf->reqid, wbuf->arrayid);
	}

	/*
	 *	Ideally, this reqid should already have a request node,
	 *	but if it doesn't, we'll make one
	 */
	if ((rqptr = find_request(wbuf->reqid, wbuf->arrayid)) == NULL) {
		if (db_flag > 2) {
			Ndebug("wm_init(3): Making request node for "
			       "reqid(%lld), type WM_INIT, subtype(%d).\n",
			       wbuf->reqid, wbuf->subtype);
		}
		make_request(NORM_REQ);
		rqptr = rhead->last;
		rqptr->reqid = wbuf->reqid;
		rqptr->arrayid = wbuf->arrayid;

	} else if (rqptr->slast == NULL) {
		make_segment(rqptr, NORM_REQ);
	}

	/*
	 *	If the previous record type for this reqid is not
	 *	WM_RECV, we need to add a segment node to the end
	 *	of this reqid's list.
	 */
	if (rqptr->ltype != WM_RECV && rqptr->ltype != WM_NO_LTYPE) {
		sptr = make_segment(rqptr, NORM_REQ);
		riptr = sptr->riptr;
	} else {
		riptr = rqptr->slast->riptr;
	}

	/*
	 *	Initialize the wkmgmtbs(c) node with values from the
	 *	input record.
	 */
	init_wkmgmtbs(riptr, wbuf);
	riptr->init_subtype = wbuf->subtype;
	if (wbuf->enter_time > 0) {
		riptr->qwtime = wbuf->time - wbuf->enter_time;
	}

	rqptr->ltype    = wbuf->type;
	rqptr->lsubtype = wbuf->subtype;

	/*
	 *	Time stamp on output record is always the time stamp
	 *	of the WM_INIT record, if it exists.
	 */
	rqptr->stime = riptr->start_time = wbuf->time;

	return;
}
Ejemplo n.º 15
0
icalcomponent *icalparser_add_line(icalparser *parser, char *line)
{
    char *str;
    char *end;
    int pcount = 0;
    int vcount = 0;
    icalproperty *prop;
    icalproperty_kind prop_kind;
    icalvalue *value;
    icalvalue_kind value_kind = ICAL_NO_VALUE;

    icalerror_check_arg_rz((parser != 0), "parser");

    if (line == 0) {
        parser->state = ICALPARSER_ERROR;
        return 0;
    }

    if (line_is_blank(line) == 1) {
        return 0;
    }

    /* Begin by getting the property name at the start of the line. The
       property name may end up being "BEGIN" or "END" in which case it
       is not really a property, but the marker for the start or end of
       a component */

    end = 0;
    str = parser_get_prop_name(line, &end);

    if (str == 0 || *str == '\0') {
        /* Could not get a property name */
        icalcomponent *tail = pvl_data(pvl_tail(parser->components));

        if (tail) {
            insert_error(
                tail, line,
                "Got a data line, but could not find a property name or component begin tag",
                ICAL_XLICERRORTYPE_COMPONENTPARSEERROR);
        }
        tail = 0;
        parser->state = ICALPARSER_ERROR;
        icalmemory_free_buffer(str);
        str = NULL;
        return 0;
    }

    /**********************************************************************
     * Handle begin and end of components
     **********************************************************************/
    /* If the property name is BEGIN or END, we are actually
       starting or ending a new component */

    if (strcasecmp(str, "BEGIN") == 0) {
        icalcomponent *c;
        icalcomponent_kind comp_kind;

        parser->level++;
        icalmemory_free_buffer(str);
        str = parser_get_next_value(end, &end, value_kind);

        comp_kind = icalenum_string_to_component_kind(str);

        c = icalcomponent_new(comp_kind);

        if (c == 0) {
            c = icalcomponent_new(ICAL_XLICINVALID_COMPONENT);
            insert_error(c, str, "Parse error in component name",
                         ICAL_XLICERRORTYPE_COMPONENTPARSEERROR);
        }

        pvl_push(parser->components, c);

        parser->state = ICALPARSER_BEGIN_COMP;

        icalmemory_free_buffer(str);
        str = NULL;
        return 0;

    } else if (strcasecmp(str, "END") == 0) {
        icalcomponent *tail;

        parser->level--;
        icalmemory_free_buffer(str);
        str = parser_get_next_value(end, &end, value_kind);

        /* Pop last component off of list and add it to the second-to-last */
        parser->root_component = pvl_pop(parser->components);

        tail = pvl_data(pvl_tail(parser->components));

        if (tail != 0) {
            icalcomponent_add_component(tail, parser->root_component);
        }

        tail = 0;
        icalmemory_free_buffer(str);
        str = NULL;

        if (parser->level < 0) {
            // Encountered an END before any BEGIN, this must be invalid data
            icalerror_warn("Encountered END before BEGIN");

            parser->state = ICALPARSER_ERROR;
            parser->level = 0;
            return 0;
        } else if (parser->level == 0) {
            /* Return the component if we are back to the 0th level */
            icalcomponent *rtrn;

            if (pvl_count(parser->components) != 0) {
                /* There are still components on the stack -- this means
                   that one of them did not have a proper "END" */
                pvl_push(parser->components, parser->root_component);
                (void)icalparser_clean(parser); /* may reset parser->root_component */
            }

            assert(pvl_count(parser->components) == 0);

            parser->state = ICALPARSER_SUCCESS;
            rtrn = parser->root_component;
            parser->root_component = 0;
            return rtrn;

        } else {
            parser->state = ICALPARSER_END_COMP;
            return 0;
        }
    }

    /* There is no point in continuing if we have not seen a
       component yet */

    if (pvl_data(pvl_tail(parser->components)) == 0) {
        parser->state = ICALPARSER_ERROR;
        icalmemory_free_buffer(str);
        str = NULL;
        return 0;
    }

    /**********************************************************************
     * Handle property names
     **********************************************************************/

    /* At this point, the property name really is a property name,
       (Not a component name) so make a new property and add it to
       the component */

    prop_kind = icalproperty_string_to_kind(str);

    prop = icalproperty_new(prop_kind);

    if (prop != 0) {
        icalcomponent *tail = pvl_data(pvl_tail(parser->components));

        if (prop_kind == ICAL_X_PROPERTY) {
            icalproperty_set_x_name(prop, str);
        }

        icalcomponent_add_property(tail, prop);

        /* Set the value kind for the default for this type of
           property. This may be re-set by a VALUE parameter */
        value_kind = icalproperty_kind_to_value_kind(icalproperty_isa(prop));

    } else {
        icalcomponent *tail = pvl_data(pvl_tail(parser->components));

        insert_error(tail, str, "Parse error in property name",
                     ICAL_XLICERRORTYPE_PROPERTYPARSEERROR);

        tail = 0;
        parser->state = ICALPARSER_ERROR;
        icalmemory_free_buffer(str);
        str = NULL;
        return 0;
    }

    icalmemory_free_buffer(str);
    str = NULL;

    /**********************************************************************
     * Handle parameter values
     **********************************************************************/

    /* Now, add any parameters to the last property */

    while (pcount < MAXIMUM_ALLOWED_PARAMETERS) {
        if (*(end - 1) == ':') {
            /* if the last separator was a ":" and the value is a
               URL, icalparser_get_next_parameter will find the
               ':' in the URL, so better break now. */
            break;
        }

        icalmemory_free_buffer(str);
        str = parser_get_next_parameter(end, &end);
        strstriplt(str);
        if (str != 0) {
            char *name_heap = 0;
            char *pvalue_heap = 0;
            char name_stack[TMP_BUF_SIZE];
            char pvalue_stack[TMP_BUF_SIZE];
            char *name = name_stack;
            char *pvalue = pvalue_stack;

            icalparameter *param = 0;
            icalparameter_kind kind;
            icalcomponent *tail = pvl_data(pvl_tail(parser->components));

            if (!parser_get_param_name_stack(str, name_stack, sizeof(name_stack),
                                             pvalue_stack, sizeof(pvalue_stack))) {
                name_heap = parser_get_param_name_heap(str, &pvalue_heap);

                name = name_heap;
                pvalue = pvalue_heap;

                if (name_heap == 0) {
                    /* 'tail' defined above */
                    insert_error(tail, str, "Cant parse parameter name",
                                 ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR);
                    tail = 0;
                    break;
                }
            }

            kind = icalparameter_string_to_kind(name);

            if (kind == ICAL_X_PARAMETER) {
                param = icalparameter_new(ICAL_X_PARAMETER);
                if (param != 0) {
                    icalparameter_set_xname(param, name);
                    icalparameter_set_xvalue(param, pvalue);
                }
            } else if (kind == ICAL_IANA_PARAMETER) {
                ical_unknown_token_handling tokHandlingSetting =
                    ical_get_unknown_token_handling_setting();
                if (tokHandlingSetting == ICAL_DISCARD_TOKEN) {
                    if (name_heap) {
                        icalmemory_free_buffer(name_heap);
                        name_heap = 0;
                    }
                    if (pvalue_heap) {
                        icalmemory_free_buffer(pvalue_heap);
                        pvalue_heap = 0;
                    }
                    continue;
                }

                param = icalparameter_new(ICAL_IANA_PARAMETER);

                if (param != 0) {
                    icalparameter_set_xname(param, name);
                    icalparameter_set_xvalue(param, pvalue);
                }
            } else if (kind == ICAL_TZID_PARAMETER && *(end - 1) != ';') {
                /*
                   Special case handling for TZID to work around invalid incoming data.
                   For example, Google Calendar will send back stuff like this:
                   DTSTART;TZID=GMT+05:30:20120904T020000

                   In this case we read to the next semicolon or the last colon rather
                   than the first colon.  This way the TZID will become GMT+05:30 rather
                   than trying to parse the date-time as 30:20120904T020000.

                   This also handles properties that look like this:
                   DTSTART;TZID=GMT+05:30;VALUE=DATE-TIME:20120904T020000
                 */
                char *lastColon = 0;
                char *nextColon = end;
                char *nextSemicolon = parser_get_next_char(';', end, 1);

                /* Find the last colon in the line */
                do {
                    nextColon = parser_get_next_char(':', nextColon, 1);

                    if (nextColon) {
                        lastColon = nextColon;
                    }
                } while (nextColon);

                if (lastColon && nextSemicolon && nextSemicolon < lastColon) {
                    /*
                       Ensures that we don't read past a semicolon

                       Handles the following line:
                       DTSTART;TZID=GMT+05:30;VALUE=DATE-TIME:20120904T020000
                     */
                    lastColon = nextSemicolon;
                }

                /*
                   Rebuild str so that it includes everything up to the next semicolon
                   or the last colon. So given the above example, str will go from
                   "TZID=GMT+05" to "TZID=GMT+05:30"
                 */
                if (lastColon && *(lastColon + 1) != 0) {
                    char *strStart = line + strlen(name) + 2;

                    end = lastColon + 1;

                    icalmemory_free_buffer(str);
                    str = make_segment(strStart, end - 1);
                }

                /* Reparse the parameter name and value with the new segment */
                if (!parser_get_param_name_stack(str, name_stack, sizeof(name_stack),
                                                 pvalue_stack, sizeof(pvalue_stack))) {
                    if (pvalue_heap) {
                        icalmemory_free_buffer(pvalue_heap);
                        pvalue_heap = 0;
                        pvalue = 0;
                    }
                    if (name_heap) {
                        icalmemory_free_buffer(name_heap);
                        name = 0;
                    }
                    name_heap = parser_get_param_name_heap(str, &pvalue_heap);
                    pvalue = pvalue_heap;
                }
                param = icalparameter_new_from_value_string(kind, pvalue);
            } else if (kind != ICAL_NO_PARAMETER) {
                param = icalparameter_new_from_value_string(kind, pvalue);
            } else {
                /* Error. Failed to parse the parameter */
                /* 'tail' defined above */

                /* Change for mozilla */
                /* have the option of being flexible towards unsupported parameters */
#if ICAL_ERRORS_ARE_FATAL == 1
                insert_error(tail, str, "Cant parse parameter name",
                             ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR);
                tail = 0;
                parser->state = ICALPARSER_ERROR;
                if (pvalue_heap) {
                    icalmemory_free_buffer(pvalue_heap);
                    pvalue = 0;
                }
                if (name_heap) {
                    icalmemory_free_buffer(name_heap);
                    name = 0;
                }
                icalmemory_free_buffer(str);
                str = NULL;
                return 0;
#else
                if (name_heap) {
                    icalmemory_free_buffer(name_heap);
                    name_heap = 0;
                }
                if (pvalue_heap) {
                    icalmemory_free_buffer(pvalue_heap);
                    pvalue_heap = 0;
                }
                icalmemory_free_buffer(str);
                str = NULL;
                continue;
#endif
            }

            if (pvalue_heap) {
                icalmemory_free_buffer(pvalue_heap);
                pvalue_heap = 0;
            }

            if (name_heap) {
                icalmemory_free_buffer(name_heap);
                name_heap = 0;
            }

            if (param == 0) {
                /* 'tail' defined above */
                insert_error(tail, str, "Cant parse parameter value",
                             ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR);

                tail = 0;
                parser->state = ICALPARSER_ERROR;

                icalmemory_free_buffer(str);
                str = NULL;

                continue;
            }

            /* If it is a VALUE parameter, set the kind of value */
            if (icalparameter_isa(param) == ICAL_VALUE_PARAMETER) {
                value_kind =
                    (icalvalue_kind)icalparameter_value_to_value_kind(
                        icalparameter_get_value(param));

                if (!icalproperty_value_kind_is_valid(prop_kind, value_kind)) {

                    /* Ooops, invalid VALUE parameter, so reset the value_kind */

                    const char *err_str = "Invalid VALUE type for property";
                    const char *prop_str = icalproperty_kind_to_string(prop_kind);
                    size_t tmp_buf_len = strlen(err_str) + strlen(prop_str) + 2;
                    char *tmp_buf = icalmemory_tmp_buffer(tmp_buf_len);
                    snprintf(tmp_buf, tmp_buf_len, "%s %s", err_str, prop_str);

                    insert_error(tail, str, tmp_buf,
                                 ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR);

                    value_kind = icalproperty_kind_to_value_kind(prop_kind);

                    icalparameter_free(param);
                    tail = 0;
                    parser->state = ICALPARSER_ERROR;

                    icalmemory_free_buffer(str);
                    str = NULL;
                    pcount++;
                    continue;
                }
            }

            /* Everything is OK, so add the parameter */
            icalproperty_add_parameter(prop, param);
            tail = 0;
            icalmemory_free_buffer(str);
            str = NULL;
            pcount++;

        } else {
            /* str is NULL */
            break;
        }

    }   /* while(1) */

    /**********************************************************************
     * Handle values
     **********************************************************************/

    /* Look for values. If there are ',' characters in the values,
       then there are multiple values, so clone the current
       parameter and add one part of the value to each clone */

    vcount = 0;
    while (vcount < MAXIMUM_ALLOWED_MULTIPLE_VALUES) {
        /* Only some properties can have multiple values. This list was taken
           from rfc5545. Also added the x-properties, because the spec actually
           says that commas should be escaped. For x-properties, other apps may
           depend on that behaviour
         */
        icalmemory_free_buffer(str);
        str = NULL;

        if (icalproperty_value_kind_is_multivalued(prop_kind, &value_kind)) {
            str = parser_get_next_value(end, &end, value_kind);
        } else {
            str = icalparser_get_value(end, &end, value_kind);
        }
        strstriplt(str);

        if (str != 0) {

            if (vcount > 0) {
                /* Actually, only clone after the second value */
                icalproperty *clone = icalproperty_clone(prop);
                icalcomponent *tail = pvl_data(pvl_tail(parser->components));

                icalcomponent_add_property(tail, clone);
                prop = clone;
                tail = 0;
            }

            value = icalvalue_new_from_string(value_kind, str);

            /* Don't add properties without value */
            if (value == 0) {
                char temp[200]; /* HACK */

                icalproperty_kind prop_kind = icalproperty_isa(prop);
                icalcomponent *tail = pvl_data(pvl_tail(parser->components));

                snprintf(temp, sizeof(temp),
                         "Can't parse as %s value in %s property. Removing entire property",
                         icalvalue_kind_to_string(value_kind),
                         icalproperty_kind_to_string(prop_kind));

                insert_error(tail, str, temp, ICAL_XLICERRORTYPE_VALUEPARSEERROR);

                /* Remove the troublesome property */
                icalcomponent_remove_property(tail, prop);
                icalproperty_free(prop);
                prop = 0;
                tail = 0;
                parser->state = ICALPARSER_ERROR;

                icalmemory_free_buffer(str);
                str = NULL;
                return 0;

            } else {
                vcount++;
                icalproperty_set_value(prop, value);
            }
            icalmemory_free_buffer(str);
            str = NULL;

        } else {
#if ICAL_ALLOW_EMPTY_PROPERTIES
            /* Don't replace empty properties with an error.
               Set an empty length string (not null) as the value instead */
            if (vcount == 0) {
                icalproperty_set_value(prop, icalvalue_new(ICAL_NO_VALUE));
            }

            break;
#else
            if (vcount == 0) {
                char temp[200]; /* HACK */

                icalproperty_kind prop_kind = icalproperty_isa(prop);
                icalcomponent *tail = pvl_data(pvl_tail(parser->components));

                snprintf(temp, sizeof(temp), "No value for %s property. Removing entire property",
                         icalproperty_kind_to_string(prop_kind));

                insert_error(tail, str, temp, ICAL_XLICERRORTYPE_VALUEPARSEERROR);

                /* Remove the troublesome property */
                icalcomponent_remove_property(tail, prop);
                icalproperty_free(prop);
                prop = 0;
                tail = 0;
                parser->state = ICALPARSER_ERROR;
                return 0;
            } else {

                break;
            }
#endif
        }
    }

    /****************************************************************
     * End of component parsing.
     *****************************************************************/

    if (pvl_data(pvl_tail(parser->components)) == 0 && parser->level == 0) {
        /* HACK. Does this clause ever get executed? */
        parser->state = ICALPARSER_SUCCESS;
        assert(0);
        return parser->root_component;
    } else {
        parser->state = ICALPARSER_IN_PROGRESS;
        return 0;
    }
}
Ejemplo n.º 16
0
void* Heap::get_mem(int size)
{
	if (size <= SEGMENTSIZE)
	{
		Segment*  now_current = current;
		while (now_current != 0)
		{
			for (int i = 0; i < now_current->descriptor_count; i++)
			{
				if (size <= now_current->descriptor[i].size && !now_current->descriptor[i].used)
				{
					if (size == now_current->descriptor[i].size)
					{
						now_current->descriptor[i].used = true;
						return now_current->descriptor[i].offset;
					}
					else
					{
						if (now_current->descriptor_count + 1 <= SEGMENTCOUNT)
						{
							Chunk my_Chunk;
							my_Chunk.offset = (char*)(now_current->descriptor[i].offset) + size;
							my_Chunk.size = now_current->descriptor[i].size - size;
							my_Chunk.used = false;

							now_current->descriptor[i].used = true;
							now_current->descriptor[i].size = size;
							now_current->descriptor_count++;

							for (int h = now_current->descriptor_count; h > i; h--)
							{
								now_current->descriptor[h] = now_current->descriptor[h - 1];
							}
							now_current->descriptor[i + 1] = my_Chunk;
							print();
							return now_current->descriptor[i].offset;
						}
					}
				}
			}
			now_current = now_current->prev;
		}

		if (make_segment() == 0)
		{
			Chunk my_Chunk;
			my_Chunk.offset = (char*)(current->data) + size;
			my_Chunk.size = current->descriptor[0].size - size;
			my_Chunk.used = false;

			current->descriptor[0].used = true;
			current->descriptor[0].size = size;
			current->descriptor[1] = my_Chunk;
			current->descriptor_count++;
			print();
			return current->descriptor[0].offset;
		}
		else
		{
			errorReporter.FReport(logfile, "A lot of segment of memory", 0, 0);
		}
	}
	else
		errorReporter.FReport(logfile, "A big size for segment of memory", 0, 0);

	return nullptr;
}
Ejemplo n.º 17
0
/*
 *	Process WM_SPOOL records
 *	  Update or create a wkmgmtbs(c) entry on the pp list.  These
 *	  entries contain information about the pipeclients and
 *	  netclients.
 *
 */
static void wm_spool(struct wkmgmtbs *wbuf)
{
	struct	wkmgmtbs *riptr;
	struct	wmreq	*rqptr;
	struct	wmseg	*sptr;

	if (db_flag > 8) {
		Ndebug("wm_spool(9): SPOOL - reqid(%lld), arrayid(%d).\n",
		       wbuf->reqid, wbuf->arrayid);
	}

	if ((rqptr = find_request(wbuf->reqid, wbuf->arrayid)) == NULL) {
		/*
		 * This is a new reqid. Create request, segment
		 * and wkmgmtbs(c) entries for it.
		 */
		if (db_flag > 2) {
			Ndebug("wm_spool(3): making request node for "
			       "reqid(%lld), type WM_SPOOL, subtype(%d).\n",
			       wbuf->reqid, wbuf->subtype);
		}
		make_request(AUX_REQ);
		rqptr = rhead->last;	
		rqptr->reqid = wbuf->reqid;
		rqptr->arrayid = wbuf->arrayid;
		riptr = rqptr->pplast->riptr;
		init_wkmgmtbs(riptr, wbuf);

	} else if (rqptr->pplast == NULL) {
		/*
		 * This reqid does not have any wkmgmtbs(c) entries on the
		 * pp list, so make one.
		 */
		if (db_flag > 2) {
			Ndebug("wm_spool(3): pplast == NULL.\n");
		}
		make_segment(rqptr, AUX_REQ);
		riptr = rqptr->pplast->riptr;
		init_wkmgmtbs(riptr, wbuf);

	} else {
		/*
		 * Look through the entire pp list for this jid, since
		 * there could be multiple active pipeclients and
		 * netclients.  If jid = 0 (which could happen on a
		 * WM_SPOOL_TERM record), then update the first active
		 * entry.
		 */
		int	found = 0;

		if (db_flag > 2) {
			Ndebug("wm_spool(3):  looking for a wkmgmtbs(c) "
			       "entry with jid(0x%llx).\n", wbuf->jid);
		}

		for (sptr = rqptr->ppfirst, riptr = sptr->riptr;
		     ((sptr != NULL) && (found == 0)); sptr = sptr->nptr) {
			riptr = sptr->riptr;

			switch (wbuf->jid) {
			case 0:
				if (riptr->term_subtype == WM_NO_TERM) {
					found = 1;
				}
				break;

			default:
				if (riptr->jid == wbuf->jid) {
					found = 1;
				}
				break;
			}		/* end of switch(jid) */
		}

		if (!found) {
			if (db_flag > 2) {
				Ndebug("wm_spool(3): making new "
				       "segment node.\n");
			}
			make_segment(rqptr, AUX_REQ);
			riptr = rqptr->pplast->riptr;
			init_wkmgmtbs(riptr, wbuf);
		}
	}

	/*
	 * Update the wkmgmtbs(c) entry.
	 */
	switch (wbuf->subtype) {

	case WM_SPOOL_INIT:
		riptr->init_subtype = WM_SPOOL_INIT;
		break;

	case WM_SPOOL_TERM:
		if (riptr->init_subtype != WM_SPOOL_INIT) {
			riptr->init_subtype = WM_SPOOL_INIT;
		}
		riptr->utime = wbuf->utime;
		riptr->stime = wbuf->stime;
		riptr->term_subtype = WM_SPOOL_TERM;
		break;

	default:
		acct_err(ACCT_CAUT,
		  _("An unknown NQ_SENT subtype (%d) was found in the '%s' routine."),
		    wbuf->subtype, "wm_spool()");
		break;
	}		/* end of switch(subtype) */

	return;
}
Ejemplo n.º 18
0
bool
insert_fprintf (struct format_val *vec,
                const struct parser_table *entry,
                char *format)
{
  char *segstart = format;
  char *fmt_editpos;       /* Current address in scanning `format'. */
  struct segment **segmentp;      /* Address of current segment. */
  struct predicate *our_pred;

  our_pred = insert_primary_withpred (entry, pred_fprintf, format);
  our_pred->side_effects = our_pred->no_default_print = true;
  our_pred->args.printf_vec = *vec;
  our_pred->need_type = false;
  our_pred->need_stat = false;
  our_pred->p_cost    = NeedsNothing;

  segmentp = &our_pred->args.printf_vec.segment;
  *segmentp = NULL;

  for (fmt_editpos = segstart; *fmt_editpos; fmt_editpos++)
    {
      if (fmt_editpos[0] == '\\' && fmt_editpos[1] == 'c')
        {
          make_segment (segmentp, segstart, fmt_editpos - segstart,
                        KIND_STOP, 0, 0,
                        our_pred);
          if (our_pred->need_stat && (our_pred->p_cost < NeedsStatInfo))
            our_pred->p_cost = NeedsStatInfo;
          return true;
        }
      else if (*fmt_editpos == '\\')
        {
          size_t readpos = 1;
          if (!fmt_editpos[readpos])
            {
              error (0, 0, _("warning: escape `\\' followed by nothing at all"));
              --readpos;
              /* (*fmt_editpos) is already '\\' and that's a reasonable result. */
            }
          else if (is_octal_char(fmt_editpos[readpos]))
            {
              size_t consumed = 0;
              *fmt_editpos = parse_octal_escape(fmt_editpos + readpos, &consumed);
              readpos += consumed;
            }
          else
            {
              const char val = parse_escape_char(fmt_editpos[readpos]);
              if (val)
                {
                  fmt_editpos[0] = val;
                }
              else
                {
                  error (0, 0, _("warning: unrecognized escape `\\%c'"),
                         fmt_editpos[readpos]);
                  fmt_editpos += readpos;
                  continue;
                }
            }
          segmentp = make_segment (segmentp,
                                   segstart, fmt_editpos - segstart + 1,
                                   KIND_PLAIN, 0, 0,
                                   our_pred);
          segstart = fmt_editpos + readpos + 1; /* Move past the escape. */
          fmt_editpos += readpos;  /* Incremented immediately by `for'. */
        }
      else if (fmt_editpos[0] == '%')
        {
          size_t len;
          if (fmt_editpos[1] == 0)
            {
              /* Trailing %.  We don't like those. */
              error (EXIT_FAILURE, 0,
                     _("error: %s at end of format string"), fmt_editpos);
            }

          if (fmt_editpos[1] == '%') /* %% produces just %. */
            len = 1;
          else
            len = get_format_flags_length(fmt_editpos);
          fmt_editpos += len;

          len = get_format_specifer_length (fmt_editpos[0]);
          if (len && (fmt_editpos[len-1]))
            {
              const char fmt2 = (len == 2) ? fmt_editpos[1] : 0;
              segmentp = make_segment (segmentp, segstart,
                                       fmt_editpos - segstart,
                                       KIND_FORMAT, fmt_editpos[0], fmt2,
                                       our_pred);
              fmt_editpos += (len - 1);
            }
          else
            {
              if (strchr ("{[(", fmt_editpos[0]))
                {
                  error (EXIT_FAILURE, 0,
                         _("error: the format directive `%%%c' is reserved for future use"),
                         (int)fmt_editpos[0]);
                  /*NOTREACHED*/
                }

              if (len == 2 && !fmt_editpos[1])
                {
                  error (0, 0,
                         _("warning: format directive `%%%c' "
                           "should be followed by another character"),
                         fmt_editpos[0]);
                }
              else
                {
                  /* An unrecognized % escape.  Print the char after the %. */
                  error (0, 0,
                         _("warning: unrecognized format directive `%%%c'"),
                         fmt_editpos[0]);
                }
              segmentp = make_segment (segmentp,
                                       segstart, fmt_editpos + 1 - segstart,
                                       KIND_PLAIN, 0, 0,
                                       our_pred);
            }
          segstart = fmt_editpos + 1;
        }
    }

  if (fmt_editpos > segstart)
    make_segment (segmentp, segstart, fmt_editpos - segstart, KIND_PLAIN, 0, 0,
                  our_pred);
  return true;
}
Ejemplo n.º 19
0
static char *parser_get_next_value(char *line, char **end, icalvalue_kind kind)
{
    char *next = 0;
    char *p;
    char *str;
    size_t length = strlen(line);
    int quoted = 0;

    if (line[0] == '\"' && line[length - 1] == '\"') {
        /* This line is quoted, don't split into multiple values */
        quoted = 1;
    }

    p = line;
    while (!quoted) {

        next = parser_get_next_char(',', p, 1);

        /* Unforunately, RFC2445 allowed that for the RECUR value, COMMA
           could both separate digits in a list, and it could separate
           multiple recurrence specifications. This is not a friendly
           part of the spec and was deprecated in RFC5545. The following
           weirdness tries to distinguish the two uses. It is probably a HACK */

        if (kind == ICAL_RECUR_VALUE) {
            if (next != 0 && (*end + length) > next + 5 && strncmp(next, "FREQ", 4) == 0) {
                /* The COMMA was followed by 'FREQ', is it a real separator */
                /* Fall through */
            } else if (next != 0) {
                /* Not real, get the next COMMA */
                p = next + 1;
                next = 0;
                continue;
            }
        }
        /* ignore all , for query value. select dtstart, dtend etc ... */
        else if (kind == ICAL_QUERY_VALUE) {
            if (next != 0) {
                p = next + 1;
                continue;
            } else {
                break;
            }
        }

        /* If the comma is preceded by a '\', then it is a literal and
           not a value separator */

        if ((next != 0 && *(next - 1) == '\\') || (next != 0 && *(next - 3) == '\\')
            )
            /*second clause for '/' is on prev line. HACK may be out of bounds */
        {
            p = next + 1;
        } else {
            break;
        }
    }

    if (next == 0) {
        next = (char *)(size_t) line + length;
        *end = next;
    } else {
        *end = next + 1;
    }

    if (next == line) {
        return 0;
    }

    str = make_segment(line, next);
    return str;
}