From: Philipp Zabel Date: Wed, 24 Feb 2010 16:57:57 +0000 (+0100) Subject: Add mce.ini parser X-Git-Tag: v0.0.1~12 X-Git-Url: https://vcs.maemo.org/git/?p=led-pattern-ed;a=commitdiff_plain;h=911de41af8c39c28a29b87865c4486a1882642d3 Add mce.ini parser --- diff --git a/Makefile b/Makefile index f57d8f9..18a8ae6 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ led_pattern_editor_SOURCES = $(patsubst %.vala,%.c,${led_pattern_editor_VALASOUR led_pattern_editor_VALASOURCES = \ src/led-pattern-editor.vala \ src/led-pattern.vala \ - src/led-pattern-rx51.vala + src/led-pattern-rx51.vala \ + src/mce-ini-parse.vala led_pattern_editor_VALAFLAGS = --pkg hildon-1 --pkg libosso diff --git a/src/mce-ini-parse.vala b/src/mce-ini-parse.vala new file mode 100644 index 0000000..d7a4438 --- /dev/null +++ b/src/mce-ini-parse.vala @@ -0,0 +1,75 @@ +/* This file is part of LED Pattern Editor. + * + * Copyright (C) 2010 Philipp Zabel + * + * LED Pattern Editor 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 3 of the License, or + * (at your option) any later version. + * + * LED Pattern Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LED Pattern Editor. If not, see . + */ + +List mce_ini_parse () { + var list = new List (); + var f = FileStream.open ("/etc/mce/mce.ini", "r"); + + var line = f.read_line (); + while (line != null) { + if (line == "[LEDPatternLystiRX51]") { + line = f.read_line (); + while ((line != null) && (line[0] != '[')) { + if (line.has_prefix ("Pattern")) { + var pattern = new LedPatternRX51 (); + pattern.parse (line); + list.append (pattern); + } + line = f.read_line (); + } + } + line = f.read_line (); + } + + return list; +} + +void mce_ini_store (List list) { + var f = FileStream.open ("/etc/mce/mce.ini", "r"); + var g = FileStream.open ("/tmp/mce.ini", "w"); + + var line = f.read_line (); + while (line != null) { + if (line == "[LEDPatternLystiRX51]") { + g.printf ("%s\n", line); + line = f.read_line (); + while ((line != null) && (line[0] != '[')) { + if (line.has_prefix ("Pattern")) { + unowned List node; + for (node = list.first (); node != null; node = node.next) { + if (line.has_prefix (node.data.name + "=")) { + g.printf ("%s\n", node.data.dump ()); + break; + } + } + if (node == null) { + g.printf ("%s\n", line); + } + } else { + g.printf ("%s\n", line); + } + line = f.read_line (); + } + if (line[0] == '[') + g.printf ("%s\n", line); + } else { + g.printf ("%s\n", line); + } + line = f.read_line (); + } +}