* flower/include/std-string.hh: excise flower string.
2006-02-06 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * 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
+++ /dev/null
-/*
- (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 <cassert>
-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<class T> 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 T>
-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<typename T>
- T const &
- back (Array<T> const &v, vsize i)
- {
- return v[v.size () - i - 1];
- }
-
- template<typename T>
- T&
- back (Array<T> &v, vsize i)
- {
- return v[v.size () - i - 1];
- }
-
- template<typename T>
- T const &
- boundary (Array<T> const &v, int dir, vsize i)
- {
- assert (dir);
- return v[dir == -1 ? i : v.size () - 1 - i];
- }
-
- template<typename T>
- T &
- boundary (Array<T> &v, int dir, vsize i)
- {
- assert (dir);
- return v[dir == -1 ? i : v.size () - 1 - i];
- }
-
- template<class T>
- void
- reverse (Array<T> &v)
- {
- vsize h = v.size () / 2;
- for (vsize i = 0, j = v.size () - 1; i < h; i++, j--)
- swap (v[i], v[j]);
- }
-
- template<typename T>
- void
- concat (Array<T> &v, Array<T> const& w)
- {
- v.insert (v.end (), w.begin (), w.end ());
- }
-
- template<typename T>
- void
- vector_sort (Array<T> &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
#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 T>
-class Link_array : private Array<void *>
+class Link_array : public std::vector<T *>
{
-
- Link_array (Array<void *> const &v)
- :Array<void *> (v)
- {
- }
-
-public:
- Link_array ()
- {
- }
-
- T *const &back() const
- {
- return (T * const &) Array<void *>::back();
- }
-
- T *&back ()
- {
- return (T *&) Array<void *>::back ();
- }
-
- Array<void *>::begin;
- Array<void *>::data;
- Array<void *>::end;
- Array<void *>::clear;
- Array<void *>::erase;
- Array<void *>::resize;
- Array<void *>::size;
- Array<void *>::empty;
- Array<void *>::pop_back;
-
-
- /* Flower compat */
- Array<void *>::unordered_del;
- Array<void *>::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 *> ((void **)tp, n)
- {
- }
-
- Link_array (Link_array<T> const &src)
- : Array<void *> (src)
- {
- }
-
- /* std::vector interface */
- //typedef T** iterator;
- //typedef T* const* iterator_const;
-
- Link_array (const_iterator begin, const_iterator end)
- : Array<void *> (begin, end)
- {
- }
-
- T *at (int i)
- {
- return (T *) Array<void *>::at (i);
- }
- T const *at (int i) const
- {
- return (T const *) Array<void *>::at (i);
- }
-
- /// access element
- T *&operator [] (int i)
- {
- return (T *&) Array<void *>::at (i);
- }
- /// access element
- T *const operator [] (int i) const
- {
- return (T *const) Array<void *>::at (i);
- }
- T *pop ()
- {
- T* t = (T *) Array<void *>::back ();
- pop_back ();
- return t;
- }
- void insert (iterator b, T *t)
- {
- Array<void *>::insert (b, t);
- }
- void insert (iterator pos, const_iterator b, const_iterator e)
- {
- Array<void *>::insert (pos, b, e);
- }
- void push_back (T *t)
- {
- Array<void *>::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<T> 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<void *>::data ();
- }
-
- T * const*
- data () const
- {
- return (T**) Array<void *>::data ();
- }
-
- /**
- remove i-th element, and return it.
- */
- T *get (vsize i)
- {
- T *t = at (i);
- Array<void*>::erase (Array<void*>::begin () + i);
- return t;
- }
- Link_array<T>
- slice (int l, int u) const
- {
- return Array<void *>::Array (begin () + l, begin () + u);
- }
- void concat (Link_array<T> const &a2)
- {
- Array<void *>::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<class T, class V>
-Link_array<T>
-typecasts (Link_array<V> const &a, T * /* dummy */)
-{
- Link_array<T> ret;
- for (vsize i = a.size (); i--;)
- ret.push_back (dynamic_cast<T *> (a[i])); // ugh?
- return ret;
-}
-
-template<class T> inline void
-Link_array<T>::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<class T>
-void
-junk_pointers (Link_array<T> &a)
-{
- for (vsize i = 0; i < a.size (); i++)
- delete a[i];
- a.clear ();
-}
-
-template<class T>
-int
-binary_search (Link_array<T> 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<class T>
-void
-binary_search_bounds (Link_array<T> 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<class T>
-void
-reverse (Link_array<T> &v)
-{
- vsize h = v.size () / 2;
- for (vsize i = 0, j = v.size () - 1; i < h; i++, j--)
- swap (v[i], v[j]);
-}
-
-template<typename T>
-void
-concat (Link_array<T> &v, Link_array<T> const& w)
-{
- v.insert (v.end (), w.begin (), w.end ());
-}
-
-template<typename T>
-void
-vector_sort (Link_array<T> &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<typename T>
-void
-uniq (Link_array<T> &v)
-{
- v.uniq ();
-}
-
-template<typename T>
-typename Array<void *>::const_iterator
-find (Link_array<T> const &v, T * const& key)
-{
- return v.begin () + v.find_index (key);
-}
-
-}
-
#endif // PARRAY_HH
#ifndef STD_STRING_HH
#define STD_STRING_HH
-
-#if !STD_STRING
-
-/* Also declare string, in the wrong way. */
-#include <algorithm>
-#include <iostream>
-#include <sstream>
-
-#endif
-
-
+
#include "compare.hh"
-#if STD_STRING
#include <string>
-#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);
return 0;
}
-#if !STD_VECTOR
-/* Also declare vector, in the wrong way. */
-#include <iostream>
-#include <sstream>
-#endif
-
#include "compare.hh"
-
-#if STD_VECTOR
-
#include "config.hh"
#if HAVE_STL_DATA_METHOD
#define vector __vector
#include <vector>
#undef vector
+
namespace std {
/* Interface without pointer arithmetic (iterator) semantics. */
template<typename T>
}
-#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 */
+++ /dev/null
-/*
- string-data.hh -- declare String_data
-
- source file of the LilyPond music typesetter
-
- (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#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
+++ /dev/null
-/* -*-C++-*-
- String_data.inl -- implement String_data
-
- source file of Flower lib
-
- (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#ifndef STRINGDATA_INL
-#define STRINGDATA_INL
-
-#include "string-data.hh"
-
-#include <cassert>
-#include <cstring>
-#include <memory>
-using namespace std;
-
-const int INITIALMAX = 8;
-
-#include <sys/types.h>
-
-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 //
+++ /dev/null
-/*
- string-handle.hh -- declare String_handle
-
- source file of the LilyPond music typesetter
-
- (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#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
+++ /dev/null
-/* -*-c++-*-
-
-stringhandle.inl -- implement String_handle
-
-source file of Flower lib
-
-(c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#ifndef STRINGHANDLE_INL
-#define STRINGHANDLE_INL
-
-#include <cassert>
-#include <memory>
-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
+++ /dev/null
-/*
- 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 <iostream>
-#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 */
+++ /dev/null
-/*
- string.icc -- implement String inlines
-
- source file of the Flower Library
-
- (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#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 */
+++ /dev/null
-/*
- 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 <cstdlib>
-#include <cstdio>
-#include <cassert>
-#include <cstring>
-
-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 ();
-}
-
-\f
-
-#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 ();
-}
-
-\f
-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;
-}
-\f
-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);
-}
-\f
-
-int
-String::to_int () const
-{
- return String_convert::dec2int (*this);
-}
-
-double
-String::to_double () const
-{
- return String_convert::dec2double (*this);
-}
-
-#ifdef STREAM_SUPPORT
-#include <iostream>
-
-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 */
-
+++ /dev/null
-/*
- 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 <hanwen@xs4all.nl> */
-
-#if !STD_STRING
-
-
-#ifdef STRING_DEBUG
-#define memmove mymemmove
-#endif
-
-#ifndef STRING_UTILS_INLINED
-
-#ifdef INLINE
-#undef INLINE
-#endif
-
-#define INLINE
-
-#include <algorithm>
-
-#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 <sys/types.h>
-#include <memory>
-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 */
(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))
/* FIXME: when Link_array is dropped, do grand s/r to vector<TYPE*>. */
#if STD_VECTOR
+
+#include "std-vector.hh"
+
#define Link_array__char_ std::vector<char*>
#define Link_array__Grob_ std::vector<Grob*>
#define Link_array__Accidental_placement_entry_ std::vector<Accidental_placement_entry*>
;;
;; 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)))
PREAMBLE = 'preamble'
PRINTFILENAME = 'printfilename'
QUOTE = 'quote'
-RAGGEDRIGHT = 'raggedright'
+RAGGED_RIGHT = 'ragged-right'
RELATIVE = 'relative'
STAFFSIZE = 'staffsize'
TEXIDOC = 'texidoc'
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''',
},
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:
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]