make ncmpcpp compile with -fno-exceptions
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
bin_PROGRAMS = ncmpcpp
|
bin_PROGRAMS = ncmpcpp
|
||||||
ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp conv.cpp display.cpp \
|
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 \
|
error.cpp help.cpp helpers.cpp info.cpp libmpdclient.c lyrics.cpp \
|
||||||
menu.cpp misc.cpp mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.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 \
|
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
|
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.
|
# the library search path.
|
||||||
ncmpcpp_LDFLAGS = $(all_libraries)
|
ncmpcpp_LDFLAGS = $(all_libraries)
|
||||||
noinst_HEADERS = browser.h charset.h clock.h conv.h display.h global.h help.h \
|
noinst_HEADERS = browser.h charset.h clock.h conv.h display.h error.h global.h \
|
||||||
helpers.h home.h info.h lyrics.h media_library.h menu.h misc.h mpdpp.h outputs.h \
|
help.h helpers.h home.h info.h lyrics.h media_library.h menu.h misc.h mpdpp.h \
|
||||||
playlist_editor.h screen.h scrollpad.h search_engine.h settings.h song.h tag_editor.h \
|
outputs.h playlist_editor.h screen.h scrollpad.h search_engine.h settings.h \
|
||||||
tiny_tag_editor.h visualizer.h window.h
|
song.h tag_editor.h tiny_tag_editor.h visualizer.h window.h
|
||||||
|
|||||||
46
src/error.cpp
Normal file
46
src/error.cpp
Normal 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
35
src/error.h
Normal 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
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ std::string FindSharedDir(Menu<Song> *menu)
|
|||||||
std::string FindSharedDir(const SongList &v)
|
std::string FindSharedDir(const SongList &v)
|
||||||
{
|
{
|
||||||
if (v.empty()) // this should never happen, but in case...
|
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;
|
size_t i = -1;
|
||||||
std::string first = v.front()->GetDirectory();
|
std::string first = v.front()->GetDirectory();
|
||||||
for (SongList::const_iterator it = ++v.begin(); it != v.end(); ++it)
|
for (SongList::const_iterator it = ++v.begin(); it != v.end(); ++it)
|
||||||
|
|||||||
27
src/menu.h
27
src/menu.h
@@ -24,6 +24,7 @@
|
|||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "strbuffer.h"
|
#include "strbuffer.h"
|
||||||
|
|
||||||
@@ -34,16 +35,6 @@ namespace NCurses
|
|||||||
class List
|
class List
|
||||||
{
|
{
|
||||||
public:
|
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()
|
/// @see Menu::Select()
|
||||||
///
|
///
|
||||||
virtual void Select(int pos, bool state) = 0;
|
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()
|
template <typename T> T &NCurses::Menu<T>::Back()
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->back())
|
if (!itsOptionsPtr->back())
|
||||||
throw InvalidItem();
|
FatalError("Menu::Back() has requested separator!");
|
||||||
return itsOptionsPtr->back()->Item;
|
return itsOptionsPtr->back()->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> const T &NCurses::Menu<T>::Back() const
|
template <typename T> const T &NCurses::Menu<T>::Back() const
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->back())
|
if (!itsOptionsPtr->back())
|
||||||
throw InvalidItem();
|
FatalError("Menu::Back() has requested separator!");
|
||||||
return itsOptionsPtr->back()->Item;
|
return itsOptionsPtr->back()->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> T &NCurses::Menu<T>::Current()
|
template <typename T> T &NCurses::Menu<T>::Current()
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->at(itsHighlight))
|
if (!itsOptionsPtr->at(itsHighlight))
|
||||||
throw InvalidItem();
|
FatalError("Menu::Current() has requested separator!");
|
||||||
return (*itsOptionsPtr)[itsHighlight]->Item;
|
return (*itsOptionsPtr)[itsHighlight]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> const T &NCurses::Menu<T>::Current() const
|
template <typename T> const T &NCurses::Menu<T>::Current() const
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->at(itsHighlight))
|
if (!itsOptionsPtr->at(itsHighlight))
|
||||||
throw InvalidItem();
|
FatalError("Menu::Current() const has requested separator!");
|
||||||
return (*itsOptionsPtr)[itsHighlight]->Item;
|
return (*itsOptionsPtr)[itsHighlight]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> T &NCurses::Menu<T>::at(size_t pos)
|
template <typename T> T &NCurses::Menu<T>::at(size_t pos)
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->at(pos))
|
if (!itsOptionsPtr->at(pos))
|
||||||
throw InvalidItem();
|
FatalError("Menu::at() has requested separator!");
|
||||||
return (*itsOptionsPtr)[pos]->Item;
|
return (*itsOptionsPtr)[pos]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> const T &NCurses::Menu<T>::at(size_t pos) const
|
template <typename T> const T &NCurses::Menu<T>::at(size_t pos) const
|
||||||
{
|
{
|
||||||
if (!itsOptions->at(pos))
|
if (!itsOptions->at(pos))
|
||||||
throw InvalidItem();
|
FatalError("Menu::at() const has requested separator!");
|
||||||
return (*itsOptionsPtr)[pos]->Item;
|
return (*itsOptionsPtr)[pos]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> const T &NCurses::Menu<T>::operator[](size_t pos) const
|
template <typename T> const T &NCurses::Menu<T>::operator[](size_t pos) const
|
||||||
{
|
{
|
||||||
if (!(*itsOptionsPtr)[pos])
|
if (!(*itsOptionsPtr)[pos])
|
||||||
throw InvalidItem();
|
FatalError("Menu::operator[] const has requested separator!");
|
||||||
return (*itsOptionsPtr)[pos]->Item;
|
return (*itsOptionsPtr)[pos]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> T &NCurses::Menu<T>::operator[](size_t pos)
|
template <typename T> T &NCurses::Menu<T>::operator[](size_t pos)
|
||||||
{
|
{
|
||||||
if (!(*itsOptionsPtr)[pos])
|
if (!(*itsOptionsPtr)[pos])
|
||||||
throw InvalidItem();
|
FatalError("Menu::operator[] has requested separator!");
|
||||||
return (*itsOptionsPtr)[pos]->Item;
|
return (*itsOptionsPtr)[pos]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1535,11 +1535,7 @@ int main(int argc, char *argv[])
|
|||||||
int newpos = 0;
|
int newpos = 0;
|
||||||
if (position.find(':') != std::string::npos) // probably time in mm:ss
|
if (position.find(':') != std::string::npos) // probably time in mm:ss
|
||||||
{
|
{
|
||||||
try
|
newpos = StrToInt(position)*60 + StrToInt(position.substr(position.find(':')+1));
|
||||||
{
|
|
||||||
newpos = StrToInt(position)*60 + StrToInt(position.substr(position.find(':')+1));
|
|
||||||
}
|
|
||||||
catch (std::out_of_range) { }
|
|
||||||
if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
|
if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
|
||||||
Mpd.Seek(newpos);
|
Mpd.Seek(newpos);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -330,12 +330,10 @@ void SearchEngine::Prepare()
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < w->Size(); ++i)
|
for (size_t i = 0; i < w->Size(); ++i)
|
||||||
{
|
{
|
||||||
try
|
if (i == 10 || i == 14 || i == ResetButton+1 || i == ResetButton+3) // separators
|
||||||
{
|
continue;
|
||||||
delete (*w)[i].first;
|
delete (*w)[i].first;
|
||||||
delete (*w)[i].second;
|
delete (*w)[i].second;
|
||||||
}
|
|
||||||
catch (List::InvalidItem) { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w->SetTitle("");
|
w->SetTitle("");
|
||||||
@@ -347,11 +345,9 @@ void SearchEngine::Prepare()
|
|||||||
|
|
||||||
for (size_t i = 0; i < 17; ++i)
|
for (size_t i = 0; i < 17; ++i)
|
||||||
{
|
{
|
||||||
try
|
if (i == 10 || i == 14) // separators
|
||||||
{
|
continue;
|
||||||
w->at(i).first = new Buffer();
|
(*w)[i].first = new Buffer();
|
||||||
}
|
|
||||||
catch (List::InvalidItem) { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*w->at(0).first << fmtBold << "Any: " << fmtBoldEnd << ' ';
|
*w->at(0).first << fmtBold << "Any: " << fmtBoldEnd << ' ';
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ void ReadConfiguration(ncmpcpp_config &conf)
|
|||||||
{
|
{
|
||||||
conf.progressbar = TO_WSTRING(v);
|
conf.progressbar = TO_WSTRING(v);
|
||||||
if (conf.progressbar.length() != 2)
|
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)
|
else if (cl.find("default_tag_editor_pattern") != std::string::npos)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "charset.h"
|
#include "charset.h"
|
||||||
#include "conv.h"
|
#include "conv.h"
|
||||||
|
#include "error.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
MPD::Song::Song(mpd_Song *s, bool copy_ptr) : itsSong(s ? s : mpd_newSong()),
|
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;
|
--braces;
|
||||||
}
|
}
|
||||||
if (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()
|
void MPD::Song::SetHashAndSlash()
|
||||||
|
|||||||
@@ -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::vector< std::pair<char, std::string> > tags;
|
||||||
std::string file = s.GetName().substr(0, s.GetName().rfind("."));
|
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);
|
||||||
tags.push_back(std::make_pair(mask.at(i+1), ""));
|
i = mask.find("%");
|
||||||
mask = mask.substr(i+2);
|
if (!mask.empty())
|
||||||
i = mask.find("%");
|
separators.push_back(mask.substr(0, i));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
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)
|
for (std::vector< std::pair<char, std::string> >::iterator it = tags.begin(); it != tags.end(); ++it)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
using namespace NCurses;
|
using namespace NCurses;
|
||||||
@@ -95,7 +96,7 @@ Window::Window(size_t startx,
|
|||||||
|| itsStartY > size_t(LINES)
|
|| itsStartY > size_t(LINES)
|
||||||
|| itsWidth+itsStartX > size_t(COLS)
|
|| itsWidth+itsStartX > size_t(COLS)
|
||||||
|| itsHeight+itsStartY > size_t(LINES))
|
|| itsHeight+itsStartY > size_t(LINES))
|
||||||
throw BadSize();
|
FatalError("Constructed window is bigger than terminal size!");
|
||||||
|
|
||||||
if (itsBorder != brNone)
|
if (itsBorder != brNone)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -463,12 +463,6 @@ namespace NCurses
|
|||||||
static size_t Length(const std::wstring &ws);
|
static size_t Length(const std::wstring &ws);
|
||||||
|
|
||||||
protected:
|
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)
|
/// Sets colors of window (interal use only)
|
||||||
/// @param fg foregound color
|
/// @param fg foregound color
|
||||||
/// @param bg background color
|
/// @param bg background color
|
||||||
|
|||||||
Reference in New Issue
Block a user