qli_rlb* GEN_rlb_extend(qli_rlb* rlb) { /************************************** * * G E N _ r l b _ e x t e n d * ************************************** * * Functional description * * Allocate a new larger request language buffer * and copy generated request language into it * **************************************/ if (!rlb) rlb = (qli_rlb*) ALLOCD(type_rlb); UCHAR* const old_string = rlb->rlb_base; const ULONG len = rlb->rlb_data - rlb->rlb_base; rlb->rlb_length += RLB_BUFFER_SIZE; UCHAR* new_string = (UCHAR*) ALLQ_malloc((SLONG) rlb->rlb_length); if (old_string) { memcpy(new_string, old_string, len); ALLQ_free(old_string); } rlb->rlb_base = new_string; rlb->rlb_data = new_string + len; rlb->rlb_limit = rlb->rlb_data + RLB_BUFFER_SIZE - RLB_SAFETY_MARGIN; return rlb; }
void Matrix::resizeAndKeep(size_t r, size_t c) { if (r == m_nrows && c == m_ncols) return; if ((!r && c) || (r && !c)) throw Error("invalid dimension"); // Row and Column values that will be kept. int nrows = std::min(m_nrows, r); int ncols = std::min(m_ncols, c); // Column difference. int clm_diff = c - m_ncols; // Matrix copy. double* newdata = ALLOCD(m_size + 1); std::memcpy(newdata, m_data, m_size * sizeof(double)); erase(); m_nrows = r; m_ncols = c; m_size = r * c; m_data = ALLOCD(m_size + 1); m_counter = m_data + m_size; *m_counter = 1; fill(0); int itr = 0, icr = 0; for (int i = 0; i < nrows; ++i) { for (int j = 0; j < ncols; ++j) { m_data[(i * ncols + j) + icr] = newdata[itr]; ++itr; } clm_diff > 0 ? icr += clm_diff : itr -= clm_diff; } std::free(newdata); }
void Matrix::resize(size_t r, size_t c) { erase(); if ((!r && c) || (r && !c)) throw Error("invalid dimension"); m_nrows = r; m_ncols = c; m_size = r * c; m_data = ALLOCD(m_size + 1); m_counter = m_data + m_size; *m_counter = 1; }
void Matrix::split(void) { if (!m_size) return; if ((*m_counter) == 1) return; (*m_counter)--; double* newdata = ALLOCD(m_size + 1); std::memcpy(newdata, m_data, m_size * sizeof(double)); m_data = newdata; m_counter = m_data + m_size; *m_counter = 1; }
pics* PIC_analyze(const TEXT* string, const dsc* desc) { /************************************** * * P I C _ a n a l y z e * ************************************** * * Functional description * Analyze a picture in preparation for formatting. * **************************************/ if (!string) { if (!desc) return NULL; string = default_edit_string(desc, NULL); } pics* picture = (pics*) ALLOCD(type_pic); picture->pic_string = picture->pic_pointer = string; // Make a first pass just counting characters bool debit = false; TEXT c; while ((c = generate(picture)) && c != '?') { c = UPPER(c); switch (c) { case 'X': case 'A': ++picture->pic_chars; break; case '9': case 'Z': case '*': // Count all digits; // count them as fractions only after a decimal pt and // before an E ++picture->pic_digits; if (picture->pic_decimals && !picture->pic_exponents) ++picture->pic_fractions; break; case 'H': ++picture->pic_hex_digits; break; case '.': ++picture->pic_decimals; break; case '-': case '+': picture->pic_flags |= PIC_signed; case '$': if (picture->pic_chars || picture->pic_exponents) ++picture->pic_literals; else if (picture->pic_floats) ++picture->pic_digits; else ++picture->pic_floats; break; case 'M': ++picture->pic_months; break; case 'D': // DB is ambiguous, could be Day Blank or DeBit... if (UPPER(*picture->pic_pointer) == 'B') { ++picture->pic_pointer; ++picture->pic_literals; debit = true; } ++picture->pic_days; break; case 'Y': ++picture->pic_years; break; case 'J': ++picture->pic_julians; break; case 'W': ++picture->pic_weekdays; break; case 'N': ++picture->pic_nmonths; break; case 'E': ++picture->pic_exponents; break; case 'G': ++picture->pic_float_digits; break; case '(': case ')': picture->pic_flags |= PIC_signed; ++picture->pic_brackets; break; case '\'': case '"': picture->pic_flags |= PIC_literal; { TEXT d; // Shouldn't UPPER be used on d before comparing with c? while ((d = generate(picture)) && d != c) ++picture->pic_literals; } picture->pic_flags &= ~PIC_literal; break; case '\\': ++picture->pic_literals; picture->pic_flags |= PIC_literal; generate(picture); picture->pic_flags &= ~PIC_literal; break; case 'C': case 'R': picture->pic_flags |= PIC_signed; ++picture->pic_brackets; if (generate(picture)) ++picture->pic_brackets; else ++picture->pic_count; break; case 'P': ++picture->pic_meridian; break; case 'T': if (picture->pic_hours < 2) ++picture->pic_hours; else if (picture->pic_minutes < 2) ++picture->pic_minutes; else ++picture->pic_seconds; break; case 'B': case '%': case ',': case '/': default: ++picture->pic_literals; break; } } if (c == '?') picture->pic_missing = PIC_analyze(picture->pic_pointer, 0); // if a DB showed up, and the string is numeric, treat the DB as DeBit if (debit && (picture->pic_digits || picture->pic_hex_digits)) { --picture->pic_days; --picture->pic_literals; picture->pic_flags |= PIC_signed; ++picture->pic_brackets; ++picture->pic_brackets; } picture->pic_print_length = picture->pic_digits + picture->pic_hex_digits + picture->pic_chars + picture->pic_floats + picture->pic_literals + picture->pic_decimals + picture->pic_months + picture->pic_days + picture->pic_weekdays + picture->pic_years + picture->pic_nmonths + picture->pic_julians + picture->pic_brackets + picture->pic_exponents + picture->pic_float_digits + picture->pic_hours + picture->pic_minutes + picture->pic_seconds + picture->pic_meridian; if (picture->pic_missing) { picture->pic_length = MAX(picture->pic_print_length, picture->pic_missing->pic_print_length); picture->pic_missing->pic_length = picture->pic_length; } else picture->pic_length = picture->pic_print_length; if (picture->pic_days || picture->pic_weekdays || picture->pic_months || picture->pic_nmonths || picture->pic_years || picture->pic_hours || picture->pic_julians) { picture->pic_type = pic_date; } else if (picture->pic_exponents || picture->pic_float_digits) picture->pic_type = pic_float; else if (picture->pic_digits || picture->pic_hex_digits) picture->pic_type = pic_numeric; else picture->pic_type = pic_alpha; return picture; }