diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 47d455dd55be855e4cc691c32f687f723d9247ee (patch) | |
tree | 52e236aaa2576bdb3840ebede26619692fed6d7d /kgamma/xf86gammacfg/xf86gammacfg.cpp | |
download | tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kgamma/xf86gammacfg/xf86gammacfg.cpp')
-rw-r--r-- | kgamma/xf86gammacfg/xf86gammacfg.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/kgamma/xf86gammacfg/xf86gammacfg.cpp b/kgamma/xf86gammacfg/xf86gammacfg.cpp new file mode 100644 index 00000000..db98a8fb --- /dev/null +++ b/kgamma/xf86gammacfg/xf86gammacfg.cpp @@ -0,0 +1,138 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Wed Aug 7 18:11:19 CEST 2002 + copyright : (C) 2002 by Michael v.Ostheim + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include <stdio.h> + +#include <stdlib.h> + +#include <iostream> +#include <fstream> +#include <string> +#include <vector> + +#include <config.h> + +#ifdef HAVE_SSTREAM +#include <sstream> +#else +#include <strstream.h> +#define istringstream istrstream +#endif + +using namespace std; + +int main(int argc, char *argv[]) +{ + + bool cpyonly, secmon, success; + + cpyonly = secmon = success = false; + + if ( !((argc-1) % 3) ) { + int Screen = 0; + int ScreenCount = (argc-1) / 3; + + // First, search for XF86Config or xorg.conf + vector <string> searchPaths; + searchPaths.push_back("/etc/X11/XF86Config-4"); + searchPaths.push_back("/etc/X11/XF86Config"); + searchPaths.push_back("/etc/XF86Config"); + searchPaths.push_back("/usr/X11R6/etc/X11/XF86Config-4"); + searchPaths.push_back("/usr/X11R6/etc/X11/XF86Config"); + searchPaths.push_back("/usr/X11R6/lib/X11/XF86Config-4"); + searchPaths.push_back("/usr/X11R6/lib/X11/XF86Config"); + + searchPaths.push_back("/etc/X11/xorg.conf-4"); + searchPaths.push_back("/etc/X11/xorg.conf"); + searchPaths.push_back("/etc/xorg.conf"); + searchPaths.push_back("/usr/X11R6/etc/X11/xorg.conf-4"); + searchPaths.push_back("/usr/X11R6/etc/X11/xorg.conf"); + searchPaths.push_back("/usr/X11R6/lib/X11/xorg.conf-4"); + searchPaths.push_back("/usr/X11R6/lib/X11/xorg.conf"); + + std::vector<string>::iterator it = searchPaths.begin(); + for (; it != searchPaths.end(); ++it ) { + //Try to open file + std::ifstream in( (*it).c_str() ); + + if ( in.is_open() ) { + std::ofstream out( ( (*it) + ".tmp" ).c_str() ); + if ( out.is_open() ) { + std::string s, buf; + std::vector<string> words; + + while (getline(in, s,'\n')) { + if (!cpyonly) { + words.clear(); + std::istringstream ss(s.c_str()); + while (ss >> buf) words.push_back(buf); + + if ( !words.empty() ) { + if ( words[0] == "Section" && words.size() > 1 ) { + if ( words[1] == "\"Monitor\"" ) { + secmon = true; + out << s << endl; + continue; + } + } + if ( secmon ) { + if ( words[0] == "Gamma" ) { + out << " Gamma " << argv[3*Screen+1] << " " << \ + argv[3*Screen+2]<< " " << argv[3*Screen+3]; + out << " # created by KGamma" << endl; + cpyonly = success = ( ++Screen == ScreenCount ); + secmon = false; + continue; + } + if ( words[0] == "EndSection" ) { + out << " Gamma " << argv[3*Screen+1] << " " << \ + argv[3*Screen+2]<< " " << argv[3*Screen+3]; + out << " # created by KGamma" << endl; + out << s << endl; + cpyonly = success = ( ++Screen == ScreenCount ); + secmon = false; + continue; + } + } + } + } + out << s << endl; + } //endwhile + + in.close(); + out.close(); + + if ( success ) { + rename( (*it).c_str(),(*it + ".kgammaorig").c_str() ); + rename( (*it + ".tmp").c_str(),(*it).c_str() ); + } + else remove( (*it + ".tmp").c_str() ); + break; + } + } + } + } + if ( !success ) + cerr << "Usage: xf86gammacfg RGAMMA GGAMMA " \ + "BGAMMA [RGAMMA GGAMMA BGAMMA [...]]" << endl; + + return success; +} + +#ifdef istringstream +#undef istringstream +#endif |