+++ /dev/null
-/*
- 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<class K, class V>
-struct Assoc_iter {
- int i;
- Assoc<K,V> &assoc_;
- /// we don't want to be bothered by const correctness
- Assoc_iter(const Assoc<K,V> &a) :
- assoc_((Assoc<K,V> &)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
+++ /dev/null
-#include <fstream.h>
-#include <ctype.h>
-
-#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;
- }
- }
-}
-
-
+++ /dev/null
-/*
- datafile.hh -- declare Data_file
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#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 << ")"<<flush;
- }
-
- warning(String s) {
- message("warning: " + s);
- }
- error(String s){
- message(s);
- exit(1);
- }
-};
-#endif // DATAFILE_HH
+++ /dev/null
-/*
- stringdata.hh -- declare String_data
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#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
+++ /dev/null
-/* -*-C++-*-
- String_data.inl -- implement String_data
-
- source file of Flower lib
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef STRINGDATA_INL
-#define STRINGDATA_INL
-
-#include <assert.h>
-#include <memory.h>
-
-#include "stringdata.hh"
-const int INITIALMAX=8;
-
-#include <sys/types.h>
-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 <? length_i_ ) + 1 );
- maxlen = j;
- delete[] data_byte_p_;
- data_byte_p_ = p;
- }
-}
-
-INLINE void
-String_data::tighten()
-{ // should be dec'd const
- maxlen = length_i_;
- Byte *p = new Byte[maxlen + 1];
- memmove( p, data_byte_p_, length_i_ + 1 );
- delete[] data_byte_p_;
- data_byte_p_ = p;
-}
-// assignment.
-INLINE void
-String_data::set( Byte const* byte_c_l, int length_i )
-{
- OKW();
-
- assert( byte_c_l && byte_c_l != data_byte_p_);
-
- length_i_ = length_i;
- remax( length_i_ ); // copies too
- memmove( data_byte_p_, byte_c_l, length_i_ );
- data_byte_p_[ length_i_ ] = 0;
-}
-
-INLINE
-void
-String_data::set( char const* ch_c_l )
-{
- set( (Byte const*)ch_c_l, strlen( ch_c_l ) );
-}
-
-
-/// concatenation.
-INLINE void
-String_data::append( Byte const* byte_c_l, int length_i )
-{
- OK();
- OKW();
- int old_i = length_i_;
-
- length_i_ += length_i;
- remax( length_i_ );
- memmove( data_byte_p_ + old_i, byte_c_l, length_i );
- data_byte_p_[ length_i_ ] = 0;
-}
-
-INLINE
-void
-String_data::operator += ( char const* ch_c_l )
-{
- append( (Byte const*)ch_c_l, strlen( ch_c_l ) );
-}
-
-
-
-INLINE
-char const*
-String_data::ch_c_l() const
-{
- return (char const*)data_byte_p_;
-}
-INLINE char*
-String_data::ch_l()
-{
- return (char*)data_byte_p_;
-}
-
-INLINE Byte const*
-String_data::byte_c_l() const
-{
- return data_byte_p_;
-}
-
-INLINE Byte*
-String_data::byte_l()
-{
- OKW();
- return data_byte_p_;
-}
-
-INLINE
-void
-String_data::trunc(int j)
-{
- OKW();
- assert(j >= 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 //
+++ /dev/null
-/*
- stringhandle.hh -- declare String_handle
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#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
+++ /dev/null
-/* -*-c++-*-
-
- stringhandle.inl -- implement String_handle
-
- source file of Flower lib
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef STRINGHANDLE_INL
-#define STRINGHANDLE_INL
-
-#include <assert.h>
-#include <memory.h>
-
-#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
+++ /dev/null
-#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<String> 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());
- }
-}
-
-
+++ /dev/null
-#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<String>
-{
- 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<String>::operator[](j);
- }
-
- Text_record(Array<String> s, String fn, int j) : Array<String>(s) {
- filename = fn; line_no = j;
- }
- Array<String>::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
+++ /dev/null
-#include "textstream.hh"
-
-Text_stream::Text_stream(String fn)
-{
- ios::sync_with_stdio();
- if (fn == "")
- {
- name = "<STDIN>";
- 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"<<get_name() << ": " << line()<<": "<<s<<endl;
-}
-
+++ /dev/null
-
-#ifndef TEXTSTR_HH
-#define TEXTSTR_HH
-
-#include <stdio.h>
-#include <ctype.h>
-#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<char> 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