+1999-11-05 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * src/bufferlist.C: use a vector to store the buffers in. This is
+ an internal change and should not affect any other thing.
+
+ * src/BufferView.C (waitForX): use XSync instead of the lengthy
+ stuff in waitForX.
+
+ * src/text.C (Fill): fix potential bug, one off bug.
+
+1999-11-04 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * src/Makefile.am (lyx_main.o): add more files it depends on.
+
+ * src/lyx_cb.C (addNewlineAndDepth): parameters in wrong order.
+
+ * src/support/lyxstring.C: use size_t for the reference count,
+ size, reserved memory and xtra.
+ (internal_compare): new private member function. Now the compare
+ functions should work for std::strings that have embedded '\0'
+ characters.
+ (compare): all compare functions rewritten to use
+ internal_compare.
+
1999-11-03 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/support/lyxstring.C (compare): pass c_str()
#
# This is all the files that contains internationalization strings.
-src/BufferView.C
-src/Chktex.C
-src/FontLoader.C
-src/LaTeX.C
-src/LaTeXLog.C
-src/Literate.C
-src/LyXAction.C
-src/LyXSendto.C
-src/LyXView.C
-src/PaperLayout.C
-src/ParagraphExtra.C
-src/TableLayout.C
src/buffer.C
src/bufferlist.C
+src/BufferView.C
src/bullet_forms.C
src/bullet_forms_cb.C
+src/Chktex.C
src/combox.C
src/credits.C
src/credits_form.C
src/filedlg.C
+src/FontLoader.C
src/form1.C
src/gettext.h
src/insets/figinset.C
src/insets/lyxinset.h
src/intl.C
src/kbmap.C
+src/LaTeX.C
+src/LaTeXLog.C
src/latexoptions.C
src/layout.C
src/layout_forms.C
+src/Literate.C
+src/LyXAction.C
src/lyx.C
src/lyx_cb.C
+src/lyxfont.C
+src/lyxfr0.C
+src/lyxfr1.C
+src/lyxfunc.C
src/lyx_gui.C
src/lyx_gui_misc.C
src/lyx_main.C
src/lyx_sendfax.C
src/lyx_sendfax_main.C
-src/lyxfont.C
-src/lyxfr0.C
-src/lyxfr1.C
-src/lyxfunc.C
+src/LyXSendto.C
src/lyxvc.C
+src/LyXView.C
src/mathed/formula.C
src/mathed/formula.h
src/mathed/formulamacro.C
src/menus.C
src/minibuffer.C
src/minibuffer.h
+src/PaperLayout.C
src/paragraph.C
+src/ParagraphExtra.C
src/print_form.C
-src/sp_form.C
src/spellchecker.C
+src/sp_form.C
src/support/filetools.C
src/support/lyxlib.h
src/support/path.h
-src/text.C
+src/TableLayout.C
src/text2.C
+src/text.C
static
void waitForX()
{
+#if 0
static Window w = 0;
static Atom a = 0;
if (!a)
XChangeProperty(fl_display, w, a, a, 8,
PropModeAppend, reinterpret_cast<unsigned char*>(""), 0);
XWindowEvent(fl_display, w, PropertyChangeMask, &ev);
+#endif
+ XSync(fl_get_display(), 0);
}
vspace.C \
vspace.h
-lyx_main.o: lyx_main.C lyx_main.h config.h version.h debug.h gettext.h
+lyx_main.o: lyx_main.C lyx_main.h config.h version.h debug.h gettext.h \
+ lyx_gui.h lyx_gui_misc.h lyxrc.h support/path.h support/filetools.h \
+ bufferlist.h debug.h support/FileInfo.h lastfiles.h intl.h \
+ lyxserver.h layout.h gettext.h
$(CXXCOMPILE) -DLYX_DIR=\"$(LYX_DIR)\" -DTOP_SRCDIR=\"$(top_srcdir)\" \
-DLYX_NAME=\"$(PACKAGE)\" -c $(top_srcdir)/src/lyx_main.C
// Use the current buffer's parameters as default
defaults.params.Copy(params);
// add an empty paragraph. Is this enough?
- defaults.paragraph = new LyXParagraph();
+ defaults.paragraph = new LyXParagraph;
return defaults.writeFile(defaults.filename,false);
}
// if par = 0 normal behavior
// else insert behavior
// Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
-bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
+bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph * par)
{
string tmptok;
Inset * inset = 0;
string pretoken;
if(!par) {
- par = new LyXParagraph();
+ par = new LyXParagraph;
+#ifdef NEW_TEXT
+ par->text.reserve(500);
+#endif
} else {
text->BreakParagraph();
return_par = text->FirstParagraph();
} else if (token == "\\layout") {
if (!return_par)
return_par = par;
- else
+ else {
+#ifdef NEW_TEXT
+ par->text.resize(par->text.size());
+#endif
par = new LyXParagraph(par);
+#ifdef NEW_TEXT
+ par->text.reserve(500);
+#endif
+ }
pos = 0;
lex.EatLine();
string layoutname = lex.GetString();
} else if (token == "\\end_float") {
if (!return_par)
return_par = par;
- else
+ else {
+#ifdef NEW_TEXT
+ par->text.resize(par->text.size());
+#endif
par = new LyXParagraph(par);
+#ifdef NEW_TEXT
+ par->text.reserve(500);
+#endif
+ }
footnotekind = LyXParagraph::FOOTNOTE;
footnoteflag = LyXParagraph::NO_FOOTNOTE;
pos = 0;
#include "lyx_cb.h"
#include "gettext.h"
-extern BufferView *current_view;
-extern MiniBuffer *minibuffer;
+extern BufferView * current_view;
+extern MiniBuffer * minibuffer;
extern void SmallUpdate(signed char);
extern void BeforeChange();
extern int RunLinuxDoc(int, string const &);
// Class BufferStorage
//
+#ifndef NEW_STORE
BufferStorage::BufferStorage()
{
// Initialize the buffer array
for (int i=NUMBER_OF_BUFFERS-1; i >=0; i--) {
buffer[i] = 0;
- }
+ }
}
+#endif
-
+#ifndef NEW_STORE
bool BufferStorage::isEmpty()
{
for (int i=NUMBER_OF_BUFFERS-1; i >=0; i--) {
}
return true;
}
+#endif
-
-void BufferStorage::release(Buffer* buf)
+void BufferStorage::release(Buffer * buf)
{
- int i=0;
- for (i=0; i<NUMBER_OF_BUFFERS; i++)
+#ifdef NEW_STORE
+ for(Container::iterator it = container.begin();
+ it != container.end(); ++it) {
+ if ((*it) == buf) {
+ Buffer * tmpbuf = (*it);
+ container.erase(it);
+ delete tmpbuf;
+ break;
+ }
+ }
+#else
+ int i = 0;
+ for (i = 0; i < NUMBER_OF_BUFFERS; i++)
if (buffer[i] == buf) break;
- Buffer *tmpbuf = buffer[i];
+ Buffer * tmpbuf = buffer[i];
buffer[i] = 0;
delete tmpbuf;
+#endif
}
-Buffer* BufferStorage::newBuffer(string const &s,
- LyXRC *lyxrc,
+Buffer * BufferStorage::newBuffer(string const & s,
+ LyXRC * lyxrc,
bool ronly)
{
+#ifdef NEW_STORE
+ Buffer * tmpbuf = new Buffer(s, lyxrc, ronly);
+ tmpbuf->params.useClassDefaults();
+ lyxerr.debug() << "Assigning to buffer "
+ << container.size() + 1 << endl;
+ container.push_back(tmpbuf);
+ return tmpbuf;
+#else
int i=0;
while (i < NUMBER_OF_BUFFERS - 1
&& buffer[i]) i++;
buffer[i]->params.useClassDefaults();
lyxerr.debug() << "Assigning to buffer " << i << endl;
return buffer[i];
+#endif
}
+#ifndef NEW_STORE
//
// Class BufferStrorage_Iter
//
-Buffer* BufferStorage_Iter::operator() ()
+Buffer * BufferStorage_Iter::operator() ()
{
- int i=0;
- for (i=index; i < BufferStorage::NUMBER_OF_BUFFERS; i++) {
+ int i = 0;
+ for (i = index; i < BufferStorage::NUMBER_OF_BUFFERS; i++) {
if (cs->buffer[i]) {
- index = i+1;
+ index = i + 1;
return cs->buffer[i];
}
}
}
-Buffer* BufferStorage_Iter::operator[] (int a)
+Buffer * BufferStorage_Iter::operator[] (int a)
{
// a is >=1
- if (a<=0) return 0;
+ if (a <= 0) return 0;
- int i=0;
+ int i = 0;
while (a--) {
while(!cs->buffer[i++]);
}
- if (i-1 < BufferStorage::NUMBER_OF_BUFFERS)
- return cs->buffer[i-1];
+ if (i - 1 < BufferStorage::NUMBER_OF_BUFFERS)
+ return cs->buffer[i - 1];
return 0;
}
+#endif
//
}
-BufferList::~BufferList()
+bool BufferList::empty()
{
- // I am sure something should be done here too.
+ return bstore.empty();
}
-bool BufferList::isEmpty()
-{
- return bstore.isEmpty();
-}
-
-extern void MenuWrite(Buffer*);
+extern void MenuWrite(Buffer *);
bool BufferList::QwriteAll()
{
bool askMoreConfirmation = false;
string unsaved;
+#ifdef NEW_STORE
+ for(BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ if (!(*it)->isLyxClean()) {
+ switch(AskConfirmation(_("Changes in document:"),
+ MakeDisplayPath((*it)->filename,
+ 50),
+ _("Save document?"))) {
+ case 1: // Yes
+ MenuWrite((*it));
+ break;
+ case 2: // No
+ askMoreConfirmation = true;
+ unsaved += MakeDisplayPath((*it)->filename,50);
+ unsaved += "\n";
+ break;
+ case 3: // Cancel
+ return false;
+ }
+ }
+ }
+#else
BufferStorage_Iter biter(bstore);
- Buffer *b=0;
- while ((b=biter())) {
+ Buffer * b = 0;
+ while ((b = biter())) {
if (!b->isLyxClean()) {
switch(AskConfirmation(_("Changes in document:"),
MakeDisplayPath(b->filename,50),
}
}
}
+#endif
if (askMoreConfirmation &&
lyxrc->exit_confirmation &&
!AskQuestion(_("Some documents were not saved:"),
// Should probably be moved to somewhere else: BufferView? LyXView?
-bool BufferList::write(Buffer *buf, bool makeBackup)
+bool BufferList::write(Buffer * buf, bool makeBackup)
{
minibuffer->Set(_("Saving document"),
MakeDisplayPath(buf->filename),"...");
void BufferList::closeAll()
{
_state = BufferList::CLOSING;
-
+#ifdef NEW_STORE
+ while (!bstore.empty()) {
+ close(bstore.front());
+ }
+#else
BufferStorage_Iter biter(bstore);
- Buffer *b=0;
- while ((b=biter())) {
+ Buffer * b = 0;
+ while ((b = biter())) {
close(b);
}
+#endif
_state = BufferList::OK;
}
void BufferList::resize()
{
+#ifdef NEW_STORE
+ for(BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ (*it)->resize();
+ }
+#else
BufferStorage_Iter biter(bstore);
- Buffer *b=0;
- while ((b=biter())) {
+ Buffer * b = 0;
+ while ((b = biter())) {
b->resize();
}
+#endif
}
-bool BufferList::close(Buffer *buf)
+bool BufferList::close(Buffer * buf)
{
buf->InsetUnlock();
in the same way as for lastfiles.[hC]
*/
{
- int ant=0;
+ int ant = 0;
+#ifdef NEW_STORE
+ for(BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ string relbuf = MakeDisplayPath((*it)->filename, 30);
+ fl_addtopup(pup, relbuf.c_str());
+ ++ant;
+ }
+#else
BufferStorage_Iter biter(bstore);
- Buffer *b=0;
- while ((b=biter())) {
- string relbuf = MakeDisplayPath(b->filename,30);
+ Buffer * b = 0;
+ while ((b = biter())) {
+ string relbuf = MakeDisplayPath(b->filename, 30);
fl_addtopup(pup, relbuf.c_str());
- ant++;
+ ++ant;
}
+#endif
if (ant == 0) fl_addtopup(pup,_("No Documents Open!%t"));
}
-Buffer* BufferList::first()
+Buffer * BufferList::first()
{
+#ifdef NEW_STORE
+ if (bstore.empty()) return 0;
+ return bstore.front();
+#else
BufferStorage_Iter biter(bstore);
return biter();
+#endif
}
-Buffer* BufferList::getBuffer(int choice)
+Buffer * BufferList::getBuffer(int choice)
{
+#ifdef NEW_STORE
+ if (choice >= bstore.size()) return 0;
+ return bstore[choice];
+#else
BufferStorage_Iter biter(bstore);
- Buffer *b=0;
+ Buffer * b = 0;
b = biter[choice];
// Be careful, this could be 0.
return b;
+#endif
}
-void BufferList::updateInset(Inset *inset, bool mark_dirty)
+void BufferList::updateInset(Inset * inset, bool mark_dirty)
{
+#ifdef NEW_STORE
+ for (BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ if ((*it)->text && (*it)->text->UpdateInset(inset)) {
+ if (mark_dirty)
+ (*it)->markDirty();
+ break;
+ }
+ }
+#else
BufferStorage_Iter biter(bstore);
Buffer *b=0;
while ((b=biter())) {
break;
}
}
+#endif
}
-int BufferList::unlockInset(UpdatableInset *inset)
+int BufferList::unlockInset(UpdatableInset * inset)
{
+#ifdef NEW_STORE
+ if (!inset) return 1;
+ for(BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ if ((*it)->the_locking_inset == inset) {
+ (*it)->InsetUnlock();
+ return 0;
+ }
+ }
+ return 1;
+#else
if (!inset) return 1;
BufferStorage_Iter biter(bstore);
}
}
return 1;
+#endif
}
void BufferList::updateIncludedTeXfiles(string const & mastertmpdir)
{
+#ifdef NEW_STORE
+ for(BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ if (!(*it)->isDepClean(mastertmpdir)) {
+ string writefile = mastertmpdir;
+ writefile += '/';
+ writefile += ChangeExtension((*it)->getFileName(),
+ ".tex", true);
+ (*it)->makeLaTeXFile(writefile, mastertmpdir,
+ false, true);
+ (*it)->markDepClean(mastertmpdir);
+
+ }
+ }
+#else
BufferStorage_Iter biter(bstore);
Buffer *b=0;
while ((b=biter())) {
b->markDepClean(mastertmpdir);
}
}
+#endif
}
void BufferList::emergencyWriteAll()
{
+#ifdef NEW_STORE
+ for (BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ if (!(*it)->isLyxClean()) {
+ bool madeit=false;
+
+ lyxerr <<_("lyx: Attempting to save"
+ " document ")
+ << (*it)->filename
+ << _(" as...") << endl;
+
+ for (int i = 0; i < 3 && !madeit; ++i) {
+ string s;
+
+ // We try to save three places:
+ // 1) Same place as document.
+ // 2) In HOME directory.
+ // 3) In "/tmp" directory.
+ if (i == 0) {
+ s = (*it)->filename;
+ } else if (i == 1) {
+ s = AddName(GetEnvPath("HOME"),
+ (*it)->filename);
+ } else { // MakeAbsPath to prepend the current drive letter on OS/2
+ s = AddName(MakeAbsPath("/tmp/"),
+ (*it)->filename);
+ }
+ s += ".emergency";
+
+ lyxerr << " " << i + 1 << ") " << s << endl;
+
+ if ((*it)->writeFile(s,true)) {
+ (*it)->markLyxClean();
+ lyxerr << _(" Save seems successful. "
+ "Phew.") << endl;
+ madeit = true;
+ } else if (i != 2) {
+ lyxerr << _(" Save failed! Trying...")
+ << endl;
+ } else {
+ lyxerr << _(" Save failed! Bummer. Document is lost.") << endl;
+ }
+ }
+ }
+ }
+#else
BufferStorage_Iter biter(bstore);
- Buffer *b=0;
- while ((b=biter())) {
+ Buffer * b = 0;
+ while ((b = biter())) {
if (!b->isLyxClean()) {
- bool madeit=false;
+ bool madeit = false;
lyxerr <<_("lyx: Attempting to save"
" document ")
// 1) Same place as document.
// 2) In HOME directory.
// 3) In "/tmp" directory.
- if (i==0) {
+ if (i == 0) {
s = b->filename;
- } else if (i==1) {
+ } else if (i == 1) {
s = AddName(GetEnvPath("HOME"),
b->filename);
} else { // MakeAbsPath to prepend the current drive letter on OS/2
}
s += ".emergency";
- lyxerr << " " << i+1 << ") " << s << endl;
+ lyxerr << " " << i + 1 << ") " << s << endl;
if (b->writeFile(s,true)) {
b->markLyxClean();
}
}
}
+#endif
}
Buffer* BufferList::readFile(string const & s, bool ronly)
{
- Buffer *b = bstore.newBuffer(s, lyxrc, ronly);
+ Buffer * b = bstore.newBuffer(s, lyxrc, ronly);
string ts = s;
string e = OnlyPath(s);
bool BufferList::exists(string const & s)
{
+#ifdef NEW_STORE
+ for (BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ if ((*it)->filename == s)
+ return true;
+ }
+ return false;
+#else
BufferStorage_Iter biter(bstore);
- Buffer *b=0;
- while ((b=biter())) {
+ Buffer * b = 0;
+ while ((b = biter())) {
if (b->filename == s)
return true;
}
return false;
+#endif
}
-Buffer* BufferList::getBuffer(string const &s)
+Buffer * BufferList::getBuffer(string const & s)
{
+#ifdef NEW_STORE
+ for(BufferStorage::iterator it = bstore.begin();
+ it != bstore.end(); ++it) {
+ if ((*it)->filename == s)
+ return (*it);
+ }
+ return 0;
+#else
BufferStorage_Iter biter(bstore);
- Buffer *b=0;
- while ((b=biter())) {
- if (b->filename ==s)
+ Buffer * b = 0;
+ while ((b = biter())) {
+ if (b->filename == s)
return b;
}
return 0;
+#endif
}
-Buffer* BufferList::newFile(string const & name, string tname)
+Buffer * BufferList::newFile(string const & name, string tname)
{
/* get a free buffer */
- Buffer *b = bstore.newBuffer(name, lyxrc);
+ Buffer * b = bstore.newBuffer(name, lyxrc);
// use defaults.lyx as a default template if it exists.
if (tname.empty()) {
WriteAlert(_("Error!"),_("Unable to open template"),
MakeDisplayPath(tname));
// no template, start with empty buffer
- b->paragraph = new LyXParagraph();
+ b->paragraph = new LyXParagraph;
+#ifdef NEW_TEXT
+ b->paragraph->text.reserve(500);
+#endif
}
}
else { // start with empty buffer
- b->paragraph = new LyXParagraph();
+ b->paragraph = new LyXParagraph;
+#ifdef NEW_TEXT
+ b->paragraph->text.reserve(500);
+#endif
}
b->markDirty();
}
-Buffer* BufferList::loadLyXFile(string const & filename, bool tolastfiles)
+Buffer * BufferList::loadLyXFile(string const & filename, bool tolastfiles)
{
// make sure our path is absolute
string s = MakeAbsPath(filename);
return getBuffer(s);
}
}
- Buffer *b=0;
+ Buffer * b = 0;
bool ro = false;
switch (IsFileWriteable(s)) {
case 0:
ro = true;
// Fall through
case 1:
- b=readFile(s, ro);
+ b = readFile(s, ro);
if (b) {
b->lyxvc.file_found_hook(s);
}
#include "buffer.h"
#include "debug.h"
+#define NEW_STORE 1
+
/** A class to hold all the buffers in a structure
The point of this class is to hide from bufferlist what kind
of structure the buffers are stored in. Should be no concern for
gave me an "internal gcc error".
*/
class BufferStorage {
+#ifdef NEW_STORE
+public:
+ ///
+ typedef vector<Buffer *> Container;
+ ///
+ typedef Container::iterator iterator;
+ ///
+ bool empty() const { return container.empty(); }
+ ///
+ void release(Buffer * buf);
+ ///
+ Buffer * newBuffer(string const & s, LyXRC *, bool = false);
+ ///
+ Container::iterator begin() { return container.begin(); }
+ ///
+ Container::iterator end() { return container.end(); }
+ ///
+ Buffer * front() { return container.front(); }
+ ///
+ Buffer * operator[](int c) { return container[c]; }
+ ///
+ int size() const { return container.size(); }
+private:
+ ///
+ Container container;
+#else
public:
///
BufferStorage();
///
- bool isEmpty();
+ bool empty();
///
- void release(Buffer* buf);
+ void release(Buffer * buf);
///
- Buffer* newBuffer(string const &s, LyXRC *, bool =false);
+ Buffer* newBuffer(string const & s, LyXRC *, bool =false);
private:
enum {
/** The max number of buffers there are possible to have
Buffer *buffer[NUMBER_OF_BUFFERS];
///
friend class BufferStorage_Iter;
+#endif
};
+
+#ifndef NEW_STORE
/// An Iterator class for BufferStorage
class BufferStorage_Iter {
public:
///
unsigned char index;
};
-
+#endif
/** The class governing all the open buffers
///
BufferList();
- ///
- ~BufferList();
-
/// state info
enum list_state {
///
true), the file name will not be added to the last opened
files list
*/
- Buffer* loadLyXFile(string const & filename,
- bool tolastfiles = true);
+ Buffer * loadLyXFile(string const & filename,
+ bool tolastfiles = true);
///
- bool isEmpty();
+ bool empty();
/// Saves buffer. Returns false if unsuccesful.
bool write(Buffer *, bool makeBackup = true);
void resize();
/// Read a file into a buffer readonly or not.
- Buffer* readFile(string const &, bool ro);
+ Buffer * readFile(string const &, bool ro);
/// Make a new file (buffer) using a template
- Buffer* newFile(string const &, string);
+ Buffer * newFile(string const &, string);
/** This one must be moved to some other place.
*/
void makePup(int);
- ///** Later with multiple frames this should not be here.
- // */
- //Buffer* switchBuffer(Buffer *from, int);
-
///
- void updateInset(Inset*, bool = true);
+ void updateInset(Inset *, bool = true);
///
- int unlockInset(UpdatableInset*);
+ int unlockInset(UpdatableInset *);
///
void updateIncludedTeXfiles(string const &);
bool close(Buffer *);
///
- Buffer* first();
+ Buffer * first();
/// returns true if the buffer exists already
bool exists(string const &);
/// returns a pointer to the buffer with the given name.
- Buffer* getBuffer(string const &);
+ Buffer * getBuffer(string const &);
/// returns a pointer to the buffer with the given number.
- Buffer* getBuffer(int);
+ Buffer * getBuffer(int);
private:
///
return;
}
- tmppar = new LyXParagraph();
+ tmppar = new LyXParagraph;
+#ifdef NEW_TEXT
+ tmppar->text.reserve(500);
+#endif
tmppar->readSimpleWholeFile(myfile);
// set the end of the string
// way to do this (and the cleanest for now). This function just inserts
// a newline in the string and the inserts 'depth'-spaces so that the
// code is indented in the right way!!!
-void addNewlineAndDepth(string &file, int const depth)
+void addNewlineAndDepth(string & file, int const depth)
{
file += '\n';
- file.append(' ', depth);
+ file.append(depth, ' ');
}
{
//#warning Please see if you can trigger this!
// emergency save
- if (!bufferlist.isEmpty())
+ if (!bufferlist.empty())
bufferlist.emergencyWriteAll();
// Get the reason for the crash.
void LyXFunc::CloseBuffer()
{
if (bufferlist.close(owner->currentBuffer()) && !quitting) {
- if (bufferlist.isEmpty()) {
+ if (bufferlist.empty()) {
// need this otherwise SEGV may occur while trying to
// set variables that don't exist
// since there's no current buffer
#endif
#define NEW_TEXT 1
-#define NEW_TABLE 1
+//#define NEW_TABLE 1
#ifdef NEW_TABLE
#include <list>
#endif
#ifdef NEW_TEXT
-//#include <vector>
-#include <deque>
+#include <vector>
+//#include <deque>
+//#define __STD_STUFF 1
+//#include <rope.h>
#endif
#include "definitions.h"
#ifdef NEW_TEXT
///
- typedef deque<char> TextContainer;
+ typedef char value_type;
+ ///
+ typedef vector<value_type> TextContainer;
+ //typedef deque<char> TextContainer;
+ //typedef rope<char> TextContainer;
typedef int size_type;
///
TextContainer text;
// set the pseudo menu-button back
fl_set_object_boxtype(ob, FL_FLAT_BOX);
fl_redraw_object(ob);
+#ifdef NEW_STORE
+ if (choice > 0) men->handleBufferMenu(choice - 1);
+#else
if (choice > 0) men->handleBufferMenu(choice);
+#endif
fl_freepup(BufferMenu);
}
#endif
#ifdef NEW_TEXT
text.erase(text.begin() + pos);
+ //text.erase(pos, 1);
#else
// Shift rest of text
for (int i = pos; i < last - 1; i++) {
return;
}
text.insert(text.begin() + pos, c);
+ //text.insert(pos, c);
#else
/* > because last is the next unused position, and you can
* use it if you want */
#ifdef NEW_TEXT
pos_end = pos_first + par->text.size() - 1;
+ tmp->text.reserve(pos_end - pos);
#else
pos_end = pos_first + par->last - 1;
/* make sure there is enough memory for the now larger
for (i = pos_end; i >= pos; i--)
par->Erase(i - pos_first);
-#ifndef NEW_TEXT
+#ifdef NEW_TEXT
+ par->text.resize(par->text.size());
+#else
/* free memory of the now shorter paragraph*/
par->FitSize();
#endif
LyXParagraph * LyXParagraph::Clone()
{
/* create a new paragraph */
- LyXParagraph * result = new LyXParagraph();
+ LyXParagraph * result = new LyXParagraph;
result->MakeSameLayout(this);
/* copy everything behind the break-position to the new paragraph */
#ifdef NEW_TEXT
+ result->text.reserve(size());
for (size_type i = 0; i < size(); i++) {
CopyIntoMinibuffer(i);
result->InsertFromMinibuffer(i);
InsertFromMinibuffer will enlarge the memory (it uses
InsertChar of course). But doing it by hand
is MUCH faster! (only one time, not thousend times!!) */
-#ifndef NEW_TEXT
+#ifdef NEW_TEXT
+ tmp->text.reserve(pos_end - pos);
+#else
tmp->Enlarge(0, pos_end - pos);
#endif
for (i = pos; i <= pos_end; i++) {
}
for (i = pos_end; i >= pos; i--)
par->Erase(i - pos_first);
-#ifndef NEW_TEXT
+#ifdef NEW_TEXT
+ par->text.resize(par->text.size());
+#else
/* free memory of the now shorter paragraph*/
par->FitSize();
#endif
struct lyxstring::Srep {
///
- static lyxstring::size_type const xtra =
- static_cast<lyxstring::size_type>(8);
+ static size_t const xtra = static_cast<size_t>(8);
/// size
- lyxstring::size_type sz;
+ size_t sz;
/// Reference count
- unsigned short ref;
+ size_t ref;
/// The total amount of data reserved for this representaion
- lyxstring::size_type res;
+ size_t res;
/// Data. At least 1 char for trailing null.
lyxstring::value_type * s;
// test every last little thing we *know* should be true.
// I may have missed a test or two, so feel free to fill
// in the gaps. ARRae.
- // NOTE: Don't put TestlyxstringInvariant() in any of the
- // lyxstring methods used below otherwise you'll get an
- // infinite recursion and a crash.
Assert(object);
Assert(object->rep);
Assert(object->rep->s); // s is never 0
Assert(object->rep->res); // always some space allocated
- Assert(object->size() <= object->rep->res);
+ Assert(object->rep->sz <= object->rep->res);
Assert(object->rep->ref >= 1); // its in use so it must be referenced
- Assert(object->rep->ref < (1 << 8*sizeof(object->rep->ref)) - 1);
+ Assert(object->rep->ref < static_cast<size_t>(1 << (8 * sizeof(object->rep->ref) - 1)));
// if it does ever == then we should be generating a new copy
// and starting again. (Is char always 8-bits?)
}
// Constructors and Deconstructors.
///////////////////////////////////////
-lyxstring::size_type const lyxstring::npos = static_cast<lyxstring::size_type>(-1);
+lyxstring::size_type const lyxstring::npos =
+static_cast<lyxstring::size_type>(-1);
lyxstring::lyxstring()
{
}
-lyxstring::size_type lyxstring::rfind(value_type const * ptr, size_type i) const
+lyxstring::size_type lyxstring::rfind(value_type const * ptr,
+ size_type i) const
{
Assert(ptr);
TestlyxstringInvariant(this);
lyxstring::size_type lyxstring::find_first_not_of(lyxstring const & a,
- size_type i) const
+ size_type i) const
{
TestlyxstringInvariant(this);
////////////////////
// Compare funcs should be verified.
-// Should we try to make them work with '\0' value_types?
-// An STL string can usually contain '\0' value_types.
+
+int lyxstring::internal_compare(size_type pos, size_type n,
+ value_type const * s,
+ size_type slen, size_type n2) const
+{
+ if ((rep->sz == 0 || n == 0) && (!*s || n2 == 0)) return 0;
+ if (!*s) return 1;
+ // since n > n2, min(n,n2) == 0, c == 0 (stops segfault also)
+
+ // remember that n can very well be a lot larger than rep->sz
+ // so we have to ensure that n is no larger than rep->sz
+ n = min(n, rep->sz);
+ n2 = min(n2, slen);
+ if (n == n2)
+ return memcmp(&(rep->s[pos]), s, n);
+ int c = memcmp(&(rep->s[pos]), s, min(n,n2));
+ if (c)
+ return c;
+ if (n < n2)
+ return -1;
+ return 1;
+}
+
int lyxstring::compare(lyxstring const & str) const
{
TestlyxstringInvariant(this);
-
- return compare(0, rep->sz, str.c_str(), str.rep->sz);
+ return internal_compare(0, rep->sz, str.rep->s,
+ str.rep->sz, str.rep->sz);
}
{
Assert(s);
TestlyxstringInvariant(this);
-
- return compare(0, rep->sz, s, (!s) ? 0 : strlen(s));
+ int n = (!s) ? 0 : strlen(s);
+ return internal_compare(0, rep->sz, s, n, n);
}
int lyxstring::compare(size_type pos, size_type n, lyxstring const & str) const
{
+ Assert(pos < rep->sz || pos == 0);
TestlyxstringInvariant(this);
-
- return compare(pos, n, str.c_str(), str.rep->sz);
+ return internal_compare(pos, n, str.rep->s, str.rep->sz, str.rep->sz);
}
int lyxstring::compare(size_type pos, size_type n, lyxstring const & str,
- size_type pos2, size_type n2) const
+ size_type pos2, size_type n2) const
{
+ Assert(pos < rep->sz || pos == 0);
+ Assert(pos2 < str.rep->sz || pos2 == 0);
TestlyxstringInvariant(this);
-
- return compare(pos, n, str.c_str() + pos2, n2);
+ return internal_compare(pos, n,
+ str.rep->s + pos2,
+ str.rep->sz - pos2, n2);
}
int lyxstring::compare(size_type pos, size_type n, value_type const * s,
- size_type n2) const
+ size_type n2) const
{
Assert(s && (pos < rep->sz || pos == 0));
TestlyxstringInvariant(this);
-
- if ((rep->sz == 0 || n == 0) && (!*s || n2 == 0)) return 0;
- if (!*s) return 1;
- // since n > n2, min(n,n2) == 0, c == 0 (stops segfault also)
-
- // remember that n can very well be a lot larger than rep->sz
- // so we have to ensure that n is no larger than rep->sz
- n = min(n, rep->sz);
- n2 = min(n2, strlen(s));
- if (n == n2)
- return memcmp(&(rep->s[pos]), s, n);
- int c = memcmp(&(rep->s[pos]), s, min(n,n2));
- if (c)
- return c;
- if (n < n2)
- return -1;
- return 1;
+ return internal_compare(pos, n, s, (!s) ? 0 : strlen(s), n2);
}
//lyxstring & operator=(int);
//
//lyxstring & operator+=(int);
-
+
+ /// Compare this with s. works with embedded '\0' chars also.
+ int internal_compare(size_type pos, size_type n,
+ value_type const * s,
+ size_type slen, size_type n2) const;
+
/// Forward declaration of the string representation
struct Srep;
// DEC cxx requires this.
LyXParagraph::size_type main_body =
BeginningOfMainBody(row->par);
LyXParagraph::size_type i = row->pos;
- while (i < last) {
+ while (i <= last) {
#else
int main_body = BeginningOfMainBody(row->par);
int i = row->pos;
if (sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)
== sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)) {
/* only within one paragraph */
- simple_cut_buffer = new LyXParagraph();
+ simple_cut_buffer = new LyXParagraph;
#ifdef NEW_TEXT
+ simple_cut_buffer->text.reserve(500);
LyXParagraph::size_type i =
sel_start_cursor.pos;
#else
== sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)) {
/* only within one paragraph */
simple_cut_buffer = new LyXParagraph;
+#if NEW_TEXT
+ simple_cut_buffer->text.reserve(500);
+#endif
for (i = sel_start_cursor.pos; i < sel_end_cursor.pos; ++i){
sel_start_cursor.par->CopyIntoMinibuffer(i);
simple_cut_buffer->InsertFromMinibuffer(i - sel_start_cursor.pos);
if (par) {
int i = 0;
while (pos + i < par->Last() && str[i] &&
- str[i]==par->GetChar(pos+i)) {
- i++;
+ str[i] == par->GetChar(pos + i)) {
+ ++i;
}
if (!str[i])
return true;
if (undo->kind == Undo::EDIT){
tmppar2->text = tmppar->text;
#ifdef NEW_TEXT
- tmppar->text.clear();
+ //tmppar->text.clear();
+ tmppar->text.erase(tmppar->text.begin(),
+ tmppar->text.end());
#else
tmppar->text = 0;
#endif
// a memory optimization: Just store the layout information when only edit
if (kind == Undo::EDIT){
#ifdef NEW_TEXT
- tmppar2->text.clear();
+ //tmppar2->text.clear();
+ tmppar2->text.erase(tmppar2->text.begin(),
+ tmppar2->text.end());
#else
if (tmppar2->text)
delete[] tmppar2->text;
// a memory optimization: Just store the layout information when only edit
if (kind == Undo::EDIT){
#ifdef NEW_TEXT
- tmppar2->next->text.clear();
+ //tmppar2->next->text.clear();
+ tmppar2->next->text.erase(tmppar2->next->text.begin(), tmppar2->next->text.end());
#else
if (tmppar2->next->text)
delete[] tmppar2->next->text;