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;
97611f2019-06-17Stephen R. van den Berg  struct pike_string*str; char *data; size_t len;
dd3c382002-05-29Per Hedbor };
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;
13670c2015-05-25Martin Nilsson 
8de3272019-06-21Stephen R. van den Berg  if (len > s->len) {
dd3c382002-05-29Per Hedbor  len = s->len; s->s.eof = 1; /* next read will be done from the next source */ }
97611f2019-06-17Stephen R. van den Berg  res.data = s->data; s->data += len; s->len -= res.len = len;
dd3c382002-05-29Per Hedbor  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;
97611f2019-06-17Stephen R. van den Berg  INT64 slen;
dd3c382002-05-29Per Hedbor 
97611f2019-06-17Stephen R. van den Berg  if (TYPEOF(*s) != PIKE_T_STRING || s->u.string->size_shift) return 0; if (!(res = calloc(1, sizeof(struct ps_source)))) return 0;
5650432004-08-28Martin Nilsson 
97611f2019-06-17Stephen R. van den Berg  debug_malloc_touch(res);
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);
8de3272019-06-21Stephen R. van den Berg  slen = res->str->len; if (start > slen) start = slen;
97611f2019-06-17Stephen R. van den Berg  res->data = res->str->str + start;
8de3272019-06-21Stephen R. van den Berg  slen -= start;
dd3c382002-05-29Per Hedbor 
8de3272019-06-21Stephen R. van den Berg  if (len < 0) len = slen; if (len > slen) len = slen;
97611f2019-06-17Stephen R. van den Berg 
8de3272019-06-21Stephen R. van den Berg  res->len = len;
dd3c382002-05-29Per Hedbor  return (struct source *)res; } void source_pikestring_init( ) { /* nothing to do here */ } void source_pikestring_exit( ) { /* nothing to do here */ }