Fixed some bugs and introduced some memory leaks!

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@220 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 1999-10-20 14:35:05 +00:00
parent 4894fbc987
commit b8426b61f9
6 changed files with 81 additions and 84 deletions

View File

@ -1,3 +1,16 @@
1999-10-20 Juergen Vigna <jug@sad.it>
* src/insets/figinset.C: just commented some fl_free_form calls
and added warnings so that this calls should be activated later
again. This avoids for now a segfault, but we have a memory leak!
* src/lyxfunc.C (processKeyEvent) (Dispatch): changed
'const char * argument' to 'string argument', this should
fix some Asserts() in lyxstring.C.
* src/lyxfunc.h: Removed the function argAsString(const char *)
as it is not used anymore.
1999-10-20 Lars Gullik Bjønnes <larsbj@lyx.org> 1999-10-20 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/support/lyxstring.C (helper): changed to use * src/support/lyxstring.C (helper): changed to use

View File

@ -973,11 +973,15 @@ static void UnregisterFigure(InsetFig *fi)
if (tmpfig->data) freefigdata(tmpfig->data); if (tmpfig->data) freefigdata(tmpfig->data);
if (tmpfig->inset->form) { if (tmpfig->inset->form) {
if (tmpfig->inset->form->Figure->visible) if (tmpfig->inset->form->Figure->visible) {
fl_set_focus_object(tmpfig->inset->form->Figure,
tmpfig->inset->form->OkBtn);
fl_hide_form(tmpfig->inset->form->Figure); fl_hide_form(tmpfig->inset->form->Figure);
fl_free_form(tmpfig->inset->form->Figure); }
free(tmpfig->inset->form); #warning Reactivate this free_form calls
tmpfig->inset->form = 0; // fl_free_form(tmpfig->inset->form->Figure);
// free(tmpfig->inset->form);
// tmpfig->inset->form = 0;
} }
i = FindFigIndex(tmpfig); i = FindFigIndex(tmpfig);
--figinsref; --figinsref;
@ -1919,10 +1923,12 @@ void InsetFig::CallbackFig(long arg)
} }
UpdateInset(this); UpdateInset(this);
if (arg == 8) { if (arg == 8) {
fl_set_focus_object(form->Figure, form->OkBtn);
fl_hide_form(form->Figure); fl_hide_form(form->Figure);
fl_free_form(form->Figure); #warning Reactivate this free_form calls
free(form); // fl_free_form(form->Figure);
form = 0; // free(form);
// form = 0;
} }
break; break;
} //if not readonly } //if not readonly
@ -1931,10 +1937,12 @@ void InsetFig::CallbackFig(long arg)
break; break;
// fall through // fall through
case 9: /* cancel = restore and close */ case 9: /* cancel = restore and close */
fl_set_focus_object(form->Figure, form->OkBtn);
fl_hide_form(form->Figure); fl_hide_form(form->Figure);
fl_free_form(form->Figure); #warning Reactivate this free_form calls
free(form); // fl_free_form(form->Figure);
form = 0; // free(form);
// form = 0;
break; break;
} }

View File

@ -59,6 +59,7 @@
#include "ImportLaTeX.h" #include "ImportLaTeX.h"
#include "ImportNoweb.h" #include "ImportNoweb.h"
#include "support/syscall.h" #include "support/syscall.h"
#include "support/lstrings.h"
extern bool cursor_follows_scrollbar; extern bool cursor_follows_scrollbar;
@ -158,19 +159,6 @@ LyXFunc::~LyXFunc()
} }
string LyXFunc::argAsString(char const * const argument)
{
string tmp(argument);
if (tmp.empty()) {
// get the arg from somewhere else, a popup, or ask for
// it in the minibuffer.
}
lyxerr.debug() << "argAsString: <" << tmp << '>' << endl;
return tmp;
}
// I changed this func slightly. I commented out the ...FinishUndo(), // I changed this func slightly. I commented out the ...FinishUndo(),
// this means that all places that used to have a moveCursorUpdate, now // this means that all places that used to have a moveCursorUpdate, now
// have a ...FinishUndo() as the preceeding statement. I have also added // have a ...FinishUndo() as the preceeding statement. I have also added
@ -201,7 +189,7 @@ int LyXFunc::processKeyEvent(XEvent *ev)
s_r[9] = '\0'; s_r[9] = '\0';
int num_bytes; int num_bytes;
int action; int action;
char *argument = 0; string argument;
XKeyEvent *keyevent = &ev->xkey; XKeyEvent *keyevent = &ev->xkey;
KeySym keysym_return; KeySym keysym_return;
@ -297,11 +285,10 @@ int LyXFunc::processKeyEvent(XEvent *ev)
if (!(keyevent->state&ControlMask) && if (!(keyevent->state&ControlMask) &&
!(keyevent->state&Mod1Mask) && !(keyevent->state&Mod1Mask) &&
(isochar && keysym_return < 0xF000)) { (isochar && keysym_return < 0xF000)) {
argument = &s_r[0]; // shall this be here argument = s_r[0]; // shall this be here
argument[0] = isochar; argument += isochar;
argument[1] = 0;
} }
if (!argument) { if (argument.empty()) {
lyxerr.debug() << "Empty argument!" << endl; lyxerr.debug() << "Empty argument!" << endl;
// This can`t possibly be of any use // This can`t possibly be of any use
// so we`ll skip the dispatch. // so we`ll skip the dispatch.
@ -309,13 +296,12 @@ int LyXFunc::processKeyEvent(XEvent *ev)
} }
} else } else
if (action==LFUN_SELFINSERT) { if (action==LFUN_SELFINSERT) {
argument = &s_r[0]; argument = s_r[0];
argument[1] = 0;
} }
bool tmp_sc = show_sc; bool tmp_sc = show_sc;
show_sc = false; show_sc = false;
Dispatch(action, argument); Dispatch(action, argument.c_str());
show_sc = tmp_sc; show_sc = tmp_sc;
// Need this for deadkeys (alkis) // Need this for deadkeys (alkis)
@ -338,7 +324,7 @@ string LyXFunc::Dispatch(string const &cmd, string const &arg)
string LyXFunc::Dispatch(int ac, string LyXFunc::Dispatch(int ac,
char const *do_not_use_this_arg) char const *do_not_use_this_arg)
{ {
char const * argument = 0; string argument;
kb_action action; kb_action action;
@ -356,7 +342,8 @@ string LyXFunc::Dispatch(int ac,
argument = tmparg; argument = tmparg;
} else { } else {
action = (kb_action)ac; action = (kb_action)ac;
argument = do_not_use_this_arg; // except here if (do_not_use_this_arg)
argument = do_not_use_this_arg; // except here
} }
selection_possible = false; selection_possible = false;
@ -409,19 +396,17 @@ string LyXFunc::Dispatch(int ac,
int pseudoaction = action; int pseudoaction = action;
bool argsadded = false; bool argsadded = false;
string argu; if (!argument.empty()) {
if (argument) {
argu = argument;
// If we have the command with argument, // If we have the command with argument,
// this is better // this is better
pseudoaction = pseudoaction =
lyxaction.searchActionArg(action, lyxaction.searchActionArg(action,
argument); argument.c_str());
if (pseudoaction == -1) { if (pseudoaction == -1) {
pseudoaction = action; pseudoaction = action;
} else { } else {
comname += " " + argu; comname += " " + argument;
argsadded = true; argsadded = true;
} }
} }
@ -431,7 +416,7 @@ string LyXFunc::Dispatch(int ac,
if (!shortcuts.empty()) { if (!shortcuts.empty()) {
comname += ": " + shortcuts; comname += ": " + shortcuts;
} else if (!argsadded) { } else if (!argsadded) {
comname += " " + argu; comname += " " + argument;
} }
if (!comname.empty()) { if (!comname.empty()) {
@ -463,10 +448,8 @@ string LyXFunc::Dispatch(int ac,
if (owner->currentView()->available() && if (owner->currentView()->available() &&
owner->currentBuffer()->the_locking_inset) { owner->currentBuffer()->the_locking_inset) {
if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) { if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
char s[8]=""; if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
if (action==LFUN_UNKNOWN_ACTION && !argument) { argument = keyseq.getiso();
sprintf(s, "%c", keyseq.getiso());
argument = &s[0];
} }
// Undo/Redo pre 0.13 is a bit tricky for insets. // Undo/Redo pre 0.13 is a bit tricky for insets.
if (action==LFUN_UNDO) { if (action==LFUN_UNDO) {
@ -492,7 +475,7 @@ string LyXFunc::Dispatch(int ac,
inset->Edit(slx, sly); inset->Edit(slx, sly);
return string(); return string();
} else } else
if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument)) if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
return string(); return string();
else { else {
setMessage(N_("Text mode")); setMessage(N_("Text mode"));
@ -512,11 +495,9 @@ string LyXFunc::Dispatch(int ac,
static string last_search; static string last_search;
string searched_string; string searched_string;
string arg = argAsString(argument); if (!argument.empty()) {
last_search = argument;
if (!arg.empty()) { searched_string = argument;
last_search = arg;
searched_string = arg;
} else { } else {
searched_string = last_search; searched_string = last_search;
} }
@ -686,7 +667,7 @@ string LyXFunc::Dispatch(int ac,
case LFUN_EXPORT: case LFUN_EXPORT:
{ {
//needs argument as string //needs argument as string
string extyp=argAsString(argument); string extyp=argument;
// latex // latex
if (extyp == "latex") { if (extyp == "latex") {
@ -762,7 +743,7 @@ string LyXFunc::Dispatch(int ac,
case LFUN_IMPORT: case LFUN_IMPORT:
{ {
//needs argument as string //needs argument as string
string imtyp=argAsString(argument); string imtyp=argument;
// latex // latex
if (imtyp == "latex") { if (imtyp == "latex") {
@ -1042,9 +1023,7 @@ string LyXFunc::Dispatch(int ac,
case LFUN_FILE_INSERT: case LFUN_FILE_INSERT:
{ {
// needs argument as string MenuInsertLyXFile(argument);
string fil = argAsString(argument);
MenuInsertLyXFile(fil);
} }
break; break;
@ -1078,7 +1057,7 @@ string LyXFunc::Dispatch(int ac,
case LFUN_LAYOUTNO: case LFUN_LAYOUTNO:
{ {
lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl; lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
int sel = atoi(argument); int sel = strToInt(argument);
lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl; lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
// Should this give a setMessage instead? // Should this give a setMessage instead?
@ -1238,7 +1217,7 @@ string LyXFunc::Dispatch(int ac,
break; break;
case LFUN_INSERT_LABEL: case LFUN_INSERT_LABEL:
MenuInsertLabel(argument); MenuInsertLabel(argument.c_str());
break; break;
case LFUN_INSERT_REF: case LFUN_INSERT_REF:
@ -1879,7 +1858,7 @@ string LyXFunc::Dispatch(int ac,
{ {
int x; int x;
long y; long y;
sscanf(argument, " %d %ld", &x, &y); sscanf(argument.c_str(), " %d %ld", &x, &y);
owner->currentBuffer()->text->SetCursorFromCoordinates(x, y); owner->currentBuffer()->text->SetCursorFromCoordinates(x, y);
} }
break; break;
@ -1932,7 +1911,7 @@ string LyXFunc::Dispatch(int ac,
{ {
char file_name[100]; char file_name[100];
int row; int row;
sscanf(argument, " %s %d", file_name, &row); sscanf(argument.c_str(), " %s %d", file_name, &row);
// Must replace extension of the file to be .lyx and get full path // Must replace extension of the file to be .lyx and get full path
string s = ChangeExtension(string(file_name), ".lyx", false); string s = ChangeExtension(string(file_name), ".lyx", false);
@ -1965,7 +1944,7 @@ string LyXFunc::Dispatch(int ac,
case LFUN_APROPOS: case LFUN_APROPOS:
case LFUN_GETTIP: case LFUN_GETTIP:
{ {
int qa = lyxaction.LookupFunc((const char*)argument); int qa = lyxaction.LookupFunc(argument.c_str());
setMessage(lyxaction.helpText((kb_action)qa)); setMessage(lyxaction.helpText((kb_action)qa));
} }
break; break;
@ -2017,7 +1996,7 @@ string LyXFunc::Dispatch(int ac,
// --- toolbar ---------------------------------- // --- toolbar ----------------------------------
case LFUN_PUSH_TOOLBAR: case LFUN_PUSH_TOOLBAR:
{ {
int nth = atoi(argument); int nth = strToInt(argument);
if (lyxerr.debugging(Debug::TOOLBAR)) { if (lyxerr.debugging(Debug::TOOLBAR)) {
lyxerr << "LFUN_PUSH_TOOLBAR: argument = `" lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
<< argument << "'\n" << argument << "'\n"
@ -2094,14 +2073,14 @@ string LyXFunc::Dispatch(int ac,
owner->currentBuffer()-> owner->currentBuffer()->
open_new_inset(new InsetFormula(false)); open_new_inset(new InsetFormula(false));
owner->currentBuffer()-> owner->currentBuffer()->
the_locking_inset->LocalDispatch(action, argument); the_locking_inset->LocalDispatch(action, argument.c_str());
} }
} }
break; break;
case LFUN_INSERT_MATH: case LFUN_INSERT_MATH:
{ {
math_insert_symbol(argument); math_insert_symbol(argument.c_str());
} }
break; break;
@ -2150,7 +2129,7 @@ string LyXFunc::Dispatch(int ac,
// ale970405 // ale970405
// The note, if any, must be after the key, delimited // The note, if any, must be after the key, delimited
// by a | so both key and remark can have spaces. // by a | so both key and remark can have spaces.
if (argument) { if (!argument.empty()) {
string lsarg(argument); string lsarg(argument);
if (contains(lsarg, "|")) { if (contains(lsarg, "|")) {
new_inset->setContents(token(lsarg, '|', 0)); new_inset->setContents(token(lsarg, '|', 0));
@ -2221,7 +2200,7 @@ string LyXFunc::Dispatch(int ac,
case LFUN_INDEX_INSERT_LAST: case LFUN_INDEX_INSERT_LAST:
{ {
InsetIndex *new_inset = new InsetIndex(); InsetIndex *new_inset = new InsetIndex();
if (argument) { if (!argument.empty()) {
string lsarg(argument); string lsarg(argument);
new_inset->setContents(lsarg); new_inset->setContents(lsarg);
owner->currentBuffer()->insertInset(new_inset); owner->currentBuffer()->insertInset(new_inset);
@ -2312,20 +2291,19 @@ string LyXFunc::Dispatch(int ac,
case LFUN_INSERTFOOTNOTE: case LFUN_INSERTFOOTNOTE:
{ {
LyXParagraph::footnote_kind kind; LyXParagraph::footnote_kind kind;
string arg = argument; if (argument == "footnote")
if (arg == "footnote")
{ kind = LyXParagraph::FOOTNOTE; } { kind = LyXParagraph::FOOTNOTE; }
else if (arg == "margin") else if (argument == "margin")
{ kind = LyXParagraph::MARGIN; } { kind = LyXParagraph::MARGIN; }
else if (arg == "figure") else if (argument == "figure")
{ kind = LyXParagraph::FIG; } { kind = LyXParagraph::FIG; }
else if (arg == "table") else if (argument == "table")
{ kind = LyXParagraph::TAB; } { kind = LyXParagraph::TAB; }
else if (arg == "wide-fig") else if (argument == "wide-fig")
{ kind = LyXParagraph::WIDE_FIG; } { kind = LyXParagraph::WIDE_FIG; }
else if (arg == "wide-tab") else if (argument == "wide-tab")
{ kind = LyXParagraph::WIDE_TAB; } { kind = LyXParagraph::WIDE_TAB; }
else if (arg == "algorithm") else if (argument == "algorithm")
{ kind = LyXParagraph::ALGORITHM; } { kind = LyXParagraph::ALGORITHM; }
else { else {
setErrorMessage(N_("Unknown kind of footnote")); setErrorMessage(N_("Unknown kind of footnote"));
@ -2362,9 +2340,8 @@ string LyXFunc::Dispatch(int ac,
case LFUN_SELFINSERT: case LFUN_SELFINSERT:
{ {
string const text = argument; for (string::size_type i = 0; i < argument.length(); ++i) {
for (string::size_type i = 0; i < text.length(); ++i) { owner->currentBuffer()->text->InsertChar(argument[i]);
owner->currentBuffer()->text->InsertChar(text[i]);
// This needs to be in the loop, or else we // This needs to be in the loop, or else we
// won't break lines correctly. (Asger) // won't break lines correctly. (Asger)
SmallUpdate(1); SmallUpdate(1);
@ -2384,7 +2361,7 @@ string LyXFunc::Dispatch(int ac,
break; break;
} }
if (argument) { if (!argument.empty()) {
/* Automatically delete the currently selected /* Automatically delete the currently selected
* text and replace it with what is being * text and replace it with what is being
@ -2400,12 +2377,12 @@ string LyXFunc::Dispatch(int ac,
} }
BeforeChange(); BeforeChange();
for(char const *p = argument; *p; p++) { for (string::size_type i = 0; i < argument.length(); ++i) {
if (greek_kb_flag) { if (greek_kb_flag) {
if (!math_insert_greek(*p)) if (!math_insert_greek(argument[i]))
owner->getIntl()->getTrans()->TranslateAndInsert(*p, owner->currentBuffer()->text); owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
} else } else
owner->getIntl()->getTrans()->TranslateAndInsert(*p, owner->currentBuffer()->text); owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
} }
SmallUpdate(1); SmallUpdate(1);

View File

@ -73,8 +73,6 @@ public:
void setHintMessage(bool); void setHintMessage(bool);
private: private:
///
string argAsString(char const *const argument);
/// ///
LyXView *owner; LyXView *owner;
/// ///

View File

@ -597,7 +597,8 @@ string AddName(string const & path, string const & fname)
// Strips path from filename // Strips path from filename
string OnlyFilename(string const & fname) string OnlyFilename(string const & fname)
{ {
Assert(!fname.empty()); // We don't allow empty filename. (Lgb) if (fname.empty())
return fname;
string::size_type j = fname.rfind('/'); string::size_type j = fname.rfind('/');
if (j == string::npos) // no '/' in fname if (j == string::npos) // no '/' in fname

View File

@ -29,7 +29,7 @@ bool isStrInt(string const & str)
} }
int LStr2Int(string const & str) int strToInt(string const & str)
{ {
string tmpstr; string tmpstr;