cst_filemap *cst_read_whole_file(const char *path) { cst_filemap *fmap; cst_file fh; if ((fh = cst_fopen(path, CST_OPEN_READ)) == NULL) { cst_errmsg("cst_read_whole_file: Failed to open file\n"); return NULL; } fmap = cst_alloc(cst_filemap, 1); fmap->fh = fh; cst_fseek(fmap->fh, 0, CST_SEEK_ENDREL); fmap->mapsize = cst_ftell(fmap->fh); fmap->mem = VirtualAlloc(NULL, fmap->mapsize, MEM_COMMIT|MEM_TOP_DOWN, PAGE_READWRITE); cst_fseek(fmap->fh, 0, CST_SEEK_ABSOLUTE); cst_fread(fmap->fh, fmap->mem, 1, fmap->mapsize); return fmap; }
int ts_set_stream_pos(cst_tokenstream *ts, int pos) { /* Note this doesn't preserve line_pos */ int new_pos, l; if (ts->fd) #ifdef FLITE_PLUS_HTS_ENGINE ; #else new_pos = (int)cst_fseek(ts->fd,(long)pos,CST_SEEK_ABSOLUTE); #endif /* !FLITE_PLUS_HTS_ENGINE */ else if (ts->string_buffer)
int ts_set_stream_pos(cst_tokenstream *ts, int pos) { /* Note this doesn't preserve line_pos */ int new_pos, l; if (ts->fd) new_pos = (int)cst_fseek(ts->fd,(long)pos,CST_SEEK_ABSOLUTE); else if (ts->string_buffer) { l = cst_strlen(ts->string_buffer); if (pos > l) new_pos = l; else if (pos < 0) new_pos = 0; else new_pos = pos; } else new_pos = pos; /* not sure it can get here */ ts->file_pos = new_pos; ts->current_char = ' '; /* To be safe */ return ts->file_pos; }