]> pilppa.org Git - lib1wire.git/blobdiff - src/W1Util.cc
Optimization for year and monthly data calculation.
[lib1wire.git] / src / W1Util.cc
index c5773bc781f2cdb805c770ace2d1e9389b2a32ce..a9fc351b9755a28e3cd18c17a94f693127108aea 100644 (file)
@@ -63,7 +63,7 @@ char *W1Util::parse_directory_path(const char *file_path) {
        return ret_val;
 }
 
-bool W1Util::mkdirs(char *path) {
+bool W1Util::mkdirs(const char *path) {
        bool    ret_val;
        char    *p;
        int     err_flg;
@@ -71,16 +71,17 @@ bool W1Util::mkdirs(char *path) {
        ret_val = true;
        if (path != NULL) {
                // go through each directory one by and and create if not exist
-               for (p = path; *p; p++) {
+               for (p = (char *)path; *p; p++) {
                    if ((p != path) &&
                        ((*p == '/') ||
                         (*p == '\\'))) {
                                *p = '\0';
-                               // test whether directory exist and is writable
-                               if (access(path, F_OK)) {
-                                       log_debug("trying to create directory: %s\n", path);
+                               // if dir does not exist, create it
+                               if (access(path, F_OK) != 0) {
+                                       //log_debug("trying to create directory: %s\n", path);
                                        err_flg = mkdir(path, S_IRWXU);
                                        if (err_flg != 0) {
+                                               log_error("Could not create directory: %s\n", path);
                                                ret_val = false;
                                                break;
                                        }
@@ -89,11 +90,12 @@ bool W1Util::mkdirs(char *path) {
                        }
                }
                if (ret_val == true) {
-                       // test also the existense of whole directory
-                       if (access(path, F_OK)) {
-                               log_debug("trying to create directory: %s\n", path);
+                       // if dir does not exist, create it
+                       if (access(path, F_OK) != 0) {
+                               //log_debug("trying to create directory: %s\n", path);
                                err_flg = mkdir(path, S_IRWXU);
                                if (err_flg != 0) {
+                                       log_error("Could not create directory: %s\n", path);
                                        ret_val = false;
                                }
                        }
@@ -108,9 +110,7 @@ bool W1Util::mkdirs(char *path) {
 
 std::ofstream *W1Util::open_for_writing(const char *f_path) {
        char            *d_path;
-       char            *p;
        size_t          b_count;
-       int             ii;
        ofstream        *ret_val;
        bool            b_flg;
 
@@ -231,7 +231,7 @@ vector<string> W1Util::get_subdirectories(const string& path) {
        bool            bool_flg;
        vector<string>  ret_val;
 
-       log_debug("scanning path: %s\n", path.c_str());
+       //log_debug("scanning path: %s\n", path.c_str());
        errno   = 0;
        if (path.empty() == false) {
                dir     = opendir(path.c_str());
@@ -296,34 +296,3 @@ Date W1Util::parse_date_str(string date_str) {
        ss >>ret_val.year >>c >>ret_val.month >>c >>ret_val.day >>ret_val.hour >>c >>ret_val.min >>c >>ret_val.sec;
        return ret_val;
 }
-
-Data *W1Util::parse_data_line(const string& dataline) {
-       stringstream    ss(dataline);
-       string          item;
-       double          val;
-       Data            *ret_val;
-       int             ii;
-       bool            suc_flg;
-       vector<double>  v;
-       Date            date;
-
-       ii      = 0;
-       while(getline(ss, item, '|')) {
-               if (ii == 0) {
-                       // parse date
-                       date    = parse_date_str(item);
-               }
-               // skip the device type and device id fields
-               // TODO: store device type and id to own file
-               else if (ii >= 3) {
-                       suc_flg = string_to_number<double>(val, item, dec);
-                       if (suc_flg) {
-                               //log_debug("adding number: %f\n", val);
-                               v.push_back(val);
-                       }
-               }
-               ii++;
-       }
-       ret_val = new Data(v, &date);
-       return ret_val;
-}