mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
changes from sprintf to string stream. see comments at top of text.C. read the ChangeLog
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@589 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
abb623f787
commit
d2b9849fff
38
ChangeLog
38
ChangeLog
@ -1,3 +1,41 @@
|
||||
2000-03-08 Lars Gullik Bjønnes <larsbj@lyx.org>
|
||||
|
||||
* src/insets/insettext.C: added <algorithm>.
|
||||
|
||||
2000-03-07 Lars Gullik Bjønnes <larsbj@lyx.org>
|
||||
|
||||
* src/mathed/math_panel.C (delim_cb): case MM_OK use string stream
|
||||
(matrix_cb): case MM_OK use string stream
|
||||
|
||||
* src/mathed/formula.C (LocalDispatch): case LFUN_SETXY use string
|
||||
stream.
|
||||
|
||||
* src/mathed/math_macro.C (draw): use string stream
|
||||
(Metrics): use string stream
|
||||
|
||||
* src/paragraph.C (TeXFootnote): for case LyXParagraph::FIG, write
|
||||
directly to the ostream.
|
||||
|
||||
* src/vspace.C (asString): use string stream.
|
||||
(asString): use string stream
|
||||
(asLatexString): use string stream
|
||||
|
||||
* src/lyx_cb.C (UpdateLayoutDocument): use string stream for
|
||||
setting Spacing::Other.
|
||||
|
||||
* src/LaTeXFeatures.C (getPackages): use string stream instead of
|
||||
sprintf when creating the stretch vale.
|
||||
|
||||
* src/text2.C (alphaCounter): changed to return a string and to
|
||||
not use a static variable internally. Also fixed a one-off bug.
|
||||
(SetCounter): changed the drawing of the labels to use string
|
||||
streams instead of sprintf.
|
||||
|
||||
* src/support/lyxmanip.h: rewrite the newlineanDepth ostream
|
||||
manipulator to use a scheme that does not require library support.
|
||||
This is also the way it is done in the new GNU libstdc++. Should
|
||||
work with DEC cxx now.
|
||||
|
||||
2000-03-06 Lars Gullik Bjønnes <larsbj@lyx.org>
|
||||
|
||||
* src/mathed/math_inset.h (Write(ostream & os): add a space at the
|
||||
|
@ -127,10 +127,24 @@ string LaTeXFeatures::getPackages(BufferParams const & params)
|
||||
packages += "\\doublespacing\n";
|
||||
break;
|
||||
case Spacing::Other:
|
||||
char value[30];
|
||||
sprintf(value, "%.2f", params.spacing.getValue());
|
||||
//char value[30];
|
||||
//sprintf(value, "%.2f", params.spacing.getValue());
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream value;
|
||||
#else
|
||||
char val[30];
|
||||
ostrstream value(val, 30);
|
||||
|
||||
#endif
|
||||
value << params.spacing.getValue(); // setw?
|
||||
#ifdef HAVE_SSTREAM
|
||||
packages += string("\\setstretch{")
|
||||
+ value + "}\n";
|
||||
+ value.str().c_str() + "}\n";
|
||||
#else
|
||||
value << '\0';
|
||||
packages += string("\\setstretch{")
|
||||
+ value.str() + "}\n";
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
using std::ifstream;
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
22
src/lyx_cb.C
22
src/lyx_cb.C
@ -10,12 +10,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <unistd.h>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <fstream>
|
||||
using std::ifstream;
|
||||
|
||||
@ -1847,9 +1841,19 @@ bool UpdateLayoutDocument(BufferParams * params)
|
||||
case Spacing::Other:
|
||||
{
|
||||
fl_set_choice(fd_form_document->choice_spacing, 4);
|
||||
char sval[20];
|
||||
sprintf(sval, "%g", params->spacing.getValue());
|
||||
fl_set_input(fd_form_document->input_spacing, sval);
|
||||
//char sval[20];
|
||||
//sprintf(sval, "%g", params->spacing.getValue());
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream sval;
|
||||
sval << params->spacing.getValue(); // setw?
|
||||
fl_set_input(fd_form_document->input_spacing,
|
||||
sval.str().c_str());
|
||||
#else
|
||||
char tval[20];
|
||||
ostrstream sval(tval, 20);
|
||||
sval << params->spacing.getValue() << '\0'; // setw?
|
||||
fl_set_input(fd_form_document->input_spacing, sval.str());
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "formula.h"
|
||||
#endif
|
||||
@ -829,9 +826,14 @@ InsetFormula::LocalDispatch(BufferView * bv,
|
||||
case LFUN_SETXY:
|
||||
{
|
||||
int x, y, x1, y1;
|
||||
sscanf(arg.c_str(), "%d %d", &x, &y);
|
||||
#ifdef HAVE_SSTREAM
|
||||
istringstream ist(arg.c_str());
|
||||
#else
|
||||
istrstream ist(arg.c_str());
|
||||
#endif
|
||||
ist >> x >> y;
|
||||
par->GetXY(x1, y1);
|
||||
mathcursor->SetPos(x1+x, y1+y);
|
||||
mathcursor->SetPos(x1 + x, y1 + y);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -268,9 +268,17 @@ void MathMacroArgument::draw(Painter & pain, int x, int baseline)
|
||||
if (expnd_mode) {
|
||||
MathParInset::draw(pain, x, baseline);
|
||||
} else {
|
||||
unsigned char s[3];
|
||||
sprintf(reinterpret_cast<char*>(s), "#%d", number);
|
||||
drawStr(pain, LM_TC_TEX, size, x, baseline, &s[0], 2);
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream ost;
|
||||
ost << '#' << number;
|
||||
drawStr(pain, LM_TC_TEX, size, x, baseline, ost.str().c_str(), 2);
|
||||
#else
|
||||
char s[3];
|
||||
ostrstream ost(s, 3);
|
||||
ost << '#' << number << '\0';
|
||||
drawStr(pain, LM_TC_TEX, size, x, baseline,
|
||||
reinterpret_cast<unsigned char*>(ost.str()), 2);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,10 +288,23 @@ void MathMacroArgument::Metrics()
|
||||
if (expnd_mode) {
|
||||
MathParInset::Metrics();
|
||||
} else {
|
||||
unsigned char s[3];
|
||||
sprintf(reinterpret_cast<char*>(s), "#%d", number);
|
||||
width = mathed_string_width(LM_TC_TEX, size, &s[0], 2);
|
||||
mathed_string_height(LM_TC_TEX, size, &s[0], 2, ascent, descent);
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream ost;
|
||||
ost << '#' << number;
|
||||
width = mathed_string_width(LM_TC_TEX, size, ost.str().c_str(), 2);
|
||||
mathed_string_height(LM_TC_TEX, size,
|
||||
ost.str().c_str(), 2, ascent, descent);
|
||||
#else
|
||||
char s[3];
|
||||
ostrstream ost(s, 3);
|
||||
ost << '#' << number << '\0';
|
||||
width = mathed_string_width(LM_TC_TEX, size,
|
||||
reinterpret_cast<unsigned char*>
|
||||
(ost.str()), 2);
|
||||
mathed_string_height(LM_TC_TEX, size,
|
||||
reinterpret_cast<unsigned char*>(ost.str()),
|
||||
2, ascent, descent);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include <config.h>
|
||||
|
||||
#include FORMS_H_LOCATION
|
||||
#include <cstdlib>
|
||||
|
||||
#include "lyx_gui_misc.h"
|
||||
#include "math_panel.h"
|
||||
@ -147,10 +146,17 @@ void delim_cb(FL_OBJECT *, long data)
|
||||
case MM_APPLY:
|
||||
case MM_OK:
|
||||
{
|
||||
char s[80];
|
||||
sprintf(s, "%d %d", delim_code[left], delim_code[right]);
|
||||
lyxfunc->Dispatch(LFUN_MATH_DELIM, s);
|
||||
if (data == MM_APPLY) break;
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream ost;
|
||||
ost << delim_code[left] << ' ' << delim_code[right];
|
||||
lyxfunc->Dispatch(LFUN_MATH_DELIM, ost.str().c_str());
|
||||
#else
|
||||
char s[80];
|
||||
ostrstream ost(s, 80);
|
||||
ost << delim_code[left] << ' ' << delim_code[right] << '\0';
|
||||
lyxfunc->Dispatch(LFUN_MATH_DELIM, ost.str());
|
||||
#endif
|
||||
if (data == MM_APPLY) break;
|
||||
}
|
||||
case MM_CLOSE: fl_hide_form(fd_delim->delim); break;
|
||||
case 2:
|
||||
@ -194,14 +200,21 @@ void matrix_cb(FL_OBJECT *, long data)
|
||||
case MM_APPLY:
|
||||
case MM_OK:
|
||||
{
|
||||
char s[80];
|
||||
char c = v_align_c[fl_get_choice(fd_matrix->valign)-1];
|
||||
char const * sh = fl_get_input(fd_matrix->halign);
|
||||
int nx = int(fl_get_slider_value(fd_matrix->columns)+0.5);
|
||||
int ny = int(fl_get_slider_value(fd_matrix->rows)+0.5);
|
||||
sprintf(s, "%d %d %c%s", nx, ny, c, sh);
|
||||
if (data == MM_OK) fl_hide_form(fd_matrix->matrix);
|
||||
lyxfunc->Dispatch(LFUN_INSERT_MATRIX, s);
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream ost;
|
||||
ost << nx << ' ' << ny << ' ' << c << sh;
|
||||
lyxfunc->Dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
|
||||
#else
|
||||
char s[80];
|
||||
ostrstream ost(s, 80);
|
||||
ost << nx << ' ' << ny << ' ' << c << sh << '\0';
|
||||
lyxfunc->Dispatch(LFUN_INSERT_MATRIX, ost.str());
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case MM_CLOSE: fl_hide_form(fd_matrix->matrix); break;
|
||||
|
@ -5326,15 +5326,13 @@ LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
|
||||
if (pextra_type == PEXTRA_FLOATFLT
|
||||
&& (!pextra_width.empty()
|
||||
|| !pextra_widthp.empty())) {
|
||||
char bufr[80];
|
||||
if (!pextra_width.empty())
|
||||
sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
|
||||
pextra_width.c_str());
|
||||
os << "\\begin{floatingfigure}{"
|
||||
<< pextra_width << "}\n";
|
||||
else
|
||||
sprintf(bufr,
|
||||
"\\begin{floatingfigure}{%f\\textwidth}\n",
|
||||
atoi(pextra_widthp.c_str())/100.0);
|
||||
os << bufr;
|
||||
os << "\\begin{floatingfigure}{"
|
||||
<< atoi(pextra_widthp.c_str())/100.0
|
||||
<< "\\textwidth}\n";
|
||||
} else {
|
||||
os << "\\begin{figure}";
|
||||
if (!params->float_placement.empty()) {
|
||||
@ -5588,7 +5586,8 @@ LyXParagraph * LyXParagraph::TeXFootnote(string & file, TexRow & texrow,
|
||||
|| !pextra_widthp.empty())) {
|
||||
char bufr[80];
|
||||
if (!pextra_width.empty())
|
||||
sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
|
||||
sprintf(bufr,
|
||||
"\\begin{floatingfigure}{%s}\n",
|
||||
pextra_width.c_str());
|
||||
else
|
||||
sprintf(bufr,
|
||||
|
@ -2,19 +2,27 @@
|
||||
#ifndef LYX_MANIP_H
|
||||
#define LYX_MANIP_H
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
///
|
||||
struct NewLineAndDepth_ {
|
||||
int depth_;
|
||||
};
|
||||
|
||||
///
|
||||
inline
|
||||
ostream & newlineAndDepth_helper(ostream & s, int n)
|
||||
NewLineAndDepth_ newlineAndDepth(int n)
|
||||
{
|
||||
return s << '\n' << string(n, ' ');
|
||||
NewLineAndDepth_ nlad_;
|
||||
nlad_.depth_ = n;
|
||||
return nlad_;
|
||||
}
|
||||
///
|
||||
inline
|
||||
omanip<int> newlineAndDepth(int n)
|
||||
ostream & operator<<(ostream & os, NewLineAndDepth_ const & nlad_)
|
||||
{
|
||||
return omanip<int>(newlineAndDepth_helper, n);
|
||||
os << string(nlad_.depth_, ' ');
|
||||
return os;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
50
src/text.C
50
src/text.C
@ -44,6 +44,31 @@ extern int bibitemMaxWidth(Painter &, LyXFont const &);
|
||||
|
||||
#define FIX_DOUBLE_SPACE 1
|
||||
|
||||
// This is the comments that some of the warnings below refers to.
|
||||
// There are some issues in this file and I don't think they are
|
||||
// really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
|
||||
// this is a problem that has been here almost from day one and that a
|
||||
// larger userbase with differenct access patters triggers the bad
|
||||
// behaviour. (segfaults.) What I think happen is: In several places
|
||||
// we store the paragraph in the current cursor and then moves the
|
||||
// cursor. This movement of the cursor will delete paragraph at the
|
||||
// old position if it is now empty. This will make the temporary
|
||||
// pointer to the old cursor paragraph invalid and dangerous to use.
|
||||
// And is some cases this will trigger a segfault. I have marked some
|
||||
// of the cases where this happens with a warning, but I am sure there
|
||||
// are others in this file and in text2.C. There is also a note in
|
||||
// Delete() that you should read. In Delete I store the paragraph->id
|
||||
// instead of a pointer to the paragraph. I am pretty sure this faulty
|
||||
// use of temporary pointers to paragraphs that might have gotten
|
||||
// invalidated (through a cursor movement) before they are used, are
|
||||
// the cause of the strange crashes we get reported often.
|
||||
//
|
||||
// It is very tiresom to change this code, especially when it is as
|
||||
// hard to read as it is. Help to fix all the cases where this is done
|
||||
// would be greately appreciated.
|
||||
//
|
||||
// Lgb
|
||||
|
||||
int LyXText::SingleWidth(LyXParagraph * par,
|
||||
LyXParagraph::size_type pos) const
|
||||
{
|
||||
@ -601,7 +626,7 @@ int LyXText::LeftMargin(Row const * row) const
|
||||
}
|
||||
}
|
||||
|
||||
int align;
|
||||
int align; // wrong type
|
||||
if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
|
||||
align = layout.align;
|
||||
else
|
||||
@ -1006,11 +1031,6 @@ int LyXText::LabelFill(Row const * row) const
|
||||
int LyXText::NumberOfSeparators(Row const * row) const
|
||||
{
|
||||
int last = RowLast(row);
|
||||
//int p = row->pos;
|
||||
//int main_body = BeginningOfMainBody(row->par);
|
||||
//if (p < main_body)
|
||||
// p = main_body;
|
||||
// I think this is equivalent to the above. (Lgb)
|
||||
int p = max(row->pos, BeginningOfMainBody(row->par));
|
||||
int n = 0;
|
||||
for (; p < last; ++p) {
|
||||
@ -1035,10 +1055,6 @@ int LyXText::NumberOfHfills(Row const * row) const
|
||||
++first;
|
||||
}
|
||||
|
||||
//int main_body = BeginningOfMainBody(row->par);
|
||||
//if (first < main_body)
|
||||
// first = main_body;
|
||||
// I think this is equivalent to the above. (Lgb)
|
||||
first = max(first, BeginningOfMainBody(row->par));
|
||||
int n = 0;
|
||||
for (int p = first; p <= last; ++p) { // last, because the end is ignored!
|
||||
@ -1060,11 +1076,7 @@ int LyXText::NumberOfLabelHfills(Row const * row) const
|
||||
while(first < last && row->par->IsHfill(first))
|
||||
++first;
|
||||
}
|
||||
//LyXParagraph::size_type main_body =
|
||||
//BeginningOfMainBody(row->par);
|
||||
//if (last > main_body)
|
||||
//last = main_body;
|
||||
// I think this is eqvialent to the above. (Lgb)
|
||||
|
||||
last = min(last, BeginningOfMainBody(row->par));
|
||||
int n = 0;
|
||||
for (LyXParagraph::size_type p = first;
|
||||
@ -1662,6 +1674,7 @@ void LyXText::OpenFootnote()
|
||||
/* set the dimensions of the cursor row */
|
||||
row->fill = Fill(row, paperwidth);
|
||||
SetHeightOfRow(row);
|
||||
#warning See comment on top of text.C
|
||||
tmppar = tmppar->Next();
|
||||
|
||||
while (tmppar != endpar) {
|
||||
@ -2258,6 +2271,7 @@ void LyXText::CheckParagraphInTable(LyXParagraph * par,
|
||||
/* redraw only the row */
|
||||
LyXCursor tmpcursor = cursor;
|
||||
SetCursorIntern(par, pos);
|
||||
#warning See comment on top of text.C
|
||||
refresh_y = y;
|
||||
refresh_x = cursor.x;
|
||||
refresh_row = row;
|
||||
@ -2769,6 +2783,7 @@ void LyXText::CursorRightOneWord() const
|
||||
{
|
||||
// treat floats, HFills and Insets as words
|
||||
LyXCursor tmpcursor = cursor;
|
||||
#warning See comment on top of text.C
|
||||
|
||||
if (tmpcursor.pos == tmpcursor.par->Last()
|
||||
&& tmpcursor.par->Next())
|
||||
@ -3068,6 +3083,7 @@ void LyXText::DeleteWordForward()
|
||||
|
||||
if (!cursor.par->Last())
|
||||
CursorRight();
|
||||
#warning See comment on top of text.C
|
||||
else {
|
||||
/* -------> Skip initial non-word stuff. */
|
||||
while ( cursor.pos < cursor.par->Last()
|
||||
@ -3094,6 +3110,7 @@ void LyXText::DeleteWordBackward()
|
||||
LyXCursor tmpcursor = cursor;
|
||||
if (!cursor.par->Last())
|
||||
CursorLeft();
|
||||
#warning See comment on top of text.C
|
||||
else{
|
||||
selection = true; // to avoid deletion
|
||||
CursorLeftOneWord();
|
||||
@ -3111,6 +3128,7 @@ void LyXText::DeleteLineForward()
|
||||
LyXCursor tmpcursor = cursor;
|
||||
if (!cursor.par->Last())
|
||||
CursorRight();
|
||||
#warning See comment on top of text.C
|
||||
else {
|
||||
CursorEnd();
|
||||
sel_cursor = cursor;
|
||||
@ -3183,6 +3201,7 @@ void LyXText::Delete()
|
||||
// just move to the right
|
||||
CursorRightIntern();
|
||||
|
||||
#warning Look at the comment here.
|
||||
// This check is not very good...
|
||||
// The CursorRightIntern calls DeleteEmptyParagrapgMechanism
|
||||
// and that can very well delete the par or par->previous in
|
||||
@ -3277,6 +3296,7 @@ void LyXText::Backspace()
|
||||
tmppar = cursor.par;
|
||||
tmprow = cursor.row;
|
||||
CursorLeftIntern();
|
||||
#warning See comment on top of text.C
|
||||
/* Pasting is not allowed, if the paragraphs have different
|
||||
layout. I think it is a real bug of all other
|
||||
word processors to allow it. It confuses the user.
|
||||
|
200
src/text2.C
200
src/text2.C
@ -10,7 +10,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <cctype>
|
||||
#include FORMS_H_LOCATION
|
||||
|
||||
|
||||
@ -925,7 +924,7 @@ void LyXText::SetSelection()
|
||||
sel_end_cursor = sel_cursor;
|
||||
}
|
||||
|
||||
selection = True;
|
||||
selection = true;
|
||||
|
||||
// first the toggling area
|
||||
if (cursor.y < last_sel_cursor.y ||
|
||||
@ -1349,17 +1348,14 @@ void LyXText::SetParagraphExtraOpt(int type,
|
||||
|
||||
|
||||
static
|
||||
char const * alphaCounter(int n) {
|
||||
static char result[2];
|
||||
result[1] = 0;
|
||||
if (n == 0)
|
||||
return "";
|
||||
else {
|
||||
result[0] = 'A' + n;
|
||||
string alphaCounter(int n) {
|
||||
if (n != 0) {
|
||||
if (n > 'Z')
|
||||
return "??";
|
||||
char result[2] = { 'A' + n - 1, 0 };
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@ -1485,8 +1481,6 @@ void LyXText::SetCounter(LyXParagraph * par) const
|
||||
if (i >= 0 && i<= parameters->secnumdepth) {
|
||||
par->incCounter(i); // increment the counter
|
||||
|
||||
char * s = new char[50];
|
||||
|
||||
// Is there a label? Useful for Chapter layout
|
||||
if (!par->appendix){
|
||||
if (!layout.labelstring().empty())
|
||||
@ -1499,103 +1493,114 @@ void LyXText::SetCounter(LyXParagraph * par) const
|
||||
else
|
||||
par->labelstring.clear();
|
||||
}
|
||||
|
||||
if (!par->appendix){
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream s;
|
||||
#else
|
||||
ostrstream s;
|
||||
#endif
|
||||
if (!par->appendix) {
|
||||
switch (2 * LABEL_FIRST_COUNTER -
|
||||
textclass.maxcounter() + i) {
|
||||
case LABEL_COUNTER_CHAPTER:
|
||||
sprintf(s, "%d",
|
||||
par->getCounter(i));
|
||||
s << par->getCounter(i);
|
||||
break;
|
||||
case LABEL_COUNTER_SECTION:
|
||||
sprintf(s, "%d.%d",
|
||||
par->getCounter(i - 1),
|
||||
par->getCounter(i));
|
||||
s << par->getCounter(i - 1) << '.'
|
||||
<< par->getCounter(i);
|
||||
break;
|
||||
case LABEL_COUNTER_SUBSECTION:
|
||||
sprintf(s, "%d.%d.%d",
|
||||
par->getCounter(i-2),
|
||||
par->getCounter(i-1),
|
||||
par->getCounter(i));
|
||||
s << par->getCounter(i - 2) << '.'
|
||||
<< par->getCounter(i - 1) << '.'
|
||||
<< par->getCounter(i);
|
||||
break;
|
||||
case LABEL_COUNTER_SUBSUBSECTION:
|
||||
sprintf(s, "%d.%d.%d.%d",
|
||||
par->getCounter(i-3),
|
||||
par->getCounter(i-2),
|
||||
par->getCounter(i-1),
|
||||
par->getCounter(i));
|
||||
s << par->getCounter(i - 3) << '.'
|
||||
<< par->getCounter(i - 2) << '.'
|
||||
<< par->getCounter(i - 1) << '.'
|
||||
<< par->getCounter(i);
|
||||
|
||||
break;
|
||||
case LABEL_COUNTER_PARAGRAPH:
|
||||
sprintf(s, "%d.%d.%d.%d.%d",
|
||||
par->getCounter(i-4),
|
||||
par->getCounter(i-3),
|
||||
par->getCounter(i-2),
|
||||
par->getCounter(i-1),
|
||||
par->getCounter(i));
|
||||
s << par->getCounter(i - 4) << '.'
|
||||
<< par->getCounter(i - 3) << '.'
|
||||
<< par->getCounter(i - 2) << '.'
|
||||
<< par->getCounter(i - 1) << '.'
|
||||
<< par->getCounter(i);
|
||||
break;
|
||||
case LABEL_COUNTER_SUBPARAGRAPH:
|
||||
sprintf(s, "%d.%d.%d.%d.%d.%d",
|
||||
par->getCounter(i-5),
|
||||
par->getCounter(i-4),
|
||||
par->getCounter(i-3),
|
||||
par->getCounter(i-2),
|
||||
par->getCounter(i-1),
|
||||
par->getCounter(i));
|
||||
s << par->getCounter(i - 5) << '.'
|
||||
<< par->getCounter(i - 4) << '.'
|
||||
<< par->getCounter(i - 3) << '.'
|
||||
<< par->getCounter(i - 2) << '.'
|
||||
<< par->getCounter(i - 1) << '.'
|
||||
<< par->getCounter(i);
|
||||
|
||||
break;
|
||||
default:
|
||||
sprintf(s, "%d.", par->getCounter(i));
|
||||
s << par->getCounter(i) << '.';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
} else { // appendix
|
||||
switch (2 * LABEL_FIRST_COUNTER - textclass.maxcounter() + i) {
|
||||
case LABEL_COUNTER_CHAPTER:
|
||||
sprintf(s, "%s",
|
||||
alphaCounter(par->getCounter(i)));
|
||||
s << alphaCounter(par->getCounter(i));
|
||||
break;
|
||||
case LABEL_COUNTER_SECTION:
|
||||
sprintf(s, "%s.%d",
|
||||
alphaCounter(par->getCounter(i - 1)),
|
||||
par->getCounter(i));
|
||||
s << alphaCounter(par->getCounter(i - 1)) << '.'
|
||||
<< par->getCounter(i);
|
||||
|
||||
break;
|
||||
case LABEL_COUNTER_SUBSECTION:
|
||||
sprintf(s, "%s.%d.%d",
|
||||
alphaCounter(par->getCounter(i-2)),
|
||||
par->getCounter(i-1),
|
||||
par->getCounter(i));
|
||||
s << alphaCounter(par->getCounter(i - 2)) << '.'
|
||||
<< par->getCounter(i-1) << '.'
|
||||
<< par->getCounter(i);
|
||||
|
||||
break;
|
||||
case LABEL_COUNTER_SUBSUBSECTION:
|
||||
sprintf(s, "%s.%d.%d.%d",
|
||||
alphaCounter(par->getCounter(i-3)),
|
||||
par->getCounter(i-2),
|
||||
par->getCounter(i-1),
|
||||
par->getCounter(i));
|
||||
s << alphaCounter(par->getCounter(i-3)) << '.'
|
||||
<< par->getCounter(i-2) << '.'
|
||||
<< par->getCounter(i-1) << '.'
|
||||
<< par->getCounter(i);
|
||||
|
||||
break;
|
||||
case LABEL_COUNTER_PARAGRAPH:
|
||||
sprintf(s, "%s.%d.%d.%d.%d",
|
||||
alphaCounter(par->getCounter(i-4)),
|
||||
par->getCounter(i-3),
|
||||
par->getCounter(i-2),
|
||||
par->getCounter(i-1),
|
||||
par->getCounter(i));
|
||||
s << alphaCounter(par->getCounter(i-4)) << '.'
|
||||
<< par->getCounter(i-3) << '.'
|
||||
<< par->getCounter(i-2) << '.'
|
||||
<< par->getCounter(i-1) << '.'
|
||||
<< par->getCounter(i);
|
||||
|
||||
break;
|
||||
case LABEL_COUNTER_SUBPARAGRAPH:
|
||||
sprintf(s, "%s.%d.%d.%d.%d.%d",
|
||||
alphaCounter(par->getCounter(i-5)),
|
||||
par->getCounter(i-4),
|
||||
par->getCounter(i-3),
|
||||
par->getCounter(i-2),
|
||||
par->getCounter(i-1),
|
||||
par->getCounter(i));
|
||||
s << alphaCounter(par->getCounter(i-5)) << '.'
|
||||
<< par->getCounter(i-4) << '.'
|
||||
<< par->getCounter(i-3) << '.'
|
||||
<< par->getCounter(i-2) << '.'
|
||||
<< par->getCounter(i-1) << '.'
|
||||
<< par->getCounter(i);
|
||||
|
||||
break;
|
||||
default:
|
||||
sprintf(s, "%c.", par->getCounter(i));
|
||||
// Can this ever be reached? And in the
|
||||
// case it is, how can this be correct?
|
||||
// (Lgb)
|
||||
s << static_cast<unsigned char>(par->getCounter(i)) << '.';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
par->labelstring += s;
|
||||
delete[] s;
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
par->labelstring += s.str().c_str();
|
||||
// We really want to remove the c_str as soon as
|
||||
// possible...
|
||||
#else
|
||||
s << '\0';
|
||||
char * tmps = s.str();
|
||||
par->labelstring += tmps;
|
||||
delete [] tmps;
|
||||
#endif
|
||||
|
||||
for (i++; i < 10; ++i) {
|
||||
// reset the following counters
|
||||
par->setCounter(i, 0);
|
||||
@ -1607,7 +1612,6 @@ void LyXText::SetCounter(LyXParagraph * par) const
|
||||
}
|
||||
} else if (layout.labeltype == LABEL_COUNTER_ENUMI) {
|
||||
par->incCounter(i + par->enumdepth);
|
||||
char * s = new char[25];
|
||||
int number = par->getCounter(i + par->enumdepth);
|
||||
|
||||
static const char *roman[20] = {
|
||||
@ -1621,35 +1625,57 @@ void LyXText::SetCounter(LyXParagraph * par) const
|
||||
'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
|
||||
'÷', 'ø', 'ù', 'ú'
|
||||
};
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream s;
|
||||
#else
|
||||
ostrstream s;
|
||||
#endif
|
||||
switch (par->enumdepth) {
|
||||
case 1:
|
||||
if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT)
|
||||
sprintf(s, "(%c)", ((number-1) % 26) + 'a');
|
||||
s << '('
|
||||
<< static_cast<unsigned char>
|
||||
(((number - 1) % 26) + 'a')
|
||||
<< ')';
|
||||
|
||||
else
|
||||
sprintf(s, "(%c)", hebrew[(number-1) % 22]);
|
||||
s << '('
|
||||
<< static_cast<unsigned char>
|
||||
(hebrew[(number - 1) % 22])
|
||||
<< ')';
|
||||
break;
|
||||
case 2:
|
||||
if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT)
|
||||
sprintf(s, "%s.", roman[(number-1) % 20]);
|
||||
s << roman[(number - 1) % 20] << '.';
|
||||
else
|
||||
sprintf(s, ".%s", roman[(number-1) % 20]);
|
||||
s << '.' << roman[(number - 1) % 20];
|
||||
break;
|
||||
case 3:
|
||||
if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT)
|
||||
sprintf(s, "%c.", ((number-1) % 26) + 'A');
|
||||
s << static_cast<unsigned char>
|
||||
(((number - 1) % 26) + 'A')
|
||||
<< '.';
|
||||
else
|
||||
sprintf(s, ".%c", ((number-1) % 26) + 'A');
|
||||
s << '.'
|
||||
<< static_cast<unsigned char>
|
||||
(((number - 1) % 26) + 'A');
|
||||
break;
|
||||
default:
|
||||
if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT)
|
||||
sprintf(s, "%d.", number);
|
||||
s << number << '.';
|
||||
else
|
||||
sprintf(s, ".%d", number);
|
||||
s << '.' << number;
|
||||
break;
|
||||
}
|
||||
par->labelstring = s;
|
||||
delete[] s;
|
||||
#ifdef HAVE_SSTREAM
|
||||
par->labelstring = s.str().c_str();
|
||||
// we really want to get rid of that c_str()
|
||||
#else
|
||||
s << '\0';
|
||||
char * tmps = s.str();
|
||||
par->labelstring = tmps;
|
||||
delete [] tmps;
|
||||
#endif
|
||||
|
||||
for (i += par->enumdepth + 1; i < 10; ++i)
|
||||
par->setCounter(i, 0); /* reset the following counters */
|
||||
|
169
src/vspace.C
169
src/vspace.C
@ -4,8 +4,8 @@
|
||||
*
|
||||
* LyX, The Document Processor
|
||||
*
|
||||
* Copyright 1995 Matthias Ettrich
|
||||
* Copyright 1995-1999 The LyX Team.
|
||||
* Copyright 1995 Matthias Ettrich
|
||||
* Copyright 1995-2000 The LyX Team.
|
||||
*
|
||||
* ====================================================== */
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
#include "vspace.h"
|
||||
#include "lyxrc.h"
|
||||
#include "lyxtext.h"
|
||||
#include <cstring>
|
||||
#include "BufferView.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
@ -55,18 +54,21 @@ static LyXLength::UNIT unit[4] = { LyXLength::UNIT_NONE,
|
||||
//static int number_index, unit_index;
|
||||
int number_index, unit_index;
|
||||
|
||||
|
||||
static inline
|
||||
void lyx_advance (string & data, unsigned int n)
|
||||
{
|
||||
data.erase(0, n);
|
||||
}
|
||||
|
||||
|
||||
static inline
|
||||
bool isEndOfData (string const & data)
|
||||
{
|
||||
return frontStrip (data).empty();
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
char nextToken (string & data)
|
||||
{
|
||||
@ -119,26 +121,33 @@ char nextToken (string & data)
|
||||
}
|
||||
}
|
||||
|
||||
static struct {
|
||||
|
||||
struct LaTeXLength {
|
||||
char const * pattern;
|
||||
int plus_val_index, minus_val_index,
|
||||
plus_uni_index, minus_uni_index;
|
||||
} table[] = { { "nu", 0, 0, 0, 0 },
|
||||
{ "nu+nu", 2, 0, 2, 0 },
|
||||
{ "nu+nu-nu", 2, 3, 2, 3 },
|
||||
{ "nu+-nu", 2, 2, 2, 2 },
|
||||
{ "nu-nu", 0, 2, 0, 2 },
|
||||
{ "nu-nu+nu", 3, 2, 3, 2 },
|
||||
{ "nu-+nu", 2, 2, 2, 2 },
|
||||
{ "n+nu", 2, 0, 1, 0 },
|
||||
{ "n+n-nu", 2, 3, 1, 1 },
|
||||
{ "n+-nu", 2, 2, 1, 1 },
|
||||
{ "n-nu", 0, 2, 0, 1 },
|
||||
{ "n-n+nu", 3, 2, 1, 1 },
|
||||
{ "n-+nu", 2, 2, 1, 1 },
|
||||
{ "", 0, 0, 0, 0 } // sentinel, must be empty
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
LaTeXLength table[] = {
|
||||
{ "nu", 0, 0, 0, 0 },
|
||||
{ "nu+nu", 2, 0, 2, 0 },
|
||||
{ "nu+nu-nu", 2, 3, 2, 3 },
|
||||
{ "nu+-nu", 2, 2, 2, 2 },
|
||||
{ "nu-nu", 0, 2, 0, 2 },
|
||||
{ "nu-nu+nu", 3, 2, 3, 2 },
|
||||
{ "nu-+nu", 2, 2, 2, 2 },
|
||||
{ "n+nu", 2, 0, 1, 0 },
|
||||
{ "n+n-nu", 2, 3, 1, 1 },
|
||||
{ "n+-nu", 2, 2, 1, 1 },
|
||||
{ "n-nu", 0, 2, 0, 1 },
|
||||
{ "n-n+nu", 3, 2, 1, 1 },
|
||||
{ "n-+nu", 2, 2, 1, 1 },
|
||||
{ "", 0, 0, 0, 0 } // sentinel, must be empty
|
||||
};
|
||||
|
||||
|
||||
bool isValidGlueLength (string const & data, LyXGlueLength * result)
|
||||
{
|
||||
// This parser is table-driven. First, it constructs a "pattern"
|
||||
@ -265,6 +274,7 @@ bool isValidLength(string const & data, LyXLength * result)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// LyXLength class
|
||||
|
||||
LyXLength::LyXLength(string const & data)
|
||||
@ -279,18 +289,26 @@ LyXLength::LyXLength(string const & data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool LyXLength::operator== (LyXLength const & other) const
|
||||
{
|
||||
return (val == other.val &&
|
||||
uni == other.uni);
|
||||
}
|
||||
|
||||
|
||||
string LyXLength::asString() const
|
||||
{
|
||||
char buffer[20];
|
||||
|
||||
sprintf (buffer, "%g%s", val, unit_name[uni]);
|
||||
return string (buffer);
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream buffer;
|
||||
buffer << val << unit_name[uni]; // setw?
|
||||
return buffer.str().c_str();
|
||||
#else
|
||||
char tbuf[20];
|
||||
ostrstream buffer(tbuf, 20);
|
||||
buffer << val << unit_name[uni] << '\0'; // setw?
|
||||
return buffer.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -327,74 +345,99 @@ bool LyXGlueLength::operator== (LyXGlueLength const & other) const
|
||||
|
||||
string LyXGlueLength::asString() const
|
||||
{
|
||||
char buffer[20];
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream buffer;
|
||||
#else
|
||||
char tbuf[20];
|
||||
ostrstream buffer(tbuf, 20);
|
||||
#endif
|
||||
if (plus_val != 0.0)
|
||||
if (minus_val != 0.0)
|
||||
if ((uni == plus_uni) && (uni == minus_uni))
|
||||
if (plus_val == minus_val)
|
||||
sprintf (buffer, "%g+-%g%s",
|
||||
val, plus_val, unit_name[uni]);
|
||||
buffer << val << "+-"
|
||||
<< plus_val << unit_name[uni];
|
||||
else
|
||||
sprintf (buffer, "%g+%g-%g%s",
|
||||
val, plus_val, minus_val,
|
||||
unit_name[uni]);
|
||||
buffer << val
|
||||
<< '+' << plus_val
|
||||
<< '-' << minus_val
|
||||
<< unit_name[uni];
|
||||
else
|
||||
if ((plus_uni == minus_uni) && (plus_val == minus_val))
|
||||
sprintf (buffer, "%g%s+-%g%s",
|
||||
val, unit_name[uni],
|
||||
plus_val, unit_name[plus_uni]);
|
||||
if (plus_uni == minus_uni
|
||||
&& plus_val == minus_val)
|
||||
buffer << val << unit_name[uni]
|
||||
<< "+-" << plus_val
|
||||
<< unit_name[plus_uni];
|
||||
|
||||
else
|
||||
sprintf (buffer, "%g%s+%g%s-%g%s",
|
||||
val, unit_name[uni],
|
||||
plus_val, unit_name[plus_uni],
|
||||
minus_val, unit_name[minus_uni]);
|
||||
buffer << val << unit_name[uni]
|
||||
<< '+' << plus_val
|
||||
<< unit_name[plus_uni]
|
||||
<< '-' << minus_val
|
||||
<< unit_name[minus_uni];
|
||||
else
|
||||
if (uni == plus_uni)
|
||||
sprintf (buffer, "%g+%g%s",
|
||||
val, plus_val, unit_name[uni]);
|
||||
buffer << val << '+' << plus_val
|
||||
<< unit_name[uni];
|
||||
else
|
||||
sprintf (buffer, "%g%s+%g%s",
|
||||
val, unit_name[uni],
|
||||
plus_val, unit_name[plus_uni]);
|
||||
buffer << val << unit_name[uni]
|
||||
<< '+' << plus_val
|
||||
<< unit_name[plus_uni];
|
||||
|
||||
else
|
||||
if (minus_val != 0.0)
|
||||
if (uni == minus_uni)
|
||||
sprintf (buffer, "%g-%g%s",
|
||||
val, minus_val, unit_name[uni]);
|
||||
buffer << val << '-' << minus_val
|
||||
<< unit_name[uni];
|
||||
|
||||
else
|
||||
sprintf (buffer, "%g%s-%g%s",
|
||||
val, unit_name[uni],
|
||||
minus_val, unit_name[minus_uni]);
|
||||
buffer << val << unit_name[uni]
|
||||
<< '-' << minus_val
|
||||
<< unit_name[minus_uni];
|
||||
else
|
||||
sprintf (buffer, "%g%s", val, unit_name[uni]);
|
||||
return string (buffer);
|
||||
buffer << val << unit_name[uni];
|
||||
#ifdef HAVE_SSTREAM
|
||||
return buffer.str().c_str();
|
||||
#else
|
||||
buffer << '\0';
|
||||
return buffer.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
string LyXGlueLength::asLatexString() const
|
||||
{
|
||||
char buffer[40];
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream buffer;
|
||||
#else
|
||||
char tbuf[40];
|
||||
ostrstream buffer(tbuf, 40);
|
||||
#endif
|
||||
|
||||
if (plus_val != 0.0)
|
||||
if (minus_val != 0.0)
|
||||
sprintf (buffer, "%g%s plus %g%s minus %g%s",
|
||||
val, unit_name[uni],
|
||||
plus_val, unit_name[plus_uni],
|
||||
minus_val, unit_name[minus_uni]);
|
||||
buffer << val << unit_name[uni]
|
||||
<< " plus "
|
||||
<< plus_val << unit_name[plus_uni]
|
||||
<< " minus "
|
||||
<< minus_val << unit_name[minus_uni];
|
||||
else
|
||||
sprintf (buffer, "%g%s plus %g%s",
|
||||
val, unit_name[uni],
|
||||
plus_val, unit_name[plus_uni]);
|
||||
buffer << val << unit_name[uni]
|
||||
<< " plus "
|
||||
<< plus_val << unit_name[plus_uni];
|
||||
else
|
||||
if (minus_val != 0.0)
|
||||
sprintf (buffer, "%g%s minus %g%s",
|
||||
val, unit_name[uni],
|
||||
minus_val, unit_name[minus_uni]);
|
||||
buffer << val << unit_name[uni]
|
||||
<< " minus "
|
||||
<< minus_val << unit_name[minus_uni];
|
||||
else
|
||||
sprintf (buffer, "%g%s",
|
||||
val, unit_name[uni]);
|
||||
return string (buffer);
|
||||
buffer << val << unit_name[uni];
|
||||
#ifdef HAVE_SSTREAM
|
||||
return buffer.str().c_str();
|
||||
#else
|
||||
buffer << '\0';
|
||||
return buffer.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user