e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
1b10db2002-10-08Martin Nilsson 
dd3c382002-05-29Per Hedbor #include "global.h" #include "stralloc.h" #include "bignum.h" #include "interpret.h" #include "shuffler.h"
1b10db2002-10-08Martin Nilsson 
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; };
feb6822009-08-13Henrik Grubbström (Grubba) static struct data get_data( struct source *src, off_t len )
dd3c382002-05-29Per Hedbor {
feb6822009-08-13Henrik Grubbström (Grubba)  struct ps_source *s = (struct ps_source *)src;
dd3c382002-05-29Per Hedbor  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; }
feb6822009-08-13Henrik Grubbström (Grubba) static void free_source( struct source *src )
dd3c382002-05-29Per Hedbor {
feb6822009-08-13Henrik Grubbström (Grubba)  free_string(((struct ps_source *)src)->str);
dd3c382002-05-29Per Hedbor } struct source *source_pikestring_make( struct svalue *s, INT64 start, INT64 len ) { struct ps_source *res;
017b572011-10-28Henrik Grubbström (Grubba)  if( TYPEOF(*s) != PIKE_T_STRING ) return 0;
0d9bf22002-05-29Per Hedbor  if( s->u.string->size_shift ) return 0;
5650432004-08-28Martin Nilsson 
9c14f32014-04-27Martin Nilsson  res = calloc( 1, sizeof( struct ps_source ) );
dc8d022014-04-27Martin Nilsson  if( !res ) return NULL;
b2986f2002-07-05Per Hedbor  debug_malloc_touch( res ); debug_malloc_touch( s );
dd3c382002-05-29Per Hedbor 
3387322002-05-29Per Hedbor  res->s.free_source = free_source;
dd3c382002-05-29Per Hedbor  res->s.get_data = get_data;
50ea682003-03-14Henrik Grubbström (Grubba)  copy_shared_string(res->str, s->u.string);
dd3c382002-05-29Per Hedbor  res->offset = start; if( len != -1 ) { if( len > res->str->len-start ) {
50ea682003-03-14Henrik Grubbström (Grubba)  sub_ref(res->str);
dd3c382002-05-29Per Hedbor  free(res); return 0; } else res->len = len; } else res->len = res->str->len-start; if( res->len <= 0 ) {
50ea682003-03-14Henrik Grubbström (Grubba)  sub_ref(res->str);
dd3c382002-05-29Per Hedbor  free(res);
5650432004-08-28Martin Nilsson  return 0;
dd3c382002-05-29Per Hedbor  } return (struct source *)res; } void source_pikestring_init( ) { /* nothing to do here */ } void source_pikestring_exit( ) { /* nothing to do here */ }