diff options
author | Paul Tagliamonte <paultag@ubuntu.com> | 2011-09-04 21:05:01 (GMT) |
---|---|---|
committer | Paul Tagliamonte <tag@loki.(none)> | 2011-09-24 15:48:48 (GMT) |
commit | 44f4b0b601a63411095b53951b110af48b3cfbdc (patch) | |
tree | 8577c75ff0b7084a73c66602374163b447c97b50 /util/fbautostart/src/xdg_parse.cc | |
parent | cc5c30c9cbdce2693d284c57ae4671017bf0660c (diff) | |
download | fluxbox_paul-44f4b0b601a63411095b53951b110af48b3cfbdc.zip fluxbox_paul-44f4b0b601a63411095b53951b110af48b3cfbdc.tar.bz2 |
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.
Diffstat (limited to 'util/fbautostart/src/xdg_parse.cc')
-rw-r--r-- | util/fbautostart/src/xdg_parse.cc | 105 |
1 files changed, 105 insertions, 0 deletions
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 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011, Paul Tagliamonte | ||
3 | * | ||
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
5 | * of this software and associated documentation files (the "Software"), to deal | ||
6 | * in the Software without restriction, including without limitation the rights | ||
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
8 | * copies of the Software, and to permit persons to whom the Software is | ||
9 | * furnished to do so, subject to the following conditions: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
20 | * THE SOFTWARE. | ||
21 | */ | ||
22 | |||
23 | #include <vector> | ||
24 | #include <fstream> | ||
25 | #include <iostream> | ||
26 | #include <dirent.h> | ||
27 | |||
28 | #include <string.h> | ||
29 | |||
30 | #include "machine.hh" | ||
31 | #include "xdg_model.hh" | ||
32 | #include "exceptions.hh" | ||
33 | #include "xdg_autostart.hh" | ||
34 | |||
35 | /** | ||
36 | * XXX: Document me | ||
37 | */ | ||
38 | void parse_file ( std::string file ) { | ||
39 | std::ifstream xdg_file(file.c_str(), std::ios::in | std::ios::binary); | ||
40 | |||
41 | if ( ! xdg_file ) { | ||
42 | std::cerr << "Crapola file." << std::endl; | ||
43 | // XXX: Raise exception | ||
44 | } | ||
45 | |||
46 | xdg_machine_next_state = &xdg_entry; | ||
47 | xdg_machine_turnkey(); // Vvvrooom! | ||
48 | |||
49 | char c; | ||
50 | |||
51 | int row = 1; | ||
52 | int col = 0; // some cosmetics | ||
53 | |||
54 | do { | ||
55 | xdg_file.read(&c, 1); | ||
56 | col++; | ||
57 | |||
58 | if ( c == '\n' ) { col = 0; row++; } | ||
59 | |||
60 | try { | ||
61 | xdg_machine_process( c ); | ||
62 | } catch ( parser_exception * fu ) { | ||
63 | parser_exception ex(row, col); | ||
64 | std::cerr << "Error parsing: R/C: " << row << ", " << col << std::endl; | ||
65 | throw &ex; // XXX: Fix this fucking hack | ||
66 | } | ||
67 | } while ( ! xdg_file.eof() ); | ||
68 | /* In the event that they don't newline the end of the | ||
69 | file */ | ||
70 | xdg_machine_process( '\n' ); | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * XXX: Document me | ||
75 | */ | ||
76 | void parse_folder ( xdg_autostart_map * binaries, std::string folder ) { | ||
77 | DIR * dir; | ||
78 | struct dirent * ent; | ||
79 | dir = opendir (folder.c_str()); | ||
80 | |||
81 | if (dir != NULL) { | ||
82 | /* print all the files and directories within directory */ | ||
83 | while ((ent = readdir (dir)) != NULL) { | ||
84 | if ( | ||
85 | strcmp (ent->d_name, ".") != 0 && | ||
86 | strcmp (ent->d_name, "..") != 0 | ||
87 | ) { | ||
88 | // std::cout << "Loading: " << folder + "/" + ent->d_name << " "; | ||
89 | try { | ||
90 | parse_file(folder + "/" + ent->d_name); | ||
91 | xdg_autostart_pair r = xdg_autostart_last_parsed(); | ||
92 | xdg_parsed_file.clear(); | ||
93 | binaries->insert(xdg_autostart_pair(ent->d_name, r.second)); | ||
94 | } catch ( parser_exception * ex ) { | ||
95 | std::cerr << "Exception parsing " << ent->d_name << std::endl; | ||
96 | std::cerr << " in " << folder << std::endl; | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | closedir (dir); | ||
101 | } else { | ||
102 | // XXX: Exceptionize this | ||
103 | } | ||
104 | } | ||
105 | |||