From d8f5dd80de28b9fb20fbf21fd0e5baf7e007f433 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 19:25:03 +0000 Subject: [PATCH] flower-1.1.4 --- flower/associter.hh | 39 -------- flower/datafile.cc | 95 ------------------ flower/datafile.hh | 59 ----------- flower/stringdata.hh | 94 ------------------ flower/stringdata.inl | 215 ---------------------------------------- flower/stringhandle.hh | 70 ------------- flower/stringhandle.inl | 151 ---------------------------- flower/textdb.cc | 48 --------- flower/textdb.hh | 55 ---------- flower/textstream.cc | 31 ------ flower/textstream.hh | 74 -------------- 11 files changed, 931 deletions(-) delete mode 100644 flower/associter.hh delete mode 100644 flower/datafile.cc delete mode 100644 flower/datafile.hh delete mode 100644 flower/stringdata.hh delete mode 100644 flower/stringdata.inl delete mode 100644 flower/stringhandle.hh delete mode 100644 flower/stringhandle.inl delete mode 100644 flower/textdb.cc delete mode 100644 flower/textdb.hh delete mode 100644 flower/textstream.cc delete mode 100644 flower/textstream.hh diff --git a/flower/associter.hh b/flower/associter.hh deleted file mode 100644 index 34b88df22d..0000000000 --- a/flower/associter.hh +++ /dev/null @@ -1,39 +0,0 @@ -/* - associter.hh -- part of flowerlib - - (c) 1996 Han-Wen Nienhuys -*/ - -#ifndef ASSOCITER_HH -#define ASSOCITER_HH - -#include "assoc.hh" - -/// an iterator for the #Assoc# class -template -struct Assoc_iter { - int i; - Assoc &assoc_; - /// we don't want to be bothered by const correctness - Assoc_iter(const Assoc &a) : - assoc_((Assoc &)a) - { - i= next(0); - } - int next(int j) { - while (j < assoc_.arr.size() && assoc_.arr[j].free) - j++; - return j; - } - bool ok() const { - return i < assoc_.arr.size(); - } - void OK()const { - assert(!ok() || !assoc_.arr[i].free); - } - void operator++(int) { i++; i = next(i); } - K key() { return assoc_.arr[i].key; } - V &val() { return assoc_.arr[i].val; } -}; - -#endif diff --git a/flower/datafile.cc b/flower/datafile.cc deleted file mode 100644 index e5940b4c40..0000000000 --- a/flower/datafile.cc +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include - -#include "datafile.hh" - -void -Data_file::gobble_white() -{ - char c; - - while ((c=data_get()) == ' ' ||c == '\t') - if (eof()) - break; - - data_unget(c); -} - -String -Data_file::get_word() -{// should handle escape seq's - String s; - - while (1) - { - char c = data_get(); - - if (isspace(c) || eof()) - { - data_unget(c); - break; - } - - - if (c == '\"') - { - rawmode= true; - - while ((c = data_get()) != '\"') - if (eof()) - error("EOF in a string"); - else - s += c; - - - rawmode= false; - } - else - s += c; - } - - return s; -} - -/** get a char - Only class member who uses text_file::get - */ -char -Data_file::data_get() { - char c = get(); - if (!rawmode && c == '#') // gobble comment - { - while ((c = get()) != '\n' && !eof()) - ; - return '\n'; - } - - return c; -} - -/// read line, gobble '\n' -String Data_file::get_line() -{ - char c; - String s; - - while ((c = data_get()) != '\n' && !eof()) - s += c; - return s; -} - -/// gobble stuff before first entry on a line. -void -Data_file::gobble_leading_white() -{ - // eat blank lines. - while (!eof()) { - char c = data_get(); - if (!isspace(c)) { - data_unget(c); - break; - } - } -} - - diff --git a/flower/datafile.hh b/flower/datafile.hh deleted file mode 100644 index 14d57369a3..0000000000 --- a/flower/datafile.hh +++ /dev/null @@ -1,59 +0,0 @@ -/* - datafile.hh -- declare Data_file - - source file of the LilyPond music typesetter - - (c) 1997 Han-Wen Nienhuys -*/ - - -#ifndef DATAFILE_HH -#define DATAFILE_HH - -#include "textstream.hh" - -/// read a data file -class Data_file : private Text_stream -{ - - public: - bool rawmode; - - Text_stream::line; - Text_stream::eof; - Text_stream::get_name; - - char data_get(); - void data_unget(char c) { - unget(c); - } - - /// read line, eat #\n# - String get_line(); - - /// read a word till next space, leave space. Also does quotes - String get_word(); - - /// gobble horizontal white stuff. - void gobble_white(); - - /// gobble empty stuff before first field. - void gobble_leading_white(); - Data_file(String s) : Text_stream(s) { - //*mlog << "(" << s << flush; - rawmode= false; - } - - ~Data_file() { - // *mlog << ")"< -*/ - - -#ifndef STRINGDATA_HH -#define STRINGDATA_HH - - -/**Internal String struct. - the data itself. Handles simple tasks (resizing, resetting) - */ -class String_data { - // GNU malloc: storage overhead is 8 bytes anyway. - -friend class String_handle; - int maxlen; // maxlen is arraysize-1 - - int length_i_; - Byte* data_byte_p_; - int references; - - /// init to "" - String_data(); - - /// init from src. Conservative allocation. - String_data(String_data const &src); - - ~String_data(); - - /** POST: maxlen >= j. - @param j, maximum stringlength_i_. - contents thrown away. - */ - void setmax(int j); - - /** POST: maxlen >= j. - @param j, maximum stringlength_i_. - contents are kept if it grows. - */ - void remax(int j); - - /// check if writeable. - void OKW(); - - /// check state. - void OK(); - - /// reduce memory usage. - void tighten(); - - // assignment. - void set( Byte const* byte_c_l, int length_i ); - - void set( char const* ch_c_l ); - - /// concatenation. - void append( Byte const* byte_c_l, int length_i ); - - void operator += ( char const* ch_c_l ); - - char const* ch_c_l() const; - - char* ch_l(); - - Byte const* byte_c_l() const; - - // idem, non const - Byte* byte_l(); - - void trunc(int j); - - /** access element. not really safe. Can alter length_i_ without - #String_data# knowing it. */ - Byte &operator [](int j); - Byte operator [](int j) const; -}; - - - -#ifdef STRING_UTILS_INLINED -#ifndef INLINE -#define INLINE inline -#endif -#include "stringdata.inl" - -#endif - - -#endif // STRING_DATA_HH diff --git a/flower/stringdata.inl b/flower/stringdata.inl deleted file mode 100644 index 7b55481085..0000000000 --- a/flower/stringdata.inl +++ /dev/null @@ -1,215 +0,0 @@ -/* -*-C++-*- - String_data.inl -- implement String_data - - source file of Flower lib - - (c) 1997 Han-Wen Nienhuys -*/ - -#ifndef STRINGDATA_INL -#define STRINGDATA_INL - -#include -#include - -#include "stringdata.hh" -const int INITIALMAX=8; - -#include -void* -mymemmove( void* dest, void const* src, size_t n ); -#if 0 // redef STRING_DEBUG -INLINE void* -mymemmove( void* dest, void const* src, size_t n ) -{ - return memmove( dest, src, n ); // wohltempererit: 69006 -} -#define memmove mymemmove -#endif - -INLINE void -String_data::OKW() -{ - assert (references == 1); -} - -INLINE void -String_data::OK() -{ - assert(maxlen >= length_i_); - assert(bool(data_byte_p_)); - assert(references >= 1); -} - - -INLINE -String_data::String_data() -{ - references=0; - maxlen = INITIALMAX; - data_byte_p_ = new Byte[maxlen + 1]; - data_byte_p_[0] = 0; - length_i_ = 0; -} - -INLINE -String_data::String_data(String_data const &src) -{ - references=0; - maxlen = length_i_ = src.length_i_; - data_byte_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead. - memmove( data_byte_p_, src.data_byte_p_, length_i_ + 1 ); -} - -INLINE -String_data::~String_data() -{ - assert(references == 0); - delete[] data_byte_p_; -} - -INLINE void -String_data::setmax(int j) -{ - OKW(); - if (j > maxlen) { - delete data_byte_p_; - maxlen = j; - data_byte_p_ = new Byte[maxlen + 1]; - - data_byte_p_[0] = 0; - length_i_ = 0; - } -} - -/* this is all quite hairy: - update of length_i_ - update of maxlen - alloc of buffer - copying of buffer - needs blondification: - split tasks - define change authority -*/ -INLINE void -String_data::remax(int j) -{ - OKW(); - if (j > maxlen) { -// maxlen = j; oeps -// Byte *p = new Byte[maxlen + 1]; - Byte *p = new Byte[j + 1]; - memmove( p, data_byte_p_, ( maxlen = 0 && j <= length_i_); - data_byte_p_[j] = 0; - length_i_ = j; -} - -INLINE Byte& -String_data::operator [](int j) -{ - assert(j >= 0 && j <= length_i_); - return data_byte_p_[j] ; -} - -INLINE Byte -String_data::operator [](int j) const -{ - assert(j >= 0 && j <= length_i_); - return data_byte_p_[j]; -} - - - - -#endif // __STRING_UTIL_CC // diff --git a/flower/stringhandle.hh b/flower/stringhandle.hh deleted file mode 100644 index df92e50216..0000000000 --- a/flower/stringhandle.hh +++ /dev/null @@ -1,70 +0,0 @@ -/* - stringhandle.hh -- declare String_handle - - source file of the LilyPond music typesetter - - (c) 1997 Han-Wen Nienhuys -*/ - - -#ifndef STRINGHANDLE_HH -#define STRINGHANDLE_HH -#include "fproto.hh" - - -/** - Reference counting for strings. - - handles ref. counting, and provides a very thin interface using - Byte * - - */ -class String_handle { - String_data* data; - - /// decrease ref count. Named kind of like a Tanenbaum semafore - void down(); - - /// increase ref count - void up(String_data *d); - - /** make sure data has only one reference. - POST: data->references == 1 - */ - void copy(); - -public: - String_handle(); - ~String_handle(); - String_handle(String_handle const & src); - - Byte const* byte_c_l() const; - char const* ch_c_l() const; - Byte* byte_l(); - char* ch_l(); - - void operator =(String_handle const &src); - void operator += (char const *s); - Byte operator[](int j) const; - - /** Access elements. WARNING: NOT SAFE - don't use this for loops. Use byte_c_l() - */ - Byte &operator[](int j); - void append( Byte const* byte_c_l, int length_i ); - void set( Byte const* byte_c_l, int length_i ); - void operator = (char const *p); - void trunc(int j); - int length_i() const; -}; - -#ifdef STRING_UTILS_INLINED -#ifndef INLINE -#define INLINE inline -#endif -#include "stringhandle.inl" -/* we should be resetting INLINE. oh well. */ -#endif - - -#endif // STRINGHANDLE_HH diff --git a/flower/stringhandle.inl b/flower/stringhandle.inl deleted file mode 100644 index bc84cd868b..0000000000 --- a/flower/stringhandle.inl +++ /dev/null @@ -1,151 +0,0 @@ -/* -*-c++-*- - - stringhandle.inl -- implement String_handle - - source file of Flower lib - - (c) 1997 Han-Wen Nienhuys -*/ - -#ifndef STRINGHANDLE_INL -#define STRINGHANDLE_INL - -#include -#include - -#include "stringdata.hh" -#include "stringhandle.hh" - -INLINE void -String_handle::down() -{ - if (!(--data->references)) delete data; data = 0; -} - -/// increase ref count -INLINE void -String_handle::up(String_data *d) -{ - data=d; data->references ++; -} - -INLINE void -String_handle::copy() -{ - if (data->references !=1){ - String_data *newdata = new String_data(*data); - down(); - up(newdata); - } -} - -INLINE -String_handle::String_handle() -{ - up(new String_data); -} - -INLINE -String_handle::~String_handle() -{ - down(); -} - -INLINE -String_handle::String_handle(String_handle const & src) -{ - up(src.data); -} - -INLINE Byte* -String_handle::byte_l() -{ - copy(); - return data->byte_l(); -} - -INLINE char* -String_handle::ch_l() -{ - copy(); - return (char*)data->byte_l(); -} - -INLINE Byte -const* String_handle::byte_c_l() const -{ - return data->byte_c_l(); -} - -INLINE char const* -String_handle::ch_c_l() const -{ - return (char const*)data->byte_c_l(); -} - -INLINE void -String_handle::operator =(String_handle const &src) -{ - if (this == &src) - return; - down(); - up(src.data); -} - -INLINE void -String_handle::operator += (char const *s) -{ - copy(); - *data += s; -} - - -INLINE Byte -String_handle::operator[](int j) const -{ - return (*data)[j]; -} - -// !NOT SAFE! -// don't use this for loops. Use byte_c_l() -INLINE Byte & -String_handle::operator[](int j) -{ - copy(); // hmm. Not efficient - return data->byte_l()[j]; -} - -INLINE void -String_handle::append( Byte const* byte_c_l, int length_i ) -{ - copy(); - data->append( byte_c_l, length_i ); -} - -INLINE void -String_handle::set( Byte const* byte_c_l, int length_i ) -{ - copy(); - data->set( byte_c_l, length_i ); -} - -INLINE void -String_handle::operator = (char const *p) -{ - copy(); - data->set( p ); -} - -INLINE void -String_handle::trunc(int j) -{ - copy(); data->trunc(j); -} - -INLINE int -String_handle::length_i() const -{ - return data->length_i_; -} - -#endif diff --git a/flower/textdb.cc b/flower/textdb.cc deleted file mode 100644 index eefea16240..0000000000 --- a/flower/textdb.cc +++ /dev/null @@ -1,48 +0,0 @@ -#include "textdb.hh" -bool -Text_db::eof() -{ - Data_file::gobble_leading_white(); - return Data_file::eof(); -} - -void -Text_db::gobble_leading_white() -{ - while (1) { - Data_file::gobble_leading_white(); - if (eof()) - return ; - char c; - if ((c = data_get()) !='\n'){ - data_unget (c); - return ; - } - } -} - - -Text_record -Text_db::get_record() -{ - while (1) { - String s; - Array fields; - assert(!eof()); - - while ((s = get_word()) != "") - { - fields.push(s); - gobble_white(); - } - - - if (get_line() != "") - assert(false); - - assert (fields.size()); - return Text_record(fields, get_name(), line()); - } -} - - diff --git a/flower/textdb.hh b/flower/textdb.hh deleted file mode 100644 index c2cff2461b..0000000000 --- a/flower/textdb.hh +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef TEXTDB_HH -#define TEXTDB_HH - -#include "datafile.hh" - -/**a "const" Array. Contents can't be changed. do "#" comments, read quote enclosed fields */ - -class Text_record : Array -{ - int line_no; - String filename; - -public: - Text_record() { } // needed because of other ctor - - /// report an error in this line. - message(String s) { - cerr << '\n'<< filename << ": "<< line_no << s << "\n"; - } - String operator[](int j) { - return Array::operator[](j); - } - - Text_record(Array s, String fn, int j) : Array(s) { - filename = fn; line_no = j; - } - Array::size; -}; - -/** abstraction for a datafile. - add a subrec/fieldsep/record separator - */ - -class Text_db : private Data_file -{ - void gobble_leading_white(); -public: - /// get a line with records - Text_record get_record(); - - Text_db(String fn):Data_file(fn) { } - Data_file::error; - bool eof(); - - /// get next line. - Text_record operator++(int) { - return get_record(); - } - /// are we done yet? - operator bool() { - return !eof(); - } -}; - -#endif diff --git a/flower/textstream.cc b/flower/textstream.cc deleted file mode 100644 index 5ab3f3fcde..0000000000 --- a/flower/textstream.cc +++ /dev/null @@ -1,31 +0,0 @@ -#include "textstream.hh" - -Text_stream::Text_stream(String fn) -{ - ios::sync_with_stdio(); - if (fn == "") - { - name = ""; - f = stdin; - } - - else - { - name = fn; - f = fopen(fn, "r"); - } - - if (!f) { - cerr <<__FUNCTION__<< ": can't open `" << fn << "'\n"; - exit(1); - } - - line_no = 1; - } - -void -Text_stream::message(String s) -{ - cerr << "\n"< -#include -#include "string.hh" -#include "varray.hh" - -/** - line counting input stream. - a stream for textfiles. linecounting. Thin interface getchar and - ungetchar. (ungetc is unlimited) - - should protect get and unget against improper use -*/ - - -class Text_stream -{ - int line_no; - - // could just have used streams. - FILE *f; - Array pushback; - String name; - - public: - Text_stream(String fn); - String get_name() { return name; } - bool eof() { - return feof(f); - } - bool eol() { - return (peek() == '\n'); - } - char peek() { - char c = get(); - unget(c); - return c; - } - int line(){ - return line_no; - } - - char get() { - char c; - - if (pushback.empty()) - c = getc(f); - else - c = pushback.pop(); - - if (c =='\n') - line_no++; - return c; - } - void unget(char c) { - if (c =='\n') - line_no--; - pushback.push(c); - } - ~Text_stream (){ - if (!eof()) - cerr <<__FUNCTION__<< ": closing unended file"; - - fclose(f); - } - - /// GNU format message. - void message(String s); -}; - -#endif -- 2.39.5