int draw_outline(void) { int raster_size; row = col = top = 0; /* get started for read of first */ bottom = 1; /* line from raster map */ scan_length = read_next(); k = 0; raster_size = Rast_cell_size(map_type); while (read_next()) { /* read rest of file, one row at *//* a time */ n1 = Rast_row_to_northing((double)row - 1., &(PS.w)); n2 = Rast_row_to_northing((double)row, &(PS.w)); n3 = Rast_row_to_northing((double)row + 1., &(PS.w)); for (col = 0; col < scan_length - 1; col++) { e1 = Rast_col_to_easting((double)col - 1., &(PS.w)); e2 = Rast_col_to_easting((double)col, &(PS.w)); e3 = Rast_col_to_easting((double)col + 1., &(PS.w)); tl = G_incr_void_ptr(buffer[top], col * raster_size); /* top left in window */ tr = G_incr_void_ptr(buffer[top], (col + 1) * raster_size); /* top right in window */ bl = G_incr_void_ptr(buffer[bottom], col * raster_size); /* bottom left in window */ br = G_incr_void_ptr(buffer[bottom], (col + 1) * raster_size); /* bottom right in window */ draw_boundaries(); if (k == 3) k = 0; } row++; } return 0; } /* draw_outlines */
/* Funkcja obsługująca sesję z komisją */ void* serve_committee(void* mesg_type) { long msg_type = atol(mesg_type); long l, k, n, rows = 0, sum = 0; while (1) { l = read_next(msg_type); if (l == -1) break; k = read_next(msg_type); n = read_next(msg_type); rows++; sum += n; } send_val(msg_snd_kom_id, msg_type, rows); send_val(msg_snd_kom_id, msg_type, sum); //procesy--; //(zapisujemy dane) return 0; }
StTextFileScanner::StTextFileScanner(const char * file, bool skip) : mFile(fopen(file, "r")), mDone(false), mSkipBlanks(skip) { read_next(); }
static void read_array(ParseInfo pi, const char *key) { if (pi->has_array_start) { call_no_value(pi->handler, oj_array_start_id, key); } pi->s++; next_non_white(pi); if (']' == *pi->s) { pi->s++; } else { while (1) { read_next(pi, 0); next_non_white(pi); if (',' == *pi->s) { pi->s++; } else if (']' == *pi->s) { pi->s++; break; } else { if (pi->has_error) { call_error("invalid format, expected , or ] while in an array", pi, __FILE__, __LINE__); } raise_error("invalid format, expected , or ] while in an array", pi->str, pi->s); } } } if (pi->has_array_end) { call_no_value(pi->handler, oj_array_end_id, key); } }
int Range::iterator::reset (const Range& rng) { cur_node = NULL; file_handle = NULL; atEnd = 0; myrange = &rng; if (myrange->GetType() == RNG_TYPE_FILE) { filename = myrange->GetDefStr()+1; if ( (file_handle = fopen(filename, "r")) == NULL) { fprintf(stderr, "Range::iterator: unable to read file '%s'\n", filename); exit(-1); } buflen = 1024; buf = NULL; bufpos = 0; bufline = 0; if ( read_next(&cur_value, file_handle, filename) == 0) { atEnd = 1; } } else { // Assume regular range cur_node = rng.getRangeList(); if (cur_node) { cur_value = cur_node->start; } else { // Empty list cur_value = 0; atEnd = 1; } } return cur_value; }
PyObject * next() { auto obj = read_next(); if( is_array( obj ) ) { if( obj.as.array_size ) { push_list( obj.as.array_size ); return nullptr; } return PyList_New( 0 ); } if( is_map( obj ) ) { if( obj.as.map_size ) { push_dict( obj.as.map_size ); return nullptr; } return PyDict_New(); } return read_simple( obj ); }
void next() { const auto next_val = read_next(detail::has_read_next<stream_type>{}, ec); if (next_val) { val_ = *next_val; } else { done_ = true; } }
I read_prev() { assert(start_ <= position_ && position_ < end_); I result = read_next(); if (position_ != 1 && _fseeki64(pFile, -2 * sizeof(I), SEEK_CUR) != 0) { perror("Error seek"); exit(1); } position_-=2; return result; }
int last_comp_index(IFILE *ifile) /*;last_comp_index*/ { /* determine the number of comp units in ifile. */ long rec; int i; i=0; for (rec=read_init(ifile); rec!=0; rec=read_next(ifile,rec)) i++; return i; }
int extract_areas(void) { double nullVal; row = col = top = 0; /* get started for read of first */ bottom = 1; /* line from raster map */ area_num = 0; tl_area = 0; G_set_d_null_value(&nullVal, 1); /* represents the "outside", the external null values */ assign_area(nullVal, 0); G_message(_("Extracting areas...")); scan_length = read_next(); while (read_next()) { /* read rest of file, one row at *//* a time */ G_percent(row, n_rows, 2); for (col = 0; col < scan_length - 1; col++) { tl = get_raster_value(buffer[top], col); /* top left in window */ tr = get_raster_value(buffer[top], col + 1); /* top right */ bl = get_raster_value(buffer[bottom], col); /* bottom left */ br = get_raster_value(buffer[bottom], col + 1); /* bottom right */ update_list(nabors()); } if (h_ptr != NULPTR) /* if we have a loose end, */ end_hline(); /* tie it down */ row++; } G_percent(row, n_rows, 2); write_area(a_list, e_list, area_num, n_equiv); G_free(a_list); G_free(e_list); return 0; } /* extract_areas */
nmea_port(boost::asio::io_service& io_service, std::string& port_name, unsigned int baud_rate) : m_serial(io_service), m_buffer(max_sentence_length) { m_serial.set_option(boost::asio::serial_port_base::baud_rate(baud_rate)); m_serial.open(port_name); read_next(); }
char Read::ReadBit() { if (_bits_count_read / 8 > _buffer_in_size - 1) { read_next(); } int bit_pos = _bits_count_read % 8; int byte_pos = _bits_count_read / 8; if (bit_pos == 0) { unsigned char answ = _buffer_in[byte_pos] >> 7; _bits_count_read++; return answ; }
double match_digit(){ char buf[128]; int i = 0; do { look_ahead = read_next(); buf[i++] = look_ahead; }while((look_ahead <='9' && look_ahead >='0') || look_ahead=='.'); buf[i] = 0; match_space(); return atof(buf); }
int FastqFile::read_next() { const int r = kseq_read(kseq); if (r == -1) { open_next(); if (fnit != fnames.end()) return read_next(); } return r; }
static void md5_stream(lua_State *L, char *output) { WORD32 d[4]; char tmp[64]; size_t lastlen = 0; size_t len = 0; size_t total; lua_pushnil(L); // read_next would pop 1 const char * message = read_next(L, &len); if (message == NULL) { return md5("", 0, output); // empty string } total = len; inic_digest(d); do { lastlen = md5_cat(tmp, lastlen, message, len, d); message = read_next(L, &len); total += len; } while (message != NULL); md5_close(tmp, lastlen, d, total); word32tobytes(d, output); }
std::string match_str(){ char buf[128]; assert(look_ahead == '\"'); memset(buf, 0, sizeof(buf)); int i = 0; do { look_ahead = read_next(); buf[i++] = look_ahead; }while(look_ahead != '\"'); buf[i-1] = 0; match_space(); return std::string(buf); }
void handle_line(const boost::system::error_code& error, size_t bytes_received) { if(!error) { boost::asio::streambuf::const_buffers_type bufs = m_buffer.data(); std::string line(boost::asio::buffers_begin(bufs), boost::asio::buffers_begin(bufs) + bytes_received); std::cerr << "Sentence: " << line << std::endl; m_buffer.consume(bytes_received); read_next(); } else { std::cerr << "Error: " << error << std::endl; } }
void assert_done() { bool err = false; try { read_next(); } catch (...) { err = true; } if (err || parser_.state() != state::start) { err_handler_->error(std::error_code(json_parser_errc::extra_character, json_parser_category()), parser_.parsing_context()); } }
static Errcode read_first(Image_file *ifile, Rcel *screen) /***************************************************************************** * Seek to the beginning of an open file, and then read in the * first frame of image into screen. ****************************************************************************/ { Ifile *gf = (Ifile *)ifile; /* There's a bit of data past ifile header */ Errcode err; /* skip past header & offset list */ if ((err = fseek(gf->file, gf->rif.frame_count * sizeof(long) + sizeof(Riff_head), SEEK_SET)) < Success) return(err); return(read_next(ifile, screen)); }
static void read_hash(ParseInfo pi, const char *key) { const char *ks; if (pi->has_hash_start) { call_no_value(pi->handler, oj_hash_start_id, key); } pi->s++; next_non_white(pi); if ('}' == *pi->s) { pi->s++; } else { while (1) { next_non_white(pi); ks = read_quoted_value(pi); next_non_white(pi); if (':' == *pi->s) { pi->s++; } else { if (pi->has_error) { call_error("invalid format, expected :", pi, __FILE__, __LINE__); } raise_error("invalid format, expected :", pi->str, pi->s); } read_next(pi, ks); next_non_white(pi); if ('}' == *pi->s) { pi->s++; break; } else if (',' == *pi->s) { pi->s++; } else { if (pi->has_error) { call_error("invalid format, expected , or } while in an object", pi, __FILE__, __LINE__); } raise_error("invalid format, expected , or } while in an object", pi->str, pi->s); } } } if (pi->has_hash_end) { call_no_value(pi->handler, oj_hash_end_id, key); } }
// returns >=0 (length of seq), -1 end of last file, -2 truncated quality string int FastqFile::read_next(string &seq, size_t& id) { const int r = kseq_read(kseq); if (r >= 0) seq.assign(kseq->seq.s); else if (r == -1) { open_next(); if (fnit != fnames.end()){ id = file_no; return read_next(seq, id); } } return r; }
std::string Avro2PBReader::read_next() { if(!get_is_valid()){ return ""; } if(!avro_reader_){ avro_reader_ = new t_avro_reader (avro_filenames_[cur_file_].c_str(), IMP::npctransport::get_avro_data_file_schema()); } IMP_npctransport::wrapper data; if( ! (avro_reader_->read(data)) ){ // no more data = go to next advance_current_reader(); return read_next(); } return std::string(data.value.begin(), data.value.end()); }
static int get_next(stream_t *stream) { int result; if (stream->dst_codec_type) { do { result = encode_next(stream); if (result <= 0) { return result; } } while (stream->dst_size == 0); stream->data = stream->dst_data; stream->size = stream->dst_size; } else { result = read_next(stream); stream->data = stream->src_packet.data; stream->size = stream->src_packet.size; } return result; }
int Range::iterator::next_el(void) { if (file_handle) { // Assume a file type if ( read_next(&cur_value, file_handle, filename) == 0) { atEnd = 1; } } else if (cur_node) { if (cur_value == cur_node->end) { // Need to move on to next node cur_node = cur_node->next; if (cur_node) { cur_value = cur_node->start; } else { cur_value = 0; atEnd = 1; } } else { cur_value += cur_node->step; } } return cur_value; }
// returns >=0 (length of seq), -1 end of last file, -2 truncated quality string int FastqFile::read_next(char* read, size_t* read_len, string &seq, size_t* seq_len, unsigned int* file_id, char* qual) { int r; if ((r = kseq_read(kseq)) >= 0) { memcpy(read, kseq->name.s, kseq->name.l + 1); // 0-terminated string *read_len = kseq->name.l; seq.assign(kseq->seq.s); *seq_len = kseq->seq.l; if (qual != NULL) memcpy(qual, kseq->qual.s, kseq->qual.l + 1); // 0-terminated string if (file_id != NULL) *file_id = file_no / 2; } else if (r == -1) { open_next(); if (fnit != fnames.end()) return read_next(read, read_len, seq, seq_len, file_id, qual); return -1; } return r; }
/* Funkcja obsługująca sesję z raportem */ void* serve_report(void* mesg_type) { long msg_type = atol(mesg_type); long l = read_next(msg_type); long x, y, z, v; int i, j; long ** rows; if (l > 0) { rows = malloc(sizeof(long)); rows[0] = malloc(sizeof(long) * K); } else { rows = malloc(sizeof(long) * L); for (i = 0; i < L; i++) rows[i] = malloc(sizeof(long) * K); } send_val(msg_snd_rap_id, msg_type, K); send_val(msg_snd_rap_id, msg_type, M); pthread_rwlock_rdlock(&rwlock); x = db.committees_served; y = db.could_vote; z = db.valid_votes; v = db.invalid_votes; if (l > 0) { for (i = 0; i < K; i++) rows[0][i] = db.votes[l-1][i]; } else { for (i = 0; i < L; i++) for (j = 0; j < K; j++) rows[i][j] = db.votes[i][j]; } pthread_rwlock_unlock(&rwlock); send_val(msg_snd_rap_id, msg_type, x); send_val(msg_snd_rap_id, msg_type, y); send_val(msg_snd_rap_id, msg_type, z); send_val(msg_snd_rap_id, msg_type, v); if (l > 0) { for (i = 0; i < K; i++) send_val(msg_snd_rap_id, msg_type, rows[0][i]); } else { for (i = 0; i < L; i++) for (j = 0; j < K; j++) send_val(msg_snd_rap_id, msg_type, rows[i][j]); } if (l > 0) free(rows[0]); else { for (i = 0; i < L; i++) free(rows[i]); } free(rows); return 0; }
static int decode_next(stream_t *stream) { int result, got_frame; AVFrame *frame = stream->decode_frame; result = read_next(stream); if (result <= 0) { return result; } avcodec_get_frame_defaults(frame); result = avcodec_decode_audio4(stream->decoder, frame, &got_frame, &stream->src_packet); if (result < 0) { /* Decoding right after seeking, especially with mp3, might fail because * we don't have the frame header available yet. */ ++stream->error_counter; musicd_log(LOG_VERBOSE, "stream", "can't decode: %s, error_counter = %d", strerror(AVUNERROR(result)), stream->error_counter); if (stream->error_counter > 10) { musicd_log(LOG_ERROR, "stream", "error_counter too high, failing: %s", strerror(AVUNERROR(result))); return -1; } /* Technically we failed, but we are going to try again so make it look * like success... */ return 1; } if (stream->error_counter) { musicd_log(LOG_VERBOSE, "stream", "recovered from error_counter = %d", stream->error_counter); stream->error_counter = 0; } if (!got_frame) { return 1; } if (stream->resampler) { if (stream->resample_frame->nb_samples < frame->nb_samples) { av_free(stream->resample_buf); int buf_size = av_samples_get_buffer_size(NULL, stream->encoder->channels, frame->nb_samples, stream->encoder->sample_fmt, 0); stream->resample_buf = av_mallocz(buf_size); stream->resample_frame->nb_samples = frame->nb_samples; result = avcodec_fill_audio_frame(stream->resample_frame, stream->encoder->channels, stream->encoder->sample_fmt, stream->resample_buf, buf_size, 0); } result = resampler_convert(stream->resampler, stream->resample_frame->extended_data, stream->resample_frame->nb_samples, (const uint8_t **)frame->extended_data, frame->nb_samples); av_audio_fifo_write(stream->src_buf, (void **)stream->resample_frame->extended_data, result); } else { av_audio_fifo_write(stream->src_buf, (void **)frame->extended_data, frame->nb_samples); } return 1; }
int main () { char line[40], *str, cmd, last_cmd = 0; if (!(ld = open_list ())) { fprintf (stderr, "Error opening List\n"); exit (1); } printf ("Type \'-?\' or \'-h\' for Help contents\n"); while (1) { printf ("list> "); fgets (line, 40, stdin); for (str = line; *str == ' ' || *str == '\t'; str++) ; str[strchr (str, '\n') - str] = '\0'; switch (*str) { case '\0' : continue; default : append (ld, str); break; case '.' : cmd = last_cmd; case '-' : if (*str != '.') cmd = last_cmd = *++str; switch (cmd) { default : fprintf (stderr, "Invalid Command\n"); continue; case '?' : case 'h' : case 'H' : printf ("Type any name to add to list\n" "-r<name> to remove from list\n" "\'-d\' to display all list items\n" "\'-f\' to print the first item in list\n" "\'-l\' to print the last item in list\n" "\'-n\' to print the next list item\n" "\'-p\' to print the previous list item\n" "\'.\' to repeat last command\n" //"\'-s\' to sort list items\n" "\'-e\' to exit\n"); break; case 'd' : case 'D' : print_list (ld); break; case 'f' : case 'F' : if (read_first (ld, str)) PRINT_MSG case 'l' : case 'L' : if (read_last (ld, str)) PRINT_MSG case 'n' : case 'N' : if (read_next (ld, str)) PRINT_MSG case 'p' : case 'P' : if (read_prev (ld, str)) PRINT_MSG case 'r' : case 'R' : if (delete (ld, ++str)) { fprintf (stderr, "%s not on list\n", str); continue; } else printf ("%s removed\n", str); break; case 'e' : case 'E' : print_list (ld); close_list (ld); printf ("===> End of App <===\n"); exit (0); } } } }
message_part_deserialize_part(struct deserialize_context *ctx, struct message_part *parent, unsigned int siblings, struct message_part **part_r) { struct message_part *p, *part, *first_part, **next_part; unsigned int children_count; uoff_t pos; bool root = parent == NULL; first_part = NULL; next_part = NULL; while (siblings > 0) { siblings--; part = p_new(ctx->pool, struct message_part, 1); part->parent = parent; for (p = parent; p != NULL; p = p->parent) p->children_count++; if (!read_next(ctx, &part->flags, sizeof(part->flags))) return FALSE; if (root) root = FALSE; else { if (!read_next(ctx, &part->physical_pos, sizeof(part->physical_pos))) return FALSE; } if (part->physical_pos < ctx->pos) { ctx->error = "physical_pos less than expected"; return FALSE; } if (!read_next(ctx, &part->header_size.physical_size, sizeof(part->header_size.physical_size))) return FALSE; if (!read_next(ctx, &part->header_size.virtual_size, sizeof(part->header_size.virtual_size))) return FALSE; if (part->header_size.virtual_size < part->header_size.physical_size) { ctx->error = "header_size.virtual_size too small"; return FALSE; } if (!read_next(ctx, &part->body_size.physical_size, sizeof(part->body_size.physical_size))) return FALSE; if (!read_next(ctx, &part->body_size.virtual_size, sizeof(part->body_size.virtual_size))) return FALSE; if ((part->flags & (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_MESSAGE_RFC822)) != 0) { if (!read_next(ctx, &part->body_size.lines, sizeof(part->body_size.lines))) return FALSE; } if (part->body_size.virtual_size < part->body_size.physical_size) { ctx->error = "body_size.virtual_size too small"; return FALSE; } if ((part->flags & (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_MESSAGE_RFC822)) != 0) { if (!read_next(ctx, &children_count, sizeof(children_count))) return FALSE; } else { children_count = 0; } if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) { /* Only one child is possible */ if (children_count == 0) { ctx->error = "message/rfc822 part has no children"; return FALSE; } if (children_count != 1) { ctx->error = "message/rfc822 part " "has multiple children"; return FALSE; } } if (children_count > 0) { /* our children must be after our physical_pos+header and the last child must be within our size. */ ctx->pos = part->physical_pos + part->header_size.physical_size; pos = ctx->pos + part->body_size.physical_size; if (!message_part_deserialize_part(ctx, part, children_count, &part->children)) return FALSE; if (ctx->pos > pos) { ctx->error = "child part location exceeds our size"; return FALSE; } ctx->pos = pos; /* save it for above check for parent */ } if (first_part == NULL) first_part = part; if (next_part != NULL) *next_part = part; next_part = &part->next; } *part_r = first_part; return TRUE; }
// Deprecated void read() { read_next(); }