From: Han-Wen Nienhuys Date: Mon, 6 Feb 2006 12:36:07 +0000 (+0000) Subject: * flower/string.cc (Module): excise flower array & string X-Git-Tag: release/2.7.32~8 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=1f308cefc064db00c46e8ade7248fdc242c74767;p=lilypond.git * flower/string.cc (Module): excise flower array & string * flower/include/std-string.hh: excise flower string. --- diff --git a/ChangeLog b/ChangeLog index 4f9f62303f..306806769b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-02-06 Han-Wen Nienhuys + * flower/string.cc (Module): excise flower array & string + + * flower/include/std-string.hh: excise flower string. + * {ly,lily,scm}/*: use dashes in \paper and \layout variables * python/convertrules.py (lilypond_version_re_str): require diff --git a/flower/include/array.hh b/flower/include/array.hh deleted file mode 100644 index 85992a5f0f..0000000000 --- a/flower/include/array.hh +++ /dev/null @@ -1,361 +0,0 @@ -/* - (c) 1995--2006 Han-Wen Nienhuys - - Distributed under GNU GPL -*/ -#ifndef STD_VECTOR_HH -#error array.hh is obsolete, use std-vector.hh -#endif - -#ifndef ARRAY_H -#define ARRAY_H - -#include -using namespace std; - -#ifndef INLINE -#define INLINE inline -#endif - -#if !STD_VECTOR -#define index_assert(i) (assert (i >= 0 && i < size_)); -#else -#define index_assert(i) (assert (i != VPOS && i < size_)); -#endif - -namespace std { -/// copy a bare (C-)array from #src# to #dest# sized #count# -template void arrcpy (T *dest, T const *src, vsize count); - -/** - Scaleable array/stack template, for a type T with default constructor. - - - This template implements a scaleable vector. With (or without) range - checking. The type T should have a default constructor. It is - best suited for simple types, such as int, double or String, it - provides a paranoidly safe replacement for the new T[int] construct. - - You should \bf{never} store pointers to objects in an Array (since - the array may be relocated without the pointer knowing it). - - It uses stack terminology, (push, pop, top), and can be used as a stack. -*/ -template -class Array -{ -public: - - /// maximum length of array. - vsize max_; - - /// the data itself - T *array_; - - /// stretch or shrink array. - void remax (vsize newmax) - { - T *newarr = new T[newmax]; - size_ = (newmax < size_) ? newmax : size_; - arrcpy (newarr, array_, size_); - - delete[] array_; - array_ = newarr; - max_ = newmax; - } - vsize size_; - -public: - /* std::vector interface */ - typedef T* iterator; - typedef T const* const_iterator; - - Array () - { - array_ = 0; - max_ = 0; - size_ = 0; - } - - Array (Array const &src) - { - array_ = src.copys (); - max_ = size_ = src.size_; - } - - Array (const_iterator begin, const_iterator end); - - T const &back () const - { - return (*this)[size_ - 1]; - } - - T &back () - { - return (*this)[size_ - 1]; - } - - bool empty () const - { - return !size_; - } - - void pop_back () - { - assert (!empty ()); - resize (size () - 1); - } - - vsize size () const - { - return size_; - } - - /** set the size_ to #s#. - POST: size () == s. - Warning: contents are unspecified */ - void resize (vsize s) - { - if (s > max_) - remax (s); - size_ = s; - } - - T* - data () - { - return array_; - } - - T const* - data () const - { - return array_; - } - - iterator - begin () - { - return data (); - } - - const_iterator - begin () const - { - return data (); - } - - iterator - end () - { - return data () + size_; - } - - const_iterator - end () const - { - return data () + size_; - } - - void clear () - { - //resize (0); - size_ = 0; - } - - T & - at (vsize i) - { - return (*this)[i]; - } - - T const & - at (vsize i) const - { - return (*this)[i]; - } - - T &operator [] (vsize i) - { - return array_[i]; - } - - T const &operator [] (vsize i) const - { - return array_[i]; - } - - iterator - erase (iterator p) - { - vsize i = p - data (); - index_assert (i); - arrcpy (array_ + i, array_ + i + 1, size_ - i - 1); - size_--; - return p; - } - - void - insert (iterator b, T k) - { - vsize j = b - array_; - resize (size_ + 1); - index_assert (j); - for (vsize i = size_ - 1; i > j; i--) - array_[i] = array_[i - 1]; - array_[j] = k; - } - - void - insert (iterator pos, const_iterator b, const_iterator e) - { - vsize j = pos - array_; - vsize k = e - b; - resize (size_ + k); - for (vsize i = size_ - 1; i > j + k; i--) - array_[i] = array_[i - k]; - for (vsize i = j; i < j + k; i++) - array_[i] = b[i - j]; - } - - /// add to the end of array - void push_back (T x) - { - if (size_ == max_) - remax (2 * max_ + 1); - - // T::operator= (T &) is called here. Safe to use with automatic - // vars - array_[size_++] = x; - } - - - /* Flower intererface */ - - - /// check invariants - void OK () const; - /** report the size_. - @see - {setsize_} - */ - - Array (T *tp, vsize n) - { - array_ = new T[n]; - max_ = size_ = n; - arrcpy (array_, tp, n); - } - - // ugh, get around gcc 2.8.1 ice; see bezier.cc - Array (vsize i) - { - max_ = size_ = i; - array_ = new T[i]; - } - - /// tighten array size_. - void tighten_maxsize () - { - remax (size_); - } - - ~Array () - { - delete[] array_; - } - - /// return a "new"ed copy of array - T *copys () const - { - T *Tarray = new T[size_]; - arrcpy (Tarray, array_, size_); - return Tarray; - } - - void operator = (Array const &src) - { - resize (src.size_); - arrcpy (array_, src.array_, size_); - } - - void unordered_del (vsize i) - { - at (i) = back (); - resize (size () -1); - } -}; - - template - T const & - back (Array const &v, vsize i) - { - return v[v.size () - i - 1]; - } - - template - T& - back (Array &v, vsize i) - { - return v[v.size () - i - 1]; - } - - template - T const & - boundary (Array const &v, int dir, vsize i) - { - assert (dir); - return v[dir == -1 ? i : v.size () - 1 - i]; - } - - template - T & - boundary (Array &v, int dir, vsize i) - { - assert (dir); - return v[dir == -1 ? i : v.size () - 1 - i]; - } - - template - void - reverse (Array &v) - { - vsize h = v.size () / 2; - for (vsize i = 0, j = v.size () - 1; i < h; i++, j--) - swap (v[i], v[j]); - } - - template - void - concat (Array &v, Array const& w) - { - v.insert (v.end (), w.begin (), w.end ()); - } - - template - void - vector_sort (Array &v, int (*compare) (T const &, T const &), - vsize lower=-1, vsize upper=-1) - { - if (lower < 0) - { - lower = 0; - upper = v.size () - 1; - } - if (lower >= upper) - return; - swap (v[lower], v[(lower + upper) / 2]); - vsize last = lower; - for (vsize i = lower +1; i <= upper; i++) - if (compare (v.array_[i], v.array_[lower]) < 0) - swap (v[++last], v[i]); - swap (v[lower], v[last]); - vector_sort (v, compare, lower, last - 1); - vector_sort (v, compare, last + 1, upper); - } - -#include "array.icc" - -} - -#endif diff --git a/flower/include/parray.hh b/flower/include/parray.hh index 64556ec4e2..3d24532bcc 100644 --- a/flower/include/parray.hh +++ b/flower/include/parray.hh @@ -9,397 +9,15 @@ #ifndef PARRAY_HH #define PARRAY_HH -#ifndef STD_VECTOR_HH -#error array.hh is obsolete, use std-vector.hh -#endif +#include "std-vector.hh" using namespace std; -namespace std { -/** - an array of pointers. - - TODO - should init to 0. -*/ template -class Link_array : private Array +class Link_array : public std::vector { - - Link_array (Array const &v) - :Array (v) - { - } - -public: - Link_array () - { - } - - T *const &back() const - { - return (T * const &) Array::back(); - } - - T *&back () - { - return (T *&) Array::back (); - } - - Array::begin; - Array::data; - Array::end; - Array::clear; - Array::erase; - Array::resize; - Array::size; - Array::empty; - Array::pop_back; - - - /* Flower compat */ - Array::unordered_del; - Array::tighten_maxsize; - - static int default_compare (T *const &p1, T *const &p2) - { - /* can't do p1 -p2, since T might be an incomplete type */ - if (p1 < p2) - return -1; - if (p2 < p1) - return 1; - return 0; - } - Link_array (T *const *tp, int n) - : Array ((void **)tp, n) - { - } - - Link_array (Link_array const &src) - : Array (src) - { - } - - /* std::vector interface */ - //typedef T** iterator; - //typedef T* const* iterator_const; - - Link_array (const_iterator begin, const_iterator end) - : Array (begin, end) - { - } - - T *at (int i) - { - return (T *) Array::at (i); - } - T const *at (int i) const - { - return (T const *) Array::at (i); - } - - /// access element - T *&operator [] (int i) - { - return (T *&) Array::at (i); - } - /// access element - T *const operator [] (int i) const - { - return (T *const) Array::at (i); - } - T *pop () - { - T* t = (T *) Array::back (); - pop_back (); - return t; - } - void insert (iterator b, T *t) - { - Array::insert (b, t); - } - void insert (iterator pos, const_iterator b, const_iterator e) - { - Array::insert (pos, b, e); - } - void push_back (T *t) - { - Array::push_back (t); - } - - T *top (vsize j) - { - return (*this)[size_ - j - 1]; - } - T *& top (vsize j) const - { - return (*this)[size_ - j - 1]; - } - - void substitute (T *old, T *new_p) - { - int i; - while ((i = find_index (old)) >= 0) - if (new_p) - at (i) = new_p; - else - erase (begin () + i); - } - void unordered_substitute (T *old, T *new_p) - { - int i; - while ((i = find_index (old)) >= 0) - if (new_p) - at (i) = new_p; - else - unordered_del (i); - } - void default_sort () - { - sort (default_compare); - } - - // quicksort. - void sort (int (*compare) (T *const &, T *const &), - int lower = -1, int upper = -1); - - void uniq () - { - Link_array ls; - for (vsize i = 0; i < size (); i++) - if (!i || at (i - 1) != at (i)) - ls.push_back (at (i)); - *this = ls; - } - - T *& boundary (int d, int i) - { - assert (d); - if (d == 1) - return top (i); - else - return at (i); - } - T *boundary (int d, int i)const - { - assert (d); - if (d == 1) - return top (i); - else - return at (i); - } - - T ** - data () - { - return (T**) Array::data (); - } - - T * const* - data () const - { - return (T**) Array::data (); - } - - /** - remove i-th element, and return it. - */ - T *get (vsize i) - { - T *t = at (i); - Array::erase (Array::begin () + i); - return t; - } - Link_array - slice (int l, int u) const - { - return Array::Array (begin () + l, begin () + u); - } - void concat (Link_array const &a2) - { - Array::insert (end (), a2.begin (), a2.end ()); - } - int find_index (T const *t) const - { - for (vsize i = 0; i < size (); i++) - if (at (i) == t) - return i; - return -1; - } - T const *find (T const *t) const - { - int i = find_index (t); - if (i >= 0) - return at (i); - else - return 0; - } - - void swap (vsize i, vsize j) - { - T *t ((*this)[i]); - (*this)[i] = (*this)[j]; - (*this)[j] = t; - } - void - reverse () - { - vsize h = size () / 2; - for (vsize i = 0, j = size () - 1; i < h; i++, j--) - swap (i, j); - } + }; -template -Link_array -typecasts (Link_array const &a, T * /* dummy */) -{ - Link_array ret; - for (vsize i = a.size (); i--;) - ret.push_back (dynamic_cast (a[i])); // ugh? - return ret; -} - -template inline void -Link_array::sort (int (*compare) (T *const &, T *const &), int lower, int upper) -{ - if (lower < 0) - { - lower = 0; - upper = size () - 1; - } - if (lower >= upper) - return; - swap (lower, (lower + upper) / 2); - int last = lower; - for (int i = lower +1; i <= upper; i++) - if (compare (at (i), at (lower)) < 0) - swap (++last, i); - swap (lower, last); - sort (compare, lower, last - 1); - sort (compare, last + 1, upper); -} - -template -void -junk_pointers (Link_array &a) -{ - for (vsize i = 0; i < a.size (); i++) - delete a[i]; - a.clear (); -} - -template -int -binary_search (Link_array const &arr, T *t, - int (*compare) (T *const &, T *const &)) -{ - int cmp; - int result; - int lo = 0; - int hi = arr.size (); - - if (hi == 0) - return -1; - - /* binary search */ - do - { - cmp = (lo + hi) / 2; - - result = (*compare) (t, arr[cmp]); - - if (result < 0) - hi = cmp; - else - lo = cmp; - } - while (hi - lo > 1); - - if (!compare (t, arr[lo])) - return lo; - /* not found */ - return -1; -} - -template -void -binary_search_bounds (Link_array const &table, - T const *key, int (*compare) (T *const &, T *const &), - int *lo, - int *hi) -{ - int cmp; - int result; - - /* binary search */ - do - { - cmp = (*lo + *hi) / 2; - - result = (*compare) ((T *) key, table[cmp]); - - if (result < 0) - *hi = cmp; - else - *lo = cmp; - } - while (*hi - *lo > 1); -} - -template -void -reverse (Link_array &v) -{ - vsize h = v.size () / 2; - for (vsize i = 0, j = v.size () - 1; i < h; i++, j--) - swap (v[i], v[j]); -} - -template -void -concat (Link_array &v, Link_array const& w) -{ - v.insert (v.end (), w.begin (), w.end ()); -} - -template -void -vector_sort (Link_array &v, int (*compare) (T *const &, T * const &), - vsize lower=-1, vsize upper=-1) -{ - if (lower < 0) - { - lower = 0; - upper = v.size () - 1; - } - if (lower >= upper) - return; - swap (v[lower], v[(lower + upper) / 2]); - vsize last = lower; - for (vsize i = lower +1; i <= upper; i++) - if (compare (v[i], v[lower]) < 0) - swap (v[++last], v[i]); - swap (v[lower], v[last]); - vector_sort (v, compare, lower, last - 1); - vector_sort (v, compare, last + 1, upper); -} - -template -void -uniq (Link_array &v) -{ - v.uniq (); -} - -template -typename Array::const_iterator -find (Link_array const &v, T * const& key) -{ - return v.begin () + v.find_index (key); -} - -} - #endif // PARRAY_HH diff --git a/flower/include/std-string.hh b/flower/include/std-string.hh index 7d2ae6d7cc..1cae94727b 100644 --- a/flower/include/std-string.hh +++ b/flower/include/std-string.hh @@ -8,50 +8,16 @@ #ifndef STD_STRING_HH #define STD_STRING_HH - -#if !STD_STRING - -/* Also declare string, in the wrong way. */ -#include -#include -#include - -#endif - - + #include "compare.hh" -#if STD_STRING #include -#endif - -#if STD_STRING namespace std { typedef size_t ssize; #define NPOS std::string::npos -} - -#else /* ! STD_STRING */ - -namespace std { - -#define string String - using namespace std; - class String; - typedef int ssize; -#define NPOS -1 - -} - -#include "string.hh" - -#endif /* ! STD_STRING */ - -namespace std { - string to_string (string s); string to_string (char c, int n = 1); string to_string (int i, char const *format = 0); diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index e77ca5ee04..b10299b744 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -39,16 +39,7 @@ int default_compare (T *const &a, T *const &b) return 0; } -#if !STD_VECTOR -/* Also declare vector, in the wrong way. */ -#include -#include -#endif - #include "compare.hh" - -#if STD_VECTOR - #include "config.hh" #if HAVE_STL_DATA_METHOD @@ -57,6 +48,7 @@ int default_compare (T *const &a, T *const &b) #define vector __vector #include #undef vector + namespace std { /* Interface without pointer arithmetic (iterator) semantics. */ template @@ -334,29 +326,6 @@ namespace std { } -#else /* ! STD_VECTOR */ - -namespace std { - -#ifndef Array -#define vector Array -#endif - - using namespace std; - -#ifndef VSIZE -#define VSIZE - typedef int vsize; -#define VPOS -1 -#endif - -} - -#include "array.hh" -#include "parray.hh" - -#endif /* !STD_VECTOR */ - using namespace std; #endif /* STD_VECTOR_HH */ diff --git a/flower/include/string-data.hh b/flower/include/string-data.hh deleted file mode 100644 index ddae249b1e..0000000000 --- a/flower/include/string-data.hh +++ /dev/null @@ -1,96 +0,0 @@ -/* - string-data.hh -- declare String_data - - source file of the LilyPond music typesetter - - (c) 1997--2006 Han-Wen Nienhuys -*/ - -#ifndef STRINGDATA_HH -#define STRINGDATA_HH - -#include "flower-proto.hh" - -namespace std { - -/**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_; - Byte *data_byte_; - int ref_count_; - - /// init to "" - String_data (); - - /// init from src. Conservative allocation. - String_data (String_data const &src); - - ~String_data (); - - /** POST: maxlen >= j. - @param j, maximum stringlength_. - contents thrown away. - */ - void setmax (int j); - - /** POST: maxlen >= j. - @param j, maximum stringlength_. - 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, int length_i); - - void set (char const *str0); - - /// concatenation. - void append (Byte const *byte, int length_i); - - void operator += (char const *str0); - - char const *c_str () const; - - char *get_c_str (); - - Byte const *to_bytes () const; - - // idem, non const - Byte *get_bytes (); - - void trunc (int j); - - /** access element. not really safe. Can alter length_ without - #String_data# knowing it. */ - Byte &operator [] (int j); - Byte operator [] (int j) const; - bool is_binary_bo () const; -}; - -} - -#ifdef STRING_UTILS_INLINED -#ifndef INLINE -#define INLINE inline -#endif -#include "string-data.icc" -#endif - -#endif // STRING_DATA_HH diff --git a/flower/include/string-data.icc b/flower/include/string-data.icc deleted file mode 100644 index d3c5f591a2..0000000000 --- a/flower/include/string-data.icc +++ /dev/null @@ -1,212 +0,0 @@ -/* -*-C++-*- - String_data.inl -- implement String_data - - source file of Flower lib - - (c) 1997--2006 Han-Wen Nienhuys -*/ - -#ifndef STRINGDATA_INL -#define STRINGDATA_INL - -#include "string-data.hh" - -#include -#include -#include -using namespace std; - -const int INITIALMAX = 8; - -#include - -namespace std { - -INLINE void -String_data::OKW () -{ - assert (ref_count_ == 1); -} - -INLINE void -String_data::OK () -{ - assert (maxlen >= length_); - assert (bool (data_byte_)); - assert (ref_count_ >= 1); -} - -INLINE -String_data::String_data () -{ - ref_count_ = 0; - maxlen = INITIALMAX; - data_byte_ = new Byte[maxlen + 1]; - data_byte_[0] = 0; - length_ = 0; -} - -INLINE -String_data::String_data (String_data const &src) -{ - ref_count_ = 0; - maxlen = length_ = src.length_; - data_byte_ = new Byte[maxlen + 1]; // should calc GNU 8byte overhead. - memcpy (data_byte_, src.data_byte_, length_ + 1); -} - -INLINE -String_data::~String_data () -{ - assert (ref_count_ == 0); - delete[] data_byte_; -} - -INLINE void -String_data::setmax (int j) -{ - OKW (); - if (j > maxlen) - { - delete[] data_byte_; - maxlen = j; - data_byte_ = new Byte[maxlen + 1]; - - data_byte_[0] = 0; - length_ = 0; - } -} - -/* this is all quite hairy: - update of length_ - 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) - { - Byte *p = new Byte[j + 1]; - memcpy (p, data_byte_, min (maxlen, length_) + 1); - maxlen = j; - delete[] data_byte_; - data_byte_ = p; - } -} - -INLINE void -String_data::tighten () -{ // should be dec'd const - maxlen = length_; - Byte *p = new Byte[maxlen + 1]; - memcpy (p, data_byte_, length_ + 1); - delete[] data_byte_; - data_byte_ = p; -} -// assignment. -INLINE void -String_data::set (Byte const *byte, int length_i) -{ - OKW (); - - assert (byte && byte != data_byte_); - - length_ = length_i; - remax (length_); // copies too - memcpy (data_byte_, byte, length_); - data_byte_[ length_ ] = 0; -} - -INLINE -void -String_data::set (char const *str0) -{ - set ((Byte const *)str0, strlen (str0)); -} - -/// concatenation. -INLINE void -String_data::append (Byte const *byte, int length_i) -{ - OK (); - OKW (); - int old_i = length_; - - length_ += length_i; - remax (length_); - memcpy (data_byte_ + old_i, byte, length_i); - data_byte_[ length_ ] = 0; -} - -INLINE -void -String_data::operator += (char const *str0) -{ - append ((Byte const *)str0, strlen (str0)); -} - -INLINE -char const * -String_data::c_str () const -{ - return (char const *)data_byte_; -} -INLINE char * -String_data::get_c_str () -{ - return (char *)data_byte_; -} - -INLINE Byte const * -String_data::to_bytes () const -{ - return data_byte_; -} - -INLINE Byte * -String_data::get_bytes () -{ - OKW (); - return data_byte_; -} - -INLINE -void -String_data::trunc (int j) -{ - OKW (); - assert (j >= 0 && j <= length_); - data_byte_[j] = 0; - length_ = j; -} - -INLINE bool -String_data::is_binary_bo () const -{ - // return !memchr (data_byte_, length_, 0); - return ((int)strlen ((char const *)data_byte_) != length_); -} - -INLINE Byte & -String_data::operator [] (int j) -{ - assert (j >= 0 && j <= length_); - return data_byte_[j]; -} - -INLINE Byte -String_data::operator [] (int j) const -{ - assert (j >= 0 && j <= length_); - return data_byte_[j]; -} - -} - -#endif // __STRING_UTIL_CC // diff --git a/flower/include/string-handle.hh b/flower/include/string-handle.hh deleted file mode 100644 index 9551508110..0000000000 --- a/flower/include/string-handle.hh +++ /dev/null @@ -1,70 +0,0 @@ -/* - string-handle.hh -- declare String_handle - - source file of the LilyPond music typesetter - - (c) 1997--2006 Han-Wen Nienhuys -*/ - -#ifndef STRINGHANDLE_HH -#define STRINGHANDLE_HH - -#include "flower-proto.hh" - -namespace std { -/** - 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 (); - - void up (String_data *d); - - /** make sure data has only one reference. - POST: data->ref_count_ == 1 - */ - void copy (); - -public: - String_handle (); - ~String_handle (); - String_handle (String_handle const &src); - - Byte const *to_bytes () const; - char const *c_str () const; - Byte *get_bytes (); - char *get_c_str (); - bool is_binary_bo () const; - 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 to_bytes () - */ - Byte &operator [] (int j); - void append (Byte const *byte, int length_i); - void set (Byte const *byte, int length_i); - void operator = (char const *p); - void trunc (int j); - int length () const; -}; - -} - -#ifdef STRING_UTILS_INLINED -#ifndef INLINE -#define INLINE inline -#endif -#include "string-handle.icc" -/* we should be resetting INLINE. oh well. */ -#endif - -#endif // STRINGHANDLE_HH diff --git a/flower/include/string-handle.icc b/flower/include/string-handle.icc deleted file mode 100644 index 7e653ef2e2..0000000000 --- a/flower/include/string-handle.icc +++ /dev/null @@ -1,169 +0,0 @@ -/* -*-c++-*- - -stringhandle.inl -- implement String_handle - -source file of Flower lib - -(c) 1997--2006 Han-Wen Nienhuys -*/ - -#ifndef STRINGHANDLE_INL -#define STRINGHANDLE_INL - -#include -#include -using namespace std; - -#include "string-data.hh" -#include "string-handle.hh" - -namespace std { - -INLINE void -String_handle::down () -{ - if (! (--data->ref_count_)) - delete data; - data = 0; -} - -/* - increase ref count - - THIS does not have to be initialized. -*/ -INLINE void -String_handle::up (String_data *d) -{ - data = d; - data->ref_count_++; -} - -INLINE void -String_handle::copy () -{ - if (data->ref_count_ != 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::get_bytes () -{ - copy (); - return data->get_bytes (); -} - -INLINE char * -String_handle::get_c_str () -{ - copy (); - return (char *)data->get_bytes (); -} - -INLINE Byte -const *String_handle::to_bytes () const -{ - return data->to_bytes (); -} - -INLINE char const * -String_handle::c_str () const -{ - return (char const *)data->to_bytes (); -} - -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 to_bytes () -INLINE Byte & -String_handle::operator [] (int j) -{ - copy (); // hmm. Not efficient - return data->get_bytes ()[j]; -} - -INLINE void -String_handle::append (Byte const *byte, int length_i) -{ - copy (); - data->append (byte, length_i); -} - -INLINE void -String_handle::set (Byte const *byte, int length_i) -{ - copy (); - data->set (byte, 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 () const -{ - return data->length_; -} - -INLINE bool -String_handle::is_binary_bo () const -{ - return data->is_binary_bo (); -} - -} - -#endif diff --git a/flower/include/string.hh b/flower/include/string.hh deleted file mode 100644 index 2673c8c074..0000000000 --- a/flower/include/string.hh +++ /dev/null @@ -1,142 +0,0 @@ -/* - FILE : string.hh -- declare String - - Rehacked by HWN 3/nov/95 - removed String & 's - introduced Class String_handle -*/ - -#ifndef STD_STRING_HH -#error string.hh is obsolete, use std-string.hh -#endif - -#ifndef STRING_HH -#define STRING_HH - -// too darn slow with gcc3 -#ifdef STREAM_SUPPORT -#if (__GNUC__ > 2) -#include -#else -class ostream; -#endif -#endif - -#include "arithmetic-operator.hh" -#include "string-handle.hh" - -namespace std { - -class String -{ -public: - - /* partial std::string interface */ - String (); - String (int n, char c); - String (char const *source); - String (char const *, int n); - String (String const &, int pos, ssize n=NPOS); - - String &operator = (String const &source); - /// concatenate s - void operator += (char const *s) { strh_ += s; } - void operator += (String s); - char &operator [] (int n); - char operator [] (int n) const; - - - char const *c_str () const; - char const *data () const; - bool empty () const; - int find (String s, int pos=0) const; - int find (char c, int pos=0) const; - int find (char const *c, int pos=0) const; - int rfind (char c) const; - String replace (int pos, int n, String str); - - String substr (int pos=0, ssize n=NPOS) const; - int compare (String const &s) const; - - void append (String); - int length () const; - - String insert (ssize pos, String); - ssize copy (char *s, ssize n, ssize pos=0) const; - -protected: - String_handle strh_; - - bool null_terminated (); - -private: - /// return "new"-ed copy of contents - Byte *get_copy_byte () const; - char *get_copy_str0 () const; - - Byte const *to_bytes () const; - Byte *get_bytes (); - - void prepend (String); - - /// return n leftmost chars - String left_string (int n) const; - - /// return n rightmost chars - String right_string (int n) const; - - /// return a piece starting at index (first char = index_i 0), length n - String cut_string (int index_i, int n) const; - - /// cut out a middle piece, return remainder - String nomid_string (int index_i, int n) const; - - static int compare (String const &s1, const String &s2); - - /// index of rightmost character C in string - int index_last (char c) const; - - int index (char c) const; - - /// index of leftmost occurance of STRING - int index (String) const; - - int index_any (String) const; - -#ifdef STREAM_SUPPORT - /// provide Stream output - void print_on (ostream &os) const; -#endif - - /// convert to an integer - int to_int () const; - - /// convert to a double - double to_double () const; - - String substitute (String find, String replace); - String substitute (char find, char replace); -}; - -// because char const* also has an operator ==, this is for safety: -bool operator == (String s1, char const *s2); -bool operator == (char const *s1, String s2); -bool operator != (String s1, char const *s2); -bool operator != (char const *s1, String s2); - -IMPLEMENT_ARITHMETIC_OPERATOR (String, +); -#ifdef STREAM_SUPPORT -ostream &operator << (ostream &os, String d); -#endif - -} - -#ifdef STRING_UTILS_INLINED -#ifndef INLINE -#define INLINE inline -#endif -#include "string.icc" -/* we should be resetting INLINE. oh well. */ -#endif - -#endif /* STRING_HH */ diff --git a/flower/include/string.icc b/flower/include/string.icc deleted file mode 100644 index 765297af6a..0000000000 --- a/flower/include/string.icc +++ /dev/null @@ -1,81 +0,0 @@ -/* - string.icc -- implement String inlines - - source file of the Flower Library - - (c) 1997--2006 Han-Wen Nienhuys -*/ - -#ifndef STRING_ICC -#define STRING_ICC - -namespace std { - - bool operator == (String const&, String const&); - bool operator != (String const&, String const&); - -INLINE -char const * -String::c_str () const -{ - return strh_.c_str (); -} - -// because char const* also has an operator ==, this is for safety: -INLINE -bool -operator == (String s1, char const *s2) -{ - return s1 == String (s2); -} - -INLINE -bool -operator == (char const *s1, String s2) -{ - return String (s1) == s2; -} - -INLINE -bool -operator != (String s1, char const *s2) -{ - return s1 != String (s2); -} - -INLINE -bool -operator != (char const *s1, String s2) -{ - return String (s2) != s1; -} - -INLINE -char & -String::operator [] (int n) -{ - return (char &) strh_[n]; -} - -INLINE -char -String::operator [] (int n) const -{ - return strh_[n]; -} - -INLINE -String::String () -{ -} - -INLINE -String::String (char const *source) -{ - assert (source); - strh_ = source; -} - -} - -#endif /* STRING_ICC */ diff --git a/flower/string.cc b/flower/string.cc deleted file mode 100644 index 76429ff812..0000000000 --- a/flower/string.cc +++ /dev/null @@ -1,414 +0,0 @@ -/* - string.cc - implement String - - (c) 1997--2006 Han-Wen Nienhuys & Jan Nieuwenhuizen -*/ -#if !STD_STRING - -#ifndef _GNU_SOURCE // we want memmem -#define _GNU_SOURCE -#endif - -#include "std-string.hh" - -#include -#include -#include -#include - -using namespace std; - -#include "libc-extension.hh" -#include "string-convert.hh" - -/* std::string interface */ - -namespace std { - -String::String (char const *s, int n) -{ - strh_.set ((Byte const *)s, n); -} - -String::String (String const &s, int pos, ssize n) -{ - *this = s.substr (pos, n); -} - -String::String (int n, char c) -{ - *this = String_convert::char_string (c, n); -} - -String & -String::operator = (String const &source) -{ - strh_ = source.strh_; - return *this; -} - -String -String::substr (int pos, ssize n) const -{ - if (n == (ssize)-1 || n == (ssize)INT_MAX || n == NPOS) - n = length () - pos; - return cut_string (pos, n); -} - -String -String::insert (ssize pos, String s) -{ - *this = substr (0, pos) + s + substr (pos + 1); - return *this; -} - -ssize -String::copy (char *buf, ssize n, ssize pos) const -{ - assert (pos == 0); - memcpy (buf, strh_.to_bytes (), strh_.length () + 1); - return n; // ? -} - -int -String::compare (String const &s) const -{ - char const *p1 = c_str (); - char const *p2 = s.c_str (); - if (p1 == p2) - return 0; - - /* - don't forget the terminating '\0' - */ - int f = min (length (), s.length ()); - int cmp_length = 1+ f; - int i = memcmp (p1, p2, cmp_length); - return i; -} - -char const * -String::data () const -{ - return (char const*) to_bytes (); -} - -bool -String::empty () const -{ - return !length (); -} - -int -String::find (char c, int pos) const -{ - String f = right_string (length () - pos); - ssize n = f.index (c); - if (n != NPOS) - return pos + n; - return NPOS; -} - -int -String::find (char const *c, int pos) const -{ - return find (String (c), pos); -} - -int -String::find (String s, int pos) const -{ - if (!pos) - return index (s); - String f = right_string (length () - pos); - ssize n = f.index (s); - if (n != NPOS) - return pos + n; - return NPOS; -} - -int -String::rfind (char c) const -{ - return index_last (c); -} - -String -String::replace (int pos, int n, String str) -{ - return this->substr (0, pos) + str + this->substr (pos + n); -} - -void -String::append (String s) -{ - strh_.append (s.to_bytes (), s.length ()); -} - -void -String::operator += (String s) -{ - append (s); -} - -int -String::length () const -{ - return strh_.length (); -} - - - - -/* String */ - -int -String::compare (String const &s1, String const &s2) -{ - return s1.compare (s2); -} - -#ifdef STRING_DEBUG -void *mymemmove (void *dest, void const *src, size_t n); -#define memmove mymemmove -#endif - -// return array, alloced with new. -Byte * -String::get_copy_byte () const -{ - Byte const *src = strh_.to_bytes (); - Byte *dest = new Byte[strh_.length () + 1]; - memcpy (dest, src, strh_.length () + 1); - return dest; -} - -char * -String::get_copy_str0 () const -{ - return (char *)get_copy_byte (); -} - - - -#if 0 -void -String::prepend (String s) -{ - s += *this; - *this = s; -} - -#endif - - -Byte const * -String::to_bytes () const -{ - return strh_.to_bytes (); -} - -Byte * -String::get_bytes () -{ - return strh_.get_bytes (); -} - - -int -String::index_last (char const c) const -{ - if (!length ()) - return NPOS; - - char const *me = strh_.c_str (); - char const *p = (char const *)memrchr ((Byte *)me, length (), c); - if (p) - return p - me; - return NPOS; -} - -/** find a character. - -@return -the index of the leftmost character #c# (0 <= return < length ()), -or NPOS if not found. - -? should return length ()?, as in string.left_string (index (delimiter)) -*/ -int -String::index (char c) const -{ - char const *me = strh_.c_str (); - char const *p = (char const *) memchr (me, c, length ()); - if (p) - return p - me; - return NPOS; -} - -/** - find a substring. - - @return - index of leftmost occurrence of #searchfor# -*/ -int -String::index (String searchfor) const -{ - char const *me = strh_.c_str (); - - char const *p - = (char const *) memmem (me, length (), - searchfor.c_str (), searchfor.length ()); - - if (p) - return p - me; - - return NPOS; -} - -/** find chars of a set. - -@return - -the index of the leftmost occurance of an element of #set#. NPOS if -nothing is found. -*/ -int -String::index_any (String set) const -{ - int n = length (); - if (!n) - return NPOS; - - void const *me = (void const *) strh_.c_str (); - for (int i = 0; i < set.length (); i++) - { - char *found = (char *) memchr (me, set[i], n); - if (found) - return found - (char const *)me; - } - return NPOS; -} - -String -String::left_string (int n) const -{ - if (n >= length ()) - return *this; - - String retval; - if (n < 1) - return retval; - - retval = *this; - retval.strh_.trunc (n); - return retval; -} - -String -String::right_string (int n) const -{ - if (n > length ()) - return *this; - - if (n < 1) - return ""; - - return String (strh_.c_str () + length () - n, n); -} - -String -String::nomid_string (int index_i, int n) const -{ - if (index_i < 0) - { - n += index_i; - index_i = 0; - } - if (n <= 0) - return *this; - - return left_string (index_i) + right_string (length () - index_i - n); -} - -String -String::cut_string (int index_i, int n) const -{ - if (index_i < 0) - { - n += index_i; - index_i = 0; - } - - if (!length () || (index_i < 0) || (index_i >= length ()) || (n < 1)) - return String (); - - if ((n > length ()) || (index_i + n > length ())) - n = length () - index_i; - - return String (c_str () + index_i, n); -} - - -int -String::to_int () const -{ - return String_convert::dec2int (*this); -} - -double -String::to_double () const -{ - return String_convert::dec2double (*this); -} - -#ifdef STREAM_SUPPORT -#include - -ostream & -operator << (ostream &os, String d) -{ - d.print_on (os); - return os; -} - -void -String::print_on (ostream &os) const -{ - if (!strh_.is_binary_bo ()) - os << c_str (); - else - for (int i = 0; i < length (); i++) - os << (Byte) (*this)[ i ]; -} -#endif - -String -String::substitute (String find, String replace) -{ - int n = find.length (); - int m = replace.length (); - for (ssize i = index (find), j = 0; i != NPOS; - i = right_string (length () - j).index (find)) - { - *this = left_string (i + j) - + replace - + right_string (length () - j - i - n); - j += i + m; - } - return *this; -} - -String -String::substitute (char find, char replace) -{ - for (ssize i = index (find); i != NPOS; i = index (find)) - (*this)[i] = replace; - return *this; -} - -} - -#endif /* !STD_STRING */ - diff --git a/flower/stringutil.cc b/flower/stringutil.cc deleted file mode 100644 index 74b5630d61..0000000000 --- a/flower/stringutil.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* - stringutil.cc -- generate non-inline members. - - This should be in a separate file, because one can include the .icc - only once. - - source file of the LilyPond music typesetter - - (c) 1997--2006 Han-Wen Nienhuys */ - -#if !STD_STRING - - -#ifdef STRING_DEBUG -#define memmove mymemmove -#endif - -#ifndef STRING_UTILS_INLINED - -#ifdef INLINE -#undef INLINE -#endif - -#define INLINE - -#include - -#include "string-data.hh" -#include "string-handle.hh" - -#include "std-string.hh" - -#include "string-data.icc" -#include "string-handle.icc" -#include "string.icc" - -#ifdef STRING_DEBUG -#include -#include -using namespace std; - -void * -mymemmove (void *dest, void const *src, size_t n) -{ - return memcpy (dest, src, n); -} -#endif - -#endif /* STRING_UTILS_INLINED */ - -#endif /* !STD_STRING */ diff --git a/input/regression/markup-eps.ly b/input/regression/markup-eps.ly index a6d20fda91..7f8b62393a 100644 --- a/input/regression/markup-eps.ly +++ b/input/regression/markup-eps.ly @@ -9,7 +9,7 @@ (display "%!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 5 5 105 105 -10 setline-width 10 10 moveto 0 90 rlineto 90 0 rlineto 0 -90 rlineto +10 setlinewidth 10 10 moveto 0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath stroke" port) (close port)) diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index 30603aff77..6a5ad5cc3e 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -180,6 +180,9 @@ typedef void (*Translator_void_method_ptr) (Translator *); /* FIXME: when Link_array is dropped, do grand s/r to vector. */ #if STD_VECTOR + +#include "std-vector.hh" + #define Link_array__char_ std::vector #define Link_array__Grob_ std::vector #define Link_array__Accidental_placement_entry_ std::vector diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index fdccdab375..42deb27cb5 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -391,7 +391,7 @@ Example: ;; ;; bind voice identifiers to the voices (map (lambda (voice-id voice) - (ly:parser-define!! parser voice-id + (ly:parser-define! parser voice-id (make-music 'SequentialMusic 'origin location 'elements voice))) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 4b6b36c308..c6fdb3ab00 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -153,7 +153,7 @@ PAPER = 'paper' PREAMBLE = 'preamble' PRINTFILENAME = 'printfilename' QUOTE = 'quote' -RAGGEDRIGHT = 'raggedright' +RAGGED_RIGHT = 'ragged-right' RELATIVE = 'relative' STAFFSIZE = 'staffsize' TEXIDOC = 'texidoc' @@ -419,7 +419,7 @@ ly_options = { QUOTE: r'''line-width = %(line-width)s - 2.0 * %(exampleindent)s''', - RAGGEDRIGHT: r'''raggedright = ##t''', + RAGGED_RIGHT: r'''ragged-right = ##t''', PACKED: r'''packed = ##t''', }, @@ -626,7 +626,7 @@ texinfo_line_widths = { def classic_lilypond_book_compatibility (key, value): if key == 'singleline' and value == None: - return (RAGGEDRIGHT, None) + return (RAGGED_RIGHT, None) m = re.search ('relative\s*([-0-9])', key) if m: @@ -806,13 +806,13 @@ class Lilypond_snippet (Snippet): if not has_line_width: if type == 'lilypond' or FRAGMENT in self.option_dict.keys (): - self.option_dict[RAGGEDRIGHT] = None + self.option_dict[RAGGED_RIGHT] = None if type == 'lilypond': if LINE_WIDTH in self.option_dict.keys (): del self.option_dict[LINE_WIDTH] else: - if RAGGEDRIGHT in self.option_dict.keys (): + if RAGGED_RIGHT in self.option_dict.keys (): if LINE_WIDTH in self.option_dict.keys (): del self.option_dict[LINE_WIDTH]