make ncmpcpp compile with -fno-exceptions

This commit is contained in:
Andrzej Rybczak
2009-09-21 06:01:21 +02:00
parent 14a774b8a3
commit 70910b77ed
12 changed files with 135 additions and 70 deletions

View File

@@ -1,7 +1,7 @@
bin_PROGRAMS = ncmpcpp
ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp conv.cpp display.cpp \
help.cpp helpers.cpp info.cpp libmpdclient.c lyrics.cpp media_library.cpp \
menu.cpp misc.cpp mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.cpp \
error.cpp help.cpp helpers.cpp info.cpp libmpdclient.c lyrics.cpp \
media_library.cpp menu.cpp misc.cpp mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.cpp \
playlist_editor.cpp scrollpad.cpp search_engine.cpp settings.cpp song.cpp status.cpp \
str_pool.c tag_editor.cpp tiny_tag_editor.cpp visualizer.cpp window.cpp
@@ -10,7 +10,7 @@ INCLUDES= $(all_includes)
# the library search path.
ncmpcpp_LDFLAGS = $(all_libraries)
noinst_HEADERS = browser.h charset.h clock.h conv.h display.h global.h help.h \
helpers.h home.h info.h lyrics.h media_library.h menu.h misc.h mpdpp.h outputs.h \
playlist_editor.h screen.h scrollpad.h search_engine.h settings.h song.h tag_editor.h \
tiny_tag_editor.h visualizer.h window.h
noinst_HEADERS = browser.h charset.h clock.h conv.h display.h error.h global.h \
help.h helpers.h home.h info.h lyrics.h media_library.h menu.h misc.h mpdpp.h \
outputs.h playlist_editor.h screen.h scrollpad.h search_engine.h settings.h \
song.h tag_editor.h tiny_tag_editor.h visualizer.h window.h

46
src/error.cpp Normal file
View File

@@ -0,0 +1,46 @@
/***************************************************************************
* Copyright (C) 2008-2009 by Andrzej Rybczak *
* electricityispower@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <ctime>
#include <cstdlib>
#include <iostream>
#include "error.h"
namespace
{
const char *Timestamp()
{
static char result[32];
time_t raw;
tm *t;
time(&raw);
t = localtime(&raw);
result[strftime(result, 31, "%Y/%m/%d %X", t)] = 0;
return result;
}
}
void FatalError(const std::string &msg)
{
std::cerr << "[" << Timestamp() << "] " << msg << std::endl;
abort();
}

35
src/error.h Normal file
View File

@@ -0,0 +1,35 @@
/***************************************************************************
* Copyright (C) 2008-2009 by Andrzej Rybczak *
* electricityispower@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef _ERROR_H
#define _ERROR_H
#if defined(__GNUC__) && __GNUC__ >= 3
# define GNUC_NORETURN __attribute__((noreturn))
#else
# define GNUC_NORETURN
#endif
#include <string>
void FatalError(const std::string &msg) GNUC_NORETURN;
#endif

View File

@@ -277,7 +277,7 @@ std::string FindSharedDir(Menu<Song> *menu)
std::string FindSharedDir(const SongList &v)
{
if (v.empty()) // this should never happen, but in case...
throw std::runtime_error("empty SongList passed to FindSharedDir(const SongList &)!");
FatalError("empty SongList passed to FindSharedDir(const SongList &)!");
size_t i = -1;
std::string first = v.front()->GetDirectory();
for (SongList::const_iterator it = ++v.begin(); it != v.end(); ++it)

View File

@@ -24,6 +24,7 @@
#include <regex.h>
#include <set>
#include "error.h"
#include "window.h"
#include "strbuffer.h"
@@ -34,16 +35,6 @@ namespace NCurses
class List
{
public:
/// Exception class, thrown by various functions
/// that return references to items on the list
/// if requested item is separator
/// @see Menu::Back()
/// @see Menu::Current()
/// @see Menu::at()
/// @see Menu::operator[]
///
class InvalidItem { };
/// @see Menu::Select()
///
virtual void Select(int pos, bool state) = 0;
@@ -1073,56 +1064,56 @@ template <typename T> std::string NCurses::Menu<T>::GetOption(size_t pos)
template <typename T> T &NCurses::Menu<T>::Back()
{
if (!itsOptionsPtr->back())
throw InvalidItem();
FatalError("Menu::Back() has requested separator!");
return itsOptionsPtr->back()->Item;
}
template <typename T> const T &NCurses::Menu<T>::Back() const
{
if (!itsOptionsPtr->back())
throw InvalidItem();
FatalError("Menu::Back() has requested separator!");
return itsOptionsPtr->back()->Item;
}
template <typename T> T &NCurses::Menu<T>::Current()
{
if (!itsOptionsPtr->at(itsHighlight))
throw InvalidItem();
FatalError("Menu::Current() has requested separator!");
return (*itsOptionsPtr)[itsHighlight]->Item;
}
template <typename T> const T &NCurses::Menu<T>::Current() const
{
if (!itsOptionsPtr->at(itsHighlight))
throw InvalidItem();
FatalError("Menu::Current() const has requested separator!");
return (*itsOptionsPtr)[itsHighlight]->Item;
}
template <typename T> T &NCurses::Menu<T>::at(size_t pos)
{
if (!itsOptionsPtr->at(pos))
throw InvalidItem();
FatalError("Menu::at() has requested separator!");
return (*itsOptionsPtr)[pos]->Item;
}
template <typename T> const T &NCurses::Menu<T>::at(size_t pos) const
{
if (!itsOptions->at(pos))
throw InvalidItem();
FatalError("Menu::at() const has requested separator!");
return (*itsOptionsPtr)[pos]->Item;
}
template <typename T> const T &NCurses::Menu<T>::operator[](size_t pos) const
{
if (!(*itsOptionsPtr)[pos])
throw InvalidItem();
FatalError("Menu::operator[] const has requested separator!");
return (*itsOptionsPtr)[pos]->Item;
}
template <typename T> T &NCurses::Menu<T>::operator[](size_t pos)
{
if (!(*itsOptionsPtr)[pos])
throw InvalidItem();
FatalError("Menu::operator[] has requested separator!");
return (*itsOptionsPtr)[pos]->Item;
}

View File

@@ -1535,11 +1535,7 @@ int main(int argc, char *argv[])
int newpos = 0;
if (position.find(':') != std::string::npos) // probably time in mm:ss
{
try
{
newpos = StrToInt(position)*60 + StrToInt(position.substr(position.find(':')+1));
}
catch (std::out_of_range) { }
newpos = StrToInt(position)*60 + StrToInt(position.substr(position.find(':')+1));
if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
Mpd.Seek(newpos);
else

View File

@@ -330,12 +330,10 @@ void SearchEngine::Prepare()
{
for (size_t i = 0; i < w->Size(); ++i)
{
try
{
delete (*w)[i].first;
delete (*w)[i].second;
}
catch (List::InvalidItem) { }
if (i == 10 || i == 14 || i == ResetButton+1 || i == ResetButton+3) // separators
continue;
delete (*w)[i].first;
delete (*w)[i].second;
}
w->SetTitle("");
@@ -347,11 +345,9 @@ void SearchEngine::Prepare()
for (size_t i = 0; i < 17; ++i)
{
try
{
w->at(i).first = new Buffer();
}
catch (List::InvalidItem) { }
if (i == 10 || i == 14) // separators
continue;
(*w)[i].first = new Buffer();
}
*w->at(0).first << fmtBold << "Any: " << fmtBoldEnd << ' ';

View File

@@ -649,7 +649,7 @@ void ReadConfiguration(ncmpcpp_config &conf)
{
conf.progressbar = TO_WSTRING(v);
if (conf.progressbar.length() != 2)
throw std::runtime_error("the length of progressbar_look is not two characters long!");
FatalError("the length of progressbar_look is not two characters long!");
}
else if (cl.find("default_tag_editor_pattern") != std::string::npos)
{

View File

@@ -29,6 +29,7 @@
#include "charset.h"
#include "conv.h"
#include "error.h"
#include "song.h"
MPD::Song::Song(mpd_Song *s, bool copy_ptr) : itsSong(s ? s : mpd_newSong()),
@@ -478,7 +479,7 @@ void MPD::Song::ValidateFormat(const std::string &type, const std::string &s)
--braces;
}
if (braces)
throw std::runtime_error(type + ": number of opening and closing braces does not equal!");
FatalError(type + ": number of opening and closing braces does not equal!");
}
void MPD::Song::SetHashAndSlash()

View File

@@ -1199,29 +1199,34 @@ std::string TagEditor::ParseFilename(MPD::Song &s, std::string mask, bool previe
std::vector< std::pair<char, std::string> > tags;
std::string file = s.GetName().substr(0, s.GetName().rfind("."));
try
for (size_t i = mask.find("%"); i != std::string::npos; i = mask.find("%"))
{
for (size_t i = mask.find("%"); i != std::string::npos; i = mask.find("%"))
{
tags.push_back(std::make_pair(mask.at(i+1), ""));
mask = mask.substr(i+2);
i = mask.find("%");
if (!mask.empty())
separators.push_back(mask.substr(0, i));
}
size_t i = 0;
for (std::vector<std::string>::const_iterator it = separators.begin(); it != separators.end(); ++it, ++i)
{
size_t j = file.find(*it);
tags.at(i).second = file.substr(0, j);
file = file.substr(j+it->length());
}
if (!file.empty())
tags.at(i).second = file;
tags.push_back(std::make_pair(mask.at(i+1), ""));
mask = mask.substr(i+2);
i = mask.find("%");
if (!mask.empty())
separators.push_back(mask.substr(0, i));
}
catch (std::out_of_range)
size_t i = 0;
for (std::vector<std::string>::const_iterator it = separators.begin(); it != separators.end(); ++it, ++i)
{
return "Error while parsing filename!";
size_t j = file.find(*it);
tags.at(i).second = file.substr(0, j);
if (j+it->length() > file.length())
goto PARSE_FAILED;
file = file.substr(j+it->length());
}
if (!file.empty())
{
if (i >= tags.size())
goto PARSE_FAILED;
tags.at(i).second = file;
}
if (0) // tss...
{
PARSE_FAILED:
return "Error while parsing filename!\n";
}
for (std::vector< std::pair<char, std::string> >::iterator it = tags.begin(); it != tags.end(); ++it)

View File

@@ -21,6 +21,7 @@
#include <cstring>
#include <cstdlib>
#include "error.h"
#include "window.h"
using namespace NCurses;
@@ -95,7 +96,7 @@ Window::Window(size_t startx,
|| itsStartY > size_t(LINES)
|| itsWidth+itsStartX > size_t(COLS)
|| itsHeight+itsStartY > size_t(LINES))
throw BadSize();
FatalError("Constructed window is bigger than terminal size!");
if (itsBorder != brNone)
{

View File

@@ -463,12 +463,6 @@ namespace NCurses
static size_t Length(const std::wstring &ws);
protected:
/// Exception class that is thrown if constructed
/// window has size bigger than actual screen size.
///
class BadSize { };
/// Sets colors of window (interal use only)
/// @param fg foregound color
/// @param bg background color