Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Typedefs | Functions
dyn-string.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dyn_string

Defines

#define dyn_string_length(STR)   ((STR)->length)
#define dyn_string_buf(STR)   ((STR)->s)
#define dyn_string_compare(DS1, DS2)   (strcmp ((DS1)->s, (DS2)->s))

Typedefs

typedef struct dyn_stringdyn_string_t

Functions

int dyn_string_init (struct dyn_string *, int)
dyn_string_t dyn_string_new (int)
void dyn_string_delete (dyn_string_t)
char * dyn_string_release (dyn_string_t)
dyn_string_t dyn_string_resize (dyn_string_t, int)
void dyn_string_clear (dyn_string_t)
int dyn_string_copy (dyn_string_t, dyn_string_t)
int dyn_string_copy_cstr (dyn_string_t, const char *)
int dyn_string_prepend (dyn_string_t, dyn_string_t)
int dyn_string_prepend_cstr (dyn_string_t, const char *)
int dyn_string_insert (dyn_string_t, int, dyn_string_t)
int dyn_string_insert_cstr (dyn_string_t, int, const char *)
int dyn_string_insert_char (dyn_string_t, int, int)
int dyn_string_append (dyn_string_t, dyn_string_t)
int dyn_string_append_cstr (dyn_string_t, const char *)
int dyn_string_append_char (dyn_string_t, int)
int dyn_string_substring (dyn_string_t, dyn_string_t, int, int)
int dyn_string_eq (dyn_string_t, dyn_string_t)

Class Documentation

struct dyn_string

Definition at line 23 of file dyn-string.h.

Class Members
int allocated
int length
char * s

Define Documentation

#define dyn_string_buf (   STR)    ((STR)->s)

Definition at line 35 of file dyn-string.h.

#define dyn_string_compare (   DS1,
  DS2 
)    (strcmp ((DS1)->s, (DS2)->s))

Definition at line 39 of file dyn-string.h.

#define dyn_string_length (   STR)    ((STR)->length)

Definition at line 31 of file dyn-string.h.


Typedef Documentation


Function Documentation

Definition at line 312 of file dyn-string.c.

{
  if (dyn_string_resize (dest, dest->length + s->length) == 0)
    return 0;
  strcpy (dest->s + dest->length, s->s);
  dest->length += s->length;
  return 1;
}

Here is the call graph for this function:

Definition at line 343 of file dyn-string.c.

{
  /* Make room for the extra character.  */
  if (dyn_string_resize (dest, dest->length + 1) == NULL)
    return 0;
  /* Append the character; it will overwrite the old NUL.  */
  dest->s[dest->length] = c;
  /* Add a new NUL at the end.  */
  dest->s[dest->length + 1] = '\0';
  /* Update the length.  */
  ++(dest->length);
  return 1;
}

Here is the call graph for this function:

Definition at line 326 of file dyn-string.c.

{
  int len = strlen (s);

  /* The new length is the old length plus the size of our string, plus
     one for the null at the end.  */
  if (dyn_string_resize (dest, dest->length + len) == NULL)
    return 0;
  strcpy (dest->s + dest->length, s);
  dest->length += len;
  return 1;
}

Here is the call graph for this function:

Definition at line 172 of file dyn-string.c.

{
  /* A dyn_string always has room for at least the NUL terminator.  */
  ds->s[0] = '\0';
  ds->length = 0;
}

Definition at line 184 of file dyn-string.c.

{
  if (dest == src)
    abort ();

  /* Make room in DEST.  */
  if (dyn_string_resize (dest, src->length) == NULL)
    return 0;
  /* Copy DEST into SRC.  */
  strcpy (dest->s, src->s);
  /* Update the size of DEST.  */
  dest->length = src->length;
  return 1;
}

Here is the call graph for this function:

Definition at line 204 of file dyn-string.c.

{
  int length = strlen (src);
  /* Make room in DEST.  */
  if (dyn_string_resize (dest, length) == NULL)
    return 0;
  /* Copy DEST into SRC.  */
  strcpy (dest->s, src);
  /* Update the size of DEST.  */
  dest->length = length;
  return 1;
}

Here is the call graph for this function:

Definition at line 108 of file dyn-string.c.

{
  free (ds->s);
  free (ds);
}

Here is the call graph for this function:

Definition at line 390 of file dyn-string.c.

{
  /* If DS1 and DS2 have different lengths, they must not be the same.  */
  if (ds1->length != ds2->length)
    return 0;
  else
    return !strcmp (ds1->s, ds2->s);
}

Here is the call graph for this function:

Definition at line 59 of file dyn-string.c.

{
  /* We need at least one byte in which to store the terminating NUL.  */
  if (space == 0)
    space = 1;

#ifdef RETURN_ON_ALLOCATION_FAILURE
  ds_struct_ptr->s = (char *) malloc (space);
  if (ds_struct_ptr->s == NULL)
    return 0;
#else
  ds_struct_ptr->s = XNEWVEC (char, space);
#endif
  ds_struct_ptr->allocated = space;
  ds_struct_ptr->length = 0;
  ds_struct_ptr->s[0] = '\0';

  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 244 of file dyn-string.c.

{
  int i;

  if (src == dest)
    abort ();

  if (dyn_string_resize (dest, dest->length + src->length) == NULL)
    return 0;
  /* Make room for the insertion.  Be sure to copy the NUL.  */
  for (i = dest->length; i >= pos; --i)
    dest->s[i + src->length] = dest->s[i];
  /* Splice in the new stuff.  */
  strncpy (dest->s + pos, src->s, src->length);
  /* Compute the new length.  */
  dest->length += src->length;
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 291 of file dyn-string.c.

{
  int i;

  if (dyn_string_resize (dest, dest->length + 1) == NULL)
    return 0;
  /* Make room for the insertion.  Be sure to copy the NUL.  */
  for (i = dest->length; i >= pos; --i)
    dest->s[i + 1] = dest->s[i];
  /* Add the new character.  */
  dest->s[pos] = c;
  /* Compute the new length.  */
  ++dest->length;
  return 1;
}

Here is the call graph for this function:

int dyn_string_insert_cstr ( dyn_string_t  ,
int  ,
const char *   
)

Definition at line 269 of file dyn-string.c.

{
  int i;
  int length = strlen (src);

  if (dyn_string_resize (dest, dest->length + length) == NULL)
    return 0;
  /* Make room for the insertion.  Be sure to copy the NUL.  */
  for (i = dest->length; i >= pos; --i)
    dest->s[i + length] = dest->s[i];
  /* Splice in the new stuff.  */
  strncpy (dest->s + pos, src, length);
  /* Compute the new length.  */
  dest->length += length;
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 86 of file dyn-string.c.

{
  dyn_string_t result;
#ifdef RETURN_ON_ALLOCATION_FAILURE
  result = (dyn_string_t) malloc (sizeof (struct dyn_string));
  if (result == NULL)
    return NULL;
  if (!dyn_string_init (result, space))
    {
      free (result);
      return NULL;
    }
#else
  result = XNEW (struct dyn_string);
  dyn_string_init (result, space);
#endif
  return result;
}

Here is the call graph for this function:

Definition at line 223 of file dyn-string.c.

{
  return dyn_string_insert (dest, 0, src);
}

Here is the call graph for this function:

Definition at line 233 of file dyn-string.c.

{
  return dyn_string_insert_cstr (dest, 0, src);
}

Here is the call graph for this function:

Definition at line 119 of file dyn-string.c.

{
  /* Store the old buffer.  */
  char* result = ds->s;
  /* The buffer is no longer owned by DS.  */
  ds->s = NULL;
  /* Delete DS.  */
  free (ds);
  /* Return the old buffer.  */
  return result;
}

Here is the call graph for this function:

Definition at line 139 of file dyn-string.c.

{
  int new_allocated = ds->allocated;

  /* Increase SPACE to hold the NUL termination.  */
  ++space;

  /* Increase allocation by factors of two.  */
  while (space > new_allocated)
    new_allocated *= 2;
    
  if (new_allocated != ds->allocated)
    {
      ds->allocated = new_allocated;
      /* We actually need more space.  */
#ifdef RETURN_ON_ALLOCATION_FAILURE
      ds->s = (char *) realloc (ds->s, ds->allocated);
      if (ds->s == NULL)
       {
         free (ds);
         return NULL;
       }
#else
      ds->s = XRESIZEVEC (char, ds->s, ds->allocated);
#endif
    }

  return ds;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 364 of file dyn-string.c.

{
  int i;
  int length = end - start;

  if (start > end || start > src->length || end > src->length)
    abort ();

  /* Make room for the substring.  */
  if (dyn_string_resize (dest, length) == NULL)
    return 0;
  /* Copy the characters in the substring,  */
  for (i = length; --i >= 0; )
    dest->s[i] = src->s[start + i];
  /* NUL-terimate the result.  */
  dest->s[length] = '\0';
  /* Record the length of the substring.  */
  dest->length = length;

  return 1;
}

Here is the call graph for this function: