Back to index

cell-binutils  2.17cvs20070401
Functions | Variables
sb.c File Reference
#include "as.h"
#include "sb.h"

Go to the source code of this file.

Functions

static void sb_check (sb *, int)
static void sb_build (sb *ptr, int size)
void sb_new (sb *ptr)
void sb_kill (sb *ptr)
void sb_add_sb (sb *ptr, sb *s)
static int scrub_from_sb (char *buf, int buflen)
void sb_scrub_and_add_sb (sb *ptr, sb *s)
void sb_reset (sb *ptr)
void sb_add_char (sb *ptr, int c)
void sb_add_string (sb *ptr, const char *s)
void sb_add_buffer (sb *ptr, const char *s, int len)
char * sb_terminate (sb *in)
int sb_skip_white (int idx, sb *ptr)
int sb_skip_comma (int idx, sb *ptr)

Variables

static int dsize = 5
static int string_count [sb_max_power_two]
struct {
sb_elementsize [sb_max_power_two]
free_list
static sbsb_to_scrub
static char * scrub_position

Function Documentation

void sb_add_buffer ( sb ptr,
const char *  s,
int  len 
)

Definition at line 193 of file sb.c.

{
  sb_check (ptr, len);
  memcpy (ptr->ptr + ptr->len, s, len);
  ptr->len += len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sb_add_char ( sb ptr,
int  c 
)

Definition at line 173 of file sb.c.

{
  sb_check (ptr, 1);
  ptr->ptr[ptr->len++] = c;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sb_add_sb ( sb ptr,
sb s 
)

Definition at line 103 of file sb.c.

{
  sb_check (ptr, s->len);
  memcpy (ptr->ptr + ptr->len, s->ptr, s->len);
  ptr->len += s->len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sb_add_string ( sb ptr,
const char *  s 
)

Definition at line 182 of file sb.c.

{
  int len = strlen (s);
  sb_check (ptr, len);
  memcpy (ptr->ptr + ptr->len, s, len);
  ptr->len += len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void sb_build ( sb ptr,
int  size 
) [static]

Definition at line 56 of file sb.c.

{
  /* See if we can find one to allocate.  */
  sb_element *e;

  assert (size < sb_max_power_two);

  e = free_list.size[size];
  if (!e)
    {
      /* Nothing there, allocate one and stick into the free list.  */
      e = (sb_element *) xmalloc (sizeof (sb_element) + (1 << size));
      e->next = free_list.size[size];
      e->size = 1 << size;
      free_list.size[size] = e;
      string_count[size]++;
    }

  /* Remove from free list.  */
  free_list.size[size] = e->next;

  /* Copy into callers world.  */
  ptr->ptr = e->data;
  ptr->pot = size;
  ptr->len = 0;
  ptr->item = e;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void sb_check ( sb ptr,
int  len 
) [static]

Definition at line 146 of file sb.c.

{
  if (ptr->len + len >= 1 << ptr->pot)
    {
      sb tmp;
      int pot = ptr->pot;

      while (ptr->len + len >= 1 << pot)
       pot++;
      sb_build (&tmp, pot);
      sb_add_sb (&tmp, ptr);
      sb_kill (ptr);
      *ptr = tmp;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sb_kill ( sb ptr)

Definition at line 93 of file sb.c.

{
  /* Return item to free list.  */
  ptr->item->next = free_list.size[ptr->pot];
  free_list.size[ptr->pot] = ptr->item;
}

Here is the caller graph for this function:

void sb_new ( sb ptr)

Definition at line 85 of file sb.c.

{
  sb_build (ptr, dsize);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sb_reset ( sb ptr)

Definition at line 165 of file sb.c.

{
  ptr->len = 0;
}

Here is the caller graph for this function:

void sb_scrub_and_add_sb ( sb ptr,
sb s 
)

Definition at line 130 of file sb.c.

{
  sb_to_scrub = s;
  scrub_position = s->ptr;
  
  sb_check (ptr, s->len);
  ptr->len += do_scrub_chars (scrub_from_sb, ptr->ptr + ptr->len, s->len);

  sb_to_scrub = 0;
  scrub_position = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sb_skip_comma ( int  idx,
sb ptr 
)

Definition at line 228 of file sb.c.

{
  while (idx < ptr->len
        && (ptr->ptr[idx] == ' '
            || ptr->ptr[idx] == '\t'))
    idx++;

  if (idx < ptr->len
      && ptr->ptr[idx] == ',')
    idx++;

  while (idx < ptr->len
        && (ptr->ptr[idx] == ' '
            || ptr->ptr[idx] == '\t'))
    idx++;

  return idx;
}

Here is the caller graph for this function:

int sb_skip_white ( int  idx,
sb ptr 
)

Definition at line 214 of file sb.c.

{
  while (idx < ptr->len
        && (ptr->ptr[idx] == ' '
            || ptr->ptr[idx] == '\t'))
    idx++;
  return idx;
}

Here is the caller graph for this function:

char* sb_terminate ( sb in)

Definition at line 203 of file sb.c.

{
  sb_add_char (in, 0);
  --in->len;
  return in->ptr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int scrub_from_sb ( char *  buf,
int  buflen 
) [static]

Definition at line 115 of file sb.c.

{
  int copy;
  copy = sb_to_scrub->len - (scrub_position - sb_to_scrub->ptr);
  if (copy > buflen)
    copy = buflen;
  memcpy (buf, scrub_position, copy);
  scrub_position += copy;
  return copy;
}

Here is the caller graph for this function:


Variable Documentation

int dsize = 5 [static]

Definition at line 41 of file sb.c.

struct { ... } free_list [static]
sb* sb_to_scrub [static]

Definition at line 112 of file sb.c.

char* scrub_position [static]

Definition at line 113 of file sb.c.

Definition at line 45 of file sb.c.