Exemple #1
0
/*  Again like strdup but it concatinates and free's and uses Realloc
*/
PUBLIC char *
NET_SACat (char **destination, const char *source)
{
    if (source && *source)
      {
        if (*destination)
          {
            int length = XP_STRLEN (*destination);
            *destination = (char *) XP_REALLOC (*destination, length + XP_STRLEN(source) + 1);
            if (*destination == NULL)
            return(NULL);

            XP_STRCPY (*destination + length, source);
          }
        else
          {
            *destination = (char *) XP_ALLOC (XP_STRLEN(source) + 1);
            if (*destination == NULL)
                return(NULL);

             XP_STRCPY (*destination, source);
          }
      }
    return *destination;
}
Exemple #2
0
/*	binary block Allocate and Concatenate
 *
 *   destination_length  is the length of the existing block
 *   source_length   is the length of the block being added to the 
 *   destination block
 */
PUBLIC char * 
NET_BACat (char **destination, 
		   size_t destination_length, 
		   const char *source, 
		   size_t source_length)
{
    if (source) 
	  {
        if (*destination) 
	      {
      	    *destination = (char *) XP_REALLOC (*destination, destination_length + source_length);
            if (*destination == NULL) 
	          return(NULL);

            XP_MEMMOVE (*destination + destination_length, source, source_length);

          } 
		else 
		  {
            *destination = (char *) XP_ALLOC (source_length);
            if (*destination == NULL) 
	          return(NULL);

            XP_MEMCPY(*destination, source, source_length);
          }
    }

  return *destination;
}
Exemple #3
0
/*
 * Appends the name/value list in count2, names2, and values2 on
 * to the name/value list in count1, names1, and values1.
 */
void
lo_AppendParamList(uint32* count1, char*** names1, char*** values1,
				   uint32 count2, char** names2, char** values2)
{		
	char** names = NULL;
	char** values = NULL;
	
	if (*names1 != NULL)
	{
		if (names2 != NULL)
		{
			names = (char**) XP_REALLOC(*names1, ((*count1 + count2) * sizeof(char*)));
			if (names != NULL)
				XP_MEMCPY(&(names[*count1]), names2, count2 * sizeof(char*));
		}
		else
			names = *names1;
	}
	else
		names = names2;
		
	if (*values1 != NULL)
	{
		if (values2 != NULL)
		{
			values = (char**) XP_REALLOC(*values1, ((*count1 + count2) * sizeof(char*)));
			if (values != NULL)
				XP_MEMCPY(&(values[*count1]), values2, count2 * sizeof(char*));
		}
		else
			values = *values1;
	}
	else
		values = values2;
		
	if (names != NULL && values != NULL)
	{
		*count1 = *count1 + count2;
		*names1 = names;
		*values1 = values;
	}
}
Exemple #4
0
void main()
{
    int ch;
    char *b;
    int32 src_count;
    char *dst;
    int32 dst_count;
    char * src;
    int src_size;
    int done;

        
    done = ch = 0;
    src_size = src_count = 0;

    src = (char *) XP_ALLOC(TEST_CSS_INITIAL_BUFSIZ);
    if (src) src_size = TEST_CSS_INITIAL_BUFSIZ;

    while (!done) {

        for (b = src + src_count; src_count < src_size; src_count++, b++) {
            *b = ch = getc(stdin);
            /* Either the null character or EOF will serve to terminate. */
            if (ch == EOF || ch == '\0') {
                done = 1;
                /* We don't need to add this character to the src_count */
                break;
            }
        }

        if (!done) {
            src_size += TEST_CSS_INCR_BUFSIZ;
            src = (char *) XP_REALLOC(src, src_size);
            if (!src) {
                src_size = src_count = 0;
                printf("css test: memory allocation failure\n");
                done = 1;
            }
        }
    }

    /* The src_count need not include the terminating NULL or EOF */
    CSS_ConvertToJS(src, src_count, &dst, &dst_count);
    printf("%s", dst);
    XP_FREE(dst);
}
/*  Buffer write.  
**  ------------
*/
extern "C"  int 
memory_stream_write (NET_StreamClass *stream, const char* s, int32 l)
{
    DataObject * data = (DataObject *)stream->data_object;	

    ASSERT(data);
    ASSERT(s);

    if(!data || !data->start || !data->loc)
        return(MK_OUT_OF_MEMORY);

    /* check the sizes - make bigger and recopy if needed */
    if(((unsigned long)(data->loc - data->start))  + l > (unsigned long)data->sz) {
    char * buffer;
        int oldcontents = data->loc - data->start;

        data->sz += DEFAULT_BUFFER_SZ;
        buffer = (char *) XP_REALLOC(data->start, data->sz);
        if(!buffer) {
          XP_FREE(data->start);
          data->start = NULL;
          data->loc = NULL;
          return(MK_OUT_OF_MEMORY);
        }
          
        data->start = buffer;
        data->loc = data->start + oldcontents;     
    }
    
    /* copy the stuff over and update the pointer */
    XP_BCOPY(s, data->loc, l);
    data->loc += l;

    data->cur_loc += l;

    float fPercent = 0.0f;

    if (data->content_length) 
        fPercent = (float)data->cur_loc / (float)data->content_length;
    if (data->cur_loc) 
        FE_SetProgressBarPercent(data->context, (int)(fPercent * 100));

    return((int) l);
}
Exemple #6
0
char *XP_AppendStr(char *in, const char *append)
{
    int alen, inlen;

    alen = XP_STRLEN(append);
    if (in) {
		inlen = XP_STRLEN(in);
		in = (char*) XP_REALLOC(in,inlen+alen+1);
		if (in) {
			XP_MEMCPY(in+inlen, append, alen+1);
		}
    } else {
		in = (char*) XP_ALLOC(alen+1);
		if (in) {
			XP_MEMCPY(in, append, alen+1);
		}
    }
    return in;
}
Exemple #7
0
static void StyleBufferWrite(char * str, int len, StyleBuffer sb)
{

    if (str == NULL)
        return;

    if (len <= 0) {
        len = strlen(str);
        if (len <= 0)
            return;
    }

    if (sb->buffer == NULL) {
        sb->buffer = (char *) XP_ALLOC(STYLE_INITIAL_BUFSIZ);
        if (sb->buffer) {
            sb->buffer_size = STYLE_INITIAL_BUFSIZ;
            *sb->buffer = '\0';
            sb->buffer_count = 1;
        }
    }

    if (sb->buffer_count + len > sb->buffer_size) {
        sb->buffer = (char *)
            XP_REALLOC(sb->buffer, sb->buffer_size + STYLE_INCR_BUFSIZ);
        if (sb->buffer) {
            sb->buffer_size += STYLE_INCR_BUFSIZ;
        } else {
            sb->buffer_size = sb->buffer_count = 0;
        }
    }

    if (sb->buffer_count + len <= sb->buffer_size) {
        (void) strncpy(sb->buffer + sb->buffer_count - 1, str, len);
        sb->buffer_count += len;
        sb->buffer[sb->buffer_count-1] = '\0';
    }
}
Exemple #8
0
// tooltips and doc string
char *XFE_AddrBookView::getDocString(CommandType cmd)
{
	uint32 count = 0;
	const int *indices = 0;
	m_outliner->getSelection(&indices, (int *) &count);

	if (count > 0) {
		char *names = 0;
		char a_line[512];
		a_line[0] = '\0';
		int len = 0;
		for (int i=0; i < count && len < 512; i++) {
			/* Take the first one 
			 */
#if defined(USE_ABCOM)
			AB_AttributeValue *value = NULL;
			int error = 
				AB_GetEntryAttributeForPane(m_pane,
											(MSG_ViewIndex) indices[i],
											AB_attribFullName,
											&value);
			XP_ASSERT(value && value->attrib == AB_attribFullName);

			XP_SAFE_SPRINTF(a_line, sizeof(a_line),
							"%s",
							value->u.string?value->u.string:"");
			AB_FreeEntryAttributeValue(value);
#else
			ABID entry;		
			entry = AB_GetEntryIDAt((AddressPane *) m_abPane, 
									(uint32) indices[i]);
			AB_GetFullName(m_dir, m_AddrBook, entry, a_line);
#endif /* USE_ABCOM */
			if (a_line) {
				len += XP_STRLEN(a_line);
				if (i)
					len += 2;

				names = names?
					((char *) XP_REALLOC(names, (len+1)*sizeof(char))):
					((char *) XP_CALLOC(1+len, sizeof(char)));

				if (i)
					names = XP_STRCAT(names, ", ");
				names = XP_STRCAT(names, a_line);			
			}/* if */
		}/* for i */

		char *cstr = 0;
		if (cmd == xfeCmdComposeMessage ||
			cmd == xfeCmdComposeMessageHTML ||
			cmd == xfeCmdComposeMessagePlain) {
			cstr = XP_STRDUP(XP_GetString(XFE_SEND_MSG_TO));	
		} else if (cmd == xfeCmdABCall) {
			cstr = XP_STRDUP(XP_GetString(XFE_PLACE_CONFERENCE_CALL_TO));
		}
		len += XP_STRLEN(cstr);
		cstr = (char *) XP_REALLOC(cstr, (1+len)*sizeof(char));
		cstr = (char *) XP_STRCAT(cstr, names);
		return cstr;
	}/* if */
	return NULL;
}
Exemple #9
0
/* 
 * Takes a "PARAM" tag and pointers to the object's attribute
 * count, attribute name array, and attribute value array.
 * Parses the name and value of the PARAM and adjusts the
 * attribute count, names, and values accordingly.
 */
void
lo_ObjectParam(MWContext* context, lo_DocState* state, PA_Tag* tag,
			   uint32* count, char*** names, char*** values)
{
	PA_Block buff;
	char *str;
	char *param_name = NULL;
	char *param_value = NULL;
	char **name_list;
	char **value_list;
	
	/*
	 * Get the name of this parameter.
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_NAME);
	if (buff != NULL)
	{
		PA_LOCK(str, char *, buff);
		if (str != NULL)
		{
			int32 len;
			char *new_str;

			len = lo_StripTextWhitespace(str, XP_STRLEN(str));
			new_str = (char *)XP_ALLOC(len + 1);
			if (new_str != NULL)
			{
				XP_STRCPY(new_str, str);
			}
			param_name = new_str;
		}
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}
	else
	{
		/* If we don't have a parameter name, it's useless */
		return;
	}

	/*
	 * Get the value of this parameter.
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_VALUE);
	if (buff != NULL)
	{
		PA_LOCK(str, char *, buff);
		if (str != NULL)
		{
			int32 len;
			char *new_str;

			len = lo_StripTextWhitespace(str, XP_STRLEN(str));
			new_str = (char *)XP_ALLOC(len + 1);
			if (new_str != NULL)
			{
				XP_STRCPY(new_str, str);
			}
			param_value = new_str;
		}
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}

	/*
	 * Add the parameter to the name/value list.
	 */
	if (*names == NULL)
		name_list = (char **)XP_ALLOC(sizeof(char *));
	else
		name_list = (char **)XP_REALLOC(*names,
						((*count + 1) * sizeof(char *)));
	
	/*
	 * If we run out of memory here, free up what
	 * we can and return.
	 */
	if (name_list == NULL)
	{
		state->top_state->out_of_memory = TRUE;
		XP_FREE(param_name);
		if (param_value != NULL)
			XP_FREE(param_value);
		return;
	}

	if (*values == NULL)
		value_list = (char **)XP_ALLOC(sizeof(char *));
	else
		value_list = (char **)XP_REALLOC(*values,
						((*count + 1) * sizeof(char *)));

	/*
	 * If we run out of memory here, free up what
	 * we can and return.
	 */
	if (value_list == NULL)
	{
		state->top_state->out_of_memory = TRUE;
		XP_FREE(param_name);
		if (param_value != NULL)
			XP_FREE(param_value);
		return;
	}
	
	*names = name_list;
	*values = value_list;
	(*names)[*count] = param_name;
	(*values)[*count] = param_value;
	(*count)++;

}