version 0.21

This commit is contained in:
a-sansara 2018-08-28 15:05:45 +02:00
parent 34dc6053c2
commit 3f4685db22
15 changed files with 656 additions and 252 deletions

74
.berel.yml Normal file
View File

@ -0,0 +1,74 @@
%YAML 1.2
%TAG !v! tag:pluie.org,2018:vala/
---
!v!Pluie.Berel.Meta meta :
keys :
software : berel; <https://git.pluie.org/pluie/berel>
version : 0.21
type : program
date : 2018
license : GPLv3.0; <http://www.gnu.org/licenses/>
author : a-Sansara; <[dev]at[pluie]dot[org]>
copyright : pluie.org; <http://www.pluie.org>
headers :
- sh :
file :
- build.sh
startline : 2
sepline :
motif : "# "
repeat : 40
comment :
start : "#^#"
end : "#^#"
begin : "# "
- meson :
file :
- meson.build
startline : 1
sepline :
motif : "# "
repeat : 40
comment :
start : "#^#"
end : "#^#"
begin : "# "
- vala :
dir :
- src
extension :
- .vala
file :
- install.vala.in
startline : 1
sepline :
motif : " *"
repeat : 40
comment :
start : "/*^"
end : "^*/"
begin : " * "
tpl : |
^sepline^
^keys^
^sepline^
This file is part of ^software.name^.
^software.name^ is free software (free as in speech) : 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.
^software.name^ 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 ^software.name^. If not, see <http://www.gnu.org/licenses/>.
^sepline^

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/

View File

@ -1,13 +1,32 @@
valac -v \
--pkg gee-0.8 \
--pkg gio-2.0 \
--pkg pluie-echo-0.2 \
--pkg pluie-yaml-0.5 \
src/Pluie/Berel.Meta.vala \
src/Pluie/Berel.HeaderDef.vala \
src/Pluie/Berel.Sepline.vala \
src/Pluie/Berel.Comment.vala \
src/Pluie/Berel.Extension.vala \
src/Pluie/Berel.Key.vala \
src/Pluie/Berel.Keys.vala \
main.vala -o main
#!/bin/bash
#^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# @software : berel <https://git.pluie.org/pluie/berel>
# @version : 0.21
# @type : program
# @date : 2018
# @license : GPLv3.0 <http://www.gnu.org/licenses/>
# @author : a-Sansara <[dev]at[pluie]dot[org]>
# @copyright : pluie.org <http://www.pluie.org>
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This file is part of berel.
#
# berel is free software (free as in speech) : 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.
#
# berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
meson --prefix=/usr/local ./ build
sudo ninja install -C build

38
install.vala.in Normal file
View File

@ -0,0 +1,38 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : berel <https://git.pluie.org/pluie/berel>
* @version : 0.21
* @type : program
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of berel.
*
* berel is free software (free as in speech) : 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.
*
* berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
namespace Pluie
{
namespace Berel
{
protected const string INSTALL_PATH = "@INSTALL_PATH@";
public const string DATA_PATH = "@DATA_PATH@";
public const string VERSION = "@VERSION@";
}
}

View File

@ -5,32 +5,13 @@ using Pluie;
int main (string[] args)
{
Echo.init(false);
var path = "./resources/berel.yml";
of.echo (path);
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = true;
var config = new Yaml.Config (path, true);
var root = config.root_node ();
if ((done = root != null)) {
root.display_childs ();
var berel = (Berel.Meta) Yaml.Builder.from_node (root.first ());
of.echo("software : %s %s".printf (berel.keys.software.name, berel.keys.software.address));
of.echo("version : %s".printf (berel.keys.version));
of.echo("type : %s".printf (berel.keys.ltype));
of.echo("date : %s".printf (berel.keys.date));
of.echo("license : %s %s".printf (berel.keys.license.name, berel.keys.license.address));
of.echo("author : %s %s".printf (berel.keys.author.name, berel.keys.author.address));
of.echo("copyright : %s %s".printf (berel.keys.copyright.name, berel.keys.copyright.address));
print (berel.tpl);
of.echo ();
print(berel.get_template ("vala"));
}
var app = new Berel.App();
done = app!=null && app.done;
of.rs (done);
of.echo ();
return (int) done;
}

73
meson.build Normal file
View File

@ -0,0 +1,73 @@
#^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# @software : berel <https://git.pluie.org/pluie/berel>
# @version : 0.21
# @type : program
# @date : 2018
# @license : GPLv3.0 <http://www.gnu.org/licenses/>
# @author : a-Sansara <[dev]at[pluie]dot[org]>
# @copyright : pluie.org <http://www.pluie.org>
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This file is part of berel.
#
# berel is free software (free as in speech) : 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.
#
# berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
project('berel', 'vala', 'c', version:'0.21')
cc = meson.get_compiler('c')
dep_glib = dependency('glib-2.0')
dep_gobject = dependency('gobject-2.0')
dep_gmodule = dependency('gmodule-2.0')
dep_gio = dependency('gio-2.0')
dep_gee = dependency('gee-0.8')
dep_echo = dependency('pluie-echo-0.2')
dep_yaml = dependency('pluie-yaml-0.5')
dep_m = cc.find_library('m', required : false)
# dep_yaml = cc.find_library('yaml', required : true)
version = meson.project_version()
bindir = join_paths(get_option('prefix'), get_option('bindir'))
datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie/berel')
libdir = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig')
incdir = join_paths(get_option('prefix'), get_option('includedir'), 'pluie')
conf = configuration_data()
conf.set('VERSION' , version)
conf.set('INSTALL_PATH', bindir)
conf.set('DATA_PATH' , datadir)
configure_file(
input: 'install.vala.in',
output: 'install.vala',
configuration: conf
)
sources = [
'build/install.vala',
'src/Pluie/Berel.App.vala',
'src/Pluie/Berel.Comment.vala',
'src/Pluie/Berel.HeaderDef.vala',
'src/Pluie/Berel.Key.vala',
'src/Pluie/Berel.Meta.vala',
'src/Pluie/Berel.Sepline.vala',
'main.vala',
]
executable('berel', sources, install : true, dependencies : [dep_glib, dep_gobject, dep_gmodule, dep_gio, dep_gee, dep_echo, dep_yaml, dep_m])

View File

@ -1,87 +0,0 @@
%YAML 1.2
%TAG !v! tag:pluie.org,2018:vala/
---
!v!Pluie.Berel.Meta meta :
!v!Pluie.Berel.Keys keys :
software :
name : pluie-yaml
address : <https://git.pluie.org/pluie/lib-yaml>
version : 0.53
ltype : library
date : 2018
license :
name : GPLv3.0
address : <http://www.gnu.org/licenses/>
author :
name : a-Sansara
address : <[dev]at[pluie]dot[org]>
copyright :
name : pluie.org
address : <http://www.pluie.org>
!v!Gee.ArrayList headers :
- !v!Pluie.Berel.HeaderDef sh :
file :
- build.sh
startline : 2
!v!Pluie.Berel.Sepline sepline :
motif : "# "
repeat : 40
extension :
- .sh
!v!Pluie.Berel.Comment comment :
start : "#^#"
end : "#^#"
begin : "# "
- !v!Pluie.Berel.HeaderDef meson :
file :
- meson.sh
startline : 1
!v!Pluie.Berel.Sepline sepline :
motif : "# "
repeat : 40
extension :
- .build
!v!Pluie.Berel.Comment comment :
start : "#^#"
end : "#^#"
begin : "# "
- !v!Pluie.Berel.HeaderDef vala :
dir :
- src
- samples
file :
- install.vala.in
extension :
- .vala
- .c
startline : 1
sepline :
motif : " *"
repeat : 40
comment :
start : /*^
end : ^*/
begin : " * "
tpl : |
^sepline^
^keys^
^sepline^
This file is part of ^software.name^.
^software.name^ is free software (free as in speech) : 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.
^software.name^ 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 ^software.name^. If not, see <http://www.gnu.org/licenses/>.
^sepline^

202
src/Pluie/Berel.App.vala Normal file
View File

@ -0,0 +1,202 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : berel <https://git.pluie.org/pluie/berel>
* @version : 0.21
* @type : program
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of berel.
*
* berel is free software (free as in speech) : 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.
*
* berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
/**
*
*/
public class Pluie.Berel.App
{
/**
*
*/
public bool done { get; internal set; }
/**
*
*/
string pwd;
/**
*
*/
Berel.Meta meta;
/**
*
*/
Io.Reader reader;
/**
*
*/
Io.Writter writter;
/**
*
*/
public App(string? path = null)
{
of.title ("Berel", Pluie.Berel.VERSION, "a-sansara");
if (this.load_config(path)) {
foreach (var header in this.meta.headers) {
this.write_header (header);
}
this.done = true;
}
}
/**
*
*/
private bool load_config (string? path = null)
{
bool done = false;
this.pwd = GLib.Environment.get_current_dir ();
var config = new Yaml.Config (Path.build_filename (path != null ? path : pwd, ".berel.yml"), false);
var root = config.root_node ();
root.name = Path.get_basename (pwd)+"/.berel.yml";
Yaml.Dumper.show_yaml_string (root);
if ((done = root != null)) {
this.meta = (Berel.Meta) Yaml.Builder.from_node (root.first ());
}
return done;
}
/**
*
*/
private void write_header (Berel.HeaderDef header)
{
of.action ("write headers from header def", header.yaml_name);
var hasHeader = false;
string? data = null;
string? path = null;
foreach (var name in header.file) {
path = Path.build_filename(this.pwd, name);
data = this.get_write_content(path, header);
this.write_file (path, data);
}
foreach (var name in header.dir) {
path = Path.build_filename(this.pwd, name);
this.write_dir (path, header);
}
}
/**
*
*/
private void write_dir (string path, HeaderDef header)
{
of.echo (" > reading directory %s".printf (path));
string? dname = null;
string? data = null;
Dir dir = Dir.open (path, 0);
while ((dname = dir.read_name ()) != null) {
string? p = Path.build_filename (path, dname);
if (FileUtils.test (p, FileTest.IS_DIR))
this.write_dir (p, header);
else {
data = this.get_write_content(p, header, true);
this.write_file (p, data);
}
}
of.echo (" < directory %s".printf (path));
}
/**
*
*/
private bool write_file (string path, string? data = null)
{
bool done = false;
of.echo (" updating file : %s".printf (path));
if (data != null && data.length > 0) {
this.writter = new Io.Writter (path, true);
done = this.writter.write (data.data);
}
of.state (done);
return done;
}
/**
*
*/
private bool match_extension (string path, Gee.ArrayList<string> extlist)
{
foreach (var ext in extlist) {
if (ext == path.substring (-ext.length)) return true;
}
return extlist.size == 0;
}
/**
*
*/
private string get_write_content (string path, HeaderDef header, bool from_dir = false)
{
bool proceed = !from_dir || this.match_extension (path, header.extension);
StringBuilder sb = new StringBuilder ();
if (proceed) {
string[] bfs = new string[header.startline];
string? s = null;
bool headbegin = false;
bool headend = false;
this.reader = new Io.Reader(path);
this.reader.rewind (new Io.StreamLineMark (0, 0));
int line = 1;
int firstempty = -1;
while (this.reader.readable && (s = this.reader.read ()) != null) {
if (header.startline > line) bfs[header.startline-line] = s;
else if (line == header.startline) {
headbegin = s.index_of (header.comment.start) == 0;
if (!headbegin) {
if (firstempty == -1 && s=="") firstempty = line;
sb.append ("%s\n".printf (s));
}
}
else {
if (!headbegin || headend || s.index_of (header.comment.end) != -1) {
if (headbegin && !headend) headend = true;
else {
if (headbegin && headend && firstempty == -1 && s=="") firstempty = line;
sb.append ("%s\n".printf (s));
}
}
}
line++;
}
if (sb.str.length > 0) {
sb.prepend ("%s%s".printf(this.meta.get_template(header), firstempty != -1 ? "" : "\n"));
if (bfs.length > 0) {
foreach (var bs in bfs) if (bs != null) sb.prepend ("%s\n".printf (bs));
}
}
}
return sb.str;
}
}

View File

@ -1,3 +1,32 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : berel <https://git.pluie.org/pluie/berel>
* @version : 0.21
* @type : program
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of berel.
*
* berel is free software (free as in speech) : 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.
*
* berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
/**
@ -37,8 +66,8 @@ public class Pluie.Berel.Comment : Yaml.Object
/**
*
*/
public string get_line (string data)
public string get_line (string data, bool disabled = false)
{
return "%s%s".printf (this.begin, data);
return "%s%s".printf (disabled ? "" : this.begin, data);
}
}

View File

@ -1,7 +0,0 @@
using GLib;
using Pluie;
public class Pluie.Berel.Extension : Yaml.Object
{
public Gee.ArrayList<string> list { get; set; }
}

View File

@ -1,3 +1,32 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : berel <https://git.pluie.org/pluie/berel>
* @version : 0.21
* @type : program
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of berel.
*
* berel is free software (free as in speech) : 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.
*
* berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;

View File

@ -1,8 +1,47 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : berel <https://git.pluie.org/pluie/berel>
* @version : 0.21
* @type : program
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of berel.
*
* berel is free software (free as in speech) : 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.
*
* berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
public class Pluie.Berel.Key : Yaml.Object
{
public string name { get; internal set; }
public string address { get; internal set; }
public string name { get; internal set; }
public string? address { get; internal set; }
public Key.with_node (Yaml.Node node)
{
this.yaml_name = node.name;
if (node.ntype.is_single_pair ()) {
var s = node.first ().data.split (";");
this.name = s[0];
if (s.length > 1) this.address = s[1];
}
}
}

View File

@ -1,84 +0,0 @@
using GLib;
using Pluie;
/**
*
*/
public class Pluie.Berel.Keys : Yaml.Object
{
/**
*
*/
public Berel.Key software { get; internal set; }
/**
*
*/
public string version { get; internal set; }
/**
*
*/
public string ltype { get; internal set; }
/**
*
*/
public string date { get; internal set; }
/**
*
*/
public Berel.Key license { get; internal set; }
/**
*
*/
public Berel.Key author { get; internal set; }
/**
*
*/
public Berel.Key copyright { get; internal set; }
/**
*
*/
public string get_all (HeaderDef hd)
{
var properties = this.get_class ().list_properties;
Berel.Key? ck = null;
string? cs = null;
foreach (var p in properties) {
if (p.value_type.is_a(typeof (Berel.Key))) {
}
}
foreach
var str = """@software : %15s %s
@version : %s %s
@type : %s
@date : %s
".printf (
""";
}
/**
*
*/
public string replace_var (string varname)
{
string val = "";
var list = varname.split(".", 2);
if (list.length == 1) {
if (this.get_class ().find_property (varname) != null) {
this.get(varname, out val);
}
}
else {
Berel.Key? k = null;
this.get(list[0], out k);
if (k != null) {
if (k.get_class ().find_property (list[1]) != null) {
k.get(list[1], out val);
}
}
}
return val;
}
}

View File

@ -1,3 +1,32 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : berel <https://git.pluie.org/pluie/berel>
* @version : 0.21
* @type : program
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of berel.
*
* berel is free software (free as in speech) : 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.
*
* berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
/**
@ -8,7 +37,7 @@ public class Pluie.Berel.Meta : Yaml.Object
/**
*
*/
public Berel.Keys keys { get; internal set; }
public Gee.ArrayList<Berel.Key> keys { get; internal set; }
/**
*
*/
@ -39,6 +68,7 @@ public class Pluie.Berel.Meta : Yaml.Object
protected override void yaml_construct ()
{
this.headers = new Gee.ArrayList<Berel.HeaderDef> ();
this.keys = new Gee.ArrayList<Berel.Key> ();
this.varlist = new Gee.HashMap<string, string> ();
Yaml.Register.add_namespace("Gee", "Pluie.Berel");
Dbg.msg ("%s (%s) instantiated".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
@ -54,66 +84,63 @@ public class Pluie.Berel.Meta : Yaml.Object
case "headers":
this.headers.add((Berel.HeaderDef) Yaml.Builder.from_node (child, typeof (Berel.HeaderDef)));
break;
case "keys":
this.keys.add (new Berel.Key.with_node(child));
break;
}
}
}
else {
var obj = Yaml.Builder.from_node(node, type);
if (name == "keys") {
this.set (node.name, (Berel.Keys ) obj);
this.set (node.name, Yaml.Builder.from_node(node, type));
}
}
/**
*
*/
public string get_template (HeaderDef hd)
{
var count = 1;
StringBuilder sb = new StringBuilder();
var s = this.tpl_replace_var (hd);
foreach (unowned string str in s.split("\\n")) {
if (count++ == 1) {
sb.append("%s\n".printf (hd.comment.start+str.substring (hd.comment.start.length)));
}
else {
this.set (node.name, obj);
sb.append("%s\n".printf (hd.comment.get_line(str, str==hd.sepline.to_string ())));
}
}
return "%s\n".printf (sb.str.substring (0, sb.str.length - 5 -(hd.sepline.motif[0] == ' ' ? 0 : 1) - hd.comment.end.length)+hd.comment.end);
}
/**
*
*/
public string get_template (string type)
{
var headerdef = this.get_header_by_type (type);
var count = 1;
this.tpl_replace_var (headerdef);
StringBuilder sb = new StringBuilder ("");
foreach (string line in this.tpl.split ("\\n")) {
if (count == 1) {
//~ sb.append (this.comment.start
}
count++;
}
return "";
}
/**
*
*/
public void tpl_replace_var (HeaderDef hd)
public string tpl_replace_var (HeaderDef hd)
{
MatchInfo? mi = null;
Regex reg = new Regex ("\\^([^\\^]+)\\^");
if (reg.match (this.tpl, 0, out mi)) {
this.replacing (mi.fetch (1), hd);
string str = this.tpl;
this.varlist = new Gee.HashMap<string, string> ();
if (reg.match (str, 0, out mi)) {
this.define_var (mi.fetch (1), hd);
while (mi.next ()) {;
this.replacing (mi.fetch (1), hd);
this.define_var (mi.fetch (1), hd);
}
}
foreach (var entry in this.varlist.entries) {
if (entry.value.length > 0) {
this.tpl = this.tpl.replace("^%s^".printf (entry.key), entry.value);
str = str.replace("^%s^".printf (entry.key), (entry.key == "sepline" ? "" : "")+entry.value);
}
}
var s = this.tpl.split("\\n");
foreach (unowned string str in s) {
print ("%s\n", hd.comment.get_line(str));
}
return str;
}
/**
*
*/
private void replacing (string key, HeaderDef hd)
private void define_var (string key, HeaderDef hd)
{
if (!this.varlist.has_key (key)) {
switch (key) {
@ -121,10 +148,10 @@ public class Pluie.Berel.Meta : Yaml.Object
this.varlist.set (key, hd.sepline.to_string ());
break;
case "keys" :
this.varlist.set (key, this.keys.get_all (hd));
this.varlist.set (key, this.get_all_keys (hd));
break;
default :
this.varlist.set (key, this.keys.replace_var(key));
this.varlist.set (key, this.replace_var(key));
break;
}
}
@ -144,4 +171,45 @@ public class Pluie.Berel.Meta : Yaml.Object
}
return hd;
}
/**
*
*/
public string get_all_keys (HeaderDef hd)
{
int len = 0;
int lenk = 0;
StringBuilder sb = new StringBuilder ();
foreach (var bk in this.keys) {
if (bk.yaml_name.length > lenk) lenk = bk.yaml_name.length;
if (bk.name.length > len) len = bk.name.length;
}
int count = 0;
foreach (var bk in this.keys) {
sb.append (hd.comment.get_line("@%s%s : %s%s%s%s".printf (
bk.yaml_name,
string.nfill(lenk+2-bk.yaml_name.length, ' '),
bk.name,
string.nfill(len+2-bk.name.length, ' '),
bk.address != null ? " %s".printf (bk.address) : "",
count == this.keys.size -1 ? "" : "\n"
),count++ == 0));
}
return sb.str;
}
/**
*
*/
public string replace_var (string varname)
{
string val = "";
var list = varname.split(".", 2);
foreach (var k in this.keys) {
if (k.yaml_name == list[0]) {
val = list.length == 1 || list[1] == "name" ? k.name : k.address;
}
}
return val;
}
}

View File

@ -1,3 +1,32 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : berel <https://git.pluie.org/pluie/berel>
* @version : 0.21
* @type : program
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of berel.
*
* berel is free software (free as in speech) : 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.
*
* berel 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 berel. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;