dd3c382002-05-29Per Hedbor #include "global.h" #include "stralloc.h" #include "bignum.h" #include "interpret.h" #include "shuffler.h"
b2986f2002-07-05Per Hedbor /* $Id: a_source_pikestring.c,v 1.5 2002/07/05 09:55:32 per Exp $ */
90ac0c2002-05-29Per Hedbor  /* Source: String * Argument: 8-bit string */
dd3c382002-05-29Per Hedbor  struct ps_source { struct source s; struct pike_string *str; int offset, len; }; static struct data get_data( struct source *_s, int len ) { struct ps_source *s = (struct ps_source *)_s; struct data res; res.do_free = 0; res.off = 0; res.data = s->str->str + s->offset; if( len > s->len ) { len = s->len; s->s.eof = 1; /* next read will be done from the next source */ } res.len = len; s->len -= len; s->offset += len; return res; } static void free_source( struct source *_s ) { free_string(((struct ps_source *)_s)->str); } struct source *source_pikestring_make( struct svalue *s, INT64 start, INT64 len ) { struct ps_source *res;
0d9bf22002-05-29Per Hedbor  if( s->type != PIKE_T_STRING ) return 0; if( s->u.string->size_shift ) return 0;
dd3c382002-05-29Per Hedbor  res = malloc( sizeof( struct ps_source ) );
b2986f2002-07-05Per Hedbor  debug_malloc_touch( res ); debug_malloc_touch( s );
dd3c382002-05-29Per Hedbor  MEMSET( res, 0, sizeof( struct ps_source ) );
3387322002-05-29Per Hedbor  res->s.free_source = free_source;
dd3c382002-05-29Per Hedbor  res->s.get_data = get_data; res->str = s->u.string; res->str->refs++; res->offset = start; if( len != -1 ) { if( len > res->str->len-start ) { res->str->refs--; free(res); return 0; } else res->len = len; } else res->len = res->str->len-start; if( res->len <= 0 ) { res->str->refs--; free(res); } return (struct source *)res; } void source_pikestring_init( ) { /* nothing to do here */ } void source_pikestring_exit( ) { /* nothing to do here */ }