new 1.3 version, internal memory management turned off;

master
Alexander Vdolainen 10 years ago
parent ead5a5e74d
commit 90d56e2c7e

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(libsexpr, 1.2)
AC_INIT(libsexpr, 1.3)
AC_CONFIG_HEADERS([config.h])

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -42,10 +42,6 @@ LA-CC-04-094
*
* -matt sottile
*/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#ifndef __CSTRING_H__
#define __CSTRING_H__

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -39,11 +39,6 @@ LA-CC-04-094
*
* \brief Implementation of a fast stack with smart memory management.
*/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#ifndef __FASTSTACK_H__
#define __FASTSTACK_H__
@ -108,7 +103,7 @@ extern "C" {
* Return a pointer to an empty stack structure. If the return value is
* NULL, one should check sexp_errno to determine why.
*/
faststack_t *make_stack(void);
faststack_t *make_stack();
/**
* Given a stack structure, destroy it and free all of the stack levels.

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,22 +34,16 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#ifndef __SEXP_H__
#define __SEXP_H__
#include <stddef.h>
#include <stdio.h> /* for BUFSIZ only */
#include "faststack.h"
#include "cstring.h"
#include "sexp_memory.h"
#include "sexp_errors.h"
/* local includes */
#include <sexpr/faststack.h>
#include <sexpr/cstring.h>
#include <sexpr/sexp_memory.h>
#include <sexpr/sexp_errors.h>
/* doxygen documentation groups defined here */
/**
@ -94,7 +88,7 @@ LA-CC-04-094
* \section credits Credits
*
* SFSEXP: Small, Fast S-Expression Library version 1.2, October 2007 \n
* Written by Matthew Sottile (matt@cs.uoregon.edu)
* Written by Matthew Sottile (mjsottile@gmail.com)
*
* \section license License Information
*
@ -346,13 +340,13 @@ typedef struct parser_event_handlers {
* The start_sexpr function pointer is called when an open parenthesis
* is encountered starting an expression.
*/
void (* start_sexpr)(void);
void (* start_sexpr)();
/**
* The end_sexpr function pointer is called when an close parenthesis
* is encountered ending an expression.
*/
void (* end_sexpr)(void);
void (* end_sexpr)();
/**
* The characters function pointer is called when an atom is completely
@ -563,7 +557,7 @@ typedef struct sexp_iowrap {
* Byte count for last read. If it is -1, there was an error. Otherwise,
* it will be a value from 0 to BUFSIZ.
*/
int cnt;
size_t cnt;
} sexp_iowrap_t;
/*========*/
@ -669,6 +663,16 @@ extern "C" {
* Allocate a new sexp_t element representing a list.
*/
sexp_t *new_sexp_list(sexp_t *l);
/**
* Allocate a new sexp_t element representing a raw binary atom.
* This element will contain a pointer to the raw binary data
* provided, as well as the binary data length. The character
* atom fields will be NULL and the corresponding val
* length and allocation size will be set to zero since this
* element is carrying a binary pointer only.
*/
sexp_t *new_sexp_binary_atom(char *data, size_t binlength);
/**
* Allocate a new sexp_t element representing a value. The user must
@ -758,7 +762,17 @@ extern "C" {
/**
* reset the value of sexp_errno to SEXP_ERR_OK.
*/
void reset_sexp_errno(void);
void reset_sexp_errno();
/**
* print the contents of the parser continuation stack to a buffer.
* this is useful if an expression is partially parsed and the caller
* realizes that something is wrong with it. with this routine,
* the caller can reconstruct the expression parsed so far and use it
* for error reporting. this works with fixed size buffers allocated
* by the caller. there is not a CSTRING-based version currently.
*/
void print_pcont(pcont_t * pc, char * buf, size_t buflen);
/* this is for C++ users */
#ifdef __cplusplus

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,11 +34,6 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#ifndef __SEXP_ERRORS_H__
#define __SEXP_ERRORS_H__
@ -132,7 +127,21 @@ typedef enum {
/**
* unknown parser state
*/
SEXP_ERR_UNKNOWN_STATE
SEXP_ERR_UNKNOWN_STATE,
/**
* parsing is incomplete and need more data to complete it.
*/
SEXP_ERR_INCOMPLETE,
/**
* this error code indicates that an atom was created with
* the incorrect constructor. For example, attempting to
* create a binary mode atom with the new_sexp_atom
* constructor intended for text atoms will cause this to
* be set.
*/
SEXP_ERR_BAD_CONSTRUCTOR
} sexp_errcode_t;

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,11 +34,6 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#ifndef __SEXP_MEMORY_H__
#define __SEXP_MEMORY_H__

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,11 +34,6 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#ifndef __SEXP_OPS_H__
#define __SEXP_OPS_H__
@ -50,7 +45,7 @@ LA-CC-04-094
* A set of routines for operating on s-expressions.
*/
#include <sexpr/sexp.h>
#include "sexp.h"
#ifdef __cplusplus
extern "C" {

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -37,10 +37,6 @@ LA-CC-04-094
/**
* \defgroup viz Visualization and debugging routines
*/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
/**
* \file sexp_vis.h

@ -4,6 +4,7 @@ AM_CPPFLAGS = \
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
-DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
-DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \
-D_NO_MEMORY_MANAGEMENT_ \
$(LIBTDATA_CFLAGS) -I../include
AM_CFLAGS =\

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -37,11 +37,6 @@ LA-CC-04-094
/**
* Implementation of stuff in cstring.h to make ron happy
*/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <sexpr/cstring.h>
#include <stdio.h>
#include <stdlib.h>
@ -92,7 +87,7 @@ CSTRING *snew(size_t s) {
}
CSTRING *sadd(CSTRING *s, char *a) {
int alen;
size_t alen;
char *newbase;
/* no string, so bail */

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,11 +34,6 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <assert.h>
#include <sexpr/sexp.h>
@ -773,7 +768,7 @@ eparse_sexp (char *str, size_t len, pcont_t *lc)
state = 15;
vcur[0] = '\0';
binexpected = atoi(val);
binexpected = (size_t) atoi(val);
assert(binexpected > 0);
binread = 0;
#ifdef __cplusplus

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -39,12 +39,6 @@ LA-CC-04-094
*
* matt sottile / matt@lanl.gov
*/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <stdlib.h>
#include <stdio.h>
#include <sexpr/faststack.h>
@ -123,7 +117,7 @@ destroy_stack (faststack_t * s)
faststack_t *
push (faststack_t * cur_stack, void *data)
{
stack_lvl_t *top;
stack_lvl_t *top, *tmp;
if (cur_stack == NULL) {
sexp_errno = SEXP_ERR_BAD_STACK;
@ -131,7 +125,6 @@ push (faststack_t * cur_stack, void *data)
}
top = cur_stack->top;
stack_lvl_t *tmp;
/* if top isn't null, try to push above it. */
if (top != NULL)

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,15 +34,14 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef WIN32
# include <unistd.h>
#else
# define ssize_t int
# include <io.h>
# include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -55,9 +54,9 @@ sexp_iowrap_t *init_iowrap(int fd) {
sexp_iowrap_t *iow;
#ifdef __cplusplus
iow = (sexp_iowrap_t *)sexp_malloc(sizeof(sexp_iowrap_t));
iow = (sexp_iowrap_t *)sexp_calloc(1,sizeof(sexp_iowrap_t));
#else
iow = sexp_malloc(sizeof(sexp_iowrap_t));
iow = sexp_calloc(1,sizeof(sexp_iowrap_t));
#endif
if (iow == NULL) {
@ -106,7 +105,7 @@ sexp_t *read_one_sexp(sexp_iowrap_t *iow) {
}
if (iow->cnt == 0) {
iow->cnt = read(iow->fd,iow->buf,BUFSIZ);
iow->cnt = (size_t) read(iow->fd,iow->buf,BUFSIZ);
if (iow->cnt == 0) {
sexp_errno = SEXP_ERR_IO_EMPTY;
@ -122,7 +121,7 @@ sexp_t *read_one_sexp(sexp_iowrap_t *iow) {
return NULL;
}
iow->cnt = read(iow->fd,iow->buf,BUFSIZ);
iow->cnt = (size_t) read(iow->fd,iow->buf,BUFSIZ);
if (iow->cnt == 0) {
sexp_errno = SEXP_ERR_IO_EMPTY;

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,16 +34,9 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sexpr/sexp.h>
#include <sexpr/faststack.h>
@ -84,7 +77,9 @@ parse_data_t;
/**
* parse_data_t stack - similar malloc prevention to sexp_t_cache.
*/
#ifndef _NO_MEMORY_MANAGEMENT_
faststack_t *pd_cache;
#endif
/**
* The global <I>sexp_t_cache</I> is a faststack implementing a cache of
@ -94,7 +89,9 @@ faststack_t *pd_cache;
* This should be left alone and manipulated only by the sexp_t_allocate and
* sexp_t_deallocate functions. Touching the stack is bad.
*/
#ifndef _NO_MEMORY_MANAGEMENT_
faststack_t *sexp_t_cache;
#endif
/**
* sexp_t allocation
@ -104,7 +101,7 @@ sexp_t *
sexp_t_allocate(void) {
sexp_t *sx = sexp_calloc(1, sizeof(sexp_t));
if (sx == NULL) {
sexp_errno = SEXP_MEMORY;
sexp_errno = SEXP_ERR_MEMORY;
return NULL;
}
@ -237,6 +234,14 @@ void sexp_cleanup(void) {
/**
* allocation
*/
#ifdef _NO_MEMORY_MANAGEMENT_
parse_data_t *
pd_allocate(void) {
parse_data_t *p = NULL;
p = sexp_malloc(sizeof(parse_data_t));
return p;
}
#else
parse_data_t *
pd_allocate(void) {
parse_data_t *p;
@ -281,10 +286,17 @@ pd_allocate(void) {
return p;
}
#endif /* _NO_MEMORY_MANAGEMENT_ */
/**
* de-allocation
*/
#ifdef _NO_MEMORY_MANAGEMENT_
void
pd_deallocate(parse_data_t *p) {
sexp_free(p, sizeof(parse_data_t));
}
#else
void
pd_deallocate(parse_data_t *p) {
if (pd_cache == NULL) {
@ -298,6 +310,101 @@ pd_deallocate(parse_data_t *p) {
pd_cache = push(pd_cache, p);
}
#endif /* _NO_MEMORY_MANAGEMENT_ */
/**
* print the current parsing state based on the contents of the parser
* continuation. Useful for error reporting if an error is detected
* while the current expression being parsed is incomplete.
*/
void print_pcont(pcont_t * pc, char * buf, size_t buflen) {
char *cur = buf;
int loc = 0;
int n;
stack_lvl_t *lvl;
parse_data_t *pdata;
sexp_t *sx;
/* return if either the buffer or continuation are null */
if (buf == NULL) return;
if (pc == NULL) return;
/* if continuation has no stack, return */
if (pc->stack == NULL) return;
/* start at the bottom of the stack */
lvl = pc->stack->bottom;
/* go until we either run out of buffer space or we hit the
top of the stack */
while (loc < buflen-1 && lvl != NULL) {
/* get the data at the current stack level */
pdata = (parse_data_t *)lvl->data;
/* if this is null, we're at a level with nothing added yet */
if (pdata == NULL) break;
/* get first fully parsed sexpr for this level. this could be
any sub-expression, like an atom or a full s-expression */
sx = pdata->fst;
/* spin through all of the s-expressions at this level */
while (sx != NULL) {
/* if we have a list that has no contents, just add the open
paren. this means we haven't finished this expression and the
stack contains it's partial contents. Just print the open paren
and break out so we can pop up the stack. */
if (sx->ty == SEXP_LIST && sx->list == NULL) {
cur[0] = '(';
cur++;
loc++;
break;
} else {
/* print the fully parsed sub-expression */
n = print_sexp(cur,buflen-loc,sx);
/* add a space between this and the next expression. note that
this may induce spaces that were not part of the original
expression. */
cur[n] = ' ';
/* increment n to compensate for the space we added */
n++;
/* push the pointer into the output buffer forward by n */
cur += n;
/* increment counter for location in buffer by n */
loc += n;
}
/* go to next s-expr */
sx = sx->next;
}
/* go up to next level in stack */
lvl = lvl->above;
}
/* at this point, all that may remain is a partially parsed string
that hasn't been turned into a sexpr yet. attach it to the
output string. */
if (pc->val_used < (buflen-loc)-1) {
strncpy(cur, pc->val, pc->val_used);
cur += pc->val_used;
} else {
/* don't bother if we're so close to the end of the buffer that
we can't attach our null terminator. */
if (buflen-loc > 2) {
strncpy(cur, pc->val, (buflen-loc)-2);
cur += (buflen-loc)-2;
}
}
/* add null terminator */
cur[0] = '\0';
}
/**
* Destroy a continuation by freeing all of its fields that it is responsible
@ -378,7 +485,6 @@ parse_sexp (char *s, size_t len)
pc = cparse_sexp (s, len, pc);
if (pc == NULL) return NULL; /* assume that cparse_sexp set sexp_errno */
sx = pc->last_sexp;
sexp_errno = pc->error;
destroy_continuation(pc);
@ -476,7 +582,6 @@ iparse_sexp (char *s, size_t len, pcont_t *cc) {
if (pc == NULL) return NULL; /* assume cparse_sexp set sexp_errno */
if (cc->last_sexp != NULL) {
sexp_errno = cc->error;
sx = cc->last_sexp;
cc->last_sexp = NULL;
}
@ -526,7 +631,13 @@ cparse_sexp (char *str, size_t len, pcont_t *lc)
parser_event_handlers_t *event_handlers = NULL;
/*** define a macro used for stashing continuation state away ***/
/** NOTE: sbuffer is set manually as appropriate. **/
/** NOTE1: sbuffer is set manually as appropriate. **/
/** NOTE2: this also sets sexp_errno to the same value as the
error field in the continuation. This used to be
done in iparse_sexp and parse_sexp, but that meant that
direct callers of cparse_sexp would see inconsistent errors.
sexp_errno could say one thing, but cc would say the other.
This has been fixed. **/
#define SAVE_CONT_STATE(err,ls) { \
cc->bindata = bindata; \
cc->binread = binread; \
@ -546,6 +657,7 @@ cparse_sexp (char *str, size_t len, pcont_t *lc)
cc->last_sexp = (ls); \
cc->error = (err); \
cc->event_handlers = event_handlers; \
sexp_errno = (err); \
}
/*** end continuation state saving macro ***/
@ -1424,12 +1536,7 @@ cparse_sexp (char *str, size_t len, pcont_t *lc)
state = 15;
vcur[0] = '\0';
binexpected = atoi(val);
if (binexpected < 0) {
SAVE_CONT_STATE(SEXP_ERR_BADCONTENT, NULL);
return cc;
}
binexpected = (size_t) atoi(val);
binread = 0;
if (binexpected > 0) {
@ -1562,7 +1669,7 @@ cparse_sexp (char *str, size_t len, pcont_t *lc)
state = 1;
SAVE_CONT_STATE(SEXP_ERR_OK, sx);
} else {
SAVE_CONT_STATE(SEXP_ERR_OK, NULL);
SAVE_CONT_STATE(SEXP_ERR_INCOMPLETE, NULL);
if (t[0] == '\0' || t == bufEnd)
cc->lastPos = NULL;
else

@ -1,9 +1,9 @@
/**
@cond IGNORE
@Cond IGNORE
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,16 +34,9 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sexpr/sexp.h>
#include <sexpr/faststack.h>
@ -94,7 +87,7 @@ int
print_sexp (char *buf, size_t size, const sexp_t * sx)
{
int retval;
int sz;
size_t sz;
char *b = buf, *tc;
size_t left = size;
int depth = 0;
@ -251,8 +244,6 @@ print_sexp (char *buf, size_t size, const sexp_t * sx)
left--;
}
if (left < 0)
left = 0;
if (left == 0)
{
sexp_errno = SEXP_ERR_BUFFER_FULL;
@ -311,7 +302,7 @@ print_sexp (char *buf, size_t size, const sexp_t * sx)
if (left != 0) {
b[0] = 0;
retval = (size-left);
retval = (int) (size-left);
} else {
b--;
b[0] = 0;
@ -480,7 +471,7 @@ print_sexp_cstr (CSTRING **s, const sexp_t *sx, size_t ss)
if (_s == NULL)
retval = 0;
else
retval = _s->curlen;
retval = (int) _s->curlen;
destroy_stack (stack);
sexp_t_deallocate(fakehead);
@ -510,11 +501,40 @@ sexp_t *new_sexp_list(sexp_t *l) {
return sx;
}
/**
* allocate a new sexp_t element representing a raw binary value
*/
sexp_t *new_sexp_binary_atom(char *data, size_t binlength) {
sexp_t *sx = sexp_t_allocate();
if (sx == NULL) {
sexp_errno = SEXP_ERR_MEMORY;
return NULL;
}
sx->ty = SEXP_VALUE;
sx->next = sx->list = NULL;
sx->aty = SEXP_BINARY;
sx->bindata = data;
sx->binlength = binlength;
sx->val = NULL;
sx->val_used = sx->val_allocated = 0;
return sx;
}
/**
* allocate a new sexp_t element representing a value
*/
sexp_t *new_sexp_atom(const char *buf, size_t bs, atom_t aty) {
sexp_t *sx = sexp_t_allocate();
sexp_t *sx = NULL;
if (aty == SEXP_BINARY) {
sexp_errno = SEXP_ERR_BAD_CONSTRUCTOR;
return NULL;
}
sx = sexp_t_allocate();
if (sx == NULL) {
sexp_errno = SEXP_ERR_MEMORY;

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,15 +34,8 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <stdlib.h>
#include <stdio.h>
#include <sexpr/sexp.h>
#include <sexpr/sexp_errors.h>
#include <sexpr/sexp_memory.h>

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,16 +34,9 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sexpr/sexp_ops.h>
/**
@ -137,94 +130,95 @@ int sexp_list_length(const sexp_t *sx) {
* Copy an s-expression.
*/
sexp_t *copy_sexp(const sexp_t *s) {
sexp_t *snew;
sexp_t *s_new;
if (s == NULL) return NULL;
snew = sexp_t_allocate();
if (snew == NULL) {
s_new = sexp_t_allocate();
if (s_new == NULL) {
sexp_errno = SEXP_ERR_MEMORY;
return NULL;
}
/* initialize fields to null and zero, and fill in only those necessary. */
snew->val_allocated = snew->val_used = 0;
snew->val = NULL;
snew->list = snew->next = NULL;
snew->bindata = NULL;
snew->binlength = 0;
s_new->val_allocated = s_new->val_used = 0;
s_new->val = NULL;
s_new->list = s_new->next = NULL;
s_new->bindata = NULL;
s_new->binlength = 0;
/* now start copying in data and setting appropriate fields. */
snew->ty = s->ty;
s_new->ty = s->ty;
/* values */
if (snew->ty == SEXP_VALUE) {
snew->aty = s->aty;
if (s_new->ty == SEXP_VALUE) {
s_new->aty = s->aty;
/* binary */
if (snew->aty == SEXP_BINARY) {
if (s_new->aty == SEXP_BINARY) {
if (s->bindata == NULL && s->binlength > 0) {
sexp_errno = SEXP_ERR_BADCONTENT;
sexp_t_deallocate(snew);
sexp_t_deallocate(s_new);
return NULL;
}
snew->binlength = s->binlength;
s_new->binlength = s->binlength;
if (s->bindata == NULL) {
snew->bindata = NULL;
s_new->bindata = NULL;
} else {
/** allocate space **/
#ifdef __cplusplus
snew->bindata = (char *)sexp_malloc(sizeof(char)*s->binlength);
s_new->bindata = (char *)sexp_malloc(sizeof(char)*s->binlength);
#else
snew->bindata = sexp_malloc(sizeof(char)*s->binlength);
s_new->bindata = sexp_malloc(sizeof(char)*s->binlength);
#endif
}
if (snew->bindata == NULL) {
if (s_new->bindata == NULL) {
sexp_errno = SEXP_ERR_MEMORY;
sexp_t_deallocate(snew);
sexp_t_deallocate(s_new);
return NULL;
}
memcpy(snew->bindata,s->bindata,s->binlength*sizeof(char));
memcpy(s_new->bindata,s->bindata,s->binlength*sizeof(char));
/* non-binary */
} else {
if (s->val == NULL && (s->val_used > 0 || s->val_allocated > 0)) {
sexp_errno = SEXP_ERR_BADCONTENT;
sexp_t_deallocate(snew);
sexp_t_deallocate(s_new);
return NULL;
}
snew->val_used = snew->val_allocated = s->val_used;
s_new->val_used = s->val_used;
s_new->val_allocated = s->val_allocated;
if (s->val == NULL) {
snew->val = NULL;
s_new->val = NULL;
} else {
/** allocate space **/
#ifdef __cplusplus
snew->val = (char *)sexp_malloc(sizeof(char)*s->val_used);
s_new->val = (char *)sexp_calloc(1,sizeof(char)*s->val_allocated);
#else
snew->val = sexp_malloc(sizeof(char)*s->val_used);
s_new->val = sexp_calloc(1,sizeof(char)*s->val_allocated);
#endif
if (snew->val == NULL) {
if (s_new->val == NULL) {
sexp_errno = SEXP_ERR_MEMORY;
sexp_t_deallocate(snew);
sexp_t_deallocate(s_new);
return NULL;
}
strcpy(snew->val,s->val);
memcpy(s_new->val, s->val, sizeof(char)*s->val_used);
}
}
} else {
snew->list = copy_sexp(s->list);
s_new->list = copy_sexp(s->list);
}
snew->next = copy_sexp(s->next);
s_new->next = copy_sexp(s->next);
return snew;
return s_new;
}

@ -3,7 +3,7 @@
======================================================
SFSEXP: Small, Fast S-Expression Library version 1.2
Written by Matthew Sottile (matt@cs.uoregon.edu)
Written by Matthew Sottile (mjsottile@gmail.com)
======================================================
Copyright (2003-2006). The Regents of the University of California. This
@ -34,12 +34,6 @@ LA-CC-04-094
@endcond
**/
/**
* Ported to Jari OS by Alfeiks Kaanoken <madtirra@jarios.org>
* (c) Jari OS Core dev team 2005-2009 <http://jarios.org>
*/
#include <sexpr/faststack.h>
#include <sexpr/sexp.h>

Loading…
Cancel
Save