mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Fix cppcheck variable scope warnings
These were all flagged by "(style) The scope of the variable 'x' can be reduced." Narowing the scope improves readability, and if it is in a loop then the compiler will be clever enough to produce efficient code, we do not need manual optimization for POD types.
This commit is contained in:
parent
4a5efb5a7d
commit
b6aed54c45
@ -320,12 +320,11 @@ bool Lexer::Pimpl::next(bool esc /* = false */)
|
||||
}
|
||||
|
||||
|
||||
unsigned char c = 0; // getc() returns an int
|
||||
char cc = 0;
|
||||
status = 0;
|
||||
while (is && !status) {
|
||||
is.get(cc);
|
||||
c = cc;
|
||||
unsigned char c = cc;
|
||||
|
||||
if (c == commentChar) {
|
||||
// Read rest of line (fast :-)
|
||||
@ -348,9 +347,8 @@ bool Lexer::Pimpl::next(bool esc /* = false */)
|
||||
|
||||
if (esc) {
|
||||
|
||||
bool escaped = false;
|
||||
do {
|
||||
escaped = false;
|
||||
bool escaped = false;
|
||||
is.get(cc);
|
||||
c = cc;
|
||||
if (c == '\r') continue;
|
||||
|
@ -2041,14 +2041,12 @@ void Paragraph::setBeginOfBody()
|
||||
pos_type end = size();
|
||||
if (i < end && !(isNewline(i) || isEnvSeparator(i))) {
|
||||
++i;
|
||||
char_type previous_char = 0;
|
||||
char_type temp = 0;
|
||||
if (i < end) {
|
||||
previous_char = d->text_[i];
|
||||
char_type previous_char = d->text_[i];
|
||||
if (!(isNewline(i) || isEnvSeparator(i))) {
|
||||
++i;
|
||||
while (i < end && previous_char != ' ') {
|
||||
temp = d->text_[i];
|
||||
char_type temp = d->text_[i];
|
||||
if (isNewline(i) || isEnvSeparator(i))
|
||||
break;
|
||||
++i;
|
||||
|
@ -129,11 +129,11 @@ void ServerSocket::dataCallback(int fd)
|
||||
return;
|
||||
shared_ptr<LyXDataSocket> client = it->second;
|
||||
string line;
|
||||
size_t pos;
|
||||
bool saidbye = false;
|
||||
while (!saidbye && client->readln(line)) {
|
||||
// The protocol must be programmed here
|
||||
// Split the key and the data
|
||||
size_t pos;
|
||||
if ((pos = line.find(':')) == string::npos) {
|
||||
client->writeln("ERROR:" + line + ":malformed message");
|
||||
continue;
|
||||
|
10
src/Text.cpp
10
src/Text.cpp
@ -1186,7 +1186,6 @@ bool Text::cursorVisLeftOneWord(Cursor & cur)
|
||||
LBUFERR(this == cur.text());
|
||||
|
||||
pos_type left_pos, right_pos;
|
||||
bool left_is_letter, right_is_letter;
|
||||
|
||||
Cursor temp_cur = cur;
|
||||
|
||||
@ -1195,9 +1194,9 @@ bool Text::cursorVisLeftOneWord(Cursor & cur)
|
||||
|
||||
// collect some information about current cursor position
|
||||
temp_cur.getSurroundingPos(left_pos, right_pos);
|
||||
left_is_letter =
|
||||
bool left_is_letter =
|
||||
(left_pos > -1 ? !temp_cur.paragraph().isWordSeparator(left_pos) : false);
|
||||
right_is_letter =
|
||||
bool right_is_letter =
|
||||
(right_pos > -1 ? !temp_cur.paragraph().isWordSeparator(right_pos) : false);
|
||||
|
||||
// if we're not at a letter/non-letter boundary, continue moving
|
||||
@ -1223,7 +1222,6 @@ bool Text::cursorVisRightOneWord(Cursor & cur)
|
||||
LBUFERR(this == cur.text());
|
||||
|
||||
pos_type left_pos, right_pos;
|
||||
bool left_is_letter, right_is_letter;
|
||||
|
||||
Cursor temp_cur = cur;
|
||||
|
||||
@ -1232,9 +1230,9 @@ bool Text::cursorVisRightOneWord(Cursor & cur)
|
||||
|
||||
// collect some information about current cursor position
|
||||
temp_cur.getSurroundingPos(left_pos, right_pos);
|
||||
left_is_letter =
|
||||
bool left_is_letter =
|
||||
(left_pos > -1 ? !temp_cur.paragraph().isWordSeparator(left_pos) : false);
|
||||
right_is_letter =
|
||||
bool right_is_letter =
|
||||
(right_pos > -1 ? !temp_cur.paragraph().isWordSeparator(right_pos) : false);
|
||||
|
||||
// if we're not at a letter/non-letter boundary, continue moving
|
||||
|
@ -2473,13 +2473,12 @@ QAbstractItemModel * GuiApplication::languageModel()
|
||||
|
||||
QStandardItemModel * lang_model = new QStandardItemModel(this);
|
||||
lang_model->insertColumns(0, 3);
|
||||
int current_row;
|
||||
QIcon speller(getPixmap("images/", "dialog-show_spellchecker", "svgz,png"));
|
||||
QIcon saurus(getPixmap("images/", "thesaurus-entry", "svgz,png"));
|
||||
Languages::const_iterator it = lyx::languages.begin();
|
||||
Languages::const_iterator end = lyx::languages.end();
|
||||
for (; it != end; ++it) {
|
||||
current_row = lang_model->rowCount();
|
||||
int current_row = lang_model->rowCount();
|
||||
lang_model->insertRows(current_row, 1);
|
||||
QModelIndex pl_item = lang_model->index(current_row, 0);
|
||||
QModelIndex sp_item = lang_model->index(current_row, 1);
|
||||
|
@ -206,10 +206,10 @@ void GuiBranches::on_renamePB_pressed()
|
||||
if (!sel_branch.isEmpty()) {
|
||||
docstring newname;
|
||||
docstring const oldname = qstring_to_ucs4(sel_branch);
|
||||
bool success = false;
|
||||
if (Alert::askForText(newname, _("Enter new branch name"), oldname)) {
|
||||
if (newname.empty() || oldname == newname)
|
||||
return;
|
||||
bool success = false;
|
||||
if (branchlist_.find(newname)) {
|
||||
docstring text = support::bformat(
|
||||
_("A branch with the name \"%1$s\" already exists.\n"
|
||||
|
@ -3506,14 +3506,13 @@ void GuiDocument::updateIncludeonlys()
|
||||
masterChildModule->childrenTW->setEnabled(true);
|
||||
masterChildModule->maintainAuxCB->setEnabled(true);
|
||||
}
|
||||
QTreeWidgetItem * item = 0;
|
||||
ListOfBuffers children = buffer().getChildren();
|
||||
ListOfBuffers::const_iterator it = children.begin();
|
||||
ListOfBuffers::const_iterator end = children.end();
|
||||
bool has_unincluded = false;
|
||||
bool all_unincluded = true;
|
||||
for (; it != end; ++it) {
|
||||
item = new QTreeWidgetItem(masterChildModule->childrenTW);
|
||||
QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
|
||||
// FIXME Unicode
|
||||
string const name =
|
||||
to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
|
||||
|
@ -233,11 +233,10 @@ void GuiIndices::on_renamePB_clicked()
|
||||
if (!sel_index.isEmpty()) {
|
||||
docstring newname;
|
||||
docstring const oldname = qstring_to_ucs4(sel_index);
|
||||
bool success = false;
|
||||
if (Alert::askForText(newname, _("Enter new index name"), oldname)) {
|
||||
if (newname.empty() || oldname == newname)
|
||||
return;
|
||||
success = indiceslist_.rename(qstring_to_ucs4(sel_index), newname);
|
||||
bool success = indiceslist_.rename(qstring_to_ucs4(sel_index), newname);
|
||||
newIndexLE->clear();
|
||||
updateView();
|
||||
if (!success)
|
||||
|
@ -96,7 +96,6 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
|
||||
}
|
||||
sort(dmap.begin(), dmap.end(), DebugSorter);
|
||||
|
||||
QTreeWidgetItem * item = 0;
|
||||
widget_->debugMessagesTW->setColumnCount(2);
|
||||
widget_->debugMessagesTW->headerItem()->setText(0, qt_("Debug Level"));
|
||||
widget_->debugMessagesTW->headerItem()->setText(1, qt_("Set"));
|
||||
@ -104,7 +103,7 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
|
||||
DebugVector::const_iterator dit = dmap.begin();
|
||||
DebugVector::const_iterator const den = dmap.end();
|
||||
for (; dit != den; ++dit) {
|
||||
item = new QTreeWidgetItem(widget_->debugMessagesTW);
|
||||
QTreeWidgetItem * item = new QTreeWidgetItem(widget_->debugMessagesTW);
|
||||
item->setText(0, dit->second);
|
||||
item->setData(0, Qt::UserRole, int(dit->first));
|
||||
item->setText(1, qt_("No"));
|
||||
|
@ -227,9 +227,6 @@ public:
|
||||
static QString const strCharacter = qt_("Character: ");
|
||||
static QString const strCodePoint = qt_("Code Point: ");
|
||||
|
||||
// FIXME THREAD
|
||||
static char codeName[10];
|
||||
|
||||
char_type c = symbols_.at(index.row());
|
||||
|
||||
if (role == Qt::TextAlignmentRole)
|
||||
@ -239,6 +236,9 @@ public:
|
||||
return toqstr(c);
|
||||
|
||||
if (role == Qt::ToolTipRole) {
|
||||
// FIXME THREAD
|
||||
static char codeName[10];
|
||||
|
||||
sprintf(codeName, "0x%04x", c);
|
||||
return strCharacter + toqstr(c) + '\n'
|
||||
+ strCodePoint + QLatin1String(codeName);
|
||||
|
@ -208,7 +208,6 @@ void TocModel::populate(unsigned int & index, QModelIndex const & parent)
|
||||
{
|
||||
int curdepth = (*toc_)[index].depth() + 1;
|
||||
|
||||
int current_row;
|
||||
QModelIndex child_item;
|
||||
model_->insertColumns(0, 1, parent);
|
||||
|
||||
@ -222,7 +221,7 @@ void TocModel::populate(unsigned int & index, QModelIndex const & parent)
|
||||
}
|
||||
maxdepth_ = max(maxdepth_, item.depth());
|
||||
mindepth_ = min(mindepth_, item.depth());
|
||||
current_row = model_->rowCount(parent);
|
||||
int current_row = model_->rowCount(parent);
|
||||
model_->insertRows(current_row, 1, parent);
|
||||
child_item = model_->index(current_row, 0, parent);
|
||||
model_->setData(child_item, toqstr(item.str()), Qt::DisplayRole);
|
||||
|
@ -348,10 +348,10 @@ bool lyxreplace(BufferView * bv,
|
||||
bool forward = parse_bool(howto);
|
||||
bool findnext = howto.empty() ? true : parse_bool(howto);
|
||||
|
||||
int replace_count = 0;
|
||||
bool update = false;
|
||||
|
||||
if (!has_deleted) {
|
||||
int replace_count = 0;
|
||||
if (all) {
|
||||
replace_count = replaceAll(bv, search, rplc, casesensitive, matchword);
|
||||
update = replace_count > 0;
|
||||
|
@ -980,9 +980,6 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
)
|
||||
cnts.step(cntr, OutputUpdate);
|
||||
ParagraphList::const_iterator send;
|
||||
// this will be positive, if we want to skip the initial word
|
||||
// (if it's been taken for the label).
|
||||
pos_type sep = 0;
|
||||
|
||||
switch (style.latextype) {
|
||||
case LATEX_ENVIRONMENT:
|
||||
@ -998,6 +995,9 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
lastlay = 0;
|
||||
}
|
||||
|
||||
// this will be positive, if we want to skip the
|
||||
// initial word (if it's been taken for the label).
|
||||
pos_type sep = 0;
|
||||
bool const labelfirst = style.htmllabelfirst();
|
||||
if (!labelfirst)
|
||||
openItemTag(xs, style, par->params());
|
||||
|
@ -141,7 +141,6 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
|
||||
static QThreadStorage<int> tMangleID;
|
||||
|
||||
MangledMap & mangledNames = tMangledNames.localData();
|
||||
int & mangleID = tMangleID.localData();
|
||||
|
||||
MangledMap::const_iterator const known = mangledNames.find(orig);
|
||||
if (known != mangledNames.end())
|
||||
@ -170,9 +169,10 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
|
||||
}
|
||||
}
|
||||
|
||||
if (mangle)
|
||||
if (mangle) {
|
||||
int & mangleID = tMangleID.localData();
|
||||
content += "-" + convert<docstring>(mangleID++);
|
||||
else if (isDigitASCII(content[content.size() - 1]))
|
||||
} else if (isDigitASCII(content[content.size() - 1]))
|
||||
content += ".";
|
||||
|
||||
mangledNames[orig] = content;
|
||||
|
@ -1007,7 +1007,6 @@ cmd_ret const runCommand(string const & cmd)
|
||||
// variants ipstream, opstream
|
||||
|
||||
#if defined (_WIN32)
|
||||
int fno;
|
||||
STARTUPINFO startup;
|
||||
PROCESS_INFORMATION process;
|
||||
SECURITY_ATTRIBUTES security;
|
||||
@ -1049,7 +1048,7 @@ cmd_ret const runCommand(string const & cmd)
|
||||
0, 0, &startup, &process)) {
|
||||
|
||||
CloseHandle(process.hThread);
|
||||
fno = _open_osfhandle((long)in, _O_RDONLY);
|
||||
int fno = _open_osfhandle((long)in, _O_RDONLY);
|
||||
CloseHandle(out);
|
||||
inf = _fdopen(fno, "r");
|
||||
}
|
||||
|
@ -2934,7 +2934,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
// the syntax is \subfloat[list entry][sub caption]{content}
|
||||
// if it is a table of figure depends on the surrounding float
|
||||
// FIXME: second optional argument is not parsed
|
||||
bool has_caption = false;
|
||||
p.skip_spaces();
|
||||
// do nothing if there is no outer float
|
||||
if (!float_type.empty()) {
|
||||
@ -2946,6 +2945,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
<< "\nstatus collapsed\n\n";
|
||||
// test for caption
|
||||
string caption;
|
||||
bool has_caption = false;
|
||||
if (p.next_token().cat() != catEscape &&
|
||||
p.next_token().character() == '[') {
|
||||
p.get_token(); // eat '['
|
||||
|
Loading…
Reference in New Issue
Block a user