+2000-01-06 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * src/BufferView.C: first go at a TextCache to speed up switching
+ between documents.
+
2000-01-05 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* lib/examples/ItemizeBullets.lyx: update from Tino Meinen.
know when a user has cancelled input. Fixes annoying problems with
inserting labels and version control.
+1999-12-29 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * src/support/lstrings.C (tostr): rewritten to use strstream and
+ stringstream
+
+1999-12-28 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * src/support/filetools.C (IsFileWriteable): use fstream to check
+ (IsDirWriteable): use fileinfo to check
+
+ * src/support/filetools.h (FilePtr): whole class deleted
+
+ * src/insets/figinset.C (GetPSSizes): rewritten to use ifstream.
+
+ * src/lyxparagraph.h (readSimpleWholeFile): make arg istream
+
+ * src/lyx_cb.C (InsertAsciiFile): use ifstream instead of FilePtr
+
+ * src/bufferlist.C (write): use ifstream and ofstream instead of
+ FILE*
+
+ * src/Spacing.h: use istrstream instead of sscanf
+
+ * src/mathed/math_defs.h: change first arg to istream from FILE*
+
+ * src/buffer.C (insertLyXFile): use ifstream instead of FilePtr
+
+ * src/mathed/math_parser.C: have yyis to be an istream
+ (LexGetArg): use istream (yyis)
+ (yylex): ditto
+ (mathed_parse): ditto
+ (mathed_parser_file): first arg istream instead of FILE*, set yyis
+
+ * src/mathed/formula.C (Read): rewritten to use istream
+
+ * src/mathed/formulamacro.C (Read): rewritten to use istream
+
+ * src/lyxlex.h (~LyXLex): deleted desturctor
+ (getStream): new function, returns an istream
+ (getFile): deleted funtion
+ (IsOK): return is.good();
+
+ * src/lyxlex.C (LyXLex): delete file and owns_file
+ (setFile): open an filebuf and assign that to a istream instead of
+ using FILE*
+ (setStream): new function, takes an istream as arg.
+ (setFile): deleted function
+ (EatLine): rewritten us use istream instead of FILE*
+ (next): ditto
+ (nextToken): ditto
+
+ * src/table.C (LyXTable): use istream instead of FILE*
+ (Read): rewritten to take an istream instead of FILE*
+
1999-12-28 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/buffer.C (Dispatch): remove an extraneous break statement.
SUBDIRS = intl po src lib
EXTRA_DIST = ANNOUNCE OLD-CHANGES INSTALL.OS2 INSTALL.autoconf README.OS2 \
- UPGRADING NEWS acconfig.h lyx.man \
+ UPGRADING lyx.man \
config development forms images
ETAGS_ARGS = --c++
man_MANS = lyx.1
# Autogenerate lib/configure.m4. We need GNU m4 for that and thus have
# to try several ones.
ok=no
+#for prog in $M4 gm4 gnum4 m4 ; do
+# case `$prog --help < /dev/null 2>&1 | grep traditional` in
+# *traditional*) echo "Building lib/configure"
+# rm -f lib/configure
+# $prog lib/configure.m4 >lib/configure
+# chmod a+x lib/configure
+# ok=yes
+# break ;;
+# *) ;;
+# esac
+#done
+# Why not use --version ? (Lgb)
for prog in $M4 gm4 gnum4 m4 ; do
- case `$prog --help < /dev/null 2>&1 | grep traditional` in
- *traditional*) echo "Building lib/configure"
+ case `$prog --version 2>&1` in
+ *GNU*) echo "Building lib/configure"
rm -f lib/configure
$prog lib/configure.m4 >lib/configure
chmod a+x lib/configure
reload_cmds='$LD$reload_flag -o $output$reload_objs'
echo $ac_n "checking for $LD option to reload object files... $ac_c" 1>&6
# PORTME Some linkers may need a different reload flag.
+if [ x$with_gnu_ld = xyes ] ; then
+reload_flag='-Ur'
+else
reload_flag='-r'
+fi
echo "$ac_t$reload_flag" 1>&6
test -n "$reload_flag" && reload_flag=" $reload_flag"
LYX_STD_COUNT
dnl we disable rtti for now
dnl LYX_CXX_RTTI
-AC_CHECK_HEADERS(ostream istream)
+AC_CHECK_HEADERS(ostream istream sstream)
LYX_CXX_STL_MODERN_STREAMS
### We need a regex implementation, so we provide our own if none is found.
#include <config.h>
+#include <algorithm>
#include <cstdlib>
#include <csignal>
#include "gettext.h"
#include "layout.h"
+using std::find_if;
+
extern BufferList bufferlist;
void sigchldhandler(pid_t pid, int * status);
delete text;
}
+// This is only the very first implemetation and use of the TextCache,
+// operations on it needs to be put into a class or a namespace, that part
+// is _NOT_ finished so don't bother to come with too many comments on it
+// (unless you have some nice ideas on where/how to do it)
+//
+// I think we need a TextCache that is common for all BufferViews,
+// please tell if you don't agree.
+//
+// Q. What are we caching?
+// A. We are caching the screen representations (LyXText) of the
+// documents (Buffer,LyXParagraph) for specific BufferView widths.
+// Q. Why the cache?
+// A. It is not really needed, but it speeds things up a lot
+// when you have more than one document loaded at once since a total
+// rebreak (reformatting) need not be done when switching between
+// documents. When the cache is in function a document only needs to be
+// formatted upon loading and when the with of the BufferView changes.
+// Later it will also be unneccessary to reformat when having two
+// BufferViews of equal width with the same document, a simple copy
+// of the LyXText structure will do.
+// Invariant for the TextCache:
+// - The buffer of the text in the TextCache _must_ exists
+// in the bufferlist.
+// - For a text in the TextCache there _must not_ be an equivalent
+// text in any BufferView. (same buffer and width).
+// Among others this mean:
+// - When a document is closed all trace of it must be removed from
+// the TextCache.
+// Senarios:
+// I belive there are only three possible senarios where the two first
+// are also covered by the third.
+// - The simplest senario is what we have now, a single BufferView only.
+// o Opening
+// Nothing to do with the TextCache is done when opening a file.
+// o Switching
+// We switch from buffer A to buffer B.
+// * A's text is cached in TextCache.
+// * We make a search for a text in TextCache that fits B
+// (same buffer and same width).
+// o Horisontal resize
+// If the BufferView's width (LyXView) is horisontaly changed all
+// the entries in the TextCache is deleted. (This causes
+// reformat of all loaded documents when next viewed)
+// o Close
+// When a buffer is closed we don't have to do anything, becuase
+// to close a single buffer it is required to only exist in the
+// BufferView and not in the TextCache. Upon LFUN_QUIT we
+// don't really care since everything is deleted anyway.
+// - The next scenario is when we have several BufferViews (in one or
+// more LyXViews) of equal width.
+// o Opening
+// Nothing to do with the TextCache is done when opening a file.
+// o Switching
+// We switch from buffer A to buffer B.
+// * If A is in another Bufferview we do not put it into TextCache.
+// else we put A into TextCache.
+// * If B is viewed in another BufferView we make a copy of its
+// text and use that, else we search in TextCache for a match.
+// (same buffer same width)
+// o Horisontal resize
+// If the BufferView's width (LyXView) is horisontaly changed all
+// the entries in the TextCache is deleted. (This causes
+// reformat of all loaded documents when next viewed)
+// o Close
+// - The last scenario should cover both the previous ones, this time
+// we have several BufferViews (in one or more LyXViews) with no
+// limitations on width. (And if you wonder why the two other
+// senarios are needed... I used them to get to this one.)
+// o Opening
+// Nothing to do with the TextCache is done when opening a file.
+// o Switching
+// We switch from buffer A to buffer B.
+// o Horisontal resize
+// o Close
+
+typedef vector<LyXText*> TextCache;
+TextCache textcache;
+
+class text_fits {
+public:
+ text_fits(Buffer * b, unsigned short p)
+ : buf(b), pw(p) {}
+ bool operator()(TextCache::value_type & vt) {
+ if (vt->params == buf && vt->paperWidth() == pw) return true;
+ return false;
+ }
+private:
+ Buffer * buf;
+ unsigned short pw;
+};
+
+
+class show_text {
+public:
+ show_text(ostream & o) : os(o) {}
+ void operator()(TextCache::value_type & vt) {
+ os << "Buffer: " << vt->params
+ << "\nWidth: " << vt->paperWidth() << endl;
+ }
+private:
+ ostream & os;
+};
+void showTextCache(string const & str)
+{
+ lyxerr << "TextCache: " << str << endl;
+ for_each(textcache.begin(), textcache.end(), show_text(lyxerr));
+}
+
+
void BufferView::buffer(Buffer * b)
{
lyxerr[Debug::INFO] << "Setting buffer in BufferView" << endl;
if (buffer_) {
buffer_->InsetSleep();
buffer_->delUser(this);
- delete text;
+ // Put the old text into the TextCache.
+ textcache.push_back(text);
+ showTextCache("buffer");
+ // delete text;
text = 0;
}
owner_->getMenus()->hideMenus();
updateScrollbar();
fl_redraw_object(work_area);
+ // Also remove all remaining text's from the testcache.
+ showTextCache("buffer delete all");
+ while (!textcache.empty()) {
+ LyXText * tt = textcache.front();
+ textcache.erase(textcache.begin());
+ delete tt;
+ }
}
// should update layoutchoice even if we don't have a buffer.
owner_->updateLayoutChoice();
selection = text->selection;
mark_set = text->mark_set;
delete text;
+ text = new LyXText(work_area->w, buffer_);
+ } else {
+ // See if we have a text in TextCache that fits
+ // the new buffer_ with the correct width.
+ TextCache::iterator it =
+ find_if(textcache.begin(),
+ textcache.end(),
+ text_fits(buffer_,
+ work_area->w));
+ if (it != textcache.end()) {
+ text = *it;
+ // take it out of textcache.
+ textcache.erase(it);
+ showTextCache("resizeCurrentBuffer");
+ } else {
+ text = new LyXText(work_area->w, buffer_);
+ }
}
- text = new LyXText(work_area->w, buffer_);
-
updateScreen();
if (par) {
if (widthChange) {
// All buffers need a resize
bufferlist.resize();
+
+ // Remove all texts from the textcache
+ showTextCache("Expose delete all");
+ while(!textcache.empty()) {
+ LyXText * tt = textcache.front();
+ textcache.erase(textcache.begin());
+ delete tt;
+ }
} else if (heightChange) {
// Rebuild image of current screen
updateScreen();
}
}
}
+
+
+void BufferView::smallUpdate(signed char f)
+{
+ getScreen()->SmallUpdate();
+ if (getScreen()->TopCursorVisible()
+ != getScreen()->first) {
+ update(f);
+ return;
+ }
+
+ fitCursor();
+ updateScrollbar();
+
+ if (!text->selection)
+ text->sel_cursor = text->cursor;
+
+ if (f == 1 || f == -1) {
+ if (buffer()->isLyxClean()) {
+ buffer()->markDirty();
+ owner()->getMiniBuffer()->setTimer(4);
+ } else {
+ buffer()->markDirty();
+ }
+ }
+}
///
void update(signed char f);
///
+ void smallUpdate(signed char f);
+ ///
void updateScrollbar();
///
void redoCurrentBuffer();
string ret(font);
// Find the position of the size spec
int cut = 0;
- string::iterator before = 0;
- string::iterator after = 0;
+ string::iterator before = string::iterator(0);
+ string::iterator after = string::iterator(0);
for (string::iterator sit = ret.begin();
sit != ret.end(); ++sit)
if ((*sit) == '-') {
DISTCLEANFILES = libintl.h config.h
MAINTAINERCLEANFILES = Makefile.in config.h.in
bin_PROGRAMS = lyx
-lyx_DEPENDENCIES = mathed/libmathed.la insets/libinsets.la support/libsupport.la
+lyx_DEPENDENCIES = mathed/libmathed.o insets/libinsets.o support/libsupport.o
lyx_LDADD = $(lyx_DEPENDENCIES) @INTLLIBS@ $(LYX_LIBS)
EXTRA_DIST = config.h.in stamp-h.in cheaders
ETAGS_ARGS = --c++
#include <config.h>
-#include <cstdio>
#include "Spacing.h"
using std::ios;
#ifndef SPACING_H
#define SPACING_H
-#include <cstdio>
-#include "support/LOstream.h"
+#ifdef HAVE_SSTREAM
+#include <sstream>
+#else
+#include <strstream>
+#endif
+#include "support/LOstream.h"
///
class Spacing {
void set(Spacing::Space sp, char const * val)
{
float fval;
- sscanf(val, "%f", &fval);
+#ifdef HAVE_SSTREAM
+ istringstream istr(val);
+#else
+ istrstream istr(val);
+#endif
+ istr >> fval;
set(sp, fval);
}
///
// all these externs should eventually be removed.
extern BufferList bufferlist;
-extern void SmallUpdate(signed char);
extern unsigned char GetCurrentTextClass();
extern void BeforeChange();
BeforeChange();
- FilePtr myfile(fname, FilePtr::read);
- if (!myfile()) {
+ ifstream ifs(fname.c_str());
+ if (!ifs) {
WriteAlert(_("Error!"),
_("Cannot open specified file: "),
MakeDisplayPath(fname, 50));
return false;
}
LyXLex lex(0, 0);
- lex.setFile(myfile);
- int c = fgetc(myfile());
- ungetc(c, myfile);
+ lex.setStream(ifs);
+ char c; ifs.get(c);
+ ifs.putback(c);
bool res = true;
continue;
else if (token[0] != '\\') {
int n = token.length();
- for (int i = 0; i < n; i++) {
+ for (int i = 0; i < n; ++i) {
par->InsertChar(pos, token[i]);
par->SetFont(pos, font);
- pos++;
+ ++pos;
}
} else if (token == "\\i") {
inset = new InsetLatexAccent;
font = LyXFont(LyXFont::ALL_INHERIT);
} else if (token == "\\begin_float") {
tmpret = lex.FindToken(string_footnotekinds);
- if (tmpret == -1) tmpret++;
+ if (tmpret == -1) ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT)
footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
if (footnotekind == LyXParagraph::FOOTNOTE
else
footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
} else if (token == "\\begin_deeper") {
- depth++;
+ ++depth;
} else if (token == "\\end_deeper") {
if (!depth) {
lex.printError("\\end_deeper: "
"depth is already null");
}
else
- depth--;
+ --depth;
} else if (token == "\\begin_preamble") {
params.readPreamble(lex);
} else if (token == "\\textclass") {
lex.EatLine();
- pair<bool, LyXTextClassList::ClassList::size_type> pp =
+ pair<bool, LyXTextClassList::size_type> pp =
textclasslist.NumberOfClass(lex.GetString());
if (pp.first) {
params.textclass = pp.second;
lex.EatLine();
params.options = lex.GetString();
} else if (token == "\\language") {
- params.readLanguage(lex);
+ params.readLanguage(lex);
} else if (token == "\\fontencoding") {
lex.EatLine();
} else if (token == "\\inputencoding") {
} else if (token == "\\defskip") {
lex.nextToken();
params.defskip = VSpace(lex.GetString());
- } else if (token == "\\no_isolatin1") {
+ } else if (token == "\\no_isolatin1") { // obsolete
lex.nextToken();
- } else if (token == "\\no_babel") {
+ } else if (token == "\\no_babel") { // obsolete
lex.nextToken();
- } else if (token == "\\no_epsfig") {
+ } else if (token == "\\no_epsfig") { // obsolete
lex.nextToken();
} else if (token == "\\epsfig") { // obsolete
// Indeed it is obsolete, but we HAVE to be backwards
} else if (token == "\\tocdepth") {
lex.nextToken();
params.tocdepth = lex.GetInteger();
- } else if (token == "\\baselinestretch") { // now obsolete
+ } else if (token == "\\baselinestretch") { // obsolete
lex.nextToken(); // should not be used directly
// anymore.
// Will probably keep a kind of support just for
} else if (token == "\\float_placement") {
lex.nextToken();
params.float_placement = lex.GetString();
- } else if (token == "\\cursor") {
+ } else if (token == "\\cursor") { // obsolete
// this is obsolete, so we just skip it.
lex.nextToken();
} else if (token == "\\family") {
} else if (token == "\\align") {
tmpret = lex.FindToken(string_align);
if (tmpret == -1) tmpret++;
- if (tmpret != LYX_LAYOUT_DEFAULT) {
+ if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
tmpret2 = 1;
- for (; tmpret>0; tmpret--)
+ for (; tmpret > 0; --tmpret)
tmpret2 = tmpret2 * 2;
par->align = LyXAlignment(tmpret2);
}
- } else if (token == "\\added_space_top"){
+ } else if (token == "\\added_space_top") {
lex.nextToken();
par->added_space_top = lex.GetString();
} else if (token == "\\added_space_bottom") {
par->InsertInset(pos, inset);
par->SetFont(pos, font);
pos++;
+#if 0
} else if (tmptok == "Label") {
// Kept for compability. Remove in 0.13.
if (lex.EatLine()) {
par->SetFont(pos, font);
pos++;
}
+#endif
} else if (tmptok == "Info") {
inset = new InsetInfo;
inset->Read(lex);
if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
inset = new InsetRef(inscmd, this);
}
- /* This condition comes from a temporary solution
- to the latexdel ref inset that was transformed to an empty ref
- inset plus the body surronded by latexdel insets */
+ // This condition comes from a
+ // temporary solution to the latexdel
+ // ref inset that was transformed to
+ // an empty ref inset plus the body
+ // surronded by latexdel insets
else {
string cont, opt, tmptmptok, cmdname;
lex.next();
inset = new InsetPrintIndex(this);
} else if (inscmd.getCmdName() == "lyxparent") {
inset = new InsetParent(inscmd.getContents(), this);
- } else
+ }
+#if 0
+ // Do we need this at all now?
+ else
// The following three are only for compatibility
if (inscmd.getCmdName() == "-") {
inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
} else
inset = inscmd.Clone();
+#endif
if (inset) {
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
}
}
} else if (token == "\\InsetQuotes") {
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
#if 0
} else if (token == "\\InsetLatex") {
inset = new InsetLatex;
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\InsetLatexDel") {
lex.printError(_("Warning: Ignoring Old Inset"));
#endif
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\SpecialChar") {
inset = new InsetSpecialChar;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\Figure") {
inset = new InsetFig(100, 100, this);
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\newline") {
par->InsertChar(pos, LyXParagraph::META_NEWLINE);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\LyXTable") {
par->table = new LyXTable(lex);
} else if (token == "\\hfill") {
par->InsertChar(pos, LyXParagraph::META_HFILL);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\protected_separator") {
par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\bibitem") { // ale970302
if (!par->bibkey)
par->bibkey = new InsetBibKey;
}else if (token == "\\backslash") {
par->InsertChar(pos, '\\');
par->SetFont(pos, font);
- pos++;
+ ++pos;
}else if (token == "\\the_end") {
the_end_read = true;
} else {
lex.printError("Unknown token `$$Token'. "
"Inserting as text.");
int n = token.length();
- for (int i = 0; i < n; i++) {
+ for (int i = 0; i < n; ++i) {
par->InsertChar(pos, token[i]);
par->SetFont(pos, font);
- pos++;
+ ++pos;
}
}
}
}
lyxerr.debug() << "lyx header finished" << endl;
// There are a few differences between nice LaTeX and usual files:
- // usual is \batchmode, uses \listfiles and has a
+ // usual is \batchmode and has a
// special input@path to allow the including of figures
// with either \input or \includegraphics (what figinsets do).
// batchmode is not set if there is a tex_code_break_column.
LFile += "\\batchmode\n"; // changed
// from \nonstopmode
texrow.newline();
- // We don't need listfiles anymore
- //LFile += "\\listfiles\n";
- //texrow.newline();
}
if (!original_path.empty()) {
LFile += "\\makeatletter\n";
void Buffer::push_tag(ostream & os, char const * tag,
int & pos, char stack[5][3])
{
- int j;
-
/* pop all previous tags */
- for (j = pos; j >= 0; --j)
+ for (int j = pos; j >= 0; --j)
os << "</" << stack[j] << ">";
/* add new tag */
sprintf(stack[++pos], "%s", tag);
/* push all tags */
- for (j = 0; j <= pos; ++j)
- os << "<" << stack[j] << ">";
+ for (int i = 0; i <= pos; ++i)
+ os << "<" << stack[i] << ">";
}
void Buffer::pop_tag(ostream & os, char const * tag,
int & pos, char stack[5][3])
{
- int j;
-
// pop all tags till specified one
- for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
+ for (int j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
os << "</" << stack[j] << ">";
// closes the tag
os << "</" << tag << ">";
// push all tags, but the specified one
- for (j = j + 1; j <= pos; ++j) {
- os << "<" << stack[j] << ">";
- strcpy(stack[j-1], stack[j]);
+ for (int i = i + 1; i <= pos; ++i) {
+ os << "<" << stack[i] << ">";
+ strcpy(stack[i - 1], stack[i]);
}
--pos;
}
return;
}
- //ResetTexRow();
texrow.reset();
ofs << "<!doctype " << top_element
#include "LyXView.h"
extern BufferView * current_view;
-extern void SmallUpdate(signed char);
extern void BeforeChange();
extern int RunLinuxDoc(int, string const &);
times->modtime = finfo.getModificationTime();
long blksize = finfo.getBlockSize();
lyxerr.debug() << "BlockSize: " << blksize << endl;
- FilePtr fin(buf->fileName(), FilePtr::read);
- FilePtr fout(s, FilePtr::truncate);
- if (fin() && fout()) {
- char * cbuf = new char[blksize+1];
- size_t c_read = 0;
- size_t c_write = 0;
- do {
- c_read = fread(cbuf, 1, blksize, fin);
- if (c_read != 0)
- c_write =
- fwrite(cbuf, 1,
- c_read, fout);
- } while (c_read);
- fin.close();
- fout.close();
+ ifstream ifs(buf->fileName().c_str());
+ ofstream ofs(s.c_str(), ios::out|ios::trunc);
+ if (ifs && ofs) {
+ char c = 0;
+ while (ifs.get(c)) {
+ ofs.put(c);
+ };
+ ifs.close();
+ ofs.close();
chmod(s.c_str(), fmode);
if (utime(s.c_str(), times)) {
lyxerr << "utime error." << endl;
}
- delete [] cbuf;
} else {
lyxerr << "LyX was not able to make "
"backupcopy. Beware." << endl;
{ Debug::LYXSERVER, "lyxserver", "External control interface"},
{ Debug::ROFF, "roff", "Keep *roff temporary files"},
{ Debug::ACTION, "action", "User commands"},
+ { Debug::LYXLEX, "lyxlex", "The LyX Lexxer"},
{ Debug::NONE, "none", "No debugging message"},
{ Debug::ANY, "any", "All debugging messages"}
};
<< " " << errorTags[i].desc << '\n';
os.flush();
}
-
-
-
///
ROFF = (1 << 13), // 8192
///
- ACTION = (1 << 14) // 16384
+ ACTION = (1 << 14), // 16384
+ ///
+ LYXLEX = (1 << 15)
};
///
static const type ANY = type(INFO | INIT | KEY | TOOLBAR |
PARSER | LYXRC | KBMAP | LATEX |
MATHED | FONT | TCLASS | LYXVC |
- LYXSERVER | ROFF | ACTION);
+ LYXSERVER | ROFF | ACTION | LYXLEX);
///
friend inline void operator|=(Debug::type & d1, Debug::type d2);
#include <config.h>
#include <unistd.h>
-#include <cstdio>
#include <cstdlib>
#include <pwd.h>
#include <grp.h>
AUTOMAKE_OPTIONS = foreign
MAINTAINERCLEANFILES = Makefile.in
-noinst_LTLIBRARIES = libinsets.la
+noinst_LTLIBRARIES = libinsets.o
LIBS =
ETAGS_ARGS = --c++
INCLUDES = -I${srcdir}/../
-libinsets_la_SOURCES = \
+libinsets_o_SOURCES = \
figinset.C \
figinset.h \
form_url.C \
}
-static char * NextToken(FILE * myfile)
+static string NextToken(istream & is)
{
- char * token = 0;
+ string token;
char c;
- int i = 0;
-
- if (!feof(myfile)) {
- token = new char[256];
+ if (!is.eof()) {
do {
- c = fgetc(myfile);
- token[i++]= c;
- } while (!feof(myfile) && !isspace(c));
-
- token[i-1]= '\0'; /* just the end of a command */
+ is.get(c);
+ token += c;
+ } while (!is.eof() && !isspace(c));
+ token.erase(token.length() - 1); // remove the isspace
}
return token;
}
void InsetFig::GetPSSizes()
{
-#ifdef WITH_WARNINGS
-#warning rewrite this method to use ifstream
-#endif
/* get %%BoundingBox: from postscript file */
- char * p = 0;
/* defaults to associated size
* ..just in case the PS-file is not readable (Henner, 24-Aug-97)
pshgh = hgh;
if (fname.empty()) return;
+ string p;
+ ifstream ifs(fname.c_str());
- FilePtr f(fname, FilePtr::read);
-
- if (!f()) return; // file not found !!!!
+ if (!ifs) return; // file not found !!!!
/* defaults to A4 page */
psx = 0;
pswid = 595;
pshgh = 842;
- int lastchar = fgetc(f);
+ char lastchar = 0; ifs.get(lastchar);
for (;;) {
- int c = fgetc(f);
- if (c == EOF) {
+ char c = 0; ifs.get(c);
+ if (ifs.eof()) {
lyxerr.debug() << "End of (E)PS file reached and"
" no BoundingBox!" << endl;
break;
}
if (c == '%' && lastchar == '%') {
- p = NextToken(f);
- if (!p) break;
+ p = NextToken(ifs);
+ if (p.empty()) break;
// we should not use this, with it we cannot
// discover bounding box and end of file.
//if (strcmp(p, "EndComments") == 0) break;
- if (strcmp(p, "BoundingBox:") == 0) {
+ lyxerr.debug() << "Token: `" << p << "'" << endl;
+ if (p == "BoundingBox:") {
float fpsx, fpsy, fpswid, fpshgh;
- if (fscanf(f, "%f %f %f %f", &fpsx, &fpsy,
- &fpswid, &fpshgh) == 4) {
+ if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
psx = int(fpsx);
psy = int(fpsy);
pswid = int(fpswid);
pshgh = int(fpshgh);
- }
-
+ }
if (lyxerr.debugging()) {
lyxerr << "%%%%BoundingBox:"
<< psx << ' '
break;
}
c = 0;
- delete[] p;
- p = 0;
}
lastchar = c;
}
- if (p) delete[] p;
pswid -= psx;
pshgh -= psy;
#include <config.h>
#include <cstring>
-#include <cstdio>
#include "support/lstrings.h"
#include "gettext.h"
//////////////////////////////////////////
// Gets textclass number from name
-pair<bool, LyXTextClassList::ClassList::size_type>
+pair<bool, LyXTextClassList::size_type>
LyXTextClassList::NumberOfClass(string const & textclass) const
{
for (ClassList::const_iterator cit = classlist.begin();
if ((*cit).name() == textclass)
return make_pair(true, cit - classlist.begin());
}
- return make_pair(false, 0);
+ return make_pair(false, size_type(0));
}
// Gets layout structure from style number and textclass number
LyXLayout const &
-LyXTextClassList::Style(LyXTextClassList::ClassList::size_type textclass,
- LyXTextClass::LayoutList::size_type layout) const
+LyXTextClassList::Style(LyXTextClassList::size_type textclass,
+ LyXTextClass::size_type layout) const
{
classlist[textclass].load();
if (layout < classlist[textclass].numLayouts())
// Gets layout number from name and textclass number
-pair<bool, LyXTextClass::LayoutList::size_type>
-LyXTextClassList::NumberOfLayout(LyXTextClassList::ClassList::size_type textclass, string const & name) const
+pair<bool, LyXTextClass::size_type>
+LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
+ string const & name) const
{
classlist[textclass].load();
for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
}
if (name == "dummy")
return make_pair(true, LYX_DUMMY_LAYOUT);
- return make_pair(false, 0); // not found
+ return make_pair(false, LyXTextClass::LayoutList::size_type(0)); // not found
}
// Gets a layout (style) name from layout number and textclass number
string const &
-LyXTextClassList::NameOfLayout(LyXTextClassList::ClassList::size_type textclass,
- LyXTextClass::LayoutList::size_type layout) const
+LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
+ LyXTextClass::size_type layout) const
{
static string dummy("dummy");
-#if 1
+#if 0
static string end("@@end@@");
#endif
classlist[textclass].load();
if (layout < classlist[textclass].numLayouts())
return classlist[textclass][layout].name();
-#if 1
+#if 0
else if (layout == LYX_DUMMY_LAYOUT)
return dummy;
else
// Gets a textclass name from number
string const &
-LyXTextClassList::NameOfClass(LyXTextClassList::ClassList::size_type number) const
+LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
{
static string dummy("dummy");
-#if 1
+#if 0
static string end("@@end@@");
#endif
if (classlist.size() == 0) {
-#if 1
+#if 0
if (number == 0) return dummy;
else return end;
#else
return dummy;
#endif
}
-#if 1
+#if 0
if (number < classlist.size())
return classlist[number].name();
else
// Gets a textclass latexname from number
string const &
-LyXTextClassList::LatexnameOfClass(LyXTextClassList::ClassList::size_type number) const
+LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
{
static string dummy("dummy");
-#if 1
+#if 0
static string end("@@end@@");
#endif
classlist[number].load();
if (classlist.size() == 0) {
-#if 1
+#if 0
if (number == 0) return dummy;
else return end;
#else
return dummy;
#endif
}
-#if 1
+#if 0
if (number < classlist.size())
return classlist[number].latexname();
// Gets a textclass description from number
string const &
-LyXTextClassList::DescOfClass(LyXTextClassList::ClassList::size_type number) const
+LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
{
static string dummy("dummy");
-#if 1
+#if 0
static string end("@@end@@");
#endif
if (classlist.size() == 0) {
-#if 1
+#if 0
if (number == 0) return dummy;
else return end;
#else
return dummy;
#endif
}
-#if 1
+#if 0
if (number < classlist.size())
return classlist[number].description();
else
// Gets a textclass structure from number
LyXTextClass const &
-LyXTextClassList::TextClass(LyXTextClassList::ClassList::size_type textclass) const
+LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
{
classlist[textclass].load();
if (textclass < classlist.size())
// compiled in... (Lgb)
}
- lex.setFile(real_file);
+ if (!lex.setFile(real_file)) {
+ lyxerr << "LyXTextClassList::Read: "
+ "lyxlex was not able to set file: "
+ << real_file << endl;
+ }
if (!lex.IsOK()) {
lyxerr << "LyXTextClassList::Read: unable to open "
Returns false if this fails
*/
bool
-LyXTextClassList::Load (LyXTextClassList::ClassList::size_type number) const
+LyXTextClassList::Load (LyXTextClassList::size_type number) const
{
bool result = true;
if (number < classlist.size()) {
Spacing spacing;
///
- LyXAlignment align; // add approp. signedness
+ LyXAlignment align;
///
- LyXAlignment alignpossible; // add approp. signedness
+ LyXAlignment alignpossible;
///
- char labeltype; // add approp. signedness
+ char labeltype; // add approp. type
///
- char margintype; // add approp. signedness
+ char margintype; // add approp. type
///
bool fill_top;
typedef vector<LyXLayout> LayoutList;
///
typedef LayoutList::const_iterator const_iterator;
-
+ ///
+ typedef LayoutList::size_type size_type;
///
LyXTextClass (string const & = string(),
string const & = string(),
///
int maxcounter() const { return maxcounter_; }
///
- LayoutList::size_type numLayouts() const { return layoutlist.size(); }
+ size_type numLayouts() const { return layoutlist.size(); }
///
- LyXLayout const & operator[](LayoutList::size_type i) const {
+ LyXLayout const & operator[](size_type i) const {
return layoutlist[i];
}
private:
///
typedef ClassList::const_iterator const_iterator;
///
+ typedef ClassList::size_type size_type;
+ ///
const_iterator begin() const { return classlist.begin(); }
///
const_iterator end() const { return classlist.end(); }
/// Gets layout structure from layout number and textclass number
- LyXLayout const & Style(ClassList::size_type textclass,
- LyXTextClass::LayoutList::size_type layout) const;
+ LyXLayout const & Style(size_type textclass,
+ LyXTextClass::size_type layout) const;
/// Gets layout number from textclass number and layout name
- pair<bool, LyXTextClass::LayoutList::size_type>
- NumberOfLayout(ClassList::size_type textclass,
+ pair<bool, LyXTextClass::size_type>
+ NumberOfLayout(size_type textclass,
string const & name) const;
/// Gets a layout name from layout number and textclass number
string const &
- NameOfLayout(ClassList::size_type textclass,
- LyXTextClass::LayoutList::size_type layout) const;
+ NameOfLayout(size_type textclass,
+ LyXTextClass::size_type layout) const;
/** Gets textclass number from name.
Returns -1 if textclass name does not exist
*/
- pair<bool, ClassList::size_type>
+ pair<bool, size_type>
NumberOfClass(string const & textclass) const;
///
- string const & NameOfClass(ClassList::size_type number) const;
+ string const & NameOfClass(size_type number) const;
///
- string const & LatexnameOfClass(ClassList::size_type number) const;
+ string const & LatexnameOfClass(size_type number) const;
///
- string const & DescOfClass(ClassList::size_type number) const;
+ string const & DescOfClass(size_type number) const;
///
- LyXTextClass const & TextClass(ClassList::size_type textclass) const;
+ LyXTextClass const & TextClass(size_type textclass) const;
/** Read textclass list.
Returns false if this fails
/** Load textclass.
Returns false if this fails
*/
- bool Load(ClassList::size_type number) const;
+ bool Load(size_type number) const;
private:
///
mutable ClassList classlist;
}
-// candidate for move to BufferView
-void SmallUpdate(signed char f)
-{
- current_view->getScreen()->SmallUpdate();
- if (current_view->getScreen()->TopCursorVisible()
- != current_view->getScreen()->first) {
- current_view->update(f);
- return;
- }
-
- current_view->fitCursor();
- current_view->updateScrollbar();
-
- if (!current_view->text->selection)
- current_view->text->sel_cursor =
- current_view->text->cursor;
-
- if (f == 1 || f == -1) {
- if (current_view->buffer()->isLyxClean()) {
- current_view->buffer()->markDirty();
- current_view->owner()->getMiniBuffer()->setTimer(4);
- }
- else {
- current_view->buffer()->markDirty();
- }
- }
-}
-
-
//
// Menu callbacks
//
return;
}
- FilePtr myfile(fname, FilePtr::read);
- if (!myfile()) {
+ ifstream ifs(fname.c_str());
+ if (!ifs) {
WriteFSAlert(_("Error! Cannot open specified file: "),
MakeDisplayPath(fname, 50));
return;
}
LyXParagraph * tmppar = new LyXParagraph;
- tmppar->readSimpleWholeFile(myfile);
+ tmppar->readSimpleWholeFile(ifs);
// set the end of the string
#ifdef WITH_WARNINGS
extern void HFill();
extern void MenuUndo();
extern void MenuRedo();
-extern void SmallUpdate(signed char);
extern void SetUpdateTimer(float timer = 0.3);
extern void FreeUpdateTimer();
extern bool MenuPreview(Buffer *);
LyXAction::ReadOnly)) {
// no
setErrorMessage(N_("Document is read-only"));
- flag = func_status(flag | LyXFunc::Disabled);
+ flag |= LyXFunc::Disabled;
}
} else {
// no
setErrorMessage(N_("Command not allowed with"
"out any document open"));
- flag = func_status(flag | LyXFunc::Disabled);
+ flag |= LyXFunc::Disabled;
}
}
if (flag & LyXFunc::Disabled)
return flag;
+ // I would really like to avoid having this switch and rather try to
+ // encode this in the function itself.
static bool noLaTeX = lyxrc->latex_command == "none";
bool disable = false;
switch (action) {
case LFUN_BREAKLINE:
BeforeChange();
owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
SetUpdateTimer(0.01);
moveCursorUpdate(false);
break;
BeforeChange();
owner->view()->text->
InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
SetUpdateTimer();
moveCursorUpdate(false);
break;
owner->view()->text->Delete();
owner->view()->text->sel_cursor =
owner->view()->text->cursor;
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
// It is possible to make it a lot faster still
// just comment out the lone below...
owner->view()->getScreen()->ShowCursor();
owner->view()->text->Delete();
owner->view()->text->sel_cursor =
owner->view()->text->cursor;
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
}
} else {
owner->view()->text->Delete();
owner->view()->text->sel_cursor =
owner->view()->text->cursor;
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
}
} else {
CutCB();
owner->view()->text->Backspace();
owner->view()->text->sel_cursor =
owner->view()->text->cursor;
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
// It is possible to make it a lot faster still
// just comment out the lone below...
owner->view()->getScreen()->ShowCursor();
owner->view()->text->Backspace();
owner->view()->text->sel_cursor
= cursor;
- SmallUpdate (1);
+ owner->view()->smallUpdate (1);
}
} else
CutCB();
{
BeforeChange();
owner->view()->text->BreakParagraph(0);
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
SetUpdateTimer(0.01);
owner->view()->text->sel_cursor =
owner->view()->text->cursor;
{
BeforeChange();
owner->view()->text->BreakParagraph(1);
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
SetUpdateTimer(0.01);
owner->view()->text->sel_cursor =
owner->view()->text->cursor;
}
else {
owner->view()->text->BreakParagraph(0);
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
}
SetUpdateTimer(0.01);
owner->view()->text->sel_cursor = cursor;
case LFUN_QUOTE:
BeforeChange();
owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
SetUpdateTimer();
moveCursorUpdate(false);
break;
keyseq.length = 0;
// copied verbatim from do_accent_char
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
SetUpdateTimer();
owner->view()->text->sel_cursor =
owner->view()->text->cursor;
owner->view()->text->InsertChar(argument[i]);
// This needs to be in the loop, or else we
// won't break lines correctly. (Asger)
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
}
SetUpdateTimer();
owner->view()->text->sel_cursor =
owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
}
- SmallUpdate(1);
+ owner->view()->smallUpdate(1);
SetUpdateTimer();
owner->view()->text->sel_cursor =
#include "support/filetools.h"
LyXLex::LyXLex(keyword_item * tab, int num)
- : table(tab), no_items(num)
+ : is(&fb__), table(tab), no_items(num)
{
- file = 0;
- owns_file = false;
+
status = 0;
pushed = 0;
}
bool LyXLex::setFile(string const & filename)
{
- if (file)
- lyxerr << "Error in LyXLex::setFile: file already set." <<endl;
- file = fopen(filename.c_str(), "r");
+ if (fb__.is_open())
+ lyxerr << "Error in LyXLex::setFile: "
+ "file or stream already set." << endl;
+ fb__.open(filename.c_str(), ios::in);
+ is.rdbuf(&fb__);
name = filename;
- owns_file = true;
lineno = 0;
- return (file ? true : false);
+ return fb__.is_open() && is.good();
}
-void LyXLex::setFile(FILE * f)
+void LyXLex::setStream(istream & i)
{
- if (file)
- lyxerr << "Error in LyXLex::setFile: file already set."
- << endl;
- file = f;
- owns_file = false;
- lineno = 0; // this is bogus if the file already has been read from
+ if (fb__.is_open() || is.rdbuf()->in_avail())
+ lyxerr << "Error in LyXLex::setStream: "
+ "file or stream already set." << endl;
+ is.rdbuf(i.rdbuf());
+ lineno = 0;
}
int LyXLex::lex()
{
//NOTE: possible bug.
- if (next() && status == LEX_TOKEN)
- return search_kw(buff);
- else
- return status;
+ if (next() && status == LEX_TOKEN)
+ return search_kw(buff);
+ else
+ return status;
}
int LyXLex::GetInteger() const
{
- if (buff[0] > ' ')
- return atoi(buff);
- else {
- printError("Bad integer `$$Token'");
- return -1;
- }
+ if (buff[0] > ' ')
+ return atoi(buff);
+ else {
+ printError("Bad integer `$$Token'");
+ return -1;
+ }
}
bool LyXLex::GetBool() const
{
- if (compare(buff, "true") == 0)
- return true;
- else if (compare(buff, "false") != 0)
- printError("Bad boolean `$$Token'. Use \"false\" or \"true\"");
- return false;
+ if (compare(buff, "true") == 0)
+ return true;
+ else if (compare(buff, "false") != 0)
+ printError("Bad boolean `$$Token'. Use \"false\" or \"true\"");
+ return false;
}
bool LyXLex::EatLine()
{
int i = 0;
- int c = '\0'; // getc() returns an int
+ unsigned char c = '\0';
- while (!feof(file) && c!= '\n' && i!= (LEX_MAX_BUFF-1)) {
- c = getc(file);
+ while(is && c != '\n' && i != (LEX_MAX_BUFF - 1)) {
+ is.get(c);
if (c != '\r')
buff[i++] = c;
}
- if (i == (LEX_MAX_BUFF-1) && c != '\n') {
- printError("Line too long");
+ if (i == (LEX_MAX_BUFF - 1) && c != '\n') {
+ printError("Line too long");
c = '\n'; // Pretend we had an end of line
--lineno; // but don't increase line counter (netto effect)
++i; // and preserve last character read.
bool LyXLex::next(bool esc)
{
if (!esc) {
- int c; // getc() returns an int
+ unsigned char c; // getc() returns an int
status = 0;
- while (!feof(file) && !status) {
- c = getc(file);
+ while (is && !status) {
+ is.get(c);
if (c == '#') {
// Read rest of line (fast :-)
- fgets(buff, sizeof(buff), file);
+ is.get(buff, sizeof(buff));
+ lyxerr[Debug::LYXLEX] << "Comment read: " << c << buff << endl;
++lineno;
continue;
}
if (c == '\"') {
int i = -1;
do {
- c = getc(file);
+ is.get(c);
if (c != '\r')
buff[++i] = c;
- } while (c!= '\"' && c!= '\n' && !feof(file) &&
- i!= (LEX_MAX_BUFF-2));
+ } while (c != '\"' && c != '\n' && is &&
+ i != (LEX_MAX_BUFF - 2));
- if (i == (LEX_MAX_BUFF-2)) {
+ if (i == (LEX_MAX_BUFF - 2)) {
printError("Line too long");
c = '\"'; // Pretend we got a "
++i;
}
- if (c!= '\"') {
+ if (c != '\"') {
printError("Missing quote");
if (c == '\n')
++lineno;
if (c == ',')
continue; /* Skip ','s */
-
- if (c > ' ' && !feof(file)) {
+
+ // using relational operators with chars other
+ // than == and != is not safe. And if it is done
+ // the type _have_ to be unsigned. It usually a
+ // lot better to use the functions from cctype
+ if (c > ' ' && is) {
+#warning Verify this! (Lgb)
+ //if (isalnum(static_cast<unsigned char>(c)) && is) {
int i = 0;
do {
buff[i++] = c;
- c = getc(file);
- } while (c > ' ' && c != ',' && !feof(file) &&
- (i != LEX_MAX_BUFF-1) );
- if (i == LEX_MAX_BUFF-1) {
+ is.get(c);
+ } while (c > ' ' && c != ',' && is
+ //} while (isalnum(static_cast<unsigned char>(c))
+ //&& c != ',' && is
+ && (i != LEX_MAX_BUFF - 1) );
+ if (i == LEX_MAX_BUFF - 1) {
printError("Line too long");
}
buff[i] = '\0';
status = LEX_TOKEN;
}
- if (c == '\r' && !feof(file)) {
+ if (c == '\r' && is) {
// The Windows support has lead to the
// possibility of "\r\n" at the end of
// a line. This will stop LyX choking
// when it expected to find a '\n'
- c = getc(file);
+ is.get(c);
}
if (c == '\n')
}
if (status) return true;
- status = (feof(file)) ? LEX_FEOF: LEX_UNDEF;
+ status = is.eof() ? LEX_FEOF: LEX_UNDEF;
buff[0] = '\0';
return false;
} else {
- int c; // getc() returns an int
+ unsigned char c; // getc() returns an int
status = 0;
- while (!feof(file) && !status) {
- c = getc(file);
+ while (is && !status) {
+ is.get(c);
// skip ','s
if (c == ',') continue;
do {
if (c == '\\') {
// escape the next char
- c = getc(file);
+ is.get(c);
}
buff[i++] = c;
- c = getc(file);
- } while (c > ' ' && c != ',' && !feof(file) &&
- (i != LEX_MAX_BUFF-1) );
- if (i == LEX_MAX_BUFF-1) {
+ is.get(c);
+ } while (c > ' ' && c != ',' && is
+ //} while (isalnum(static_cast<unsigned char>(c))
+ //&& c != ',' && is
+ && (i != LEX_MAX_BUFF - 1) );
+ if (i == LEX_MAX_BUFF - 1) {
printError("Line too long");
}
buff[i] = '\0';
if (c == '#') {
// Read rest of line (fast :-)
- fgets(buff, sizeof(buff), file);
+ is.get(buff, sizeof(buff));
+ lyxerr[Debug::LYXLEX] << "Comment read: " << c << buff << endl;
++lineno;
continue;
}
bool escaped = false;
do {
escaped = false;
- c = getc(file);
+ is.get(c);
if (c == '\r') continue;
if (c == '\\') {
// escape the next char
- c = getc(file);
+ is.get(c);
escaped = true;
}
buff[++i] = c;
if (!escaped && c == '\"') break;
- } while (c!= '\n' && !feof(file) &&
- i!= (LEX_MAX_BUFF-2));
+ } while (c != '\n' && is &&
+ i != (LEX_MAX_BUFF - 2));
- if (i == (LEX_MAX_BUFF-2)) {
+ if (i == (LEX_MAX_BUFF - 2)) {
printError("Line too long");
c = '\"'; // Pretend we got a "
++i;
}
- if (c!= '\"') {
+ if (c != '\"') {
printError("Missing quote");
if (c == '\n')
++lineno;
break;
}
- if (c > ' ' && !feof(file)) {
+ if (c > ' ' && is) {
+ //if (isalnum(static_cast<unsigned char>(c)) && is) {
int i = 0;
do {
if (c == '\\') {
// escape the next char
- c = getc(file);
+ is.get(c);
//escaped = true;
}
buff[i++] = c;
- c = getc(file);
- } while (c > ' ' && c != ',' && !feof(file) &&
- (i != LEX_MAX_BUFF-1) );
+ is.get(c);
+ } while (c > ' ' && c != ',' && is
+ //} while (isalnum(static_cast<unsigned char>(c))
+ //!= ',' && is
+ && (i != LEX_MAX_BUFF-1) );
if (i == LEX_MAX_BUFF-1) {
printError("Line too long");
}
buff[i] = '\0';
status = LEX_TOKEN;
}
-
// new line
if (c == '\n')
++lineno;
if (status) return true;
- status = (feof(file)) ? LEX_FEOF: LEX_UNDEF;
+ status = is.eof() ? LEX_FEOF: LEX_UNDEF;
buff[0] = '\0';
return false;
}
bool LyXLex::nextToken()
{
status = 0;
- while (!feof(file) && !status) {
- int c = getc(file); // getc() returns an int
+ while (is && !status) {
+ unsigned char c;
+ is.get(c);
- if (c >= ' ' && !feof(file)) {
+ if (c >= ' ' && is) {
+ //if (isprint(static_cast<unsigned char>(c)) && is) {
int i = 0;
if (c == '\\') { // first char == '\\'
do {
buff[i++] = c;
- c = getc(file);
- } while (c > ' ' && c != '\\' && !feof(file) &&
- i != (LEX_MAX_BUFF-1));
+ is.get(c);
+ } while (c > ' ' && c != '\\' && is
+ //} while (isalnum(static_cast<unsigned char>(c))
+ // && c != '\\' && is
+ && i != (LEX_MAX_BUFF-1));
} else {
do {
buff[i++] = c;
- c = getc(file);
- } while (c >= ' ' && c != '\\' && !feof(file)
+ is.get(c);
+ } while (c >= ' ' && c != '\\' && is
+ //} while (isprint(static_cast<unsigned char>(c))
+ // && c != '\\' && is
&& i != (LEX_MAX_BUFF-1));
}
- if (i == (LEX_MAX_BUFF-1)) {
+ if (i == (LEX_MAX_BUFF - 1)) {
printError("Line too long");
}
- if (c == '\\') ungetc(c, file); // put it back
+ if (c == '\\') is.putback(c); // put it back
buff[i] = '\0';
status = LEX_TOKEN;
}
}
if (status) return true;
- status = (feof(file)) ? LEX_FEOF: LEX_UNDEF;
+ status = is.eof() ? LEX_FEOF: LEX_UNDEF;
buff[0] = '\0';
return false;
}
#pragma interface
#endif
-#include <cstdio>
+#include <fstream>
#include "LString.h"
///
public:
///
LyXLex (keyword_item *, int);
- ///
- ~LyXLex() { if (file && owns_file) fclose(file); };
/// Lex basic codes
enum {
bool IsOK() const;
/// return true if able to open file, else false
bool setFile(string const & filename);
- /// if file is already read from, line numbers will be wrong.
- // should be removed
- void setFile(FILE * f);
///
- // should be removed
- FILE * getFile() { return file; }
+ void setStream(istream & i);
+ ///
+ istream & getStream() { return is; }
/// Danger! Don't use it unless you know what you are doing.
void setLineNo(int l) { lineno = l; }
/// returns a lex code
int table_siz;
};
- ///
- FILE * file;
- ///
- bool owns_file;
+ /// fb__ is only used to open files, the stream is accessed through is
+ filebuf fb__;
+ /// the stream that we use.
+ istream is;
///
string name;
///
inline
bool LyXLex::IsOK() const
{
- return (file && !feof(file));
+ return is.good();
}
+
// This is needed to ensure that the pop is done upon exit from methods
// with more than one exit point or that can return as a response to
// exceptions. (Lgb)
///
void read();
-
+
///
- void readSimpleWholeFile(FILE *);
+ void readSimpleWholeFile(istream &);
///
LyXParagraph * TeXOnePar(string & file, TexRow & texrow,
#include <config.h>
#include <cstring>
-#include <cstdio>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
cursor in a text (and thus not in a buffer). By keeping this it is
(I think) impossible to have several views with the same buffer, but
the cursor placed at different places.
+ [later]
+ Since the LyXText now has been moved from Buffer to BufferView
+ it should not be absolutely needed to move the cursor...
*/
LyXCursor cursor;
bool IsEmptyTableCell() const;
///
void toggleAppendix();
+ ///
+ unsigned short paperWidth() const { return paperwidth; }
private:
+ /// width of the paper
+ unsigned short paperwidth;
+
///
Row * firstrow;
///
Row * currentrow; /* pointer to the current row */
/// position in the text
long currentrow_y;
- /// width of the paper
- unsigned short paperwidth;
/** inserts a new row behind the specified row, increments
* the touched counters */
AUTOMAKE_OPTIONS = foreign 1.4
MAINTAINERCLEANFILES = Makefile.in
-noinst_LTLIBRARIES = libmathed.la
+noinst_LTLIBRARIES = libmathed.o
LIBS=
ETAGS_ARGS = --c++
INCLUDES = -I${top_srcdir}/images -I${srcdir}/../
-libmathed_la_SOURCES = array.h \
+libmathed_o_SOURCES = array.h \
formula.C \
formula.h \
formulamacro.C \
void InsetFormula::Read(LyXLex & lex)
{
- FILE * file = lex.getFile();
+ istream & is = lex.getStream();
- mathed_parser_file(file, lex.GetLineNo());
+ mathed_parser_file(is, lex.GetLineNo());
- // Silly hack to read labels.
- mathed_label = 0;
- mathed_parse(0, 0, &par);
- par->Metrics();
- disp_flag = (par->GetType() > 0);
-
- // Update line number
- lex.setLineNo(mathed_parser_lineno());
-
- if (mathed_label) {
- label = mathed_label;
- mathed_label = 0;
- }
+ // Silly hack to read labels.
+ mathed_label = 0;
+ mathed_parse(0, 0, &par);
+ par->Metrics();
+ disp_flag = (par->GetType() > 0);
+
+ // Update line number
+ lex.setLineNo(mathed_parser_lineno());
+
+ if (mathed_label) {
+ label = mathed_label;
+ mathed_label = 0;
+ }
#ifdef DEBUG
- Write(stdout);
- fflush(stdout);
+ Write(lyxerr);
#endif
}
void InsetFormulaMacro::Read(LyXLex & lex)
{
- FILE * file = lex.getFile();
- mathed_parser_file(file, lex.GetLineNo());
- mathed_parse(0, 0, reinterpret_cast<MathParInset **>(&tmacro));
+ istream & is = lex.getStream();
+ mathed_parser_file(is, lex.GetLineNo());
+ mathed_parse(0, 0, reinterpret_cast<MathParInset **>(&tmacro));
- // Update line number
- lex.setLineNo(mathed_parser_lineno());
-
- MathMacroTable::mathMTable.addTemplate(tmacro);
- name = tmacro->GetName();
- par = tmacro;
+ // Update line number
+ lex.setLineNo(mathed_parser_lineno());
+
+ MathMacroTable::mathMTable.addTemplate(tmacro);
+ name = tmacro->GetName();
+ par = tmacro;
}
#pragma interface
#endif
-#include <cstdio>
#include "LString.h"
#include "debug.h"
#include "array.h"
-
///
enum math_align {
///
///
void mathed_write(MathParInset *, ostream &, int *, char fragile,
char const * label = 0);
-///
-//void mathed_write(MathParInset *, FILE *, int *, char fragile,
-// char const * label = 0);
+
///
void mathed_write(MathParInset *, string &, int *, char fragile,
char const * label = 0);
///
-void mathed_parser_file(FILE *, int);
+void mathed_parser_file(istream &, int);
///
int mathed_parser_lineno();
///
/* C code produced by gperf version 2.5 (GNU C++ version) */
/* Command-line: gperf -a -p -o -t -G -D keywords */
#include <config.h>
-#include <cstdio>
+
#include <cstdlib>
#include <cstring>
#pragma interface
#endif
-#include <cstdio>
#include "math_defs.h"
#include "symbol_def.h"
#include "LString.h"
#include <config.h>
#include FORMS_H_LOCATION
-#include <cstdio>
#include <cstdlib>
#include "lyx_gui_misc.h"
static lexcode_enum lexcode[256];
static char yytext[256];
static int yylineno;
-static FILE * yyin;
+static istream * yyis;
static bool yy_mtextmode= false;
inline
char * strnew(char const * s)
{
- char *s1 = new char[strlen(s)+1]; // this leaks when not delete[]'ed
+ char * s1 = new char[strlen(s) + 1]; // this leaks when not delete[]'ed
strcpy(s1, s);
return s1;
}
static char LexGetArg(char lf, bool accept_spaces= false)
{
- char c, rg, * p = &yytext[0];
+ char rg, * p = &yytext[0];
int bcnt = 1;
-
- while (!feof(yyin)) {
- c = getc(yyin);
- if (c>' ') {
+ unsigned char c;
+ while (yyis->good()) {
+ yyis->get(c);
+ if (c > ' ') {
if (!lf) lf = c; else
- if (c!= lf)
+ if (c != lf)
lyxerr << "Math parse error: unexpected '"
<< c << "'" << endl;
break;
return '\0';
}
do {
- c = getc(yyin);
- if (c == lf) bcnt++;
- if (c == rg) bcnt--;
- if ((c>' ' || (c == ' ' && accept_spaces)) && bcnt>0) *(p++) = c;
- } while (bcnt>0 && !feof(yyin));
+ yyis->get(c);
+ if (c == lf) ++bcnt;
+ if (c == rg) --bcnt;
+ if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt>0) *(p++) = c;
+ } while (bcnt > 0 && yyis->good());
*p = '\0';
return rg;
}
if (!init_done) LexInitCodes();
- while (!feof(yyin)) {
- c = getc(yyin);
+ while (yyis->good()) {
+ yyis->get(c);
if (yy_mtextmode && c == ' ') {
yylval.i= ' ';
}
if (lexcode[c] == LexNewLine) {
- yylineno++;
+ ++yylineno;
continue;
}
if (lexcode[c] == LexComment)
- do c = getc(yyin); while (c!= '\n' % !feof(yyin)); // eat comments
+ do yyis->get(c); while (c != '\n' % yyis->good()); // eat comments
if (lexcode[c] == LexDigit || lexcode[c] == LexOther || lexcode[c] == LexMathSpace)
{ yylval.i= c; return LM_TK_STR; }
if (lexcode[c] == LexBOP) { yylval.i= c; return LM_TK_BOP; }
if (lexcode[c] == LexSelf) { return c; }
if (lexcode[c] == LexArgument) {
- c = getc(yyin);
+ yyis->get(c);
yylval.i = c - '0';
return LM_TK_ARGUMENT;
}
if (lexcode[c] == LexClose) { return LM_TK_CLOSE; }
if (lexcode[c] == LexESC) {
- c = getc(yyin);
+ yyis->get(c);
if (c == '\\') { return LM_TK_NEWLINE; }
if (c == '(') { yylval.i = LM_EN_INTEXT; return LM_TK_BEGIN; }
if (c == ')') { yylval.i = LM_EN_INTEXT; return LM_TK_END; }
}
if (lexcode[c] == LexMathSpace) {
int i;
- for (i= 0; i<4 && c!= latex_mathspace[i][0]; i++);
- yylval.i = (i<4) ? i: 0;
+ for (i = 0; i < 4 && c != latex_mathspace[i][0]; ++i);
+ yylval.i = (i < 4) ? i: 0;
return LM_TK_SPACE;
}
if (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
- char* p = &yytext[0];
+ char * p = &yytext[0];
while (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
*p = c;
- c = getc(yyin);
+ yyis->get(c);
p++;
}
*p = '\0';
- if (!feof(yyin)) ungetc(c, yyin);
- latexkeys *l = in_word_set (yytext, strlen(yytext));
+ if (yyis->good()) yyis->putback(c);
+ latexkeys * l = in_word_set (yytext, strlen(yytext));
if (l) {
if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) {
int i;
// for (i= 0; i<5 && strncmp(yytext, latex_mathenv[i],
// strlen(latex_mathenv[i])); i++);
- for (i= 0; i<6 && strcmp(yytext, latex_mathenv[i]); i++);
+ for (i = 0; i < 6 && strcmp(yytext, latex_mathenv[i]); i++);
yylval.i = i;
} else
if (l->token == LM_TK_SPACE)
int parse_align(char * hor, char *)
{
int nc = 0;
- for (char * c = hor; c && *c > ' '; ++c) nc++;
+ for (char * c = hor; c && *c > ' '; ++c) ++nc;
return nc;
}
{
MathedInset * ac = 0;
- for (int i= accent-1; i>= 0; i--) {
- if (i == accent-1)
+ for (int i = accent - 1; i >= 0; --i) {
+ if (i == accent - 1)
ac = new MathAccentInset(c, t, nestaccent[i]);
else
ac = new MathAccentInset(ac, nestaccent[i]);
{
MathedInset * ac = 0;
- for (int i= accent-1; i>= 0; i--) {
- if (i == accent-1)
+ for (int i = accent - 1; i >= 0; --i) {
+ if (i == accent - 1)
ac = new MathAccentInset(p, nestaccent[i]);
else
ac = new MathAccentInset(ac, nestaccent[i]);
}
-
-
LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
MathParInset ** mtx)
{
static int plevel = -1;
static int size = LM_ST_TEXT;
MathedTextCodes varcode = LM_TC_VAR;
- MathedInset* binset = 0;
- static MathMacroTemplate *macro= 0;
+ MathedInset * binset = 0;
+ static MathMacroTemplate * macro= 0;
int brace = 0;
int acc_brace = 0;
int acc_braces[8];
MathParInset * mt = (mtx) ? *mtx: 0;//(MathParInset*)0;
- MathedRowSt * crow = (mt) ? mt->getRowSt(): 0;
+ MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
++plevel;
if (!array) array = new LyxArrayBase;
LexGetArg('{');
// This name lives until quitting, for that reason
// I didn't care on deleting explicitly. Later I will.
- char const *name = strnew(&yytext[1]);
+ char const * name = strnew(&yytext[1]);
// ugly trick to be removed soon (lyx3)
- char c = getc(yyin);
- ungetc(c, yyin);
+ char c; yyis->get(c);
+ yyis->putback(c);
if (c == '[') {
LexGetArg('[');
na = atoi(yytext);
{
if (flags & FLAG_BRACK_ARG) {
flags &= ~FLAG_BRACK_ARG;
- char rg= LexGetArg('[');
+ char rg = LexGetArg('[');
if (rg!= ']') {
mathPrintError("Expected ']'");
panic = true;
case '^':
{
- MathParInset *p = new MathParInset(size, "", LM_OT_SCRIPT);
+ MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
LyxArrayBase * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
p->SetData(ar);
// lyxerr << "UP[" << p->GetStyle() << "]" << endl;
} else
data.Insert (yylval.l->id, tc);
} else {
- MathFuncInset *bg = new MathFuncInset(yylval.l->name);
+ MathFuncInset * bg = new MathFuncInset(yylval.l->name);
if (accent) {
data.Insert(doAccent(bg));
} else
}
case LM_TK_SPACE:
{
- if (yylval.i>= 0) {
+ if (yylval.i >= 0) {
MathSpaceInset * sp = new MathSpaceInset(yylval.i);
data.Insert(sp);
}
MathDotsInset * p = new MathDotsInset(yylval.l->name, yylval.l->id);
data.Insert(p);
break;
- }
+ }
case LM_TK_STACK:
fractype = LM_OT_STACKREL;
case LM_TK_FRAC:
{
MathParInset * rt;
- char c = getc(yyin);
+ char c; yyis->get(c);
if (c == '[') {
rt = new MathRootInset(size);
rt->SetData(mathed_parse(FLAG_BRACK_END, 0, &rt));
rt->setArgumentIdx(1);
} else {
- ungetc(c, yyin);
+ yyis->putback(c);
rt = new MathSqrtInset(size);
}
rt->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST, 0, &rt));
data.Insert(doAccent(p), p->getTCode());
else
data.Insert(p, p->getTCode());
- for (int i= 0; p->setArgumentIdx(i); i++)
+ for (int i = 0; p->setArgumentIdx(i); i++)
p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
}
else {
if (yylval.i == LM_EN_ARRAY) {
char ar[120], ar2[8];
ar[0] = ar2[0] = '\0';
- char rg= LexGetArg(0);
+ char rg = LexGetArg(0);
if (rg == ']') {
strcpy(ar2, yytext);
rg = LexGetArg('{');
data.Insert(mm, LM_TC_ACTIVE_INSET);
mathed_parse(FLAG_END, mm->GetData(), &mm);
} else
- if (yylval.i>= LM_EN_INTEXT && yylval.i<= LM_EN_EQNARRAY) {
+ if (yylval.i >= LM_EN_INTEXT && yylval.i<= LM_EN_EQNARRAY) {
if (plevel!= 0) {
mathPrintError("Misplaced environment");
break;
}
-void mathed_parser_file(FILE * file, int lineno)
+void mathed_parser_file(istream & is, int lineno)
{
- yyin = file;
+ yyis = &is;
yylineno = lineno;
if (!MathMacroTable::built)
MathMacroTable::mathMTable.builtinMacros();
#pragma interface
#endif
-#include <cstdio>
#include "math_defs.h"
#include "math_inset.h"
#include "symbol_def.h"
#include "math_panel.h"
#include "math_parser.h"
-extern void SmallUpdate(signed char);
extern void BeforeChange();
extern void Update(signed char);
extern int UnlockInset(UpdatableInset *);
#include <config.h>
-#include <stdlib.h>
+#include <cstdlib>
+
#include "math_defs.h"
#include "symbol_def.h"
*/
#include <config.h>
+
#include "LString.h"
#include "math_inset.h"
#include "math_iter.h"
}
-void LyXParagraph::readSimpleWholeFile(FILE * myfile)
+void LyXParagraph::readSimpleWholeFile(istream & is)
{
- rewind(myfile);
-
- if (!feof(myfile)) {
- char c = 0;
- do {
- c = fgetc(myfile);
- InsertChar(text.size(), c);
- } while (!feof(myfile));
-
- }
+ is.seekg(0);
+ char c = 0;
+ while(!is.eof()) {
+ is.get(c);
+ InsertChar(text.size(), c);
+ };
}
// fakes a purge of the buffer by returning n
return n;
}
+#ifdef MODERN_STL_STREAMS
+ ///
+ virtual int_type overflow(int_type c = traits_type::eof()) {
+ // fakes success by returning c
+ return c == traits_type::eof() ? ' ' : c;
+ }
+#else
///
virtual int_type overflow(int_type c = EOF) {
// fakes success by returning c
return c == EOF ? ' ' : c;
}
+#endif
};
/** A streambuf that sends the output to two different streambufs. These
teebuf(streambuf * b1, streambuf * b2)
: streambuf(), sb1(b1), sb2(b2) {}
protected:
-#ifndef MODERN_STL_STREAMS
- typedef char char_type;
- typedef int int_type;
-#endif
+#ifdef MODERN_STL_STREAMS
///
virtual int sync() {
-#ifdef MODERN_STL_STREAMS
sb2->pubsync();
return sb1->pubsync();
-#else
- sb2->sync();
- return sb1->sync();
-#endif
}
///
virtual streamsize xsputn(char_type const * p, streamsize n) {
-#ifdef MODERN_STL_STREAMS
sb2->sputn(p, n);
return sb1->sputn(p, n);
+ }
+ ///
+ virtual int_type overflow(int_type c = traits_type::eof()) {
+ sb2->sputc(c);
+ return sb1->sputc(c);
+ }
#else
+ typedef char char_type;
+ typedef int int_type;
+ ///
+ virtual int sync() {
+ sb2->sync();
+ return sb1->sync();
+ }
+ ///
+ virtual streamsize xsputn(char_type const * p, streamsize n) {
sb2->xsputn(p, n);
return sb1->xsputn(p, n);
-#endif
}
///
virtual int_type overflow(int_type c = EOF) {
-#ifdef MODERN_STL_STREAMS
- sb2->sputc(c);
- return sb1->sputc(c);
-#else
sb2->overflow(c);
return sb1->overflow(c);
-#endif
}
+#endif
private:
///
streambuf * sb1;
debugbuf(streambuf * b)
: streambuf(), sb(b) {}
protected:
-#ifndef MODERN_STL_STREAMS
- typedef char char_type;
- typedef int int_type;
-#endif
+#ifdef MODERN_STL_STREAMS
///
virtual int sync() {
-#ifdef MODERN_STL_STREAMS
return sb->pubsync();
-#else
- return sb->sync();
-#endif
}
///
virtual streamsize xsputn(char_type const * p, streamsize n) {
-#ifdef MODERN_STL_STREAMS
return sb->sputn(p, n);
+ }
+ ///
+ virtual int_type overflow(int_type c = traits_type::eof()) {
+ return sb->sputc(c);
+ }
#else
+ typedef char char_type;
+ typedef int int_type;
+ ///
+ virtual int sync() {
+ return sb->sync();
+ }
+ ///
+ virtual streamsize xsputn(char_type const * p, streamsize n) {
return sb->xsputn(p, n);
-#endif
}
///
virtual int_type overflow(int_type c = EOF) {
-#ifdef MODERN_STL_STREAMS
- return sb->sputc(c);
-#else
return sb->overflow(c);
-#endif
}
+#endif
private:
///
streambuf * sb;
#include <config.h>
#include <cctype>
+#include <fstream>
#include <utility>
using std::make_pair;
using std::pair;
// -1 error (doesn't exist, no access, anything else)
int IsFileWriteable (string const & path)
{
- FilePtr fp(path, FilePtr::update);
- if (!fp()) {
- if ((errno == EACCES) || (errno == EROFS)) {
- fp.reopen(path, FilePtr::read);
- if (fp()) {
- return 0;
- }
- }
- return -1;
+ fstream fs(path.c_str(), ios::out|ios::ate);
+ if (!fs) {
+ fs.open(path.c_str(), ios::in|ios::ate);
+ if (fs)
+ return 0;
+ else
+ return -1;
}
return 1;
}
_("Could not test if directory is writeable"));
return -1;
} else {
- FilePtr fp(tmpfl, FilePtr::truncate);
- if (!fp()) {
- if (errno == EACCES) {
- return 0;
- } else {
- WriteFSAlert(_("LyX Internal Error!"),
- _("Cannot open directory test file"));
- return -1;
- }
- }
- }
- if (remove(tmpfl.c_str())) {
- WriteFSAlert(_("LyX Internal Error!"),
- _("Created test file but cannot remove it?"));
- return -1;
+ FileInfo fi(path);
+ if (fi.writable()) return 1;
+ return 0;
}
- return 1;
}
// this leaks, but what can we do about it?
// Is doing a getenv() and a free() of the older value
// a good idea? (JMarc)
- int retval = putenv(const_cast<PUTENV_TYPE_ARG>((new string(envstr))->c_str()));
+ // Actually we don't have to leak...calling putenv like this
+ // should be enough:
+ int retval = putenv(const_cast<PUTENV_TYPE_ARG>(envstr.c_str()));
+ //int retval = putenv(const_cast<PUTENV_TYPE_ARG>((new string(envstr))->c_str()));
#else
#ifdef HAVE_SETENV
string varname;
// create our own popen based on fork, exec, pipe
// of course the best would be to have a
// pstream (process stream), with the
- // variants ipstream, opstream and
+ // variants ipstream, opstream
FILE * inf = popen(cmd.c_str(), "r");
string ret;
int c = fgetc(inf);
#pragma interface
#endif
-#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <cerrno>
+
#include "debug.h"
#include "LString.h"
#include "support/lstrings.h"
-/** A file class.
- Use this instead of FILE *, it gives a much better structure.
- It should prehaps do a bit more error checking than it does now.
- Currently it is a verbatim copy from p309 of Bjarne Stroupstrups
- The C++ Programming Language. + some additions.
- */
-class FilePtr {
-public:
- ///
- enum file_mode {
- read,
- write,
- update,
- truncate
- };
- ///
- FilePtr(string const & name, file_mode mode) {
- init();
- do_open(name, mode);
- }
- ///
- FilePtr(FILE * pp) { init(); p = pp; }
- ///
- ~FilePtr() { close(); }
-
- /** Use this if you want to rebind the FilePtr to another file.
- */
- FilePtr & reopen(string const & name, file_mode mode) {
- // close the file it it is already open
- close();
- // Now open the file.
- do_open(name, mode);
-
- return *this;
- }
- /** Close the file.
- Use this with some carefullness. After it has been used
- the FilePtr is unusable. Only use it if it is important
- that the file is closed before the FilePtr goes out
- of scope. */
- int close() {
- if (p) {
- int result = fclose(p);
- p = 0;
- return result;
- } else
- return 0;
- }
- /// automatic converson to FILE* if that is needed.
- operator FILE*() { return p; }
- ///
- FilePtr & operator=(FILE * f) { p= f; return *this;}
- ///
- FILE * operator()() { return p; }
-private:
- ///
- void do_open(string const & name, file_mode mode) {
- string modestr;
-
- switch(mode) {
- // do appropiate #ifdef here so support EMX
-#ifndef __EMX__
- case read: modestr = "r"; break;
- case write: modestr = "w"; break;
-#else
- case read: modestr = "rt"; break; // Can read both DOS & UNIX text files.
- case write: modestr = "w"; break; // Write UNIX text files.
-#endif
-
- case update: modestr = "r+"; break;
- case truncate: modestr = "w+"; break;
- }
- // Should probably be rewritten to use open(2)
- if((p = fopen(name.c_str(), modestr.c_str()))) {
- // file succesfully opened.
- if (fcntl(fileno(p), F_SETFD, FD_CLOEXEC) == -1) {
- p = 0;
- }
- } else {
- // we have an error let's check what it is.
- switch(errno) {
- case EINVAL:
- // Internal LyX error.
- lyxerr << "FilePtr: Wrong parameter given to fopen." << endl;
- break;
- default:
- // unknown error
- break;
- }
- }
- }
- ///
- void init() { p = 0; }
- ///
- FILE * p;
-};
-
///
string CreateBufferTmpDir (string const & pathfor = string());
#include <config.h>
#include <algorithm>
+#ifdef __GLIBCPP__
+#include <ctype.h>
+#else
#include <cctype>
-#include <cstdio>
+#endif
#include <cstdlib>
+#ifdef HAVE_SSTREAM
+#include <sstream>
+#else
+#include <strstream>
+#endif
+
#include "LString.h"
#include "lstrings.h"
#include "LRegex.h"
using std::count;
using std::transform;
+using std::tolower;
+using std::toupper;
int compare_no_case(string const & s, string const & s2)
{
return 1;
}
+
int compare_no_case(string const & s, string const & s2, unsigned int len)
{
//#warning verify this func please
return 1;
}
+
bool isStrInt(string const & str)
{
if (str.empty()) return false;
string lowercase(string const & a)
{
string tmp(a);
+#ifdef __GLIBCPP__
+ string::iterator result = tmp.begin();
+ for (string::iterator first = tmp.begin();
+ first != tmp.end(); ++first, ++result) {
+ *result = tolower(*first);
+ }
+#else
transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
+#endif
return tmp;
}
string uppercase(string const & a)
{
string tmp(a);
+#ifdef __GLIBCPP__
+ string::iterator result = tmp.begin();
+ for (string::iterator first = tmp.begin();
+ first != tmp.end(); ++first, ++result) {
+ *result = toupper(*first);
+ }
+#else
transform(tmp.begin(), tmp.end(), tmp.begin(), toupper);
+#endif
return tmp;
}
string tostr(long i)
{
- // should use string stream
+#ifndef HAVE_SSTREAM
+ // "Hey!", you say. "Why do we need the char str[30]?".
+ // Since strstream does not handle memory for us we have to do
+ // that ourselves, if we don't pass str in we have to capture
+ // oss.str() in a tmp variable and delete that manually.
+ // Thus we then require more temporary variables and the code
+ // gets more obfuscated.
char str[30];
- sprintf(str, "%ld", i);
- return string(str);
+ ostrstream oss(str, 30);
+ oss << i << '\0';
+#else
+ ostringstream oss;
+ oss << i;
+#endif
+ return oss.str();
}
string tostr(unsigned long i)
{
- // should use string stream
+#ifndef HAVE_SSTREAM
char str[30];
- sprintf(str, "%lu", i);
- return string(str);
+ ostrstream oss(str, 30);
+ oss << i << '\0';
+#else
+ ostringstream oss;
+ oss << i;
+#endif
+ return oss.str();
}
string tostr(double d)
{
- // should use string stream
+#ifndef HAVE_SSTREAM
char tmp[40];
- sprintf(tmp, "%f", d);
- return string(tmp);
+ ostrstream oss(tmp, 40);
+ oss << d << '\0';
+#else
+ ostringstream oss;
+ oss << d;
+#endif
+ return oss.str();
}
#include <sys/wait.h>
#include <csignal>
#include <cstdlib>
-#include <cstdio>
#include <unistd.h>
#include "debug.h"
#include "syscall.h"
}
-LyXTable::LyXTable(LyXLex &lex)
+LyXTable::LyXTable(LyXLex & lex)
{
- FILE * file = lex.getFile();
- Read(file);
+ istream & is = lex.getStream();
+ Read(is);
}
}
-void LyXTable::Read(FILE * file)
+void LyXTable::Read(istream & is)
{
- int version;
- int i, j;
- int rows_arg = 0;
- int columns_arg = 0;
- int is_long_table_arg = false;
- int rotate_arg = false;
- string s;
- int a = 0;
- int b = 0;
- int c = 0;
- int d = 0;
- int e = 0;
- int f = 0;
- int g = 0;
- int h = 0;
- char vtmp[100], stmp[100], atmp[100];
-
- fscanf(file, "%s\n", vtmp);
- s = vtmp;
- if (s.length() > 8)
- version = atoi(s.c_str() + 8);
- else
- version = 1;
+ int version;
+ int i, j;
+ int rows_arg = 0;
+ int columns_arg = 0;
+ int is_long_table_arg = false;
+ int rotate_arg = false;
+ int a = -1;
+ int b = -1;
+ int c = -1;
+ int d = -1;
+ int e = 0;
+ int f = 0;
+ int g = 0;
+ int h = 0;
+
+ string s;
+ getline(is, s);
+ if (s.length() > 8)
+ version = atoi(s.c_str() + 8);
+ else
+ version = 1;
#ifdef WITH_WARNINGS
#warning Insert a error message window here that this format is not supported anymore
#endif
- a = b = c = d = -1;
- if (version < 5) {
- lyxerr << "Tabular format < 5 is not supported anymore\n"
- "Get an older version of LyX (< 1.1.x) for conversion!"
- << endl;
- if (version > 2) {
- fgets(vtmp,sizeof(vtmp),file);
- sscanf(vtmp, "%d %d %d %d %d %d %d %d\n",
- &rows_arg, &columns_arg,
- &is_long_table_arg, &rotate_arg, &a, &b, &c, &d);
- } else
- fscanf(file, "%d %d\n",
- &rows_arg, &columns_arg);
+ if (version < 5) {
+ lyxerr << "Tabular format < 5 is not supported anymore\n"
+ "Get an older version of LyX (< 1.1.x) for conversion!"
+ << endl;
+ if (version > 2) {
+ is >> rows_arg >> columns_arg >> is_long_table_arg
+ >> rotate_arg >> a >> b >> c >> d;
+ } else
+ is >> rows_arg >> columns_arg;
+ Init(rows_arg, columns_arg);
+ SetLongTable(is_long_table_arg);
+ SetRotateTable(rotate_arg);
+ string tmp;
+ for (i = 0; i < rows; ++i) {
+ getline(is, tmp);
+ }
+ for (i = 0; i < columns; ++i) {
+ getline(is, tmp);
+ }
+ for (i = 0; i < rows; ++i) {
+ for (j = 0; j < columns; ++j) {
+ getline(is, tmp);
+ }
+ }
+ set_row_column_number_info();
+ return;
+ }
+ is >> rows_arg >> columns_arg >> is_long_table_arg
+ >> rotate_arg >> a >> b >> c >> d;
Init(rows_arg, columns_arg);
SetLongTable(is_long_table_arg);
SetRotateTable(rotate_arg);
- for (i = 0; i<rows; i++){
- fgets(vtmp, sizeof(vtmp), file);
+ endhead = a;
+ endfirsthead = b;
+ endfoot = c;
+ endlastfoot = d;
+ for (i = 0; i < rows; ++i) {
+ a = b = c = d = e = f = g = h = 0;
+ is >> a >> b >> c >> d;
+ row_info[i].top_line = a;
+ row_info[i].bottom_line = b;
+ row_info[i].is_cont_row = c;
+ row_info[i].newpage = d;
}
- for (i = 0; i<columns; i++){
- fgets(vtmp, sizeof(vtmp), file);
+ for (i = 0; i < columns; ++i) {
+ string s1;
+ string s2;
+ is >> a >> b >> c;
+ char ch; // skip '"'
+ is >> ch;
+ getline(is, s1, '"');
+ is >> ch; // skip '"'
+ getline(is, s2, '"');
+ column_info[i].alignment = static_cast<char>(a);
+ column_info[i].left_line = b;
+ column_info[i].right_line = c;
+ column_info[i].p_width = s1;
+ column_info[i].align_special = s2;
}
for (i = 0; i < rows; ++i) {
- for (j = 0; j < columns; ++j) {
- fgets(vtmp, sizeof(vtmp), file);
- }
+ for (j = 0; j < columns; ++j) {
+ string s1;
+ string s2;
+ is >> a >> b >> c >> d >> e >> f >> g;
+ char ch;
+ is >> ch; // skip '"'
+ getline(is, s1, '"');
+ is >> ch; // skip '"'
+ getline(is, s2, '"');
+ cell_info[i][j].multicolumn = static_cast<char>(a);
+ cell_info[i][j].alignment = static_cast<char>(b);
+ cell_info[i][j].top_line = static_cast<char>(c);
+ cell_info[i][j].bottom_line = static_cast<char>(d);
+ cell_info[i][j].has_cont_row = static_cast<bool>(e);
+ cell_info[i][j].rotate = static_cast<bool>(f);
+ cell_info[i][j].linebreaks = static_cast<bool>(g);
+ cell_info[i][j].align_special = s1;
+ cell_info[i][j].p_width = s2;
+ }
}
set_row_column_number_info();
- return;
- }
- fgets(vtmp, sizeof(vtmp), file);
- sscanf(vtmp, "%d %d %d %d %d %d %d %d\n", &rows_arg, &columns_arg,
- &is_long_table_arg, &rotate_arg, &a, &b, &c, &d);
- Init(rows_arg, columns_arg);
- SetLongTable(is_long_table_arg);
- SetRotateTable(rotate_arg);
- endhead = a;
- endfirsthead = b;
- endfoot = c;
- endlastfoot = d;
- for (i = 0; i<rows; i++){
- a = b = c = d = e = f = g = h = 0;
- fgets(vtmp, sizeof(vtmp), file);
- sscanf(vtmp, "%d %d %d %d\n",
- &a, &b, &c, &d);
- row_info[i].top_line = a;
- row_info[i].bottom_line = b;
- row_info[i].is_cont_row = c;
- row_info[i].newpage = d;
- }
- for (i = 0; i<columns; i++){
- *stmp = 0;
- *atmp = 0;
- fgets(vtmp, sizeof(vtmp), file);
- sscanf(vtmp, "%d %d %d %s %s", &a, &b, &c, stmp, atmp);
- column_info[i].alignment = static_cast<char>(a);
- column_info[i].left_line = b;
- column_info[i].right_line = c;
- if (*stmp == '"') { /* strip quotes if they exists */
- *stmp = 0;
- *atmp = 0;
- // there are quotes so I have to reread the string correctly
- // this is only because the old format did not have "
- // this means also that atmp is ONLY set here!!!
- if (stmp[1] == '"')
- sscanf(vtmp, "%*d %*d %*d %*s \"%[^\"]\"", atmp);
- else // otherwise after the first empty "" read is aborded
- sscanf(vtmp, "%*d %*d %*d \"%[^\"]\" \"%[^\"]\"", stmp, atmp);
- column_info[i].p_width = stmp;
- column_info[i].align_special = atmp;
- } else if (*stmp)
- column_info[i].p_width = stmp;
- }
- for (i = 0; i < rows; ++i) {
- for (j = 0; j < columns; ++j) {
- *stmp = 0;
- *atmp = 0;
- a = b = c = d = e = f = g = 0;
- fgets(vtmp, sizeof(vtmp), file);
- sscanf(vtmp, "%d %d %d %d %d %d %d %s %s\n",
- &a, &b, &c, &d, &e, &f, &g, stmp, atmp);
- cell_info[i][j].multicolumn = static_cast<char>(a);
- cell_info[i][j].alignment = static_cast<char>(b);
- cell_info[i][j].top_line = static_cast<char>(c);
- cell_info[i][j].bottom_line = static_cast<char>(d);
- cell_info[i][j].has_cont_row = static_cast<bool>(e);
- cell_info[i][j].rotate = static_cast<bool>(f);
- cell_info[i][j].linebreaks = static_cast<bool>(g);
- // this is only to see if I have an empty string first
- // this clause should be always TRUE!!!
- if (*stmp == '"') {
- *stmp = 0;
- *atmp = 0;
- if (stmp[1] == '"')
- sscanf(vtmp, "%*d %*d %*d %*d %*d %*d %*d %*s \"%[^\"]\"",
- atmp);
- else // otherwise after the first empty "" read is aborded
- sscanf(vtmp, "%*d %*d %*d %*d %*d %*d %*d \"%[^\"]\" \"%[^\"]\"",
- stmp, atmp);
- cell_info[i][j].align_special = stmp;
- cell_info[i][j].p_width = atmp;
- } else if (*stmp)
- cell_info[i][j].align_special = stmp;
- }
- }
- set_row_column_number_info();
}
#pragma interface
#endif
-#include <cstdio>
-
#include "lyxlex.h"
#include "LString.h"
#include "support/LOstream.h"
///
void Write(ostream &);
///
- void Read(FILE * file);
+ void Read(istream &);
// cell <0 will tex the preamble
// returns the number of printed newlines
#pragma implementation
#endif
+
+Undo::Undo(undo_kind kind_arg,
+ int number_before_arg, int number_behind_arg,
+ int cursor_par_arg, int cursor_pos_arg,
+ LyXParagraph * par_arg)
+{
+ kind = kind_arg;
+ number_of_before_par = number_before_arg;
+ number_of_behind_par = number_behind_arg;
+ number_of_cursor_par = cursor_par_arg;
+ cursor_pos = cursor_pos_arg;
+ par = par_arg;
+}
+
+
+Undo::~Undo()
+{
+ LyXParagraph * tmppar;
+ while (par) {
+ tmppar = par;
+ par = par->next;
+ delete tmppar;
+ }
+}
+
+
UndoStack::UndoStack()
: limit(100) {}
delete tmp;
}
}
+
+
+bool UndoStack::empty() const {
+ return stakk.empty();
+}
Undo(undo_kind kind_arg,
int number_before_arg, int number_behind_arg,
int cursor_par_arg, int cursor_pos_arg,
- LyXParagraph * par_arg)
- {
- kind = kind_arg;
- number_of_before_par = number_before_arg;
- number_of_behind_par = number_behind_arg;
- number_of_cursor_par = cursor_par_arg;
- cursor_pos = cursor_pos_arg;
- par = par_arg;
- }
- ///
- ~Undo() {
- LyXParagraph * tmppar;
- while (par) {
- tmppar = par;
- par = par->next;
- delete tmppar;
- }
- }
+ LyXParagraph * par_arg);
+ ///
+ ~Undo();
};
///
Undo * top();
///
- bool empty() const { return stakk.empty(); }
+ bool empty() const;
///
~UndoStack();
///
#include "vspace.h"
#include "lyxrc.h"
#include "lyxtext.h"
-#include <cstdio>
#include <cstring>
#include "BufferView.h"
#include "support/lstrings.h"
#pragma interface
#endif
-#include <cstdio>
#include "LString.h"
/// LyXLength Class