mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-30 08:00:51 +00:00
whitespace
This commit is contained in:
parent
d00d6a539a
commit
5a30278e77
1 changed files with 37 additions and 31 deletions
|
@ -26,6 +26,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
|
|
||||||
"$Id$";
|
"$Id$";
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -35,12 +36,13 @@ static const char rcsid[] =
|
||||||
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|
||||||
dstring_t *
|
dstring_t *
|
||||||
dstring_new (void)
|
dstring_new (void)
|
||||||
{
|
{
|
||||||
dstring_t *new;
|
dstring_t *new;
|
||||||
|
|
||||||
new = calloc (1, sizeof(dstring_t));
|
new = calloc (1, sizeof (dstring_t));
|
||||||
|
|
||||||
if (!new)
|
if (!new)
|
||||||
Sys_Error ("dstring_new: Failed to allocate memory.\n");
|
Sys_Error ("dstring_new: Failed to allocate memory.\n");
|
||||||
return new;
|
return new;
|
||||||
|
@ -53,12 +55,12 @@ dstring_delete (dstring_t *dstr)
|
||||||
free (dstr->str);
|
free (dstr->str);
|
||||||
free (dstr);
|
free (dstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dstring_adjust (dstring_t *dstr)
|
dstring_adjust (dstring_t *dstr)
|
||||||
{
|
{
|
||||||
if (dstr->size > dstr->truesize) {
|
if (dstr->size > dstr->truesize) {
|
||||||
dstr->str = realloc(dstr->str, dstr->size);
|
dstr->str = realloc (dstr->str, dstr->size);
|
||||||
if (!dstr->str)
|
if (!dstr->str)
|
||||||
Sys_Error ("dstring_adjust: Failed to reallocate memory.\n");
|
Sys_Error ("dstring_adjust: Failed to reallocate memory.\n");
|
||||||
dstr->truesize = dstr->size;
|
dstr->truesize = dstr->size;
|
||||||
|
@ -68,8 +70,8 @@ dstring_adjust (dstring_t *dstr)
|
||||||
void
|
void
|
||||||
dstring_append (dstring_t *dstr, const char *data, unsigned int len)
|
dstring_append (dstring_t *dstr, const char *data, unsigned int len)
|
||||||
{
|
{
|
||||||
unsigned int ins = dstr->size; // Save insertion point
|
unsigned int ins = dstr->size; // Save insertion point
|
||||||
|
|
||||||
dstr->size += len;
|
dstr->size += len;
|
||||||
dstring_adjust (dstr);
|
dstring_adjust (dstr);
|
||||||
memcpy (dstr->str + ins, data, len);
|
memcpy (dstr->str + ins, data, len);
|
||||||
|
@ -80,17 +82,17 @@ dstring_insert (dstring_t *dstr, const char *data, unsigned int len,
|
||||||
unsigned int pos)
|
unsigned int pos)
|
||||||
{
|
{
|
||||||
unsigned int oldsize = dstr->size;
|
unsigned int oldsize = dstr->size;
|
||||||
|
|
||||||
dstr->size += len;
|
dstr->size += len;
|
||||||
dstring_adjust (dstr);
|
dstring_adjust (dstr);
|
||||||
memmove (dstr->str+pos+len, dstr->str+pos, oldsize - pos);
|
memmove (dstr->str + pos + len, dstr->str + pos, oldsize - pos);
|
||||||
memcpy (dstr->str+pos, data, len);
|
memcpy (dstr->str + pos, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dstring_snip (dstring_t *dstr, unsigned int pos, unsigned int len)
|
dstring_snip (dstring_t *dstr, unsigned int pos, unsigned int len)
|
||||||
{
|
{
|
||||||
memmove (dstr->str+pos, dstr->str+pos+len, dstr->size-pos-len);
|
memmove (dstr->str + pos, dstr->str + pos + len, dstr->size - pos - len);
|
||||||
dstr->size -= len;
|
dstr->size -= len;
|
||||||
dstring_adjust (dstr);
|
dstring_adjust (dstr);
|
||||||
}
|
}
|
||||||
|
@ -102,50 +104,54 @@ dstring_clear (dstring_t *dstr)
|
||||||
dstring_adjust (dstr);
|
dstring_adjust (dstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
dstring_t *
|
dstring_t *
|
||||||
dstring_newstr (void)
|
dstring_newstr (void)
|
||||||
{
|
{
|
||||||
dstring_t *new;
|
dstring_t *new;
|
||||||
|
|
||||||
new = calloc(1, sizeof(dstring_t));
|
new = calloc (1, sizeof (dstring_t));
|
||||||
|
|
||||||
if (!new)
|
if (!new)
|
||||||
Sys_Error ("dstring_newstr: Failed to allocate memory.\n");
|
Sys_Error ("dstring_newstr: Failed to allocate memory.\n");
|
||||||
new->size = 1;
|
new->size = 1;
|
||||||
dstring_adjust(new);
|
dstring_adjust (new);
|
||||||
new->str[0] = 0;
|
new->str[0] = 0;
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dstring_appendstr (dstring_t *dstr, const char *str) {
|
dstring_appendstr (dstring_t *dstr, const char *str)
|
||||||
dstr->size += strlen(str);
|
{
|
||||||
dstring_adjust(dstr);
|
dstr->size += strlen (str);
|
||||||
strcat(dstr->str, str);
|
dstring_adjust (dstr);
|
||||||
|
strcat (dstr->str, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len) {
|
dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len)
|
||||||
unsigned int l = strlen (str);
|
{
|
||||||
if (len > l)
|
unsigned int l = strlen (str);
|
||||||
len = l;
|
|
||||||
dstr->size += len;
|
if (len > l)
|
||||||
dstring_adjust(dstr);
|
len = l;
|
||||||
strncat(dstr->str, str, len);
|
dstr->size += len;
|
||||||
|
dstring_adjust (dstr);
|
||||||
|
strncat (dstr->str, str, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dstring_insertstr (dstring_t *dstr, const char *str, unsigned int pos)
|
dstring_insertstr (dstring_t *dstr, const char *str, unsigned int pos)
|
||||||
{
|
{
|
||||||
// Don't insert strlen + 1 to achieve concatenation
|
// Don't insert strlen + 1 to achieve concatenation
|
||||||
dstring_insert (dstr, str, strlen(str), pos);
|
dstring_insert (dstr, str, strlen (str), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dstring_insertsubstr (dstring_t *dstr, const char *str, unsigned int pos,
|
dstring_insertsubstr (dstring_t *dstr, const char *str, unsigned int pos,
|
||||||
unsigned int len)
|
unsigned int len)
|
||||||
{
|
{
|
||||||
// Don't insert strlen + 1 to achieve concatenation
|
|
||||||
unsigned int l = strlen (str);
|
unsigned int l = strlen (str);
|
||||||
|
|
||||||
if (len > l)
|
if (len > l)
|
||||||
len = l;
|
len = l;
|
||||||
dstring_insert (dstr, str, len, pos);
|
dstring_insert (dstr, str, len, pos);
|
||||||
|
@ -167,7 +173,7 @@ dvsprintf (dstring_t *dstr, const char *fmt, va_list args)
|
||||||
size = vsnprintf (dstr->str, dstr->truesize, fmt, args) + 1; // +1 for nul
|
size = vsnprintf (dstr->str, dstr->truesize, fmt, args) + 1; // +1 for nul
|
||||||
while (size <= 0 || size > dstr->truesize) {
|
while (size <= 0 || size > dstr->truesize) {
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
dstr->size = (size + 1023) & ~1023; // 1k multiples
|
dstr->size = (size + 1023) & ~1023; // 1k multiples
|
||||||
else
|
else
|
||||||
dstr->size = dstr->truesize + 1024;
|
dstr->size = dstr->truesize + 1024;
|
||||||
dstring_adjust (dstr);
|
dstring_adjust (dstr);
|
||||||
|
|
Loading…
Reference in a new issue