void read_operator(disk_stream *inflight) { if(inflight->one_shot) { rewind_file(inflight->superp_fd[inflight->request_superp]); read_from_file(inflight->superp_fd[inflight->request_superp], inflight->request->buffer, inflight->request->bufsize); inflight->one_shot = false; inflight->request->uptodate = true; return; } unsigned long disk_buffer_pos; unsigned long bytes; disk_buffer_pos = inflight->disk_pos[inflight->request_superp]; inflight->request->set_bufsize (inflight->disk_bytes[inflight->request_superp] - inflight->disk_pos[inflight->request_superp], inflight->stream_unit_bytes); bytes = inflight->request->bufsize; inflight->disk_pos[inflight->request_superp] += bytes; BOOST_ASSERT_MSG(inflight->disk_pos[inflight->request_superp] <= inflight->disk_bytes[inflight->request_superp], "Trying to read past end of stream !"); do_read_IO(inflight->superp_fd[inflight->request_superp], inflight->request->buffer, inflight->disk_pages[inflight->request_superp], bytes, disk_buffer_pos); inflight->request->uptodate = true; }
void compress_and_write_internal(disk_stream *inflight) { z_stream *zlib_stream; BOOST_ASSERT_MSG(inflight->request->dirty, "Trying to write out clean buffer !"); inflight->set_zlib_deflate(); if(inflight->one_shot) { rewind_file(inflight->superp_fd[inflight->request_superp]); zlib_stream = inflight->zlib_streams[inflight->request_superp]; zlib_stream->next_in = inflight->request->buffer; zlib_stream->avail_in = inflight->request->bufsize; squeeze(inflight, inflight->request_superp); flush_one(inflight, inflight->request_superp); } else { for(unsigned long i=0;i<inflight->superp_cnt;i++) { if(i == inflight->request->skip_superp) { inflight->request->skip_superp = -1UL; continue; } for(unsigned long j=0;j<inflight->request->config->processors;j++) { unsigned long buffer_bytes; // Extract the buffer and squeeze out inflight->zlib_streams[i]->next_in = inflight->request->get_substream (j, i, &buffer_bytes); inflight->zlib_streams[i]->avail_in = buffer_bytes; if(buffer_bytes > 0) { squeeze(inflight, i); } } } } }
void *snag_vertex(FILE *fpin, char *s, char *value, int *group, int *type) { VertexEntity *item; item = (VertexEntity *)malloc(sizeof(VertexEntity)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->start_width = default_polyline_start_width; item->end_width = default_polyline_end_width; item->bulge = 0.0; item->vert_flags = 0x0; item->tangent = 0.0; item->mesh_indicies[0] = item->mesh_indicies[1] = item->mesh_indicies[2] = item->mesh_indicies[3] = 0; /* * Assume that we can read to the next entity group */ while (TRUE) { get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { /* common stuff */ handle_common((void *)item, *group, value); continue; } switch (*group) { /* location */ case G_X_COOR1: item->loc[0] = atof(value); break; case G_Y_COOR1: item->loc[1] = atof(value); break; case G_Z_COOR1: item->loc[2] = atof(value); break; /* start_wdith */ case G_FLOAT1: item->start_width = atof(value); break; /* end width */ case G_FLOAT2: item->end_width = atof(value); break; /* bulge */ case G_FLOAT3: item->bulge = atof(value); break; /* vert_flag */ case G_INT1: item->vert_flags = strtol(value,NULL,0); break; /* curve fit tangent */ case G_ANGLE1: item->tangent = atof(value); break; /* vertex indicies (for mesh) -- ignore edge invisble flag -- i.e. -1 */ case G_INT2: item->mesh_indicies[0] = abs(strtol(value,NULL,0)); break; case G_INT3: item->mesh_indicies[1] = abs(strtol(value,NULL,0)); break; case G_INT4: item->mesh_indicies[2] = abs(strtol(value,NULL,0)); break; case G_INT5: item->mesh_indicies[3] = abs(strtol(value,NULL,0)); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in VERTEX", *group, value, IGNORE); } } }
/* Generate a temporary file containing sort-of random data. Diffs between files of random data tend to be pretty boring, so we try to make sure there are a bunch of common substrings between two runs of this function with the same seedbase. */ static apr_file_t * generate_random_file(apr_uint32_t maxlen, apr_uint32_t subseed_base, apr_uint32_t *seed, const char *random_bytes, apr_size_t bytes_range, int dump_files, apr_pool_t *pool) { static char file_buffer[10240]; char *buf = file_buffer; char *const end = buf + sizeof file_buffer; apr_uint32_t len, seqlen; apr_file_t *fp; unsigned long r; fp = open_tempfile("random_XXXXXX", pool); len = svn_test_rand(seed) % maxlen; /* We might go over this by a bit. */ while (len > 0) { /* Generate a pseudo-random sequence of up to MAXSEQ bytes, where the seed is in the range [seedbase..seedbase+MAXSEQ-1]. (Use our own pseudo-random number generator here to avoid clobbering the seed of the libc random number generator.) */ seqlen = svn_test_rand(seed) % MAXSEQ; if (seqlen > len) seqlen = len; len -= seqlen; r = subseed_base + svn_test_rand(seed) % SEEDS; while (seqlen-- > 0) { const int ch = (random_bytes ? (unsigned)random_bytes[r % bytes_range] : (int)(r % bytes_range)); if (buf == end) { apr_size_t ignore_length; apr_file_write_full(fp, file_buffer, sizeof file_buffer, &ignore_length); buf = file_buffer; } *buf++ = (char)ch; r = r * 1103515245 + 12345; } } if (buf > file_buffer) { apr_size_t ignore_length; apr_file_write_full(fp, file_buffer, buf - file_buffer, &ignore_length); } rewind_file(fp); if (dump_files) dump_file_contents(fp); return fp; }
void *snag_shape(FILE *fpin, char *s, char *value, int *group, int *type) { Shape *item; item = (Shape *)malloc(sizeof(Shape)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->rot = 0.0; item->x_scale = 1.0; item->oblique = 0.0; while (TRUE) { /* * Assume that we can read to the next entity group */ get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { /* common stuff */ handle_common((void *)item, *group, value); continue; } switch (*group) { /* val */ case G_NAME: strncpy(item->name,value,10); break; /* size */ case G_FLOAT1: item->size = atof(value); break; /* x_scale */ case G_FLOAT2: item->x_scale = atof(value); break; /* rot */ case G_ANGLE1: item->rot = atof(value); break; /* oblique */ case G_ANGLE2: item->oblique = atof(value); break; /* point */ case G_X_COOR1: item->pt[0] = atof(value); break; case G_Y_COOR1: item->pt[1] = atof(value); break; case G_Z_COOR1: item->pt[2] = atof(value); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in SHAPE", *group, value, IGNORE); } } }
void *snag_3dface(FILE *fpin, char *s, char *value, int *group, int *type) { Face3d *item; item = (Face3d *)malloc(sizeof(Face3d)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->edge_vis_flag = 0; /* * Assume that we can read to the next entity group */ while (TRUE) { get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { /* common stuff */ handle_common((void *)item, *group, value); continue; } switch (*group) { /* edge visibility flag */ case G_INT1: item->edge_vis_flag = strtol(value,NULL,0); break; /* pt1 */ case G_X_COOR1: item->pt1[0] = atof(value); break; case G_Y_COOR1: item->pt1[1] = atof(value); break; case G_Z_COOR1: item->pt1[2] = atof(value); break; /* pt2 */ case G_X_COOR2: item->pt2[0] = atof(value); break; case G_Y_COOR2: item->pt2[1] = atof(value); break; case G_Z_COOR2: item->pt2[2] = atof(value); break; /* pt3 */ case G_X_COOR3: item->pt3[0] = atof(value); break; case G_Y_COOR3: item->pt3[1] = atof(value); break; case G_Z_COOR3: item->pt3[2] = atof(value); break; /* pt2 */ case G_X_COOR4: item->pt4[0] = atof(value); break; case G_Y_COOR4: item->pt4[1] = atof(value); break; case G_Z_COOR4: item->pt4[2] = atof(value); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in FACE", *group, value, IGNORE); } } }
static apr_file_t * copy_tempfile(apr_file_t *fp, apr_pool_t *pool) { static char file_buffer[10240]; apr_file_t *newfp; apr_size_t length1, length2; newfp = open_tempfile("copy_XXXXXX", pool); rewind_file(fp); do { apr_file_read_full(fp, file_buffer, sizeof file_buffer, &length1); apr_file_write_full(newfp, file_buffer, length1, &length2); assert(length1 == length2); } while (length1 == sizeof file_buffer); rewind_file(fp); rewind_file(newfp); return newfp; }
/* Compare two open files. The file positions may change. */ static svn_error_t * compare_files(apr_file_t *f1, apr_file_t *f2, int dump_files) { static char file_buffer_1[10240]; static char file_buffer_2[10240]; char *c1, *c2; apr_off_t pos = 0; apr_size_t len1, len2; rewind_file(f1); rewind_file(f2); if (dump_files) dump_file_contents(f2); do { apr_file_read_full(f1, file_buffer_1, sizeof file_buffer_1, &len1); apr_file_read_full(f2, file_buffer_2, sizeof file_buffer_2, &len2); for (c1 = file_buffer_1, c2 = file_buffer_2; c1 < file_buffer_1 + len1 && c2 < file_buffer_2 + len2; ++c1, ++c2, ++pos) { if (*c1 != *c2) return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, "mismatch at position %"APR_OFF_T_FMT, pos); } if (len1 != len2) return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, "unequal file sizes at position" " %"APR_OFF_T_FMT, pos); } while (len1 == sizeof file_buffer_1); return SVN_NO_ERROR; }
void *snag_block(FILE *fpin, char *s, char *value, int *group, int *type) { Block *item; int i; item = (Block *)malloc(sizeof(Block)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->processed = FALSE; init_list(&item->entities); while (TRUE) { /* * Assume that we can read to the next entity group */ get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { handle_common((void *)item, *group, value); continue; } switch (*group) { /* base point */ case G_X_COOR1: item->loc[0] = atof(value); break; case G_Y_COOR1: item->loc[1] = atof(value); break; case G_Z_COOR1: item->loc[2] = atof(value); break; /* flags */ case G_INT1: item->flags = strtol(value,NULL,0); break; /* name */ case G_NAME: strncpy(item->name,value,25); break; /* external reference -- v. 11 and later */ case G_TEXT_STRING: strncpy(item->external_ref,value,50); break; /* other text -- v. 11 and later */ case G_OTHER_TEXT1: strncpy(item->other_text,value,25); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in BLOCK", *group, value, IGNORE); } } }
static void dump_file_contents(apr_file_t *fp) { static char file_buffer[10240]; apr_size_t length = sizeof file_buffer; fputs("--------\n", stdout); do { apr_file_read_full(fp, file_buffer, sizeof file_buffer, &length); fwrite(file_buffer, 1, length, stdout); } while (length == sizeof file_buffer); putc('\n', stdout); rewind_file(fp); }
void *snag_end_block(FILE *fpin, char *s, char *value, int *group, int *type) { while (TRUE) { /* No groups except maybe the common defaults -- so just read them in and safely ignore them */ get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { continue; } switch (*group) { case G_FILE_SEP: rewind_file(); return NULL; default: print_group("Unknown group in ENDBLOCK", *group, value, IGNORE); } } }
/* Also does line_3d */ void *snag_line(FILE *fpin, char *s, char *value, int *group, int *type) { LineEntity *item; item = (LineEntity *)malloc(sizeof(LineEntity)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ /* none */ while (TRUE) { /* * Assume that we can read to the next entity group */ get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { /* common stuff */ handle_common((void *)item, *group, value); continue; } switch (*group) { /* start */ case G_X_COOR1: item->start[0] = atof(value); break; case G_Y_COOR1: item->start[1] = atof(value); break; case G_Z_COOR1: item->start[2] = atof(value); break; /* end */ case G_X_COOR2: item->end[0] = atof(value); break; case G_Y_COOR2: item->end[1] = atof(value); break; case G_Z_COOR2: item->end[2] = atof(value); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in LINE", *group, value, IGNORE); } } }
void *snag_arc(FILE *fpin, char *s, char *value, int *group, int *type) { Arc *item; item = (Arc *)malloc(sizeof(Arc)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ /* none */ /* * Assume that we can read to the next entity group */ while (TRUE) { get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { /* common stuff */ handle_common((void *)item, *group, value); continue; } switch (*group) { /* center */ case G_X_COOR1: item->center[0] = atof(value); break; case G_Y_COOR1: item->center[1] = atof(value); break; case G_Z_COOR1: item->center[2] = atof(value); break; /* radius */ case G_FLOAT1: item->radius = atof(value); break; /* start and stop angles */ case G_ANGLE1: item->start_angle = atof(value); break; case G_ANGLE2: item->end_angle = atof(value); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in ARC", *group, value, IGNORE); } } }
void *snag_point(FILE *fpin, char *s, char *value, int *group, int *type) { PointEntity *item; item = (PointEntity *)malloc(sizeof(PointEntity)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->angle = 0; while (TRUE) { /* * Assume that we can read to the next entity group */ get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { handle_common((void *)item, *group, value); continue; } switch (*group) { /* angle */ case G_ANGLE1: item->angle = atof(value); break; /* PointEntity */ case G_X_COOR1: item->pt[0] = atof(value); break; case G_Y_COOR1: item->pt[1] = atof(value); break; case G_Z_COOR1: item->pt[2] = atof(value); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in POINT", *group, value, IGNORE); } } }
blargg_err_t File_Extractor::data( const void** data_out ) { assert( !done() ); *data_out = NULL; if ( !data_ptr_ ) { BOOST::uint64_t old_tell = tell(); RETURN_ERR( rewind_file() ); void const* ptr; RETURN_ERR( data_v( &ptr ) ); data_ptr_ = ptr; // Now that data is in memory, we can seek by simply setting remain set_remain( size() - old_tell ); } *data_out = data_ptr_; return blargg_ok; }
void write_internal(disk_stream *inflight) { BOOST_ASSERT_MSG(inflight->request->dirty, "Trying to write out clean buffer !"); // Special case: one shot if(inflight->one_shot) { rewind_file(inflight->superp_fd[inflight->request_superp]); write_to_file(inflight->superp_fd[inflight->request_superp], inflight->request->buffer, inflight->request->bufsize); inflight->one_shot = false; inflight->request->dirty = false; inflight->request->uptodate = true; return; } for(unsigned long i=0;i<inflight->superp_cnt;i++) { if(i == inflight->request->skip_superp) { inflight->request->skip_superp = -1UL; continue; } for(unsigned long j=0;j<inflight->request->config->processors;j++) { unsigned char *buffer; unsigned long buffer_bytes; // Extract the buffer buffer = inflight->request->get_substream(j, i, &buffer_bytes); // Do the write unsigned long disk_buffer_pos = inflight->disk_pos[i]; inflight->disk_pos[i] += buffer_bytes; inflight->disk_bytes[i] += buffer_bytes; do_write_IO(inflight->superp_fd[i], buffer, buffer_bytes, disk_buffer_pos, inflight->disk_pages[i]); } } }
void *snag_attrib(FILE *fpin, char *s, char *value, int *group, int *type) { Attdef *item; item = (Attdef *)malloc(sizeof(Attdef)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->pt[0] = item->pt[1] = item->pt[2] = 0.0; item->text_height = 0; strcpy(item->value,""); item->attribute_flags = 0x0; item->field_length = 0; item->text_rotation = 0.0; item->rel_x_scale = 0.0; item->obliquing_angle = 0.0; strcpy(item->text_style,""); item->text_generation_flags = 0x0; item->horz_just = 0x0; item->vert_just = 0x0; item->align_pt[0] = item->align_pt[1] = item->align_pt[2] = 0.0; while (TRUE) { /* No groups except maybe the common defaults -- so just read them in and safely ignore them */ get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { continue; } switch(*group) { /* text start */ case G_X_COOR1: item->pt[0] = atof(value); break; case G_Y_COOR1: item->pt[1] = atof(value); break; case G_Z_COOR1: item->pt[2] = atof(value); break; /* alignment point */ case G_X_COOR2: item->align_pt[0] = atof(value); break; case G_Y_COOR2: item->align_pt[1] = atof(value); break; case G_Z_COOR2: item->align_pt[2] = atof(value); break; /* default value */ case G_TEXT_STRING: strncpy(item->value, value, 25); break; /* text style */ case G_TEXT_STYLE: strncpy(item->text_style, value, 10); break; /* attribute flags */ case G_INT1: item->attribute_flags = strtol(value, NULL, 0); break; /* text generation flag */ case G_INT2: item->text_generation_flags = strtol(value, NULL, 0); break; /* horiz text justification */ case G_INT3: item->horz_just = strtol(value, NULL, 0); break; /* field length */ case G_INT4: item->field_length = strtol(value, NULL, 0); break; /* vert text just */ case G_INT5: item->vert_just = strtol(value, NULL, 0); break; /* rotation angle */ case G_ANGLE1: item->text_rotation = atof(value); break; /* oblique angle */ case G_ANGLE2: item->obliquing_angle = atof(value); break; /* text height */ case G_FLOAT1: item->text_height = strtol(value,NULL,0); break; /* x scale */ case G_FLOAT2: item->rel_x_scale = atof(value); break; /* next group */ case G_FILE_SEP: rewind_file(); return NULL; default: print_group("Unknown group in ENDBLOCK", *group, value, IGNORE); } } }
void *snag_insert(FILE *fpin, char *s, char *value, int *group, int *type) { Insert *item; item = (Insert *)malloc(sizeof(Insert)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->attrs_follow = 0x0; item->translate[0] = item->translate[1] = item->translate[1] = 0.0; item->scale[0] = item->scale[1] = item->scale[2] = 1.0; item->rot = 0.0; item->col_cnt = 1; item->row_cnt = 1; item->col_space = 0.0; item->row_space = 0.0; /* * Assume that we can read to the next entity group */ while (TRUE) { get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { /* common stuff */ handle_common((void *)item, *group, value); continue; } switch (*group) { /* position of insertion */ case G_X_COOR1: item->translate[0] = atof(value); break; case G_Y_COOR1: item->translate[1] = atof(value); break; case G_Z_COOR1: item->translate[2] = atof(value); break; /* attributes follow */ case G_ENTS_FOLLOW: item->attrs_follow = strtol(value,NULL,0); break; /* block name to insert */ case G_NAME: strncpy(item->block_name,value,25); break; /* scales */ case G_FLOAT2: item->scale[0] = atof(value); break; case G_FLOAT3: item->scale[1] = atof(value); break; case G_FLOAT4: item->scale[2] = atof(value); break; /* rotation angle */ case G_ANGLE1: item->rot = atof(value); break; /* column a row counts */ case G_INT1: item->col_cnt = strtol(value, NULL, 0); break; case G_INT2: item->row_cnt = strtol(value, NULL, 0); break; /* column a row spacing */ case G_FLOAT5: item->col_space = atof(value); break; case G_FLOAT6: item->row_space = atof(value); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in INSERT", *group, value, IGNORE); } } }
void *snag_polyline(FILE *fpin, char *s, char *value, int *group, int *type) { Polyline *item; item = (Polyline *)malloc(sizeof(Polyline)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->verts_follow = 0x0; item->elev[0] = item->elev[1] = item->elev[2] = 0.0; item->polyline_flags = 0x0; item->start_width = 0.0; item->end_width = 0.0; item->mesh_m = 0; item->mesh_n = 0; item->smooth_m = 0; item->smooth_n = 0; item->smooth_type = 0; /* * Assume that we can read to the next entity group */ while (TRUE) { get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { /* common stuff */ handle_common((void *)item, *group, value); continue; } switch (*group) { /* position of polyline -- not in spec!!! */ case G_X_COOR1: item->elev[0] = atof(value); break; case G_Y_COOR1: item->elev[1] = atof(value); break; case G_Z_COOR1: item->elev[2] = atof(value); break; /* verts follow flag */ case G_ENTS_FOLLOW: item->verts_follow = strtol(value,NULL,0); break; /* polyline flags */ case G_INT1: item->polyline_flags = strtol(value,NULL,0); break; /* start width */ case G_FLOAT1: item->start_width = atof(value); default_polyline_start_width = item->start_width; break; /* start width */ case G_FLOAT2: item->end_width = atof(value); default_polyline_end_width = item->start_width; break; /* mesh_m */ case G_INT2: item->mesh_m = strtol(value,NULL,0); break; /* mesh_n */ case G_INT3: item->mesh_n = strtol(value,NULL,0); break; /* smooth m */ case G_INT4: item->smooth_m = strtol(value,NULL,0); break; /* smooth n */ case G_INT5: item->smooth_n = strtol(value,NULL,0); break; /* smooth type */ case G_INT6: item->smooth_type = strtol(value,NULL,0); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in POLYLINE", *group, value, IGNORE); } } }
void read_and_decompress_operator(disk_stream *inflight) { z_stream *zlib_stream = inflight->zlib_streams[inflight->request_superp]; int ret; inflight->set_zlib_inflate(); if(inflight->one_shot) { rewind_file(inflight->superp_fd[inflight->request_superp]); } else { inflight->request->set_bufsize (ULONG_MAX, inflight->stream_unit_bytes); } zlib_stream->next_out = inflight->request->buffer; zlib_stream->avail_out = inflight->request->bufsize; while(zlib_stream->avail_out) { if(zlib_stream->avail_in == 0) { unsigned long bytes; flip_buffer * fb = inflight->flip_buffers[inflight->request_superp]; do { unsigned long disk_buffer_pos = inflight->disk_pos[inflight->request_superp]; unsigned long avail = inflight->disk_bytes[inflight->request_superp] - inflight->disk_pos[inflight->request_superp]; if(avail == 0) { bytes = 0; } else { bytes = stream_unit; while(bytes > avail) { if(bytes == DISK_PAGE_SIZE) { break; } bytes = bytes/2; } if(bytes <= avail) { inflight->disk_pos[inflight->request_superp] += bytes; } else { inflight->disk_pos[inflight->request_superp] += avail; } } do_flip_IO(fb, disk_buffer_pos, bytes, true); } while(fb->ready_bytes == 0 && bytes != 0); zlib_stream->avail_in = fb->ready_bytes; zlib_stream->next_in = fb->ready; } ret = inflate(zlib_stream, Z_NO_FLUSH); if(ret == Z_STREAM_END) { inflight->zlib_eof[inflight->request_superp] = true; init_flip_buffer(inflight->flip_buffers[inflight->request_superp], inflight->superp_fd[inflight->request_superp]); reset_inflate_state(zlib_stream); break; } else if(ret == Z_BUF_ERROR) { BOOST_LOG_TRIVIAL(fatal) << "Trying to read past end of compressed stream !" << " disk bytes " << inflight->disk_bytes[inflight->request_superp] << " disk pos " << inflight->disk_pos[inflight->request_superp] << " buffer bytes " << zlib_stream->avail_in << " output bytes " << zlib_stream->avail_out; exit(-1); } else if(ret != Z_OK) { BOOST_LOG_TRIVIAL(fatal) << "Decompression error:(" << ret << ")" << zerr(ret); exit(-1); } } inflight->request->bufsize -= zlib_stream->avail_out; if(inflight->one_shot) { inflight->one_shot = false; } inflight->request->uptodate = true; return; }
void *snag_text(FILE *fpin, char *s, char *value, int *group, int *type) { Text *item; item = (Text *)malloc(sizeof(Text)); if (!item) { printf("malloc failed\n"); return NULL; } /* common defaults */ common_defaults((void *)item); /* entity defaults */ item->rot = 0.0; item->x_scale = 1.0; item->oblique = 0.0; strncpy(item->style,"STANDARD",10); item->flags = 0x0; item->just = 0.0; item->align_pt[0] = item->align_pt[1] = item->align_pt[2] = 0.0; while (TRUE) { /* * Assume that we can read to the next entity group */ get_next_group(fpin, REQUIRED, s, value, group, type); if (is_common(*group)) { /* common stuff */ handle_common((void *)item, *group, value); continue; } switch (*group) { /* val */ case G_TEXT_STRING: strncpy(item->val,value,25); break; /* height */ case G_FLOAT1: item->height = atof(value); break; /* x_scale */ case G_FLOAT2: item->x_scale = atof(value); break; /* rot */ case G_ANGLE1: item->rot = atof(value); break; /* oblique */ case G_ANGLE2: item->oblique = atof(value); break; /* style */ case G_TEXT_STYLE: strncpy(item->style,value,10); break; /* flags */ case G_INT2: item->flags = strtol(value,NULL,0); break; /* just */ case G_INT3: item->just = strtol(value,NULL,0); break; /* point */ case G_X_COOR1: item->pt[0] = atof(value); break; case G_Y_COOR1: item->pt[1] = atof(value); break; case G_Z_COOR1: item->pt[2] = atof(value); break; /* align_pt */ case G_X_COOR2: item->align_pt[0] = atof(value); break; case G_Y_COOR2: item->align_pt[1] = atof(value); break; case G_Z_COOR2: item->align_pt[2] = atof(value); break; /* next group */ case G_FILE_SEP: rewind_file(); return (void *)item; default: print_group("Unknown group in TEXT", *group, value, IGNORE); } } }
/* * HEADER:100:rewind_file:setup:1:rewinds file if already opened, X=filename, CW2 * only useful when wgrib is called as a subroutine, no error if failure */ int f_rewind_file(ARG1) { if (mode == -1) { rewind_file(arg1); } return 0; }