aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/fbrun/FbRun.cc10
-rw-r--r--util/fbrun/main.cc6
-rw-r--r--util/fbsetbg4
-rw-r--r--util/fluxbox-update_configs.cc37
4 files changed, 39 insertions, 18 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc
index f98a02e..3bf83aa 100644
--- a/util/fbrun/FbRun.cc
+++ b/util/fbrun/FbRun.cc
@@ -21,11 +21,11 @@
21 21
22#include "FbRun.hh" 22#include "FbRun.hh"
23 23
24#include "App.hh" 24#include "FbTk/App.hh"
25#include "EventManager.hh" 25#include "FbTk/EventManager.hh"
26#include "Color.hh" 26#include "FbTk/Color.hh"
27#include "KeyUtil.hh" 27#include "FbTk/KeyUtil.hh"
28#include "FileUtil.hh" 28#include "FbTk/FileUtil.hh"
29 29
30#ifdef HAVE_CONFIG_H 30#ifdef HAVE_CONFIG_H
31#include "config.h" 31#include "config.h"
diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc
index 0bb8456..edb88ff 100644
--- a/util/fbrun/main.cc
+++ b/util/fbrun/main.cc
@@ -20,9 +20,9 @@
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22#include "FbRun.hh" 22#include "FbRun.hh"
23#include "App.hh" 23#include "FbTk/App.hh"
24#include "StringUtil.hh" 24#include "FbTk/StringUtil.hh"
25#include "Color.hh" 25#include "FbTk/Color.hh"
26 26
27#ifdef XINERAMA 27#ifdef XINERAMA
28extern "C" { 28extern "C" {
diff --git a/util/fbsetbg b/util/fbsetbg
index a12d427..47aa33b 100644
--- a/util/fbsetbg
+++ b/util/fbsetbg
@@ -308,6 +308,7 @@ while [ $# -gt 0 ]; do
308 remember=false 308 remember=false
309 break 309 break
310 fi 310 fi
311 ignore_missing_wallpaper=true
311 style="style" 312 style="style"
312 shift ;; 313 shift ;;
313 -Z) 314 -Z)
@@ -521,6 +522,9 @@ fi
521 522
522 523
523if [ ! -r "$wallpaper" ]; then 524if [ ! -r "$wallpaper" ]; then
525 if [ "$ignore_missing_wallpaper" == "true" ]; then
526 exit 0
527 fi
524 message "Can't find wallpaper $wallpaper" 528 message "Can't find wallpaper $wallpaper"
525 exit 1 529 exit 1
526fi 530fi
diff --git a/util/fluxbox-update_configs.cc b/util/fluxbox-update_configs.cc
index 43dd1f2..77b3ff7 100644
--- a/util/fluxbox-update_configs.cc
+++ b/util/fluxbox-update_configs.cc
@@ -23,7 +23,7 @@
23#include "../src/FbTk/Resource.hh" 23#include "../src/FbTk/Resource.hh"
24#include "../src/FbTk/StringUtil.hh" 24#include "../src/FbTk/StringUtil.hh"
25 25
26#include "../src/defaults.hh" 26#include "defaults.hh"
27 27
28#ifdef HAVE_CONFIG_H 28#ifdef HAVE_CONFIG_H
29#include "config.h" 29#include "config.h"
@@ -44,6 +44,8 @@
44 #include <string.h> 44 #include <string.h>
45#endif 45#endif
46 46
47#include <sys/stat.h>
48
47#include <iostream> 49#include <iostream>
48#include <fstream> 50#include <fstream>
49#include <set> 51#include <set>
@@ -63,8 +65,8 @@ using std::list;
63using std::exit; 65using std::exit;
64using std::getenv; 66using std::getenv;
65 67
66string read_file(string filename); 68string read_file(const string& filename);
67void write_file(string filename, string &contents); 69void write_file(const string& filename, const string &contents);
68void save_all_files(); 70void save_all_files();
69 71
70int run_updates(int old_version, FbTk::ResourceManager &rm) { 72int run_updates(int old_version, FbTk::ResourceManager &rm) {
@@ -455,18 +457,28 @@ int main(int argc, char **argv) {
455 return 0; 457 return 0;
456} 458}
457 459
458static set<string> modified_files; 460namespace {
461
462set<string> modified_files;
459// we may want to put a size limit on this cache, so it doesn't grow too big 463// we may want to put a size limit on this cache, so it doesn't grow too big
460static map<string,string> file_cache; 464map<string,string> file_cache;
465
466};
461 467
462// returns the contents of the file given, either from the cache or by reading 468// returns the contents of the file given, either from the cache or by reading
463// the file from disk 469// the file from disk
464string read_file(string filename) { 470string read_file(const string& filename) {
465 // check if we already have the file in memory 471 // check if we already have the file in memory
466 map<string,string>::iterator it = file_cache.find(filename); 472 map<string,string>::iterator it = file_cache.find(filename);
467 if (it != file_cache.end()) 473 if (it != file_cache.end())
468 return it->second; 474 return it->second;
469 475
476 struct stat s;
477 stat(filename.c_str(), &s);
478
479 if (! (s.st_mode & S_IFREG))
480 return "";
481
470 // nope, we'll have to read the file 482 // nope, we'll have to read the file
471 ifstream infile(filename.c_str()); 483 ifstream infile(filename.c_str());
472 string whole_file = ""; 484 string whole_file = "";
@@ -474,10 +486,15 @@ string read_file(string filename) {
474 if (!infile) // failed to open file 486 if (!infile) // failed to open file
475 return whole_file; 487 return whole_file;
476 488
489 string linebuffer;
477 while (!infile.eof()) { 490 while (!infile.eof()) {
478 string linebuffer;
479
480 getline(infile, linebuffer); 491 getline(infile, linebuffer);
492
493 // check if we read something at all. if its 0, its a strange file
494 // (eg a directory) or we are at the end
495 if (infile.gcount() == 0) {
496 break;
497 }
481 whole_file += linebuffer + "\n"; 498 whole_file += linebuffer + "\n";
482 } 499 }
483 infile.close(); 500 infile.close();
@@ -488,7 +505,7 @@ string read_file(string filename) {
488 505
489#ifdef NOT_USED 506#ifdef NOT_USED
490// remove the file from the cache, writing to disk if it's been changed 507// remove the file from the cache, writing to disk if it's been changed
491void forget_file(string filename) { 508void forget_file(const string& filename) {
492 map<string,string>::iterator cache_it = file_cache.find(filename); 509 map<string,string>::iterator cache_it = file_cache.find(filename);
493 // check if we knew about the file to begin with 510 // check if we knew about the file to begin with
494 if (cache_it == file_cache.end()) 511 if (cache_it == file_cache.end())
@@ -511,7 +528,7 @@ void forget_file(string filename) {
511 528
512// updates the file contents in the cache and marks the file as modified so it 529// updates the file contents in the cache and marks the file as modified so it
513// gets saved later 530// gets saved later
514void write_file(string filename, string &contents) { 531void write_file(const string& filename, const string &contents) {
515 modified_files.insert(filename); 532 modified_files.insert(filename);
516 file_cache[filename] = contents; 533 file_cache[filename] = contents;
517} 534}