From 44f4b0b601a63411095b53951b110af48b3cfbdc Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Sun, 4 Sep 2011 21:05:01 +0000 Subject: Importing xdg-state stuff that I was prototyping. I'm not using ragel because I just plain don't like it. Sorry ragel users, I'm sure it's great, but I really don't like the syntax at all. Not saying this is better, just saying it's understandable. --- util/fbautostart/Makefile.am | 2 +- util/fbautostart/Makefile.old | 5 + util/fbautostart/include/comment.hh | 37 ++++ util/fbautostart/include/dot_desktop.hh | 55 ----- util/fbautostart/include/entry.hh | 37 ++++ util/fbautostart/include/exceptions.hh | 52 +++++ util/fbautostart/include/fbautostart.hh | 147 ------------ util/fbautostart/include/group.hh | 41 ++++ util/fbautostart/include/invalid.hh | 37 ++++ util/fbautostart/include/key.hh | 39 ++++ util/fbautostart/include/machine.hh | 35 +++ util/fbautostart/include/main.hh | 29 +++ util/fbautostart/include/state.hh | 33 +++ util/fbautostart/include/value.hh | 39 ++++ util/fbautostart/include/xdg_autostart.hh | 36 +++ util/fbautostart/include/xdg_model.hh | 37 ++++ util/fbautostart/include/xdg_parse.hh | 32 +++ util/fbautostart/include/xdg_spec.hh | 33 +++ util/fbautostart/src/Makefile.old | 20 ++ util/fbautostart/src/comment.cc | 44 ++++ util/fbautostart/src/dot_desktop.cc | 147 ------------ util/fbautostart/src/entry.cc | 63 ++++++ util/fbautostart/src/fbautostart.cc | 356 ------------------------------ util/fbautostart/src/group.cc | 52 +++++ util/fbautostart/src/invalid.cc | 38 ++++ util/fbautostart/src/key.cc | 55 +++++ util/fbautostart/src/machine.cc | 63 ++++++ util/fbautostart/src/main.cc | 237 ++++++++++++++------ util/fbautostart/src/state.cc | 36 +++ util/fbautostart/src/value.cc | 73 ++++++ util/fbautostart/src/xdg_autostart.cc | 111 ++++++++++ util/fbautostart/src/xdg_model.cc | 26 +++ util/fbautostart/src/xdg_parse.cc | 105 +++++++++ util/fbautostart/src/xdg_spec.cc | 31 +++ 34 files changed, 1415 insertions(+), 768 deletions(-) create mode 100644 util/fbautostart/Makefile.old create mode 100644 util/fbautostart/include/comment.hh delete mode 100644 util/fbautostart/include/dot_desktop.hh create mode 100644 util/fbautostart/include/entry.hh create mode 100644 util/fbautostart/include/exceptions.hh delete mode 100644 util/fbautostart/include/fbautostart.hh create mode 100644 util/fbautostart/include/group.hh create mode 100644 util/fbautostart/include/invalid.hh create mode 100644 util/fbautostart/include/key.hh create mode 100644 util/fbautostart/include/machine.hh create mode 100644 util/fbautostart/include/main.hh create mode 100644 util/fbautostart/include/state.hh create mode 100644 util/fbautostart/include/value.hh create mode 100644 util/fbautostart/include/xdg_autostart.hh create mode 100644 util/fbautostart/include/xdg_model.hh create mode 100644 util/fbautostart/include/xdg_parse.hh create mode 100644 util/fbautostart/include/xdg_spec.hh create mode 100644 util/fbautostart/src/Makefile.old create mode 100644 util/fbautostart/src/comment.cc delete mode 100644 util/fbautostart/src/dot_desktop.cc create mode 100644 util/fbautostart/src/entry.cc delete mode 100644 util/fbautostart/src/fbautostart.cc create mode 100644 util/fbautostart/src/group.cc create mode 100644 util/fbautostart/src/invalid.cc create mode 100644 util/fbautostart/src/key.cc create mode 100644 util/fbautostart/src/machine.cc create mode 100644 util/fbautostart/src/state.cc create mode 100644 util/fbautostart/src/value.cc create mode 100644 util/fbautostart/src/xdg_autostart.cc create mode 100644 util/fbautostart/src/xdg_model.cc create mode 100644 util/fbautostart/src/xdg_parse.cc create mode 100644 util/fbautostart/src/xdg_spec.cc diff --git a/util/fbautostart/Makefile.am b/util/fbautostart/Makefile.am index 9e6639a..2c85234 100644 --- a/util/fbautostart/Makefile.am +++ b/util/fbautostart/Makefile.am @@ -1,4 +1,4 @@ # FBAutoStart automakefile. INCLUDES = -I./include bin_PROGRAMS = fbautostart -fbautostart_SOURCES = src/main.cc src/fbautostart.cc src/dot_desktop.cc +fbautostart_SOURCES = src/comment.cc src/key.cc src/state.cc src/xdg_parse.cc src/entry.cc src/machine.cc src/value.cc src/xdg_spec.cc src/group.cc src/main.cc src/xdg_autostart.cc src/invalid.cc src/Makefile src/xdg_model.cc diff --git a/util/fbautostart/Makefile.old b/util/fbautostart/Makefile.old new file mode 100644 index 0000000..0b0c291 --- /dev/null +++ b/util/fbautostart/Makefile.old @@ -0,0 +1,5 @@ + +all: + rm -rf bin/ + mkdir bin + cd src && make diff --git a/util/fbautostart/include/comment.hh b/util/fbautostart/include/comment.hh new file mode 100644 index 0000000..27d3539 --- /dev/null +++ b/util/fbautostart/include/comment.hh @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef COMMENT_H_ +#define COMMENT_H_ ja + +#include "state.hh" + +class comment : public state { + public: + void leave_state(); + void enter_state(); + void process( char c ); +}; + +extern comment xdg_comment; + +#endif diff --git a/util/fbautostart/include/dot_desktop.hh b/util/fbautostart/include/dot_desktop.hh deleted file mode 100644 index c234061..0000000 --- a/util/fbautostart/include/dot_desktop.hh +++ /dev/null @@ -1,55 +0,0 @@ -/* - * dot_desktop.hh - * - * This file is part of the Fluxbox Autostart ( fbautostart ) - * Utility. - * - * Copyright (C) 2011 by Paul Tagliamonte - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#ifndef _DOT_DESKTOP_H -#define _DOT_DESKTOP_H ohai - -#include - -namespace fbautostart { - class dot_desktop_attr { - public: - std::string attr; - std::string value; - }; - - class dot_desktop { - protected: - std::vector * attr; - std::string file; - std::string id; - public: - dot_desktop( std::string s, std::string id ); - void load(); - std::string getAttr( std::string sx ); - bool validate(); - std::string getFile(); - std::string getID(); - }; -} -#endif diff --git a/util/fbautostart/include/entry.hh b/util/fbautostart/include/entry.hh new file mode 100644 index 0000000..6b2fd51 --- /dev/null +++ b/util/fbautostart/include/entry.hh @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef ENTRY_H_ +#define ENTRY_H_ ja + +#include "state.hh" + +class entry : public state { + public: + void leave_state(); + void enter_state(); + void process( char c ); +}; + +extern entry xdg_entry; + +#endif diff --git a/util/fbautostart/include/exceptions.hh b/util/fbautostart/include/exceptions.hh new file mode 100644 index 0000000..46040bc --- /dev/null +++ b/util/fbautostart/include/exceptions.hh @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +class parser_exception : public std::exception { + private: + int row; + int col; + public: + parser_exception(int row, int col) { + this->row = row; + this->col = col; + } + virtual const char* what() const throw() { + return "Parsing exception"; + } +}; + +class incomplete_process : public std::exception { + public: + virtual const char* what() const throw() { + return "Incomplete parsing"; + } +}; + +class hidden_file : public std::exception { + public: + virtual const char* what() const throw() { + return "Incomplete parsing"; + } +}; + diff --git a/util/fbautostart/include/fbautostart.hh b/util/fbautostart/include/fbautostart.hh deleted file mode 100644 index 6ce1144..0000000 --- a/util/fbautostart/include/fbautostart.hh +++ /dev/null @@ -1,147 +0,0 @@ -/* - * fbautostart.hh - * - * This file is part of the Fluxbox Autostart ( fbautostart ) - * Utility. - * - * Copyright (C) 2011 by Paul Tagliamonte - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#ifndef _FBAUTOSTART_H -#define _FBAUTOSTART_H ohai - -#define PACKAGE "fbautostart" -#define PACKAGE_VERSION "2.71828" - -#ifndef _DEBUG_MODE -#define _DEBUG_MODE 0 -#endif - -extern const char * _ON_BEHALF_OF; -extern bool noexec; - -#include "dot_desktop.hh" - -#define _DEFAULT_XDG_HOME "~/.config" -#define _DEFAULT_XDG_DIRS "/etc/xdg" -#define _XDG_AUTOSTART_DIR "/autostart/" - -// XXX: Please document these functions better. -// the @param names need to be fixed up as well. -// stuff like `foo' or `loc' sucks ass. -// -PRT - -namespace fbautostart { - - /** - * Print a help message to the user - */ - void help(); - - /** - * Lecture the user on correct invocation. - */ - void lecture(); - - /** - * Print version of fbautostart to stdout. - */ - void version(); - - /** - * Log an error to stderr. - * @param s std::string with the error message - */ - void logError( std::string s ); - - /** - * Log an error to stderr, to print a single integer. - * @param i int to print to stderr - */ - void logError( int i ); - - /** - * Print the string to the screen if debug mode is enabled. - * @param s std::string with the message to print to the screen - */ - void debug( const std::string & s ); - - /** - * Print a std::vector to the screen if debug mode is enabled. - * @param foo std::vector to dump - */ - void debug( const std::vector & foo ); - - /** - * Print a size_t to the screen if debug mode is enabled. - * @param foo size_t to be printed to the screen - */ - void debug( size_t foo ); - - /** - * processArgs should only be called by main, and pass the main arguments to processArgs. - * @param argc number of arguments in args - * @param argv char array of arguments - */ - void processArgs( int argc, char ** args ); - - /** - * Run a command on the system - * @param appl command to run - * @return return status of the application - */ - int runCommand( std::string appl ); - - /** - * Break a line up based on a ":" - * @param locs the std::vector to push tokens back into - * @param lines to process - */ - void breakupLine( std::vector * locs, std::string lines ); - - /** - * Fix paths with a tilde in them. - * @param locs a std::vector of paths to fix up - * @param home the home path of the user, absolute - */ - void fixHomePathing( std::vector * locs, std::string home ); - - /** - * Get configuration directories according to the XDG spec. - * @param loc std::vector to load up results in - * @return returns false if we are unable to complete processing (such as null $HOME) - */ - bool getConfDirs( std::vector & loc ); - - /** - * Get all the .desktop files to process. - * @param dirs the directories to search - * @param out_files the vector we are loading up - * @return if we were able to complete processing with success - */ - bool getDesktopFiles( - const std::vector & dirs, - std::vector & out_files - ); -} - -#endif diff --git a/util/fbautostart/include/group.hh b/util/fbautostart/include/group.hh new file mode 100644 index 0000000..9b9892c --- /dev/null +++ b/util/fbautostart/include/group.hh @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GROUP_H_ +#define GROUP_H_ ja + +#define _XDG_GROUP_UNDEFINED "_PAULTAG_UNDEFINED" + +#include +#include "state.hh" + +class group : public state { + public: + void leave_state(); + void enter_state(); + void process( char c ); +}; + +extern group xdg_group; +extern std::string xdg_state_group_lastparsed; + +#endif diff --git a/util/fbautostart/include/invalid.hh b/util/fbautostart/include/invalid.hh new file mode 100644 index 0000000..9d9522e --- /dev/null +++ b/util/fbautostart/include/invalid.hh @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef INVALID_H_ +#define INVALID_H_ ja + +#include "state.hh" + +class invalid : public state { + public: + void leave_state(); + void enter_state(); + void process( char c ); +}; + +extern invalid xdg_invalid; + +#endif diff --git a/util/fbautostart/include/key.hh b/util/fbautostart/include/key.hh new file mode 100644 index 0000000..cbf241e --- /dev/null +++ b/util/fbautostart/include/key.hh @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef KEY_H_ +#define KEY_H_ ja + +#include +#include "state.hh" + +class key : public state { + public: + void leave_state(); + void enter_state(); + void process( char c ); +}; + +extern key xdg_key; +extern std::string xdg_state_key_lastparsed; + +#endif diff --git a/util/fbautostart/include/machine.hh b/util/fbautostart/include/machine.hh new file mode 100644 index 0000000..0012af7 --- /dev/null +++ b/util/fbautostart/include/machine.hh @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MACHINE_H_ +#define MACHINE_H_ ja + +#include "comment.hh" +#include "entry.hh" +#include "state.hh" + +extern state * xdg_machine_next_state; + +void xdg_machine_process( char c ); +void xdg_machine_turnkey(); + +#endif diff --git a/util/fbautostart/include/main.hh b/util/fbautostart/include/main.hh new file mode 100644 index 0000000..cc2ba5b --- /dev/null +++ b/util/fbautostart/include/main.hh @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _MAIN_H_ +#define _MAIN_H_ yes + +std::string fix_home_pathing( std::string ref, std::string home ); + +#endif + diff --git a/util/fbautostart/include/state.hh b/util/fbautostart/include/state.hh new file mode 100644 index 0000000..9c50947 --- /dev/null +++ b/util/fbautostart/include/state.hh @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef STATE_H_ +#define STATE_H_ ja + +class state { + public: + virtual void leave_state(); + virtual void enter_state(); + virtual void process( char c ); +}; + +#endif diff --git a/util/fbautostart/include/value.hh b/util/fbautostart/include/value.hh new file mode 100644 index 0000000..c598f40 --- /dev/null +++ b/util/fbautostart/include/value.hh @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef VALUE_H_ +#define VALUE_H_ ja + +#include +#include "state.hh" + +class value : public state { + public: + void leave_state(); + void enter_state(); + void process( char c ); +}; + +extern value xdg_value; +extern std::string xdg_state_value_lastparsed; + +#endif diff --git a/util/fbautostart/include/xdg_autostart.hh b/util/fbautostart/include/xdg_autostart.hh new file mode 100644 index 0000000..55fd0c8 --- /dev/null +++ b/util/fbautostart/include/xdg_autostart.hh @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef XDG_AUTOSTART_H_ +#define XDG_AUTOSTART_H_ ja + +#include +#include + +typedef std::pair xdg_autostart_pair; +typedef std::map xdg_autostart_map; + +xdg_autostart_pair xdg_autostart_last_parsed(); +xdg_autostart_pair xdg_autostart_last_parsed(std::string s); + +#endif + diff --git a/util/fbautostart/include/xdg_model.hh b/util/fbautostart/include/xdg_model.hh new file mode 100644 index 0000000..7bea736 --- /dev/null +++ b/util/fbautostart/include/xdg_model.hh @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef XDG_MODEL_H_ +#define XDG_MODEL_H_ ja + +#include +#include + +typedef std::pair xdg_model_entry_t; +typedef std::map xdg_model_entry; + +typedef std::pair xdg_model_entries_t; +typedef std::map xdg_model_entries; + +extern xdg_model_entries xdg_parsed_file; + +#endif diff --git a/util/fbautostart/include/xdg_parse.hh b/util/fbautostart/include/xdg_parse.hh new file mode 100644 index 0000000..1e9f683 --- /dev/null +++ b/util/fbautostart/include/xdg_parse.hh @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _XDG_PARSE_H_ +#define _XDG_PARSE_H_ yes + +#include "xdg_autostart.hh" + +void parse_file ( std::string file ); +void parse_folder ( xdg_autostart_map * binaries, std::string folder ); + +#endif + diff --git a/util/fbautostart/include/xdg_spec.hh b/util/fbautostart/include/xdg_spec.hh new file mode 100644 index 0000000..9933de3 --- /dev/null +++ b/util/fbautostart/include/xdg_spec.hh @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef XDG_SPEC_H_ +#define XDG_SPEC_H_ yes + +#include + +extern std::string _xdg_window_manager; +extern std::string _xdg_default_global; +extern std::string _xdg_default_local; + +#endif + diff --git a/util/fbautostart/src/Makefile.old b/util/fbautostart/src/Makefile.old new file mode 100644 index 0000000..2848de6 --- /dev/null +++ b/util/fbautostart/src/Makefile.old @@ -0,0 +1,20 @@ +CXX=g++ + +CFLAGS=-Wall +BIN=../bin/ +INC=../include/ + +TARGETS=$(shell ls *.cc | sed s/.cc/.o/g) + + +all: $(TARGETS) link clean + +clean: + @echo "Removing all .o files." + @rm -f *.o + +link: + $(CXX) $(TARGETS) -o $(BIN)fluxbox-xdg + +.cc.o: + $(CXX) $(CFLAGS) -I$(INC) -c -o $@ $< diff --git a/util/fbautostart/src/comment.cc b/util/fbautostart/src/comment.cc new file mode 100644 index 0000000..1343212 --- /dev/null +++ b/util/fbautostart/src/comment.cc @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "comment.hh" +#include "entry.hh" +#include "machine.hh" + +comment xdg_comment; + +void comment::leave_state() { /* nullop */ } +void comment::enter_state() { /* nullop */ } + +void comment::process( char c ) { + switch ( c ) { + case '\n': + xdg_machine_next_state = &xdg_entry; + break; + default: + /* nullop */ + break; + } +} + diff --git a/util/fbautostart/src/dot_desktop.cc b/util/fbautostart/src/dot_desktop.cc deleted file mode 100644 index 4c7ca68..0000000 --- a/util/fbautostart/src/dot_desktop.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* - * dot_desktop.cc - * - * This file is part of the Fluxbox Autostart ( fbautostart ) - * Utility. - * - * Copyright (C) 2011 by Paul Tagliamonte - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -/* - * BIG BOLDFACE WARNING: - * BIG BOLDFACE WARNING: - * BIG BOLDFACE WARNING: - * - * This is *NOT* a full implementation of the - * .desktop spec. If you decide to use this code - * for anything outside of basic basic use ( read: - * what we're using it for ) - * - * In fact, this is almost as bare bones as I can make it - * It will break on more then one directive, and barf to stderr - * when it finds something it thinks is disgusting. - * - * It also does not trim strings, so there may be whitespace crap - * screwing stuff up. - * - * This needs some love. Patches welcome. Don't suggest - * the GNOME library. That relies on GTK+. WTF, really GNOME. - * -- PRT - * - */ - -#define _DOT_DESKTOP_GIVEAWAY "[Desktop Entry]" - -#include -#include -#include - -#include "fbautostart.hh" - -fbautostart::dot_desktop::dot_desktop( std::string s, std::string id ) { - this->attr = new std::vector(); - this->file = s; - this->id = id; - this->load(); -} - -bool fbautostart::dot_desktop::validate() { - std::ifstream fp_in(this->file.c_str()); - std::string line; - bool ret = false; - bool gah = true; - while ( gah && std::getline(fp_in, line) ) { // XXX: This sucks. Fix me. - if ( line.substr(0,strlen(_DOT_DESKTOP_GIVEAWAY)) == _DOT_DESKTOP_GIVEAWAY ) { - // debug(""); - // debug("Found us a Desktop file!"); - ret = true; - gah = false; - } else if ( line.substr(0,1) == "#" || line.substr(0,1) == "" ) { // XXX: This sucks. Fix me. - // ok. comment or whitespace - } else { - ret = false; - gah = false; - - debug(""); - debug("Looks like the following file is not a desktop file."); - debug(this->file); - debug("The giveaway was:"); - debug(line); - } - } - fp_in.close(); - return ret; -} - -void fbautostart::dot_desktop::load() { - if ( this->validate() ) { - std::ifstream fp_in(this->file.c_str()); - std::string line; - - while ( std::getline(fp_in, line) ) { - int index = -1; - if ( line.substr(0,1) != "#" ) { - index = line.find("="); - if ( index > 0 ) { - std::string id = line.substr(0,index); - std::string data = line.substr(index+1,strlen(line.c_str())); - dot_desktop_attr * new_attr = new dot_desktop_attr; - new_attr->attr = id; - new_attr->value = data; - this->attr->push_back( new_attr ); - } else if ( line.substr(0,1) == "[" && line.substr(line.length()-1,line.length()) == "]" ) { - // debug("Found a new header:"); // XXX: This sucks. Fix me. - // debug(line); - } else if ( line == "" ) { - // just a blank line. - } else { - logError(""); - logError( "We've got an issue with the following file:" ); - logError( this->file ); - logError( "Line in question is: " ); - logError( line ); - } - } - } - fp_in.close(); - } else { - logError(""); - logError( "We've got an issue with the following file:" ); - logError( this->file ); - } -} - -std::string fbautostart::dot_desktop::getFile() { - return this->file; -} - -std::string fbautostart::dot_desktop::getID() { - return this->id; -} - -std::string fbautostart::dot_desktop::getAttr( std::string s ){ - for ( unsigned int i = 0; i < this->attr->size(); ++i ) { - if ( this->attr->at(i)->attr == s ) - return this->attr->at(i)->value; - } - return ""; -} diff --git a/util/fbautostart/src/entry.cc b/util/fbautostart/src/entry.cc new file mode 100644 index 0000000..fd5a4ec --- /dev/null +++ b/util/fbautostart/src/entry.cc @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "key.hh" +#include "entry.hh" + +#include "group.hh" +#include "comment.hh" +#include "invalid.hh" +#include "machine.hh" +#include "exceptions.hh" + +entry xdg_entry; + +void entry::leave_state() {} +void entry::enter_state() {} + +void entry::process( char c ) { + switch ( c ) { + case '#': + /* Lines that begin with # are comments*/ + xdg_machine_next_state = &xdg_comment; + break; + case '=': + /* We've got no key, this is an invalid transition */ + xdg_machine_next_state = &xdg_invalid; + break; + case '[': + /* Lines that begin with [ are groups */ + xdg_machine_next_state = &xdg_group; + break; + case '\n': + /* Let's just eat newlines */ + break; + default: + /* Anything else is a key */ + xdg_machine_next_state = &xdg_key; + throw new incomplete_process(); + break; + } +} + diff --git a/util/fbautostart/src/fbautostart.cc b/util/fbautostart/src/fbautostart.cc deleted file mode 100644 index dd3b81b..0000000 --- a/util/fbautostart/src/fbautostart.cc +++ /dev/null @@ -1,356 +0,0 @@ -/* - * fbautostart.cc - * - * This file is part of the Fluxbox Autostart ( fbautostart ) - * Utility. - * - * Copyright (C) 2011 by Paul Tagliamonte - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fbautostart.hh" - -#ifndef _FBAUTOSTART_CPP -#define _FBAUTOSTART_CPP foomanchu - -#define _APPNAME_ PACKAGE -#define _VERSION_ PACKAGE_VERSION - -#ifndef _ON_BEHALF_OF_DEFAULT - -/** - * I'm a bit biased on what this should - * be starting up for. Considering the - * name of this app and such. - */ - -#define _ON_BEHALF_OF_DEFAULT "FLUXBOX" -#endif - -const char * _ON_BEHALF_OF = _ON_BEHALF_OF_DEFAULT; - -bool noexec = false; - -void fbautostart::version() { - std::cout << "" << _APPNAME_ << " " << _VERSION_ << std::endl; -} - -void fbautostart::lecture() { - version(); - std::cout << "Copyright (C) 2011 The Fluxbox Team" << std::endl; - std::cout << "Copyright (C) 2010 Paul Tagliamonte" << std::endl; - std::cout << "This software is licensed under the MIT License." << std::endl; - std::cout << "This is free software: you are free to change and redistribute it." << std::endl; - std::cout << "There is NO WARRANTY, to the extent permitted by law." << std::endl; -} - -void fbautostart::help() { - std::cout << "Usage: fbautostart [OPTION] ... " << std::endl; - std::cout << "Startup all applications according to the" << std::endl; - std::cout << "XDG Spec. Right now, I'm hardcoded to think that" << std::endl; - std::cout << "I am doing this on behalf of '" << _ON_BEHALF_OF << "'" << std::endl; - - std::cout << std::endl; - - std::cout << "--license Print out license information" << std::endl; - std::cout << "--help Print out this message" << std::endl; - std::cout << "--noexec Don't exec, just do a dry run" << std::endl; - std::cout << "--window-manager ID Override hardcoded value ( " << _ON_BEHALF_OF << " )" << std::endl; - - std::cout << "" << std::endl; - - std::cout << "Copyleft (c) The Fluxbox Team, 2011, MIT License" << std::endl; - std::cout << "Copyleft (c) Paul Tagliamonte, 2010, MIT License" << std::endl; - // ^^^^^^^^^^^^^^^^ That is pretty fucking awesome - // Future maintainer: Your name must - // be exactly 16 chars long. kthx. - - std::cout << "" << std::endl; -} - -int fbautostart::runCommand( std::string appl ) { - /* - * The following is almost directly ripped off from - * Fluxbox's implementation. ( at ak|ra's behest ) - */ - - pid_t pid = fork(); - if (pid) - return pid; - - // get shell path from the environment - // - // this process exits immediately, so we don't have to - // worry about memleaks - std::string shell = getenv("SHELL"); - - if ( shell != "" ) - shell = "/bin/sh"; - - if ( ! noexec ) { // we'll do it live - execl( - shell.c_str(), - shell.c_str(), - "-c", - appl.c_str(), - static_cast(NULL) - ); - exit ( EXIT_SUCCESS ); - return pid; // compiler happy -> we are happy ;) - } else { // dummy mode ( test ) - std::cout << "Would have run: " << appl << std::endl; - exit(0); - return 0; - } -} - -void fbautostart::processArgs( int argc, char ** args ) { - for ( int i = 1; i < argc; ++i ) { - if ( strcmp(args[i], "--license") == 0 ) { - lecture(); - exit(0); - } else if ( strcmp(args[i], "--version") == 0 ) { - version(); - exit(0); - } else if ( strcmp(args[i], "--help") == 0 ) { - help(); - exit(0); - } else if ( strcmp(args[i], "--noexec") == 0 ) { - noexec = true; - } else if ( strcmp(args[i], "--window-manager") == 0 ) { - _ON_BEHALF_OF = args[i+1]; - i = i+1; - } else { - help(); - - std::cout << "Holy god. I have no idea what:" << std::endl; - std::cout << " " << args[i] << std::endl; - std::cout << "means. Try again :/" << std::endl; - std::cout << std::endl; - - exit(1); - } - } -} - -/* - * OK. Here's some Spec text. I accessed this data on - * October 14th, 2010. - * - * The URL was: - * http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html - * - * - * == Autostart Directories == - * - * The Autostart Directories are $XDG_CONFIG_DIRS/autostart as - * defined in accordance with the "Referencing this specification" - * section in the "desktop base directory specification". - * - * If the same filename is located under multiple Autostart Directories - * only the file under the most important directory should be used. - * - * Example: If $XDG_CONFIG_HOME is not set the Autostart Directory - * in the user's home directory is ~/.config/autostart/ - * - * Example: If $XDG_CONFIG_DIRS is not set the system wide Autostart - * Directory is /etc/xdg/autostart/ - * - * Example: If $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS are not set and - * the two files /etc/xdg/autostart/foo.desktop and - * ~/.config/autostart/foo.desktop exist then only the file - * ~/.config/autostart/foo.desktop will be used because - * ~/.config/autostart/ is more important than /etc/xdg/autostart/ - */ - - -void fbautostart::logError( std::string s ) { // [e]: my error line - std::cerr << "[e]: " << s << std::endl; -} - -void fbautostart::logError( int i ) { // [e]: (int) n - std::cerr << "[e]: (int) " << i << std::endl; -} - -void fbautostart::debug( const std::string & s ) { // [l]: my debug line - if ( _DEBUG_MODE ) { - std::cout << "[l]: " << s << std::endl; - } -} - -void fbautostart::debug( const std::vector & foo ) { // [l]: my debug line - if ( _DEBUG_MODE ) { - std::cout << "[l]: The following is an array" << std::endl; - for ( unsigned int i = 0; i < foo.size(); ++i ) { - std::cout << "[l]: " << foo.at(i) << std::endl; - } - } -} - -void fbautostart::debug( size_t foo ) { // [l]: my debug line - if ( _DEBUG_MODE ) { - std::cout << "[l]: " << foo << std::endl; - } -} - -void fbautostart::breakupLine( std::vector * locs, std::string lines ) { - std::string token; - std::istringstream iss(lines); - while ( getline(iss, token, ':') ) { - token.append( _XDG_AUTOSTART_DIR ); // use the xdg autostart dir. - locs->push_back( token ); - } -} - -void fbautostart::fixHomePathing( std::vector * locs, std::string home ) { - for ( unsigned int i = 0; i < locs->size(); ++i ) { - if ( locs->at(i)[0] == '~' && locs->at(i)[1] == '/' ) { - debug(""); - debug("Fixing a path old / new path follows."); - debug(locs->at(i)); - locs->at(i).replace(0, 1, home ); - debug(locs->at(i)); - } - } -} - -bool fbautostart::getConfDirs( std::vector & loc ) { - - const char * xdg_home = getenv("XDG_CONFIG_HOME"); // See the spec for why - const char * xdg_dirs = getenv("XDG_CONFIG_DIRS"); // I'm using what I'm using. - const char * uzr_home = getenv("HOME"); - - if ( uzr_home != NULL ) { - - std::string XDG_home, XDG_dirs; - - if ( xdg_dirs != NULL ) { - debug( "We have an overridden xdg dir. Using it." ); - XDG_dirs = xdg_dirs; - } else { - XDG_dirs = _DEFAULT_XDG_DIRS; - } - - if ( xdg_home != NULL ) { - debug( "We have an overridden xdg home. Using it." ); - XDG_home = xdg_home; - } else { - XDG_home = _DEFAULT_XDG_HOME; - } - - debug("Following is the targets"); - debug(XDG_home); - debug(XDG_dirs); - - breakupLine( &loc, XDG_dirs ); - breakupLine( &loc, XDG_home ); - - for ( unsigned int i = 0; i < loc.size(); ++i ) - fixHomePathing( &loc, uzr_home ); - - debug(""); - debug("Using the following array to find files ( Expanded ): "); - debug(loc); - - return true; - } else { - logError( "the env var HOME is not set. Panic!" ); - return false; - } -} - -bool fbautostart::getDesktopFiles( - const std::vector & dirs, - std::vector & out_files -) { - std::vector files; - - for ( unsigned int i = 0; i < dirs.size(); ++i ) { - DIR * dp = NULL; - struct dirent * dirp = NULL; - if ( (dp = opendir(dirs.at(i).c_str())) == NULL ) { - if ( errno == ENOENT ) { // E(RROR) NO EXIST ( or whatever ) - debug(""); - debug("Looks like the dir does not exist. Dir follows."); - debug( dirs.at(i) ); - } else { - logError(""); - logError("Oh no! Error opening directory! Directory, then Errorno follows: "); - logError( dirs.at(i) ); - logError(errno); - return false; - } - } else { - while ((dirp = readdir(dp)) != NULL) { // for every file in the directory - std::string file(dirp->d_name); // char arrays suck - if ( file != "." && file != ".." ) { // make sure we don't use . / .. - int dupe = -1; // there's no -1st element, silly! - - for ( unsigned int n = 0; n < files.size(); ++n ) { - if ( files.at(n).getID() == file ) { // make sure it's unique - // ( as the xdg - // spec requires ) - - dupe = n; // there can be only one - // dupe in the array, so it's - // OK to think that there will - // be only one - } - } - - std::string desktop_filepath = dirs.at(i); - desktop_filepath.append(file); - dot_desktop new_file( desktop_filepath, file ); - - if ( dupe >= 0 ) { - files.at(dupe) = new_file; - } else { - files.push_back( new_file ); - } - } - } - closedir(dp); - } - } - - if ( ! files.empty() ) { - std::swap( files, out_files ); - return true; - } else { - return false; - } -} - -#endif diff --git a/util/fbautostart/src/group.cc b/util/fbautostart/src/group.cc new file mode 100644 index 0000000..077a17b --- /dev/null +++ b/util/fbautostart/src/group.cc @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "group.hh" +#include "entry.hh" +#include "machine.hh" +#include "invalid.hh" + +group xdg_group; +std::string xdg_state_group_lastparsed = _XDG_GROUP_UNDEFINED; + +void group::leave_state() {} +void group::enter_state() { + xdg_state_group_lastparsed = ""; +} + +void group::process( char c ) { + switch ( c ) { + case ']': + /* End of group declr */ + xdg_machine_next_state = &xdg_entry; + break; + case '\n': + /* We've got got a ], invalid */ + xdg_machine_next_state = &xdg_invalid; + break; + default: + /* push back the group entry */ + xdg_state_group_lastparsed.append(1, c); + break; + } +} + diff --git a/util/fbautostart/src/invalid.cc b/util/fbautostart/src/invalid.cc new file mode 100644 index 0000000..6feeb53 --- /dev/null +++ b/util/fbautostart/src/invalid.cc @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "invalid.hh" +#include "exceptions.hh" + +invalid xdg_invalid; + +void invalid::leave_state() { } +void invalid::enter_state() { } + +void invalid::process( char c ) { + // XXX: Fix this up + std::cerr << "Crap! Error parsing!!" << std::endl; + throw new parser_exception(-1,-1); +} + diff --git a/util/fbautostart/src/key.cc b/util/fbautostart/src/key.cc new file mode 100644 index 0000000..0e1cb86 --- /dev/null +++ b/util/fbautostart/src/key.cc @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "key.hh" +#include "value.hh" +#include "invalid.hh" +#include "machine.hh" + +key xdg_key; + +std::string xdg_state_key_lastparsed; + +void key::leave_state() { } +void key::enter_state() { + xdg_state_key_lastparsed = ""; +} + +void key::process( char c ) { + switch ( c ) { + case '=': + /* Once we hit a =, we grab values */ + xdg_machine_next_state = &xdg_value; + break; + case '\n': + /* If we hit a newline with now =, it's invalid */ + xdg_machine_next_state = &xdg_invalid; + break; + default: + /* push back char */ + xdg_state_key_lastparsed.append(1, c); + break; + } +} + diff --git a/util/fbautostart/src/machine.cc b/util/fbautostart/src/machine.cc new file mode 100644 index 0000000..6a4538e --- /dev/null +++ b/util/fbautostart/src/machine.cc @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "exceptions.hh" +#include "xdg_model.hh" +#include "machine.hh" +#include "state.hh" + +state * xdg_machine_next_state; +state * xdg_machine_curr_state; + +void xdg_machine_turnkey() { + xdg_machine_curr_state = xdg_machine_next_state; +} + +void xdg_machine_process( char c ) { + bool passchar = false; + + try { + xdg_machine_curr_state->process(c); + } catch ( incomplete_process * ex ) { + /* If the machine can't fully processes the char, + we must pass it to the next state */ + passchar = true; + } + + if ( xdg_machine_curr_state != xdg_machine_next_state ) { + /* a machine has requested a state transition. + We can hanlde this the right (tm) way. */ + + xdg_machine_curr_state->leave_state(); + xdg_machine_curr_state = xdg_machine_next_state; + xdg_machine_curr_state->enter_state(); + + /* All set to keep processing. Now, let's see + if we have to process the next char. If we do, + then let's recurse. */ + if ( passchar ) + xdg_machine_process(c); + } +} + diff --git a/util/fbautostart/src/main.cc b/util/fbautostart/src/main.cc index 09f2d10..0eafdee 100644 --- a/util/fbautostart/src/main.cc +++ b/util/fbautostart/src/main.cc @@ -1,21 +1,16 @@ /* - * main.cc - * - * This file is part of the Fluxbox Autostart ( fbautostart ) - * Utility. + * Copyright (C) 2011, Paul Tagliamonte * - * Copyright (C) 2011 by Paul Tagliamonte - * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,68 +18,186 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. - * */ +#include +#include #include +#include +#include +#include +#include -#include "fbautostart.hh" +#include "exceptions.hh" -using namespace std; +#include "main.hh" +#include "state.hh" +#include "entry.hh" +#include "machine.hh" +#include "xdg_spec.hh" +#include "xdg_parse.hh" +#include "xdg_model.hh" +#include "xdg_autostart.hh" -int main ( int argc, char ** argv ) { - fbautostart::processArgs( argc, argv ); +bool noexec = false; + +/** + * XXX: Docme + */ +int run_command( std::string appl ) { + if ( appl == "" ) + return 0; + + pid_t pid = fork(); + + if (pid) + return pid; + + std::string shell = getenv("SHELL"); + + if ( shell != "" ) + shell = "/bin/sh"; + + if ( ! noexec ) { // we'll do it live + execl( + shell.c_str(), + shell.c_str(), + "-c", + appl.c_str(), + static_cast(NULL) + ); + exit ( EXIT_SUCCESS ); + return pid; + } else { + std::cout << " Would have run: " << appl << std::endl; + exit(0); + return 0; + } +} + +/** + * XXX: Document me + */ +void pre_exec() { + const char * home = getenv("XDG_CONFIG_HOME"); + const char * dirs = getenv("XDG_CONFIG_DIRS"); + const char * userhome = getenv("HOME"); + const char * desktopenv = getenv("FBXDG_DE"); + const char * execmodel = getenv("FBXDG_EXEC"); + + /* TABLE OF ENV VARS + * + * +------------------+----------------------------+ + * | XDG_CONFIG_HOME | XDG Local dir (~/.config) | + * | XDG_CONFIG_DIRS | XDG Global dir (/etc/xdg) | + * | HOME | User home (/home/tag) | + * | FBXDG_DE | Who to act on behalf of | + * | FBXDG_EXEC | 0 for exec, 1 for noexec | + * +------------------+----------------------------+ + * + */ + + const char * blank = ""; /* -Waddress errrs. + ( to avoid using strcmp, which we actually + do use later, so XXX: Fixme ) */ + + home = home == NULL ? blank : home; + dirs = dirs == NULL ? blank : dirs; + desktopenv = desktopenv == NULL ? blank : desktopenv; + execmodel = execmodel == NULL ? blank : execmodel; + /* + * If we're null, set to "" rather then keep NULL. + */ - if ( noexec ) { - std::cout << "Warning: In noexec mode." << std::endl; + _xdg_default_global = dirs == blank ? _xdg_default_global : dirs; + _xdg_default_local = home == blank ? _xdg_default_local : home; + _xdg_window_manager = desktopenv == blank ? _xdg_window_manager : desktopenv; + /* + * If we have a env var, set them to the global prefs. + */ + + if ( strcmp(execmodel,"0") == 0 ) + noexec = false; + else if ( strcmp(execmodel,"1") == 0 ) + noexec = true; + /* + * Fuck this mess. Someone needs to clean this up to use true/false + * and have it relate in a sane way. + * XXX: Fixme + */ + + _xdg_default_global = fix_home_pathing( _xdg_default_global, userhome ); + _xdg_default_local = fix_home_pathing( _xdg_default_local, userhome ); + /* + * If the luser gives us (or we default to) a path with tlde in it, + * let's expand it to use $HOME to figure out where the real path actually + * is. + */ + + std::cout << "" << std::endl; + std::cout << "Hello! I'll be your friendly XDG Autostarter today." << std::endl; + std::cout << "Here's what's on the menu:" << std::endl; + std::cout << "" << std::endl; + std::cout << " Appetizers" << std::endl; + std::cout << "" << std::endl; + + std::cout << " * $XDG_CONFIG_HOME: " << home << std::endl; + std::cout << " * $XDG_CONFIG_DIRS: " << dirs << std::endl; + std::cout << " * $FBXDG_DE: " << desktopenv << std::endl; + std::cout << " * $FBXDG_EXEC: " << execmodel << std::endl; + + std::cout << "" << std::endl; + std::cout << " Entrées" << std::endl; + std::cout << "" << std::endl; + + std::cout << " * Desktop Enviroment: " << _xdg_window_manager << std::endl; + std::cout << " * Global XDG Directory: " << _xdg_default_global << std::endl; + std::cout << " * Local XDG Directory: " << _xdg_default_local << std::endl; + std::cout << " * Current exec Model: " << noexec << std::endl; + + std::cout << "" << std::endl; + std::cout << " - Chef Tagliamonte" << std::endl; + std::cout << " & The Fluxbox Crew" << std::endl; + std::cout << "" << std::endl; +} + +/** + * XXX: Document me + */ +std::string fix_home_pathing( std::string ref, std::string home ) { + // std::cout << "preref: " << ref << std::endl; + if ( ref[0] == '~' && ref[1] == '/' ) { + // std::cout << " +-> confirmed." << std::endl; + ref.replace(0, 1, home ); + // std::cout << " +-> postref: " << ref << std::endl; } + return ref; +} + + +int main ( int argc, char ** argv ) { + pre_exec(); /* pre_exec allows us to read goodies and set up + the env for us. */ - std::cout << "Launching on behalf of " << _ON_BEHALF_OF << std::endl; - - std::vector files; - std::vector dirs; - - if ( fbautostart::getConfDirs( dirs ) ) { // if no directories barf in our face - if ( fbautostart::getDesktopFiles( dirs, files ) ) { // and we load everything with glee - for ( unsigned int i = 0; i < files.size(); ++i ) { // run through all the files - fbautostart::dot_desktop d = files.at(i); - bool happy = true; - std::string only = d.getAttr("OnlyShowIn"); // Only one per file ( per xdg ) - std::string noti = d.getAttr("NotShowIn"); // We'll ignore that until we care - // XXX: This is most likely a bug. - if ( only != "" ) { // even if an attr does not exist - // the object will return it as "". - int index = -1; - index = only.find(_ON_BEHALF_OF); // if we have our WM in the OnlyLaunch - if ( index < 0 ) { // we're disabled ( not found ) - happy = false; - fbautostart::debug(""); - fbautostart::debug("Not running the following app ( Excluded by a OnlyShowIn )"); - fbautostart::debug(d.getAttr("Name")); - } - } - if ( noti != "" ) { // (NotShowIn (don't show)) - int index = -1; - index = noti.find(_ON_BEHALF_OF); // if we have found our WM - if ( index >= 0 ) { // We're in Launch, stop from launching it. - happy = false; - fbautostart::debug(""); - fbautostart::debug("Forced into not running the following app ( Included by not being in NotShowIn )"); - fbautostart::debug(d.getAttr("Name")); - } - } - if ( d.getAttr("Hidden") == "" && happy ) { // If we sould exec - std::string appl = d.getAttr("Exec"); // get the line to run - if ( appl != "" ) { // if it's defined and ready to go - fbautostart::debug( "Processing File: "); - fbautostart::debug(d.getFile()); - fbautostart::runCommand( appl ); // kickoff (regardless of noexec) - } - } // otherwise, we're out of here. - } - return 0; - } - return 0xDEADBEEF; + xdg_autostart_map binaries; /* the map of what stuff to start + up or ignore or whatever. */ + + parse_folder( &binaries, _xdg_default_global + "/autostart/" ); + parse_folder( &binaries, _xdg_default_local + "/autostart/" ); + /* + * Let's kick off the parse routines on the directories. + */ + + std::cout << "" << std::endl; + std::cout << "Finished parsing all files." << std::endl; + std::cout << "" << std::endl; + + for ( xdg_autostart_map::iterator i = binaries.begin(); + i != binaries.end(); ++i + ) { + std::cout << " Handling stub for: " << i->first << std::endl; + run_command( i->second ); + /* foreach command, let's run it :) */ } - return 0xCAFEBABE; } + diff --git a/util/fbautostart/src/state.cc b/util/fbautostart/src/state.cc new file mode 100644 index 0000000..720dc86 --- /dev/null +++ b/util/fbautostart/src/state.cc @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "state.hh" + +void state::leave_state() { + /* nullop */ +} + +void state::enter_state() { + /* nullop */ +} + +void state::process( char c ) { + /* nullop */ +} + diff --git a/util/fbautostart/src/value.cc b/util/fbautostart/src/value.cc new file mode 100644 index 0000000..d96648b --- /dev/null +++ b/util/fbautostart/src/value.cc @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +#include "key.hh" +#include "value.hh" +#include "entry.hh" +#include "group.hh" +#include "machine.hh" +#include "xdg_model.hh" + +value xdg_value; + +std::string xdg_state_value_lastparsed; + +void value::leave_state() { + + std::string group = xdg_state_group_lastparsed; + std::string key = xdg_state_key_lastparsed; + std::string value = xdg_state_value_lastparsed; + + xdg_model_entries::iterator iter = xdg_parsed_file.find(group); + + if (iter != xdg_parsed_file.end()) { + xdg_model_entry * group_map = &iter->second; + xdg_model_entry_t new_item( key, value ); + group_map->insert(new_item); + } else { + xdg_model_entry group_map; + xdg_model_entry_t new_item( key, value ); + group_map.insert(new_item); + xdg_model_entries_t payload( group, group_map ); + xdg_parsed_file.insert(payload); + } +} + +void value::enter_state() { + xdg_state_value_lastparsed = ""; +} + +void value::process( char c ) { + switch ( c ) { + case '\n': + xdg_machine_next_state = &xdg_entry; + break; + default: + /* push back char */ + xdg_state_value_lastparsed.append(1, c); + break; + } +} + diff --git a/util/fbautostart/src/xdg_autostart.cc b/util/fbautostart/src/xdg_autostart.cc new file mode 100644 index 0000000..c645ad2 --- /dev/null +++ b/util/fbautostart/src/xdg_autostart.cc @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +#include "xdg_spec.hh" +#include "xdg_model.hh" +#include "exceptions.hh" +#include "xdg_autostart.hh" + +/** + * XXX: Document me + */ +xdg_autostart_pair xdg_autostart_last_parsed() { + return xdg_autostart_last_parsed("Desktop Entry"); +} + +/** + * XXX: Document me + */ +xdg_autostart_pair xdg_autostart_last_parsed(std::string group) { + xdg_model_entries::iterator entries = xdg_parsed_file.find(group); + + if (entries != xdg_parsed_file.end()) { + // handle entries + xdg_model_entry asf = entries->second; // asf = AutoStartFile + + std::string name = asf["Name"]; + + std::string onlyshow = asf["OnlyShowIn"]; + std::string notshow = asf["NotShowIn"]; + std::string tryexec = asf["TryExec"]; + std::string hidden = asf["Hidden"]; + std::string exec = asf["Exec"]; + + + bool notshowin = (notshow.find( _xdg_window_manager) != std::string::npos); + + + std::cout << "Now Serving: " << name << std::endl; + + if ( onlyshow != "" ) { + bool onlyshowin = (onlyshow.find(_xdg_window_manager) != std::string::npos); + if ( onlyshowin ) { + std::cout << " Attrinf: We're the only DE that can handle this :3" << std::endl; + std::cout << " Attrinf: " << onlyshow << std::endl; + } else { + std::cout << " Attrinf: We're not in the OnlyShowIn. We must not execute." << std::endl; + std::cout << " Attrinf: " << onlyshow << std::endl; + hidden = "true"; + } + } + + if ( notshowin ) { + std::cout << " Attrinf: We can't handle this item. Marking hidden :(" << std::endl; + std::cout << " Attrinf: " << notshow << std::endl; + hidden = "true"; + } + + if ( hidden == "true" ) { + std::cout << " Hidden: " << hidden << std::endl; + std::cout << " +-> (To be clear, I'm stopping here)" << std::endl; + xdg_autostart_pair ret = xdg_autostart_pair(name, ""); + return ret; + } else { + std::cout << " Hidden: " << hidden << std::endl; + std::cout << " +-> (To be clear, I'm going to continue parsing)" << std::endl; + } + + std::string binary_name = ""; + + if ( tryexec != "" ) { + // std::cout << " TryExec: " << tryexec << std::endl; + binary_name = tryexec; + } else if ( exec != "" ) { + // std::cout << " Exec: " << exec << std::endl; + binary_name = exec; + } else { + std::cout << " No Exec directive!" << std::endl; + } + + xdg_autostart_pair ret = xdg_autostart_pair(name, binary_name); + + return ret; + } else { + std::cerr << "Invalid .desktop file ( Can't find " << + group << " ). Ignoring." << std::endl; + throw new parser_exception(-1,-1); + } +} + diff --git a/util/fbautostart/src/xdg_model.cc b/util/fbautostart/src/xdg_model.cc new file mode 100644 index 0000000..6ce8e6a --- /dev/null +++ b/util/fbautostart/src/xdg_model.cc @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "xdg_model.hh" + +xdg_model_entries xdg_parsed_file; + diff --git a/util/fbautostart/src/xdg_parse.cc b/util/fbautostart/src/xdg_parse.cc new file mode 100644 index 0000000..6584f49 --- /dev/null +++ b/util/fbautostart/src/xdg_parse.cc @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include + +#include + +#include "machine.hh" +#include "xdg_model.hh" +#include "exceptions.hh" +#include "xdg_autostart.hh" + +/** + * XXX: Document me + */ +void parse_file ( std::string file ) { + std::ifstream xdg_file(file.c_str(), std::ios::in | std::ios::binary); + + if ( ! xdg_file ) { + std::cerr << "Crapola file." << std::endl; + // XXX: Raise exception + } + + xdg_machine_next_state = &xdg_entry; + xdg_machine_turnkey(); // Vvvrooom! + + char c; + + int row = 1; + int col = 0; // some cosmetics + + do { + xdg_file.read(&c, 1); + col++; + + if ( c == '\n' ) { col = 0; row++; } + + try { + xdg_machine_process( c ); + } catch ( parser_exception * fu ) { + parser_exception ex(row, col); + std::cerr << "Error parsing: R/C: " << row << ", " << col << std::endl; + throw &ex; // XXX: Fix this fucking hack + } + } while ( ! xdg_file.eof() ); + /* In the event that they don't newline the end of the + file */ + xdg_machine_process( '\n' ); +} + +/** + * XXX: Document me + */ +void parse_folder ( xdg_autostart_map * binaries, std::string folder ) { + DIR * dir; + struct dirent * ent; + dir = opendir (folder.c_str()); + + if (dir != NULL) { + /* print all the files and directories within directory */ + while ((ent = readdir (dir)) != NULL) { + if ( + strcmp (ent->d_name, ".") != 0 && + strcmp (ent->d_name, "..") != 0 + ) { + // std::cout << "Loading: " << folder + "/" + ent->d_name << " "; + try { + parse_file(folder + "/" + ent->d_name); + xdg_autostart_pair r = xdg_autostart_last_parsed(); + xdg_parsed_file.clear(); + binaries->insert(xdg_autostart_pair(ent->d_name, r.second)); + } catch ( parser_exception * ex ) { + std::cerr << "Exception parsing " << ent->d_name << std::endl; + std::cerr << " in " << folder << std::endl; + } + } + } + closedir (dir); + } else { + // XXX: Exceptionize this + } +} + diff --git a/util/fbautostart/src/xdg_spec.cc b/util/fbautostart/src/xdg_spec.cc new file mode 100644 index 0000000..b790965 --- /dev/null +++ b/util/fbautostart/src/xdg_spec.cc @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2011, Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "xdg_spec.hh" + +std::string _xdg_window_manager = "FLUXBOX"; /* Default DE to start on behalf of */ + +std::string _xdg_default_global = "/etc/xdg"; +std::string _xdg_default_local = "~/.config"; + -- cgit v0.11.2