moving some non-portable code to stlplus
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 15 Jun 2010 03:31:48 +0000 (21:31 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 15 Jun 2010 03:31:48 +0000 (21:31 -0600)
src/Main.cc
src/moof/resource.cc
src/moof/resource.hh
src/moof/settings.cc

index 2992ea052a7ded280725439b183a97b8da0c5b0f..8361b39d3dffe7a5e24eda753650e2722aad6092 100644 (file)
 
 #include "../config.h"
 
-#include <cstdlib>             // atexit, getenv
+#include <cstdlib>             // atexit
 #include <exception>
 #include <functional>
 #include <iostream>
 #include <string>
-#include <unistd.h>            // access
+
+#include <stlplus/portability/file_system.hpp>
+#include <stlplus/portability/subprocesses.hpp>
 
 #include <moof/log.hh>
 #include <moof/modal_dialog.hh>
@@ -104,12 +106,13 @@ std::string Main::getSearchPath()
        // 1. YOINK_DATADIR (environment)
        // 2. YOINK_DATADIR (configure)
        
-       std::string path;
+       std::string                     path;
+       stlplus::env_vector     environment;
 
-       char* dataDir = getenv("YOINK_DATADIR");
-       if (dataDir)
+       std::string datadir = environment["YOINK_DATADIR"];
+       if (!datadir.empty())
        {
-               path += dataDir;
+               path += datadir;
                path += ":";
        }
        path += YOINK_DATADIR;
@@ -128,16 +131,18 @@ std::string Main::getConfigPath()
        std::string path("yoinkrc");
        moof::resource::find(path);
 
+       stlplus::env_vector environment;
+
 #if !defined(_WIN32)
        path += ":/etc/yoinkrc";
 #endif
        path += ":$HOME/.yoinkrc";
 
-       char* configFile = getenv("YOINKRC");
-       if (configFile)
+       std::string rc_file = environment["YOINKRC"];
+       if (!rc_file.empty())
        {
                path += ":";
-               path += configFile;
+               path += rc_file;
        }
 
        return path;
@@ -194,28 +199,22 @@ void Main::printUsage()
 
 void Main::printInfo(int argc, char* argv[])
 {
-       std::string assets;
-       std::string datadir;
-       std::string config;
+       stlplus::env_vector environment;
 
+       std::string assets;
        assets.assign(YOINK_DATADIR);
-       int accessible = access(assets.c_str(), R_OK);
-       if (accessible != 0) assets += " (no access)";
+       if (!stlplus::file_readable(assets)) assets += " (no access)";
 
-       char* temp = getenv("YOINK_DATADIR");
-       if (temp)
+       std::string datadir = environment["YOINK_DATADIR"];
+       if (!datadir.empty())
        {
-               datadir = temp;
-               accessible = access(temp, R_OK);
-               if (accessible != 0) datadir += " (no access)";
+               if (!stlplus::folder_readable(datadir)) datadir += " (no access)";
        }
 
-       temp = getenv("YOINKRC");
-       if (temp)
+       std::string rc_file = environment["YOINKRC"];
+       if (!rc_file.empty())
        {
-               config = temp;
-               accessible = access(temp, R_OK);
-               if (accessible != 0) config += " (no access)";
+               if (!stlplus::file_readable(rc_file)) rc_file += " (no access)";
        }
 
        std::cout << "   Executable: " << argv[0] << std::endl
@@ -259,7 +258,7 @@ void Main::printInfo(int argc, char* argv[])
                          << "-"
 #endif
                          << "threads" << std::endl
-                         << "      YOINKRC: " << config << std::endl
+                         << "      YOINKRC: " << rc_file << std::endl
                          << "YOINK_DATADIR: " << datadir << std::endl;
 }
 
@@ -372,84 +371,17 @@ int main(int argc, char* argv[])
        if (asset) asset->cool();
        else moof::log_warning("no asset obtained!!");
 
-       moof::timer reloadTimer(
-                       boost::bind(&moof::resource::reload_as_needed),
-                       SCALAR(2.0),
-                       moof::timer::repeat);
-
-       //for (;;)
-       //{
-               //myAsset.get()->cool();
-               //moof::resource::reload_as_needed();
-               //sleep(1);
-       //}
-
-       //return 0;
-
-       moof::resolver_task task("4950", "lappy");
-       task.run();
+       //moof::timer reloadTimer(
+                       //boost::bind(&moof::resource::reload_as_needed),
+                       //SCALAR(2.0),
+                       //moof::timer::repeat);
 
-       int i = task.wait();
-       moof::log_warning("task ended with code:", i);
-
-       std::vector<moof::socket::address>::const_iterator it;
-       for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
+       for (;;)
        {
-               moof::socket::address addr = *it;
-
-               moof::log_info("address:", addr, "(", addr.type(), ")");
+               if (myAsset) myAsset.get()->cool();
+               moof::resource::reload_as_needed();
+               sleep(1);
        }
-
-       //ASSERT(5 == 8 && "uh oh that's not right");
-       
-
-       std::vector<uint8_t> hi;
-       for (int a = 0; a < 4000; a++)
-       {
-               hi.push_back(a);
-       }
-
-       moof::log_info("array size:", hi.size());
-       moof::packet packet;
-       packet << hi;
-
-       //for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
-       //{
-               //moof::socket sock(*it);
-               moof::socket sock(moof::socket::address::broadcast("4950"));
-               //moof::socket sock("4950", "lappy", SOCK_DGRAM);
-               sock.set(SO_BROADCAST, 1);
-               sock.connect();
-
-               //if (sock.isConnected())
-               //{
-                       moof::packet pack;
-                       pack << "hello world";
-                       sock.write(pack);
-                       //sock.write(pack, sock.address());
-                       moof::log_info("sent", pack.size(), "bytes");
-
-                       const char* data = pack.bytes();
-                       for (unsigned i = 0; i < pack.size(); ++i)
-                       {
-                               moof::log_warning("meh:", data[i]);
-                       }
-
-                       char data2[56];
-                       pack.read(data2, 13);
-                       for (int i = 0; i < 13; ++i)
-                       {
-                               moof::log_warning("meh:", data2[i]);
-                       }
-               //}
-               //else
-               //{
-                       //moof::log_error("NOT CONNECTED");
-               //}
-       //}
-
-
-       //return 0;
        
 
        if (argc > 1)
index ac200f7831e380866665bc490a48ed416340a7e7..5cd75360d85d5c8c5041d76da80987bc830cccf0 100644 (file)
@@ -23,7 +23,7 @@
 #include "../config.h"
 #endif
 
-#if USE_HOTLOADING
+#ifdef USE_HOTLOADING
 #include <sys/inotify.h>
 #include <sys/ioctl.h>
 #endif
@@ -45,7 +45,7 @@ static hash<std::string,resource_weakptr,hash_function> resource_table_;
 resource::type_lookup_ptr resource::type_lookup_;
 
 
-#if USE_HOTLOADING
+#ifdef USE_HOTLOADING
 static hash<int,std::string,hash_function> monitor_lookup_;
 static int monitor_fd_ = inotify_init1(IN_NONBLOCK);
 #endif
@@ -54,7 +54,7 @@ int resource::reload_as_needed()
 {
        int num_resources = 0;
 
-#if USE_HOTLOADING
+#ifdef USE_HOTLOADING
        log_info("hotloading?");
        char bytes[BUF_SIZE];
        int num_bytes;
@@ -99,7 +99,7 @@ int resource::reload_as_needed()
 
 resource::~resource()
 {
-#if USE_HOTLOADING
+#ifdef USE_HOTLOADING
        inotify_rm_watch(monitor_fd_, wd_);
 #endif
 }
@@ -128,7 +128,7 @@ resource_ptr resource::load(const std::string& path)
                rsrc->set_loader(path, (*jt).second);
                resource_table_[path] = rsrc;
 
-#if USE_HOTLOADING
+#ifdef USE_HOTLOADING
                int wd = inotify_add_watch(monitor_fd_,
                                path.c_str(), IN_MODIFY);
                rsrc->set_watch_descriptor(wd);
@@ -172,7 +172,7 @@ void resource::reload()
        typeinfo_ = resource->typeinfo_;
        unloader_ = resource->unloader_;
 
-#if USE_HOTLOADING
+#ifdef USE_HOTLOADING
        int wd = inotify_add_watch(monitor_fd_,
                        path_.c_str(), IN_MODIFY);
        set_watch_descriptor(wd);
index 0f797571c3e1266f493f148b098e06594b32cbc2..7616d69c280ecde861e9857c1a1138bd3127a4d8 100644 (file)
@@ -247,7 +247,7 @@ private:
        typedef boost::shared_ptr<type_lookup> type_lookup_ptr;
        static type_lookup_ptr type_lookup_;
 
-#if USE_HOTLOADING
+#ifdef USE_HOTLOADING
        int wd_;
 
        void set_watch_descriptor(int wd)
index 4e026929dd779c8dfbffaa0dfa98b26f15f6a928..11dfe31b7d9b4478af16a457cb1e42863602e0c0 100644 (file)
@@ -9,7 +9,7 @@
 *
 **************************************************************************/
 
-#include <cstdlib>             // getenv
+#include <stlplus/portability/file_system.hpp>
 
 #include "log.hh"
 #include "settings.hh"
@@ -41,8 +41,7 @@ void settings::parse_args(int argc, char* argv[])
                {
                        std::string str;
                        script_[-1].get(str);
-                       log_warning << "invalid option: " << argv[i]
-                                          << ": " << str << std::endl;
+                       log_warning("invalid option", argv[i], "returned", str);
                        script_.clear_stack();
                }
        }
@@ -59,19 +58,10 @@ void settings::load_files(const std::string& path)
 
 void settings::load_files(const std::vector<std::string>& path)
 {
-       std::vector<std::string> copy(path);
-       std::vector<std::string>::iterator it;
-
-#if defined(_WIN32)
-       char* homeDrive = getenv("HOMEDRIVE");
-       char* homePath = getenv("HOMEPATH");
-       std::string home(homeDrive ? homeDrive : "");
-       if (homePath) home += homePath;
-#else
-       char *homePath = getenv("HOME");
-       std::string home(homePath ? homePath : "");
-#endif
+       std::string home = stlplus::folder_home();
 
+       std::vector<std::string>::iterator it;
+       std::vector<std::string> copy(path);
        for (it = copy.begin(); it != copy.end(); ++it)
        {
                if (!home.empty())
This page took 0.029633 seconds and 4 git commands to generate.