]> git.tdb.fi Git - libs/core.git/commitdiff
Fix references to deprecated functions
authorMikko Rasa <tdb@tdb.fi>
Mon, 3 Jun 2019 11:31:17 +0000 (14:31 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 3 Jun 2019 11:31:17 +0000 (14:31 +0300)
13 files changed:
examples/grep.cpp
examples/ls.cpp
examples/z.cpp
source/core/windows/semaphore.cpp
source/fs/android/dir_location.cpp
source/fs/dir.cpp
source/fs/osx/dir_location.cpp
source/fs/unix/dir_location.cpp
source/fs/windows/dir_location.cpp
tests/datetime.cpp
tests/pipe.cpp
tests/thread.cpp
tests/timezone.cpp

index c87ee72171615ec8056adcf687f8f0e74d78b621..66d70f3a486fe6801b7b95ad970cf1a554a48726 100644 (file)
@@ -9,19 +9,13 @@ using namespace Msp;
 int main(int argc, char **argv)
 {
        bool debug = false;
 int main(int argc, char **argv)
 {
        bool debug = false;
+       string re_str;
        GetOpt getopt;
        getopt.add_option('d', "debug", debug, GetOpt::NO_ARG);
        GetOpt getopt;
        getopt.add_option('d', "debug", debug, GetOpt::NO_ARG);
+       getopt.add_argument("regex", re_str, GetOpt::REQUIRED_ARG);
        getopt(argc, argv);
 
        getopt(argc, argv);
 
-       const vector<string> &args = getopt.get_args();
-
-       if(args.empty())
-       {
-               cerr<<"Usage: "<<argv[0]<<" <regex>\n";
-               return 1;
-       }
-
-       Regex regex(args[0]);
+       Regex regex(re_str);
        if(debug)
                cout<<regex.disassemble();
        string line;
        if(debug)
                cout<<regex.disassemble();
        string line;
index a31c19bf7240364d514f95b73161b2e8bb3b56ae..3e873180d57bf04b72e53b40281bf9088693a2c2 100644 (file)
@@ -31,9 +31,9 @@ Ls::Ls(int argc, char **argv):
 {
        GetOpt getopt;
        getopt.add_option('l', "long", long_format, GetOpt::NO_ARG);
 {
        GetOpt getopt;
        getopt.add_option('l', "long", long_format, GetOpt::NO_ARG);
+       getopt.add_argument("file", args, GetOpt::OPTIONAL_ARG);
        getopt(argc, argv);
 
        getopt(argc, argv);
 
-       args = getopt.get_args();
        if(args.empty())
                args.push_back(".");
 }
        if(args.empty())
                args.push_back(".");
 }
index 54f0eb7d336249c010ccb5911103f8bb88b7ee4a..d98392cfeaa92d18c102607ab171c3d1bed444d1 100644 (file)
@@ -26,13 +26,14 @@ public:
 Z::Z(int argc, char **argv):
        input_file(0)
 {
 Z::Z(int argc, char **argv):
        input_file(0)
 {
+       string input_fn;
        GetOpt getopt;
        getopt.add_option('d', "decompress", decompress, GetOpt::NO_ARG);
        GetOpt getopt;
        getopt.add_option('d', "decompress", decompress, GetOpt::NO_ARG);
+       getopt.add_argument("filename", input_fn, GetOpt::OPTIONAL_ARG);
        getopt(argc, argv);
 
        getopt(argc, argv);
 
-       const vector<string> &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<IO::Base *>(input_file) : static_cast<IO::Base *>(&IO::cin));
        output = &IO::cout;
 
        input = (input_file ? static_cast<IO::Base *>(input_file) : static_cast<IO::Base *>(&IO::cin));
        output = &IO::cout;
index 749d99313c3f356fa042b8a8a77a54fcb5cc91ff..c81f815a2ad4bbcb50897f1bb1a327fdd6ef1df5 100644 (file)
@@ -1,6 +1,6 @@
 #include <windows.h>
 #include <msp/core/systemerror.h>
 #include <windows.h>
 #include <msp/core/systemerror.h>
-#include <msp/time/units.h>
+#include <msp/time/timedelta.h>
 #include "semaphore.h"
 
 namespace Msp {
 #include "semaphore.h"
 
 namespace Msp {
index f9e0ea58d4760386ef009a954b868a41141611af..da6b5c70ac47c28093e530e962d0c4f580a212bb 100644 (file)
@@ -13,6 +13,11 @@ Path get_home_dir()
 }
 
 Path get_user_data_dir(const string &)
 }
 
 Path get_user_data_dir(const string &)
+{
+       return get_user_data_dir();
+}
+
+Path get_user_data_dir()
 {
        Android::MainThread *thread = reinterpret_cast<Android::MainThread *>(Application::get_data());
        return thread->get_internal_data_path();
 {
        Android::MainThread *thread = reinterpret_cast<Android::MainThread *>(Application::get_data());
        return thread->get_internal_data_path();
index bd9eaa59fe06ad933209f5331b12e86a0ae6a0a5..8625b783ef464357439833a0d3685175ab40041a 100644 (file)
@@ -130,18 +130,16 @@ list<string> list_filtered(const Path &path, const string &filter)
        return result;
 }
 
        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);
 
 
        Path dir = get_bin_dir(argv0);
 
@@ -156,58 +154,46 @@ Path get_sys_conf_dir(const string &argv0)
                return dir;
 }
 
                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")
 
        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;
 }
 
        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")
 
        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;
 }
 
        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<Path> &paths)
 {
        for(list<Path>::const_iterator i=paths.begin(); i!=paths.end(); ++i)
 Path path_lookup(const string &name, const list<Path> &paths)
 {
        for(list<Path>::const_iterator i=paths.begin(); i!=paths.end(); ++i)
index 7ce89f7a33de31bdf83e76d31c3da513811ca437..7e9985b008228d25bce53ae5331839d4e933c428 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/application.h>
 #include "dir.h"
 
 using namespace std;
 #include "dir.h"
 
 using namespace std;
@@ -22,8 +23,17 @@ Path get_home_dir()
        return ".";
 }
 
        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)
        char buf[1024];
        unsigned len = get_application_support_dir(buf, sizeof(buf));
        if(len)
index e81b8b97a55bba9b5fcc5e806018b494da84f3ac..804229ebed253f967e593e11c0f91167108f4020 100644 (file)
@@ -1,4 +1,5 @@
 #include <cstdlib>
 #include <cstdlib>
+#include <msp/core/application.h>
 #include "dir.h"
 
 using namespace std;
 #include "dir.h"
 
 using namespace std;
@@ -14,10 +15,17 @@ Path get_home_dir()
        return ".";
 }
 
        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())
        if(appname.empty())
-               throw invalid_argument("get_user_data_dir");
+               throw logic_error("no application name");
+
        return get_home_dir()/("."+appname);
 }
 
        return get_home_dir()/("."+appname);
 }
 
index ea542be3a75abcf87b68fec82edc83734bfa93a6..a1d24de672e7c51857dd361fcbd9fbb3877f7c8f 100644 (file)
@@ -1,4 +1,5 @@
 #include <shlobj.h>
 #include <shlobj.h>
+#include <msp/core/application.h>
 #include "dir.h"
 
 using namespace std;
 #include "dir.h"
 
 using namespace std;
@@ -14,10 +15,17 @@ Path get_home_dir()
        return ".";
 }
 
        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())
        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;
        char datadir[MAX_PATH];
        if(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, datadir)==S_OK)
                return Path(datadir)/appname;
index 45a869984453909ada6e4415cec06001a95e97e2..fafd6d5413d172aec8f63772c1c6eb0bc607c97e 100644 (file)
@@ -1,7 +1,7 @@
 #include <msp/time/datetime.h>
 #include <msp/time/datetime.h>
+#include <msp/time/timedelta.h>
 #include <msp/time/timestamp.h>
 #include <msp/time/timezone.h>
 #include <msp/time/timestamp.h>
 #include <msp/time/timezone.h>
-#include <msp/time/units.h>
 #include <msp/test/test.h>
 
 using namespace std;
 #include <msp/test/test.h>
 
 using namespace std;
index 0310bdfc7f88df47abfbf4f92e9935de57ab9647..f9aa5bc1d816c39037132e1adef023a943146ff6 100644 (file)
@@ -1,7 +1,7 @@
 #include <msp/core/thread.h>
 #include <msp/io/pipe.h>
 #include <msp/io/poll.h>
 #include <msp/core/thread.h>
 #include <msp/io/pipe.h>
 #include <msp/io/poll.h>
-#include <msp/time/units.h>
+#include <msp/time/timedelta.h>
 #include <msp/test/test.h>
 
 using namespace Msp;
 #include <msp/test/test.h>
 
 using namespace Msp;
index 9529af85caacaf9e85fba0ad867fe0a2338a9148..7f925027112b112ab73eca3ccc73163a99646aa4 100644 (file)
@@ -1,7 +1,7 @@
 #include <list>
 #include <vector>
 #include <msp/core/thread.h>
 #include <list>
 #include <vector>
 #include <msp/core/thread.h>
-#include <msp/time/units.h>
+#include <msp/time/timedelta.h>
 #include <msp/time/utils.h>
 #include <msp/test/test.h>
 
 #include <msp/time/utils.h>
 #include <msp/test/test.h>
 
index c59cdd3abcb5874cef3019159be671671807edce..1b4a72f049d9ad84ae1da12639aa6c2db307b0d3 100644 (file)
@@ -1,4 +1,4 @@
-#include <msp/time/units.h>
+#include <msp/time/timedelta.h>
 #include <msp/time/timezone.h>
 #include <msp/test/test.h>
 
 #include <msp/time/timezone.h>
 #include <msp/test/test.h>