Example #1
0
int (list_insert_after) (
                        SCL_list_t     a_list,
                        SCL_iterator_t a_iterator,
                        const void*    a_data
                        )
   {
   S_SCL_list_t* const list = a_list;
   S_node_t* ilink = (S_node_t*)a_iterator;
   S_node_t* node;

   if (ilink == list->tail) return list_push_back (a_list, a_data);

   node = SCL_ALLOCATOR (sizeof(S_node_t));
   if (node == NULL) return SCL_NOMEM;

   node->data = a_data;
   PRED(node) = ilink;
   SUCC(node) = SUCC(ilink);

   PRED(SUCC(ilink)) = node;
   SUCC(ilink) = node;

   list->count += 1;

   return SCL_OK;
   }
Example #2
0
int (list_insert) (SCL_list_t a_list, size_t a_index, const void* a_data)
   {
   S_SCL_list_t* const list = a_list;
   S_node_t* ilink = list->head;
   S_node_t* node;

   if (a_index == 0) return list_push_front (a_list, a_data);
   if (a_index == a_list->count) return list_push_back (a_list, a_data);
   if (a_index > a_list->count) return SCL_NOTFOUND;

   node = SCL_ALLOCATOR (sizeof(S_node_t));
   if (node == NULL) return SCL_NOMEM;

   node->data = a_data;

   while (--a_index > 0) ilink = SUCC(ilink);

   PRED(node) = ilink;
   SUCC(node) = SUCC(ilink);
   PRED(SUCC(ilink)) = node;
   SUCC(ilink) = node;

   list->count += 1;

   return SCL_OK;
   }
Example #3
0
SCL_stackbuf_t (stackbuf_new) (
                              SCL_getfn_t a_getfn,
                              SCL_putfn_t a_putfn,
                              size_t      a_len
                              )
   {
   S_SCL_stackbuf_t* const s = SCL_ALLOCATOR (sizeof(S_SCL_stackbuf_t));

   s->getfn = a_getfn;
   s->putfn = a_putfn;
   s->blen = sizeof(S_block_t) + a_len;

   return s;
   }
Example #4
0
int (stackbuf_pull_alloc) (
                          SCL_stackbuf_t a_stackbuf,
                          void** a_data,
                          size_t a_len
                          )
   {
   int count = 0;
   S_block_t* block;
   size_t blen;
   char* dst;
   const char* src;

   dst = SCL_ALLOCATOR (a_len);
   if (dst == NULL) return SCL_NOMEM;
   *a_data = dst;

   while (a_len > 0)
      {
      block = a_stackbuf->block;

      if (block == NULL)
         {
         block = (*a_stackbuf->getfn) (a_stackbuf->blen);
         if (block == NULL) return count;
         a_stackbuf->block = (S_block_t*)block;
         a_stackbuf->nin += 1;
         }

      blen = block->size;
      src = &block->data[blen];

      while ((blen > 0) && (a_len > 0))
         {
         *dst++ = *--src;
         blen  -= 1;
         a_len -= 1;
         count += 1;
         }
      block->size = blen;

      if (blen == 0)
         {
         SCL_DEALLOCATOR (a_stackbuf->block);
         a_stackbuf->block = NULL;
         }
      }

   return count;
   }
Example #5
0
int (stackbuf_push) (
                    SCL_stackbuf_t a_stackbuf,
                    const void*    a_data,
                    size_t         a_len
                    )
   {
   S_block_t* block;
   size_t size;
   size_t blen;
   char* dst;
   const char* src = (const char*)a_data;

   while (a_len > 0)
      {
      block = a_stackbuf->block;

      if (block == NULL)
         {
         block = SCL_ALLOCATOR (a_stackbuf->blen);
         if (block == NULL) return SCL_NOMEM;
         a_stackbuf->block = (S_block_t*)block;
         }

      size = block->size;
      blen = a_stackbuf->blen - sizeof(S_block_t) - size;
      dst = &block->data[size];

      while ((blen > 0) && (a_len > 0))
         {
         *dst++ = *src++;
         blen  -= 1;
         a_len -= 1;
         size  += 1;
         }
      block->size = size;

      if (blen == 0)
         {
         (void)(*a_stackbuf->putfn) ((void*)block, a_stackbuf->blen);
         a_stackbuf->block = NULL;
         a_stackbuf->nout += 1;
         }
      }

   return SCL_OK;
   }
Example #6
0
int (list_push_back) (SCL_list_t a_list, const void* a_data)
   {
   S_SCL_list_t* const list = a_list;
   S_node_t* const node = SCL_ALLOCATOR (sizeof(S_node_t));

   if (node == NULL) return SCL_NOMEM;

   node->data = a_data;
   PRED(node) = list->tail;

   if (list->tail != NULL)
      SUCC(list->tail) = node;
   else
      list->head = node;
   list->tail = node;
   list->count += 1;

   return SCL_OK;
   }
Example #7
0
int (queuebuf_get_alloc) (void* a_qbuf, void** a_data, size_t* a_size)
   {
   S_queuebuf_t* const buff = (S_queuebuf_t*)a_qbuf;
   const S_node_t* node;
   const char* data;
   char* dst;
   size_t d;
   size_t c;

   if (buff->count == 0) return SCL_NOSVC;

   node = &buff->header[ buff->tail ];
   data = (char*)&buff->header[buff->headerCount];

   dst = SCL_ALLOCATOR (node->size);
   if (dst == NULL) return SCL_NOMEM;
   *a_data = dst;

   d = node->head;
   c = node->size;
   while (c-- > 0)
      {
      *dst++ = data[d++];
      if (d == buff->bufferSize) d = 0;
      }
   *a_size = node->size;

   buff->count -= 1;
   buff->bufferAvail += node->size;

   if (buff->count == 0)
      buff->head = buff->tail = -1;
   else
      buff->tail = buff->tail > 0 ? buff->tail - 1 : buff->headerCount - 1;

   return SCL_OK;
   }
Example #8
0
SCL_list_t (list_new) (void)
   {
   return SCL_ALLOCATOR (sizeof(S_SCL_list_t));
   }
Example #9
0
SCL_symbol_t (symbol_new) (void)
   {
   return SCL_ALLOCATOR (sizeof(S_SCL_symbol_t));
   }