static chtype * ChStr(const char *source) { if (source != 0) { size_t need = ChLen(source) + 1; int n = 0; if (need > temp_length) { temp_length = need * 2; temp_buffer = typeRealloc(chtype, temp_length, temp_buffer); } do { const char *s; chtype ch = UChar(*source++); if (!pass_ctls && (s = unctrl(ch)) != 0) { while (*s != '\0') { temp_buffer[n++] = UChar(*s++); } } else { temp_buffer[n++] = ch; } } while (source[0] != 0); temp_buffer[n] = 0; } else if (temp_buffer != 0) { free(temp_buffer); temp_buffer = 0; temp_length = 0; } return temp_buffer; }
static char * _nc_trace_alloc(int bufnum, size_t want) { #ifdef TRACE char *result = 0; if (bufnum >= 0) { if ((size_t) (bufnum + 1) > MySize) { size_t need = (bufnum + 1) * 2; if ((MyList = typeRealloc(TRACEBUF, need, MyList)) != 0) { while (need > MySize) MyList[MySize++].text = 0; } } if (MyList != 0) { if (MyList[bufnum].text == 0 || want > MyList[bufnum].size) { MyList[bufnum].text = typeRealloc(char, want, MyList[bufnum].text); if (MyList[bufnum].text != 0) MyList[bufnum].size = want; } result = MyList[bufnum].text; } }
void LYAllocHistory(int entries) { CTRACE((tfp, "LYAllocHistory %d vs %d\n", entries, size_history)); if (entries + 1 >= size_history) { unsigned want; int save = size_history; size_history = (entries + 2) * 2; want = (unsigned) size_history *(unsigned) sizeof(*history); if (history == 0) { history = typeMallocn(HistInfo, want); } else { history = typeRealloc(HistInfo, history, want); } if (history == 0) outofmem(__FILE__, "LYAllocHistory"); assert(history != NULL); while (save < size_history) { memset(&history[save++], 0, sizeof(history[0])); } } CTRACE((tfp, "...LYAllocHistory %d vs %d\n", entries, size_history)); }
/* * Add a window to our list. */ static void add_window(WINDOW *parent, WINDOW *child) { static unsigned have = 0; unsigned need = ((num_windows + 1) | 31) + 1; keypad(child, TRUE); if (need > have) { all_windows = typeRealloc(FRAME, need, all_windows); if (!all_windows) failed("add_window"); } all_windows[num_windows].parent = parent; all_windows[num_windows].child = child; num_windows++; }
static void realign_data(TERMTYPE *to, char **ext_Names, int ext_Booleans, int ext_Numbers, int ext_Strings) { int n, m, base; int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings); if (to->ext_Booleans != ext_Booleans) { EXTEND_NUM(num_Booleans, ext_Booleans); to->Booleans = typeRealloc(NCURSES_SBOOL, to->num_Booleans, to->Booleans); for (n = to->ext_Booleans - 1, m = ext_Booleans - 1, base = to->num_Booleans - (m + 1); m >= 0; m--) { if (find_name(to->ext_Names, limit, ext_Names[m])) { to->Booleans[base + m] = to->Booleans[base + n--]; } else { to->Booleans[base + m] = FALSE; } } to->ext_Booleans = UShort(ext_Booleans); } if (to->ext_Numbers != ext_Numbers) { EXTEND_NUM(num_Numbers, ext_Numbers); to->Numbers = typeRealloc(short, to->num_Numbers, to->Numbers); for (n = to->ext_Numbers - 1, m = ext_Numbers - 1, base = to->num_Numbers - (m + 1); m >= 0; m--) { if (find_name(to->ext_Names, limit, ext_Names[m + ext_Booleans])) { to->Numbers[base + m] = to->Numbers[base + n--]; } else { to->Numbers[base + m] = ABSENT_NUMERIC; } } to->ext_Numbers = UShort(ext_Numbers); }
static struct name_table_entry const * _nc_extend_names(ENTRY * entryp, char *name, int token_type) { static struct name_table_entry temp; TERMTYPE *tp = &(entryp->tterm); unsigned offset = 0; unsigned actual; unsigned tindex; unsigned first, last, n; bool found; switch (token_type) { case BOOLEAN: first = 0; last = tp->ext_Booleans; offset = tp->ext_Booleans; tindex = tp->num_Booleans; break; case NUMBER: first = tp->ext_Booleans; last = tp->ext_Numbers + first; offset = tp->ext_Booleans + tp->ext_Numbers; tindex = tp->num_Numbers; break; case STRING: first = tp->ext_Booleans + tp->ext_Numbers; last = tp->ext_Strings + first; offset = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings; tindex = tp->num_Strings; break; case CANCEL: actual = NUM_EXT_NAMES(tp); for (n = 0; n < actual; n++) { if (!strcmp(name, tp->ext_Names[n])) { if (n > (unsigned) (tp->ext_Booleans + tp->ext_Numbers)) { token_type = STRING; } else if (n > tp->ext_Booleans) { token_type = NUMBER; } else { token_type = BOOLEAN; } return _nc_extend_names(entryp, name, token_type); } } /* Well, we are given a cancel for a name that we don't recognize */ return _nc_extend_names(entryp, name, STRING); default: return 0; } /* Adjust the 'offset' (insertion-point) to keep the lists of extended * names sorted. */ for (n = first, found = FALSE; n < last; n++) { int cmp = strcmp(tp->ext_Names[n], name); if (cmp == 0) found = TRUE; if (cmp >= 0) { offset = n; tindex = n - first; switch (token_type) { case BOOLEAN: tindex += BOOLCOUNT; break; case NUMBER: tindex += NUMCOUNT; break; case STRING: tindex += STRCOUNT; break; } break; } } if (!found) { switch (token_type) { case BOOLEAN: tp->ext_Booleans += 1; tp->num_Booleans += 1; tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans); for (last = tp->num_Booleans - 1; last > tindex; last--) tp->Booleans[last] = tp->Booleans[last - 1]; break; case NUMBER: tp->ext_Numbers += 1; tp->num_Numbers += 1; tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers); for (last = tp->num_Numbers - 1; last > tindex; last--) tp->Numbers[last] = tp->Numbers[last - 1]; break; case STRING: tp->ext_Strings += 1; tp->num_Strings += 1; tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings); for (last = tp->num_Strings - 1; last > tindex; last--) tp->Strings[last] = tp->Strings[last - 1]; break; } actual = NUM_EXT_NAMES(tp); tp->ext_Names = typeRealloc(char *, actual, tp->ext_Names); while (--actual > offset) tp->ext_Names[actual] = tp->ext_Names[actual - 1]; tp->ext_Names[offset] = _nc_save_str(name); } temp.nte_name = tp->ext_Names[offset]; temp.nte_type = token_type; temp.nte_index = tindex; temp.nte_link = -1; return &temp; }