From: Mikko Rasa Date: Mon, 3 Jun 2019 11:31:17 +0000 (+0300) Subject: Fix references to deprecated functions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9e98607f1b6a2c757de51fca6c1649cbdf536597;p=libs%2Fcore.git Fix references to deprecated functions --- diff --git a/examples/grep.cpp b/examples/grep.cpp index c87ee72..66d70f3 100644 --- a/examples/grep.cpp +++ b/examples/grep.cpp @@ -9,19 +9,13 @@ using namespace Msp; int main(int argc, char **argv) { bool debug = false; + string re_str; GetOpt getopt; getopt.add_option('d', "debug", debug, GetOpt::NO_ARG); + getopt.add_argument("regex", re_str, GetOpt::REQUIRED_ARG); getopt(argc, argv); - const vector &args = getopt.get_args(); - - if(args.empty()) - { - cerr<<"Usage: "<\n"; - return 1; - } - - Regex regex(args[0]); + Regex regex(re_str); if(debug) cout< &args = getopt.get_args(); - if(!args.empty()) - input_file = new IO::File(args[0]); + if(!input_fn.empty()) + input_file = new IO::File(input_fn); input = (input_file ? static_cast(input_file) : static_cast(&IO::cin)); output = &IO::cout; diff --git a/source/core/windows/semaphore.cpp b/source/core/windows/semaphore.cpp index 749d993..c81f815 100644 --- a/source/core/windows/semaphore.cpp +++ b/source/core/windows/semaphore.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include "semaphore.h" namespace Msp { diff --git a/source/fs/android/dir_location.cpp b/source/fs/android/dir_location.cpp index f9e0ea5..da6b5c7 100644 --- a/source/fs/android/dir_location.cpp +++ b/source/fs/android/dir_location.cpp @@ -13,6 +13,11 @@ Path get_home_dir() } Path get_user_data_dir(const string &) +{ + return get_user_data_dir(); +} + +Path get_user_data_dir() { Android::MainThread *thread = reinterpret_cast(Application::get_data()); return thread->get_internal_data_path(); diff --git a/source/fs/dir.cpp b/source/fs/dir.cpp index bd9eaa5..8625b78 100644 --- a/source/fs/dir.cpp +++ b/source/fs/dir.cpp @@ -130,18 +130,16 @@ list list_filtered(const Path &path, const string &filter) return result; } -Path get_user_data_dir() +Path get_sys_conf_dir(const string &) { - const string &name = Application::get_name(); - if(name.empty()) - throw logic_error("application name not known"); - return get_user_data_dir(name); + return get_sys_conf_dir(); } -Path get_sys_conf_dir(const string &argv0) +Path get_sys_conf_dir() { - if(argv0.empty()) - throw invalid_argument("get_sys_conf_dir"); + const char *argv0 = Application::get_argv0(); + if(!argv0) + throw logic_error("no startup command"); Path dir = get_bin_dir(argv0); @@ -156,58 +154,46 @@ Path get_sys_conf_dir(const string &argv0) return dir; } -Path get_sys_conf_dir() +Path get_sys_data_dir(const string &, const string &) { - const char *argv0 = Application::get_argv0(); - if(!argv0) - throw logic_error("no startup command"); - return get_sys_conf_dir(argv0); + return get_sys_data_dir(); } -Path get_sys_data_dir(const string &argv0, const string &appname) +Path get_sys_data_dir() { - if(argv0.empty() || appname.empty()) - throw invalid_argument("get_sys_data_dir"); + const char *argv0 = Application::get_argv0(); + if(!argv0) + throw logic_error("no startup command"); Path dir = get_bin_dir(argv0); if(dir[-1]=="bin" || dir[-1]=="sbin") - return dir/".."/"share"/appname; + return dir/".."/"share"/Application::get_name(); else if(dir[-1]=="MacOS") return dir/".."/"Resources"; else return dir; } -Path get_sys_data_dir() +Path get_sys_lib_dir(const string &, const string &) { - const char *argv0 = Application::get_argv0(); - if(!argv0) - throw logic_error("no startup command"); - return get_sys_data_dir(argv0, Application::get_name()); + return get_sys_lib_dir(); } -Path get_sys_lib_dir(const string &argv0, const string &appname) +Path get_sys_lib_dir() { - if(argv0.empty() || appname.empty()) - throw invalid_argument("get_sys_lib_dir"); + const char *argv0 = Application::get_argv0(); + if(!argv0) + throw logic_error("no startup command"); Path dir = get_bin_dir(argv0); if(dir[-1]=="bin" || dir[-1]=="sbin") - return dir/".."/"lib"/appname; + return dir/".."/"lib"/Application::get_name(); else return dir; } -Path get_sys_lib_dir() -{ - const char *argv0 = Application::get_argv0(); - if(!argv0) - throw logic_error("no startup command"); - return get_sys_lib_dir(argv0, Application::get_name()); -} - Path path_lookup(const string &name, const list &paths) { for(list::const_iterator i=paths.begin(); i!=paths.end(); ++i) diff --git a/source/fs/osx/dir_location.cpp b/source/fs/osx/dir_location.cpp index 7ce89f7..7e9985b 100644 --- a/source/fs/osx/dir_location.cpp +++ b/source/fs/osx/dir_location.cpp @@ -1,3 +1,4 @@ +#include #include "dir.h" using namespace std; @@ -22,8 +23,17 @@ Path get_home_dir() return "."; } -Path get_user_data_dir(const string &appname) +Path get_user_data_dir(const string &) { + return get_user_data_dir(); +} + +Path get_user_data_dir() +{ + const string &appname = Application::get_name(); + if(appname.empty()) + throw logic_error("no application name"); + char buf[1024]; unsigned len = get_application_support_dir(buf, sizeof(buf)); if(len) diff --git a/source/fs/unix/dir_location.cpp b/source/fs/unix/dir_location.cpp index e81b8b9..804229e 100644 --- a/source/fs/unix/dir_location.cpp +++ b/source/fs/unix/dir_location.cpp @@ -1,4 +1,5 @@ #include +#include #include "dir.h" using namespace std; @@ -14,10 +15,17 @@ Path get_home_dir() return "."; } -Path get_user_data_dir(const string &appname) +Path get_user_data_dir(const string &) { + return get_user_data_dir(); +} + +Path get_user_data_dir() +{ + const string &appname = Application::get_name(); if(appname.empty()) - throw invalid_argument("get_user_data_dir"); + throw logic_error("no application name"); + return get_home_dir()/("."+appname); } diff --git a/source/fs/windows/dir_location.cpp b/source/fs/windows/dir_location.cpp index ea542be..a1d24de 100644 --- a/source/fs/windows/dir_location.cpp +++ b/source/fs/windows/dir_location.cpp @@ -1,4 +1,5 @@ #include +#include #include "dir.h" using namespace std; @@ -14,10 +15,17 @@ Path get_home_dir() return "."; } -Path get_user_data_dir(const string &appname) +Path get_user_data_dir(const string &) { + return get_user_data_dir(); +} + +Path get_user_data_dir() +{ + const string &appname = Application::get_name(); if(appname.empty()) - throw invalid_argument("get_user_data_dir"); + throw logic_error("no application name"); + char datadir[MAX_PATH]; if(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, datadir)==S_OK) return Path(datadir)/appname; diff --git a/tests/datetime.cpp b/tests/datetime.cpp index 45a8699..fafd6d5 100644 --- a/tests/datetime.cpp +++ b/tests/datetime.cpp @@ -1,7 +1,7 @@ #include +#include #include #include -#include #include using namespace std; diff --git a/tests/pipe.cpp b/tests/pipe.cpp index 0310bdf..f9aa5bc 100644 --- a/tests/pipe.cpp +++ b/tests/pipe.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include using namespace Msp; diff --git a/tests/thread.cpp b/tests/thread.cpp index 9529af8..7f92502 100644 --- a/tests/thread.cpp +++ b/tests/thread.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/timezone.cpp b/tests/timezone.cpp index c59cdd3..1b4a72f 100644 --- a/tests/timezone.cpp +++ b/tests/timezone.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include