/* augeas.vapi
 *
 * Copyright (C) 2010  Fabian Deutsch
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * As a special exception, if you use inline functions from this file, this
 * file does not by itself cause the resulting executable to be covered by
 * the GNU Lesser General Public License.
 *
 * Author:
 *  Fabian Deutsch <fabian.deutsch@gmx.de>
 */

[CCode (cheader_filename = "augeas.h")]
namespace LibAugeas {

	[Flags]
	[CCode (cprefix = "AUG_")]
	public enum InitFlags {
		NONE,
		SAVE_BACKUP,
		SAVE_NEWFILE,
		TYPE_CHECK,
		NO_STDINC,
		SAVE_NOOP,
		NO_LOAD,
		NO_MODL_AUTOLOAD
	}

	[CCode (cprefix= "AUG_")]
	public enum ErrorCode
	{
		NOERROR,
		ENOMEM,
		EINTERNAL,
		EPATHX,
		ENOMATCH,
		EMMATCH,
		ESYNTAX,
		ENOLENS,
		EMXFM
	}

	[Compact]
	[CCode (cname = "augeas", cprefix = "aug_", free_function = "aug_close")]
	public class Augeas {

		[CCode (cname = "aug_init")]
		public Augeas (string? root = null, string? loadpath = null, uint flags = 0);

		public int defvar (string name, string? expr);
		public int defnode (string name, string expr, string value, out int created);

		public int get (string path, out unowned string? value);
		public int set (string path, string value);
		public int insert (string path, string label, int before);

		public int rm (string path);
		public int mv (string src, string dst);

		[CCode (cname = "aug_match_wrapper")]
		public int match (string path, out string[]? matches = null)
		{
			int len = _match (path, out matches);
			if( matches != null ) matches.length = len;
			return len;
		}
		[CCode (cname = "aug_match")]
		int _match(string p, [CCode (array_length = false)] out string[]? matches);

		public int save ();
		public int load ();
#if POSIX
		public int print (Posix.FILE out, string path);
#else
		public int print (GLib.FileStream out, string path);
#endif
		public void close ();

		public ErrorCode error ();
		public string error_message ();
		public string error_minor_message ();
		public string error_details ();
	}
}

