#pragma implementation /* $Log: textlist.cc,v $ /* Revision 1.1.1.1 2000/12/16 20:45:45 stuart /* Released TUIPeer sources /* // Revision 1.3 1993/12/13 17:36:03 stuart // strip nulls from message as well as '\r' // */ #include #include #include #include #include #include "textlist.h" void TextArray::print() { puts("------------------"); for (int i = 0; ; ++i) { const char *p = (*this)[i]; if (!p) break; puts(p); } } int TextArray::size() { int i; for (i = 0; (*this)[i]; ++i); return i; } const char *TextList::operator[](int i) { if (i < idx || idx < 0) { if (!first()) return 0; idx = 0; } while (idx < i) { if (!next()) return 0; ++idx; } return *this; } const char *StringArray::operator[](int i) { if (i < 0 || i >= txt.size()) return 0; return txt[i]; } StringArray::StringArray() { h = new Obstack; } StringArray::~StringArray() { delete h; } void StringArray::clear() { delete h; h = new Obstack; //h->free(0); // free(0) no longer works txt.clear(); } char const *StringArray::copy(const char *s) { return (char *)h->copy(s); } int StringArray::add(const char *s) { txt.add((char *)h->copy(s)); return 1; } void StringArray::put(const char *s) { txt.add(s); } /* binary sort */ void sort(const char **a,int n) { for (int gap = n/2; gap > 0; gap /= 2) { for (int i = gap; i < n; ++i) { for (int j = i - gap; j >= 0; j -= gap) { if (strcmp(a[j],a[j+gap]) <= 0) break; const char * temp = a[j]; a[j] = a[j+gap]; a[j+gap] = temp; } } } } void StringArray::sort() { int n = txt.size(); if (n > 1) ::sort(&txt[0],n); }